Fixed issues with spying

This commit is contained in:
Lilac 2019-10-13 17:49:11 +01:00
parent 15bb7fc2e8
commit 83ec20e5ea
3 changed files with 42 additions and 7 deletions

View File

@ -102,7 +102,8 @@ public class UltimateModeration extends JavaPlugin {
Bukkit.getPluginManager().registerEvents(new ChatListener(this), this);
Bukkit.getPluginManager().registerEvents(new LoginListener(this), this);
Bukkit.getPluginManager().registerEvents(new MobTargetLister(), this);
Bukkit.getPluginManager().registerEvents(new SpyingDismountListener(), this);
if (isServerVersionAtLeast(ServerVersion.V1_13)) Bukkit.getPluginManager().registerEvents(new SpyingDismountListener(), this);
// Start tasks
SlowModeTask.startTask(this);

View File

@ -43,10 +43,12 @@ public class CommandSpy extends AbstractCommand {
if (!CommandVanish.isVanished(senderP)) {
CommandVanish.vanish(senderP);
senderP.setCanPickupItems(false);
didVanish = true;
}
spying.put(senderP.getUniqueId(), new Spy(senderP.getLocation(), didVanish));
senderP.teleport(player.getPlayer().getLocation());
spying.put(senderP.getUniqueId(), new Spy(senderP.getLocation(), didVanish));
player.getPlayer().addPassenger(senderP);
instance.getLocale().getMessage("command.spy.success")
@ -120,6 +122,10 @@ public class CommandSpy extends AbstractCommand {
return "Allows you to spy on a player.";
}
public static Map<UUID, Spy> getSpying() {
return spying;
}
public static class Spy {
private Location lastLocation;
private boolean vanishApplied;

View File

@ -1,20 +1,48 @@
package com.songoda.ultimatemoderation.listeners;
import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.command.commands.CommandSpy;
import com.songoda.ultimatemoderation.command.commands.CommandVanish;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.spigotmc.event.entity.EntityDismountEvent;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class SpyingDismountListener implements Listener {
private Map<UUID, GameMode> gamemodes = new HashMap<>();
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityDismountEvent(EntityDismountEvent e) {
if (!(e.getDismounted() instanceof Player)) return;
if (!(e.getEntity() instanceof Player)) return;
if (CommandSpy.isSpying((((Player) e.getEntity()).getPlayer()))) {
e.setCancelled(true);
public void onEntityDismountEvent(EntityDismountEvent event) {
if (!(event.getDismounted() instanceof Player)) return;
if (!(event.getEntity() instanceof Player)) return;
if (CommandSpy.isSpying((((Player) event.getEntity()).getPlayer()))) {
Player player = (Player) event.getEntity();
gamemodes.put(player.getUniqueId(), player.getGameMode());
player.setGameMode(GameMode.SPECTATOR);
Bukkit.getScheduler().scheduleSyncDelayedTask(UltimateModeration.getInstance(), () ->
player.setSpectatorTarget(event.getDismounted()), 5L);
}
}
@EventHandler
public void onSneak(PlayerToggleSneakEvent event) {
Player player = event.getPlayer();
if (player.isSneaking() || !CommandSpy.isSpying(player) || player.getGameMode() != GameMode.SPECTATOR) return;
CommandSpy.Spy spyingEntry = CommandSpy.getSpying().remove(player.getUniqueId());
player.teleport(spyingEntry.getLastLocation());
if (spyingEntry.isVanishApplied() && CommandVanish.isVanished(player))
CommandVanish.vanish(player);
player.setGameMode(gamemodes.get(player.getUniqueId()));
UltimateModeration.getInstance().getLocale().getMessage("command.spy.returned").sendPrefixedMessage(player);
}
}