Merge branch 'plugin-smackdown'

Closes #328
This commit is contained in:
Tim Ekl 2011-12-22 22:01:22 -06:00
commit 20ad724e5a
6 changed files with 91 additions and 21 deletions

View File

@ -58,13 +58,14 @@ 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<String, String> teleportQueue = new HashMap<String, String>();
private AnchorManager anchorManager = new AnchorManager(this);
/**
* 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 +77,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
@ -324,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);

View File

@ -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");

View File

@ -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 = "";

View File

@ -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.
@ -138,15 +137,23 @@ 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;
}
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())) {

View File

@ -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,34 @@ public class PermissionTools {
return returnString + "*";
}
public boolean playerHasMoneyToEnter(MultiverseWorld fromWorld, MultiverseWorld toWorld, Player teleporter, Player teleportee, boolean pay) {
if (teleporter == null) {
return true;
public boolean playerHasMoneyToEnter(MultiverseWorld fromWorld, MultiverseWorld toWorld, CommandSender teleporter, Player teleportee, boolean pay) {
Player teleporterPlayer;
if (MultiverseCore.TeleportIntercept) {
if (teleporter instanceof ConsoleCommandSender) {
return true;
}
if (teleporter == null) {
teleporter = teleportee;
}
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;
}
}
// 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 +117,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 +138,47 @@ 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) {
// The console can send anyone anywhere
if (teleporter == null) {
return true;
public boolean playerCanGoFromTo(MultiverseWorld fromWorld, MultiverseWorld toWorld, CommandSender teleporter, Player teleportee) {
this.plugin.log(Level.FINEST, "Checking '" + teleporter + "' can send '" + teleportee + "' somewhere");
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;
}
// 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;
}
}
// 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 {

View File

@ -10,3 +10,4 @@ enforcegamemodes: true
bedrespawn: true
version: 2.4
displaypermerrors: true
teleportintercept: true