Added support for spying.
This commit is contained in:
parent
5c5a0d40b8
commit
ed55fadd9d
|
@ -34,6 +34,7 @@ public class CommandManager implements CommandExecutor {
|
||||||
instance.getCommand("InvSee").setExecutor(this);
|
instance.getCommand("InvSee").setExecutor(this);
|
||||||
instance.getCommand("Freeze").setExecutor(this);
|
instance.getCommand("Freeze").setExecutor(this);
|
||||||
instance.getCommand("Revive").setExecutor(this);
|
instance.getCommand("Revive").setExecutor(this);
|
||||||
|
instance.getCommand("Spy").setExecutor(this);
|
||||||
|
|
||||||
AbstractCommand commandUltimateModeration = addCommand(new CommandUltimateModeration());
|
AbstractCommand commandUltimateModeration = addCommand(new CommandUltimateModeration());
|
||||||
addCommand(new CommandClearChat());
|
addCommand(new CommandClearChat());
|
||||||
|
@ -44,6 +45,7 @@ public class CommandManager implements CommandExecutor {
|
||||||
addCommand(new CommandInvSee());
|
addCommand(new CommandInvSee());
|
||||||
addCommand(new CommandFreeze());
|
addCommand(new CommandFreeze());
|
||||||
addCommand(new CommandRevive());
|
addCommand(new CommandRevive());
|
||||||
|
addCommand(new CommandSpy());
|
||||||
|
|
||||||
addCommand(new CommandSettings(commandUltimateModeration));
|
addCommand(new CommandSettings(commandUltimateModeration));
|
||||||
addCommand(new CommandReload(commandUltimateModeration));
|
addCommand(new CommandReload(commandUltimateModeration));
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,15 +28,39 @@ public class CommandVanish extends AbstractCommand {
|
||||||
@Override
|
@Override
|
||||||
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) {
|
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) {
|
||||||
Player player = ((Player)sender);
|
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();
|
UUID uuid = player.getUniqueId();
|
||||||
|
|
||||||
|
UltimateModeration instance = UltimateModeration.getInstance();
|
||||||
|
|
||||||
if (inVanish.contains(uuid)) {
|
if (inVanish.contains(uuid)) {
|
||||||
inVanish.remove(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 {
|
} else {
|
||||||
inVanish.add(uuid);
|
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()) {
|
if (SettingsManager.Setting.VANISH_EFFECTS.getBoolean()) {
|
||||||
player.getWorld().playSound(player.getLocation(), Sound.valueOf(SettingsManager.Setting.VANISH_SOUND.getString()), 1L, 1L);
|
player.getWorld().playSound(player.getLocation(), Sound.valueOf(SettingsManager.Setting.VANISH_SOUND.getString()), 1L, 1L);
|
||||||
|
|
||||||
|
@ -64,24 +88,10 @@ public class CommandVanish extends AbstractCommand {
|
||||||
else
|
else
|
||||||
p.showPlayer(player);
|
p.showPlayer(player);
|
||||||
}
|
}
|
||||||
return ReturnType.SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static boolean isVanished(Player player) {
|
||||||
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) {
|
return inVanish.contains(player.getUniqueId());
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -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.bypass = "&aYou were immune to the chat toggle because of your perms."
|
||||||
command.togglechat.muted = "&cChat is currently disabled, try again later."
|
command.togglechat.muted = "&cChat is currently disabled, try again later."
|
||||||
|
|
||||||
command.vanish.toggledOn = "&7You are now visible."
|
command.vanish.toggledOn = "&7You are now vanished."
|
||||||
command.vanish.toggledOff = "&7You are now vanished."
|
command.vanish.toggledOff = "&7You are now visible."
|
||||||
|
|
||||||
command.freeze.add = "&7You have frozen &6%player%&7 successfully.";
|
command.freeze.add = "&7You have frozen &6%player%&7 successfully.";
|
||||||
command.freeze.remove = "&7You have unfrozen &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.noloot = "&cNo loot could be found to revive the player with."
|
||||||
command.revive.success = "&7You have revived &6%player% &7successfully."
|
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"
|
|
@ -47,4 +47,8 @@ commands:
|
||||||
Revive:
|
Revive:
|
||||||
description: Revive
|
description: Revive
|
||||||
default: false
|
default: false
|
||||||
usage: /revive
|
usage: /revive
|
||||||
|
Spy:
|
||||||
|
description: Spy
|
||||||
|
default: false
|
||||||
|
usage: /spy
|
Loading…
Reference in New Issue