From 2879c2a96e8a9f36f9980fdd9c06fef206713c1d Mon Sep 17 00:00:00 2001 From: Tim Ekl Date: Wed, 21 Dec 2011 22:44:26 -0600 Subject: [PATCH 1/4] Add bonus log messages for teleport permissions --- .../MultiverseCore/listeners/MVPlayerListener.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java index f121f556..43069086 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java @@ -138,6 +138,8 @@ public class MVPlayerListener extends PlayerListener { @Override public void onPlayerTeleport(PlayerTeleportEvent event) { + this.plugin.log(Level.FINEST, "Got teleport event for player '" + event.getPlayer().getName() + "' with cause '" + event.getCause() + "'"); + if (event.isCancelled()) { return; } @@ -167,6 +169,8 @@ public class MVPlayerListener extends PlayerListener { if (event.isCancelled() && teleporter != null) { this.plugin.log(Level.FINE, "Player '" + teleportee.getName() + "' was DENIED ACCESS to '" + event.getTo().getWorld().getName() + "' because '" + teleporter.getName() + "' don't have: multiverse.access." + event.getTo().getWorld().getName()); + } else { + this.plugin.log(Level.FINE, "Player '" + teleportee.getName() + "' was allowed to go to '" + event.getTo().getWorld().getName() + "' under normal circumstances."); } } else { this.plugin.log(Level.FINE, "Player '" + teleportee.getName() + "' was allowed to go to '" + event.getTo().getWorld().getName() + "' because enforceaccess is off."); From 6761be6952fb635f96a605da7eaa9f6bc1338c51 Mon Sep 17 00:00:00 2001 From: Tim Ekl Date: Wed, 21 Dec 2011 23:20:58 -0600 Subject: [PATCH 2/4] Intercept other plugins' teleports properly This commit will eventually provide a fix for #328, when it gets merged --- .../MultiverseCore/MultiverseCore.java | 7 +-- .../listeners/MVPlayerListener.java | 15 +++--- .../MultiverseCore/utils/PermissionTools.java | 50 +++++++++++++++---- 3 files changed, 53 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 1684a21f..3d39e8a9 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -63,8 +63,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { /** * This method is used to find out who is teleporting a player. - * @param playerName The teleported player. - * @return The player that teleported the other one. + * @param playerName The teleported player (the teleportee). + * @return The player that teleported the other one (the teleporter). */ public static String getPlayerTeleporter(String playerName) { if (teleportQueue.containsKey(playerName)) { @@ -76,7 +76,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { } public static void addPlayerToTeleportQueue(String teleporter, String teleportee) { - teleportQueue.put(teleporter, teleportee); + staticLog(Level.FINEST, "Adding mapping '" + teleporter + "' => '" + teleportee + "' to teleport queue"); + teleportQueue.put(teleportee, teleporter); } @Override diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java index 43069086..89560a9f 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java @@ -17,6 +17,7 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.player.*; @@ -61,8 +62,6 @@ public class MVPlayerListener extends PlayerListener { @Override public void onPlayerRespawn(PlayerRespawnEvent event) { - - World world = event.getPlayer().getWorld(); MultiverseWorld mvWorld = this.worldManager.getMVWorld(world.getName()); // If it's not a World MV manages we stop. @@ -144,11 +143,17 @@ public class MVPlayerListener extends PlayerListener { return; } Player teleportee = event.getPlayer(); - Player teleporter = null; + CommandSender teleporter = null; String teleporterName = MultiverseCore.getPlayerTeleporter(teleportee.getName()); if (teleporterName != null) { - teleporter = this.plugin.getServer().getPlayer(teleporterName); + if (teleporterName.equals("CONSOLE")) { + this.plugin.log(Level.FINEST, "We know the teleporter is the console! Magical!"); + teleporter = this.plugin.getServer().getConsoleSender(); + } else { + teleporter = this.plugin.getServer().getPlayer(teleporterName); + } } + this.plugin.log(Level.FINEST, "Inferred sender '" + teleporter + "' from name '" + teleporterName + "', fetched from name '" + teleportee.getName() + "'"); MultiverseWorld fromWorld = this.worldManager.getMVWorld(event.getFrom().getWorld().getName()); MultiverseWorld toWorld = this.worldManager.getMVWorld(event.getTo().getWorld().getName()); if (event.getFrom().getWorld().equals(event.getTo().getWorld())) { @@ -169,8 +174,6 @@ public class MVPlayerListener extends PlayerListener { if (event.isCancelled() && teleporter != null) { this.plugin.log(Level.FINE, "Player '" + teleportee.getName() + "' was DENIED ACCESS to '" + event.getTo().getWorld().getName() + "' because '" + teleporter.getName() + "' don't have: multiverse.access." + event.getTo().getWorld().getName()); - } else { - this.plugin.log(Level.FINE, "Player '" + teleportee.getName() + "' was allowed to go to '" + event.getTo().getWorld().getName() + "' under normal circumstances."); } } else { this.plugin.log(Level.FINE, "Player '" + teleportee.getName() + "' was allowed to go to '" + event.getTo().getWorld().getName() + "' because enforceaccess is off."); diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java b/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java index b61cac01..bba4ff62 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java @@ -7,9 +7,12 @@ package com.onarandombox.MultiverseCore.utils; +import java.util.logging.Level; import com.fernferret.allpay.GenericBank; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MultiverseWorld; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; import org.bukkit.permissions.Permission; @@ -79,10 +82,20 @@ public class PermissionTools { return returnString + "*"; } - public boolean playerHasMoneyToEnter(MultiverseWorld fromWorld, MultiverseWorld toWorld, Player teleporter, Player teleportee, boolean pay) { - if (teleporter == null) { + public boolean playerHasMoneyToEnter(MultiverseWorld fromWorld, MultiverseWorld toWorld, CommandSender teleporter, Player teleportee, boolean pay) { + if (teleporter instanceof ConsoleCommandSender) { return true; } + + if (teleporter == null) { + teleporter = teleportee; + } + + if (!(teleporter instanceof Player)) { + return false; + } + Player teleporterPlayer = (Player) teleporter; + // Only check payments if it's a different world: if (!toWorld.equals(fromWorld)) { // If the player does not have to pay, return now. @@ -90,14 +103,14 @@ public class PermissionTools { return true; } GenericBank bank = plugin.getBank(); - String errString = "You need " + bank.getFormattedAmount(teleporter, toWorld.getPrice(), toWorld.getCurrency()) + " to send " + teleportee + " to " + toWorld.getColoredWorldString(); + String errString = "You need " + bank.getFormattedAmount(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency()) + " to send " + teleportee + " to " + toWorld.getColoredWorldString(); if (teleportee.equals(teleporter)) { - errString = "You need " + bank.getFormattedAmount(teleporter, toWorld.getPrice(), toWorld.getCurrency()) + " to enter " + toWorld.getColoredWorldString(); + errString = "You need " + bank.getFormattedAmount(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency()) + " to enter " + toWorld.getColoredWorldString(); } - if (!bank.hasEnough(teleporter, toWorld.getPrice(), toWorld.getCurrency(), errString)) { + if (!bank.hasEnough(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency(), errString)) { return false; } else if(pay) { - bank.pay(teleporter, toWorld.getPrice(), toWorld.getCurrency()); + bank.pay(teleporterPlayer, toWorld.getPrice(), toWorld.getCurrency()); } } return true; @@ -111,16 +124,33 @@ public class PermissionTools { * * @param fromWorld The MultiverseWorld they are in. * @param toWorld The MultiverseWorld they want to go to. - * @param teleporter The player that wants to travel. + * @param teleporter The CommandSender that wants to send someone somewhere. If null, + * will be given the same value as teleportee. + * @param teleportee The player going somewhere. * @return True if they can't go to the world, False if they can. */ - public boolean playerCanGoFromTo(MultiverseWorld fromWorld, MultiverseWorld toWorld, Player teleporter, Player teleportee) { + public boolean playerCanGoFromTo(MultiverseWorld fromWorld, MultiverseWorld toWorld, CommandSender teleporter, Player teleportee) { + this.plugin.log(Level.FINEST, "Checking '" + teleporter + "' can send '" + teleportee + "' somewhere"); + // The console can send anyone anywhere - if (teleporter == null) { + if (teleporter instanceof ConsoleCommandSender) { return true; } + + // Make sure we have a teleporter of some kind, even if it's inferred to be the teleportee + if (teleporter == null) { + teleporter = teleportee; + } + + // Now make sure we can cast the teleporter to a player, 'cause I'm tired of console things now + if (!(teleporter instanceof Player)) { + return false; + } + Player teleporterPlayer = (Player) teleporter; + + // Actual checks if (toWorld != null) { - if (!this.plugin.getMVPerms().canEnterWorld(teleporter, toWorld)) { + if (!this.plugin.getMVPerms().canEnterWorld(teleporterPlayer, toWorld)) { if (teleportee.equals(teleporter)) { teleporter.sendMessage("You don't have access to go here..."); } else { From 8345c83afdadd27c7944ad41005f63f04d811423 Mon Sep 17 00:00:00 2001 From: Tim Ekl Date: Wed, 21 Dec 2011 23:34:35 -0600 Subject: [PATCH 3/4] Add config value (`teleportintercept`) New config value sets whether to attempt to block non-permissible teleport attempts initiated from other plugins. Previous behavior was new config value `false` - MV would not intercept these outside teleports. New default configured value is `true` - MV will intercept (and possibly block) other plugins' teleports. --- .../MultiverseCore/MultiverseCore.java | 2 + .../commands/VersionCommand.java | 1 + .../MultiverseCore/enums/ConfigProperty.java | 2 +- .../MultiverseCore/utils/PermissionTools.java | 70 +++++++++++++------ src/main/resources/defaults/config.yml | 1 + 5 files changed, 54 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 3d39e8a9..f7bf1039 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -58,6 +58,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { public static boolean EnforceGameModes; public static boolean PrefixChat; public static boolean DisplayPermErrors; + public static boolean TeleportIntercept; public static Map teleportQueue = new HashMap(); private AnchorManager anchorManager = new AnchorManager(this); @@ -325,6 +326,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { EnforceGameModes = this.multiverseConfig.getBoolean("enforcegamemodes", true); PrefixChat = this.multiverseConfig.getBoolean("worldnameprefix", true); DisplayPermErrors = this.multiverseConfig.getBoolean("displaypermerrors", true); + TeleportIntercept = this.multiverseConfig.getBoolean("teleportintercept", true); // Default as the server.props world. this.worldManager.setFirstSpawnWorld(this.multiverseConfig.getString("firstspawnworld", getDefaultWorldName())); DisplayPermErrors = this.multiverseConfig.getBoolean("displaypermerrors", true); diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java index 14228da2..990462ef 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java @@ -56,6 +56,7 @@ public class VersionCommand extends MultiverseCommand { logAndAddToPasteBinBuffer("enforceaccess: " + MultiverseCore.EnforceAccess); logAndAddToPasteBinBuffer("enforcegamemodes: " + MultiverseCore.EnforceGameModes); logAndAddToPasteBinBuffer("displaypermerrors: " + MultiverseCore.DisplayPermErrors); + logAndAddToPasteBinBuffer("teleportintercept: " + MultiverseCore.TeleportIntercept); logAndAddToPasteBinBuffer("debug: " + MultiverseCore.GlobalDebug); logAndAddToPasteBinBuffer("Special Code: FRN002"); diff --git a/src/main/java/com/onarandombox/MultiverseCore/enums/ConfigProperty.java b/src/main/java/com/onarandombox/MultiverseCore/enums/ConfigProperty.java index f0e85aa6..1b7c7cf4 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/enums/ConfigProperty.java +++ b/src/main/java/com/onarandombox/MultiverseCore/enums/ConfigProperty.java @@ -8,7 +8,7 @@ package com.onarandombox.MultiverseCore.enums; public enum ConfigProperty { - messagecooldown, teleportcooldown, worldnameprefix, enforcegamemodes, enforceaccess, displaypermerrors, debug, firstworldspawn; + messagecooldown, teleportcooldown, worldnameprefix, enforcegamemodes, enforceaccess, displaypermerrors, debug, firstworldspawn, teleportintercept; public static String getAllValues() { String buffer = ""; diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java b/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java index bba4ff62..2e0f9e5b 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java @@ -83,18 +83,32 @@ public class PermissionTools { } public boolean playerHasMoneyToEnter(MultiverseWorld fromWorld, MultiverseWorld toWorld, CommandSender teleporter, Player teleportee, boolean pay) { - if (teleporter instanceof ConsoleCommandSender) { - return true; - } + Player teleporterPlayer; + if (MultiverseCore.TeleportIntercept) { + if (teleporter instanceof ConsoleCommandSender) { + return true; + } - if (teleporter == null) { - teleporter = teleportee; - } + if (teleporter == null && MultiverseCore.TeleportIntercept) { + teleporter = teleportee; + } - if (!(teleporter instanceof Player)) { - return false; + if (!(teleporter instanceof Player)) { + return false; + } + teleporterPlayer = (Player) teleporter; + } else { + if (teleporter instanceof Player) { + teleporterPlayer = (Player) teleporter; + } else { + teleporterPlayer = null; + } + + // Old-style! + if (teleporterPlayer == null) { + return true; + } } - Player teleporterPlayer = (Player) teleporter; // Only check payments if it's a different world: if (!toWorld.equals(fromWorld)) { @@ -132,21 +146,35 @@ public class PermissionTools { public boolean playerCanGoFromTo(MultiverseWorld fromWorld, MultiverseWorld toWorld, CommandSender teleporter, Player teleportee) { this.plugin.log(Level.FINEST, "Checking '" + teleporter + "' can send '" + teleportee + "' somewhere"); - // The console can send anyone anywhere - if (teleporter instanceof ConsoleCommandSender) { - return true; - } + Player teleporterPlayer; + if(MultiverseCore.TeleportIntercept) { + // The console can send anyone anywhere + if (teleporter instanceof ConsoleCommandSender) { + return true; + } - // Make sure we have a teleporter of some kind, even if it's inferred to be the teleportee - if (teleporter == null) { - teleporter = teleportee; - } + // Make sure we have a teleporter of some kind, even if it's inferred to be the teleportee + if (teleporter == null) { + teleporter = teleportee; + } - // Now make sure we can cast the teleporter to a player, 'cause I'm tired of console things now - if (!(teleporter instanceof Player)) { - return false; + // Now make sure we can cast the teleporter to a player, 'cause I'm tired of console things now + if (!(teleporter instanceof Player)) { + return false; + } + teleporterPlayer = (Player) teleporter; + } else { + if (teleporter instanceof Player) { + teleporterPlayer = (Player) teleporter; + } else { + teleporterPlayer = null; + } + + // Old-style! + if (teleporterPlayer == null) { + return true; + } } - Player teleporterPlayer = (Player) teleporter; // Actual checks if (toWorld != null) { diff --git a/src/main/resources/defaults/config.yml b/src/main/resources/defaults/config.yml index 0a74ebd6..aec58797 100644 --- a/src/main/resources/defaults/config.yml +++ b/src/main/resources/defaults/config.yml @@ -10,3 +10,4 @@ enforcegamemodes: true bedrespawn: true version: 2.4 displaypermerrors: true +teleportintercept: true From 8f44a8e77a638c720ff72804fb6037b6482419db Mon Sep 17 00:00:00 2001 From: Tim Ekl Date: Thu, 22 Dec 2011 09:50:06 -0600 Subject: [PATCH 4/4] Remove redundant `TeleportIntercept` check --- .../com/onarandombox/MultiverseCore/utils/PermissionTools.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java b/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java index 2e0f9e5b..a99fe0c3 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/PermissionTools.java @@ -89,7 +89,7 @@ public class PermissionTools { return true; } - if (teleporter == null && MultiverseCore.TeleportIntercept) { + if (teleporter == null) { teleporter = teleportee; }