merge upstream

This commit is contained in:
ZLOFENIX 2013-09-04 17:52:05 +04:00
parent f0e6d400cb
commit bee5089161
3 changed files with 296 additions and 296 deletions

View file

@ -1,111 +1,111 @@
package cr0s.WarpDrive; package cr0s.WarpDrive;
import java.util.HashMap; import java.util.HashMap;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.DamageSource; import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper; import net.minecraft.util.MathHelper;
import net.minecraftforge.common.DimensionManager; import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
/** /**
* Обработчик событий в мире Space * Обработчик событий в мире Space
* @author Cr0s * @author Cr0s
*/ */
public class SpaceEventHandler { public class SpaceEventHandler {
private HashMap<String, Integer> vacuumPlayers; private HashMap<String, Integer> vacuumPlayers;
public SpaceEventHandler() { public SpaceEventHandler() {
vacuumPlayers = new HashMap<String, Integer>(); vacuumPlayers = new HashMap<String, Integer>();
} }
@ForgeSubscribe @ForgeSubscribe
public void livingUpdate(LivingUpdateEvent event) { public void livingUpdate(LivingUpdateEvent event) {
EntityLivingBase entity = event.entityLiving; EntityLivingBase entity = event.entityLiving;
if (Math.abs(MathHelper.floor_double(entity.posX)) > WarpDrive.WORLD_LIMIT_BLOCKS || Math.abs(MathHelper.floor_double(entity.posZ)) > WarpDrive.WORLD_LIMIT_BLOCKS) { if (Math.abs(MathHelper.floor_double(entity.posX)) > WarpDrive.WORLD_LIMIT_BLOCKS || Math.abs(MathHelper.floor_double(entity.posZ)) > WarpDrive.WORLD_LIMIT_BLOCKS) {
if (entity instanceof EntityPlayerMP) { if (entity instanceof EntityPlayerMP) {
if (((EntityPlayerMP)entity).capabilities.isCreativeMode) { if (((EntityPlayerMP)entity).capabilities.isCreativeMode) {
return; return;
} }
} }
entity.attackEntityFrom(DamageSource.outOfWorld, 9000); entity.attackEntityFrom(DamageSource.outOfWorld, 9000);
return; return;
} }
final int HELMET_ID_SKUBA = 30082; final int HELMET_ID_SKUBA = 30082;
final int HELMET_ID_HAZMAT = 14023; final int HELMET_ID_HAZMAT = 14023;
final int HELMET_ID_QUANTUM = 30174; final int HELMET_ID_QUANTUM = 30174;
final int AIR_CELL_ID = 30079; final int AIR_CELL_ID = 30079;
// Обновление происходит в космическом или гипер пространстве // Обновление происходит в космическом или гипер пространстве
if (entity.worldObj.provider.dimensionId == WarpDrive.instance.spaceDimID || entity.worldObj.provider.dimensionId == WarpDrive.instance.hyperSpaceDimID) { if (entity.worldObj.provider.dimensionId == WarpDrive.instance.spaceDimID || entity.worldObj.provider.dimensionId == WarpDrive.instance.hyperSpaceDimID) {
boolean inVacuum = isEntityInVacuum(entity); boolean inVacuum = isEntityInVacuum(entity);
// Damage entity if in vacuum without protection // Damage entity if in vacuum without protection
if (inVacuum) { if (inVacuum) {
if (entity instanceof EntityPlayerMP) { if (entity instanceof EntityPlayerMP) {
if (((EntityPlayerMP)entity).getCurrentArmor(3) != null && ((((EntityPlayerMP)entity).getCurrentArmor(3).itemID == HELMET_ID_SKUBA || ((EntityPlayerMP)entity).getCurrentArmor(3).itemID == HELMET_ID_HAZMAT) || ((EntityPlayerMP)entity).getCurrentArmor(3).itemID == HELMET_ID_QUANTUM)) { if (((EntityPlayerMP)entity).getCurrentArmor(3) != null && ((((EntityPlayerMP)entity).getCurrentArmor(3).itemID == HELMET_ID_SKUBA || ((EntityPlayerMP)entity).getCurrentArmor(3).itemID == HELMET_ID_HAZMAT) || ((EntityPlayerMP)entity).getCurrentArmor(3).itemID == HELMET_ID_QUANTUM)) {
Integer airValue = vacuumPlayers.get(((EntityPlayerMP)entity).username); Integer airValue = vacuumPlayers.get(((EntityPlayerMP)entity).username);
if (airValue == null) { if (airValue == null) {
vacuumPlayers.put(((EntityPlayerMP)entity).username, 300); vacuumPlayers.put(((EntityPlayerMP)entity).username, 300);
airValue = 300; airValue = 300;
} }
if (airValue <= 0) { if (airValue <= 0) {
if (((EntityPlayerMP)entity).inventory.consumeInventoryItem(AIR_CELL_ID)) { if (((EntityPlayerMP)entity).inventory.consumeInventoryItem(AIR_CELL_ID)) {
setPlayerAirValue(entity, 300); setPlayerAirValue(entity, 300);
} else { } else {
setPlayerAirValue(entity, 0); setPlayerAirValue(entity, 0);
entity.attackEntityFrom(DamageSource.drown, 1); entity.attackEntityFrom(DamageSource.drown, 1);
} }
} else { } else {
setPlayerAirValue(entity, airValue - 1); setPlayerAirValue(entity, airValue - 1);
} }
} else { } else {
entity.attackEntityFrom(DamageSource.drown, 1); entity.attackEntityFrom(DamageSource.drown, 1);
} }
// Отправить назад на Землю // Отправить назад на Землю
if (entity.posY < -10.0D) { if (entity.posY < -10.0D) {
((EntityPlayerMP)entity).mcServer.getConfigurationManager().transferPlayerToDimension(((EntityPlayerMP) entity), 0, new SpaceTeleporter(DimensionManager.getWorld(WarpDrive.instance.spaceDimID), 0, MathHelper.floor_double(entity.posX), 250, MathHelper.floor_double(entity.posZ))); ((EntityPlayerMP)entity).mcServer.getConfigurationManager().transferPlayerToDimension(((EntityPlayerMP) entity), 0, new SpaceTeleporter(DimensionManager.getWorld(WarpDrive.instance.spaceDimID), 0, MathHelper.floor_double(entity.posX), 250, MathHelper.floor_double(entity.posZ)));
((EntityPlayerMP)entity).setFire(30); ((EntityPlayerMP)entity).setFire(30);
((EntityPlayerMP)entity).setPositionAndUpdate(entity.posX, 250D, entity.posZ); ((EntityPlayerMP)entity).setPositionAndUpdate(entity.posX, 250D, entity.posZ);
} }
} else { } else {
entity.attackEntityFrom(DamageSource.drown, 1); entity.attackEntityFrom(DamageSource.drown, 1);
} }
} }
} }
} }
private void setPlayerAirValue(EntityLivingBase entity, Integer air) { private void setPlayerAirValue(EntityLivingBase entity, Integer air) {
vacuumPlayers.remove(((EntityPlayerMP)entity).username); vacuumPlayers.remove(((EntityPlayerMP)entity).username);
vacuumPlayers.put(((EntityPlayerMP)entity).username, air); vacuumPlayers.put(((EntityPlayerMP)entity).username, air);
} }
/** /**
* Проверка, находится ли Entity в открытом космосе * Проверка, находится ли Entity в открытом космосе
* @param e * @param e
* @return * @return
*/ */
private boolean isEntityInVacuum(Entity e) { private boolean isEntityInVacuum(Entity e) {
int x = MathHelper.floor_double(e.posX); int x = MathHelper.floor_double(e.posX);
int y = MathHelper.floor_double(e.posY); int y = MathHelper.floor_double(e.posY);
int z = MathHelper.floor_double(e.posZ); int z = MathHelper.floor_double(e.posZ);
int id1 = e.worldObj.getBlockId(x, y, z); int id1 = e.worldObj.getBlockId(x, y, z);
int id2 = e.worldObj.getBlockId(x, y + 1, z); int id2 = e.worldObj.getBlockId(x, y + 1, z);
if (id1 == WarpDrive.instance.config.airID || id2 == WarpDrive.instance.config.airID) { if (id1 == WarpDrive.instance.config.airID || id2 == WarpDrive.instance.config.airID) {
return false; return false;
} }
return true; return true;
} }
} }

