Bugfix: entering water no longer dismounts spying players
Created Listener for EntityDismountEvent and cancel it the player is spying on another player. This prevents the forced dismount when the spied-on player enters water.
This commit is contained in:
parent
c9fb8d7c8c
commit
42d6ac9406
|
@ -102,6 +102,7 @@ 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);
|
||||
|
||||
// Start tasks
|
||||
SlowModeTask.startTask(this);
|
||||
|
|
|
@ -51,6 +51,10 @@ public class CommandSpy extends AbstractCommand {
|
|||
|
||||
instance.getLocale().getMessage("command.spy.success")
|
||||
.processPlaceholder("player", player.getName()).sendPrefixedMessage(senderP);
|
||||
}
|
||||
|
||||
public static boolean isSpying(OfflinePlayer player) {
|
||||
return spying.containsKey(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -63,11 +67,11 @@ public class CommandSpy extends AbstractCommand {
|
|||
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))
|
||||
Spy spyingEntry = spying.remove(senderP.getUniqueId());
|
||||
senderP.teleport(spyingEntry.getLastLocation());
|
||||
if (spyingEntry.isVanishApplied() && CommandVanish.isVanished(senderP))
|
||||
CommandVanish.vanish(senderP);
|
||||
|
||||
spying.remove(senderP.getUniqueId());
|
||||
instance.getLocale().getMessage("command.spy.returned").sendPrefixedMessage(sender);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package com.songoda.ultimatemoderation.listeners;
|
||||
|
||||
import com.songoda.ultimatemoderation.command.commands.CommandSpy;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.spigotmc.event.entity.EntityDismountEvent;
|
||||
|
||||
public class SpyingDismountListener implements Listener {
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue