Minor changes to teleport mixin

This commit is contained in:
Olof Larsson 2013-03-20 14:43:33 +01:00
parent 2ff98d2ddb
commit ea17db7298
7 changed files with 109 additions and 23 deletions

View File

@ -17,6 +17,7 @@ import com.massivecraft.mcore.cmd.CmdMcore;
import com.massivecraft.mcore.integration.protocollib.ProtocolLibFeatures; import com.massivecraft.mcore.integration.protocollib.ProtocolLibFeatures;
import com.massivecraft.mcore.mixin.ScheduledTeleportEngine; import com.massivecraft.mcore.mixin.ScheduledTeleportEngine;
import com.massivecraft.mcore.mixin.SenderIdMixinDefault; import com.massivecraft.mcore.mixin.SenderIdMixinDefault;
import com.massivecraft.mcore.mixin.TeleportMixinCauseEngine;
import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.ps.PS;
import com.massivecraft.mcore.ps.PSAdapter; import com.massivecraft.mcore.ps.PSAdapter;
import com.massivecraft.mcore.store.Coll; import com.massivecraft.mcore.store.Coll;
@ -118,6 +119,7 @@ public class MCore extends MPlugin
InternalListener.get().setup(); InternalListener.get().setup();
ScheduledTeleportEngine.get().setup(); ScheduledTeleportEngine.get().setup();
FirstTeleportUtil.get().setup(); FirstTeleportUtil.get().setup();
TeleportMixinCauseEngine.get().setup();
// Schedule the collection ticker. // Schedule the collection ticker.
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this.collTickTask, 1, 1); Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this.collTickTask, 1, 1);

View File