View file

@ -1,37 +1,37 @@
package cr0s.serverMods; package cr0s.serverMods;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.MathHelper; import net.minecraft.util.MathHelper;
import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.living.LivingFallEvent; import net.minecraftforge.event.entity.living.LivingFallEvent;
/** /**
* Гашение урона при падении с джетпаком или квантовыми бутсами * Гашение урона при падении с джетпаком или квантовыми бутсами
* @author Cr0s * @author Cr0s
*/ */
public class AntiFallDamage { public class AntiFallDamage {
private final int JETPACK_ID = 30210; private final int JETPACK_ID = 30210;
private final int ELECTRIC_JETPACK_ID = 30209; private final int ELECTRIC_JETPACK_ID = 30209;
private final int QUANTUM_BOOTS_ID = 30171; private final int QUANTUM_BOOTS_ID = 30171;
@ForgeSubscribe @ForgeSubscribe
public void livingFall(LivingFallEvent event) { public void livingFall(LivingFallEvent event) {
EntityLivingBase entity = event.entityLiving; EntityLivingBase entity = event.entityLiving;
float distance = event.distance; float distance = event.distance;
if (entity instanceof EntityPlayer) { if (entity instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) entity; EntityPlayer player = (EntityPlayer) entity;
int check = MathHelper.ceiling_float_int(distance - 3.0F); int check = MathHelper.ceiling_float_int(distance - 3.0F);
if (check > 0) { // Падение может нанести урон if (check > 0) { // Падение может нанести урон
// Проверяем наличие защиты // Проверяем наличие защиты
if ((player.getCurrentArmor(0) != null && player.getCurrentArmor(0).itemID == QUANTUM_BOOTS_ID) || if ((player.getCurrentArmor(0) != null && player.getCurrentArmor(0).itemID == QUANTUM_BOOTS_ID) ||
(player.getCurrentArmor(2) != null && player.getCurrentArmor(2).itemID == JETPACK_ID) || (player.getCurrentArmor(2) != null && player.getCurrentArmor(2).itemID == JETPACK_ID) ||
(player.getCurrentArmor(2) != null && player.getCurrentArmor(2).itemID == ELECTRIC_JETPACK_ID)) { (player.getCurrentArmor(2) != null && player.getCurrentArmor(2).itemID == ELECTRIC_JETPACK_ID)) {
event.setCanceled(true); // Блокируем падение, если защита есть event.setCanceled(true); // Блокируем падение, если защита есть
} }
} }
} }
} }
} }

