From 10597cec2f3f70628e753616ff5371f65fa39f5f Mon Sep 17 00:00:00 2001 From: ementalo Date: Wed, 7 Dec 2011 01:12:36 +0000 Subject: Catch TeleportClause.COMMAND in the teleport listener. Changed Teleport methods to pass a TeleportClause param --- .../essentials/EssentialsPlayerListener.java | 2 +- Essentials/src/com/earth2me/essentials/Jails.java | 3 +- .../src/com/earth2me/essentials/Teleport.java | 51 ++++++++++++---------- .../src/com/earth2me/essentials/api/ITeleport.java | 3 +- .../earth2me/essentials/commands/Commandhome.java | 5 ++- .../earth2me/essentials/commands/Commandjump.java | 3 +- .../earth2me/essentials/commands/Commandtop.java | 3 +- .../earth2me/essentials/commands/Commandtp.java | 7 +-- .../essentials/commands/Commandtpaccept.java | 5 ++- .../earth2me/essentials/commands/Commandtpall.java | 3 +- .../essentials/commands/Commandtphere.java | 3 +- .../earth2me/essentials/commands/Commandtpo.java | 3 +- .../essentials/commands/Commandtpohere.java | 3 +- .../earth2me/essentials/commands/Commandtppos.java | 3 +- .../earth2me/essentials/commands/Commandwarp.java | 5 ++- .../earth2me/essentials/commands/Commandworld.java | 3 +- .../com/earth2me/essentials/signs/SignWarp.java | 3 +- .../earth2me/essentials/spawn/Commandspawn.java | 7 +-- .../spawn/EssentialsSpawnPlayerListener.java | 3 +- 19 files changed, 69 insertions(+), 49 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index 5525b2562..0991a16e4 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -235,7 +235,7 @@ public class EssentialsPlayerListener extends PlayerListener final User user = ess.getUser(event.getPlayer()); //There is TeleportCause.COMMMAND but plugins have to actively pass the cause in on their teleports. - if(event.getCause() == TeleportCause.PLUGIN && ess.getSettings().registerBackInListener()) + if((event.getCause() == TeleportCause.PLUGIN || event.getCause() == TeleportCause.COMMAND)&& ess.getSettings().registerBackInListener()) { user.setLastLocation(); } diff --git a/Essentials/src/com/earth2me/essentials/Jails.java b/Essentials/src/com/earth2me/essentials/Jails.java index 2fbc57aa5..de23ea241 100644 --- a/Essentials/src/com/earth2me/essentials/Jails.java +++ b/Essentials/src/com/earth2me/essentials/Jails.java @@ -13,6 +13,7 @@ import org.bukkit.event.Event.Priority; import org.bukkit.event.Event.Type; import org.bukkit.event.block.*; import org.bukkit.event.player.*; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.plugin.PluginManager; @@ -109,7 +110,7 @@ public class Jails extends AsyncStorageObjectHolder homes = player.getHomes(); if (homes.isEmpty() && player.equals(user)) { - user.getTeleport().respawn(charge); + user.getTeleport().respawn(charge, TeleportCause.COMMAND); } else if (homes.isEmpty()) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandjump.java b/Essentials/src/com/earth2me/essentials/commands/Commandjump.java index 8e37da0c8..39ca305e3 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandjump.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandjump.java @@ -6,6 +6,7 @@ import com.earth2me.essentials.User; import com.earth2me.essentials.Util; import org.bukkit.Location; import org.bukkit.Server; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; public class Commandjump extends EssentialsCommand @@ -35,6 +36,6 @@ public class Commandjump extends EssentialsCommand final Trade charge = new Trade(this.getName(), ess); charge.isAffordableFor(user); - user.getTeleport().teleport(loc, charge); + user.getTeleport().teleport(loc, charge, TeleportCause.COMMAND); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtop.java b/Essentials/src/com/earth2me/essentials/commands/Commandtop.java index 5cd9376cd..e91d0984a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtop.java @@ -5,6 +5,7 @@ import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; import org.bukkit.Location; import org.bukkit.Server; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; public class Commandtop extends EssentialsCommand @@ -20,7 +21,7 @@ public class Commandtop extends EssentialsCommand final int topX = user.getLocation().getBlockX(); final int topZ = user.getLocation().getBlockZ(); final int topY = user.getWorld().getHighestBlockYAt(topX, topZ); - user.getTeleport().teleport(new Location(user.getWorld(), user.getLocation().getX(), topY + 1, user.getLocation().getZ()), new Trade(this.getName(), ess)); + user.getTeleport().teleport(new Location(user.getWorld(), user.getLocation().getX(), topY + 1, user.getLocation().getZ()), new Trade(this.getName(), ess), TeleportCause.COMMAND); user.sendMessage(_("teleportTop")); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtp.java b/Essentials/src/com/earth2me/essentials/commands/Commandtp.java index 10c381b2e..7ea3f0541 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtp.java @@ -6,6 +6,7 @@ import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; import org.bukkit.Server; import org.bukkit.command.CommandSender; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; public class Commandtp extends EssentialsCommand @@ -32,7 +33,7 @@ public class Commandtp extends EssentialsCommand user.sendMessage(_("teleporting")); final Trade charge = new Trade(this.getName(), ess); charge.isAffordableFor(user); - user.getTeleport().teleport(player, charge); + user.getTeleport().teleport(player, charge, TeleportCause.COMMAND); throw new NoChargeException(); default: @@ -44,7 +45,7 @@ public class Commandtp extends EssentialsCommand user.sendMessage(_("teleporting")); final User target = getPlayer(server, args, 0); final User toPlayer = getPlayer(server, args, 1); - target.getTeleport().now(toPlayer, false); + target.getTeleport().now(toPlayer, false, TeleportCause.COMMAND); target.sendMessage(_("teleportAtoB", user.getDisplayName(), toPlayer.getDisplayName())); break; } @@ -61,7 +62,7 @@ public class Commandtp extends EssentialsCommand sender.sendMessage(_("teleporting")); final User target = getPlayer(server, args, 0); final User toPlayer = getPlayer(server, args, 1); - target.getTeleport().now(toPlayer, false); + target.getTeleport().now(toPlayer, false, TeleportCause.COMMAND); target.sendMessage(_("teleportAtoB", Console.NAME, toPlayer.getDisplayName())); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java index 164a1afad..954f3f038 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java @@ -5,6 +5,7 @@ import com.earth2me.essentials.OfflinePlayer; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; import org.bukkit.Server; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; public class Commandtpaccept extends EssentialsCommand @@ -40,11 +41,11 @@ public class Commandtpaccept extends EssentialsCommand if (user.isTeleportRequestHere()) { - user.getTeleport().teleport(target, charge); + user.getTeleport().teleport(target, charge, TeleportCause.COMMAND); } else { - target.getTeleport().teleport(user, charge); + target.getTeleport().teleport(user, charge, TeleportCause.COMMAND); } user.requestTeleport(null, false); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java index d3b8917aa..f21f1a6bc 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java @@ -5,6 +5,7 @@ import com.earth2me.essentials.User; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; public class Commandtpall extends EssentialsCommand @@ -43,7 +44,7 @@ public class Commandtpall extends EssentialsCommand } try { - player.getTeleport().now(user, false); + player.getTeleport().now(user, false, TeleportCause.COMMAND); } catch (Exception ex) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java b/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java index ecfb6b6a6..733091d1a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java @@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; import org.bukkit.Server; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; public class Commandtphere extends EssentialsCommand @@ -21,7 +22,7 @@ public class Commandtphere extends EssentialsCommand { throw new Exception(_("teleportDisabled", player.getDisplayName())); } - player.getTeleport().teleport(user, new Trade(this.getName(), ess)); + player.getTeleport().teleport(user, new Trade(this.getName(), ess), TeleportCause.COMMAND); user.sendMessage(_("teleporting")); player.sendMessage(_("teleporting")); throw new NoChargeException(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpo.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpo.java index d225725be..7c13b80d4 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpo.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpo.java @@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.OfflinePlayer; import com.earth2me.essentials.User; import org.bukkit.Server; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; public class Commandtpo extends EssentialsCommand @@ -32,7 +33,7 @@ public class Commandtpo extends EssentialsCommand // Verify permission if (!player.isHidden() || user.isAuthorized("essentials.teleport.hidden")) { - user.getTeleport().now(player, false); + user.getTeleport().now(player, false, TeleportCause.COMMAND); user.sendMessage(_("teleporting")); } else diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpohere.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpohere.java index 0a6bc5180..e226f0702 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpohere.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpohere.java @@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.OfflinePlayer; import com.earth2me.essentials.User; import org.bukkit.Server; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; public class Commandtpohere extends EssentialsCommand @@ -33,7 +34,7 @@ public class Commandtpohere extends EssentialsCommand // Verify permission if (!player.isHidden() || user.isAuthorized("essentials.teleport.hidden")) { - player.getTeleport().now(user, false); + player.getTeleport().now(user, false, TeleportCause.COMMAND); user.sendMessage(_("teleporting")); } else diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java b/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java index 203628753..226fa44e3 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java @@ -5,6 +5,7 @@ import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; import org.bukkit.Location; import org.bukkit.Server; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; public class Commandtppos extends EssentialsCommand @@ -37,7 +38,7 @@ public class Commandtppos extends EssentialsCommand final Trade charge = new Trade(this.getName(), ess); charge.isAffordableFor(user); user.sendMessage(_("teleporting")); - user.getTeleport().teleport(location, charge); + user.getTeleport().teleport(location, charge, TeleportCause.COMMAND); throw new NoChargeException(); } } \ No newline at end of file diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java b/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java index b15af349d..8fe84ba16 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java @@ -10,6 +10,7 @@ import java.util.Iterator; import java.util.List; import org.bukkit.Server; import org.bukkit.command.CommandSender; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; public class Commandwarp extends EssentialsCommand @@ -118,11 +119,11 @@ public class Commandwarp extends EssentialsCommand { if (user.isAuthorized("essentials.warp." + name)) { - user.getTeleport().warp(name, charge); + user.getTeleport().warp(name, charge, TeleportCause.COMMAND); return; } throw new Exception(_("warpUsePermission")); } - user.getTeleport().warp(name, charge); + user.getTeleport().warp(name, charge, TeleportCause.COMMAND); } } \ No newline at end of file diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandworld.java b/Essentials/src/com/earth2me/essentials/commands/Commandworld.java index b62276cf8..41554c8ce 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandworld.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandworld.java @@ -7,6 +7,7 @@ import java.util.List; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.World; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; public class Commandworld extends EssentialsCommand @@ -81,7 +82,7 @@ public class Commandworld extends EssentialsCommand final Trade charge = new Trade(this.getName(), ess); charge.isAffordableFor(user); - user.getTeleport().teleport(target, charge); + user.getTeleport().teleport(target, charge, TeleportCause.COMMAND); throw new NoChargeException(); } } diff --git a/Essentials/src/com/earth2me/essentials/signs/SignWarp.java b/Essentials/src/com/earth2me/essentials/signs/SignWarp.java index bd56be46e..76e8e730b 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignWarp.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignWarp.java @@ -4,6 +4,7 @@ import com.earth2me.essentials.ChargeException; import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; public class SignWarp extends EssentialsSign @@ -56,7 +57,7 @@ public class SignWarp extends EssentialsSign final Trade charge = getTrade(sign, 3, ess); try { - player.getTeleport().warp(warpName, charge); + player.getTeleport().warp(warpName, charge, TeleportCause.PLUGIN); } catch (Exception ex) { diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java index fe1630b4d..f29707b82 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java @@ -7,6 +7,7 @@ import com.earth2me.essentials.commands.NotEnoughArgumentsException; import static com.earth2me.essentials.I18n._; import org.bukkit.Server; import org.bukkit.command.CommandSender; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; public class Commandspawn extends EssentialsCommand @@ -24,7 +25,7 @@ public class Commandspawn extends EssentialsCommand if (args.length > 0 && user.isAuthorized("essentials.spawn.others")) { final User otherUser = getPlayer(server, args, 0); - otherUser.getTeleport().respawn(charge); + otherUser.getTeleport().respawn(charge, TeleportCause.COMMAND); if (!otherUser.equals(user)) { otherUser.sendMessage(_("teleportAtoB", user.getDisplayName(), "spawn")); @@ -33,7 +34,7 @@ public class Commandspawn extends EssentialsCommand } else { - user.getTeleport().respawn(charge); + user.getTeleport().respawn(charge, TeleportCause.COMMAND); } } @@ -45,7 +46,7 @@ public class Commandspawn extends EssentialsCommand throw new NotEnoughArgumentsException(); } final User user = getPlayer(server, args, 0); - user.getTeleport().respawn(null); + user.getTeleport().respawn(null, TeleportCause.COMMAND); user.sendMessage(_("teleportAtoB", user.getDisplayName(), "spawn")); sender.sendMessage(_("teleporting")); } diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java index 6bb453f12..8c3678a92 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java @@ -9,6 +9,7 @@ import org.bukkit.Location; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerListener; import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; public class EssentialsSpawnPlayerListener extends PlayerListener @@ -84,7 +85,7 @@ public class EssentialsSpawnPlayerListener extends PlayerListener { try { - user.getTeleport().now(spawns.getSpawn(ess.getSettings().getNewbieSpawn()), false); + user.getTeleport().now(spawns.getSpawn(ess.getSettings().getNewbieSpawn()), false, TeleportCause.PLUGIN); } catch (Exception ex) { -- cgit v1.2.3