From e2f877946633409ac1dee74ecf347a26bae7af72 Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 22 Sep 2011 00:50:26 +0200 Subject: So... it's just some updates. --- .../essentials/perm/BPermissionsHandler.java | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Essentials/src/com/earth2me/essentials/perm/BPermissionsHandler.java b/Essentials/src/com/earth2me/essentials/perm/BPermissionsHandler.java index 90b905113..7758d5cce 100644 --- a/Essentials/src/com/earth2me/essentials/perm/BPermissionsHandler.java +++ b/Essentials/src/com/earth2me/essentials/perm/BPermissionsHandler.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.perm; import de.bananaco.permissions.Permissions; import de.bananaco.permissions.interfaces.PermissionSet; import de.bananaco.permissions.worlds.WorldPermissionsManager; +import de.bananaco.permissions.info.InfoReader; import java.util.List; import org.bukkit.entity.Player; @@ -10,10 +11,12 @@ import org.bukkit.entity.Player; public class BPermissionsHandler extends SuperpermsHandler { private final transient WorldPermissionsManager wpm; - + private final InfoReader info; public BPermissionsHandler() { wpm = Permissions.getWorldPermissionsManager(); + info = new InfoReader(); + info.instantiate(); } @Override @@ -48,4 +51,24 @@ public class BPermissionsHandler extends SuperpermsHandler } return groups.contains(group); } + + @Override + public boolean canBuild(final Player base, final String group) + { + return hasPermission(base, "bPermissions.build"); + } + + @Override + public String getPrefix(final Player base) + { + return info.getPrefix(base); + } + + @Override + public String getSuffix(final Player base) + { + return info.getSuffix(base); + } + + } -- cgit v1.2.3 From d5b95bdc1c59fcd69a49163daedb79a8488ac523 Mon Sep 17 00:00:00 2001 From: snowleo Date: Thu, 22 Sep 2011 01:03:54 +0200 Subject: BPermissions 1.6.0 Prefix/suffix support for bPermissions Star permissions are now done by bPermissions --- .../com/earth2me/essentials/perm/BPermissionsHandler.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/perm/BPermissionsHandler.java b/Essentials/src/com/earth2me/essentials/perm/BPermissionsHandler.java index 7758d5cce..6914c2816 100644 --- a/Essentials/src/com/earth2me/essentials/perm/BPermissionsHandler.java +++ b/Essentials/src/com/earth2me/essentials/perm/BPermissionsHandler.java @@ -8,10 +8,10 @@ import java.util.List; import org.bukkit.entity.Player; -public class BPermissionsHandler extends SuperpermsHandler +public class BPermissionsHandler implements IPermissionsHandler { private final transient WorldPermissionsManager wpm; - private final InfoReader info; + private final transient InfoReader info; public BPermissionsHandler() { wpm = Permissions.getWorldPermissionsManager(); @@ -69,6 +69,10 @@ public class BPermissionsHandler extends SuperpermsHandler { return info.getSuffix(base); } - - + + @Override + public boolean hasPermission(final Player base, final String node) + { + return base.hasPermission(node); + } } -- cgit v1.2.3 -- cgit v1.2.3 From 2e91767f6954e619b71ae5870528513e4857be44 Mon Sep 17 00:00:00 2001 From: snowleo Date: Thu, 22 Sep 2011 10:39:43 +0200 Subject: New Methods in Player --- Essentials/src/com/earth2me/essentials/OfflinePlayer.java | 12 ++++++++++++ Essentials/src/com/earth2me/essentials/PlayerWrapper.java | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/Essentials/src/com/earth2me/essentials/OfflinePlayer.java b/Essentials/src/com/earth2me/essentials/OfflinePlayer.java index 199526648..07092d0bb 100644 --- a/Essentials/src/com/earth2me/essentials/OfflinePlayer.java +++ b/Essentials/src/com/earth2me/essentials/OfflinePlayer.java @@ -701,5 +701,17 @@ public class OfflinePlayer implements Player { throw new UnsupportedOperationException("Not supported yet."); } + + @Override + public boolean isSprinting() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void setSprinting(boolean bln) + { + throw new UnsupportedOperationException("Not supported yet."); + } } diff --git a/Essentials/src/com/earth2me/essentials/PlayerWrapper.java b/Essentials/src/com/earth2me/essentials/PlayerWrapper.java index 8876e804a..2b6dd92ad 100644 --- a/Essentials/src/com/earth2me/essentials/PlayerWrapper.java +++ b/Essentials/src/com/earth2me/essentials/PlayerWrapper.java @@ -731,5 +731,17 @@ public class PlayerWrapper implements Player { return base.getBedSpawnLocation(); } + + @Override + public boolean isSprinting() + { + return base.isSprinting(); + } + + @Override + public void setSprinting(boolean bln) + { + base.setSprinting(bln); + } } -- cgit v1.2.3 From 18dcbc2ce73bdbde39f0d6bfdc3a9a1d5126b57f Mon Sep 17 00:00:00 2001 From: snowleo Date: Thu, 22 Sep 2011 10:46:23 +0200 Subject: Correctly implement food level on god mode --- Essentials/src/com/earth2me/essentials/Essentials.java | 1 + Essentials/src/com/earth2me/essentials/EssentialsTimer.java | 4 ---- Essentials/src/com/earth2me/essentials/User.java | 9 +++++++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index 518e853bb..c98671d94 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -188,6 +188,7 @@ public class Essentials extends JavaPlugin implements IEssentials pm.registerEvent(Type.ENTITY_DAMAGE, entityListener, Priority.Lowest, this); pm.registerEvent(Type.ENTITY_COMBUST, entityListener, Priority.Lowest, this); pm.registerEvent(Type.ENTITY_DEATH, entityListener, Priority.Lowest, this); + pm.registerEvent(Type.FOOD_LEVEL_CHANGE, entityListener, Priority.Lowest, this); jail = new Jail(this); final JailPlayerListener jailPlayerListener = new JailPlayerListener(this); diff --git a/Essentials/src/com/earth2me/essentials/EssentialsTimer.java b/Essentials/src/com/earth2me/essentials/EssentialsTimer.java index ab19450f8..f3b447dae 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsTimer.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsTimer.java @@ -26,10 +26,6 @@ public class EssentialsTimer implements Runnable onlineUsers.add(user); user.setLastOnlineActivity(currentTime); user.checkActivity(); - // Food for god mode - if (user.isGodModeEnabled() && user.getFoodLevel() < 20) { - user.setFoodLevel(20); - } } final Iterator iterator = onlineUsers.iterator(); diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java index 2f4fc2951..736274de0 100644 --- a/Essentials/src/com/earth2me/essentials/User.java +++ b/Essentials/src/com/earth2me/essentials/User.java @@ -464,4 +464,13 @@ public class User extends UserData implements Comparable, IReplyTo, IUser { return afkPosition; } + + @Override + public boolean toggleGodModeEnabled() + { + if (!isGodModeEnabled()) { + setFoodLevel(20); + } + return super.toggleGodModeEnabled(); + } } -- cgit v1.2.3 From 7bcafee89fea9b161d537386fa23cca4bad9c051 Mon Sep 17 00:00:00 2001 From: snowleo Date: Thu, 22 Sep 2011 10:47:39 +0200 Subject: Missing file for last commit --- .../src/com/earth2me/essentials/EssentialsEntityListener.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java b/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java index ce97726dc..2eda73540 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java @@ -8,6 +8,7 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityListener; +import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.inventory.ItemStack; @@ -80,4 +81,13 @@ public class EssentialsEntityListener extends EntityListener } } } + + @Override + public void onFoodLevelChange(FoodLevelChangeEvent event) + { + if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled()) + { + event.setFoodLevel(20); + } + } } -- cgit v1.2.3 From ed9043c184c71ac5c051368590076b2e9b37d6c3 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Thu, 22 Sep 2011 15:08:55 +0100 Subject: Adding extra creature types to prevent spawn setting. --- Essentials/src/config.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index 6edf0244d..13b7def41 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -422,6 +422,9 @@ protect: squid: false zombie: false wolf: false + cave_spider: false + enderman: false + silverfish: false # Maximum height the creeper should explode. -1 allows them to explode everywhere. # Set prevent.creeper-explosion to true, if you want to disable creeper explosions. -- cgit v1.2.3 From b0e2e4e1e729f91583920fe1146eb4347a473393 Mon Sep 17 00:00:00 2001 From: ementalo Date: Thu, 22 Sep 2011 17:29:00 +0100 Subject: Throw correct exceptions Test #943 --- Essentials/src/com/earth2me/essentials/commands/Commandinvsee.java | 1 + Essentials/src/com/earth2me/essentials/commands/Commandmail.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandinvsee.java b/Essentials/src/com/earth2me/essentials/commands/Commandinvsee.java index 8b6dc8182..07710d40a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandinvsee.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandinvsee.java @@ -49,5 +49,6 @@ public class Commandinvsee extends EssentialsCommand user.getInventory().setContents(invUserStack); user.sendMessage(Util.format("invSee", invUser.getDisplayName())); user.sendMessage(Util.i18n("invSeeHelp")); + throw new NoChargeException(); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java index a98fabbd2..e08a6c8e5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java @@ -64,6 +64,6 @@ public class Commandmail extends EssentialsCommand user.setMails(null); throw new Exception(Util.i18n("mailCleared")); } - throw new NotEnoughArgumentsException(); + throw new NoChargeException(); } } -- cgit v1.2.3 From 5f27e184d41cca5b4b39c49f58f4ea74108a5635 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Thu, 22 Sep 2011 17:50:42 +0100 Subject: Fix for home names containing invalid characters. --- Essentials/src/com/earth2me/essentials/UserData.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Essentials/src/com/earth2me/essentials/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java index 75d126c3e..39cebbd2a 100644 --- a/Essentials/src/com/earth2me/essentials/UserData.java +++ b/Essentials/src/com/earth2me/essentials/UserData.java @@ -154,6 +154,8 @@ public abstract class UserData extends PlayerExtension implements IConf public void setHome(String name, Location loc) { + //Invalid names will corrupt the yaml + name = Util.sanitizeFileName(name); homes.put(name, loc); config.setProperty("homes." + name, loc); config.save(); -- cgit v1.2.3 From f230439ed3f66cef5acbba679e3fc98e346ebb2a Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sat, 24 Sep 2011 03:19:05 +0100 Subject: Minor typing errors in messages.properties --- Essentials/src/messages.properties | 6 +++--- Essentials/src/messages_en.properties | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index d90d788eb..c756d4384 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -54,7 +54,7 @@ deleteJail = \u00a77Jail {0} has been removed. deleteWarp = \u00a77Warp {0} has been removed. deniedAccessCommand = {0} was denied access to command. dependancyDownloaded = [Essentials] Dependancy {0} downloaded successfully. -dependancyException = [Essentials] An error occured when trying to download a dependacy +dependancyException = [Essentials] An error occurred when trying to download a dependacy dependancyNotFound = [Essentials] A required dependancy was not found, downloading now. depth = \u00a77You are at sea level. depthAboveSea = \u00a77You are {0} block(s) above sea level. @@ -171,7 +171,7 @@ mobsAvailable = \u00a77Mobs: {0} mobSpawnError = Error while changing mob spawner. mobSpawnLimit = Mob quantity limited to server limit mobSpawnTarget = Target block must be a mob spawner. -moneyRecievedFrom = \u00a7a{0} has been recieved from {1} +moneyRecievedFrom = \u00a7a{0} has been received from {1} moneySentTo = \u00a7a{0} has been sent to {1} moneyTaken = {0} taken from your bank account. month = month @@ -265,7 +265,7 @@ requestAcceptedFrom = \u00a77{0} accepted your teleport request. requestDenied = \u00a77Teleport request denied. requestDeniedFrom = \u00a77{0} denied your teleport request. requestSent = \u00a77Request sent to {0}\u00a77. -returnPlayerToJailError = Error occured when trying to return player to jail. +returnPlayerToJailError = Error occurred when trying to return player to jail. second = second seconds = seconds seenOffline = Player {0} is offline since {1} diff --git a/Essentials/src/messages_en.properties b/Essentials/src/messages_en.properties index a9dc9c9a8..ea73ccc56 100644 --- a/Essentials/src/messages_en.properties +++ b/Essentials/src/messages_en.properties @@ -54,7 +54,7 @@ deleteJail = \u00a77Jail {0} has been removed. deleteWarp = \u00a77Warp {0} has been removed. deniedAccessCommand = {0} was denied access to command. dependancyDownloaded = [Essentials] Dependancy {0} downloaded successfully. -dependancyException = [Essentials] An error occured when trying to download a dependacy +dependancyException = [Essentials] An error occurred when trying to download a dependacy dependancyNotFound = [Essentials] A required dependancy was not found, downloading now. depth = \u00a77You are at sea level. depthAboveSea = \u00a77You are {0} block(s) above sea level. @@ -170,7 +170,7 @@ missingPrefixSuffix = Missing a prefix or suffix for {0} mobSpawnError = Error while changing mob spawner. mobSpawnLimit = Mob quantity limited to server limit mobSpawnTarget = Target block must be a mob spawner. -moneyRecievedFrom = \u00a7a{0} has been recieved from {1} +moneyRecievedFrom = \u00a7a{0} has been received from {1} moneySentTo = \u00a7a{0} has been sent to {1} moneyTaken = {0} taken from your bank account. month = month @@ -264,7 +264,7 @@ requestAcceptedFrom = \u00a77{0} accepted your teleport request. requestDenied = \u00a77Teleport request denied. requestDeniedFrom = \u00a77{0} denied your teleport request requestSent = \u00a77Request sent to {0}\u00a77. -returnPlayerToJailError = Error occured when trying to return player to jail. +returnPlayerToJailError = Error occurred when trying to return player to jail. second = second seconds = seconds seenOffline = Player {0} is offline since {1} -- cgit v1.2.3 From a819a09b6effd22ec6930f32d4fda6b84916a3d0 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sat, 24 Sep 2011 03:31:20 +0100 Subject: Adjusting behavior of 'spawn-if-no-home'. --- .../src/com/earth2me/essentials/commands/Commandhome.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhome.java b/Essentials/src/com/earth2me/essentials/commands/Commandhome.java index 2ee2661e6..16b9fca2a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhome.java @@ -45,17 +45,17 @@ public class Commandhome extends EssentialsCommand catch (NotEnoughArgumentsException e) { List homes = u.getHomes(); - if (homes.isEmpty()) + if (homes.isEmpty() && u.equals(user) && ess.getSettings().spawnIfNoHome()) { - throw new Exception(u == user ? Util.i18n("noHomeSet") : Util.i18n("noHomeSetPlayer")); + user.getTeleport().respawn(ess.getSpawn(), charge); } - else if ((homes.size() == 1) && u == user) + else if (homes.isEmpty()) { - user.getTeleport().home(u, homes.get(0), charge); + throw new Exception(u == user ? Util.i18n("noHomeSet") : Util.i18n("noHomeSetPlayer")); } - else if (ess.getSettings().spawnIfNoHome()) + else if (homes.size() == 1 && u.equals(user)) { - user.getTeleport().respawn(ess.getSpawn(), charge); + user.getTeleport().home(u, homes.get(0), charge); } else { -- cgit v1.2.3 From f7b30b83b305da68f560767edcdfc61c7fc00747 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Mon, 26 Sep 2011 03:20:56 +0100 Subject: Updating for register 1.3 --- .../essentials/EssentialsPluginListener.java | 4 +- .../earth2me/essentials/commands/Commandptime.java | 22 +- .../earth2me/essentials/commands/Commandtime.java | 4 +- .../earth2me/essentials/commands/Commandunban.java | 4 +- .../essentials/register/payment/Method.java | 10 +- .../essentials/register/payment/Methods.java | 158 ++++---- .../essentials/register/payment/methods/BOSE6.java | 441 ++++++++++++--------- .../essentials/register/payment/methods/BOSE7.java | 420 +++++++++++--------- .../essentials/register/payment/methods/MCUR.java | 241 ++++++----- .../essentials/register/payment/methods/iCo4.java | 292 ++++++++------ .../essentials/register/payment/methods/iCo5.java | 23 +- .../essentials/register/payment/methods/iCo6.java | 299 ++++++++------ 12 files changed, 1111 insertions(+), 807 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPluginListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPluginListener.java index e64496171..6b92d7aa2 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPluginListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPluginListener.java @@ -21,10 +21,9 @@ public class EssentialsPluginListener extends ServerListener implements IConf public void onPluginEnable(final PluginEnableEvent event) { ess.getPermissionsHandler().checkPermissions(); - if (!ess.getPaymentMethod().hasMethod() && ess.getPaymentMethod().setMethod(event.getPlugin())) + if (!ess.getPaymentMethod().hasMethod() && ess.getPaymentMethod().setMethod(ess.getServer().getPluginManager())) { LOGGER.log(Level.INFO, "[Essentials] Payment method found (" + ess.getPaymentMethod().getMethod().getName() + " version: " + ess.getPaymentMethod().getMethod().getVersion() + ")"); - } } @@ -35,6 +34,7 @@ public class EssentialsPluginListener extends ServerListener implements IConf // Check to see if the plugin thats being disabled is the one we are using if (ess.getPaymentMethod() != null && ess.getPaymentMethod().hasMethod() && ess.getPaymentMethod().checkDisabled(event.getPlugin())) { + ess.getPaymentMethod().reset(); LOGGER.log(Level.INFO, "[Essentials] Payment method was disabled. No longer accepting payments."); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandptime.java b/Essentials/src/com/earth2me/essentials/commands/Commandptime.java index 2eb580ea4..115bb20ef 100755 --- a/Essentials/src/com/earth2me/essentials/commands/Commandptime.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandptime.java @@ -11,7 +11,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.TreeSet; -import org.bukkit.ChatColor; import org.bukkit.World; import org.bukkit.entity.Player; @@ -97,29 +96,31 @@ public class Commandptime extends EssentialsCommand */ private void getUsersTime(final CommandSender sender, final Collection users) { - if (users.size() > 1) + if (users.size() > 1) { sender.sendMessage(Util.format("pTimePlayers")); } - - for (User user : users) + + for (User user : users) { - if(user.getPlayerTimeOffset() == 0) + if (user.getPlayerTimeOffset() == 0) { sender.sendMessage(Util.format("pTimeNormal", user.getName())); } - else { + else + { String time = DescParseTickFormat.format(user.getPlayerTime()); - if(!user.isPlayerTimeRelative()) + if (!user.isPlayerTimeRelative()) { sender.sendMessage(Util.format("pTimeCurrentFixed", user.getName(), time)); } - else { + else + { sender.sendMessage(Util.format("pTimeCurrent", user.getName(), time)); } } } - + return; } @@ -177,7 +178,8 @@ public class Commandptime extends EssentialsCommand { sender.sendMessage(Util.format("pTimeSetFixed", time, msg.toString())); } - else { + else + { sender.sendMessage(Util.format("pTimeSet", time, msg.toString())); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtime.java b/Essentials/src/com/earth2me/essentials/commands/Commandtime.java index 72bb2b65f..687396f53 100755 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtime.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtime.java @@ -25,7 +25,7 @@ public class Commandtime extends EssentialsCommand { worldSelector = args[1]; } - Set worlds = getWorlds(server, sender, worldSelector); + final Set worlds = getWorlds(server, sender, worldSelector); // If no arguments we are reading the time if (args.length == 0) @@ -34,7 +34,7 @@ public class Commandtime extends EssentialsCommand return; } - User user = ess.getUser(sender); + final User user = ess.getUser(sender); if (user != null && !user.isAuthorized("essentials.time.set")) { user.sendMessage(Util.i18n("timeSetPermission")); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandunban.java b/Essentials/src/com/earth2me/essentials/commands/Commandunban.java index 8bc921d64..4877c2aeb 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandunban.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandunban.java @@ -21,11 +21,9 @@ public class Commandunban extends EssentialsCommand throw new NotEnoughArgumentsException(); } - String name; try { - User u = getPlayer(server, args, 0, true); - name = u.getName(); + final User u = getPlayer(server, args, 0, true); u.setBanned(false); sender.sendMessage(Util.i18n("unbannedPlayer")); } diff --git a/Essentials/src/com/earth2me/essentials/register/payment/Method.java b/Essentials/src/com/earth2me/essentials/register/payment/Method.java index 7394f6b2f..f8bd814ef 100644 --- a/Essentials/src/com/earth2me/essentials/register/payment/Method.java +++ b/Essentials/src/com/earth2me/essentials/register/payment/Method.java @@ -4,7 +4,7 @@ import org.bukkit.plugin.Plugin; /** - * Method.java + * Interface to be implemented by a payment method. * * @author Nijikokun (@nijikokun) * @copyright Copyright (C) 2011 @@ -41,6 +41,14 @@ public interface Method */ public String getVersion(); + /** + * Returns the amount of decimal places that get stored + * NOTE: it will return -1 if there is no rounding + * + * @return int for each decimal place + */ + public int fractionalDigits(); + /** * Formats amounts into this payment methods style of currency display. * diff --git a/Essentials/src/com/earth2me/essentials/register/payment/Methods.java b/Essentials/src/com/earth2me/essentials/register/payment/Methods.java index 3dc7a2c63..0fc65534f 100644 --- a/Essentials/src/com/earth2me/essentials/register/payment/Methods.java +++ b/Essentials/src/com/earth2me/essentials/register/payment/Methods.java @@ -5,9 +5,6 @@ import java.util.Set; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; -import java.util.HashSet; -import java.util.Set; - /** * The Methods initializes Methods that utilize the Method interface @@ -15,15 +12,13 @@ import java.util.Set; * * Allowing you to check whether a payment method exists or not. * - *
- *  Methods methods = new Methods();
- * 
- * * Methods also allows you to set a preferred method of payment before it captures * payment plugins in the initialization process. * + * in bukkit.yml: *
- *  Methods methods = new Methods("iConomy");
+ *  economy:
+ *      preferred: "iConomy"
  * 