@ -8,6 +8,7 @@ import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.permissions.Permissible; import org.bukkit.permissions.Permissible;
import com.massivecraft.mcore.Predictate; import com.massivecraft.mcore.Predictate;
@ -290,6 +291,11 @@ public class Mixin
// STATIC EXPOSE: TELEPORTER // STATIC EXPOSE: TELEPORTER
// -------------------------------------------- // // -------------------------------------------- //
public static boolean isCausedByMixin(PlayerTeleportEvent event)
{
return getTeleportMixin().isCausedByMixin(event);
}
public static void teleport(Player teleportee, PS destinationPs) throws TeleporterException public static void teleport(Player teleportee, PS destinationPs) throws TeleporterException
{ {
getTeleportMixin().teleport(teleportee, destinationPs); getTeleportMixin().teleport(teleportee, destinationPs);

View File

@ -1,12 +1,19 @@
package com.massivecraft.mcore.mixin; package com.massivecraft.mcore.mixin;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.permissions.Permissible; import org.bukkit.permissions.Permissible;
import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.ps.PS;
public interface TeleportMixin public interface TeleportMixin
{ {
// -------------------------------------------- //
// CHECK
// -------------------------------------------- //
public boolean isCausedByMixin(PlayerTeleportEvent event);
// -------------------------------------------- // // -------------------------------------------- //
// PLAYER // PLAYER
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -1,6 +1,7 @@
package com.massivecraft.mcore.mixin; package com.massivecraft.mcore.mixin;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.permissions.Permissible; import org.bukkit.permissions.Permissible;
import com.massivecraft.mcore.Conf; import com.massivecraft.mcore.Conf;
@ -13,6 +14,12 @@ public abstract class TeleportMixinAbstract implements TeleportMixin
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override
public boolean isCausedByMixin(PlayerTeleportEvent event)
{
return TeleportMixinCauseEngine.get().isCausedByTeleportMixin(event);
}
@Override @Override
public void teleport(Player teleportee, PS destinationPs) throws TeleporterException public void teleport(Player teleportee, PS destinationPs) throws TeleporterException
{ {
@ -68,21 +75,4 @@ public abstract class TeleportMixinAbstract implements TeleportMixin
return Conf.getTpdelay(delayPermissible); return Conf.getTpdelay(delayPermissible);
} }
/*
public static void otherPermCheck(String teleporteeId, CommandSender otherSender, String otherPerm) throws TeleporterException
{
String otherSenderId = SenderUtil.getSenderId(otherSender);
if (otherSenderId.equalsIgnoreCase(teleporteeId)) return;
if (PermUtil.has(otherSender, otherPerm, false)) return;
throw new TeleporterException(PermUtil.getForbiddenMessage(otherPerm));
}
public static void validateTeleporteeId(String teleporteeId) throws TeleporterException
{
if (!SenderUtil.isPlayerId(teleporteeId)) throw new TeleporterException(Txt.parse("<white>%s <b>is not a player.", Mixin.getDisplayName(teleporteeId)));
if (Mixin.isOffline(teleporteeId)) throw new TeleporterException(Txt.parse("<white>%s <b>is offline.", Mixin.getDisplayName(teleporteeId)));
}*/
} }

View File

@ -0,0 +1,73 @@
package com.massivecraft.mcore.mixin;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerTeleportEvent;
import com.massivecraft.mcore.MCore;
public class TeleportMixinCauseEngine implements Listener
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static TeleportMixinCauseEngine i = new TeleportMixinCauseEngine();
public static TeleportMixinCauseEngine get() { return i; }
public TeleportMixinCauseEngine() {}
// -------------------------------------------- //
// SETUP
// -------------------------------------------- //
public void setup()
{
Bukkit.getPluginManager().registerEvents(this, MCore.get());
}
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private boolean mixinCausedTeleportIncoming = false;
public boolean isMixinCausedTeleportIncoming() { return this.mixinCausedTeleportIncoming; }
public void setMixinCausedTeleportIncoming(boolean mixinCausedTeleportIncoming) { this.mixinCausedTeleportIncoming = mixinCausedTeleportIncoming; }
private Set<PlayerTeleportEvent> mixinCausedTeleportEvents = Collections.newSetFromMap(new ConcurrentHashMap<PlayerTeleportEvent, Boolean>());
// -------------------------------------------- //
// TO BE USED
// -------------------------------------------- //
public boolean isCausedByTeleportMixin(PlayerTeleportEvent event)
{
return this.mixinCausedTeleportEvents.contains(event);
}
// -------------------------------------------- //
// LISTENER
// -------------------------------------------- //
@EventHandler(priority = EventPriority.LOWEST)
public void markEvent(final PlayerTeleportEvent event)
{
if (!mixinCausedTeleportIncoming) return;
mixinCausedTeleportIncoming = false;
mixinCausedTeleportEvents.add(event);
Bukkit.getScheduler().scheduleSyncDelayedTask(MCore.get(), new Runnable()
{
@Override
public void run()
{
mixinCausedTeleportEvents.remove(event);
}
});
}
}

View File

@ -1,7 +1,6 @@
package com.massivecraft.mcore.mixin; package com.massivecraft.mcore.mixin;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
@ -23,11 +22,11 @@ public class TeleportMixinDefault extends TeleportMixinAbstract
// CORE LOGIC // CORE LOGIC
// -------------------------------------------- // // -------------------------------------------- //
public static void teleportEntity(Entity entity, PS ps) throws TeleporterException public static void teleportPlayer(Player player, PS ps) throws TeleporterException
{ {
// Base the PS location on the entity location // Base the PS location on the entity location
ps = ps.getEntity(true); ps = ps.getEntity(true);
ps = PS.valueOf(entity.getLocation()).with(ps); ps = PS.valueOf(player.getLocation()).with(ps);
// Bukkit Location // Bukkit Location
Location location = null; Location location = null;
@ -40,7 +39,10 @@ public class TeleportMixinDefault extends TeleportMixinAbstract
{ {
throw new TeleporterException(Txt.parse("<b>Could not calculate the location: %s", e.getMessage())); throw new TeleporterException(Txt.parse("<b>Could not calculate the location: %s", e.getMessage()));
} }
entity.teleport(location);
TeleportMixinCauseEngine.get().setMixinCausedTeleportIncoming(true);
player.teleport(location);
TeleportMixinCauseEngine.get().setMixinCausedTeleportIncoming(false);
// Bukkit velocity // Bukkit velocity
Vector velocity = null; Vector velocity = null;
@ -52,7 +54,7 @@ public class TeleportMixinDefault extends TeleportMixinAbstract
{ {
return; return;
} }
entity.setVelocity(velocity); player.setVelocity(velocity);
} }
// -------------------------------------------- // // -------------------------------------------- //
@ -97,7 +99,7 @@ public class TeleportMixinDefault extends TeleportMixinAbstract
Player teleportee = SenderUtil.getPlayer(teleporteeId); Player teleportee = SenderUtil.getPlayer(teleporteeId);
if (teleportee != null) if (teleportee != null)
{ {
teleportEntity(teleportee, destinationPs); teleportPlayer(teleportee, destinationPs);
} }
else else
{ {

View File

@ -38,6 +38,7 @@ import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.inventory.InventoryType.SlotType; import org.bukkit.event.inventory.InventoryType.SlotType;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -151,6 +152,11 @@ public class MUtil
return one.getWorld().equals(two.getWorld()); return one.getWorld().equals(two.getWorld());
} }
public static boolean isSameBlock(PlayerMoveEvent event)
{
return isSameBlock(event.getFrom(), event.getTo());
}
// -------------------------------------------- // // -------------------------------------------- //
// FACE AND YAW // FACE AND YAW
// -------------------------------------------- // // -------------------------------------------- //