From ed55fadd9d9b4d68cd3a5f019d004048745d5bcc Mon Sep 17 00:00:00 2001 From: Brianna O'Keefe Date: Thu, 28 Feb 2019 16:57:39 -0500 Subject: [PATCH] Added support for spying. --- .../command/CommandManager.java | 2 + .../command/commands/CommandSpy.java | 103 ++++++++++++++++++ .../command/commands/CommandVanish.java | 48 ++++---- src/main/resources/en_US.lang | 9 +- src/main/resources/plugin.yml | 6 +- 5 files changed, 145 insertions(+), 23 deletions(-) create mode 100644 src/main/java/com/songoda/ultimatemoderation/command/commands/CommandSpy.java diff --git a/src/main/java/com/songoda/ultimatemoderation/command/CommandManager.java b/src/main/java/com/songoda/ultimatemoderation/command/CommandManager.java index 847e2bb..d509e94 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/CommandManager.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/CommandManager.java @@ -34,6 +34,7 @@ public class CommandManager implements CommandExecutor { instance.getCommand("InvSee").setExecutor(this); instance.getCommand("Freeze").setExecutor(this); instance.getCommand("Revive").setExecutor(this); + instance.getCommand("Spy").setExecutor(this); AbstractCommand commandUltimateModeration = addCommand(new CommandUltimateModeration()); addCommand(new CommandClearChat()); @@ -44,6 +45,7 @@ public class CommandManager implements CommandExecutor { addCommand(new CommandInvSee()); addCommand(new CommandFreeze()); addCommand(new CommandRevive()); + addCommand(new CommandSpy()); addCommand(new CommandSettings(commandUltimateModeration)); addCommand(new CommandReload(commandUltimateModeration)); diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandSpy.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandSpy.java new file mode 100644 index 0000000..a34cfe2 --- /dev/null +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandSpy.java @@ -0,0 +1,103 @@ +package com.songoda.ultimatemoderation.command.commands; + +import com.songoda.ultimatemoderation.UltimateModeration; +import com.songoda.ultimatemoderation.command.AbstractCommand; +import com.songoda.ultimatemoderation.listeners.DeathListener; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import java.util.*; + +public class CommandSpy extends AbstractCommand { + + private static Map spying = new HashMap<>(); + + public CommandSpy() { + super(true, true,"Spy"); + } + + @Override + protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { + if (args.length > 1) + return ReturnType.SYNTAX_ERROR; + + Player senderP = ((Player)sender); + + if (args.length == 0) { + if (!spying.containsKey(senderP.getUniqueId())) + return ReturnType.SYNTAX_ERROR; + senderP.teleport(spying.get(senderP.getUniqueId()).getLastLocation()); + if (spying.get(senderP.getUniqueId()).isVanishApplied() && CommandVanish.isVanished(senderP)) + CommandVanish.vanish(senderP); + + spying.remove(senderP.getUniqueId()); + senderP.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.spy.returned")); + return ReturnType.SUCCESS; + } + + Player player = Bukkit.getPlayer(args[0]); + + if (player == null) { + sender.sendMessage(instance.getReferences().getPrefix() + "That player does not exist or is not online."); + return ReturnType.FAILURE; + } + + if (player == senderP) { + sender.sendMessage(instance.getReferences().getPrefix() + "You cannot spy on yourself."); + return ReturnType.FAILURE; + } + + boolean didVanish = false; + if (!CommandVanish.isVanished(senderP)) { + didVanish = true; + CommandVanish.vanish(senderP); + } + + spying.put(senderP.getUniqueId(), new Spy(senderP.getLocation(), didVanish)); + player.addPassenger(senderP); + + senderP.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.spy.success", player.getName())); + return ReturnType.SUCCESS; + } + + @Override + protected List onTab(UltimateModeration instance, CommandSender sender, String... args) { + return null; + } + + @Override + public String getPermissionNode() { + return "um.spy"; + } + + @Override + public String getSyntax() { + return "/Spy [player]"; + } + + @Override + public String getDescription() { + return "Allows you to spy on a player."; + } + + public class Spy { + private Location lastLocation; + private boolean vanishApplied; + + public Spy(Location lastLocation, boolean vanishApplied) { + this.lastLocation = lastLocation; + this.vanishApplied = vanishApplied; + } + + public Location getLastLocation() { + return lastLocation; + } + + public boolean isVanishApplied() { + return vanishApplied; + } + } +} diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandVanish.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandVanish.java index edee7bb..d83d3e2 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandVanish.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandVanish.java @@ -28,15 +28,39 @@ public class CommandVanish extends AbstractCommand { @Override protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { Player player = ((Player)sender); + vanish(player); + return ReturnType.SUCCESS; + } + + @Override + protected List onTab(UltimateModeration instance, CommandSender sender, String... args) { + return null; + } + + public static void registerVanishedPlayers(Player player) { + for (UUID uuid : inVanish) { + Player vanished = Bukkit.getPlayer(uuid); + if (vanished == null) continue; + if(player.hasPermission("um.vanish.bypass")) { + player.showPlayer(vanished); + } else { + player.hidePlayer(vanished); + } + } + } + + public static void vanish(Player player) { UUID uuid = player.getUniqueId(); + + UltimateModeration instance = UltimateModeration.getInstance(); + if (inVanish.contains(uuid)) { inVanish.remove(uuid); - sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.vanish.toggledOff"))); + player.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.vanish.toggledOff"))); } else { inVanish.add(uuid); - sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.vanish.toggledOn"))); + player.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.vanish.toggledOn"))); } - if (SettingsManager.Setting.VANISH_EFFECTS.getBoolean()) { player.getWorld().playSound(player.getLocation(), Sound.valueOf(SettingsManager.Setting.VANISH_SOUND.getString()), 1L, 1L); @@ -64,24 +88,10 @@ public class CommandVanish extends AbstractCommand { else p.showPlayer(player); } - return ReturnType.SUCCESS; } - @Override - protected List onTab(UltimateModeration instance, CommandSender sender, String... args) { - return null; - } - - public static void registerVanishedPlayers(Player player) { - for (UUID uuid : inVanish) { - Player vanished = Bukkit.getPlayer(uuid); - if (vanished == null) continue; - if(player.hasPermission("um.vanish.bypass")) { - player.showPlayer(vanished); - } else { - player.hidePlayer(vanished); - } - } + public static boolean isVanished(Player player) { + return inVanish.contains(player.getUniqueId()); } @Override diff --git a/src/main/resources/en_US.lang b/src/main/resources/en_US.lang index 3ae6cbf..0583c71 100644 --- a/src/main/resources/en_US.lang +++ b/src/main/resources/en_US.lang @@ -10,8 +10,8 @@ command.togglechat.toggledOff = "&cChat was globally Muted..." command.togglechat.bypass = "&aYou were immune to the chat toggle because of your perms." command.togglechat.muted = "&cChat is currently disabled, try again later." -command.vanish.toggledOn = "&7You are now visible." -command.vanish.toggledOff = "&7You are now vanished." +command.vanish.toggledOn = "&7You are now vanished." +command.vanish.toggledOff = "&7You are now visible." command.freeze.add = "&7You have frozen &6%player%&7 successfully."; command.freeze.remove = "&7You have unfrozen &6%player%&7 successfully."; @@ -21,4 +21,7 @@ command.freeze.nope = "&cYou cannot do that because you are currently frozen..." command.revive.noloot = "&cNo loot could be found to revive the player with." command.revive.success = "&7You have revived &6%player% &7successfully." -command.revive.revived = "&7You have been revived." \ No newline at end of file +command.revive.revived = "&7You have been revived." + +command.spy.returned = "&7You were returned to your previous location" +command.spy.success = "&7You are now spying on &6%player%&7. Use the command &6/spy &7to return to your previous location&7" \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index a228288..fd8b38b 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -47,4 +47,8 @@ commands: Revive: description: Revive default: false - usage: /revive \ No newline at end of file + usage: /revive + Spy: + description: Spy + default: false + usage: /spy \ No newline at end of file