View file

@ -1,149 +1,149 @@
package cr0s.serverMods; package cr0s.serverMods;
import cpw.mods.fml.common.network.IConnectionHandler; import cpw.mods.fml.common.network.IConnectionHandler;
import cpw.mods.fml.common.network.Player; import cpw.mods.fml.common.network.Player;
import java.io.*; import java.io.*;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.minecraft.network.INetworkManager; import net.minecraft.network.INetworkManager;
import net.minecraft.network.NetLoginHandler; import net.minecraft.network.NetLoginHandler;
import net.minecraft.network.packet.NetHandler; import net.minecraft.network.packet.NetHandler;
import net.minecraft.network.packet.Packet1Login; import net.minecraft.network.packet.Packet1Login;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
/** /**
* РђРІСРѕСЂРёР·Р°СРёСЏ РЅРёРє.пароль * РђРІСРѕСЂРёР·Р°СРёСЏ РЅРёРє.пароль
* @author Cr0s * @author Cr0s
*/ */
public class LoginHookClass implements IConnectionHandler { public class LoginHookClass implements IConnectionHandler {
private String kickReason = ""; private String kickReason = "";
private File uFile; private File uFile;
public LoginHookClass() { public LoginHookClass() {
uFile = MinecraftServer.getServer().getFile("users.txt"); uFile = MinecraftServer.getServer().getFile("users.txt");
} }
private void checkLogin(NetLoginHandler netHandler) throws FileNotFoundException, IOException { private void checkLogin(NetLoginHandler netHandler) throws FileNotFoundException, IOException {
String s = netHandler.clientUsername; String s = netHandler.clientUsername;
System.out.println("[SERVER MODS] Logging in user: " + s); System.out.println("[SERVER MODS] Logging in user: " + s);
BufferedReader bufferedreader = new BufferedReader(new FileReader(uFile)); BufferedReader bufferedreader = new BufferedReader(new FileReader(uFile));
if (s.indexOf(".") == -1 || s.split("\\.").length != 2) { if (s.indexOf(".") == -1 || s.split("\\.").length != 2) {
kickReason = "Никнейм и пароль должны быть разделены точками."; kickReason = "Никнейм и пароль должны быть разделены точками.";
bufferedreader.close(); bufferedreader.close();
return; return;
} }
if (!s.matches("^[a-zA-Z0-9_.]+$")) { if (!s.matches("^[a-zA-Z0-9_.]+$")) {
kickReason = "Р<EFBFBD>РјСЏ пользователя или пароль содержат недопустимые символы."; kickReason = "Р<EFBFBD>РјСЏ пользователя или пароль содержат недопустимые символы.";
bufferedreader.close(); bufferedreader.close();
return; return;
} }
String s4 = s.split("\\.")[0].trim(); String s4 = s.split("\\.")[0].trim();
String s5 = s.split("\\.")[1].trim(); String s5 = s.split("\\.")[1].trim();
if (s4.length() < 2 && !s4.equals("Q")) { if (s4.length() < 2 && !s4.equals("Q")) {
kickReason = "Р<EFBFBD>РјСЏ пользователя слишком короткое."; kickReason = "Р<EFBFBD>РјСЏ пользователя слишком короткое.";
bufferedreader.close(); bufferedreader.close();
return; return;
} }
if (s5.length() < 3) { if (s5.length() < 3) {
kickReason = "Пароль слишком короткий."; kickReason = "Пароль слишком короткий.";
bufferedreader.close(); bufferedreader.close();
return; return;
} }
if (s4.length() > 15) { if (s4.length() > 15) {
kickReason = "\u0421\u043B\u0438\u0448\u043A\u043E\u043C \u0434\u043B\u0438\u043D\u043D\u044B\u0439 \u043B\u043E\u0433\u0438\u043D! (>15)"; kickReason = "\u0421\u043B\u0438\u0448\u043A\u043E\u043C \u0434\u043B\u0438\u043D\u043D\u044B\u0439 \u043B\u043E\u0433\u0438\u043D! (>15)";
bufferedreader.close(); bufferedreader.close();
return; return;
} }
String s1; String s1;
while ((s1 = bufferedreader.readLine()) != null) { while ((s1 = bufferedreader.readLine()) != null) {
String s2; String s2;
String s3; String s3;
try { try {
s2 = s1.split("\\.")[0]; s2 = s1.split("\\.")[0];
s3 = s1.split("\\.")[1]; s3 = s1.split("\\.")[1];
} catch (Exception exception) { } catch (Exception exception) {
kickReason = "login.password error, database is corrupted."; kickReason = "login.password error, database is corrupted.";
bufferedreader.close(); bufferedreader.close();
return; return;
} }
if (s2.toLowerCase().equals(s4.toLowerCase())) { if (s2.toLowerCase().equals(s4.toLowerCase())) {
if (!s3.equals(s5)) { if (!s3.equals(s5)) {
kickReason = "Неправильный пароль!"; kickReason = "Неправильный пароль!";
System.out.println((new StringBuilder()).append(netHandler.clientUsername).append(" failed to login (pwd: ").append(s3).append(")").toString()); System.out.println((new StringBuilder()).append(netHandler.clientUsername).append(" failed to login (pwd: ").append(s3).append(")").toString());
bufferedreader.close(); bufferedreader.close();
return; return;
} else { } else {
bufferedreader.close(); bufferedreader.close();
return; return;
} }
} }
} }
bufferedreader.close(); bufferedreader.close();
// РЎРѕР·РґР°СРј РЅРѕРІСР Р°РєРєР°СѓРЅС // РЎРѕР·РґР°СРј РЅРѕРІСРаккаунС
PrintWriter printwriter = new PrintWriter(new FileWriter(uFile, true)); PrintWriter printwriter = new PrintWriter(new FileWriter(uFile, true));
printwriter.println(s); printwriter.println(s);
printwriter.close(); printwriter.close();
kickReason = ""; kickReason = "";
} }
@Override @Override
public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager) { public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager) {
//throw new UnsupportedOperationException("Not supported yet."); //throw new UnsupportedOperationException("Not supported yet.");
} }
@Override @Override
public String connectionReceived(NetLoginHandler netHandler, INetworkManager manager) { public String connectionReceived(NetLoginHandler netHandler, INetworkManager manager) {
kickReason = ""; kickReason = "";
try { try {
checkLogin(netHandler); checkLogin(netHandler);
} catch (FileNotFoundException ex) { } catch (FileNotFoundException ex) {
Logger.getLogger(LoginHookClass.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(LoginHookClass.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) { } catch (IOException ex) {
Logger.getLogger(LoginHookClass.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(LoginHookClass.class.getName()).log(Level.SEVERE, null, ex);
} }
// РќРµ РєРёРєР°ССЊ // РќРµ РєРёРєР°ССЊ
if (kickReason.isEmpty()) { if (kickReason.isEmpty()) {
// УдалиССЊ пароль РёР· имени пользоваСеля // УдалиССЊ пароль РёР· имени пользоваСеля
netHandler.clientUsername = netHandler.clientUsername.split("\\.")[0]; netHandler.clientUsername = netHandler.clientUsername.split("\\.")[0];
} }
return kickReason; return kickReason;
} }
@Override @Override
public void connectionOpened(NetHandler netClientHandler, String server, int port, INetworkManager manager) { public void connectionOpened(NetHandler netClientHandler, String server, int port, INetworkManager manager) {
//throw new UnsupportedOperationException("Not supported yet."); //throw new UnsupportedOperationException("Not supported yet.");
} }
@Override @Override
public void connectionOpened(NetHandler netClientHandler, MinecraftServer server, INetworkManager manager) { public void connectionOpened(NetHandler netClientHandler, MinecraftServer server, INetworkManager manager) {
//throw new UnsupportedOperationException("Not supported yet."); //throw new UnsupportedOperationException("Not supported yet.");
} }
@Override @Override
public void connectionClosed(INetworkManager manager) { public void connectionClosed(INetworkManager manager) {
//throw new UnsupportedOperationException("Not supported yet."); //throw new UnsupportedOperationException("Not supported yet.");
} }
@Override @Override
public void clientLoggedIn(NetHandler clientHandler, INetworkManager manager, Packet1Login login) { public void clientLoggedIn(NetHandler clientHandler, INetworkManager manager, Packet1Login login) {
throw new UnsupportedOperationException("Not supported yet."); throw new UnsupportedOperationException("Not supported yet.");
} }
} }