diff --git a/src/com/redstoner/misc/Main.java b/src/com/redstoner/misc/Main.java index 68936f6..faef2ce 100644 --- a/src/com/redstoner/misc/Main.java +++ b/src/com/redstoner/misc/Main.java @@ -15,16 +15,18 @@ import com.redstoner.modules.damnspam.DamnSpam; import com.redstoner.modules.imout.Imout; import com.redstoner.modules.lagchunks.LagChunks; import com.redstoner.modules.loginsecurity.LoginSecurity; +import com.redstoner.modules.mentio.Mentio; import com.redstoner.modules.motd.Motd; import com.redstoner.modules.scriptutils.Scriptutils; import com.redstoner.modules.skullclick.SkullClick; +import com.redstoner.modules.vanish.Vanish; import com.redstoner.modules.warn.Warn; import com.redstoner.modules.webtoken.WebToken; /** Main class. Duh. * * @author Pepich */ -@Version(major = 1, minor = 3, revision = 3, compatible = -1) +@Version(major = 1, minor = 3, revision = 4, compatible = -1) public class Main extends JavaPlugin { public static JavaPlugin plugin; @@ -48,7 +50,7 @@ public class Main extends JavaPlugin ModuleLoader.addModule(Imout.class); ModuleLoader.addModule(LagChunks.class); ModuleLoader.addModule(LoginSecurity.class); - // TODO: ModuleLoader.addModule(Mentio.class); + ModuleLoader.addModule(Mentio.class); // TODO: ModuleLoader.addModule(Misc.class); ModuleLoader.addModule(Motd.class); // TODO: ModuleLoader.addModule(Nametags.class); @@ -60,7 +62,7 @@ public class Main extends JavaPlugin // TODO: ModuleLoader.addModule(Signalstrength.class); ModuleLoader.addModule(SkullClick.class); // TODO: ModuleLoader.addModule(Tag.class); - // TODO: ModuleLoader.addModule(Vanish.class); + ModuleLoader.addModule(Vanish.class); ModuleLoader.addModule(Warn.class); ModuleLoader.addModule(WebToken.class); // And enable them diff --git a/src/com/redstoner/modules/vanish/Vanish.java b/src/com/redstoner/modules/vanish/Vanish.java new file mode 100644 index 0000000..56bc937 --- /dev/null +++ b/src/com/redstoner/modules/vanish/Vanish.java @@ -0,0 +1,248 @@ +package com.redstoner.modules.vanish; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map.Entry; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +import com.nemez.cmdmgr.Command; +import com.nemez.cmdmgr.Command.AsyncType; +import com.redstoner.annotations.AutoRegisterListener; +import com.redstoner.annotations.Version; +import com.redstoner.misc.Utils; +import com.redstoner.modules.Module; + +@AutoRegisterListener +@Version(major = 1, minor = 0, revision = 0, compatible = 1) +public class Vanish implements Module, Listener +{ + private boolean enabled = false; + private ArrayList vanished = new ArrayList(); + private HashMap> vanishOthers = new HashMap>(); + + @Command(hook = "vanish", async = AsyncType.ALWAYS) + public boolean vanish(CommandSender sender) + { + UUID uid = ((Player) sender).getUniqueId(); + if (vanished.contains(uid)) + { + vanished.remove(uid); + Utils.sendMessage(sender, null, "You are no longer vanished!"); + unvanishPlayer((Player) sender); + } + else + { + vanished.add(uid); + Utils.sendMessage(sender, null, "You are now vanished!"); + vanishPlayer((Player) sender); + } + return true; + } + + @Command(hook = "vanish_on", async = AsyncType.ALWAYS) + public boolean vanishOn(CommandSender sender) + { + UUID uid = ((Player) sender).getUniqueId(); + if (vanished.contains(uid)) + Utils.sendMessage(sender, null, + "You were already vanished, however we refreshed the vanish for you just to be sure!"); + else + { + vanished.add(uid); + Utils.sendMessage(sender, null, "You are now vanished!"); + } + vanishPlayer((Player) sender); + return true; + } + + @Command(hook = "vanish_off", async = AsyncType.ALWAYS) + public boolean vanishOff(CommandSender sender) + { + UUID uid = ((Player) sender).getUniqueId(); + if (!vanished.contains(uid)) + Utils.sendMessage(sender, null, + "You were not vanished, however we refreshed the vanish for you just to be sure!"); + else + { + vanished.remove(uid); + Utils.sendMessage(sender, null, "You are no longer vanished!"); + } + unvanishPlayer((Player) sender); + return true; + } + + @Command(hook = "vanish_other", async = AsyncType.ALWAYS) + public boolean vanishOther(CommandSender sender, String name) + { + Player player = Bukkit.getPlayer(name); + if (player == null) + { + Utils.sendMessage(sender, null, "&cPlayer &6" + name + " &ccould not be found!", '&'); + return true; + } + UUID uid = player.getUniqueId(); + if (player.hasPermission("utils.vanish")) + { + if (vanished.contains(uid)) + { + vanished.remove(uid); + Utils.sendMessage(sender, null, "Successfully unvanished player &6" + name, '&'); + Utils.sendMessage(player, null, "You are no longer vanished!"); + } + else + { + vanished.add(uid); + Utils.sendMessage(sender, null, "Successfully vanished player &6" + name, '&'); + Utils.sendMessage(player, null, "You are now vanished!"); + } + return true; + } + for (Entry> entry : vanishOthers.entrySet()) + { + if (entry.getValue().contains(uid)) + { + entry.getValue().remove(uid); + Utils.sendMessage(sender, null, "Successfully unvanished player &6" + name, '&'); + Utils.sendMessage(player, null, "You are no longer vanished!"); + if (entry.getValue().size() == 0) + vanishOthers.remove(entry.getKey()); + return true; + } + } + UUID uuid = ((Player) sender).getUniqueId(); + ArrayList toAddTo = vanishOthers.get(uuid); + if (toAddTo == null) + toAddTo = new ArrayList(); + toAddTo.add(uid); + vanishOthers.put(uuid, toAddTo); + Utils.sendMessage(sender, null, "Successfully vanished player &6" + name, '&'); + Utils.sendMessage(player, null, "You are now vanished!"); + return true; + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + Player player = event.getPlayer(); + if (player.hasPermission("utils.vanish")) + return; + for (UUID uid : vanished) + { + Player p = Bukkit.getPlayer(uid); + if (p == null) + continue; + player.hidePlayer(p); + } + for (Entry> entry : vanishOthers.entrySet()) + { + for (UUID uid : entry.getValue()) + { + Player p = Bukkit.getPlayer(uid); + if (p == null) + continue; + player.hidePlayer(p); + } + } + } + + @EventHandler + public void onPlayerLeave(PlayerJoinEvent event) + { + Player player = event.getPlayer(); + UUID uid = player.getUniqueId(); + if (vanishOthers.containsKey(uid)) + { + ArrayList toUnvanish = vanishOthers.remove(uid); + for (UUID uuid : toUnvanish) + { + Player p = Bukkit.getPlayer(uuid); + if (p != null) + unvanishPlayer(p); + } + } + boolean wasVanished = false; + for (Entry> entry : vanishOthers.entrySet()) + { + if (entry.getValue().contains(uid)) + { + entry.getValue().remove(uid); + wasVanished = true; + break; + } + } + if (wasVanished) + unvanishPlayer(player); + } + + private void vanishPlayer(Player player) + { + for (Player p : Bukkit.getOnlinePlayers()) + { + if (!p.hasPermission("utils.vanish")) + p.hidePlayer(player); + } + } + + private void unvanishPlayer(Player player) + { + for (Player p : Bukkit.getOnlinePlayers()) + p.showPlayer(p); + } + + @Override + public void onEnable() + { + enabled = true; + } + + @Override + public void onDisable() + { + enabled = false; + } + + @Override + public boolean enabled() + { + return enabled; + } + + // @noformat + @Override + public String getCommandString() + { + return "command vanish {\n" + + " [empty] {\n" + + " help Toggles your vanish status.;\n" + + " type player;\n" + + " run vanish;\n" + + " perm utils.vanish;\n" + + " }\n" + + " on {\n" + + " help Turns your vanish on.;\n" + + " type player;\n" + + " run vanish_on;\n" + + " perm utils.vanish;\n" + + " }\n" + + " off {\n" + + " help Turns your vanish off.;\n" + + " type player;\n" + + " run vanish_off;\n" + + " perm utils.vanish;\n" + + " }\n" + + " [string:name] {\n" + + " help Toggles someone elses vanish;\n" + + " run vanish_other name;\n" + + " perm utils.vanish;\n" + + " }\n" + + "}"; + } + // @format +}