Stop teleport on inventory management

This commit is contained in:
Olof Larsson 2015-11-25 08:59:56 +01:00
parent 14ad78ef15
commit ab3eec7afe

View File

@ -4,11 +4,14 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@ -113,46 +116,56 @@ public class EngineMassiveCoreScheduledTeleport extends EngineAbstract
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void cancelTeleport(PlayerMoveEvent event) public void cancelTeleport(PlayerMoveEvent event)
{ {
// If the player moved from one block to another ...
if (MUtil.isSameBlock(event)) return; if (MUtil.isSameBlock(event)) return;
// ... cancel teleport! final Player player = event.getPlayer();
Player player = event.getPlayer();
this.cancelTeleport(player); this.cancelTeleport(player);
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void cancelTeleport(EntityDamageEvent event) public void cancelTeleport(EntityDamageEvent event)
{ {
// If an entity takes damage ... final Entity entity = event.getEntity();
Entity entity = event.getEntity();
// ... and that entity is a player ...
if (MUtil.isntPlayer(entity)) return; if (MUtil.isntPlayer(entity)) return;
Player player = (Player)entity; final Player player = (Player)entity;
// ... cancel teleport!
this.cancelTeleport(player); this.cancelTeleport(player);
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void cancelTeleport(PlayerDeathEvent event) public void cancelTeleport(PlayerDeathEvent event)
{ {
// If a player dies ... final Player player = event.getEntity();
Player player = event.getEntity();
// ... cancel teleport!
this.cancelTeleport(player); this.cancelTeleport(player);
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void cancelTeleport(EventMassiveCorePlayerLeave event) public void cancelTeleport(EventMassiveCorePlayerLeave event)
{ {
// If a player quits ...
if ( ! Mixin.isActualLeave(event)) return; if ( ! Mixin.isActualLeave(event)) return;
final Player player = event.getPlayer();
this.cancelTeleport(player);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void cancelTeleport(InventoryOpenEvent event)
{
final HumanEntity human = event.getPlayer();
if (MUtil.isntPlayer(human)) return;
final Player player = (Player)human;
this.cancelTeleport(player);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void cancelTeleport(InventoryClickEvent event)
{
final HumanEntity human = event.getWhoClicked();
if (MUtil.isntPlayer(human)) return;
final Player player = (Player)human;
// ... cancel teleport!
Player player = event.getPlayer();
this.cancelTeleport(player); this.cancelTeleport(player);
} }