From 88b8865fe118232c200e7d5a439efa861610b09d Mon Sep 17 00:00:00 2001 From: ementalo Date: Tue, 6 Dec 2011 22:56:38 +0000 Subject: Adding ability to save /back location from teleport events outside essentilals New config setting to turn this on "register-back-in-listener" Test #1200 CB#1560 / B#1055 --- Essentials/src/com/earth2me/essentials/Essentials.java | 3 +-- .../com/earth2me/essentials/EssentialsPlayerListener.java | 13 +++++++++++-- Essentials/src/com/earth2me/essentials/ISettings.java | 2 ++ Essentials/src/com/earth2me/essentials/OfflinePlayer.java | 13 +++++++++++++ Essentials/src/com/earth2me/essentials/Settings.java | 6 ++++++ Essentials/src/config.yml | 4 ++++ Essentials/test/com/earth2me/essentials/FakeServer.java | 6 ++++++ 7 files changed, 43 insertions(+), 4 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index 376e0318c..8e5a2f588 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -56,13 +56,12 @@ import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitScheduler; -import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.error.YAMLException; public class Essentials extends JavaPlugin implements IEssentials { - public static final int BUKKIT_VERSION = 1538; + public static final int BUKKIT_VERSION = 1560; private static final Logger LOGGER = Logger.getLogger("Minecraft"); private transient ISettings settings; private final transient TNTExplodeListener tntListener = new TNTExplodeListener(this); diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index a9e4bcac7..5525b2562 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -20,6 +20,8 @@ import org.bukkit.entity.Player; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerLoginEvent.Result; import org.bukkit.event.player.*; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.inventory.ItemStack; @@ -225,12 +227,19 @@ public class EssentialsPlayerListener extends PlayerListener @Override public void onPlayerTeleport(PlayerTeleportEvent event) - { + { if (event.isCancelled()) { return; } - final User user = ess.getUser(event.getPlayer()); + + 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()) + { + user.setLastLocation(); + } + if (ess.getSettings().changeDisplayName()) { user.setDisplayNick(); diff --git a/Essentials/src/com/earth2me/essentials/ISettings.java b/Essentials/src/com/earth2me/essentials/ISettings.java index de25c5c4f..97b0fad93 100644 --- a/Essentials/src/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/com/earth2me/essentials/ISettings.java @@ -144,4 +144,6 @@ public interface ISettings extends IConf boolean getRepairEnchanted(); boolean getIsWorldTeleportPermissions(); + + boolean registerBackInListener(); } diff --git a/Essentials/src/com/earth2me/essentials/OfflinePlayer.java b/Essentials/src/com/earth2me/essentials/OfflinePlayer.java index b554ec4fe..45359a837 100644 --- a/Essentials/src/com/earth2me/essentials/OfflinePlayer.java +++ b/Essentials/src/com/earth2me/essentials/OfflinePlayer.java @@ -12,6 +12,7 @@ import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.entity.*; import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import org.bukkit.map.MapView; @@ -803,4 +804,16 @@ public class OfflinePlayer implements Player { throw new UnsupportedOperationException("Not supported yet."); } + + @Override + public boolean teleport(Location lctn, TeleportCause tc) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean teleport(Entity entity, TeleportCause tc) + { + throw new UnsupportedOperationException("Not supported yet."); + } } diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java index b06677b44..efda428ef 100644 --- a/Essentials/src/com/earth2me/essentials/Settings.java +++ b/Essentials/src/com/earth2me/essentials/Settings.java @@ -566,4 +566,10 @@ public class Settings implements ISettings { return config.getBoolean("world-teleport-permissions", false); } + + @Override + public boolean registerBackInListener() + { + return config.getBoolean("register-back-in-listener", false); + } } diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index a507959c5..3b7637fea 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -239,6 +239,10 @@ oversized-stacksize: 64 # essentials.repair.enchanted repair-enchanted: true +#Do you want essentials to keep track of previous location for /back in the teleport listener? +#If you set this to true any plugin that uses teleport will have the previous location registered. +register-back-in-listener: false + ############################################################ # +------------------------------------------------------+ # # | EssentialsHome | # diff --git a/Essentials/test/com/earth2me/essentials/FakeServer.java b/Essentials/test/com/earth2me/essentials/FakeServer.java index eb549ca37..d0fe51c9a 100644 --- a/Essentials/test/com/earth2me/essentials/FakeServer.java +++ b/Essentials/test/com/earth2me/essentials/FakeServer.java @@ -593,4 +593,10 @@ public class FakeServer implements Server { throw new UnsupportedOperationException("Not supported yet."); } + + @Override + public OfflinePlayer[] getOfflinePlayers() + { + throw new UnsupportedOperationException("Not supported yet."); + } } -- cgit v1.2.3