Added support for spying.

This commit is contained in:
Brianna O'Keefe 2019-02-28 16:57:39 -05:00
parent 5c5a0d40b8
commit ed55fadd9d
5 changed files with 145 additions and 23 deletions

View File

@ -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));

View File

@ -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<UUID, Spy> 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<String> 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;
}
}
}

View File

@ -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<String> 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<String> 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

View File

@ -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."
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"

View File

@ -47,4 +47,8 @@ commands:
Revive:
description: Revive
default: false
usage: /revive
usage: /revive
Spy:
description: Spy
default: false
usage: /spy