From 8bd355ac259512dc13b4e7fc06df238c883e2b08 Mon Sep 17 00:00:00 2001 From: Pepich Date: Fri, 3 Feb 2017 21:17:42 +0100 Subject: [PATCH] Added pmtoggle module --- src/com/redstoner/misc/Main.java | 3 +- .../redstoner/modules/pmtoggle/Pmtoggle.java | 119 ++++++++++++++++++ 2 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 src/com/redstoner/modules/pmtoggle/Pmtoggle.java diff --git a/src/com/redstoner/misc/Main.java b/src/com/redstoner/misc/Main.java index 2db9013..6e4cc64 100644 --- a/src/com/redstoner/misc/Main.java +++ b/src/com/redstoner/misc/Main.java @@ -19,6 +19,7 @@ import com.redstoner.modules.loginsecurity.LoginSecurity; import com.redstoner.modules.mentio.Mentio; import com.redstoner.modules.motd.Motd; import com.redstoner.modules.nametags.NameTags; +import com.redstoner.modules.pmtoggle.Pmtoggle; import com.redstoner.modules.scriptutils.Scriptutils; import com.redstoner.modules.skullclick.SkullClick; import com.redstoner.modules.vanish.Vanish; @@ -58,7 +59,7 @@ public class Main extends JavaPlugin // TODO: ModuleLoader.addModule(Misc.class); ModuleLoader.addModule(Motd.class); ModuleLoader.addModule(NameTags.class); - // TODO: ModuleLoader.addModule(Pmtoggle.class); + ModuleLoader.addModule(Pmtoggle.class); // TODO: ModuleLoader.addModule(Reports.class); // TODO: ModuleLoader.addModule(Saylol.class); ModuleLoader.addModule(Scriptutils.class); diff --git a/src/com/redstoner/modules/pmtoggle/Pmtoggle.java b/src/com/redstoner/modules/pmtoggle/Pmtoggle.java new file mode 100644 index 0000000..7ae5585 --- /dev/null +++ b/src/com/redstoner/modules/pmtoggle/Pmtoggle.java @@ -0,0 +1,119 @@ +package com.redstoner.modules.pmtoggle; + +import java.util.HashMap; +import java.util.Map.Entry; + +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.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +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 Pmtoggle implements Module, Listener +{ + private boolean enabled; + HashMap toggles = new HashMap(); + + @Override + public void onEnable() + { + enabled = true; + } + + @Override + public void onDisable() + { + enabled = false; + } + + @Override + public boolean enabled() + { + return enabled; + } + + @Command(hook = "pmtoggle_off", async = AsyncType.ALWAYS) + public boolean pmtoggle_off(CommandSender sender) + { + Player player = (Player) sender; + if (toggles.remove(player) != null) + Utils.sendMessage(player, null, "Your pmtoggle was removed!"); + else + Utils.sendMessage(player, null, "You didn't have pmtoggle enabled! Use /pmtoggle to enabled it."); + return true; + } + + @Command(hook = "pmtoggle", async = AsyncType.ALWAYS) + public boolean pmtoggle(CommandSender sender, String player) + { + Player p = Bukkit.getPlayer(player); + if (p == null && !player.equals("CONSOLE")) + { + Utils.sendMessage(sender, null, "§cThat player couldn't be found!"); + return true; + } + toggles.put((Player) sender, player); + Utils.sendMessage(sender, null, "Locked your pmtoggle onto §6" + player + "§7."); + return true; + } + + @EventHandler + public void onPlayerChat(AsyncPlayerChatEvent event) + { + Player player = event.getPlayer(); + if (toggles.containsKey(player)) + { + Bukkit.dispatchCommand(player, "m " + toggles.get(player) + " " + event.getMessage()); + event.setCancelled(true); + } + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) + { + toggles.remove(event.getPlayer()); + String player = event.getPlayer().getName(); + if (toggles.containsValue(player)) + { + for (Entry entry : toggles.entrySet()) + { + if (entry.getValue().equals(player)) + { + toggles.remove(player); + Utils.sendMessage(entry.getKey(), null, + "We removed your pmtoggle for &6" + player + "&7, as he left the game.", '&'); + } + } + } + } + + // @noformat + @Override + public String getCommandString() + { + return "command pmtoggle {\n" + + " [empty] {\n" + + " help Turns off your toggle.;\n" + + " type player;\n" + + " run pmtoggle_off;\n" + + " }\n" + + " [string:player] {\n" + + " help Turns on your pmtoggle and locks onto .;\n" + + " type player;\n" + + " run pmtoggle player;\n" + + " }\n" + + "}"; + } + // @format +}