From bee50891611b46b14e0602d217ac5ab885f894e4 Mon Sep 17 00:00:00 2001 From: ZLOFENIX Date: Wed, 4 Sep 2013 17:52:05 +0400 Subject: [PATCH] merge upstream --- src/cr0s/WarpDrive/SpaceEventHandler.java | 222 ++++++++-------- src/cr0s/serverMods/AntiFallDamage.java | 74 +++--- src/cr0s/serverMods/LoginHookClass.java | 296 +++++++++++----------- 3 files changed, 296 insertions(+), 296 deletions(-) diff --git a/src/cr0s/WarpDrive/SpaceEventHandler.java b/src/cr0s/WarpDrive/SpaceEventHandler.java index 71a21242..c85888ee 100644 --- a/src/cr0s/WarpDrive/SpaceEventHandler.java +++ b/src/cr0s/WarpDrive/SpaceEventHandler.java @@ -1,111 +1,111 @@ -package cr0s.WarpDrive; - -import java.util.HashMap; - -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.util.DamageSource; -import net.minecraft.util.MathHelper; -import net.minecraftforge.common.DimensionManager; -import net.minecraftforge.event.ForgeSubscribe; -import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; - -/** - * Обработчик событий в мире Space - * @author Cr0s - */ -public class SpaceEventHandler { - private HashMap vacuumPlayers; - - public SpaceEventHandler() { - vacuumPlayers = new HashMap(); - } - - @ForgeSubscribe - public void livingUpdate(LivingUpdateEvent event) { - 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 (entity instanceof EntityPlayerMP) { - if (((EntityPlayerMP)entity).capabilities.isCreativeMode) { - return; - } - } - entity.attackEntityFrom(DamageSource.outOfWorld, 9000); - return; - } - - final int HELMET_ID_SKUBA = 30082; - final int HELMET_ID_HAZMAT = 14023; - final int HELMET_ID_QUANTUM = 30174; - final int AIR_CELL_ID = 30079; - - // Обновление происходит в космическом или гипер пространстве - if (entity.worldObj.provider.dimensionId == WarpDrive.instance.spaceDimID || entity.worldObj.provider.dimensionId == WarpDrive.instance.hyperSpaceDimID) { - boolean inVacuum = isEntityInVacuum(entity); - - // Damage entity if in vacuum without protection - if (inVacuum) { - 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)) { - Integer airValue = vacuumPlayers.get(((EntityPlayerMP)entity).username); - if (airValue == null) { - vacuumPlayers.put(((EntityPlayerMP)entity).username, 300); - airValue = 300; - } - - if (airValue <= 0) { - if (((EntityPlayerMP)entity).inventory.consumeInventoryItem(AIR_CELL_ID)) { - setPlayerAirValue(entity, 300); - } else { - setPlayerAirValue(entity, 0); - entity.attackEntityFrom(DamageSource.drown, 1); - } - } else { - setPlayerAirValue(entity, airValue - 1); - } - } else { - entity.attackEntityFrom(DamageSource.drown, 1); - } - - // Отправить назад на Землю - 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).setFire(30); - ((EntityPlayerMP)entity).setPositionAndUpdate(entity.posX, 250D, entity.posZ); - } - } else { - entity.attackEntityFrom(DamageSource.drown, 1); - } - } - } - } - - private void setPlayerAirValue(EntityLivingBase entity, Integer air) { - vacuumPlayers.remove(((EntityPlayerMP)entity).username); - vacuumPlayers.put(((EntityPlayerMP)entity).username, air); - } - - - /** - * Проверка, находится ли Entity в открытом космосе - * @param e - * @return - */ - private boolean isEntityInVacuum(Entity e) { - - int x = MathHelper.floor_double(e.posX); - int y = MathHelper.floor_double(e.posY); - int z = MathHelper.floor_double(e.posZ); - - int id1 = e.worldObj.getBlockId(x, y, z); - int id2 = e.worldObj.getBlockId(x, y + 1, z); - - if (id1 == WarpDrive.instance.config.airID || id2 == WarpDrive.instance.config.airID) { - return false; - } - - return true; - } -} +package cr0s.WarpDrive; + +import java.util.HashMap; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.util.DamageSource; +import net.minecraft.util.MathHelper; +import net.minecraftforge.common.DimensionManager; +import net.minecraftforge.event.ForgeSubscribe; +import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; + +/** + * Обработчик событий в мире Space + * @author Cr0s + */ +public class SpaceEventHandler { + private HashMap vacuumPlayers; + + public SpaceEventHandler() { + vacuumPlayers = new HashMap(); + } + + @ForgeSubscribe + public void livingUpdate(LivingUpdateEvent event) { + 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 (entity instanceof EntityPlayerMP) { + if (((EntityPlayerMP)entity).capabilities.isCreativeMode) { + return; + } + } + entity.attackEntityFrom(DamageSource.outOfWorld, 9000); + return; + } + + final int HELMET_ID_SKUBA = 30082; + final int HELMET_ID_HAZMAT = 14023; + final int HELMET_ID_QUANTUM = 30174; + final int AIR_CELL_ID = 30079; + + // Обновление происходит в космическом или гипер пространстве + if (entity.worldObj.provider.dimensionId == WarpDrive.instance.spaceDimID || entity.worldObj.provider.dimensionId == WarpDrive.instance.hyperSpaceDimID) { + boolean inVacuum = isEntityInVacuum(entity); + + // Damage entity if in vacuum without protection + if (inVacuum) { + 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)) { + Integer airValue = vacuumPlayers.get(((EntityPlayerMP)entity).username); + if (airValue == null) { + vacuumPlayers.put(((EntityPlayerMP)entity).username, 300); + airValue = 300; + } + + if (airValue <= 0) { + if (((EntityPlayerMP)entity).inventory.consumeInventoryItem(AIR_CELL_ID)) { + setPlayerAirValue(entity, 300); + } else { + setPlayerAirValue(entity, 0); + entity.attackEntityFrom(DamageSource.drown, 1); + } + } else { + setPlayerAirValue(entity, airValue - 1); + } + } else { + entity.attackEntityFrom(DamageSource.drown, 1); + } + + // Отправить назад на Землю + 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).setFire(30); + ((EntityPlayerMP)entity).setPositionAndUpdate(entity.posX, 250D, entity.posZ); + } + } else { + entity.attackEntityFrom(DamageSource.drown, 1); + } + } + } + } + + private void setPlayerAirValue(EntityLivingBase entity, Integer air) { + vacuumPlayers.remove(((EntityPlayerMP)entity).username); + vacuumPlayers.put(((EntityPlayerMP)entity).username, air); + } + + + /** + * Проверка, находится ли Entity в открытом космосе + * @param e + * @return + */ + private boolean isEntityInVacuum(Entity e) { + + int x = MathHelper.floor_double(e.posX); + int y = MathHelper.floor_double(e.posY); + int z = MathHelper.floor_double(e.posZ); + + int id1 = e.worldObj.getBlockId(x, y, z); + int id2 = e.worldObj.getBlockId(x, y + 1, z); + + if (id1 == WarpDrive.instance.config.airID || id2 == WarpDrive.instance.config.airID) { + return false; + } + + return true; + } +} diff --git a/src/cr0s/serverMods/AntiFallDamage.java b/src/cr0s/serverMods/AntiFallDamage.java index fbd5aa9b..807d88f7 100644 --- a/src/cr0s/serverMods/AntiFallDamage.java +++ b/src/cr0s/serverMods/AntiFallDamage.java @@ -1,37 +1,37 @@ -package cr0s.serverMods; - -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.MathHelper; -import net.minecraftforge.event.ForgeSubscribe; -import net.minecraftforge.event.entity.living.LivingFallEvent; - -/** - * Гашение урона при падении с джетпаком или квантовыми бутсами - * @author Cr0s - */ -public class AntiFallDamage { - private final int JETPACK_ID = 30210; - private final int ELECTRIC_JETPACK_ID = 30209; - private final int QUANTUM_BOOTS_ID = 30171; - - @ForgeSubscribe - public void livingFall(LivingFallEvent event) { - EntityLivingBase entity = event.entityLiving; - float distance = event.distance; - - if (entity instanceof EntityPlayer) { - EntityPlayer player = (EntityPlayer) entity; - - int check = MathHelper.ceiling_float_int(distance - 3.0F); - if (check > 0) { // Падение может нанести урон - // Проверяем наличие защиты - 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 == ELECTRIC_JETPACK_ID)) { - event.setCanceled(true); // Блокируем падение, если защита есть - } - } - } - } -} +package cr0s.serverMods; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.MathHelper; +import net.minecraftforge.event.ForgeSubscribe; +import net.minecraftforge.event.entity.living.LivingFallEvent; + +/** + * Гашение урона при падении с джетпаком или квантовыми бутсами + * @author Cr0s + */ +public class AntiFallDamage { + private final int JETPACK_ID = 30210; + private final int ELECTRIC_JETPACK_ID = 30209; + private final int QUANTUM_BOOTS_ID = 30171; + + @ForgeSubscribe + public void livingFall(LivingFallEvent event) { + EntityLivingBase entity = event.entityLiving; + float distance = event.distance; + + if (entity instanceof EntityPlayer) { + EntityPlayer player = (EntityPlayer) entity; + + int check = MathHelper.ceiling_float_int(distance - 3.0F); + if (check > 0) { // Падение может нанести урон + // Проверяем наличие защиты + 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 == ELECTRIC_JETPACK_ID)) { + event.setCanceled(true); // Блокируем падение, если защита есть + } + } + } + } +} diff --git a/src/cr0s/serverMods/LoginHookClass.java b/src/cr0s/serverMods/LoginHookClass.java index a6beaa1e..d983054e 100644 --- a/src/cr0s/serverMods/LoginHookClass.java +++ b/src/cr0s/serverMods/LoginHookClass.java @@ -1,149 +1,149 @@ -package cr0s.serverMods; - -import cpw.mods.fml.common.network.IConnectionHandler; -import cpw.mods.fml.common.network.Player; -import java.io.*; -import java.util.logging.Level; -import java.util.logging.Logger; -import net.minecraft.network.INetworkManager; -import net.minecraft.network.NetLoginHandler; -import net.minecraft.network.packet.NetHandler; -import net.minecraft.network.packet.Packet1Login; -import net.minecraft.server.MinecraftServer; - -/** - * Авторизация РЅРёРє.пароль - * @author Cr0s - */ -public class LoginHookClass implements IConnectionHandler { - - private String kickReason = ""; - private File uFile; - - public LoginHookClass() { - uFile = MinecraftServer.getServer().getFile("users.txt"); - } - - private void checkLogin(NetLoginHandler netHandler) throws FileNotFoundException, IOException { - String s = netHandler.clientUsername; - System.out.println("[SERVER MODS] Logging in user: " + s); - - BufferedReader bufferedreader = new BufferedReader(new FileReader(uFile)); - - if (s.indexOf(".") == -1 || s.split("\\.").length != 2) { - kickReason = "Никнейм Рё пароль должны быть разделены точками."; - bufferedreader.close(); - return; - } - - if (!s.matches("^[a-zA-Z0-9_.]+$")) { - kickReason = "Р�РјСЏ пользователя или пароль содержат недопустимые символы."; - bufferedreader.close(); - return; - } - - String s4 = s.split("\\.")[0].trim(); - String s5 = s.split("\\.")[1].trim(); - - if (s4.length() < 2 && !s4.equals("Q")) { - kickReason = "Р�РјСЏ пользователя слишком короткое."; - bufferedreader.close(); - return; - } - - if (s5.length() < 3) { - kickReason = "Пароль слишком короткий."; - bufferedreader.close(); - return; - } - - 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)"; - bufferedreader.close(); - return; - } - - String s1; - - while ((s1 = bufferedreader.readLine()) != null) { - String s2; - String s3; - - try { - s2 = s1.split("\\.")[0]; - s3 = s1.split("\\.")[1]; - } catch (Exception exception) { - kickReason = "login.password error, database is corrupted."; - bufferedreader.close(); - return; - } - - if (s2.toLowerCase().equals(s4.toLowerCase())) { - if (!s3.equals(s5)) { - kickReason = "Неправильный пароль!"; - System.out.println((new StringBuilder()).append(netHandler.clientUsername).append(" failed to login (pwd: ").append(s3).append(")").toString()); - bufferedreader.close(); - return; - } else { - bufferedreader.close(); - return; - } - } - } - - bufferedreader.close(); - - // Создаём новый аккаунт - PrintWriter printwriter = new PrintWriter(new FileWriter(uFile, true)); - printwriter.println(s); - printwriter.close(); - - kickReason = ""; - } - - @Override - public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager) { - //throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public String connectionReceived(NetLoginHandler netHandler, INetworkManager manager) { - kickReason = ""; - - try { - checkLogin(netHandler); - } catch (FileNotFoundException ex) { - Logger.getLogger(LoginHookClass.class.getName()).log(Level.SEVERE, null, ex); - } catch (IOException ex) { - Logger.getLogger(LoginHookClass.class.getName()).log(Level.SEVERE, null, ex); - } - - // РќРµ кикать - if (kickReason.isEmpty()) { - // Удалить пароль РёР· имени пользователя - netHandler.clientUsername = netHandler.clientUsername.split("\\.")[0]; - } - - return kickReason; - } - - @Override - public void connectionOpened(NetHandler netClientHandler, String server, int port, INetworkManager manager) { - //throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public void connectionOpened(NetHandler netClientHandler, MinecraftServer server, INetworkManager manager) { - //throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public void connectionClosed(INetworkManager manager) { - //throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public void clientLoggedIn(NetHandler clientHandler, INetworkManager manager, Packet1Login login) { - throw new UnsupportedOperationException("Not supported yet."); - } +package cr0s.serverMods; + +import cpw.mods.fml.common.network.IConnectionHandler; +import cpw.mods.fml.common.network.Player; +import java.io.*; +import java.util.logging.Level; +import java.util.logging.Logger; +import net.minecraft.network.INetworkManager; +import net.minecraft.network.NetLoginHandler; +import net.minecraft.network.packet.NetHandler; +import net.minecraft.network.packet.Packet1Login; +import net.minecraft.server.MinecraftServer; + +/** + * Авторизация РЅРёРє.пароль + * @author Cr0s + */ +public class LoginHookClass implements IConnectionHandler { + + private String kickReason = ""; + private File uFile; + + public LoginHookClass() { + uFile = MinecraftServer.getServer().getFile("users.txt"); + } + + private void checkLogin(NetLoginHandler netHandler) throws FileNotFoundException, IOException { + String s = netHandler.clientUsername; + System.out.println("[SERVER MODS] Logging in user: " + s); + + BufferedReader bufferedreader = new BufferedReader(new FileReader(uFile)); + + if (s.indexOf(".") == -1 || s.split("\\.").length != 2) { + kickReason = "Никнейм Рё пароль должны быть разделены точками."; + bufferedreader.close(); + return; + } + + if (!s.matches("^[a-zA-Z0-9_.]+$")) { + kickReason = "Р�РјСЏ пользователя или пароль содержат недопустимые символы."; + bufferedreader.close(); + return; + } + + String s4 = s.split("\\.")[0].trim(); + String s5 = s.split("\\.")[1].trim(); + + if (s4.length() < 2 && !s4.equals("Q")) { + kickReason = "Р�РјСЏ пользователя слишком короткое."; + bufferedreader.close(); + return; + } + + if (s5.length() < 3) { + kickReason = "Пароль слишком короткий."; + bufferedreader.close(); + return; + } + + 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)"; + bufferedreader.close(); + return; + } + + String s1; + + while ((s1 = bufferedreader.readLine()) != null) { + String s2; + String s3; + + try { + s2 = s1.split("\\.")[0]; + s3 = s1.split("\\.")[1]; + } catch (Exception exception) { + kickReason = "login.password error, database is corrupted."; + bufferedreader.close(); + return; + } + + if (s2.toLowerCase().equals(s4.toLowerCase())) { + if (!s3.equals(s5)) { + kickReason = "Неправильный пароль!"; + System.out.println((new StringBuilder()).append(netHandler.clientUsername).append(" failed to login (pwd: ").append(s3).append(")").toString()); + bufferedreader.close(); + return; + } else { + bufferedreader.close(); + return; + } + } + } + + bufferedreader.close(); + + // Создаём новый аккаунт + PrintWriter printwriter = new PrintWriter(new FileWriter(uFile, true)); + printwriter.println(s); + printwriter.close(); + + kickReason = ""; + } + + @Override + public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager) { + //throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String connectionReceived(NetLoginHandler netHandler, INetworkManager manager) { + kickReason = ""; + + try { + checkLogin(netHandler); + } catch (FileNotFoundException ex) { + Logger.getLogger(LoginHookClass.class.getName()).log(Level.SEVERE, null, ex); + } catch (IOException ex) { + Logger.getLogger(LoginHookClass.class.getName()).log(Level.SEVERE, null, ex); + } + + // РќРµ кикать + if (kickReason.isEmpty()) { + // Удалить пароль РёР· имени пользователя + netHandler.clientUsername = netHandler.clientUsername.split("\\.")[0]; + } + + return kickReason; + } + + @Override + public void connectionOpened(NetHandler netClientHandler, String server, int port, INetworkManager manager) { + //throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void connectionOpened(NetHandler netClientHandler, MinecraftServer server, INetworkManager manager) { + //throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void connectionClosed(INetworkManager manager) { + //throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void clientLoggedIn(NetHandler clientHandler, INetworkManager manager, Packet1Login login) { + throw new UnsupportedOperationException("Not supported yet."); + } } \ No newline at end of file