diff --git a/vMinecraftCommands.java b/vMinecraftCommands.java index ea7bf0b3a..2269e7da9 100644 --- a/vMinecraftCommands.java +++ b/vMinecraftCommands.java @@ -4,6 +4,8 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.HashMap; +import java.util.List; //===================================================================== //Class: vMinecraftCommands @@ -11,6 +13,7 @@ import java.util.logging.Logger; //Author: nos, trapalice, cerevisiae //===================================================================== public class vMinecraftCommands{ +private static HashMap hidden = new HashMap(); //Log output protected static final Logger log = Logger.getLogger("Minecraft"); @@ -52,6 +55,8 @@ public class vMinecraftCommands{ cl.register("/who", "who"); cl.register("/promote", "promote", "Promote a player one rank"); cl.register("/demote", "demote", "Demote a player one rank"); + cl.register("/hide", "hide", "Turn invisible"); + cl.register("/silent", "silent", "Turn off global messages for yourself"); //Party cl.register("/party", "party"); @@ -183,6 +188,105 @@ public class vMinecraftCommands{ .globalmessages()); return EXIT_SUCCESS; } + public void onDisconnect(Player player){ + if(hidden.containsKey(player.getName())) + hidden.remove(player.getName()); + if(vMinecraftSettings.getInstance().isEzModo(player.getName())) + vMinecraftSettings.getInstance().removeEzModo(player.getName()); + } + + public void run() + { + for (Player InvisiblePlayer : hidden.values()) + { + for (Player p : etc.getServer().getPlayerList()) + { + if (vMinecraftParty.getDistance(InvisiblePlayer, p) <= vMinecraftSettings.range && p.getUser() != InvisiblePlayer.getUser()) + { + p.getUser().a.b(new dv(InvisiblePlayer.getUser().g)); + } + } + } + } + public static int hide(Player player, String[] args){ + if (player.canUseCommand("/hide")){ + if(hidden.get(player.getName()) != null) { + hidden.remove(player.getName()); + player.sendMessage(Colors.DarkPurple + "You are no longer invisible"); + hidden.remove(player.getName()); + updateInvisibleForAll(); + List playerList = etc.getServer().getPlayerList(); + for (Player p : playerList) + { + if (vMinecraftParty.getDistance(player, p) < vMinecraftSettings.range && p.getUser() != player.getUser()) + { + p.getUser().a.b(new d(player.getUser())); + } + } + log.log(Level.INFO, "{0} reappeared.", player.getName()); + player.sendMessage(Colors.Rose + "You have reappeared!"); + return EXIT_SUCCESS; + } + hidden.put(player.getName(), player); + player.sendMessage(Colors.DarkPurple + "You are now invisible"); + for (Player p : etc.getServer().getPlayerList()) + { + if (vMinecraftParty.getDistance(player, p) <= vMinecraftSettings.range && p.getUser() != player.getUser()) + { + p.getUser().a.b(new dv(player.getUser().g)); + } + } + return EXIT_SUCCESS; + } + return EXIT_FAIL; + } + public void reappear(Player player) +{ +if (hidden.get(player.getName()) != null) +{ +hidden.remove(player.getName()); +// make someone really disappear if there's any doubt, should remove +// cloning +updateInvisibleForAll(); +List playerList = etc.getServer().getPlayerList(); +for (Player p : playerList) +{ +if (vMinecraftParty.getDistance(player, p) < vMinecraftSettings.range && p.getUser() != player.getUser()) +{ +// new d (player.getUser() ) +// new Packet20NamedEntitySpawn player EntityPlayerMP ) +p.getUser().a.b(new d(player.getUser())); +} +} +log.log( Level.INFO, "{0} reappeared.", player.getName()); +player.sendMessage(Colors.Rose + "You have reappeared!"); +} +} + public void reappearAll() + { + log.info("Everyone is going reappear."); + for (Player InvisiblePlayer : hidden.values()) + { + reappear(InvisiblePlayer); + } + hidden.clear(); + } + + public static void updateInvisibleForAll() + { + List playerList = etc.getServer().getPlayerList(); + for (Player InvisiblePlayer : hidden.values()) + { + for (Player p : playerList) + { + if (vMinecraftParty.getDistance(InvisiblePlayer, p) <= vMinecraftSettings.range && p.getUser() != InvisiblePlayer.getUser()) + { + p.getUser().a.b(new dv(InvisiblePlayer.getUser().g)); + // players.add(p); + } + } + } + } public static int partychat(Player player, String[] args){ if (args.length < 1) { player.sendMessage(Colors.Rose + "Usage is /p [Message]"); diff --git a/vMinecraftParty.java b/vMinecraftParty.java index cd0ab3367..902f610db 100644 --- a/vMinecraftParty.java +++ b/vMinecraftParty.java @@ -9,4 +9,9 @@ public class vMinecraftParty { return false; } } + public static double getDistance(Player player1, Player player2) + { + return Math.sqrt(Math.pow(player1.getX() - player2.getX(), 2) + Math.pow(player1.getY() - player2.getY(), 2) + + Math.pow(player1.getZ() - player2.getZ(), 2)); + } } diff --git a/vMinecraftSettings.java b/vMinecraftSettings.java index fd4a54f02..48f558f86 100644 --- a/vMinecraftSettings.java +++ b/vMinecraftSettings.java @@ -12,6 +12,7 @@ public class vMinecraftSettings { //private final static Object syncLock = new Object(); protected static final Logger log = Logger.getLogger("Minecraft"); private static volatile vMinecraftSettings instance; + static int range; //The feature settings @@ -139,6 +140,7 @@ public class vMinecraftSettings { writer.write("rules=Rules@#1: No griefing@#2: No griefing\r\n"); writer.write("#The Random Death messages, seperate them by comma. All death messages start with the player name and a space.\r\n"); writer.write("deathMessages=is no more,died horribly,went peacefully\r\n"); + writer.write("hiddendistance=1024"); } catch (Exception e) { log.log(Level.SEVERE, "Exception while creating " + location, e); } finally { @@ -203,6 +205,7 @@ public class vMinecraftSettings { ezModo = new ArrayList(); ezModo.addAll(Arrays.asList(tempEz)); ranks = properties.getString("ranks").split(","); + range = properties.getInt("hiddendistance",1024); log.log(Level.INFO, "vminecraft plugin successfully loaded"); } catch (Exception e)