* * @author: Nijikokun (@nijikokun) @@ -32,51 +27,62 @@ import java.util.Set; */ public class Methods { - private boolean self = false; - private Method Method = null; - private String preferred = ""; - private Set Methods = new HashSet(); - private Set Dependencies = new HashSet(); - private Set Attachables = new HashSet(); + private static String version = null; + private static boolean self = false; + private static Method Method = null; + private static String preferred = ""; + private static Set Methods = new HashSet(); + private static Set Dependencies = new HashSet(); + private static Set Attachables = new HashSet(); + + static + { + _init(); + } /** - * Initialize Method class + * Implement all methods along with their respective name & class. */ - public Methods() + private static void _init() { - this._init(); + addMethod("iConomy", new com.earth2me.essentials.register.payment.methods.iCo6()); + addMethod("iConomy", new com.earth2me.essentials.register.payment.methods.iCo5()); + addMethod("iConomy", new com.earth2me.essentials.register.payment.methods.iCo4()); + addMethod("BOSEconomy", new com.earth2me.essentials.register.payment.methods.BOSE6()); + addMethod("BOSEconomy", new com.earth2me.essentials.register.payment.methods.BOSE7()); + addMethod("Currency", new com.earth2me.essentials.register.payment.methods.MCUR()); + Dependencies.add("MultiCurrency"); } /** - * Initializes Methods class utilizing a "preferred" payment method check before - * returning the first method that was initialized. - * - * @param preferred Payment method that is most preferred for this setup. + * Used by the plugin to setup version + * + * @param v version */ - public Methods(String preferred) + public static void setVersion(String v) { - this._init(); + version = v; + } - if (this.Dependencies.contains(preferred)) - { - this.preferred = preferred; - } + /** + * Use to reset methods during disable + */ + public static void reset() + { + version = null; + self = false; + Method = null; + preferred = ""; + Attachables.clear(); } /** - * Implement all methods along with their respective name & class. - * - * @see #Methods() - * @see #Methods(java.lang.String) + * Use to get version of Register plugin + * @return version */ - private void _init() + public static String getVersion() { - this.addMethod("iConomy", new com.earth2me.essentials.register.payment.methods.iCo4()); - this.addMethod("iConomy", new com.earth2me.essentials.register.payment.methods.iCo5()); - this.addMethod("iConomy", new com.earth2me.essentials.register.payment.methods.iCo6()); - this.addMethod("BOSEconomy", new com.earth2me.essentials.register.payment.methods.BOSE6()); - this.addMethod("BOSEconomy", new com.earth2me.essentials.register.payment.methods.BOSE7()); - this.addMethod("MultiCurrency", new com.earth2me.essentials.register.payment.methods.MCUR()); + return version; } /** @@ -86,7 +92,7 @@ public class Methods * @return Set - Array of payment methods that are loaded. * @see #setMethod(org.bukkit.plugin.Plugin) */ - public Set getDependencies() + public static Set getDependencies() { return Dependencies; } @@ -98,7 +104,7 @@ public class Methods * @param plugin Plugin data from bukkit, Internal Class file. * @return Method or Null */ - public Method createMethod(Plugin plugin) + public static Method createMethod(Plugin plugin) { for (Method method : Methods) { @@ -112,7 +118,7 @@ public class Methods return null; } - private void addMethod(String name, Method method) + private static void addMethod(String name, Method method) { Dependencies.add(name); Methods.add(method); @@ -125,7 +131,7 @@ public class Methods * @see #setMethod(org.bukkit.plugin.Plugin) * @see #checkDisabled(org.bukkit.plugin.Plugin) */ - public boolean hasMethod() + public static boolean hasMethod() { return (Method != null); } @@ -134,15 +140,16 @@ public class Methods * Checks Plugin Class against a multitude of checks to verify it's usability * as a payment method. * - * @param method Plugin data from bukkit, Internal Class file. + * @param PluginManager the plugin manager for the server * @return boolean True on success, False on failure. */ - public boolean setMethod(Plugin method) + public static boolean setMethod(PluginManager manager) { if (hasMethod()) { return true; } + if (self) { self = false; @@ -152,44 +159,37 @@ public class Methods int count = 0; boolean match = false; Plugin plugin = null; - PluginManager manager = method.getServer().getPluginManager(); - for (String name : this.getDependencies()) + for (String name : getDependencies()) { if (hasMethod()) { break; } - if (method.getDescription().getName().equals(name)) - { - plugin = method; - } - else - { - plugin = manager.getPlugin(name); - } + + plugin = manager.getPlugin(name); if (plugin == null) { continue; } - Method current = this.createMethod(plugin); + Method current = createMethod(plugin); if (current == null) { continue; } - if (this.preferred.isEmpty()) + if (preferred.isEmpty()) { - this.Method = current; + Method = current; } else { - this.Attachables.add(current); + Attachables.add(current); } } - if (!this.preferred.isEmpty()) + if (!preferred.isEmpty()) { do { @@ -199,7 +199,7 @@ public class Methods } else { - for (Method attached : this.Attachables) + for (Method attached : Attachables) { if (attached == null) { @@ -212,21 +212,21 @@ public class Methods break; } - if (this.preferred.isEmpty()) + if (preferred.isEmpty()) { - this.Method = attached; + Method = attached; } if (count == 0) { - if (this.preferred.equalsIgnoreCase(attached.getName())) + if (preferred.equalsIgnoreCase(attached.getName())) { - this.Method = attached; + Method = attached; + } + else + { + Method = attached; } - } - else - { - this.Method = attached; } } @@ -239,12 +239,28 @@ public class Methods return hasMethod(); } + /** + * Sets the preferred economy + * + * @return boolean + */ + public static boolean setPreferred(String check) + { + if (getDependencies().contains(check)) + { + preferred = check; + return true; + } + + return false; + } + /** * Grab the existing and initialized (hopefully) Method Class. * * @return Method or Null */ - public Method getMethod() + public static Method getMethod() { return Method; } @@ -256,16 +272,18 @@ public class Methods * @param method Plugin data from bukkit, Internal Class file. * @return boolean */ - public boolean checkDisabled(Plugin method) + public static boolean checkDisabled(Plugin method) { if (!hasMethod()) { return true; } + if (Method.isCompatible(method)) { Method = null; } + return (Method == null); } } diff --git a/Essentials/src/com/earth2me/essentials/register/payment/methods/BOSE6.java b/Essentials/src/com/earth2me/essentials/register/payment/methods/BOSE6.java index 8400eebd0..7c83c9b76 100644 --- a/Essentials/src/com/earth2me/essentials/register/payment/methods/BOSE6.java +++ b/Essentials/src/com/earth2me/essentials/register/payment/methods/BOSE6.java @@ -1,9 +1,11 @@ package com.earth2me.essentials.register.payment.methods; import com.earth2me.essentials.register.payment.Method; + import cosine.boseconomy.BOSEconomy; import org.bukkit.plugin.Plugin; + /** * BOSEconomy 6 Implementation of Method * @@ -11,191 +13,256 @@ import org.bukkit.plugin.Plugin; * @copyright (c) 2011 * @license AOL license */ -public class BOSE6 implements Method { - private BOSEconomy BOSEconomy; - - public BOSEconomy getPlugin() { - return this.BOSEconomy; - } - - public String getName() { - return "BOSEconomy"; - } - - public String getVersion() { - return "0.6.2"; - } - - public String format(double amount) { - String currency = this.BOSEconomy.getMoneyNamePlural(); - if(amount == 1) currency = this.BOSEconomy.getMoneyName(); - return amount + " " + currency; - } - - public boolean hasBanks() { - return true; - } - - public boolean hasBank(String bank) { - return this.BOSEconomy.bankExists(bank); - } - - public boolean hasAccount(String name) { - return this.BOSEconomy.playerRegistered(name, false); - } - - public boolean hasBankAccount(String bank, String name) { - return this.BOSEconomy.isBankOwner(bank, name) || this.BOSEconomy.isBankMember(bank, name); - } - - public MethodAccount getAccount(String name) { - if(!hasAccount(name)) return null; - return new BOSEAccount(name, this.BOSEconomy); - } - - public MethodBankAccount getBankAccount(String bank, String name) { - if(!hasBankAccount(bank, name)) return null; - return new BOSEBankAccount(bank, BOSEconomy); - } - - public boolean isCompatible(Plugin plugin) { - return plugin.getDescription().getName().equalsIgnoreCase("boseconomy") && plugin instanceof BOSEconomy && plugin.getDescription().getVersion().equals("0.6.2"); - } - - public void setPlugin(Plugin plugin) { - BOSEconomy = (BOSEconomy)plugin; - } - - public class BOSEAccount implements MethodAccount { - private String name; - private BOSEconomy BOSEconomy; - - public BOSEAccount(String name, BOSEconomy bOSEconomy) { - this.name = name; - this.BOSEconomy = bOSEconomy; - } - - public double balance() { - return (double) this.BOSEconomy.getPlayerMoney(this.name); - } - - public boolean set(double amount) { - int IntAmount = (int)Math.ceil(amount); - return this.BOSEconomy.setPlayerMoney(this.name, IntAmount, false); - } - - public boolean add(double amount) { - int IntAmount = (int)Math.ceil(amount); - return this.BOSEconomy.addPlayerMoney(this.name, IntAmount, false); - } - - public boolean subtract(double amount) { - int IntAmount = (int)Math.ceil(amount); - int balance = (int)this.balance(); - return this.BOSEconomy.setPlayerMoney(this.name, (balance - IntAmount), false); - } - - public boolean multiply(double amount) { - int IntAmount = (int)Math.ceil(amount); - int balance = (int)this.balance(); - return this.BOSEconomy.setPlayerMoney(this.name, (balance * IntAmount), false); - } - - public boolean divide(double amount) { - int IntAmount = (int)Math.ceil(amount); - int balance = (int)this.balance(); - return this.BOSEconomy.setPlayerMoney(this.name, (balance / IntAmount), false); - } - - public boolean hasEnough(double amount) { - return (this.balance() >= amount); - } - - public boolean hasOver(double amount) { - return (this.balance() > amount); - } - - public boolean hasUnder(double amount) { - return (this.balance() < amount); - } - - public boolean isNegative() { - return (this.balance() < 0); - } - - public boolean remove() { - return false; - } - } - - public class BOSEBankAccount implements MethodBankAccount { - private final String bank; - private final BOSEconomy BOSEconomy; - - public BOSEBankAccount(String bank, BOSEconomy bOSEconomy) { - this.bank = bank; - this.BOSEconomy = bOSEconomy; - } - - public String getBankName() { - return this.bank; - } - - public int getBankId() { - return -1; - } - - public double balance() { - return (double) this.BOSEconomy.getBankMoney(bank); - } - - public boolean set(double amount) { - int IntAmount = (int)Math.ceil(amount); - return this.BOSEconomy.setBankMoney(bank, IntAmount, true); - } - - public boolean add(double amount) { - int IntAmount = (int)Math.ceil(amount); - int balance = (int)this.balance(); - return this.BOSEconomy.setBankMoney(bank, (balance + IntAmount), false); - } - - public boolean subtract(double amount) { - int IntAmount = (int)Math.ceil(amount); - int balance = (int)this.balance(); - return this.BOSEconomy.setBankMoney(bank, (balance - IntAmount), false); - } - - public boolean multiply(double amount) { - int IntAmount = (int)Math.ceil(amount); - int balance = (int)this.balance(); - return this.BOSEconomy.setBankMoney(bank, (balance * IntAmount), false); - } - - public boolean divide(double amount) { - int IntAmount = (int)Math.ceil(amount); - int balance = (int)this.balance(); - return this.BOSEconomy.setBankMoney(bank, (balance / IntAmount), false); - } - - public boolean hasEnough(double amount) { - return (this.balance() >= amount); - } - - public boolean hasOver(double amount) { - return (this.balance() > amount); - } - - public boolean hasUnder(double amount) { - return (this.balance() < amount); - } - - public boolean isNegative() { - return (this.balance() < 0); - } - - public boolean remove() { - return this.BOSEconomy.removeBank(bank); - } - } +@SuppressWarnings("deprecation") +public class BOSE6 implements Method +{ + private BOSEconomy BOSEconomy; + + public BOSEconomy getPlugin() + { + return this.BOSEconomy; + } + + public String getName() + { + return "BOSEconomy"; + } + + public String getVersion() + { + return "0.6.2"; + } + + public int fractionalDigits() + { + return 0; + } + + public String format(double amount) + { + String currency = this.BOSEconomy.getMoneyNamePlural(); + + if (amount == 1) + { + currency = this.BOSEconomy.getMoneyName(); + } + + return amount + " " + currency; + } + + public boolean hasBanks() + { + return true; + } + + public boolean hasBank(String bank) + { + return this.BOSEconomy.bankExists(bank); + } + + public boolean hasAccount(String name) + { + return this.BOSEconomy.playerRegistered(name, false); + } + + public boolean hasBankAccount(String bank, String name) + { + return this.BOSEconomy.isBankOwner(bank, name) + || this.BOSEconomy.isBankMember(bank, name); + } + + public MethodAccount getAccount(String name) + { + if (!hasAccount(name)) + { + return null; + } + + return new BOSEAccount(name, this.BOSEconomy); + } + + public MethodBankAccount getBankAccount(String bank, String name) + { + if (!hasBankAccount(bank, name)) + { + return null; + } + + return new BOSEBankAccount(bank, BOSEconomy); + } + + public boolean isCompatible(Plugin plugin) + { + return plugin.getDescription().getName().equalsIgnoreCase("boseconomy") + && plugin instanceof BOSEconomy + && plugin.getDescription().getVersion().equals("0.6.2"); + } + + public void setPlugin(Plugin plugin) + { + BOSEconomy = (BOSEconomy)plugin; + } + + + public class BOSEAccount implements MethodAccount + { + private final String name; + private final BOSEconomy BOSEconomy; + + public BOSEAccount(String name, BOSEconomy bOSEconomy) + { + this.name = name; + this.BOSEconomy = bOSEconomy; + } + + public double balance() + { + return (double)this.BOSEconomy.getPlayerMoney(this.name); + } + + public boolean set(double amount) + { + int IntAmount = (int)Math.ceil(amount); + return this.BOSEconomy.setPlayerMoney(this.name, IntAmount, false); + } + + public boolean add(double amount) + { + int IntAmount = (int)Math.ceil(amount); + return this.BOSEconomy.addPlayerMoney(this.name, IntAmount, false); + } + + public boolean subtract(double amount) + { + int IntAmount = (int)Math.ceil(amount); + int balance = (int)this.balance(); + return this.BOSEconomy.setPlayerMoney(this.name, (balance - IntAmount), false); + } + + public boolean multiply(double amount) + { + int IntAmount = (int)Math.ceil(amount); + int balance = (int)this.balance(); + return this.BOSEconomy.setPlayerMoney(this.name, (balance * IntAmount), false); + } + + public boolean divide(double amount) + { + int IntAmount = (int)Math.ceil(amount); + int balance = (int)this.balance(); + return this.BOSEconomy.setPlayerMoney(this.name, (balance / IntAmount), false); + } + + public boolean hasEnough(double amount) + { + return (this.balance() >= amount); + } + + public boolean hasOver(double amount) + { + return (this.balance() > amount); + } + + public boolean hasUnder(double amount) + { + return (this.balance() < amount); + } + + public boolean isNegative() + { + return (this.balance() < 0); + } + + public boolean remove() + { + return false; + } + } + + + public class BOSEBankAccount implements MethodBankAccount + { + private final String bank; + private final BOSEconomy BOSEconomy; + + public BOSEBankAccount(String bank, BOSEconomy bOSEconomy) + { + this.bank = bank; + this.BOSEconomy = bOSEconomy; + } + + public String getBankName() + { + return this.bank; + } + + public int getBankId() + { + return -1; + } + + public double balance() + { + return (double)this.BOSEconomy.getBankMoney(bank); + } + + public boolean set(double amount) + { + int IntAmount = (int)Math.ceil(amount); + return this.BOSEconomy.setBankMoney(bank, IntAmount, true); + } + + public boolean add(double amount) + { + int IntAmount = (int)Math.ceil(amount); + int balance = (int)this.balance(); + return this.BOSEconomy.setBankMoney(bank, (balance + IntAmount), false); + } + + public boolean subtract(double amount) + { + int IntAmount = (int)Math.ceil(amount); + int balance = (int)this.balance(); + return this.BOSEconomy.setBankMoney(bank, (balance - IntAmount), false); + } + + public boolean multiply(double amount) + { + int IntAmount = (int)Math.ceil(amount); + int balance = (int)this.balance(); + return this.BOSEconomy.setBankMoney(bank, (balance * IntAmount), false); + } + + public boolean divide(double amount) + { + int IntAmount = (int)Math.ceil(amount); + int balance = (int)this.balance(); + return this.BOSEconomy.setBankMoney(bank, (balance / IntAmount), false); + } + + public boolean hasEnough(double amount) + { + return (this.balance() >= amount); + } + + public boolean hasOver(double amount) + { + return (this.balance() > amount); + } + + public boolean hasUnder(double amount) + { + return (this.balance() < amount); + } + + public boolean isNegative() + { + return (this.balance() < 0); + } + + public boolean remove() + { + return this.BOSEconomy.removeBank(bank); + } + } } \ No newline at end of file diff --git a/Essentials/src/com/earth2me/essentials/register/payment/methods/BOSE7.java b/Essentials/src/com/earth2me/essentials/register/payment/methods/BOSE7.java index 3b0f53c4d..288e4a5c5 100644 --- a/Essentials/src/com/earth2me/essentials/register/payment/methods/BOSE7.java +++ b/Essentials/src/com/earth2me/essentials/register/payment/methods/BOSE7.java @@ -1,9 +1,11 @@ package com.earth2me.essentials.register.payment.methods; import com.earth2me.essentials.register.payment.Method; + import cosine.boseconomy.BOSEconomy; import org.bukkit.plugin.Plugin; + /** * BOSEconomy 7 Implementation of Method * @@ -12,182 +14,244 @@ import org.bukkit.plugin.Plugin; * @copyright (c) 2011 * @license AOL license */ - -public class BOSE7 implements Method { - private BOSEconomy BOSEconomy; - - public BOSEconomy getPlugin() { - return this.BOSEconomy; - } - - public String getName() { - return "BOSEconomy"; - } - - public String getVersion() { - return "0.7.0"; - } - - public String format(double amount) { - String currency = this.BOSEconomy.getMoneyNamePlural(); - if(amount == 1) currency = this.BOSEconomy.getMoneyName(); - return amount + " " + currency; - } - - public boolean hasBanks() { - return true; - } - - public boolean hasBank(String bank) { - return this.BOSEconomy.bankExists(bank); - } - - public boolean hasAccount(String name) { - return this.BOSEconomy.playerRegistered(name, false); - } - - public boolean hasBankAccount(String bank, String name) { - return this.BOSEconomy.isBankOwner(bank, name) || this.BOSEconomy.isBankMember(bank, name); - } - - public MethodAccount getAccount(String name) { - if(!hasAccount(name)) return null; - return new BOSEAccount(name, this.BOSEconomy); - } - - public MethodBankAccount getBankAccount(String bank, String name) { - if(!hasBankAccount(bank, name)) return null; - return new BOSEBankAccount(bank, BOSEconomy); - } - - public boolean isCompatible(Plugin plugin) { - return plugin.getDescription().getName().equalsIgnoreCase("boseconomy") && plugin instanceof BOSEconomy && !plugin.getDescription().getVersion().equals("0.6.2"); - } - - public void setPlugin(Plugin plugin) { - BOSEconomy = (BOSEconomy)plugin; - } - - public class BOSEAccount implements MethodAccount { - private String name; - private BOSEconomy BOSEconomy; - - public BOSEAccount(String name, BOSEconomy bOSEconomy) { - this.name = name; - this.BOSEconomy = bOSEconomy; - } - - public double balance() { - return this.BOSEconomy.getPlayerMoneyDouble(this.name); - } - - public boolean set(double amount) { - return this.BOSEconomy.setPlayerMoney(this.name, amount, false); - } - - public boolean add(double amount) { - return this.BOSEconomy.addPlayerMoney(this.name, amount, false); - } - - public boolean subtract(double amount) { - double balance = this.balance(); - return this.BOSEconomy.setPlayerMoney(this.name, (balance - amount), false); - } - - public boolean multiply(double amount) { - double balance = this.balance(); - return this.BOSEconomy.setPlayerMoney(this.name, (balance * amount), false); - } - - public boolean divide(double amount) { - double balance = this.balance(); - return this.BOSEconomy.setPlayerMoney(this.name, (balance / amount), false); - } - - public boolean hasEnough(double amount) { - return (this.balance() >= amount); - } - - public boolean hasOver(double amount) { - return (this.balance() > amount); - } - - public boolean hasUnder(double amount) { - return (this.balance() < amount); - } - - public boolean isNegative() { - return (this.balance() < 0); - } - - public boolean remove() { - return false; - } - } - - public class BOSEBankAccount implements MethodBankAccount { - private String bank; - private BOSEconomy BOSEconomy; - - public BOSEBankAccount(String bank, BOSEconomy bOSEconomy) { - this.bank = bank; - this.BOSEconomy = bOSEconomy; - } - - public String getBankName() { - return this.bank; - } - - public int getBankId() { - return -1; - } - - public double balance() { - return this.BOSEconomy.getBankMoneyDouble(bank); - } - - public boolean set(double amount) { - return this.BOSEconomy.setBankMoney(bank, amount, true); - } - - public boolean add(double amount) { - double balance = this.balance(); - return this.BOSEconomy.setBankMoney(bank, (balance + amount), false); - } - - public boolean subtract(double amount) { - double balance = this.balance(); - return this.BOSEconomy.setBankMoney(bank, (balance - amount), false); - } - - public boolean multiply(double amount) { - double balance = this.balance(); - return this.BOSEconomy.setBankMoney(bank, (balance * amount), false); - } - - public boolean divide(double amount) { - double balance = this.balance(); - return this.BOSEconomy.setBankMoney(bank, (balance / amount), false); - } - - public boolean hasEnough(double amount) { - return (this.balance() >= amount); - } - - public boolean hasOver(double amount) { - return (this.balance() > amount); - } - - public boolean hasUnder(double amount) { - return (this.balance() < amount); - } - - public boolean isNegative() { - return (this.balance() < 0); - } - - public boolean remove() { - return this.BOSEconomy.removeBank(bank); - } - } +public class BOSE7 implements Method +{ + private BOSEconomy BOSEconomy; + + public BOSEconomy getPlugin() + { + return this.BOSEconomy; + } + + public String getName() + { + return "BOSEconomy"; + } + + public String getVersion() + { + return "0.7.0"; + } + + public int fractionalDigits() + { + return this.BOSEconomy.getFractionalDigits(); + } + + public String format(double amount) + { + String currency = this.BOSEconomy.getMoneyNamePlural(); + + if (amount == 1) + { + currency = this.BOSEconomy.getMoneyName(); + } + + return amount + " " + currency; + } + + public boolean hasBanks() + { + return true; + } + + public boolean hasBank(String bank) + { + return this.BOSEconomy.bankExists(bank); + } + + public boolean hasAccount(String name) + { + return this.BOSEconomy.playerRegistered(name, false); + } + + public boolean hasBankAccount(String bank, String name) + { + return this.BOSEconomy.isBankOwner(bank, name) || this.BOSEconomy.isBankMember(bank, name); + } + + public MethodAccount getAccount(String name) + { + if (!hasAccount(name)) + { + return null; + } + + return new BOSEAccount(name, this.BOSEconomy); + } + + public MethodBankAccount getBankAccount(String bank, String name) + { + if (!hasBankAccount(bank, name)) + { + return null; + } + + return new BOSEBankAccount(bank, BOSEconomy); + } + + public boolean isCompatible(Plugin plugin) + { + return plugin.getDescription().getName().equalsIgnoreCase("boseconomy") + && plugin instanceof BOSEconomy + && !plugin.getDescription().getVersion().equals("0.6.2"); + } + + public void setPlugin(Plugin plugin) + { + BOSEconomy = (BOSEconomy)plugin; + } + + + public class BOSEAccount implements MethodAccount + { + private String name; + private BOSEconomy BOSEconomy; + + public BOSEAccount(String name, BOSEconomy bOSEconomy) + { + this.name = name; + this.BOSEconomy = bOSEconomy; + } + + public double balance() + { + return this.BOSEconomy.getPlayerMoneyDouble(this.name); + } + + public boolean set(double amount) + { + return this.BOSEconomy.setPlayerMoney(this.name, amount, false); + } + + public boolean add(double amount) + { + return this.BOSEconomy.addPlayerMoney(this.name, amount, false); + } + + public boolean subtract(double amount) + { + double balance = this.balance(); + return this.BOSEconomy.setPlayerMoney(this.name, (balance - amount), false); + } + + public boolean multiply(double amount) + { + double balance = this.balance(); + return this.BOSEconomy.setPlayerMoney(this.name, (balance * amount), false); + } + + public boolean divide(double amount) + { + double balance = this.balance(); + return this.BOSEconomy.setPlayerMoney(this.name, (balance / amount), false); + } + + public boolean hasEnough(double amount) + { + return (this.balance() >= amount); + } + + public boolean hasOver(double amount) + { + return (this.balance() > amount); + } + + public boolean hasUnder(double amount) + { + return (this.balance() < amount); + } + + public boolean isNegative() + { + return (this.balance() < 0); + } + + public boolean remove() + { + return false; + } + } + + + public class BOSEBankAccount implements MethodBankAccount + { + private String bank; + private BOSEconomy BOSEconomy; + + public BOSEBankAccount(String bank, BOSEconomy bOSEconomy) + { + this.bank = bank; + this.BOSEconomy = bOSEconomy; + } + + public String getBankName() + { + return this.bank; + } + + public int getBankId() + { + return -1; + } + + public double balance() + { + return this.BOSEconomy.getBankMoneyDouble(bank); + } + + public boolean set(double amount) + { + return this.BOSEconomy.setBankMoney(bank, amount, true); + } + + public boolean add(double amount) + { + double balance = this.balance(); + return this.BOSEconomy.setBankMoney(bank, (balance + amount), false); + } + + public boolean subtract(double amount) + { + double balance = this.balance(); + return this.BOSEconomy.setBankMoney(bank, (balance - amount), false); + } + + public boolean multiply(double amount) + { + double balance = this.balance(); + return this.BOSEconomy.setBankMoney(bank, (balance * amount), false); + } + + public boolean divide(double amount) + { + double balance = this.balance(); + return this.BOSEconomy.setBankMoney(bank, (balance / amount), false); + } + + public boolean hasEnough(double amount) + { + return (this.balance() >= amount); + } + + public boolean hasOver(double amount) + { + return (this.balance() > amount); + } + + public boolean hasUnder(double amount) + { + return (this.balance() < amount); + } + + public boolean isNegative() + { + return (this.balance() < 0); + } + + public boolean remove() + { + return this.BOSEconomy.removeBank(bank); + } + } } \ No newline at end of file diff --git a/Essentials/src/com/earth2me/essentials/register/payment/methods/MCUR.java b/Essentials/src/com/earth2me/essentials/register/payment/methods/MCUR.java index 8ea709c19..6248b1b91 100644 --- a/Essentials/src/com/earth2me/essentials/register/payment/methods/MCUR.java +++ b/Essentials/src/com/earth2me/essentials/register/payment/methods/MCUR.java @@ -7,6 +7,7 @@ import me.ashtheking.currency.CurrencyList; import org.bukkit.plugin.Plugin; + /** * MultiCurrency Method implementation. * @@ -14,107 +15,141 @@ import org.bukkit.plugin.Plugin; * @copyright (c) 2011 * @license AOL license */ -public class MCUR implements Method { - private Currency currencyList; - - public Object getPlugin() { - return this.currencyList; - } - - public String getName() { - return "MultiCurrency"; - } - - public String getVersion() { - return "0.09"; - } - - public String format(double amount) { - return amount + " Currency"; - } - - public boolean hasBanks() { - return false; - } - - public boolean hasBank(String bank) { - return false; - } - - public boolean hasAccount(String name) { - return true; - } - - public boolean hasBankAccount(String bank, String name) { - return false; - } - - public MethodAccount getAccount(String name) { - return new MCurrencyAccount(name); - } - - public MethodBankAccount getBankAccount(String bank, String name) { - return null; - } - - public boolean isCompatible(Plugin plugin) { - return plugin.getDescription().getName().equalsIgnoreCase(getName()) && plugin instanceof Currency; - } - - public void setPlugin(Plugin plugin) { - currencyList = (Currency) plugin; - } - - public class MCurrencyAccount implements MethodAccount{ - private String name; - - public MCurrencyAccount(String name) { - this.name = name; - } - - public double balance() { - return CurrencyList.getValue((String) CurrencyList.maxCurrency(name)[0], name); - } - - public boolean set(double amount) { - CurrencyList.setValue((String) CurrencyList.maxCurrency(name)[0], name, amount); - return true; - } - - public boolean add(double amount) { - return CurrencyList.add(name, amount); - } - - public boolean subtract(double amount) { - return CurrencyList.subtract(name, amount); - } - - public boolean multiply(double amount) { - return CurrencyList.multiply(name, amount); - } - - public boolean divide(double amount) { - return CurrencyList.divide(name, amount); - } - - public boolean hasEnough(double amount) { - return CurrencyList.hasEnough(name, amount); - } - - public boolean hasOver(double amount) { - return CurrencyList.hasOver(name, amount); - } - - public boolean hasUnder(double amount) { - return CurrencyList.hasUnder(name, amount); - } - - public boolean isNegative() { - return CurrencyList.isNegative(name); - } - - public boolean remove() { - return CurrencyList.remove(name); - } - } +public class MCUR implements Method +{ + private Currency currencyList; + + public Object getPlugin() + { + return this.currencyList; + } + + public String getName() + { + return "MultiCurrency"; + } + + public String getVersion() + { + return "0.09"; + } + + public int fractionalDigits() + { + return -1; + } + + public String format(double amount) + { + return amount + " Currency"; + } + + public boolean hasBanks() + { + return false; + } + + public boolean hasBank(String bank) + { + return false; + } + + public boolean hasAccount(String name) + { + return true; + } + + public boolean hasBankAccount(String bank, String name) + { + return false; + } + + public MethodAccount getAccount(String name) + { + return new MCurrencyAccount(name); + } + + public MethodBankAccount getBankAccount(String bank, String name) + { + return null; + } + + public boolean isCompatible(Plugin plugin) + { + return (plugin.getDescription().getName().equalsIgnoreCase("Currency") + || plugin.getDescription().getName().equalsIgnoreCase("MultiCurrency")) + && plugin instanceof Currency; + } + + public void setPlugin(Plugin plugin) + { + currencyList = (Currency)plugin; + } + + + public class MCurrencyAccount implements MethodAccount + { + private String name; + + public MCurrencyAccount(String name) + { + this.name = name; + } + + public double balance() + { + return CurrencyList.getValue((String)CurrencyList.maxCurrency(name)[0], name); + } + + public boolean set(double amount) + { + CurrencyList.setValue((String)CurrencyList.maxCurrency(name)[0], name, amount); + return true; + } + + public boolean add(double amount) + { + return CurrencyList.add(name, amount); + } + + public boolean subtract(double amount) + { + return CurrencyList.subtract(name, amount); + } + + public boolean multiply(double amount) + { + return CurrencyList.multiply(name, amount); + } + + public boolean divide(double amount) + { + return CurrencyList.divide(name, amount); + } + + public boolean hasEnough(double amount) + { + return CurrencyList.hasEnough(name, amount); + } + + public boolean hasOver(double amount) + { + return CurrencyList.hasOver(name, amount); + } + + public boolean hasUnder(double amount) + { + return CurrencyList.hasUnder(name, amount); + } + + public boolean isNegative() + { + return CurrencyList.isNegative(name); + } + + public boolean remove() + { + return CurrencyList.remove(name); + } + } } diff --git a/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo4.java b/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo4.java index 933959586..fcdb7c43b 100644 --- a/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo4.java +++ b/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo4.java @@ -1,12 +1,13 @@ package com.earth2me.essentials.register.payment.methods; +import com.earth2me.essentials.register.payment.Method; import com.nijiko.coelho.iConomy.iConomy; import com.nijiko.coelho.iConomy.system.Account; -import com.earth2me.essentials.register.payment.Method; import org.bukkit.plugin.Plugin; + /** * iConomy 4 Implementation of Method * @@ -14,122 +15,175 @@ import org.bukkit.plugin.Plugin; * @copyright (c) 2011 * @license AOL license */ -public class iCo4 implements Method { - private iConomy iConomy; - - public iConomy getPlugin() { - return this.iConomy; - } - - public String getName() { - return "iConomy"; - } - - public String getVersion() { - return "4"; - } - - public String format(double amount) { - return this.iConomy.getBank().format(amount); - } - - public boolean hasBanks() { - return false; - } - - public boolean hasBank(String bank) { - return false; - } - - public boolean hasAccount(String name) { - return this.iConomy.getBank().hasAccount(name); - } - - public boolean hasBankAccount(String bank, String name) { - return false; - } - - public MethodAccount getAccount(String name) { - return new iCoAccount(this.iConomy.getBank().getAccount(name)); - } - - public MethodBankAccount getBankAccount(String bank, String name) { - return null; - } - - public boolean isCompatible(Plugin plugin) { - return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && plugin.getClass().getName().equals("com.nijiko.coelho.iConomy.iConomy") && plugin instanceof iConomy; - } - - public void setPlugin(Plugin plugin) { - iConomy = (iConomy)plugin; - } - - public class iCoAccount implements MethodAccount { - private Account account; - - public iCoAccount(Account account) { - this.account = account; - } - - public Account getiCoAccount() { - return account; - } - - public double balance() { - return this.account.getBalance(); - } - - public boolean set(double amount) { - if(this.account == null) return false; - this.account.setBalance(amount); - return true; - } - - public boolean add(double amount) { - if(this.account == null) return false; - this.account.add(amount); - return true; - } - - public boolean subtract(double amount) { - if(this.account == null) return false; - this.account.subtract(amount); - return true; - } - - public boolean multiply(double amount) { - if(this.account == null) return false; - this.account.multiply(amount); - return true; - } - - public boolean divide(double amount) { - if(this.account == null) return false; - this.account.divide(amount); - return true; - } - - public boolean hasEnough(double amount) { - return this.account.hasEnough(amount); - } - - public boolean hasOver(double amount) { - return this.account.hasOver(amount); - } - - public boolean hasUnder(double amount) { - return (this.balance() < amount); - } - - public boolean isNegative() { - return this.account.isNegative(); - } - - public boolean remove() { - if(this.account == null) return false; - this.account.remove(); - return true; - } - } +public class iCo4 implements Method +{ + private iConomy iConomy; + + public iConomy getPlugin() + { + return this.iConomy; + } + + public String getName() + { + return "iConomy"; + } + + public String getVersion() + { + return "4"; + } + + public int fractionalDigits() + { + return 2; + } + + public String format(double amount) + { + return com.nijiko.coelho.iConomy.iConomy.getBank().format(amount); + } + + public boolean hasBanks() + { + return false; + } + + public boolean hasBank(String bank) + { + return false; + } + + public boolean hasAccount(String name) + { + return com.nijiko.coelho.iConomy.iConomy.getBank().hasAccount(name); + } + + public boolean hasBankAccount(String bank, String name) + { + return false; + } + + public MethodAccount getAccount(String name) + { + return new iCoAccount(com.nijiko.coelho.iConomy.iConomy.getBank().getAccount(name)); + } + + public MethodBankAccount getBankAccount(String bank, String name) + { + return null; + } + + public boolean isCompatible(Plugin plugin) + { + return plugin.getDescription().getName().equalsIgnoreCase("iconomy") + && plugin.getClass().getName().equals("com.nijiko.coelho.iConomy.iConomy") + && plugin instanceof iConomy; + } + + public void setPlugin(Plugin plugin) + { + iConomy = (iConomy)plugin; + } + + + public class iCoAccount implements MethodAccount + { + private Account account; + + public iCoAccount(Account account) + { + this.account = account; + } + + public Account getiCoAccount() + { + return account; + } + + public double balance() + { + return this.account.getBalance(); + } + + public boolean set(double amount) + { + if (this.account == null) + { + return false; + } + this.account.setBalance(amount); + return true; + } + + public boolean add(double amount) + { + if (this.account == null) + { + return false; + } + this.account.add(amount); + return true; + } + + public boolean subtract(double amount) + { + if (this.account == null) + { + return false; + } + this.account.subtract(amount); + return true; + } + + public boolean multiply(double amount) + { + if (this.account == null) + { + return false; + } + this.account.multiply(amount); + return true; + } + + public boolean divide(double amount) + { + if (this.account == null) + { + return false; + } + this.account.divide(amount); + return true; + } + + public boolean hasEnough(double amount) + { + return this.account.hasEnough(amount); + } + + public boolean hasOver(double amount) + { + return this.account.hasOver(amount); + } + + public boolean hasUnder(double amount) + { + return (this.balance() < amount); + } + + public boolean isNegative() + { + return this.account.isNegative(); + } + + public boolean remove() + { + if (this.account == null) + { + return false; + } + this.account.remove(); + return true; + } + } } diff --git a/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo5.java b/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo5.java index bcd6deb6d..462cb76d5 100644 --- a/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo5.java +++ b/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo5.java @@ -1,12 +1,12 @@ package com.earth2me.essentials.register.payment.methods; +import com.earth2me.essentials.register.payment.Method; import com.iConomy.iConomy; import com.iConomy.system.Account; import com.iConomy.system.BankAccount; import com.iConomy.system.Holdings; import com.iConomy.util.Constants; -import com.earth2me.essentials.register.payment.Method; import org.bukkit.plugin.Plugin; @@ -37,9 +37,14 @@ public class iCo5 implements Method return "5"; } + public int fractionalDigits() + { + return 2; + } + public String format(double amount) { - return this.iConomy.format(amount); + return com.iConomy.iConomy.format(amount); } public boolean hasBanks() @@ -49,32 +54,34 @@ public class iCo5 implements Method public boolean hasBank(String bank) { - return (hasBanks()) && this.iConomy.Banks.exists(bank); + return (hasBanks()) && com.iConomy.iConomy.Banks.exists(bank); } public boolean hasAccount(String name) { - return this.iConomy.hasAccount(name); + return com.iConomy.iConomy.hasAccount(name); } public boolean hasBankAccount(String bank, String name) { - return (hasBank(bank)) && this.iConomy.getBank(bank).hasAccount(name); + return (hasBank(bank)) && com.iConomy.iConomy.getBank(bank).hasAccount(name); } public MethodAccount getAccount(String name) { - return new iCoAccount(this.iConomy.getAccount(name)); + return new iCoAccount(com.iConomy.iConomy.getAccount(name)); } public MethodBankAccount getBankAccount(String bank, String name) { - return new iCoBankAccount(this.iConomy.getBank(bank).getAccount(name)); + return new iCoBankAccount(com.iConomy.iConomy.getBank(bank).getAccount(name)); } public boolean isCompatible(Plugin plugin) { - return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && plugin.getClass().getName().equals("com.iConomy.iConomy") && plugin instanceof iConomy; + return plugin.getDescription().getName().equalsIgnoreCase("iconomy") + && plugin.getClass().getName().equals("com.iConomy.iConomy") + && plugin instanceof iConomy; } public void setPlugin(Plugin plugin) diff --git a/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo6.java b/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo6.java index d890bc6df..b74367173 100644 --- a/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo6.java +++ b/Essentials/src/com/earth2me/essentials/register/payment/methods/iCo6.java @@ -1,14 +1,15 @@ package com.earth2me.essentials.register.payment.methods; +import com.earth2me.essentials.register.payment.Method; import com.iCo6.iConomy; import com.iCo6.system.Account; import com.iCo6.system.Accounts; import com.iCo6.system.Holdings; -import com.earth2me.essentials.register.payment.Method; import org.bukkit.plugin.Plugin; + /** * iConomy 6 Implementation of Method * @@ -16,127 +17,177 @@ import org.bukkit.plugin.Plugin; * @copyright (c) 2011 * @license AOL license */ -public class iCo6 implements Method { - private iConomy iConomy; - - public iConomy getPlugin() { - return this.iConomy; - } - - public String getName() { - return "iConomy"; - } - - public String getVersion() { - return "6"; - } - - public String format(double amount) { - return this.iConomy.format(amount); - } - - public boolean hasBanks() { - return false; - } - - public boolean hasBank(String bank) { - return false; - } - - public boolean hasAccount(String name) { - return (new Accounts()).exists(name); - } - - public boolean hasBankAccount(String bank, String name) { - return false; - } - - public MethodAccount getAccount(String name) { - return new iCoAccount((new Accounts()).get(name)); - } - - public MethodBankAccount getBankAccount(String bank, String name) { - return null; - } - - public boolean isCompatible(Plugin plugin) { - try { Class.forName("com.iCo6.IO"); } - catch(Exception e) { return false; } - - return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && plugin.getClass().getName().equals("com.iCo6.iConomy") && plugin instanceof iConomy; - } - - public void setPlugin(Plugin plugin) { - iConomy = (iConomy)plugin; - } - - public class iCoAccount implements MethodAccount { - private Account account; - private Holdings holdings; - - public iCoAccount(Account account) { - this.account = account; - this.holdings = account.getHoldings(); - } - - public Account getiCoAccount() { - return account; - } - - public double balance() { - return this.holdings.getBalance(); - } - - public boolean set(double amount) { - if(this.holdings == null) return false; - this.holdings.setBalance(amount); - return true; - } - - public boolean add(double amount) { - if(this.holdings == null) return false; - this.holdings.add(amount); - return true; - } - - public boolean subtract(double amount) { - if(this.holdings == null) return false; - this.holdings.subtract(amount); - return true; - } - - public boolean multiply(double amount) { - if(this.holdings == null) return false; - this.holdings.multiply(amount); - return true; - } - - public boolean divide(double amount) { - if(this.holdings == null) return false; - this.holdings.divide(amount); - return true; - } - - public boolean hasEnough(double amount) { - return this.holdings.hasEnough(amount); - } - - public boolean hasOver(double amount) { - return this.holdings.hasOver(amount); - } - - public boolean hasUnder(double amount) { - return this.holdings.hasUnder(amount); - } - - public boolean isNegative() { - return this.holdings.isNegative(); - } - - public boolean remove() { - if(this.account == null) return false; - this.account.remove(); - return true; - } - } +public class iCo6 implements Method +{ + private iConomy iConomy; + + public iConomy getPlugin() + { + return this.iConomy; + } + + public String getName() + { + return "iConomy"; + } + + public String getVersion() + { + return "6"; + } + + public int fractionalDigits() + { + return 2; + } + + public String format(double amount) + { + return com.iCo6.iConomy.format(amount); + } + + public boolean hasBanks() + { + return false; + } + + public boolean hasBank(String bank) + { + return false; + } + + public boolean hasAccount(String name) + { + return (new Accounts()).exists(name); + } + + public boolean hasBankAccount(String bank, String name) + { + return false; + } + + public MethodAccount getAccount(String name) + { + return new iCoAccount((new Accounts()).get(name)); + } + + public MethodBankAccount getBankAccount(String bank, String name) + { + return null; + } + + public boolean isCompatible(Plugin plugin) + { + return plugin.getDescription().getName().equalsIgnoreCase("iconomy") + && plugin.getClass().getName().equals("com.iCo6.iConomy") + && plugin instanceof iConomy; + } + + public void setPlugin(Plugin plugin) + { + iConomy = (iConomy)plugin; + } + + + public class iCoAccount implements MethodAccount + { + private Account account; + private Holdings holdings; + + public iCoAccount(Account account) + { + this.account = account; + this.holdings = account.getHoldings(); + } + + public Account getiCoAccount() + { + return account; + } + + public double balance() + { + return this.holdings.getBalance(); + } + + public boolean set(double amount) + { + if (this.holdings == null) + { + return false; + } + this.holdings.setBalance(amount); + return true; + } + + public boolean add(double amount) + { + if (this.holdings == null) + { + return false; + } + this.holdings.add(amount); + return true; + } + + public boolean subtract(double amount) + { + if (this.holdings == null) + { + return false; + } + this.holdings.subtract(amount); + return true; + } + + public boolean multiply(double amount) + { + if (this.holdings == null) + { + return false; + } + this.holdings.multiply(amount); + return true; + } + + public boolean divide(double amount) + { + if (this.holdings == null) + { + return false; + } + this.holdings.divide(amount); + return true; + } + + public boolean hasEnough(double amount) + { + return this.holdings.hasEnough(amount); + } + + public boolean hasOver(double amount) + { + return this.holdings.hasOver(amount); + } + + public boolean hasUnder(double amount) + { + return this.holdings.hasUnder(amount); + } + + public boolean isNegative() + { + return this.holdings.isNegative(); + } + + public boolean remove() + { + if (this.account == null) + { + return false; + } + this.account.remove(); + return true; + } + } } -- cgit v1.2.3 From 223ae8c87b189c542f9f797c39df5d27a84912f0 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Mon, 26 Sep 2011 22:37:14 +0100 Subject: BanIP fixed, work around for isBanned. --- .../src/com/earth2me/essentials/EssentialsPlayerListener.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index 9ba02b5c3..2c93bb402 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -307,6 +307,7 @@ public class EssentialsPlayerListener extends PlayerListener { if (event.getResult() != Result.ALLOWED && event.getResult() != Result.KICK_FULL && event.getResult() != Result.KICK_BANNED) { + LOGGER.log(Level.INFO, "Disconnecting user " + event.getPlayer().toString() + " due to " + event.getResult().toString()); return; } User user = ess.getUser(event.getPlayer()); @@ -316,11 +317,12 @@ public class EssentialsPlayerListener extends PlayerListener user.checkBanTimeout(currentTime); user.checkMuteTimeout(currentTime); user.checkJailTimeout(currentTime); - - if (user.isBanned()) + + if (user.isBanned() || event.getResult() == Result.KICK_BANNED) { final String banReason = user.getBanReason(); - event.disallow(Result.KICK_BANNED, banReason != null && !banReason.isEmpty() ? banReason : Util.i18n("defaultBanReason")); + LOGGER.log(Level.INFO, "Banned for '" + banReason + "'"); + event.disallow(Result.KICK_BANNED, banReason != null && !banReason.isEmpty() && !banReason.equalsIgnoreCase("ban") ? banReason : Util.i18n("defaultBanReason")); return; } -- cgit v1.2.3 From ce6586e0bb2ec3654c8195af751aa5520843b264 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Mon, 26 Sep 2011 23:37:00 +0100 Subject: Make sure we don't bounce people with expired tempbans. --- .../com/earth2me/essentials/EssentialsPlayerListener.java | 10 +++++----- Essentials/src/com/earth2me/essentials/User.java | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index 2c93bb402..54efe1af1 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -108,7 +108,8 @@ public class EssentialsPlayerListener extends PlayerListener } Location afk = user.getAfkPosition(); - if (afk == null || !event.getTo().getWorld().equals(afk.getWorld()) || afk.distanceSquared(event.getTo()) > 9) { + if (afk == null || !event.getTo().getWorld().equals(afk.getWorld()) || afk.distanceSquared(event.getTo()) > 9) + { user.updateActivity(true); } @@ -314,14 +315,13 @@ public class EssentialsPlayerListener extends PlayerListener user.setNPC(false); final long currentTime = System.currentTimeMillis(); - user.checkBanTimeout(currentTime); + boolean banExpired = user.checkBanTimeout(currentTime); user.checkMuteTimeout(currentTime); user.checkJailTimeout(currentTime); - - if (user.isBanned() || event.getResult() == Result.KICK_BANNED) + + if (banExpired == false && (user.isBanned() || event.getResult() == Result.KICK_BANNED)) { final String banReason = user.getBanReason(); - LOGGER.log(Level.INFO, "Banned for '" + banReason + "'"); event.disallow(Result.KICK_BANNED, banReason != null && !banReason.isEmpty() && !banReason.equalsIgnoreCase("ban") ? banReason : Util.i18n("defaultBanReason")); return; } diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java index 736274de0..3b57f48fd 100644 --- a/Essentials/src/com/earth2me/essentials/User.java +++ b/Essentials/src/com/earth2me/essentials/User.java @@ -381,7 +381,8 @@ public class User extends UserData implements Comparable, IReplyTo, IUser this.hidden = hidden; } - public void checkJailTimeout(final long currentTime) + //Returns true if status expired during this check + public boolean checkJailTimeout(final long currentTime) { if (getJailTimeout() > 0 && getJailTimeout() < currentTime && isJailed()) { @@ -396,26 +397,34 @@ public class User extends UserData implements Comparable, IReplyTo, IUser catch (Exception ex) { } + return true; } + return false; } - public void checkMuteTimeout(final long currentTime) + //Returns true if status expired during this check + public boolean checkMuteTimeout(final long currentTime) { if (getMuteTimeout() > 0 && getMuteTimeout() < currentTime && isMuted()) { setMuteTimeout(0); sendMessage(Util.i18n("canTalkAgain")); setMuted(false); + return true; } + return false; } - public void checkBanTimeout(final long currentTime) + //Returns true if status expired during this check + public boolean checkBanTimeout(final long currentTime) { if (getBanTimeout() > 0 && getBanTimeout() < currentTime && isBanned()) { setBanTimeout(0); setBanned(false); + return true; } + return false; } public void updateActivity(final boolean broadcast) -- cgit v1.2.3 From 821a7bf104fdfe8ca5177120a53a7ebc00813d8c Mon Sep 17 00:00:00 2001 From: snowleo Date: Thu, 29 Sep 2011 01:10:54 +0200 Subject: Allow both essentials.build and permissions.build in PermissionsBukkit --- .../src/com/earth2me/essentials/perm/BPermissionsHandler.java | 2 +- .../src/com/earth2me/essentials/perm/PermissionsBukkitHandler.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Essentials/src/com/earth2me/essentials/perm/BPermissionsHandler.java b/Essentials/src/com/earth2me/essentials/perm/BPermissionsHandler.java index 6914c2816..b30a7c0c7 100644 --- a/Essentials/src/com/earth2me/essentials/perm/BPermissionsHandler.java +++ b/Essentials/src/com/earth2me/essentials/perm/BPermissionsHandler.java @@ -55,7 +55,7 @@ public class BPermissionsHandler implements IPermissionsHandler @Override public boolean canBuild(final Player base, final String group) { - return hasPermission(base, "bPermissions.build"); + return hasPermission(base, "essentials.build") || hasPermission(base, "bPermissions.build"); } @Override diff --git a/Essentials/src/com/earth2me/essentials/perm/PermissionsBukkitHandler.java b/Essentials/src/com/earth2me/essentials/perm/PermissionsBukkitHandler.java index d47c3c8a4..b3cc62979 100644 --- a/Essentials/src/com/earth2me/essentials/perm/PermissionsBukkitHandler.java +++ b/Essentials/src/com/earth2me/essentials/perm/PermissionsBukkitHandler.java @@ -74,4 +74,10 @@ public class PermissionsBukkitHandler extends SuperpermsHandler } return false; } + + @Override + public boolean canBuild(Player base, String group) + { + return base.hasPermission("essentials.build") || base.hasPermission("permissions.build"); + } } -- cgit v1.2.3 From e06e8cddcf56357ed39ccbcd3b85fd272238012d Mon Sep 17 00:00:00 2001 From: ementalo Date: Thu, 29 Sep 2011 00:24:52 +0100 Subject: Fix freezeafk so that moving with mouse does not teleport you about. Add check for if some takes the ground away from you --- .../essentials/EssentialsPlayerListener.java | 979 ++++++++++----------- 1 file changed, 486 insertions(+), 493 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index 54efe1af1..6d97bc17d 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -1,493 +1,486 @@ -package com.earth2me.essentials; - -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Server; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.event.block.Action; -import org.bukkit.event.player.PlayerAnimationEvent; -import org.bukkit.event.player.PlayerAnimationType; -import org.bukkit.event.player.PlayerBucketEmptyEvent; -import org.bukkit.event.player.PlayerChatEvent; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.player.PlayerEggThrowEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerListener; -import org.bukkit.event.player.PlayerLoginEvent; -import org.bukkit.event.player.PlayerLoginEvent.Result; -import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.player.PlayerRespawnEvent; -import org.bukkit.event.player.PlayerTeleportEvent; -import org.bukkit.inventory.ItemStack; - - -public class EssentialsPlayerListener extends PlayerListener -{ - private static final Logger LOGGER = Logger.getLogger("Minecraft"); - private final transient Server server; - private final transient IEssentials ess; - - public EssentialsPlayerListener(final IEssentials parent) - { - this.ess = parent; - this.server = parent.getServer(); - } - - @Override - public void onPlayerRespawn(final PlayerRespawnEvent event) - { - final User user = ess.getUser(event.getPlayer()); - user.setDisplayName(user.getNick()); - updateCompass(user); - if (ess.getSettings().changeDisplayName()) - { - user.setDisplayName(user.getNick()); - } - } - - @Override - public void onPlayerChat(final PlayerChatEvent event) - { - final User user = ess.getUser(event.getPlayer()); - if (user.isMuted()) - { - event.setCancelled(true); - user.sendMessage(Util.i18n("playerMuted")); - LOGGER.info(Util.format("mutedUserSpeaks", user.getName())); - } - final Iterator it = event.getRecipients().iterator(); - while (it.hasNext()) - { - final User u = ess.getUser(it.next()); - if (u.isIgnoredPlayer(user.getName())) - { - it.remove(); - } - } - user.updateActivity(true); - if (ess.getSettings().changeDisplayName()) - { - user.setDisplayName(user.getNick()); - } - } - - @Override - public void onPlayerMove(final PlayerMoveEvent event) - { - if (event.isCancelled()) - { - return; - } - final User user = ess.getUser(event.getPlayer()); - - if (user.isAfk() && ess.getSettings().getFreezeAfkPlayers()) - { - final Location from = event.getFrom(); - final Location to = event.getTo().clone(); - to.setX(from.getX()); - to.setY(from.getY()); - to.setZ(from.getZ()); - try - { - event.setTo(Util.getSafeDestination(to)); - } - catch (Exception ex) - { - event.setTo(to); - } - return; - } - - Location afk = user.getAfkPosition(); - if (afk == null || !event.getTo().getWorld().equals(afk.getWorld()) || afk.distanceSquared(event.getTo()) > 9) - { - user.updateActivity(true); - } - - if (!ess.getSettings().getNetherPortalsEnabled()) - { - return; - } - - final Block block = event.getPlayer().getWorld().getBlockAt(event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ()); - final List worlds = server.getWorlds(); - - if (block.getType() == Material.PORTAL && worlds.size() > 1 && user.isAuthorized("essentials.portal")) - { - if (user.getJustPortaled()) - { - return; - } - - World nether = server.getWorld(ess.getSettings().getNetherName()); - if (nether == null) - { - for (World world : worlds) - { - if (world.getEnvironment() == World.Environment.NETHER) - { - nether = world; - break; - } - } - if (nether == null) - { - return; - } - } - final World world = user.getWorld() == nether ? worlds.get(0) : nether; - - double factor; - if (user.getWorld().getEnvironment() == World.Environment.NETHER && world.getEnvironment() == World.Environment.NORMAL) - { - factor = ess.getSettings().getNetherRatio(); - } - else if (user.getWorld().getEnvironment() == World.Environment.NORMAL && world.getEnvironment() == World.Environment.NETHER) - { - factor = 1.0 / ess.getSettings().getNetherRatio(); - } - else - { - factor = 1.0; - } - - Location loc = event.getTo(); - int x = loc.getBlockX(); - int y = loc.getBlockY(); - int z = loc.getBlockZ(); - - if (user.getWorld().getBlockAt(x, y, z - 1).getType() == Material.PORTAL) - { - z--; - } - if (user.getWorld().getBlockAt(x - 1, y, z).getType() == Material.PORTAL) - { - x--; - } - - x = (int)(x * factor); - z = (int)(z * factor); - loc = new Location(world, x + .5, y, z + .5); - - Block dest = world.getBlockAt(x, y, z); - NetherPortal portal = NetherPortal.findPortal(dest); - if (portal == null) - { - if (world.getEnvironment() == World.Environment.NETHER || ess.getSettings().getGenerateExitPortals()) - { - portal = NetherPortal.createPortal(dest); - LOGGER.info(Util.format("userCreatedPortal", event.getPlayer().getName())); - user.sendMessage(Util.i18n("generatingPortal")); - loc = portal.getSpawn(); - } - } - else - { - LOGGER.info(Util.format("userUsedPortal", event.getPlayer().getName())); - user.sendMessage(Util.i18n("usingPortal")); - loc = portal.getSpawn(); - } - - event.setFrom(loc); - event.setTo(loc); - try - { - user.getTeleport().now(loc, new Trade("portal", ess)); - } - catch (Exception ex) - { - user.sendMessage(ex.getMessage()); - } - user.setJustPortaled(true); - user.sendMessage(Util.i18n("teleportingPortal")); - - event.setCancelled(true); - return; - } - - user.setJustPortaled(false); - } - - @Override - public void onPlayerQuit(final PlayerQuitEvent event) - { - final User user = ess.getUser(event.getPlayer()); - if (ess.getSettings().removeGodOnDisconnect() && user.isGodModeEnabled()) - { - user.toggleGodModeEnabled(); - } - if (user.getSavedInventory() != null) - { - user.getInventory().setContents(user.getSavedInventory()); - user.setSavedInventory(null); - } - user.updateActivity(false); - user.dispose(); - if (!ess.getSettings().getReclaimSetting()) - { - return; - } - final Thread thread = new Thread(new Runnable() - { - public void run() - { - try - { - Thread.sleep(1000); - Runtime rt = Runtime.getRuntime(); - double mem = rt.freeMemory(); - rt.runFinalization(); - rt.gc(); - mem = rt.freeMemory() - mem; - mem /= 1024 * 1024; - LOGGER.log(Level.INFO, Util.format("freedMemory", mem)); - } - catch (InterruptedException ex) - { - return; - } - } - }); - thread.setPriority(Thread.MIN_PRIORITY); - thread.start(); - } - - @Override - public void onPlayerJoin(final PlayerJoinEvent event) - { - ess.getBackup().onPlayerJoin(); - final User user = ess.getUser(event.getPlayer()); - - if (ess.getSettings().changeDisplayName()) - { - user.setDisplayName(user.getNick()); - } - user.updateActivity(false); - if (user.isAuthorized("essentials.sleepingignored")) - { - user.setSleepingIgnored(true); - } - - if (!ess.getSettings().isCommandDisabled("motd") && user.isAuthorized("essentials.motd")) - { - for (String m : ess.getMotd(user, null)) - { - if (m == null) - { - continue; - } - user.sendMessage(m); - } - } - - if (!ess.getSettings().isCommandDisabled("mail") && user.isAuthorized("essentials.mail")) - { - final List mail = user.getMails(); - if (mail.isEmpty()) - { - user.sendMessage(Util.i18n("noNewMail")); - } - else - { - user.sendMessage(Util.format("youHaveNewMail", mail.size())); - } - } - } - - @Override - public void onPlayerLogin(final PlayerLoginEvent event) - { - if (event.getResult() != Result.ALLOWED && event.getResult() != Result.KICK_FULL && event.getResult() != Result.KICK_BANNED) - { - LOGGER.log(Level.INFO, "Disconnecting user " + event.getPlayer().toString() + " due to " + event.getResult().toString()); - return; - } - User user = ess.getUser(event.getPlayer()); - user.setNPC(false); - - final long currentTime = System.currentTimeMillis(); - boolean banExpired = user.checkBanTimeout(currentTime); - user.checkMuteTimeout(currentTime); - user.checkJailTimeout(currentTime); - - if (banExpired == false && (user.isBanned() || event.getResult() == Result.KICK_BANNED)) - { - final String banReason = user.getBanReason(); - event.disallow(Result.KICK_BANNED, banReason != null && !banReason.isEmpty() && !banReason.equalsIgnoreCase("ban") ? banReason : Util.i18n("defaultBanReason")); - return; - } - - if (server.getOnlinePlayers().length >= server.getMaxPlayers() && !user.isAuthorized("essentials.joinfullserver")) - { - event.disallow(Result.KICK_FULL, Util.i18n("serverFull")); - return; - } - event.allow(); - - user.setLastLogin(System.currentTimeMillis()); - updateCompass(user); - } - - private void updateCompass(final User user) - { - try - { - user.setCompassTarget(user.getHome(user.getLocation())); - } - catch (Exception ex) - { - } - } - - @Override - public void onPlayerTeleport(PlayerTeleportEvent event) - { - if (event.isCancelled()) - { - return; - } - final User user = ess.getUser(event.getPlayer()); - if (ess.getSettings().changeDisplayName()) - { - user.setDisplayName(user.getNick()); - } - updateCompass(user); - } - - @Override - public void onPlayerInteract(final PlayerInteractEvent event) - { - if (event.isCancelled()) - { - return; - } - if (event.getAction() != Action.RIGHT_CLICK_BLOCK) - { - return; - } - - if (ess.getSettings().getBedSetsHome() && event.getClickedBlock().getType() == Material.BED_BLOCK) - { - try - { - final User user = ess.getUser(event.getPlayer()); - user.setHome(); - user.sendMessage(Util.i18n("homeSetToBed")); - } - catch (Throwable ex) - { - } - } - } - - @Override - public void onPlayerEggThrow(final PlayerEggThrowEvent event) - { - final User user = ess.getUser(event.getPlayer()); - final ItemStack is = new ItemStack(Material.EGG, 1); - if (user.hasUnlimited(is)) - { - user.getInventory().addItem(is); - user.updateInventory(); - } - } - - @Override - public void onPlayerBucketEmpty(final PlayerBucketEmptyEvent event) - { - final User user = ess.getUser(event.getPlayer()); - if (user.hasUnlimited(new ItemStack(event.getBucket()))) - { - event.getItemStack().setType(event.getBucket()); - ess.scheduleSyncDelayedTask(new Runnable() - { - public void run() - { - user.updateInventory(); - } - }); - } - } - - @Override - public void onPlayerAnimation(final PlayerAnimationEvent event) - { - usePowertools(event); - } - - private void usePowertools(final PlayerAnimationEvent event) - { - if (event.getAnimationType() != PlayerAnimationType.ARM_SWING) - { - return; - } - final User user = ess.getUser(event.getPlayer()); - final ItemStack is = user.getItemInHand(); - if (is == null || is.getType() == Material.AIR || !user.arePowerToolsEnabled()) - { - return; - } - final List commandList = user.getPowertool(is); - if (commandList == null || commandList.isEmpty()) - { - return; - } - - // We need to loop through each command and execute - for (String command : commandList) - { - if (command.matches(".*\\{player\\}.*")) - { - //user.sendMessage("Click a player to use this command"); - continue; - } - else if (command.startsWith("c:")) - { - for (Player p : server.getOnlinePlayers()) - { - p.sendMessage(user.getDisplayName() + ":" + command.substring(2)); - } - } - else - { - user.getServer().dispatchCommand(event.getPlayer(), command); - } - } - } - - @Override - public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) - { - if (event.isCancelled()) - { - return; - } - final User user = ess.getUser(event.getPlayer()); - final String cmd = event.getMessage().toLowerCase().split(" ")[0].replace("/", "").toLowerCase(); - final List commands = Arrays.asList("msg", "r", "mail", "m", "t", "emsg", "tell", "er", "reply", "ereply", "email"); - if (commands.contains(cmd)) - { - for (Player player : ess.getServer().getOnlinePlayers()) - { - User spyer = ess.getUser(player); - if (spyer.isSocialSpyEnabled() && !user.equals(spyer)) - { - player.sendMessage(user.getDisplayName() + " : " + event.getMessage()); - } - } - } - if (!cmd.equalsIgnoreCase("afk")) - { - user.updateActivity(true); - } - } -} +package com.earth2me.essentials; + +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Server; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerAnimationEvent; +import org.bukkit.event.player.PlayerAnimationType; +import org.bukkit.event.player.PlayerBucketEmptyEvent; +import org.bukkit.event.player.PlayerChatEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerEggThrowEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerListener; +import org.bukkit.event.player.PlayerLoginEvent; +import org.bukkit.event.player.PlayerLoginEvent.Result; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.inventory.ItemStack; + + +public class EssentialsPlayerListener extends PlayerListener +{ + private static final Logger LOGGER = Logger.getLogger("Minecraft"); + private final transient Server server; + private final transient IEssentials ess; + + public EssentialsPlayerListener(final IEssentials parent) + { + this.ess = parent; + this.server = parent.getServer(); + } + + @Override + public void onPlayerRespawn(final PlayerRespawnEvent event) + { + final User user = ess.getUser(event.getPlayer()); + user.setDisplayName(user.getNick()); + updateCompass(user); + if (ess.getSettings().changeDisplayName()) + { + user.setDisplayName(user.getNick()); + } + } + + @Override + public void onPlayerChat(final PlayerChatEvent event) + { + final User user = ess.getUser(event.getPlayer()); + if (user.isMuted()) + { + event.setCancelled(true); + user.sendMessage(Util.i18n("playerMuted")); + LOGGER.info(Util.format("mutedUserSpeaks", user.getName())); + } + final Iterator it = event.getRecipients().iterator(); + while (it.hasNext()) + { + final User u = ess.getUser(it.next()); + if (u.isIgnoredPlayer(user.getName())) + { + it.remove(); + } + } + user.updateActivity(true); + if (ess.getSettings().changeDisplayName()) + { + user.setDisplayName(user.getNick()); + } + } + + @Override + public void onPlayerMove(final PlayerMoveEvent event) + { + if (event.isCancelled()) + { + return; + } + final User user = ess.getUser(event.getPlayer()); + + if (user.isAfk() && ess.getSettings().getFreezeAfkPlayers()) + { + final Location from = event.getFrom(); + final Location to = event.getTo().clone(); + to.setX(from.getX()); + to.setY(from.getBlock().getTypeId() == 0 ? from.getY() - 1 : from.getY()); + to.setZ(from.getZ()); + event.setTo(to); + return; + } + + Location afk = user.getAfkPosition(); + if (afk == null || !event.getTo().getWorld().equals(afk.getWorld()) || afk.distanceSquared(event.getTo()) > 9) + { + user.updateActivity(true); + } + + if (!ess.getSettings().getNetherPortalsEnabled()) + { + return; + } + + final Block block = event.getPlayer().getWorld().getBlockAt(event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ()); + final List worlds = server.getWorlds(); + + if (block.getType() == Material.PORTAL && worlds.size() > 1 && user.isAuthorized("essentials.portal")) + { + if (user.getJustPortaled()) + { + return; + } + + World nether = server.getWorld(ess.getSettings().getNetherName()); + if (nether == null) + { + for (World world : worlds) + { + if (world.getEnvironment() == World.Environment.NETHER) + { + nether = world; + break; + } + } + if (nether == null) + { + return; + } + } + final World world = user.getWorld() == nether ? worlds.get(0) : nether; + + double factor; + if (user.getWorld().getEnvironment() == World.Environment.NETHER && world.getEnvironment() == World.Environment.NORMAL) + { + factor = ess.getSettings().getNetherRatio(); + } + else if (user.getWorld().getEnvironment() == World.Environment.NORMAL && world.getEnvironment() == World.Environment.NETHER) + { + factor = 1.0 / ess.getSettings().getNetherRatio(); + } + else + { + factor = 1.0; + } + + Location loc = event.getTo(); + int x = loc.getBlockX(); + int y = loc.getBlockY(); + int z = loc.getBlockZ(); + + if (user.getWorld().getBlockAt(x, y, z - 1).getType() == Material.PORTAL) + { + z--; + } + if (user.getWorld().getBlockAt(x - 1, y, z).getType() == Material.PORTAL) + { + x--; + } + + x = (int)(x * factor); + z = (int)(z * factor); + loc = new Location(world, x + .5, y, z + .5); + + Block dest = world.getBlockAt(x, y, z); + NetherPortal portal = NetherPortal.findPortal(dest); + if (portal == null) + { + if (world.getEnvironment() == World.Environment.NETHER || ess.getSettings().getGenerateExitPortals()) + { + portal = NetherPortal.createPortal(dest); + LOGGER.info(Util.format("userCreatedPortal", event.getPlayer().getName())); + user.sendMessage(Util.i18n("generatingPortal")); + loc = portal.getSpawn(); + } + } + else + { + LOGGER.info(Util.format("userUsedPortal", event.getPlayer().getName())); + user.sendMessage(Util.i18n("usingPortal")); + loc = portal.getSpawn(); + } + + event.setFrom(loc); + event.setTo(loc); + try + { + user.getTeleport().now(loc, new Trade("portal", ess)); + } + catch (Exception ex) + { + user.sendMessage(ex.getMessage()); + } + user.setJustPortaled(true); + user.sendMessage(Util.i18n("teleportingPortal")); + + event.setCancelled(true); + return; + } + + user.setJustPortaled(false); + } + + @Override + public void onPlayerQuit(final PlayerQuitEvent event) + { + final User user = ess.getUser(event.getPlayer()); + if (ess.getSettings().removeGodOnDisconnect() && user.isGodModeEnabled()) + { + user.toggleGodModeEnabled(); + } + if (user.getSavedInventory() != null) + { + user.getInventory().setContents(user.getSavedInventory()); + user.setSavedInventory(null); + } + user.updateActivity(false); + user.dispose(); + if (!ess.getSettings().getReclaimSetting()) + { + return; + } + final Thread thread = new Thread(new Runnable() + { + public void run() + { + try + { + Thread.sleep(1000); + Runtime rt = Runtime.getRuntime(); + double mem = rt.freeMemory(); + rt.runFinalization(); + rt.gc(); + mem = rt.freeMemory() - mem; + mem /= 1024 * 1024; + LOGGER.log(Level.INFO, Util.format("freedMemory", mem)); + } + catch (InterruptedException ex) + { + return; + } + } + }); + thread.setPriority(Thread.MIN_PRIORITY); + thread.start(); + } + + @Override + public void onPlayerJoin(final PlayerJoinEvent event) + { + ess.getBackup().onPlayerJoin(); + final User user = ess.getUser(event.getPlayer()); + + if (ess.getSettings().changeDisplayName()) + { + user.setDisplayName(user.getNick()); + } + user.updateActivity(false); + if (user.isAuthorized("essentials.sleepingignored")) + { + user.setSleepingIgnored(true); + } + + if (!ess.getSettings().isCommandDisabled("motd") && user.isAuthorized("essentials.motd")) + { + for (String m : ess.getMotd(user, null)) + { + if (m == null) + { + continue; + } + user.sendMessage(m); + } + } + + if (!ess.getSettings().isCommandDisabled("mail") && user.isAuthorized("essentials.mail")) + { + final List mail = user.getMails(); + if (mail.isEmpty()) + { + user.sendMessage(Util.i18n("noNewMail")); + } + else + { + user.sendMessage(Util.format("youHaveNewMail", mail.size())); + } + } + } + + @Override + public void onPlayerLogin(final PlayerLoginEvent event) + { + if (event.getResult() != Result.ALLOWED && event.getResult() != Result.KICK_FULL && event.getResult() != Result.KICK_BANNED) + { + LOGGER.log(Level.INFO, "Disconnecting user " + event.getPlayer().toString() + " due to " + event.getResult().toString()); + return; + } + User user = ess.getUser(event.getPlayer()); + user.setNPC(false); + + final long currentTime = System.currentTimeMillis(); + boolean banExpired = user.checkBanTimeout(currentTime); + user.checkMuteTimeout(currentTime); + user.checkJailTimeout(currentTime); + + if (banExpired == false && (user.isBanned() || event.getResult() == Result.KICK_BANNED)) + { + final String banReason = user.getBanReason(); + event.disallow(Result.KICK_BANNED, banReason != null && !banReason.isEmpty() && !banReason.equalsIgnoreCase("ban") ? banReason : Util.i18n("defaultBanReason")); + return; + } + + if (server.getOnlinePlayers().length >= server.getMaxPlayers() && !user.isAuthorized("essentials.joinfullserver")) + { + event.disallow(Result.KICK_FULL, Util.i18n("serverFull")); + return; + } + event.allow(); + + user.setLastLogin(System.currentTimeMillis()); + updateCompass(user); + } + + private void updateCompass(final User user) + { + try + { + user.setCompassTarget(user.getHome(user.getLocation())); + } + catch (Exception ex) + { + } + } + + @Override + public void onPlayerTeleport(PlayerTeleportEvent event) + { + if (event.isCancelled()) + { + return; + } + final User user = ess.getUser(event.getPlayer()); + if (ess.getSettings().changeDisplayName()) + { + user.setDisplayName(user.getNick()); + } + updateCompass(user); + } + + @Override + public void onPlayerInteract(final PlayerInteractEvent event) + { + if (event.isCancelled()) + { + return; + } + if (event.getAction() != Action.RIGHT_CLICK_BLOCK) + { + return; + } + + if (ess.getSettings().getBedSetsHome() && event.getClickedBlock().getType() == Material.BED_BLOCK) + { + try + { + final User user = ess.getUser(event.getPlayer()); + user.setHome(); + user.sendMessage(Util.i18n("homeSetToBed")); + } + catch (Throwable ex) + { + } + } + } + + @Override + public void onPlayerEggThrow(final PlayerEggThrowEvent event) + { + final User user = ess.getUser(event.getPlayer()); + final ItemStack is = new ItemStack(Material.EGG, 1); + if (user.hasUnlimited(is)) + { + user.getInventory().addItem(is); + user.updateInventory(); + } + } + + @Override + public void onPlayerBucketEmpty(final PlayerBucketEmptyEvent event) + { + final User user = ess.getUser(event.getPlayer()); + if (user.hasUnlimited(new ItemStack(event.getBucket()))) + { + event.getItemStack().setType(event.getBucket()); + ess.scheduleSyncDelayedTask(new Runnable() + { + public void run() + { + user.updateInventory(); + } + }); + } + } + + @Override + public void onPlayerAnimation(final PlayerAnimationEvent event) + { + usePowertools(event); + } + + private void usePowertools(final PlayerAnimationEvent event) + { + if (event.getAnimationType() != PlayerAnimationType.ARM_SWING) + { + return; + } + final User user = ess.getUser(event.getPlayer()); + final ItemStack is = user.getItemInHand(); + if (is == null || is.getType() == Material.AIR || !user.arePowerToolsEnabled()) + { + return; + } + final List commandList = user.getPowertool(is); + if (commandList == null || commandList.isEmpty()) + { + return; + } + + // We need to loop through each command and execute + for (String command : commandList) + { + if (command.matches(".*\\{player\\}.*")) + { + //user.sendMessage("Click a player to use this command"); + continue; + } + else if (command.startsWith("c:")) + { + for (Player p : server.getOnlinePlayers()) + { + p.sendMessage(user.getDisplayName() + ":" + command.substring(2)); + } + } + else + { + user.getServer().dispatchCommand(event.getPlayer(), command); + } + } + } + + @Override + public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) + { + if (event.isCancelled()) + { + return; + } + final User user = ess.getUser(event.getPlayer()); + final String cmd = event.getMessage().toLowerCase().split(" ")[0].replace("/", "").toLowerCase(); + final List commands = Arrays.asList("msg", "r", "mail", "m", "t", "emsg", "tell", "er", "reply", "ereply", "email"); + if (commands.contains(cmd)) + { + for (Player player : ess.getServer().getOnlinePlayers()) + { + User spyer = ess.getUser(player); + if (spyer.isSocialSpyEnabled() && !user.equals(spyer)) + { + player.sendMessage(user.getDisplayName() + " : " + event.getMessage()); + } + } + } + if (!cmd.equalsIgnoreCase("afk")) + { + user.updateActivity(true); + } + } +} -- cgit v1.2.3 From e1801d6d40aae9c9d4a822edb065e4405f440a29 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Thu, 29 Sep 2011 00:33:55 +0100 Subject: Hiding the nether options, that are going to be removed in a future release. --- Essentials/src/com/earth2me/essentials/Settings.java | 4 ++-- Essentials/src/config.yml | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java index 665da17a6..5bcbd7311 100644 --- a/Essentials/src/com/earth2me/essentials/Settings.java +++ b/Essentials/src/com/earth2me/essentials/Settings.java @@ -220,7 +220,7 @@ public class Settings implements ISettings @Override public boolean isNetherEnabled() { - return config.getBoolean("nether.enabled", true); + return config.getBoolean("nether.enabled", false); } @Override @@ -362,7 +362,7 @@ public class Settings implements ISettings if (config.getBoolean("nether.use-1to1-ratio", false)) { return 1.0; } - return config.getDouble("nether.ratio", 16.0); + return config.getDouble("nether.ratio", 8.0); } @Override diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index 13b7def41..ee956b0fc 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -79,14 +79,11 @@ reclaim-onlogout: false # Should primitive spawn protection be enabled? For most servers, this should be flase; it is better to use a third-party plugin to protect it. spawn-protection: false -# Nether settings (switch between worlds with "/world nether" and "/world normal") -# Sets whether the nether system is enabled, what folder to save the world in, and whether portals should teleport players between worlds. +# Nether settings +# Sets wether you want to change the default behaviour of the nether portals. nether: - enabled: false - folder: nether portals-enabled: false generate-exit-portals: false - ratio: 16 # Mob limit on spawnmob spawnmob-limit: 10 -- cgit v1.2.3 From b18da4aea613411170c53de00f3e3a6111854535 Mon Sep 17 00:00:00 2001 From: snowleo Date: Thu, 29 Sep 2011 01:38:56 +0200 Subject: Fixing line endings --- .../essentials/EssentialsPlayerListener.java | 972 ++++++++++----------- 1 file changed, 486 insertions(+), 486 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index 6d97bc17d..2f690910f 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -1,486 +1,486 @@ -package com.earth2me.essentials; - -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Server; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.event.block.Action; -import org.bukkit.event.player.PlayerAnimationEvent; -import org.bukkit.event.player.PlayerAnimationType; -import org.bukkit.event.player.PlayerBucketEmptyEvent; -import org.bukkit.event.player.PlayerChatEvent; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.player.PlayerEggThrowEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerListener; -import org.bukkit.event.player.PlayerLoginEvent; -import org.bukkit.event.player.PlayerLoginEvent.Result; -import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.player.PlayerRespawnEvent; -import org.bukkit.event.player.PlayerTeleportEvent; -import org.bukkit.inventory.ItemStack; - - -public class EssentialsPlayerListener extends PlayerListener -{ - private static final Logger LOGGER = Logger.getLogger("Minecraft"); - private final transient Server server; - private final transient IEssentials ess; - - public EssentialsPlayerListener(final IEssentials parent) - { - this.ess = parent; - this.server = parent.getServer(); - } - - @Override - public void onPlayerRespawn(final PlayerRespawnEvent event) - { - final User user = ess.getUser(event.getPlayer()); - user.setDisplayName(user.getNick()); - updateCompass(user); - if (ess.getSettings().changeDisplayName()) - { - user.setDisplayName(user.getNick()); - } - } - - @Override - public void onPlayerChat(final PlayerChatEvent event) - { - final User user = ess.getUser(event.getPlayer()); - if (user.isMuted()) - { - event.setCancelled(true); - user.sendMessage(Util.i18n("playerMuted")); - LOGGER.info(Util.format("mutedUserSpeaks", user.getName())); - } - final Iterator it = event.getRecipients().iterator(); - while (it.hasNext()) - { - final User u = ess.getUser(it.next()); - if (u.isIgnoredPlayer(user.getName())) - { - it.remove(); - } - } - user.updateActivity(true); - if (ess.getSettings().changeDisplayName()) - { - user.setDisplayName(user.getNick()); - } - } - - @Override - public void onPlayerMove(final PlayerMoveEvent event) - { - if (event.isCancelled()) - { - return; - } - final User user = ess.getUser(event.getPlayer()); - - if (user.isAfk() && ess.getSettings().getFreezeAfkPlayers()) - { - final Location from = event.getFrom(); - final Location to = event.getTo().clone(); - to.setX(from.getX()); - to.setY(from.getBlock().getTypeId() == 0 ? from.getY() - 1 : from.getY()); - to.setZ(from.getZ()); - event.setTo(to); - return; - } - - Location afk = user.getAfkPosition(); - if (afk == null || !event.getTo().getWorld().equals(afk.getWorld()) || afk.distanceSquared(event.getTo()) > 9) - { - user.updateActivity(true); - } - - if (!ess.getSettings().getNetherPortalsEnabled()) - { - return; - } - - final Block block = event.getPlayer().getWorld().getBlockAt(event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ()); - final List worlds = server.getWorlds(); - - if (block.getType() == Material.PORTAL && worlds.size() > 1 && user.isAuthorized("essentials.portal")) - { - if (user.getJustPortaled()) - { - return; - } - - World nether = server.getWorld(ess.getSettings().getNetherName()); - if (nether == null) - { - for (World world : worlds) - { - if (world.getEnvironment() == World.Environment.NETHER) - { - nether = world; - break; - } - } - if (nether == null) - { - return; - } - } - final World world = user.getWorld() == nether ? worlds.get(0) : nether; - - double factor; - if (user.getWorld().getEnvironment() == World.Environment.NETHER && world.getEnvironment() == World.Environment.NORMAL) - { - factor = ess.getSettings().getNetherRatio(); - } - else if (user.getWorld().getEnvironment() == World.Environment.NORMAL && world.getEnvironment() == World.Environment.NETHER) - { - factor = 1.0 / ess.getSettings().getNetherRatio(); - } - else - { - factor = 1.0; - } - - Location loc = event.getTo(); - int x = loc.getBlockX(); - int y = loc.getBlockY(); - int z = loc.getBlockZ(); - - if (user.getWorld().getBlockAt(x, y, z - 1).getType() == Material.PORTAL) - { - z--; - } - if (user.getWorld().getBlockAt(x - 1, y, z).getType() == Material.PORTAL) - { - x--; - } - - x = (int)(x * factor); - z = (int)(z * factor); - loc = new Location(world, x + .5, y, z + .5); - - Block dest = world.getBlockAt(x, y, z); - NetherPortal portal = NetherPortal.findPortal(dest); - if (portal == null) - { - if (world.getEnvironment() == World.Environment.NETHER || ess.getSettings().getGenerateExitPortals()) - { - portal = NetherPortal.createPortal(dest); - LOGGER.info(Util.format("userCreatedPortal", event.getPlayer().getName())); - user.sendMessage(Util.i18n("generatingPortal")); - loc = portal.getSpawn(); - } - } - else - { - LOGGER.info(Util.format("userUsedPortal", event.getPlayer().getName())); - user.sendMessage(Util.i18n("usingPortal")); - loc = portal.getSpawn(); - } - - event.setFrom(loc); - event.setTo(loc); - try - { - user.getTeleport().now(loc, new Trade("portal", ess)); - } - catch (Exception ex) - { - user.sendMessage(ex.getMessage()); - } - user.setJustPortaled(true); - user.sendMessage(Util.i18n("teleportingPortal")); - - event.setCancelled(true); - return; - } - - user.setJustPortaled(false); - } - - @Override - public void onPlayerQuit(final PlayerQuitEvent event) - { - final User user = ess.getUser(event.getPlayer()); - if (ess.getSettings().removeGodOnDisconnect() && user.isGodModeEnabled()) - { - user.toggleGodModeEnabled(); - } - if (user.getSavedInventory() != null) - { - user.getInventory().setContents(user.getSavedInventory()); - user.setSavedInventory(null); - } - user.updateActivity(false); - user.dispose(); - if (!ess.getSettings().getReclaimSetting()) - { - return; - } - final Thread thread = new Thread(new Runnable() - { - public void run() - { - try - { - Thread.sleep(1000); - Runtime rt = Runtime.getRuntime(); - double mem = rt.freeMemory(); - rt.runFinalization(); - rt.gc(); - mem = rt.freeMemory() - mem; - mem /= 1024 * 1024; - LOGGER.log(Level.INFO, Util.format("freedMemory", mem)); - } - catch (InterruptedException ex) - { - return; - } - } - }); - thread.setPriority(Thread.MIN_PRIORITY); - thread.start(); - } - - @Override - public void onPlayerJoin(final PlayerJoinEvent event) - { - ess.getBackup().onPlayerJoin(); - final User user = ess.getUser(event.getPlayer()); - - if (ess.getSettings().changeDisplayName()) - { - user.setDisplayName(user.getNick()); - } - user.updateActivity(false); - if (user.isAuthorized("essentials.sleepingignored")) - { - user.setSleepingIgnored(true); - } - - if (!ess.getSettings().isCommandDisabled("motd") && user.isAuthorized("essentials.motd")) - { - for (String m : ess.getMotd(user, null)) - { - if (m == null) - { - continue; - } - user.sendMessage(m); - } - } - - if (!ess.getSettings().isCommandDisabled("mail") && user.isAuthorized("essentials.mail")) - { - final List mail = user.getMails(); - if (mail.isEmpty()) - { - user.sendMessage(Util.i18n("noNewMail")); - } - else - { - user.sendMessage(Util.format("youHaveNewMail", mail.size())); - } - } - } - - @Override - public void onPlayerLogin(final PlayerLoginEvent event) - { - if (event.getResult() != Result.ALLOWED && event.getResult() != Result.KICK_FULL && event.getResult() != Result.KICK_BANNED) - { - LOGGER.log(Level.INFO, "Disconnecting user " + event.getPlayer().toString() + " due to " + event.getResult().toString()); - return; - } - User user = ess.getUser(event.getPlayer()); - user.setNPC(false); - - final long currentTime = System.currentTimeMillis(); - boolean banExpired = user.checkBanTimeout(currentTime); - user.checkMuteTimeout(currentTime); - user.checkJailTimeout(currentTime); - - if (banExpired == false && (user.isBanned() || event.getResult() == Result.KICK_BANNED)) - { - final String banReason = user.getBanReason(); - event.disallow(Result.KICK_BANNED, banReason != null && !banReason.isEmpty() && !banReason.equalsIgnoreCase("ban") ? banReason : Util.i18n("defaultBanReason")); - return; - } - - if (server.getOnlinePlayers().length >= server.getMaxPlayers() && !user.isAuthorized("essentials.joinfullserver")) - { - event.disallow(Result.KICK_FULL, Util.i18n("serverFull")); - return; - } - event.allow(); - - user.setLastLogin(System.currentTimeMillis()); - updateCompass(user); - } - - private void updateCompass(final User user) - { - try - { - user.setCompassTarget(user.getHome(user.getLocation())); - } - catch (Exception ex) - { - } - } - - @Override - public void onPlayerTeleport(PlayerTeleportEvent event) - { - if (event.isCancelled()) - { - return; - } - final User user = ess.getUser(event.getPlayer()); - if (ess.getSettings().changeDisplayName()) - { - user.setDisplayName(user.getNick()); - } - updateCompass(user); - } - - @Override - public void onPlayerInteract(final PlayerInteractEvent event) - { - if (event.isCancelled()) - { - return; - } - if (event.getAction() != Action.RIGHT_CLICK_BLOCK) - { - return; - } - - if (ess.getSettings().getBedSetsHome() && event.getClickedBlock().getType() == Material.BED_BLOCK) - { - try - { - final User user = ess.getUser(event.getPlayer()); - user.setHome(); - user.sendMessage(Util.i18n("homeSetToBed")); - } - catch (Throwable ex) - { - } - } - } - - @Override - public void onPlayerEggThrow(final PlayerEggThrowEvent event) - { - final User user = ess.getUser(event.getPlayer()); - final ItemStack is = new ItemStack(Material.EGG, 1); - if (user.hasUnlimited(is)) - { - user.getInventory().addItem(is); - user.updateInventory(); - } - } - - @Override - public void onPlayerBucketEmpty(final PlayerBucketEmptyEvent event) - { - final User user = ess.getUser(event.getPlayer()); - if (user.hasUnlimited(new ItemStack(event.getBucket()))) - { - event.getItemStack().setType(event.getBucket()); - ess.scheduleSyncDelayedTask(new Runnable() - { - public void run() - { - user.updateInventory(); - } - }); - } - } - - @Override - public void onPlayerAnimation(final PlayerAnimationEvent event) - { - usePowertools(event); - } - - private void usePowertools(final PlayerAnimationEvent event) - { - if (event.getAnimationType() != PlayerAnimationType.ARM_SWING) - { - return; - } - final User user = ess.getUser(event.getPlayer()); - final ItemStack is = user.getItemInHand(); - if (is == null || is.getType() == Material.AIR || !user.arePowerToolsEnabled()) - { - return; - } - final List commandList = user.getPowertool(is); - if (commandList == null || commandList.isEmpty()) - { - return; - } - - // We need to loop through each command and execute - for (String command : commandList) - { - if (command.matches(".*\\{player\\}.*")) - { - //user.sendMessage("Click a player to use this command"); - continue; - } - else if (command.startsWith("c:")) - { - for (Player p : server.getOnlinePlayers()) - { - p.sendMessage(user.getDisplayName() + ":" + command.substring(2)); - } - } - else - { - user.getServer().dispatchCommand(event.getPlayer(), command); - } - } - } - - @Override - public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) - { - if (event.isCancelled()) - { - return; - } - final User user = ess.getUser(event.getPlayer()); - final String cmd = event.getMessage().toLowerCase().split(" ")[0].replace("/", "").toLowerCase(); - final List commands = Arrays.asList("msg", "r", "mail", "m", "t", "emsg", "tell", "er", "reply", "ereply", "email"); - if (commands.contains(cmd)) - { - for (Player player : ess.getServer().getOnlinePlayers()) - { - User spyer = ess.getUser(player); - if (spyer.isSocialSpyEnabled() && !user.equals(spyer)) - { - player.sendMessage(user.getDisplayName() + " : " + event.getMessage()); - } - } - } - if (!cmd.equalsIgnoreCase("afk")) - { - user.updateActivity(true); - } - } -} +package com.earth2me.essentials; + +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Server; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerAnimationEvent; +import org.bukkit.event.player.PlayerAnimationType; +import org.bukkit.event.player.PlayerBucketEmptyEvent; +import org.bukkit.event.player.PlayerChatEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerEggThrowEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerListener; +import org.bukkit.event.player.PlayerLoginEvent; +import org.bukkit.event.player.PlayerLoginEvent.Result; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.inventory.ItemStack; + + +public class EssentialsPlayerListener extends PlayerListener +{ + private static final Logger LOGGER = Logger.getLogger("Minecraft"); + private final transient Server server; + private final transient IEssentials ess; + + public EssentialsPlayerListener(final IEssentials parent) + { + this.ess = parent; + this.server = parent.getServer(); + } + + @Override + public void onPlayerRespawn(final PlayerRespawnEvent event) + { + final User user = ess.getUser(event.getPlayer()); + user.setDisplayName(user.getNick()); + updateCompass(user); + if (ess.getSettings().changeDisplayName()) + { + user.setDisplayName(user.getNick()); + } + } + + @Override + public void onPlayerChat(final PlayerChatEvent event) + { + final User user = ess.getUser(event.getPlayer()); + if (user.isMuted()) + { + event.setCancelled(true); + user.sendMessage(Util.i18n("playerMuted")); + LOGGER.info(Util.format("mutedUserSpeaks", user.getName())); + } + final Iterator it = event.getRecipients().iterator(); + while (it.hasNext()) + { + final User u = ess.getUser(it.next()); + if (u.isIgnoredPlayer(user.getName())) + { + it.remove(); + } + } + user.updateActivity(true); + if (ess.getSettings().changeDisplayName()) + { + user.setDisplayName(user.getNick()); + } + } + + @Override + public void onPlayerMove(final PlayerMoveEvent event) + { + if (event.isCancelled()) + { + return; + } + final User user = ess.getUser(event.getPlayer()); + + if (user.isAfk() && ess.getSettings().getFreezeAfkPlayers()) + { + final Location from = event.getFrom(); + final Location to = event.getTo().clone(); + to.setX(from.getX()); + to.setY(from.getBlock().getTypeId() == 0 ? from.getY() - 1 : from.getY()); + to.setZ(from.getZ()); + event.setTo(to); + return; + } + + Location afk = user.getAfkPosition(); + if (afk == null || !event.getTo().getWorld().equals(afk.getWorld()) || afk.distanceSquared(event.getTo()) > 9) + { + user.updateActivity(true); + } + + if (!ess.getSettings().getNetherPortalsEnabled()) + { + return; + } + + final Block block = event.getPlayer().getWorld().getBlockAt(event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ()); + final List worlds = server.getWorlds(); + + if (block.getType() == Material.PORTAL && worlds.size() > 1 && user.isAuthorized("essentials.portal")) + { + if (user.getJustPortaled()) + { + return; + } + + World nether = server.getWorld(ess.getSettings().getNetherName()); + if (nether == null) + { + for (World world : worlds) + { + if (world.getEnvironment() == World.Environment.NETHER) + { + nether = world; + break; + } + } + if (nether == null) + { + return; + } + } + final World world = user.getWorld() == nether ? worlds.get(0) : nether; + + double factor; + if (user.getWorld().getEnvironment() == World.Environment.NETHER && world.getEnvironment() == World.Environment.NORMAL) + { + factor = ess.getSettings().getNetherRatio(); + } + else if (user.getWorld().getEnvironment() == World.Environment.NORMAL && world.getEnvironment() == World.Environment.NETHER) + { + factor = 1.0 / ess.getSettings().getNetherRatio(); + } + else + { + factor = 1.0; + } + + Location loc = event.getTo(); + int x = loc.getBlockX(); + int y = loc.getBlockY(); + int z = loc.getBlockZ(); + + if (user.getWorld().getBlockAt(x, y, z - 1).getType() == Material.PORTAL) + { + z--; + } + if (user.getWorld().getBlockAt(x - 1, y, z).getType() == Material.PORTAL) + { + x--; + } + + x = (int)(x * factor); + z = (int)(z * factor); + loc = new Location(world, x + .5, y, z + .5); + + Block dest = world.getBlockAt(x, y, z); + NetherPortal portal = NetherPortal.findPortal(dest); + if (portal == null) + { + if (world.getEnvironment() == World.Environment.NETHER || ess.getSettings().getGenerateExitPortals()) + { + portal = NetherPortal.createPortal(dest); + LOGGER.info(Util.format("userCreatedPortal", event.getPlayer().getName())); + user.sendMessage(Util.i18n("generatingPortal")); + loc = portal.getSpawn(); + } + } + else + { + LOGGER.info(Util.format("userUsedPortal", event.getPlayer().getName())); + user.sendMessage(Util.i18n("usingPortal")); + loc = portal.getSpawn(); + } + + event.setFrom(loc); + event.setTo(loc); + try + { + user.getTeleport().now(loc, new Trade("portal", ess)); + } + catch (Exception ex) + { + user.sendMessage(ex.getMessage()); + } + user.setJustPortaled(true); + user.sendMessage(Util.i18n("teleportingPortal")); + + event.setCancelled(true); + return; + } + + user.setJustPortaled(false); + } + + @Override + public void onPlayerQuit(final PlayerQuitEvent event) + { + final User user = ess.getUser(event.getPlayer()); + if (ess.getSettings().removeGodOnDisconnect() && user.isGodModeEnabled()) + { + user.toggleGodModeEnabled(); + } + if (user.getSavedInventory() != null) + { + user.getInventory().setContents(user.getSavedInventory()); + user.setSavedInventory(null); + } + user.updateActivity(false); + user.dispose(); + if (!ess.getSettings().getReclaimSetting()) + { + return; + } + final Thread thread = new Thread(new Runnable() + { + public void run() + { + try + { + Thread.sleep(1000); + Runtime rt = Runtime.getRuntime(); + double mem = rt.freeMemory(); + rt.runFinalization(); + rt.gc(); + mem = rt.freeMemory() - mem; + mem /= 1024 * 1024; + LOGGER.log(Level.INFO, Util.format("freedMemory", mem)); + } + catch (InterruptedException ex) + { + return; + } + } + }); + thread.setPriority(Thread.MIN_PRIORITY); + thread.start(); + } + + @Override + public void onPlayerJoin(final PlayerJoinEvent event) + { + ess.getBackup().onPlayerJoin(); + final User user = ess.getUser(event.getPlayer()); + + if (ess.getSettings().changeDisplayName()) + { + user.setDisplayName(user.getNick()); + } + user.updateActivity(false); + if (user.isAuthorized("essentials.sleepingignored")) + { + user.setSleepingIgnored(true); + } + + if (!ess.getSettings().isCommandDisabled("motd") && user.isAuthorized("essentials.motd")) + { + for (String m : ess.getMotd(user, null)) + { + if (m == null) + { + continue; + } + user.sendMessage(m); + } + } + + if (!ess.getSettings().isCommandDisabled("mail") && user.isAuthorized("essentials.mail")) + { + final List mail = user.getMails(); + if (mail.isEmpty()) + { + user.sendMessage(Util.i18n("noNewMail")); + } + else + { + user.sendMessage(Util.format("youHaveNewMail", mail.size())); + } + } + } + + @Override + public void onPlayerLogin(final PlayerLoginEvent event) + { + if (event.getResult() != Result.ALLOWED && event.getResult() != Result.KICK_FULL && event.getResult() != Result.KICK_BANNED) + { + LOGGER.log(Level.INFO, "Disconnecting user " + event.getPlayer().toString() + " due to " + event.getResult().toString()); + return; + } + User user = ess.getUser(event.getPlayer()); + user.setNPC(false); + + final long currentTime = System.currentTimeMillis(); + boolean banExpired = user.checkBanTimeout(currentTime); + user.checkMuteTimeout(currentTime); + user.checkJailTimeout(currentTime); + + if (banExpired == false && (user.isBanned() || event.getResult() == Result.KICK_BANNED)) + { + final String banReason = user.getBanReason(); + event.disallow(Result.KICK_BANNED, banReason != null && !banReason.isEmpty() && !banReason.equalsIgnoreCase("ban") ? banReason : Util.i18n("defaultBanReason")); + return; + } + + if (server.getOnlinePlayers().length >= server.getMaxPlayers() && !user.isAuthorized("essentials.joinfullserver")) + { + event.disallow(Result.KICK_FULL, Util.i18n("serverFull")); + return; + } + event.allow(); + + user.setLastLogin(System.currentTimeMillis()); + updateCompass(user); + } + + private void updateCompass(final User user) + { + try + { + user.setCompassTarget(user.getHome(user.getLocation())); + } + catch (Exception ex) + { + } + } + + @Override + public void onPlayerTeleport(PlayerTeleportEvent event) + { + if (event.isCancelled()) + { + return; + } + final User user = ess.getUser(event.getPlayer()); + if (ess.getSettings().changeDisplayName()) + { + user.setDisplayName(user.getNick()); + } + updateCompass(user); + } + + @Override + public void onPlayerInteract(final PlayerInteractEvent event) + { + if (event.isCancelled()) + { + return; + } + if (event.getAction() != Action.RIGHT_CLICK_BLOCK) + { + return; + } + + if (ess.getSettings().getBedSetsHome() && event.getClickedBlock().getType() == Material.BED_BLOCK) + { + try + { + final User user = ess.getUser(event.getPlayer()); + user.setHome(); + user.sendMessage(Util.i18n("homeSetToBed")); + } + catch (Throwable ex) + { + } + } + } + + @Override + public void onPlayerEggThrow(final PlayerEggThrowEvent event) + { + final User user = ess.getUser(event.getPlayer()); + final ItemStack is = new ItemStack(Material.EGG, 1); + if (user.hasUnlimited(is)) + { + user.getInventory().addItem(is); + user.updateInventory(); + } + } + + @Override + public void onPlayerBucketEmpty(final PlayerBucketEmptyEvent event) + { + final User user = ess.getUser(event.getPlayer()); + if (user.hasUnlimited(new ItemStack(event.getBucket()))) + { + event.getItemStack().setType(event.getBucket()); + ess.scheduleSyncDelayedTask(new Runnable() + { + public void run() + { + user.updateInventory(); + } + }); + } + } + + @Override + public void onPlayerAnimation(final PlayerAnimationEvent event) + { + usePowertools(event); + } + + private void usePowertools(final PlayerAnimationEvent event) + { + if (event.getAnimationType() != PlayerAnimationType.ARM_SWING) + { + return; + } + final User user = ess.getUser(event.getPlayer()); + final ItemStack is = user.getItemInHand(); + if (is == null || is.getType() == Material.AIR || !user.arePowerToolsEnabled()) + { + return; + } + final List commandList = user.getPowertool(is); + if (commandList == null || commandList.isEmpty()) + { + return; + } + + // We need to loop through each command and execute + for (String command : commandList) + { + if (command.matches(".*\\{player\\}.*")) + { + //user.sendMessage("Click a player to use this command"); + continue; + } + else if (command.startsWith("c:")) + { + for (Player p : server.getOnlinePlayers()) + { + p.sendMessage(user.getDisplayName() + ":" + command.substring(2)); + } + } + else + { + user.getServer().dispatchCommand(event.getPlayer(), command); + } + } + } + + @Override + public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) + { + if (event.isCancelled()) + { + return; + } + final User user = ess.getUser(event.getPlayer()); + final String cmd = event.getMessage().toLowerCase().split(" ")[0].replace("/", "").toLowerCase(); + final List commands = Arrays.asList("msg", "r", "mail", "m", "t", "emsg", "tell", "er", "reply", "ereply", "email"); + if (commands.contains(cmd)) + { + for (Player player : ess.getServer().getOnlinePlayers()) + { + User spyer = ess.getUser(player); + if (spyer.isSocialSpyEnabled() && !user.equals(spyer)) + { + player.sendMessage(user.getDisplayName() + " : " + event.getMessage()); + } + } + } + if (!cmd.equalsIgnoreCase("afk")) + { + user.updateActivity(true); + } + } +} -- cgit v1.2.3 From d4ccabfb86715f1dafca0cb2d1035362dd5a5a27 Mon Sep 17 00:00:00 2001 From: snowleo Date: Thu, 29 Sep 2011 23:36:49 +0200 Subject: Corrected plurals of new creatures and removed Monster creature, because it can't be spawned anymore --- Essentials/src/com/earth2me/essentials/Mob.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/Mob.java b/Essentials/src/com/earth2me/essentials/Mob.java index df4a5b72f..d937ba0fb 100644 --- a/Essentials/src/com/earth2me/essentials/Mob.java +++ b/Essentials/src/com/earth2me/essentials/Mob.java @@ -26,11 +26,10 @@ public enum Mob SPIDER("Spider", Enemies.ENEMY, CreatureType.SPIDER), SQUID("Squid", Enemies.FRIENDLY, CreatureType.SQUID), ZOMBIE("Zombie", Enemies.ENEMY, CreatureType.ZOMBIE), - MONSTER("Monster", Enemies.ENEMY, CreatureType.MONSTER), WOLF("Wolf", Enemies.NEUTRAL, CreatureType.WOLF), CAVESPIDER("CaveSpider", Enemies.ENEMY, CreatureType.CAVE_SPIDER), - ENDERMAN("Enderman", Enemies.ENEMY, CreatureType.ENDERMAN), - SILVERFISH("Silverfish", Enemies.ENEMY, CreatureType.SILVERFISH); + ENDERMAN("Enderman", Enemies.ENEMY, "", CreatureType.ENDERMAN), + SILVERFISH("Silverfish", Enemies.ENEMY, "", CreatureType.SILVERFISH); public static final Logger logger = Logger.getLogger("Minecraft"); -- cgit v1.2.3 From 1011475bf04ba245758d068172890bd792fcf5cd Mon Sep 17 00:00:00 2001 From: snowleo Date: Thu, 29 Sep 2011 23:54:48 +0200 Subject: Only afk people, if they have essentials.afk permission. --- Essentials/src/com/earth2me/essentials/User.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java index 3b57f48fd..d5aa197e7 100644 --- a/Essentials/src/com/earth2me/essentials/User.java +++ b/Essentials/src/com/earth2me/essentials/User.java @@ -460,7 +460,7 @@ public class User extends UserData implements Comparable, IReplyTo, IUser } } final long autoafk = ess.getSettings().getAutoAfk(); - if (!isAfk() && autoafk > 0 && lastActivity + autoafk * 1000 < System.currentTimeMillis()) + if (!isAfk() && autoafk > 0 && lastActivity + autoafk * 1000 < System.currentTimeMillis() && isAuthorized("essentials.afk")) { setAfk(true); if (!isHidden()) { -- cgit v1.2.3 From 42498a141788d4bcfe19db4c1b81d13763f5ebb5 Mon Sep 17 00:00:00 2001 From: snowleo Date: Thu, 29 Sep 2011 23:56:02 +0200 Subject: Correctly throw exceptions if mob spawn protection is on --- .../earth2me/essentials/commands/Commandspawnmob.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java index f46264582..97bcb9c8e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java @@ -56,11 +56,6 @@ public class Commandspawnmob extends EssentialsCommand } } - if (ess.getSettings().getProtectPreventSpawn(mobType.toLowerCase()) - || (mountType != null && ess.getSettings().getProtectPreventSpawn(mountType.toLowerCase()))) - { - throw new Exception(Util.i18n("unableToSpawnMob")); - } Entity spawnedMob = null; Mob mob = null; @@ -72,6 +67,12 @@ public class Commandspawnmob extends EssentialsCommand { throw new Exception(Util.i18n("invalidMob")); } + + if (ess.getSettings().getProtectPreventSpawn(mob.getType().toString().toLowerCase())) + { + throw new Exception(Util.i18n("unableToSpawnMob")); + } + int[] ignore = { 8, 9 @@ -102,6 +103,11 @@ public class Commandspawnmob extends EssentialsCommand user.sendMessage(Util.i18n("invalidMob")); return; } + + if (ess.getSettings().getProtectPreventSpawn(mobMount.getType().toString().toLowerCase())) + { + throw new Exception(Util.i18n("unableToSpawnMob")); + } try { spawnedMount = mobMount.spawn(user, server, loc); -- cgit v1.2.3 From 4ff9d4f90f5bb24fe998e53819ec1c2beadd62a4 Mon Sep 17 00:00:00 2001 From: snowleo Date: Thu, 29 Sep 2011 23:57:44 +0200 Subject: More exceptions thrown --- .../com/earth2me/essentials/commands/Commandspawnmob.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java index 97bcb9c8e..3ea3aae40 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java @@ -80,8 +80,7 @@ public class Commandspawnmob extends EssentialsCommand Block block = (new TargetBlock(user, 300, 0.2, ignore)).getTargetBlock(); if (block == null) { - user.sendMessage(Util.i18n("unableToSpawnMob")); - return; + throw new Exception(Util.i18n("unableToSpawnMob")); } Location loc = block.getLocation(); Location sloc = Util.getSafeDestination(loc); @@ -91,8 +90,7 @@ public class Commandspawnmob extends EssentialsCommand } catch (MobException e) { - user.sendMessage(Util.i18n("unableToSpawnMob")); - return; + throw new Exception(Util.i18n("unableToSpawnMob")); } if (mountType != null) @@ -114,8 +112,7 @@ public class Commandspawnmob extends EssentialsCommand } catch (MobException e) { - user.sendMessage(Util.i18n("unableToSpawnMob")); - return; + throw new Exception(Util.i18n("unableToSpawnMob")); } spawnedMob.setPassenger(spawnedMount); } @@ -150,8 +147,7 @@ public class Commandspawnmob extends EssentialsCommand } catch (MobException e) { - user.sendMessage(Util.i18n("unableToSpawnMob")); - return; + throw new Exception(Util.i18n("unableToSpawnMob")); } spawnedMob.setPassenger(spawnedMount); } -- cgit v1.2.3 From cbe352a4dd9f23884798e0182b330dc77443c5f1 Mon Sep 17 00:00:00 2001 From: snowleo Date: Fri, 30 Sep 2011 00:09:48 +0200 Subject: Fix god mode enabled after afk player quit the game --- Essentials/src/com/earth2me/essentials/User.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java index d5aa197e7..b68e93656 100644 --- a/Essentials/src/com/earth2me/essentials/User.java +++ b/Essentials/src/com/earth2me/essentials/User.java @@ -20,14 +20,12 @@ public class User extends UserData implements Comparable, IReplyTo, IUser private transient long lastOnlineActivity; private transient long lastActivity = System.currentTimeMillis(); private boolean hidden = false; - private transient boolean godStateBeforeAfk; private transient Location afkPosition; User(final Player base, final IEssentials ess) { super(base, ess); teleport = new Teleport(this, ess); - godStateBeforeAfk = isGodModeEnabled(); afkPosition = getLocation(); } @@ -348,15 +346,6 @@ public class User extends UserData implements Comparable, IReplyTo, IUser public void setAfk(final boolean set) { this.setSleepingIgnored(this.isAuthorized("essentials.sleepingignored") ? true : set); - if (set && !isAfk() && ess.getSettings().getFreezeAfkPlayers()) - { - godStateBeforeAfk = isGodModeEnabled(); - setGodModeEnabled(true); - } - if (!set && isAfk() && ess.getSettings().getFreezeAfkPlayers()) - { - setGodModeEnabled(godStateBeforeAfk); - } if (set && !isAfk()) { afkPosition = getLocation(); } @@ -481,5 +470,11 @@ public class User extends UserData implements Comparable, IReplyTo, IUser setFoodLevel(20); } return super.toggleGodModeEnabled(); - } + } + + @Override + public boolean isGodModeEnabled() + { + return super.isGodModeEnabled() || (isAfk() && ess.getSettings().getFreezeAfkPlayers()); + } } -- cgit v1.2.3 From c97fb64d0a4aa96951cd5ce424be43842203273f Mon Sep 17 00:00:00 2001 From: snowleo Date: Fri, 30 Sep 2011 00:15:57 +0200 Subject: Allow delhome for offline users --- Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java b/Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java index aa60c9168..1d80b6a17 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java @@ -31,7 +31,7 @@ public class Commanddelhome extends EssentialsCommand } else if (args.length > 1 && (user == null || user.isAuthorized("essentials.delhome.others"))) { - user = getPlayer(server, args, 0); + user = getPlayer(server, args, 0, true); name = args[1]; } else -- cgit v1.2.3 From 331aaa111105902981835fdaac3a74837ed08b6b Mon Sep 17 00:00:00 2001 From: snowleo Date: Fri, 30 Sep 2011 00:27:53 +0200 Subject: Allow the deletion of broken homes --- Essentials/src/com/earth2me/essentials/UserData.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Essentials/src/com/earth2me/essentials/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java index 39cebbd2a..90da6bb5c 100644 --- a/Essentials/src/com/earth2me/essentials/UserData.java +++ b/Essentials/src/com/earth2me/essentials/UserData.java @@ -163,7 +163,12 @@ public abstract class UserData extends PlayerExtension implements IConf public void delHome(String name) throws Exception { - if (getHome(name) != null) + String search = name; + if (!homes.containsKey(search)) + { + search = Util.sanitizeFileName(name); + } + if (homes.containsKey(search)) { homes.remove(name); config.removeProperty("homes." + name); -- cgit v1.2.3 From 7cdca6800a43be7c0d9c3409fe0e66c8fd809b80 Mon Sep 17 00:00:00 2001 From: snowleo Date: Fri, 30 Sep 2011 00:53:25 +0200 Subject: Kits timeout are now saved in user data --- .../src/com/earth2me/essentials/UserData.java | 30 +++++++++ .../earth2me/essentials/commands/Commandkit.java | 73 +++++++++------------- 2 files changed, 59 insertions(+), 44 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java index 90da6bb5c..33d08909f 100644 --- a/Essentials/src/com/earth2me/essentials/UserData.java +++ b/Essentials/src/com/earth2me/essentials/UserData.java @@ -58,6 +58,7 @@ public abstract class UserData extends PlayerExtension implements IConf isSocialSpyEnabled = _isSocialSpyEnabled(); isNPC = _isNPC(); arePowerToolsEnabled = _arePowerToolsEnabled(); + kitTimestamps = _getKitTimestamps(); } private double money; @@ -813,4 +814,33 @@ public abstract class UserData extends PlayerExtension implements IConf return config.getBoolean("powertoolsenabled", true); } + private Map kitTimestamps; + + private Map _getKitTimestamps() + { + final Object map = config.getProperty("timestamps.kits"); + + if (map instanceof Map) + { + return (Map)map; + } + else + { + return new HashMap(); + } + } + + public Long getKitTimestamp(final String name) + { + final Number num = (Number)kitTimestamps.get(name.toLowerCase()); + return num == null ? null : num.longValue(); + } + + public void setKitTimestamp(final String name, final long time) + { + kitTimestamps.put(name.toLowerCase(), time); + config.setProperty("timestamps.kits", kitTimestamps); + config.save(); + } + } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkit.java b/Essentials/src/com/earth2me/essentials/commands/Commandkit.java index 75cc83887..ae7963c5e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkit.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkit.java @@ -15,22 +15,20 @@ import org.bukkit.inventory.ItemStack; public class Commandkit extends EssentialsCommand { - static private final Map> kitPlayers = new HashMap>(); - public Commandkit() { super("kit"); } @Override - public void run(Server server, User user, String commandLabel, String[] args) throws Exception + public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { try { - Map kits = ess.getSettings().getKits(); - StringBuilder list = new StringBuilder(); + final Map kits = ess.getSettings().getKits(); + final StringBuilder list = new StringBuilder(); for (String k : kits.keySet()) { if (user.isAuthorized("essentials.kit." + k.toLowerCase())) @@ -56,8 +54,8 @@ public class Commandkit extends EssentialsCommand { try { - String kitName = args[0].toLowerCase(); - Object kit = ess.getSettings().getKit(kitName); + final String kitName = args[0].toLowerCase(); + final Object kit = ess.getSettings().getKit(kitName); List items; if (!user.isAuthorized("essentials.kit." + kitName)) @@ -70,39 +68,26 @@ public class Commandkit extends EssentialsCommand { //System.out.println("Kit is timed"); - Map els = (Map)kit; + final Map els = (Map)kit; items = (List)els.get("items"); - double delay = els.containsKey("delay") ? ((Number)els.get("delay")).doubleValue() : 0L; - Calendar c = new GregorianCalendar(); - c.add(Calendar.SECOND, (int)delay); - c.add(Calendar.MILLISECOND, (int)((delay*1000.0)%1000.0)); + final double delay = els.containsKey("delay") ? ((Number)els.get("delay")).doubleValue() : 0L; + final Calendar c = new GregorianCalendar(); + c.add(Calendar.SECOND, -(int)delay); + c.add(Calendar.MILLISECOND, -(int)((delay*1000.0)%1000.0)); - long time = c.getTimeInMillis(); - Calendar now = new GregorianCalendar(); - - Map kitTimes; - if (!kitPlayers.containsKey(user)) - { - kitTimes = new HashMap(); - kitTimes.put(kitName, time); - kitPlayers.put(user, kitTimes); - } - else - { - kitTimes = kitPlayers.get(user); - if (!kitTimes.containsKey(kitName)) - { - kitTimes.put(kitName, time); - } - else if (kitTimes.get(kitName) < now.getTimeInMillis()) - { - kitTimes.put(kitName, time); - } - else - { - user.sendMessage(Util.format("kitTimed", Util.formatDateDiff(kitTimes.get(kitName)))); - return; - } + final long mintime = c.getTimeInMillis(); + + final Long lastTime = user.getKitTimestamp(kitName); + if (lastTime == null || lastTime < mintime) { + final Calendar now = new GregorianCalendar(); + user.setKitTimestamp(kitName, now.getTimeInMillis()); + } else { + final Calendar future = new GregorianCalendar(); + future.setTimeInMillis(lastTime); + future.add(Calendar.SECOND, (int)delay); + future.add(Calendar.MILLISECOND, (int)((delay*1000.0)%1000.0)); + user.sendMessage(Util.format("kitTimed", Util.formatDateDiff(future.getTimeInMillis()))); + return; } } catch (Exception ex) @@ -110,7 +95,7 @@ public class Commandkit extends EssentialsCommand items = (List)kit; } - Trade charge = new Trade("kit-" + kitName, ess); + final Trade charge = new Trade("kit-" + kitName, ess); try { charge.isAffordableFor(user); @@ -124,11 +109,11 @@ public class Commandkit extends EssentialsCommand boolean spew = false; for (String d : items) { - String[] parts = d.split("[^0-9]+", 3); - int id = Material.getMaterial(Integer.parseInt(parts[0])).getId(); - int amount = parts.length > 1 ? Integer.parseInt(parts[parts.length > 2 ? 2 : 1]) : 1; - short data = parts.length > 2 ? Short.parseShort(parts[1]) : 0; - HashMap overfilled = user.getInventory().addItem(new ItemStack(id, amount, data)); + final String[] parts = d.split("[^0-9]+", 3); + final int id = Material.getMaterial(Integer.parseInt(parts[0])).getId(); + final int amount = parts.length > 1 ? Integer.parseInt(parts[parts.length > 2 ? 2 : 1]) : 1; + final short data = parts.length > 2 ? Short.parseShort(parts[1]) : 0; + final HashMap overfilled = user.getInventory().addItem(new ItemStack(id, amount, data)); for (ItemStack itemStack : overfilled.values()) { user.getWorld().dropItemNaturally(user.getLocation(), itemStack); -- cgit v1.2.3 From da63f575e337f4ab3a400aa87eded2177e884f69 Mon Sep 17 00:00:00 2001 From: snowleo Date: Fri, 30 Sep 2011 01:09:00 +0200 Subject: Deprecation our TargetBlock class: There is a function in bukkit that we should use instead user.getTargetBlock(...) --- Essentials/src/com/earth2me/essentials/TargetBlock.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Essentials/src/com/earth2me/essentials/TargetBlock.java b/Essentials/src/com/earth2me/essentials/TargetBlock.java index d1f2e5cbb..3d45afc55 100644 --- a/Essentials/src/com/earth2me/essentials/TargetBlock.java +++ b/Essentials/src/com/earth2me/essentials/TargetBlock.java @@ -10,6 +10,7 @@ import org.bukkit.entity.Player; /** * Original authors: toi & Raphfrk */ +@Deprecated public class TargetBlock { private transient final Location location; -- cgit v1.2.3 From f5bf895a0ef64905ab4b3ca0fbdbfcf92d09ee21 Mon Sep 17 00:00:00 2001 From: snowleo Date: Fri, 30 Sep 2011 02:11:13 +0200 Subject: Don't set last location if it's invalid --- .../src/com/earth2me/essentials/UserData.java | 23 +++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java index 33d08909f..f0a461b70 100644 --- a/Essentials/src/com/earth2me/essentials/UserData.java +++ b/Essentials/src/com/earth2me/essentials/UserData.java @@ -249,12 +249,13 @@ public abstract class UserData extends PlayerExtension implements IConf } - public void clearAllPowertools() { + public void clearAllPowertools() + { powertools.clear(); config.setProperty("powertools", powertools); config.save(); } - + public List getPowertool(ItemStack stack) { return (List)powertools.get(stack.getTypeId()); @@ -273,12 +274,11 @@ public abstract class UserData extends PlayerExtension implements IConf config.setProperty("powertools", powertools); config.save(); } - + public boolean hasPowerTools() { return powertools.size() > 0; } - private Location lastLocation; private Location _getLastLocation() @@ -300,6 +300,10 @@ public abstract class UserData extends PlayerExtension implements IConf public void setLastLocation(Location loc) { + if (loc == null || loc.getWorld() == null) + { + return; + } lastLocation = loc; config.setProperty("lastlocation", loc); config.save(); @@ -787,33 +791,31 @@ public abstract class UserData extends PlayerExtension implements IConf config.setProperty("npc", set); config.save(); } - private boolean arePowerToolsEnabled; - + public boolean arePowerToolsEnabled() { return arePowerToolsEnabled; } - + public void setPowerToolsEnabled(boolean set) { arePowerToolsEnabled = set; config.setProperty("powertoolsenabled", set); config.save(); } - + public boolean togglePowerToolsEnabled() { boolean ret = !arePowerToolsEnabled(); setPowerToolsEnabled(ret); return ret; } - + private boolean _arePowerToolsEnabled() { return config.getBoolean("powertoolsenabled", true); } - private Map kitTimestamps; private Map _getKitTimestamps() @@ -842,5 +844,4 @@ public abstract class UserData extends PlayerExtension implements IConf config.setProperty("timestamps.kits", kitTimestamps); config.save(); } - } -- cgit v1.2.3 From 27b0a1b651aadd4136fc5a2415ac902bad9a7adf Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sat, 1 Oct 2011 04:57:49 +0100 Subject: Patching /unlimited to not give items if player is in creative mode. --- Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java b/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java index 7cd15180b..72c308655 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java @@ -1,6 +1,7 @@ package com.earth2me.essentials; import java.util.logging.Logger; +import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.event.block.BlockListener; import org.bukkit.event.block.BlockPlaceEvent; @@ -93,7 +94,7 @@ public class EssentialsBlockListener extends BlockListener return; } boolean unlimitedForUser = user.hasUnlimited(is); - if (unlimitedForUser) + if (unlimitedForUser && user.getGameMode() == GameMode.SURVIVAL) { ess.scheduleSyncDelayedTask( new Runnable() -- cgit v1.2.3 From 857f8a4aeca6a7196b9d272d5e90a58cb0dc01dc Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sat, 1 Oct 2011 05:02:32 +0100 Subject: Adding MOTD flags to config.yml Setting config.yml 'warn-on-build-disallow: true' - should reduce number of confused support requests. --- Essentials/src/config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index ee956b0fc..82639d157 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -92,6 +92,7 @@ spawnmob-limit: 10 warn-on-smite: true # The message of the day, displayed on connect and by typing /motd. +# Valid tags are: {PLAYER}, {IP}, {BALANCE}, {MAILS}, {WORLD}, {ONLINE}, {UNIQUE}, {PLAYERLIST} motd: - '&cWelcome, {PLAYER}&c!' - '&fType &c/help&f for a list of commands.' @@ -485,7 +486,7 @@ protect: use: true # Should we tell people they are not allowed to build - warn-on-build-disallow: false + warn-on-build-disallow: true # Disable weather options -- cgit v1.2.3 From ba67ed976b8e346480c387ce376ab46dd95667c1 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sat, 1 Oct 2011 10:08:58 +0100 Subject: Allow different 'sets' of multiple homes, definable by permission. - Not sure I like this, but it does seem to work - changed config key for backwards compatibility (config node sets value on failure). --- .../src/com/earth2me/essentials/ISettings.java | 6 +- .../src/com/earth2me/essentials/Settings.java | 134 +++++++++++++++------ .../essentials/commands/Commandsethome.java | 4 +- Essentials/src/config.yml | 14 ++- 4 files changed, 114 insertions(+), 44 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/ISettings.java b/Essentials/src/com/earth2me/essentials/ISettings.java index 82c057648..af95e2cbc 100644 --- a/Essentials/src/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/com/earth2me/essentials/ISettings.java @@ -73,7 +73,11 @@ public interface ISettings extends IConf boolean getRespawnAtHome(); - int getMultipleHomes(); + List getMultipleHomes(); + + int getHomeLimit(String set); + + int getHomeLimit(User user); boolean getSortListByGroups(); diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java index 5bcbd7311..3c06fb300 100644 --- a/Essentials/src/com/earth2me/essentials/Settings.java +++ b/Essentials/src/com/earth2me/essentials/Settings.java @@ -30,17 +30,45 @@ public class Settings implements ISettings { return config.getBoolean("respawn-at-home", false); } - + @Override - public int getMultipleHomes() + public boolean getBedSetsHome() { - return config.getInt("multiple-homes", 5); + return config.getBoolean("bed-sethome", false); } @Override - public boolean getBedSetsHome() + public List getMultipleHomes() { - return config.getBoolean("bed-sethome", false); + return config.getKeys("sethome-multiple"); + } + + @Override + public int getHomeLimit(final User user) + { + final List homeList = getMultipleHomes(); + if (homeList == null) + { + //TODO: Replace this code to remove backwards compat, after settings are automatically updated + // return getHomeLimit("default"); + return config.getInt("multiple-homes", 5); + } + int limit = getHomeLimit("default"); + for (String set : homeList) + { + logger.log(Level.INFO, "Found home set: " + set); + if (user.hasPermission("essentials.sethome.multiple." + set) && limit < getHomeLimit(set)) + { + limit = getHomeLimit(set); + } + } + return limit; + } + + @Override + public int getHomeLimit(final String set) + { + return config.getInt("sethome-multiple." + set, config.getInt("sethome-multiple.default", 3)); } @Override @@ -60,7 +88,7 @@ public class Settings implements ISettings { return config.getInt("default-stack-size", 64); } - + @Override public int getStartingBalance() { @@ -84,7 +112,10 @@ public class Settings implements ISettings { for (String c : config.getStringList("disabled-commands", new ArrayList(0))) { - if (!c.equalsIgnoreCase(label)) continue; + if (!c.equalsIgnoreCase(label)) + { + continue; + } return true; } return config.getBoolean("disable-" + label.toLowerCase(), false); @@ -101,18 +132,24 @@ public class Settings implements ISettings { for (String c : config.getStringList("restricted-commands", new ArrayList(0))) { - if (!c.equalsIgnoreCase(label)) continue; + if (!c.equalsIgnoreCase(label)) + { + continue; + } return true; } return config.getBoolean("restrict-" + label.toLowerCase(), false); } - + @Override public boolean isPlayerCommand(String label) { for (String c : config.getStringList("player-commands", new ArrayList(0))) { - if (!c.equalsIgnoreCase(label)) continue; + if (!c.equalsIgnoreCase(label)) + { + continue; + } return true; } return false; @@ -126,7 +163,9 @@ public class Settings implements ISettings for (String c : config.getStringList("overridden-commands", defaultList)) { if (!c.equalsIgnoreCase(name)) + { continue; + } return true; } return config.getBoolean("override-" + name.toLowerCase(), false); @@ -143,7 +182,9 @@ public class Settings implements ISettings { double cost = config.getDouble("command-costs." + label, 0.0); if (cost == 0.0) + { cost = config.getDouble("cost-" + label, 0.0); + } return cost; } @@ -171,13 +212,14 @@ public class Settings implements ISettings Map kits = (Map)config.getProperty("kits"); for (Map.Entry entry : kits.entrySet()) { - if (entry.getKey().equalsIgnoreCase(name.replace('.', '_').replace('/', '_'))) { + if (entry.getKey().equalsIgnoreCase(name.replace('.', '_').replace('/', '_'))) + { return entry.getValue(); } } return null; } - + @Override public Map getKits() { @@ -190,9 +232,13 @@ public class Settings implements ISettings String colorName = config.getString("ops-name-color", null); if (colorName == null) + { return ChatColor.RED; - if("none".equalsIgnoreCase(colorName) || colorName.isEmpty()) + } + if ("none".equalsIgnoreCase(colorName) || colorName.isEmpty()) + { throw new Exception(); + } try { @@ -228,18 +274,18 @@ public class Settings implements ISettings { return config.getInt("spawnmob-limit", 10); } - + @Override public boolean showNonEssCommandsInHelp() { return config.getBoolean("non-ess-in-help", true); } - + @Override - public boolean hidePermissionlessHelp() + public boolean hidePermissionlessHelp() { return config.getBoolean("hide-permissionless-help", true); - } + } @Override public int getProtectCreeperMaxHeight() @@ -301,12 +347,13 @@ public class Settings implements ISettings { return config.getString("newbies.spawnpoint", "default"); } + @Override - public boolean getPerWarpPermission() + public boolean getPerWarpPermission() { return config.getBoolean("per-warp-permission", false); } - + @Override public boolean getSortListByGroups() { @@ -314,7 +361,8 @@ public class Settings implements ISettings } @Override - public void reloadConfig() { + public void reloadConfig() + { config.load(); } @@ -322,16 +370,21 @@ public class Settings implements ISettings public List itemSpawnBlacklist() { final List epItemSpwn = new ArrayList(); - for (String itemName : config.getString("item-spawn-blacklist", "").split(",")) { + for (String itemName : config.getString("item-spawn-blacklist", "").split(",")) + { itemName = itemName.trim(); - if (itemName.isEmpty()) { + if (itemName.isEmpty()) + { continue; } ItemStack is; - try { + try + { is = ess.getItemDb().get(itemName); epItemSpwn.add(is.getTypeId()); - } catch (Exception ex) { + } + catch (Exception ex) + { logger.log(Level.SEVERE, Util.format("unknownItemInList", itemName, "item-spawn-blacklist")); } } @@ -355,16 +408,17 @@ public class Settings implements ISettings { return config.getBoolean("nether.use-1to1-ratio", false); } - + @Override public double getNetherRatio() { - if (config.getBoolean("nether.use-1to1-ratio", false)) { + if (config.getBoolean("nether.use-1to1-ratio", false)) + { return 1.0; } return config.getDouble("nether.ratio", 8.0); } - + @Override public boolean isDebug() { @@ -374,9 +428,9 @@ public class Settings implements ISettings @Override public boolean warnOnSmite() { - return config.getBoolean("warn-on-smite" ,true); + return config.getBoolean("warn-on-smite", true); } - + @Override public boolean permissionBasedItemSpawn() { @@ -410,23 +464,28 @@ public class Settings implements ISettings @Override public boolean getProtectPreventSpawn(final String creatureName) { - return config.getBoolean("protect.prevent.spawn."+creatureName, false); + return config.getBoolean("protect.prevent.spawn." + creatureName, false); } @Override public List getProtectList(final String configName) { final List list = new ArrayList(); - for (String itemName : config.getString(configName, "").split(",")) { + for (String itemName : config.getString(configName, "").split(",")) + { itemName = itemName.trim(); - if (itemName.isEmpty()) { + if (itemName.isEmpty()) + { continue; } ItemStack itemStack; - try { + try + { itemStack = ess.getItemDb().get(itemName); list.add(itemStack.getTypeId()); - } catch (Exception ex) { + } + catch (Exception ex) + { logger.log(Level.SEVERE, Util.format("unknownItemInList", itemName, configName)); } } @@ -444,12 +503,13 @@ public class Settings implements ISettings { return config.getBoolean(configName, def); } - private final static double MAXMONEY = 10000000000000.0; + public double getMaxMoney() { double max = config.getDouble("max-money", MAXMONEY); - if (Math.abs(max) > MAXMONEY) { + if (Math.abs(max) > MAXMONEY) + { max = max < 0 ? -MAXMONEY : MAXMONEY; } return max; @@ -459,7 +519,7 @@ public class Settings implements ISettings { return config.getBoolean("economy-log-enabled", false); } - + public boolean removeGodOnDisconnect() { return config.getBoolean("remove-god-on-disconnect", false); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java b/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java index 82d66a71c..b59984f05 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java @@ -28,14 +28,14 @@ public class Commandsethome extends EssentialsCommand { if (user.isAuthorized("essentials.sethome.multiple")) { - if ((user.isAuthorized("essentials.sethome.multiple.unlimited")) || (user.getHomes().size() < ess.getSettings().getMultipleHomes()) + if ((user.isAuthorized("essentials.sethome.multiple.unlimited")) || (user.getHomes().size() < ess.getSettings().getHomeLimit(user)) || (user.getHomes().contains(args[0].toLowerCase()))) { user.setHome(args[0].toLowerCase()); } else { - throw new Exception(Util.format("maxHomes", ess.getSettings().getMultipleHomes())); + throw new Exception(Util.format("maxHomes", ess.getSettings().getHomeLimit(user))); } } diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index 82639d157..7b1525d40 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -260,10 +260,16 @@ bed-sethome: false # If no home is set send you to spawn when /home is used spawn-if-no-home: false -# If users have essentials.sethome.multiple how many homes can they have -# People with essentials.sethome.multiple.unlimited are not limited by this number -multiple-homes: 5 - +# Allow players to have multiple homes. +# Define different amounts of multiple homes for different permissions, e.g. essentials.sethome.multiple.vip +# People with essentials.sethome.multiple.unlimited are not limited by these numbers. +sethome-multiple: + # essentials.sethome.multiple + default: 3 + # essentials.sethome.multiple.vip + vip: 5 + # essentials.sethome.multiple.staff + staff: 10 ############################################################ # +------------------------------------------------------+ # -- cgit v1.2.3 From 64de3475e5cc48223a4a8f8238eb874aec367546 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Mon, 3 Oct 2011 06:42:38 +0100 Subject: Fixing mail argument errors. --- .../src/com/earth2me/essentials/commands/Commandmail.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java index e08a6c8e5..acffd57a1 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java @@ -23,13 +23,15 @@ public class Commandmail extends EssentialsCommand List mail = user.getMails(); if (mail.isEmpty()) { - throw new Exception(Util.i18n("noMail")); + user.sendMessage(Util.i18n("noMail")); + throw new NoChargeException(); } for (String s : mail) { user.sendMessage(s); } - throw new Exception(Util.i18n("mailClear")); + user.sendMessage(Util.i18n("mailClear")); + return; } if (args.length >= 3 && "send".equalsIgnoreCase(args[0])) { @@ -62,8 +64,9 @@ public class Commandmail extends EssentialsCommand if (args.length >= 1 && "clear".equalsIgnoreCase(args[0])) { user.setMails(null); - throw new Exception(Util.i18n("mailCleared")); + user.sendMessage(Util.i18n("mailCleared")); + return; } - throw new NoChargeException(); + throw new NotEnoughArgumentsException(); } } -- cgit v1.2.3 From 786dcae29e2ab4b5d529490d77cdad71e5699451 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Mon, 3 Oct 2011 08:08:05 +0100 Subject: Updating safe teleport locations to include 1.8 blocks. --- Essentials/src/com/earth2me/essentials/Util.java | 32 ++++++++++++++---------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java index 7d0093680..52409049d 100644 --- a/Essentials/src/com/earth2me/essentials/Util.java +++ b/Essentials/src/com/earth2me/essentials/Util.java @@ -227,30 +227,36 @@ public class Util AIR_MATERIALS.add(Material.SAPLING.getId()); AIR_MATERIALS.add(Material.POWERED_RAIL.getId()); AIR_MATERIALS.add(Material.DETECTOR_RAIL.getId()); + AIR_MATERIALS.add(Material.LONG_GRASS.getId()); AIR_MATERIALS.add(Material.DEAD_BUSH.getId()); - AIR_MATERIALS.add(Material.RAILS.getId()); AIR_MATERIALS.add(Material.YELLOW_FLOWER.getId()); AIR_MATERIALS.add(Material.RED_ROSE.getId()); - AIR_MATERIALS.add(Material.RED_MUSHROOM.getId()); AIR_MATERIALS.add(Material.BROWN_MUSHROOM.getId()); + AIR_MATERIALS.add(Material.RED_MUSHROOM.getId()); + AIR_MATERIALS.add(Material.TORCH.getId()); + AIR_MATERIALS.add(Material.REDSTONE_WIRE.getId()); AIR_MATERIALS.add(Material.SEEDS.getId()); AIR_MATERIALS.add(Material.SIGN_POST.getId()); - AIR_MATERIALS.add(Material.WALL_SIGN.getId()); + AIR_MATERIALS.add(Material.WOODEN_DOOR.getId()); AIR_MATERIALS.add(Material.LADDER.getId()); - AIR_MATERIALS.add(Material.SUGAR_CANE_BLOCK.getId()); - AIR_MATERIALS.add(Material.REDSTONE_WIRE.getId()); + AIR_MATERIALS.add(Material.RAILS.getId()); + AIR_MATERIALS.add(Material.WALL_SIGN.getId()); + AIR_MATERIALS.add(Material.LEVER.getId()); + AIR_MATERIALS.add(Material.STONE_PLATE.getId()); + AIR_MATERIALS.add(Material.IRON_DOOR_BLOCK.getId()); + AIR_MATERIALS.add(Material.WOOD_PLATE.getId()); AIR_MATERIALS.add(Material.REDSTONE_TORCH_OFF.getId()); AIR_MATERIALS.add(Material.REDSTONE_TORCH_ON.getId()); - AIR_MATERIALS.add(Material.TORCH.getId()); - AIR_MATERIALS.add(Material.SOIL.getId()); + AIR_MATERIALS.add(Material.STONE_BUTTON.getId()); + AIR_MATERIALS.add(Material.SUGAR_CANE_BLOCK.getId()); AIR_MATERIALS.add(Material.DIODE_BLOCK_OFF.getId()); - AIR_MATERIALS.add(Material.DIODE_BLOCK_ON.getId()); + AIR_MATERIALS.add(Material.DIODE_BLOCK_ON.getId()); AIR_MATERIALS.add(Material.TRAP_DOOR.getId()); - AIR_MATERIALS.add(Material.STONE_BUTTON.getId()); - AIR_MATERIALS.add(Material.STONE_PLATE.getId()); - AIR_MATERIALS.add(Material.WOOD_PLATE.getId()); - AIR_MATERIALS.add(Material.IRON_DOOR_BLOCK.getId()); - AIR_MATERIALS.add(Material.WOODEN_DOOR.getId()); + AIR_MATERIALS.add(Material.PUMPKIN_STEM.getId()); + AIR_MATERIALS.add(Material.MELON_STEM.getId()); + AIR_MATERIALS.add(Material.VINE.getId()); + //TODO: Add 1.9 materials + } public static Location getSafeDestination(final Location loc) throws Exception -- cgit v1.2.3 From b9e3e5f7e530e39c2bddaea9a81ea58aa7875b1c Mon Sep 17 00:00:00 2001 From: KHobbits Date: Mon, 3 Oct 2011 09:58:46 +0100 Subject: Safe location fix: x and z needs floor, while y should be round. --- Essentials/src/com/earth2me/essentials/Util.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java index 52409049d..c1b0ed7bf 100644 --- a/Essentials/src/com/earth2me/essentials/Util.java +++ b/Essentials/src/com/earth2me/essentials/Util.java @@ -266,9 +266,9 @@ public class Util throw new Exception(Util.i18n("destinationNotSet")); } final World world = loc.getWorld(); - int x = (int)Math.round(loc.getX()); + int x = loc.getBlockX(); int y = (int)Math.round(loc.getY()); - int z = (int)Math.round(loc.getZ()); + int z = loc.getBlockZ(); while (isBlockAboveAir(world, x, y, z)) { -- cgit v1.2.3 From 7a27be54f83ccd5646072a38ec7c86839cb33e17 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Tue, 4 Oct 2011 06:54:45 +0100 Subject: Updating to CB 1240 Bukkit 875 --- .../src/com/earth2me/essentials/FakeWorld.java | 18 ++++++ .../src/com/earth2me/essentials/OfflinePlayer.java | 15 ++++- .../src/com/earth2me/essentials/PlayerWrapper.java | 12 ++++ .../test/com/earth2me/essentials/FakeServer.java | 73 ++++++++++++++++++++-- 4 files changed, 110 insertions(+), 8 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/FakeWorld.java b/Essentials/src/com/earth2me/essentials/FakeWorld.java index 8894e8df1..0b5d68be1 100644 --- a/Essentials/src/com/earth2me/essentials/FakeWorld.java +++ b/Essentials/src/com/earth2me/essentials/FakeWorld.java @@ -5,6 +5,7 @@ import java.util.UUID; import org.bukkit.BlockChangeDelegate; import org.bukkit.Chunk; import org.bukkit.ChunkSnapshot; +import org.bukkit.Difficulty; import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.TreeType; @@ -437,4 +438,21 @@ public class FakeWorld implements World throw new UnsupportedOperationException("Not supported yet."); } + @Override + public Difficulty getDifficulty() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void setDifficulty(Difficulty difficulty) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public int getSeaLevel() + { + throw new UnsupportedOperationException("Not supported yet."); + } } diff --git a/Essentials/src/com/earth2me/essentials/OfflinePlayer.java b/Essentials/src/com/earth2me/essentials/OfflinePlayer.java index 07092d0bb..1b0058f24 100644 --- a/Essentials/src/com/earth2me/essentials/OfflinePlayer.java +++ b/Essentials/src/com/earth2me/essentials/OfflinePlayer.java @@ -695,7 +695,7 @@ public class OfflinePlayer implements Player { throw new UnsupportedOperationException("Not supported yet."); } - + @Override public Location getBedSpawnLocation() { @@ -713,5 +713,16 @@ public class OfflinePlayer implements Player { throw new UnsupportedOperationException("Not supported yet."); } - + + @Override + public void setPlayerListName(String name) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String getPlayerListName() + { + throw new UnsupportedOperationException("Not supported yet."); + } } diff --git a/Essentials/src/com/earth2me/essentials/PlayerWrapper.java b/Essentials/src/com/earth2me/essentials/PlayerWrapper.java index 2b6dd92ad..4b998af47 100644 --- a/Essentials/src/com/earth2me/essentials/PlayerWrapper.java +++ b/Essentials/src/com/earth2me/essentials/PlayerWrapper.java @@ -744,4 +744,16 @@ public class PlayerWrapper implements Player base.setSprinting(bln); } + @Override + public void setPlayerListName(String name) + { + base.setPlayerListName(name); + } + + @Override + public String getPlayerListName() + { + return base.getPlayerListName(); + } + } diff --git a/Essentials/test/com/earth2me/essentials/FakeServer.java b/Essentials/test/com/earth2me/essentials/FakeServer.java index ac5636c61..2344c4513 100644 --- a/Essentials/test/com/earth2me/essentials/FakeServer.java +++ b/Essentials/test/com/earth2me/essentials/FakeServer.java @@ -1,6 +1,7 @@ package com.earth2me.essentials; import com.avaje.ebean.config.ServerConfig; +import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -14,7 +15,9 @@ import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.World; import org.bukkit.World.Environment; +import org.bukkit.WorldCreator; import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.PluginCommand; import org.bukkit.entity.Player; import org.bukkit.generator.ChunkGenerator; @@ -43,41 +46,48 @@ public class FakeServer implements Server return "1.0"; } + @Override public Player[] getOnlinePlayers() { return players.toArray(new Player[0]); } - + public void setOnlinePlayers(List players) { this.players = players; } + @Override public int getMaxPlayers() { return 100; } + @Override public int getPort() { return 25565; } + @Override public String getIp() { return "127.0.0.1"; } + @Override public String getServerName() { return "Test Server"; } + @Override public String getServerId() { return "Test Server"; } + @Override public int broadcastMessage(String string) { int i = 0; @@ -89,11 +99,19 @@ public class FakeServer implements Server return i; } + @Override public String getUpdateFolder() { return "update"; } + @Override + public File getUpdateFolderFile() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override public Player getPlayer(String string) { for (Player player : players) @@ -106,6 +124,7 @@ public class FakeServer implements Server return null; } + @Override public List matchPlayer(String string) { List matches = new ArrayList(); @@ -119,15 +138,17 @@ public class FakeServer implements Server return matches; } + @Override public PluginManager getPluginManager() { throw new UnsupportedOperationException("Not supported yet."); } + @Override public BukkitScheduler getScheduler() { - return new BukkitScheduler() { - + return new BukkitScheduler() + { @Override public int scheduleSyncDelayedTask(Plugin plugin, Runnable r, long l) { @@ -215,16 +236,19 @@ public class FakeServer implements Server }; } + @Override public ServicesManager getServicesManager() { throw new UnsupportedOperationException("Not supported yet."); } + @Override public List getWorlds() { return worlds; } + @Override public World createWorld(String string, Environment e) { World w = new FakeWorld(string, e); @@ -232,6 +256,7 @@ public class FakeServer implements Server return w; } + @Override public World createWorld(String string, Environment e, long l) { World w = new FakeWorld(string, e); @@ -239,45 +264,54 @@ public class FakeServer implements Server return w; } + @Override public World getWorld(String string) { for (World world : worlds) { - if (world.getName().equalsIgnoreCase(string)) { + if (world.getName().equalsIgnoreCase(string)) + { return world; } } return null; } + @Override public void reload() { } + @Override public Logger getLogger() { return Logger.getLogger("Minecraft"); } + @Override public PluginCommand getPluginCommand(String string) { throw new UnsupportedOperationException("Not supported yet."); } + @Override public void savePlayers() { } + @Override public boolean dispatchCommand(CommandSender cs, String string) { throw new UnsupportedOperationException("Not supported yet."); } + @Override public void configureDbConfig(ServerConfig sc) { throw new UnsupportedOperationException("Not supported yet."); } + @Override public boolean addRecipe(Recipe recipe) { throw new UnsupportedOperationException("Not supported yet."); @@ -287,7 +321,7 @@ public class FakeServer implements Server { players.add(base1); } - + public OfflinePlayer createPlayer(String name, IEssentials ess) { OfflinePlayer player = new OfflinePlayer(name, ess); @@ -295,41 +329,55 @@ public class FakeServer implements Server return player; } + @Override public World createWorld(String string, Environment e, ChunkGenerator cg) { throw new UnsupportedOperationException("Not supported yet."); } + @Override public World createWorld(String string, Environment e, long l, ChunkGenerator cg) { throw new UnsupportedOperationException("Not supported yet."); } + @Override + public World createWorld(WorldCreator creator) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override public boolean unloadWorld(String string, boolean bln) { throw new UnsupportedOperationException("Not supported yet."); } + @Override public boolean unloadWorld(World world, boolean bln) { throw new UnsupportedOperationException("Not supported yet."); } + @Override public Map getCommandAliases() { throw new UnsupportedOperationException("Not supported yet."); } + @Override public int getSpawnRadius() { throw new UnsupportedOperationException("Not supported yet."); } + @Override public void setSpawnRadius(int i) { throw new UnsupportedOperationException("Not supported yet."); } + @Override public boolean getOnlineMode() { throw new UnsupportedOperationException("Not supported yet."); @@ -340,6 +388,7 @@ public class FakeServer implements Server throw new UnsupportedOperationException("Not supported yet."); } + @Override public World getWorld(UUID uuid) { throw new UnsupportedOperationException("Not supported yet."); @@ -454,7 +503,19 @@ public class FakeServer implements Server } @Override - public void setDefaultGameMode(GameMode gm) + public void setDefaultGameMode(GameMode gamemode) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public ConsoleCommandSender getConsoleSender() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Set getOperators() { throw new UnsupportedOperationException("Not supported yet."); } -- cgit v1.2.3 From c97e69cd71afe34812fcbbe6af33ce92eff1218f Mon Sep 17 00:00:00 2001 From: KHobbits Date: Tue, 4 Oct 2011 06:55:42 +0100 Subject: Removing a few restrictions on manuadd, it shouldnt be a clone of manpromote after all. --- .../src/org/anjocaido/groupmanager/GroupManager.java | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index a13406eab..0fe8a15d4 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -365,15 +365,7 @@ public class GroupManager extends JavaPlugin { sender.sendMessage(ChatColor.RED + "Can't modify player involving a group that you don't inherit."); return false; } - if (!isConsole && !isOpOverride && (!permissionHandler.hasGroupInInheritance(auxUser.getGroup(), auxGroup.getName()) && !permissionHandler.hasGroupInInheritance(auxGroup, auxUser.getGroupName()))) { - sender.sendMessage(ChatColor.RED + "Can't modify player using groups with different heritage line."); - return false; - } - if (!isConsole && !isOpOverride && (!permissionHandler.hasGroupInInheritance(auxGroup, auxUser.getGroupName()))) { - sender.sendMessage(ChatColor.RED + "The new group must be a higher rank."); - return false; - } - + //PARECE OK auxUser.setGroup(auxGroup); sender.sendMessage(ChatColor.YELLOW + "You changed player '" + auxUser.getName() + "' group to '" + auxGroup.getName() + "'."); -- cgit v1.2.3 From fd43a6898eccccf7cbf9c21aeb4b50b7a1b4f26f Mon Sep 17 00:00:00 2001 From: KHobbits Date: Tue, 4 Oct 2011 07:21:09 +0100 Subject: Adding list name to /nick support. --- .../src/com/earth2me/essentials/EssentialsPlayerListener.java | 10 +++++----- Essentials/src/com/earth2me/essentials/User.java | 6 ++++++ .../src/com/earth2me/essentials/commands/Commandnick.java | 8 ++++---- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index 2f690910f..ddf0a6806 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -46,11 +46,11 @@ public class EssentialsPlayerListener extends PlayerListener public void onPlayerRespawn(final PlayerRespawnEvent event) { final User user = ess.getUser(event.getPlayer()); - user.setDisplayName(user.getNick()); + user.setDisplayNick(user.getNick()); updateCompass(user); if (ess.getSettings().changeDisplayName()) { - user.setDisplayName(user.getNick()); + user.setDisplayNick(user.getNick()); } } @@ -76,7 +76,7 @@ public class EssentialsPlayerListener extends PlayerListener user.updateActivity(true); if (ess.getSettings().changeDisplayName()) { - user.setDisplayName(user.getNick()); + user.setDisplayNick(user.getNick()); } } @@ -262,7 +262,7 @@ public class EssentialsPlayerListener extends PlayerListener if (ess.getSettings().changeDisplayName()) { - user.setDisplayName(user.getNick()); + user.setDisplayNick(user.getNick()); } user.updateActivity(false); if (user.isAuthorized("essentials.sleepingignored")) @@ -351,7 +351,7 @@ public class EssentialsPlayerListener extends PlayerListener final User user = ess.getUser(event.getPlayer()); if (ess.getSettings().changeDisplayName()) { - user.setDisplayName(user.getNick()); + user.setDisplayNick(user.getNick()); } updateCompass(user); } diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java index b68e93656..fe811e50f 100644 --- a/Essentials/src/com/earth2me/essentials/User.java +++ b/Essentials/src/com/earth2me/essentials/User.java @@ -282,6 +282,12 @@ public class User extends UserData implements Comparable, IReplyTo, IUser return nickname.toString(); } + + public void setDisplayNick(String name) + { + setDisplayName(name); + setPlayerListName(name); + } public Teleport getTeleport() { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java index 253ec7646..f2165aebc 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java @@ -41,7 +41,7 @@ public class Commandnick extends EssentialsCommand String nick = args[0]; if ("off".equalsIgnoreCase(nick) || user.getName().equalsIgnoreCase(nick)) { - user.setDisplayName(user.getName()); + user.setDisplayNick(user.getName()); user.setNickname(null); user.sendMessage(Util.i18n("nickNoMore")); return; @@ -67,7 +67,7 @@ public class Commandnick extends EssentialsCommand } } - user.setDisplayName(ess.getSettings().getNicknamePrefix() + nick); + user.setDisplayNick(ess.getSettings().getNicknamePrefix() + nick); user.setNickname(nick); user.sendMessage(Util.format("nickSet", user.getDisplayName() + "§7.")); } @@ -95,13 +95,13 @@ public class Commandnick extends EssentialsCommand String nick = args[1]; if ("off".equalsIgnoreCase(nick) || target.getName().equalsIgnoreCase(nick)) { - target.setDisplayName(target.getName()); + target.setDisplayNick(target.getName()); target.setNickname(null); target.sendMessage(Util.i18n("nickNoMore")); } else { - target.setDisplayName(ess.getSettings().getNicknamePrefix() + nick); + target.setDisplayNick(ess.getSettings().getNicknamePrefix() + nick); target.setNickname(nick); target.sendMessage(Util.format("nickSet", target.getDisplayName() + "§7.")); } -- cgit v1.2.3 From a58ba8e931de926e49123ec1cc36d8ff2eb9c78d Mon Sep 17 00:00:00 2001 From: KHobbits Date: Tue, 4 Oct 2011 08:34:06 +0100 Subject: Add hunger replenish to /heal (Do we want to add a toggle?) --- Essentials/src/com/earth2me/essentials/commands/Commandheal.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandheal.java b/Essentials/src/com/earth2me/essentials/commands/Commandheal.java index d60fc09fe..68de488af 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandheal.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandheal.java @@ -34,6 +34,7 @@ public class Commandheal extends EssentialsCommand user.healCooldown(); } user.setHealth(20); + user.setFoodLevel(20); user.sendMessage(Util.i18n("heal")); } -- cgit v1.2.3 From 07c8537d07d1d7ded18b31039a14d9a4138d6ddc Mon Sep 17 00:00:00 2001 From: KHobbits Date: Tue, 4 Oct 2011 09:05:04 +0100 Subject: FoodLevelChange event, update. --- .../src/com/earth2me/essentials/EssentialsEntityListener.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java b/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java index 2eda73540..f5d6cec48 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java @@ -84,10 +84,12 @@ public class EssentialsEntityListener extends EntityListener @Override public void onFoodLevelChange(FoodLevelChangeEvent event) - { + { if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled()) - { + { + //TODO: Remove the following line, when we're happy to remove backwards compatability with 1185. event.setFoodLevel(20); + event.setCancelled(true); } } } -- cgit v1.2.3 From 8954cf111c8451ac1567e4a78e4809e4bf4a97b2 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Tue, 4 Oct 2011 09:23:44 +0100 Subject: Adding unjail alias to tjail. --- Essentials/src/plugin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Essentials/src/plugin.yml b/Essentials/src/plugin.yml index 0c5f689a7..61a054c45 100644 --- a/Essentials/src/plugin.yml +++ b/Essentials/src/plugin.yml @@ -293,7 +293,7 @@ commands: togglejail: description: Prevents a player from interacting with the world and teleports him/her to the the jail specified usage: / [player] [jailname] - aliases: [tjail,etogglejail] + aliases: [tjail,unjail,eunjail,etogglejail] top: description: Teleport to the highest block at your current position. usage: / -- cgit v1.2.3 -- cgit v1.2.3