Added invisibility, still need to fix up the code and add a few things. Wouldn't have been possible without the Vanish plugin authors permission to use his code. Double thanks!

This commit is contained in:
nossr50 2011-01-04 13:06:02 -08:00
parent e192fd366e
commit f5d220e7a3
3 changed files with 112 additions and 0 deletions

View File

@ -4,6 +4,8 @@ import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.HashMap;
import java.util.List;
//===================================================================== //=====================================================================
//Class: vMinecraftCommands //Class: vMinecraftCommands
@ -11,6 +13,7 @@ import java.util.logging.Logger;
//Author: nos, trapalice, cerevisiae //Author: nos, trapalice, cerevisiae
//===================================================================== //=====================================================================
public class vMinecraftCommands{ public class vMinecraftCommands{
private static HashMap<String, Player> hidden = new HashMap<String, Player>();
//Log output //Log output
protected static final Logger log = Logger.getLogger("Minecraft"); protected static final Logger log = Logger.getLogger("Minecraft");
@ -52,6 +55,8 @@ public class vMinecraftCommands{
cl.register("/who", "who"); cl.register("/who", "who");
cl.register("/promote", "promote", "Promote a player one rank"); cl.register("/promote", "promote", "Promote a player one rank");
cl.register("/demote", "demote", "Demote 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 //Party
cl.register("/party", "party"); cl.register("/party", "party");
@ -183,6 +188,105 @@ public class vMinecraftCommands{
.globalmessages()); .globalmessages());
return EXIT_SUCCESS; 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<Player> 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<Player> 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<Player> 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){ public static int partychat(Player player, String[] args){
if (args.length < 1) { if (args.length < 1) {
player.sendMessage(Colors.Rose + "Usage is /p [Message]"); player.sendMessage(Colors.Rose + "Usage is /p [Message]");

View File

@ -9,4 +9,9 @@ public class vMinecraftParty {
return false; 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));
}
} }

View File

@ -12,6 +12,7 @@ public class vMinecraftSettings {
//private final static Object syncLock = new Object(); //private final static Object syncLock = new Object();
protected static final Logger log = Logger.getLogger("Minecraft"); protected static final Logger log = Logger.getLogger("Minecraft");
private static volatile vMinecraftSettings instance; private static volatile vMinecraftSettings instance;
static int range;
//The feature settings //The feature settings
@ -139,6 +140,7 @@ public class vMinecraftSettings {
writer.write("rules=Rules@#1: No griefing@#2: No griefing\r\n"); 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("#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("deathMessages=is no more,died horribly,went peacefully\r\n");
writer.write("hiddendistance=1024");
} catch (Exception e) { } catch (Exception e) {
log.log(Level.SEVERE, "Exception while creating " + location, e); log.log(Level.SEVERE, "Exception while creating " + location, e);
} finally { } finally {
@ -203,6 +205,7 @@ public class vMinecraftSettings {
ezModo = new ArrayList<String>(); ezModo = new ArrayList<String>();
ezModo.addAll(Arrays.asList(tempEz)); ezModo.addAll(Arrays.asList(tempEz));
ranks = properties.getString("ranks").split(","); ranks = properties.getString("ranks").split(",");
range = properties.getInt("hiddendistance",1024);
log.log(Level.INFO, "vminecraft plugin successfully loaded"); log.log(Level.INFO, "vminecraft plugin successfully loaded");
} }
catch (Exception e) catch (Exception e)