Fix for spy issues.

This commit is contained in:
Brianna 2020-04-14 16:31:52 -04:00
parent 2f32e940e2
commit 5c183748f7
2 changed files with 24 additions and 10 deletions

View File

@ -3,7 +3,9 @@ package com.songoda.ultimatemoderation.commands;
import com.songoda.core.commands.AbstractCommand;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.listeners.SpyingDismountListener;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
@ -25,11 +27,22 @@ public class CommandSpy extends AbstractCommand {
public static void spy(OfflinePlayer oPlayer, Player senderP) {
UltimateModeration instance = UltimateModeration.getInstance();
if (isSpying(senderP) && oPlayer == null) {
CommandSpy.Spy spyingEntry = CommandSpy.getSpying().remove(senderP.getUniqueId());
senderP.teleport(spyingEntry.getLastLocation());
if (spyingEntry.isVanishApplied() && CommandVanish.isVanished(senderP))
CommandVanish.vanish(senderP);
senderP.setGameMode(SpyingDismountListener.getGamemodes().get(senderP.getUniqueId()));
UltimateModeration.getInstance().getLocale().getMessage("command.spy.returned").sendPrefixedMessage(senderP);
}
if (!ServerVersion.isServerVersionAtLeast(ServerVersion.V1_12)) {
instance.getLocale().newMessage("This feature is not compatible with this version of spigot.").sendPrefixedMessage(senderP);
return;
}
if (oPlayer == null) return;
Player player = oPlayer.getPlayer();
if (player == null) {

View File

@ -2,7 +2,6 @@ package com.songoda.ultimatemoderation.listeners;
import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.commands.CommandSpy;
import com.songoda.ultimatemoderation.commands.CommandVanish;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
@ -12,13 +11,14 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.spigotmc.event.entity.EntityDismountEvent;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class SpyingDismountListener implements Listener {
private Map<UUID, GameMode> gamemodes = new HashMap<>();
private static Map<UUID, GameMode> gamemodes = new HashMap<>();
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityDismountEvent(EntityDismountEvent event) {
@ -28,8 +28,11 @@ public class SpyingDismountListener implements Listener {
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);
Bukkit.getScheduler().scheduleSyncDelayedTask(UltimateModeration.getInstance(), () -> {
if (player.getGameMode() == GameMode.SPECTATOR)
player.setSpectatorTarget(event.getDismounted());
}, 5L);
}
}
@ -37,12 +40,10 @@ public class SpyingDismountListener implements Listener {
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()));
CommandSpy.spy(null, player);
}
UltimateModeration.getInstance().getLocale().getMessage("command.spy.returned").sendPrefixedMessage(player);
public static Map<UUID, GameMode> getGamemodes() {
return Collections.unmodifiableMap(gamemodes);
}
}