diff options
author | okamosy <okamosy@gmail.com> | 2011-09-10 09:39:15 +0100 |
---|---|---|
committer | okamosy <okamosy@gmail.com> | 2011-09-10 09:39:15 +0100 |
commit | 8d6e3e7c18f6b292440db737f48337e093ea5073 (patch) | |
tree | 28e9239fc02f764f6146322a3fa51764f4251fa8 | |
parent | 8249a961f6c9a2fe1d550b3d5d32f3a21f2ea378 (diff) | |
parent | 0b057d8e29a7f91e1ab27d99d9c9d4aaa53bdebf (diff) | |
download | Essentials-8d6e3e7c18f6b292440db737f48337e093ea5073.tar Essentials-8d6e3e7c18f6b292440db737f48337e093ea5073.tar.gz Essentials-8d6e3e7c18f6b292440db737f48337e093ea5073.tar.lz Essentials-8d6e3e7c18f6b292440db737f48337e093ea5073.tar.xz Essentials-8d6e3e7c18f6b292440db737f48337e093ea5073.zip |
Merge branch 'master' of github.com:essentials/Essentials
121 files changed, 1431 insertions, 750 deletions
diff --git a/.gitignore b/.gitignore index 7152ec996..4d5963e6b 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,8 @@ /EssentialsPermissionsCommands/dist/ /Essentials/nbproject/private/ /Essentials/dist/ -/Essentials/build/
\ No newline at end of file +/Essentials/build/ +/YamlAnnotations/ +/EssentialsUpdate/nbproject/private/ +/EssentialsRelease/ +/EssentialsUpdate/
\ No newline at end of file diff --git a/Essentials/nbproject/project.properties b/Essentials/nbproject/project.properties index 8df8ef4d2..db78855e6 100644 --- a/Essentials/nbproject/project.properties +++ b/Essentials/nbproject/project.properties @@ -62,6 +62,7 @@ dist.javadoc.dir=${dist.dir}/javadoc endorsed.classpath= excludes= file.reference.BOSEconomy7.jar=../lib/BOSEconomy7.jar +file.reference.bPermissions.jar=../lib/bPermissions.jar file.reference.craftbukkit-0.0.1-SNAPSHOT.jar=..\\lib\\craftbukkit-0.0.1-SNAPSHOT.jar file.reference.iCo4.jar=../lib/iCo4.jar file.reference.iCo5.jar=../lib/iCo5.jar @@ -69,6 +70,7 @@ file.reference.iCo6.jar=../lib/iCo6.jar file.reference.junit-4.5.jar=..\\lib\\junit_4\\junit-4.5.jar file.reference.MultiCurrency.jar=../lib/MultiCurrency.jar file.reference.Permissions3.jar=../lib/Permissions3.jar +file.reference.PermissionsBukkit-1.2.jar=../lib/PermissionsBukkit-1.2.jar file.reference.PermissionsEx.jar=../lib/PermissionsEx.jar includes=** jar.archive.disabled=${jnlp.enabled} @@ -82,7 +84,9 @@ javac.classpath=\ ${file.reference.iCo6.jar}:\ ${file.reference.MultiCurrency.jar}:\ ${file.reference.BOSEconomy7.jar}:\ - ${file.reference.PermissionsEx.jar} + ${file.reference.PermissionsEx.jar}:\ + ${file.reference.bPermissions.jar}:\ + ${file.reference.PermissionsBukkit-1.2.jar} # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false diff --git a/Essentials/src/com/earth2me/essentials/Backup.java b/Essentials/src/com/earth2me/essentials/Backup.java index 6b88eaef9..b7b441b1e 100644 --- a/Essentials/src/com/earth2me/essentials/Backup.java +++ b/Essentials/src/com/earth2me/essentials/Backup.java @@ -1,35 +1,45 @@ package com.earth2me.essentials; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStreamReader; import java.util.logging.Level; import java.util.logging.Logger; import org.bukkit.command.CommandSender; import org.bukkit.craftbukkit.CraftServer; -public class Backup implements Runnable { - private static final Logger logger = Logger.getLogger("Minecraft"); - private final CraftServer server; - private final IEssentials ess; - private boolean running = false; - private int taskId = -1; - private boolean active = false; - public Backup(IEssentials ess) { +public class Backup implements Runnable +{ + private static final Logger LOGGER = Logger.getLogger("Minecraft"); + private transient final CraftServer server; + private transient final IEssentials ess; + private transient boolean running = false; + private transient int taskId = -1; + private transient boolean active = false; + + public Backup(final IEssentials ess) + { this.ess = ess; server = (CraftServer)ess.getServer(); - if (server.getOnlinePlayers().length > 0) { + if (server.getOnlinePlayers().length > 0) + { startTask(); } - } + } - void onPlayerJoin() { + void onPlayerJoin() + { startTask(); } - - private void startTask() { - if (!running) { - long interval = ess.getSettings().getBackupInterval()*1200; // minutes -> ticks - if (interval < 1200) { + + private void startTask() + { + if (!running) + { + final long interval = ess.getSettings().getBackupInterval() * 1200; // minutes -> ticks + if (interval < 1200) + { return; } taskId = ess.scheduleSyncRepeatingTask(this, interval, interval); @@ -37,48 +47,84 @@ public class Backup implements Runnable { } } - public void run() { - if (active) return; + public void run() + { + if (active) + { + return; + } active = true; final String command = ess.getSettings().getBackupCommand(); - if (command == null || "".equals(command)) { + if (command == null || "".equals(command)) + { return; } - logger.log(Level.INFO, Util.i18n("backupStarted")); + LOGGER.log(Level.INFO, Util.i18n("backupStarted")); final CommandSender cs = server.getServer().console; server.dispatchCommand(cs, "save-all"); server.dispatchCommand(cs, "save-off"); - - ess.scheduleAsyncDelayedTask( - new Runnable() { - - public void run() { - try { - Process child = Runtime.getRuntime().exec(command); - child.waitFor(); - } catch (InterruptedException ex) { - logger.log(Level.SEVERE, null, ex); - } catch (IOException ex) { - logger.log(Level.SEVERE, null, ex); - } finally { - ess.scheduleSyncDelayedTask( - new Runnable() { - public void run() { - server.dispatchCommand(cs, "save-on"); - if (server.getOnlinePlayers().length == 0) { - running = false; - if (taskId != -1) { - server.getScheduler().cancelTask(taskId); + ess.scheduleAsyncDelayedTask( + new Runnable() + { + public void run() + { + try + { + final ProcessBuilder childBuilder = new ProcessBuilder(command); + childBuilder.redirectErrorStream(true); + childBuilder.directory(ess.getDataFolder().getParentFile().getParentFile()); + final Process child = childBuilder.start(); + final BufferedReader reader = new BufferedReader(new InputStreamReader(child.getInputStream())); + try + { + child.waitFor(); + String line; + do + { + line = reader.readLine(); + if (line != null) + { + LOGGER.log(Level.INFO, line); + } } + while (line != null); + } + finally + { + reader.close(); } - active = false; - logger.log(Level.INFO, Util.i18n("backupFinished")); } - }); - } - } - }); + catch (InterruptedException ex) + { + LOGGER.log(Level.SEVERE, null, ex); + } + catch (IOException ex) + { + LOGGER.log(Level.SEVERE, null, ex); + } + finally + { + ess.scheduleSyncDelayedTask( + new Runnable() + { + public void run() + { + server.dispatchCommand(cs, "save-on"); + if (server.getOnlinePlayers().length == 0) + { + running = false; + if (taskId != -1) + { + server.getScheduler().cancelTask(taskId); + } + } + active = false; + LOGGER.log(Level.INFO, Util.i18n("backupFinished")); + } + }); + } + } + }); } - } diff --git a/Essentials/src/com/earth2me/essentials/BukkitPermissionsHandler.java b/Essentials/src/com/earth2me/essentials/BukkitPermissionsHandler.java deleted file mode 100644 index aee9ef0b4..000000000 --- a/Essentials/src/com/earth2me/essentials/BukkitPermissionsHandler.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.earth2me.essentials; - -import org.bukkit.entity.Player; - - -public class BukkitPermissionsHandler implements IPermissionsHandler -{ - public String getGroup(Player base) - { - return "default"; - } - - public boolean canBuild(Player base, String group) - { - return true; - } - - public boolean inGroup(Player base, String group) - { - return false; - } - - public boolean hasPermission(Player base, String node) - { - if (base.hasPermission("-" + node)) - { - return false; - } - final String[] parts = node.split("\\."); - final StringBuilder sb = new StringBuilder(); - for (String part : parts) - { - if (base.hasPermission(sb.toString() + "*")) - { - return true; - } - sb.append(part).append("."); - } - return base.hasPermission(node); - } - - public String getPrefix(Player base) - { - return ""; - } - - public String getSuffix(Player base) - { - return ""; - } -} diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index b74b2b5c4..386e9cc5a 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -26,7 +26,9 @@ import org.bukkit.*; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import com.earth2me.essentials.commands.IEssentialsCommand; +import com.earth2me.essentials.commands.NoChargeException; import com.earth2me.essentials.commands.NotEnoughArgumentsException; +import com.earth2me.essentials.perm.PermissionsHandler; import com.earth2me.essentials.register.payment.Methods; import com.earth2me.essentials.signs.SignBlockListener; import com.earth2me.essentials.signs.SignEntityListener; @@ -38,7 +40,6 @@ import org.bukkit.command.PluginCommand; import org.bukkit.entity.Player; import org.bukkit.event.Event.Priority; import org.bukkit.event.Event.Type; -import org.bukkit.event.server.ServerListener; import org.bukkit.plugin.*; import org.bukkit.plugin.java.*; import org.bukkit.scheduler.BukkitScheduler; @@ -62,7 +63,7 @@ public class Essentials extends JavaPlugin implements IEssentials private transient final Methods paymentMethod = new Methods(); private transient final static boolean enableErrorLogging = false; private transient final EssentialsErrorHandler errorHandler = new EssentialsErrorHandler(); - private transient IPermissionsHandler permissionsHandler; + private transient PermissionsHandler permissionsHandler; private transient UserMap userMap; @Override @@ -87,7 +88,7 @@ public class Essentials extends JavaPlugin implements IEssentials this.initialize(null, server, new PluginDescriptionFile(new FileReader(new File("src" + File.separator + "plugin.yml"))), dataFolder, null, null); settings = new Settings(this); userMap = new UserMap(this); - permissionsHandler = new ConfigPermissionsHandler(this); + permissionsHandler = new PermissionsHandler(this, false); Economy.setEss(this); } @@ -148,9 +149,11 @@ public class Essentials extends JavaPlugin implements IEssentials LOGGER.log(Level.INFO, Util.i18n("bukkitFormatChanged")); } - final ServerListener serverListener = new EssentialsPluginListener(this); + permissionsHandler = new PermissionsHandler(this, settings.useBukkitPermissions()); + final EssentialsPluginListener serverListener = new EssentialsPluginListener(this); pm.registerEvent(Type.PLUGIN_ENABLE, serverListener, Priority.Low, this); pm.registerEvent(Type.PLUGIN_DISABLE, serverListener, Priority.Low, this); + confList.add(serverListener); final EssentialsPlayerListener playerListener = new EssentialsPlayerListener(this); pm.registerEvent(Type.PLAYER_JOIN, playerListener, Priority.Monitor, this); @@ -207,12 +210,12 @@ public class Essentials extends JavaPlugin implements IEssentials pm.registerEvent(Type.ENTITY_EXPLODE, tntListener, Priority.High, this); final EssentialsTimer timer = new EssentialsTimer(this); - getScheduler().scheduleSyncRepeatingTask(this, timer, 1, 50); + getScheduler().scheduleSyncRepeatingTask(this, timer, 1, 100); Economy.setEss(this); if (getSettings().isUpdateEnabled()) { updateTimer = new EssentialsUpdateTimer(this); - getScheduler().scheduleAsyncRepeatingTask(this, updateTimer, 20 * 60, 20 * 3600 * 6); + getScheduler().scheduleAsyncRepeatingTask(this, updateTimer, 20 * 60 * 10, 20 * 3600 * 6); } LOGGER.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), Util.joinList(this.getDescription().getAuthors()))); } @@ -448,6 +451,10 @@ public class Essentials extends JavaPlugin implements IEssentials } return true; } + catch (NoChargeException ex) + { + return true; + } catch (NotEnoughArgumentsException ex) { sender.sendMessage(command.getDescription()); @@ -561,7 +568,7 @@ public class Essentials extends JavaPlugin implements IEssentials } catch (NullPointerException ex) { - return null; + return new User(base, this); } } @@ -605,14 +612,20 @@ public class Essentials extends JavaPlugin implements IEssentials } @Override - public int broadcastMessage(final String name, final String message) + public int broadcastMessage(final IUser sender, final String message) { + if (sender == null) { + return getServer().broadcastMessage(message); + } + if (sender.isHidden()) { + return 0; + } final Player[] players = getServer().getOnlinePlayers(); for (Player player : players) { final User user = getUser(player); - if (!user.isIgnoredPlayer(name)) + if (!user.isIgnoredPlayer(sender.getName())) { player.sendMessage(message); } @@ -657,18 +670,12 @@ public class Essentials extends JavaPlugin implements IEssentials } @Override - public IPermissionsHandler getPermissionsHandler() + public PermissionsHandler getPermissionsHandler() { return permissionsHandler; } @Override - public void setPermissionsHandler(final IPermissionsHandler handler) - { - this.permissionsHandler = handler; - } - - @Override public BanWorkaround getBans() { return bans; diff --git a/Essentials/src/com/earth2me/essentials/EssentialsConf.java b/Essentials/src/com/earth2me/essentials/EssentialsConf.java index 2e3920eba..c48f9f987 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsConf.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsConf.java @@ -47,11 +47,6 @@ public class EssentialsConf extends Configuration LOGGER.log(Level.SEVERE, Util.format("failedToCreateConfig", configFile.toString())); } } - if (configFile.exists() && configFile.length() == 0 && !configFile.delete()) - { - LOGGER.log(Level.SEVERE, "Could not delete file " + configFile.toString()); - } - // This will delete files where the first character is 0. In most cases they are broken. if (configFile.exists() && configFile.length() != 0) { diff --git a/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java b/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java index 91c4bdce4..ce97726dc 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java @@ -1,13 +1,10 @@ package com.earth2me.essentials; import java.util.List; -import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityCombustEvent; -import org.bukkit.event.entity.EntityDamageByBlockEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageByProjectileEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityListener; @@ -52,16 +49,12 @@ public class EssentialsEntityListener extends EntityListener } } } - if (event instanceof EntityDamageEvent || event instanceof EntityDamageByBlockEvent || event instanceof EntityDamageByProjectileEvent) + if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled()) { - - if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled()) - { - CraftPlayer player = (CraftPlayer)event.getEntity(); - player.getHandle().fireTicks = 0; - player.setRemainingAir(player.getMaximumAir()); - event.setCancelled(true); - } + final Player player = (Player)event.getEntity(); + player.setFireTicks(0); + player.setRemainingAir(player.getMaximumAir()); + event.setCancelled(true); } } diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index fbd6995c5..c70afa20d 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -73,7 +73,7 @@ public class EssentialsPlayerListener extends PlayerListener it.remove(); } } - user.updateActivity(); + user.updateActivity(true); if (ess.getSettings().changeDisplayName()) { user.setDisplayName(user.getNick()); @@ -107,7 +107,10 @@ public class EssentialsPlayerListener extends PlayerListener return; } - user.updateActivity(); + 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()) { @@ -226,7 +229,7 @@ public class EssentialsPlayerListener extends PlayerListener user.getInventory().setContents(user.getSavedInventory()); user.setSavedInventory(null); } - user.updateActivity(); + user.updateActivity(false); user.dispose(); if (!ess.getSettings().getReclaimSetting()) { @@ -275,7 +278,7 @@ public class EssentialsPlayerListener extends PlayerListener { user.setDisplayName(user.getNick()); } - user.setAfk(false); + user.updateActivity(false); if (user.isAuthorized("essentials.sleepingignored")) { user.setSleepingIgnored(true); @@ -310,15 +313,11 @@ public class EssentialsPlayerListener extends PlayerListener @Override public void onPlayerLogin(final PlayerLoginEvent event) { - if (event.getResult() != Result.ALLOWED && event.getResult() != Result.KICK_FULL) + if (event.getResult() != Result.ALLOWED && event.getResult() != Result.KICK_FULL && event.getResult() != Result.KICK_BANNED) { return; } User user = ess.getUser(event.getPlayer()); - if (user == null) - { - user = new User(event.getPlayer(), ess); - } user.setNPC(false); final long currentTime = System.currentTimeMillis(); @@ -466,7 +465,7 @@ public class EssentialsPlayerListener extends PlayerListener } else { - user.getServer().dispatchCommand(user, command); + user.getServer().dispatchCommand(event.getPlayer(), command); } } } @@ -493,7 +492,7 @@ public class EssentialsPlayerListener extends PlayerListener } if (!cmd.equalsIgnoreCase("afk")) { - user.updateActivity(); + user.updateActivity(true); } } } diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPluginListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPluginListener.java index 34632dd40..e64496171 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPluginListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPluginListener.java @@ -1,16 +1,13 @@ package com.earth2me.essentials; -import com.earth2me.essentials.register.payment.Methods; import java.util.logging.Level; import java.util.logging.Logger; import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.event.server.ServerListener; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginManager; -public class EssentialsPluginListener extends ServerListener +public class EssentialsPluginListener extends ServerListener implements IConf { private final transient IEssentials ess; private static final Logger LOGGER = Logger.getLogger("Minecraft"); @@ -23,7 +20,7 @@ public class EssentialsPluginListener extends ServerListener @Override public void onPluginEnable(final PluginEnableEvent event) { - checkPermissions(); + ess.getPermissionsHandler().checkPermissions(); if (!ess.getPaymentMethod().hasMethod() && ess.getPaymentMethod().setMethod(event.getPlugin())) { LOGGER.log(Level.INFO, "[Essentials] Payment method found (" + ess.getPaymentMethod().getMethod().getName() + " version: " + ess.getPaymentMethod().getMethod().getVersion() + ")"); @@ -32,50 +29,20 @@ public class EssentialsPluginListener extends ServerListener } @Override - public void onPluginDisable(PluginDisableEvent event) + public void onPluginDisable(final PluginDisableEvent event) { - checkPermissions(); + ess.getPermissionsHandler().checkPermissions(); // 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())) { LOGGER.log(Level.INFO, "[Essentials] Payment method was disabled. No longer accepting payments."); } } - - private void checkPermissions() - { - final PluginManager pm = ess.getServer().getPluginManager(); - final Plugin permissionsExPlugin = pm.getPlugin("PermissionsEx"); - if (permissionsExPlugin == null || !permissionsExPlugin.isEnabled()) - { - final Plugin permissionsPlugin = pm.getPlugin("Permissions"); - if (permissionsPlugin == null || !permissionsPlugin.isEnabled()) - { - if (ess.getSettings().useBukkitPermissions()) - { - ess.setPermissionsHandler(new BukkitPermissionsHandler()); - } - else - { - ess.setPermissionsHandler(new ConfigPermissionsHandler(ess)); - } - } - else - { - if (permissionsPlugin.getDescription().getVersion().charAt(0) == '3') - { - ess.setPermissionsHandler(new Permissions3Handler(permissionsPlugin)); - } - else - { - ess.setPermissionsHandler(new Permissions2Handler(permissionsPlugin)); - } - } - } - else - { - ess.setPermissionsHandler(new PermissionsExHandler()); - } + @Override + public void reloadConfig() + { + ess.getPermissionsHandler().setUseSuperperms(ess.getSettings().useBukkitPermissions()); + ess.getPermissionsHandler().checkPermissions(); } } diff --git a/Essentials/src/com/earth2me/essentials/IEssentials.java b/Essentials/src/com/earth2me/essentials/IEssentials.java index 9f427b220..0ac8c54d3 100644 --- a/Essentials/src/com/earth2me/essentials/IEssentials.java +++ b/Essentials/src/com/earth2me/essentials/IEssentials.java @@ -1,5 +1,6 @@ package com.earth2me.essentials; +import com.earth2me.essentials.perm.PermissionsHandler; import com.earth2me.essentials.register.payment.Methods; import org.bukkit.World; import org.bukkit.command.Command; @@ -22,7 +23,7 @@ public interface IEssentials extends Plugin World getWorld(String name); - int broadcastMessage(String name, String message); + int broadcastMessage(IUser sender, String message); ISettings getSettings(); @@ -56,9 +57,7 @@ public interface IEssentials extends Plugin TNTExplodeListener getTNTListener(); - IPermissionsHandler getPermissionsHandler(); - - void setPermissionsHandler(IPermissionsHandler handler); + PermissionsHandler getPermissionsHandler(); void showError(final CommandSender sender, final Throwable exception, final String commandLabel); diff --git a/Essentials/src/com/earth2me/essentials/IUser.java b/Essentials/src/com/earth2me/essentials/IUser.java index 91a121e0a..27f95430c 100644 --- a/Essentials/src/com/earth2me/essentials/IUser.java +++ b/Essentials/src/com/earth2me/essentials/IUser.java @@ -54,4 +54,6 @@ public interface IUser InetSocketAddress getAddress(); String getDisplayName(); + + boolean isHidden(); } diff --git a/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java b/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java index 9aee4033c..3f0f89af2 100644 --- a/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java +++ b/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java @@ -3,7 +3,6 @@ package com.earth2me.essentials; import java.util.HashMap; import java.util.Map; import org.bukkit.Location; -import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.entity.Item; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; @@ -130,7 +129,7 @@ public final class InventoryWorkaround // More than a single stack! if (item.getAmount() > item.getType().getMaxStackSize()) { - cinventory.setItem(firstFree, new CraftItemStack(item.getTypeId(), item.getType().getMaxStackSize(), item.getDurability())); + cinventory.setItem(firstFree, new ItemStack(item.getTypeId(), item.getType().getMaxStackSize(), item.getDurability())); item.setAmount(item.getAmount() - item.getType().getMaxStackSize()); } else diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java index 2b7eea8f6..665da17a6 100644 --- a/Essentials/src/com/earth2me/essentials/Settings.java +++ b/Essentials/src/com/earth2me/essentials/Settings.java @@ -483,7 +483,7 @@ public class Settings implements ISettings @Override public boolean isUpdateEnabled() { - return config.getBoolean("update-check", true); + return config.getBoolean("update-check", false); } @Override diff --git a/Essentials/src/com/earth2me/essentials/TNTExplodeListener.java b/Essentials/src/com/earth2me/essentials/TNTExplodeListener.java index bdd453266..90c66aa35 100644 --- a/Essentials/src/com/earth2me/essentials/TNTExplodeListener.java +++ b/Essentials/src/com/earth2me/essentials/TNTExplodeListener.java @@ -4,6 +4,8 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; import net.minecraft.server.ChunkPosition; import net.minecraft.server.Packet60Explosion; import org.bukkit.Location; @@ -52,6 +54,7 @@ public class TNTExplodeListener extends EntityListener implements Runnable { return; } + try { final Set<ChunkPosition> set = new HashSet<ChunkPosition>(event.blockList().size()); final Player[] players = ess.getServer().getOnlinePlayers(); final List<ChunkPosition> blocksUnderPlayers = new ArrayList<ChunkPosition>(players.length); @@ -72,6 +75,9 @@ public class TNTExplodeListener extends EntityListener implements Runnable } } ((CraftServer)ess.getServer()).getHandle().sendPacketNearby(loc.getX(), loc.getY(), loc.getZ(), 64.0, ((CraftWorld)loc.getWorld()).getHandle().worldProvider.dimension, new Packet60Explosion(loc.getX(), loc.getY(), loc.getZ(), 3.0F, set)); + } catch (Throwable ex) { + Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex); + } event.setCancelled(true); } diff --git a/Essentials/src/com/earth2me/essentials/Teleport.java b/Essentials/src/com/earth2me/essentials/Teleport.java index 14574b83c..608663561 100644 --- a/Essentials/src/com/earth2me/essentials/Teleport.java +++ b/Essentials/src/com/earth2me/essentials/Teleport.java @@ -264,14 +264,7 @@ public class Teleport implements Runnable final Location loc = user.getHome(home); if (loc == null) { - if (ess.getSettings().spawnIfNoHome()) - { - respawn(ess.getSpawn(), chargeFor); - } - else - { - throw new NotEnoughArgumentsException(); - } + throw new NotEnoughArgumentsException(); } teleport(new Target(loc), chargeFor); } diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java index d160a6f07..4a93fa264 100644 --- a/Essentials/src/com/earth2me/essentials/User.java +++ b/Essentials/src/com/earth2me/essentials/User.java @@ -17,16 +17,18 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser private transient User teleportRequester; private transient boolean teleportRequestHere; private transient final Teleport teleport; - private transient long lastOnlineActivity = System.currentTimeMillis();; - private transient long lastActivity; + 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(); } User update(final Player base) @@ -50,6 +52,11 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser @Override public boolean isAuthorized(final String node) { + if (base instanceof OfflinePlayer) + { + return false; + } + if (isOp()) { return true; @@ -60,7 +67,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser return false; } - return ess.getPermissionsHandler().hasPermission(this, node); + return ess.getPermissionsHandler().hasPermission(base, node); } public void healCooldown() throws Exception @@ -264,8 +271,8 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser if (ess.getSettings().addPrefixSuffix()) { - final String prefix = ess.getPermissionsHandler().getPrefix(this).replace('&', '§').replace("{WORLDNAME}", this.getWorld().getName()); - final String suffix = ess.getPermissionsHandler().getSuffix(this).replace('&', '§').replace("{WORLDNAME}", this.getWorld().getName()); + final String prefix = ess.getPermissionsHandler().getPrefix(base).replace('&', '§').replace("{WORLDNAME}", this.getWorld().getName()); + final String suffix = ess.getPermissionsHandler().getSuffix(base).replace('&', '§').replace("{WORLDNAME}", this.getWorld().getName()); nickname.insert(0, prefix); nickname.append(suffix); @@ -341,13 +348,18 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser public void setAfk(final boolean set) { this.setSleepingIgnored(this.isAuthorized("essentials.sleepingignored") ? true : set); - if (set && !isAfk() && ess.getSettings().getFreezeAfkPlayers()) { + if (set && !isAfk() && ess.getSettings().getFreezeAfkPlayers()) + { godStateBeforeAfk = isGodModeEnabled(); setGodModeEnabled(true); } - if (!set && isAfk() && ess.getSettings().getFreezeAfkPlayers()) { + if (!set && isAfk() && ess.getSettings().getFreezeAfkPlayers()) + { setGodModeEnabled(godStateBeforeAfk); } + if (set && !isAfk()) { + afkPosition = getLocation(); + } super.setAfk(set); } @@ -406,13 +418,15 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser } } - public void updateActivity() + public void updateActivity(final boolean broadcast) { if (isAfk()) { setAfk(false); - ess.broadcastMessage(getName(), Util.format("userIsNotAway", getDisplayName())); - return; + if (broadcast && !isHidden()) + { + ess.broadcastMessage(this, Util.format("userIsNotAway", getDisplayName())); + } } lastActivity = System.currentTimeMillis(); } @@ -421,9 +435,9 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser { final long autoafkkick = ess.getSettings().getAutoAfkKick(); if (autoafkkick > 0 && lastActivity + autoafkkick * 1000 < System.currentTimeMillis() - && !isAuthorized("essentials.kick.exempt") && !isAuthorized("essentials.afk.kickexempt")) + && !isHidden() && !isAuthorized("essentials.kick.exempt") && !isAuthorized("essentials.afk.kickexempt")) { - final String kickReason = Util.format("autoAfkKickReason", autoafkkick/60.0); + final String kickReason = Util.format("autoAfkKickReason", autoafkkick / 60.0); kickPlayer(kickReason); @@ -440,7 +454,14 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser if (!isAfk() && autoafk > 0 && lastActivity + autoafk * 1000 < System.currentTimeMillis()) { setAfk(true); - ess.broadcastMessage(getName(), Util.format("userIsAway", getDisplayName())); + if (!isHidden()) { + ess.broadcastMessage(this, Util.format("userIsAway", getDisplayName())); + } } } + + public Location getAfkPosition() + { + return afkPosition; + } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandafk.java b/Essentials/src/com/earth2me/essentials/commands/Commandafk.java index 03950966c..8bf70873d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandafk.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandafk.java @@ -15,8 +15,6 @@ public class Commandafk extends EssentialsCommand @Override public void run(Server server, User user, String commandLabel, String[] args) throws Exception { - charge(user); - if (args.length > 0 && user.isAuthorized("essentials.afk.others")) { User afkUser = ess.getUser(ess.getServer().matchPlayer(args[0])); @@ -35,13 +33,20 @@ public class Commandafk extends EssentialsCommand { if (!user.toggleAfk()) { - user.sendMessage(Util.i18n("markedAsNotAway")); - ess.broadcastMessage(user.getName(), Util.format("userIsNotAway", user.getDisplayName())); + //user.sendMessage(Util.i18n("markedAsNotAway")); + if (!user.isHidden()) + { + ess.broadcastMessage(user, Util.format("userIsNotAway", user.getDisplayName())); + } + user.updateActivity(false); } else { - user.sendMessage(Util.i18n("markedAsAway")); - ess.broadcastMessage(user.getName(), Util.format("userIsAway", user.getDisplayName())); + //user.sendMessage(Util.i18n("markedAsAway")); + if (!user.isHidden()) + { + ess.broadcastMessage(user, Util.format("userIsAway", user.getDisplayName())); + } } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandantioch.java b/Essentials/src/com/earth2me/essentials/commands/Commandantioch.java index 4dd3042d0..5bfdd3835 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandantioch.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandantioch.java @@ -17,9 +17,8 @@ public class Commandantioch extends EssentialsCommand @Override public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { - charge(user); - ess.broadcastMessage(user.getName(), "...lobbest thou thy Holy Hand Grenade of Antioch towards thy foe,"); - ess.broadcastMessage(user.getName(), "who being naughty in My sight, shall snuff it."); + ess.broadcastMessage(user, "...lobbest thou thy Holy Hand Grenade of Antioch towards thy foe,"); + ess.broadcastMessage(user, "who being naughty in My sight, shall snuff it."); final Location loc = new TargetBlock(user).getTargetBlock().getLocation(); loc.getWorld().spawn(loc, TNTPrimed.class); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbackup.java b/Essentials/src/com/earth2me/essentials/commands/Commandbackup.java index 8f6e8e8bf..6bbf8361c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbackup.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbackup.java @@ -19,9 +19,8 @@ public class Commandbackup extends EssentialsCommand Backup backup = ess.getBackup(); if (backup == null) { - return; + throw new Exception(); } - charge(sender); backup.run(); sender.sendMessage(Util.i18n("backupStarted")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java b/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java index 7dd1fb449..d26df68cb 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java @@ -26,7 +26,6 @@ public class Commandbalance extends EssentialsCommand @Override public void run(Server server, User user, String commandLabel, String[] args) throws Exception { - charge(user); double bal = (args.length < 1 || !(user.isAuthorized("essentials.balance.others") || user.isAuthorized("essentials.balance.other")) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbigtree.java b/Essentials/src/com/earth2me/essentials/commands/Commandbigtree.java index 8370896b1..ded3ffdaf 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbigtree.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbigtree.java @@ -41,12 +41,11 @@ public class Commandbigtree extends EssentialsCommand final boolean success = user.getWorld().generateTree(safeLocation, (TreeType)tree); if (success) { - charge(user); user.sendMessage(Util.i18n("bigTreeSuccess")); } else { - user.sendMessage(Util.i18n("bigTreeFailure")); + throw new Exception(Util.i18n("bigTreeFailure")); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java b/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java index 3ca9d3fd0..9b92434a4 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java @@ -1,6 +1,5 @@ package com.earth2me.essentials.commands; -import com.earth2me.essentials.Console; import com.earth2me.essentials.Util; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -15,15 +14,14 @@ public class Commandbroadcast extends EssentialsCommand } @Override - public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception + public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { throw new NotEnoughArgumentsException(); } - charge(sender); - ess.broadcastMessage(sender instanceof Player ? ((Player)sender).getName() : Console.NAME, + ess.broadcastMessage(null, Util.format("broadcast", getFinalArg(args, 0))); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandburn.java b/Essentials/src/com/earth2me/essentials/commands/Commandburn.java index e63331203..5df3cb5d8 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandburn.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandburn.java @@ -21,7 +21,6 @@ public class Commandburn extends EssentialsCommand throw new NotEnoughArgumentsException(); } - charge(sender); for (Player p : server.matchPlayer(args[0])) { p.setFireTicks(Integer.parseInt(args[1]) * 20); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java b/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java index 09496c7a2..447689691 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java @@ -27,7 +27,6 @@ public class Commandclearinventory extends EssentialsCommand if (!online.isEmpty()) { - charge(user); for (Player p : online) { p.getInventory().clear(); @@ -42,7 +41,6 @@ public class Commandclearinventory extends EssentialsCommand Player p = server.getPlayer(args[0]); if (p != null) { - charge(user); p.getInventory().clear(); user.sendMessage(Util.format("inventoryClearedOthers", p.getDisplayName())); } @@ -54,7 +52,6 @@ public class Commandclearinventory extends EssentialsCommand } else { - charge(user); user.getInventory().clear(); user.sendMessage(Util.i18n("inventoryCleared")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandcompass.java b/Essentials/src/com/earth2me/essentials/commands/Commandcompass.java index 0386485f4..bd07c2b9b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandcompass.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandcompass.java @@ -15,7 +15,6 @@ public class Commandcompass extends EssentialsCommand @Override public void run(Server server, User user, String commandLabel, String[] args) throws Exception { - charge(user); int r = (int)user.getCorrectedYaw(); String dir; if (r < 23) dir = "N"; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanddeljail.java b/Essentials/src/com/earth2me/essentials/commands/Commanddeljail.java index 7fb6f816c..23ec04c4e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanddeljail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanddeljail.java @@ -16,7 +16,6 @@ public class Commanddeljail extends EssentialsCommand { { throw new NotEnoughArgumentsException(); } - charge(sender); ess.getJail().delJail(args[0]); sender.sendMessage(Util.format("deleteJail", args[0])); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanddelwarp.java b/Essentials/src/com/earth2me/essentials/commands/Commanddelwarp.java index 42a68dda8..7c2795dda 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanddelwarp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanddelwarp.java @@ -19,7 +19,6 @@ public class Commanddelwarp extends EssentialsCommand { throw new NotEnoughArgumentsException(); } - charge(sender); ess.getWarps().delWarp(args[0]); sender.sendMessage(Util.format("deleteWarp", args[0])); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanddepth.java b/Essentials/src/com/earth2me/essentials/commands/Commanddepth.java index 9a719335e..5ceb62591 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanddepth.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanddepth.java @@ -15,7 +15,6 @@ public class Commanddepth extends EssentialsCommand @Override public void run(Server server, User user, String commandLabel, String[] args) throws Exception { - charge(user); int y = user.getLocation().getBlockY() - 63; if (y > 0) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java index bf0226138..fda7061d5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java @@ -102,7 +102,6 @@ public class Commandessentials extends EssentialsCommand return; } ess.reload(); - charge(sender); sender.sendMessage(Util.format("essentialsReload", ess.getDescription().getVersion())); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandext.java b/Essentials/src/com/earth2me/essentials/commands/Commandext.java index 339351ef1..afb9fa3a6 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandext.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandext.java @@ -30,7 +30,6 @@ public class Commandext extends EssentialsCommand { if (args.length < 1) { - charge(user); user.setFireTicks(0); user.sendMessage(Util.i18n("extinguish")); return; @@ -43,7 +42,6 @@ public class Commandext extends EssentialsCommand { for (Player p : server.matchPlayer(name)) { - charge(sender); p.setFireTicks(0); sender.sendMessage(Util.format("extinguishOthers", p.getDisplayName())); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandfireball.java b/Essentials/src/com/earth2me/essentials/commands/Commandfireball.java index 73c314935..19e7eddf1 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandfireball.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandfireball.java @@ -17,7 +17,6 @@ public class Commandfireball extends EssentialsCommand @Override protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { - charge(user); final Vector direction = user.getEyeLocation().getDirection().multiply(2); user.getWorld().spawn(user.getEyeLocation().add(direction.getX(), direction.getY(), direction.getZ()), Fireball.class); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgc.java b/Essentials/src/com/earth2me/essentials/commands/Commandgc.java index dd3cf35f4..28164bd78 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgc.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgc.java @@ -16,7 +16,6 @@ public class Commandgc extends EssentialsCommand @Override protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception { - charge(sender); sender.sendMessage(Util.format("gcmax", (Runtime.getRuntime().maxMemory() / 1024 / 1024))); sender.sendMessage(Util.format("gcfree", (Runtime.getRuntime().freeMemory() / 1024 / 1024))); sender.sendMessage(Util.format("gctotal", (Runtime.getRuntime().totalMemory() / 1024 / 1024))); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java b/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java index 517ef0c9a..bf5cff75d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java @@ -15,7 +15,6 @@ public class Commandgetpos extends EssentialsCommand @Override public void run(Server server, User user, String commandLabel, String[] args) throws Exception { - charge(user); Location coords = user.getLocation(); user.sendMessage("§7X: " + coords.getBlockX() + " (-North <-> +South)"); user.sendMessage("§7Y: " + coords.getBlockY() + " (+Up <-> -Down)"); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java index 68bfe8a30..065b76d03 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java @@ -36,8 +36,7 @@ public class Commandgive extends EssentialsCommand : (!ess.getUser(sender).isAuthorized("essentials.itemspawn.exempt") && !ess.getUser(sender).canSpawnItem(stack.getTypeId())))) { - sender.sendMessage(ChatColor.RED + "You are not allowed to spawn the item " + itemname); - return; + throw new Exception(ChatColor.RED + "You are not allowed to spawn the item " + itemname); } if (args.length > 2 && Integer.parseInt(args[2]) > 0) { @@ -46,13 +45,11 @@ public class Commandgive extends EssentialsCommand if (stack.getType() == Material.AIR) { - sender.sendMessage(ChatColor.RED + "You can't give air."); - return; + throw new Exception(ChatColor.RED + "You can't give air."); } User giveTo = getPlayer(server, args, 0); String itemName = stack.getType().toString().toLowerCase().replace('_', ' '); - charge(sender); sender.sendMessage(ChatColor.BLUE + "Giving " + stack.getAmount() + " of " + itemName + " to " + giveTo.getDisplayName() + "."); giveTo.getInventory().addItem(stack); giveTo.updateInventory(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgod.java b/Essentials/src/com/earth2me/essentials/commands/Commandgod.java index 6bb9f1390..d4c35e113 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgod.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgod.java @@ -28,7 +28,6 @@ public class Commandgod extends EssentialsCommand @Override protected void run(Server server, User user, String commandLabel, String[] args) throws Exception { - charge(user); if (args.length > 0 && user.isAuthorized("essentials.god.others")) { godOtherPlayers(server, user, args[0]); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandheal.java b/Essentials/src/com/earth2me/essentials/commands/Commandheal.java index effe64604..d60fc09fe 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandheal.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandheal.java @@ -25,7 +25,6 @@ public class Commandheal extends EssentialsCommand { user.healCooldown(); } - charge(user); healOtherPlayers(server, user, args[0]); return; } @@ -34,7 +33,6 @@ public class Commandheal extends EssentialsCommand { user.healCooldown(); } - charge(user); user.setHealth(20); user.sendMessage(Util.i18n("heal")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java b/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java index 53ed22a23..8e99dc1ed 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java @@ -20,6 +20,9 @@ import java.util.logging.Level; public class Commandhelp extends EssentialsCommand { + private static final String DESCRIPTION = "description"; + private static final String PERMISSION = "permission"; + private static final String PERMISSIONS = "permissions"; public final Yaml yaml = new Yaml(new SafeConstructor()); public Commandhelp() @@ -28,7 +31,7 @@ public class Commandhelp extends EssentialsCommand } @Override - protected void run(Server server, User user, String commandLabel, String[] args) throws Exception + protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { int page = 1; String match = ""; @@ -53,34 +56,32 @@ public class Commandhelp extends EssentialsCommand } } - List<String> lines = getHelpLines(user, match); - if (lines.size() > 0) + final List<String> lines = getHelpLines(user, match); + if (lines.isEmpty()) { - int start = (page - 1) * 9; - int pages = lines.size() / 9 + (lines.size() % 9 > 0 ? 1 : 0); - - user.sendMessage(Util.format("helpPages", page, pages)); - for (int i = start; i < lines.size() && i < start + 9; i++) - { - user.sendMessage(lines.get(i)); - } + throw new Exception(Util.i18n("noHelpFound")); } - else + + final int start = (page - 1) * 9; + final int pages = lines.size() / 9 + (lines.size() % 9 > 0 ? 1 : 0); + + user.sendMessage(Util.format("helpPages", page, pages)); + for (int i = start; i < lines.size() && i < start + 9; i++) { - user.sendMessage(Util.i18n("noHelpFound")); + user.sendMessage(lines.get(i)); } } @Override - protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception + protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception { sender.sendMessage(Util.i18n("helpConsole")); } @SuppressWarnings("CallToThreadDumpStack") - private List<String> getHelpLines(User user, String match) throws Exception + private List<String> getHelpLines(final User user, final String match) throws Exception { - List<String> retval = new ArrayList<String>(); + final List<String> retval = new ArrayList<String>(); File helpFile = new File(ess.getDataFolder(), "help_" + Util.sanitizeFileName(user.getName()) + ".txt"); if (!helpFile.exists()) { @@ -116,15 +117,16 @@ public class Commandhelp extends EssentialsCommand try { final PluginDescriptionFile desc = p.getDescription(); - final HashMap<String, HashMap<String, String>> cmds = (HashMap<String, HashMap<String, String>>)desc.getCommands(); + final HashMap<String, HashMap<String, Object>> cmds = (HashMap<String, HashMap<String, Object>>)desc.getCommands(); pluginName = p.getDescription().getName().toLowerCase(); - for (Entry<String, HashMap<String, String>> k : cmds.entrySet()) + for (Entry<String, HashMap<String, Object>> k : cmds.entrySet()) { try { if ((!match.equalsIgnoreCase("")) && (!k.getKey().toLowerCase().contains(match)) - && (!k.getValue().get("description").toLowerCase().contains(match)) + && (!(k.getValue().get(DESCRIPTION) instanceof String + && ((String)k.getValue().get(DESCRIPTION)).toLowerCase().contains(match))) && (!pluginName.contains(match))) { continue; @@ -135,37 +137,69 @@ public class Commandhelp extends EssentialsCommand final String node = "essentials." + k.getKey(); if (!ess.getSettings().isCommandDisabled(k.getKey()) && user.isAuthorized(node)) { - retval.add("§c" + k.getKey() + "§7: " + k.getValue().get("description")); + retval.add("§c" + k.getKey() + "§7: " + k.getValue().get(DESCRIPTION)); } } else { if (ess.getSettings().showNonEssCommandsInHelp()) { - final HashMap<String, String> value = k.getValue(); - if (value.containsKey("permission") && value.get("permission") != null && !(value.get("permission").equals(""))) + final HashMap<String, Object> value = k.getValue(); + if (value.containsKey(PERMISSION) && value.get(PERMISSION) instanceof String && !(value.get(PERMISSION).equals(""))) { - if (user.isAuthorized(value.get("permission"))) + if (user.isAuthorized((String)value.get(PERMISSION))) { - retval.add("§c" + k.getKey() + "§7: " + value.get("description")); + retval.add("§c" + k.getKey() + "§7: " + value.get(DESCRIPTION)); } } - else if (value.containsKey("permissions") && value.get("permissions") != null && !(value.get("permissions").equals(""))) + else if (value.containsKey(PERMISSION) && value.get(PERMISSION) instanceof List && !((List<Object>)value.get(PERMISSION)).isEmpty()) { - if (user.isAuthorized(value.get("permissions"))) + boolean enabled = false; + for (Object o : (List<Object>)value.get(PERMISSION)) + { + if (o instanceof String && user.isAuthorized((String)o)) + { + enabled = true; + break; + } + } + if (enabled) + { + retval.add("§c" + k.getKey() + "§7: " + value.get(DESCRIPTION)); + } + } + else if (value.containsKey(PERMISSIONS) && value.get(PERMISSIONS) instanceof String && !(value.get(PERMISSIONS).equals(""))) + { + if (user.isAuthorized((String)value.get(PERMISSIONS))) + { + retval.add("§c" + k.getKey() + "§7: " + value.get(DESCRIPTION)); + } + } + else if (value.containsKey(PERMISSIONS) && value.get(PERMISSIONS) instanceof List && !((List<Object>)value.get(PERMISSIONS)).isEmpty()) + { + boolean enabled = false; + for (Object o : (List<Object>)value.get(PERMISSIONS)) + { + if (o instanceof String && user.isAuthorized((String)o)) + { + enabled = true; + break; + } + } + if (enabled) { - retval.add("§c" + k.getKey() + "§7: " + value.get("description")); + retval.add("§c" + k.getKey() + "§7: " + value.get(DESCRIPTION)); } } else if (user.isAuthorized("essentials.help." + pluginName)) { - retval.add("§c" + k.getKey() + "§7: " + value.get("description")); + retval.add("§c" + k.getKey() + "§7: " + value.get(DESCRIPTION)); } else { if (!ess.getSettings().hidePermissionlessHelp()) { - retval.add("§c" + k.getKey() + "§7: " + value.get("description")); + retval.add("§c" + k.getKey() + "§7: " + value.get(DESCRIPTION)); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java b/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java index 261cad062..158b0d40b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java @@ -22,7 +22,6 @@ public class Commandhelpop extends EssentialsCommand throw new NotEnoughArgumentsException(); } - charge(user); final String message = Util.format("helpOp", user.getDisplayName(), getFinalArg(args, 0)); logger.log(Level.INFO, message); for (Player p : server.getOnlinePlayers()) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhome.java b/Essentials/src/com/earth2me/essentials/commands/Commandhome.java index f556ea360..2ee2661e6 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhome.java @@ -53,10 +53,15 @@ public class Commandhome extends EssentialsCommand { user.getTeleport().home(u, homes.get(0), charge); } + else if (ess.getSettings().spawnIfNoHome()) + { + user.getTeleport().respawn(ess.getSpawn(), charge); + } else { user.sendMessage(Util.format("homes", Util.joinList(homes))); } } + throw new NoChargeException(); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandinfo.java b/Essentials/src/com/earth2me/essentials/commands/Commandinfo.java index 4db469b58..97dd71d35 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandinfo.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandinfo.java @@ -68,9 +68,8 @@ public class Commandinfo extends EssentialsCommand } else { - sender.sendMessage(Util.i18n("infoFileDoesNotExist")); file.createNewFile(); - return; + throw new Exception(Util.i18n("infoFileDoesNotExist")); } if (bookmarks.isEmpty()) @@ -88,7 +87,6 @@ public class Commandinfo extends EssentialsCommand int start = (page - 1) * 9; int pages = lines.size() / 9 + (lines.size() % 9 > 0 ? 1 : 0); - charge(sender); sender.sendMessage(Util.format("infoPages", page, pages )); for (int i = start; i < lines.size() && i < start + 9; i++) { @@ -140,7 +138,6 @@ public class Commandinfo extends EssentialsCommand } int pages = end / 9 + (end % 9 > 0 ? 1 : 0); - charge(sender); sender.sendMessage(Util.format("infoPages", page, pages )); for (int i = start; i < end && i < start + 9; i++) { @@ -182,7 +179,6 @@ public class Commandinfo extends EssentialsCommand int page = chapterpage + 1; int pages = (chapterend - chapterstart) / 9 + ((chapterend - chapterstart) % 9 > 0 ? 1 : 0); - charge(sender); sender.sendMessage(Util.format("infoChapterPages", pageStr, page , pages)); for (int i = start; i < chapterend && i < start + 9; i++) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandinvsee.java b/Essentials/src/com/earth2me/essentials/commands/Commandinvsee.java index e5877fe40..8b6dc8182 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandinvsee.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandinvsee.java @@ -31,11 +31,9 @@ public class Commandinvsee extends EssentialsCommand { invUser.getInventory().setContents(user.getSavedInventory()); user.setSavedInventory(null); - user.sendMessage(Util.i18n("invRestored")); - return; + throw new Exception(Util.i18n("invRestored")); } - charge(user); if (user.getSavedInventory() == null) { user.setSavedInventory(user.getInventory().getContents()); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanditem.java b/Essentials/src/com/earth2me/essentials/commands/Commanditem.java index 79e8344f1..352ce18eb 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanditem.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanditem.java @@ -31,8 +31,7 @@ public class Commanditem extends EssentialsCommand : (!user.isAuthorized("essentials.itemspawn.exempt") && !user.canSpawnItem(stack.getTypeId()))) { - user.sendMessage(Util.format("cantSpawnItem", itemname)); - return; + throw new Exception(Util.format("cantSpawnItem", itemname)); } if (args.length > 1 && Integer.parseInt(args[1]) > 0) @@ -42,12 +41,10 @@ public class Commanditem extends EssentialsCommand if (stack.getType() == Material.AIR) { - user.sendMessage(Util.format("cantSpawnItem", "Air")); - return; + throw new Exception(Util.format("cantSpawnItem", "Air")); } String itemName = stack.getType().toString().toLowerCase().replace('_', ' '); - charge(user); user.sendMessage(Util.format("itemSpawn", stack.getAmount(), itemName)); user.getInventory().addItem(stack); user.updateInventory(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkick.java b/Essentials/src/com/earth2me/essentials/commands/Commandkick.java index e9b3720fe..fd0d4a8e0 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkick.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkick.java @@ -26,10 +26,8 @@ public class Commandkick extends EssentialsCommand User player = getPlayer(server, args, 0); if (player.isAuthorized("essentials.kick.exempt")) { - sender.sendMessage(Util.i18n("kickExempt")); - return; + throw new Exception(Util.i18n("kickExempt")); } - charge(sender); final String kickReason = args.length > 1 ? getFinalArg(args, 1) : Util.i18n("kickDefault"); player.kickPlayer(kickReason); String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java b/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java index c52dc8d14..8d36f50d5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java @@ -16,8 +16,6 @@ public class Commandkickall extends EssentialsCommand @Override public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception { - charge(sender); - for (Player p : server.getOnlinePlayers()) { if (sender instanceof Player && p.getName().equalsIgnoreCase(((Player)sender).getName())) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkill.java b/Essentials/src/com/earth2me/essentials/commands/Commandkill.java index c849463b7..03afeadc4 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkill.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkill.java @@ -21,7 +21,6 @@ public class Commandkill extends EssentialsCommand throw new NotEnoughArgumentsException(); } - charge(sender); for (Player p : server.matchPlayer(args[0])) { p.setHealth(0); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkit.java b/Essentials/src/com/earth2me/essentials/commands/Commandkit.java index 7f9a91590..75cc83887 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkit.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkit.java @@ -141,7 +141,6 @@ public class Commandkit extends EssentialsCommand } try { - charge(user); charge.charge(user); } catch (Exception ex) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java b/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java index c9135d61e..dc4387833 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java @@ -26,20 +26,14 @@ public class Commandlightning extends EssentialsCommand if (args.length < 1 & user != null) { user.getWorld().strikeLightning(user.getTargetBlock(null, 600).getLocation()); - charge(user); return; } if (server.matchPlayer(args[0]).isEmpty()) { - sender.sendMessage(Util.i18n("playerNotFound")); - return; + throw new Exception(Util.i18n("playerNotFound")); } - if (user != null) - { - charge(user); - } for (Player p : server.matchPlayer(args[0])) { sender.sendMessage(Util.format("lightningUse", p.getDisplayName())); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java index ef7d6e9f8..98066d7e7 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java @@ -44,7 +44,6 @@ public class Commandlist extends EssentialsCommand playerHidden++; } } - charge(sender); //TODO: move these to messages file StringBuilder online = new StringBuilder(); online.append(ChatColor.BLUE).append("There are ").append(ChatColor.RED).append(server.getOnlinePlayers().length - playerHidden); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java index b54b88a12..a98fabbd2 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java @@ -23,22 +23,19 @@ public class Commandmail extends EssentialsCommand List<String> mail = user.getMails(); if (mail.isEmpty()) { - user.sendMessage(Util.i18n("noMail")); - return; + throw new Exception(Util.i18n("noMail")); } for (String s : mail) { user.sendMessage(s); } - user.sendMessage(Util.i18n("mailClear")); - return; + throw new Exception(Util.i18n("mailClear")); } if (args.length >= 3 && "send".equalsIgnoreCase(args[0])) { if (!user.isAuthorized("essentials.mail.send")) { - user.sendMessage(Util.i18n("noMailSendPerm")); - return; + throw new Exception(Util.i18n("noMailSendPerm")); } Player player = server.getPlayer(args[1]); @@ -53,10 +50,8 @@ public class Commandmail extends EssentialsCommand } if (u == null) { - user.sendMessage(Util.format("playerNeverOnServer", args[1])); - return; + throw new Exception(Util.format("playerNeverOnServer", args[1])); } - charge(user); if (!u.isIgnoredPlayer(user.getName())) { u.addMail(ChatColor.stripColor(user.getDisplayName()) + ": " + getFinalArg(args, 2)); @@ -67,8 +62,7 @@ public class Commandmail extends EssentialsCommand if (args.length >= 1 && "clear".equalsIgnoreCase(args[0])) { user.setMails(null); - user.sendMessage(Util.i18n("mailCleared")); - return; + throw new Exception(Util.i18n("mailCleared")); } throw new NotEnoughArgumentsException(); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandme.java b/Essentials/src/com/earth2me/essentials/commands/Commandme.java index 098558f11..02bcecdc2 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandme.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandme.java @@ -17,21 +17,22 @@ public class Commandme extends EssentialsCommand { if (user.isMuted()) { - user.sendMessage(Util.i18n("voiceSilenced")); - return; + throw new Exception(Util.i18n("voiceSilenced")); } if (args.length < 1) { throw new NotEnoughArgumentsException(); } - StringBuilder message = new StringBuilder(); + final StringBuilder message = new StringBuilder(); + message.append("* "); + message.append(user.getDisplayName()); + message.append(' '); for (int i = 0; i < args.length; i++) { message.append(args[i]); message.append(' '); } - charge(user); - ess.broadcastMessage(user.getName(), "* " + user.getDisplayName() + " " + message); + ess.broadcastMessage(user, message.toString()); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmotd.java b/Essentials/src/com/earth2me/essentials/commands/Commandmotd.java index 4712c331b..c695338f6 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmotd.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmotd.java @@ -15,7 +15,6 @@ public class Commandmotd extends EssentialsCommand @Override public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception { - charge(sender); for (String m : ess.getMotd(sender, Util.i18n("noMotd"))) { sender.sendMessage(m); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java b/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java index 42f17bed2..f14935648 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java @@ -30,8 +30,7 @@ public class Commandmsg extends EssentialsCommand User user = ess.getUser(sender); if (user.isMuted()) { - user.sendMessage(Util.i18n("voiceSilenced")); - return; + throw new Exception(Util.i18n("voiceSilenced")); } } @@ -55,8 +54,7 @@ public class Commandmsg extends EssentialsCommand if (matches.isEmpty()) { - sender.sendMessage(Util.i18n("playerNotFound")); - return; + throw new Exception(Util.i18n("playerNotFound")); } int i = 0; @@ -70,11 +68,9 @@ public class Commandmsg extends EssentialsCommand } if (i == matches.size()) { - sender.sendMessage(Util.i18n("playerNotFound")); - return; + throw new Exception(Util.i18n("playerNotFound")); } - charge(sender); for (Player p : matches) { sender.sendMessage(Util.format("msgFormat", translatedMe, p.getDisplayName(), message)); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmute.java b/Essentials/src/com/earth2me/essentials/commands/Commandmute.java index e56ddc42c..1777c5b48 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmute.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmute.java @@ -24,8 +24,7 @@ public class Commandmute extends EssentialsCommand User p = getPlayer(server, args, 0, true); if (!p.isMuted() && p.isAuthorized("essentials.mute.exempt")) { - sender.sendMessage(Util.i18n("muteExempt")); - return; + throw new Exception(Util.i18n("muteExempt")); } long muteTimestamp = 0; if (args.length > 1) @@ -34,7 +33,6 @@ public class Commandmute extends EssentialsCommand muteTimestamp = Util.parseDateDiff(time, true); } p.setMuteTimeout(muteTimestamp); - charge(sender); boolean muted = p.toggleMuted(); sender.sendMessage( muted diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java index 99c779ba4..253ec7646 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java @@ -23,16 +23,14 @@ public class Commandnick extends EssentialsCommand } if (!ess.getSettings().changeDisplayName()) { - user.sendMessage(Util.i18n("nickDisplayName")); - return; + throw new Exception(Util.i18n("nickDisplayName")); } if (args.length > 1) { if (!user.isAuthorized("essentials.nick.others")) { - user.sendMessage(Util.i18n("nickOthersPermission")); - return; + throw new Exception(Util.i18n("nickOthersPermission")); } setOthersNickname(server, user, args); @@ -51,8 +49,7 @@ public class Commandnick extends EssentialsCommand if (nick.matches("[^a-zA-Z_0-9]")) { - user.sendMessage(Util.i18n("nickNamesAlpha")); - return; + throw new Exception(Util.i18n("nickNamesAlpha")); } for (Player p : server.getOnlinePlayers()) @@ -66,12 +63,10 @@ public class Commandnick extends EssentialsCommand String nk = nick.toLowerCase(); if (nk.equals(dn) || nk.equals(n)) { - user.sendMessage(Util.i18n("nickInUse")); - return; + throw new Exception(Util.i18n("nickInUse")); } } - charge(user); user.setDisplayName(ess.getSettings().getNicknamePrefix() + nick); user.setNickname(nick); user.sendMessage(Util.format("nickSet", user.getDisplayName() + "§7.")); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandplugin.java b/Essentials/src/com/earth2me/essentials/commands/Commandplugin.java deleted file mode 100644 index 9e7939d57..000000000 --- a/Essentials/src/com/earth2me/essentials/commands/Commandplugin.java +++ /dev/null @@ -1,173 +0,0 @@ -package com.earth2me.essentials.commands; - -import java.io.File; -import org.bukkit.Server; -import org.bukkit.command.CommandSender; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginManager; - - -public class Commandplugin extends EssentialsCommand -{ - private Server server; - - public Commandplugin() - { - super("plugin"); - } - - @Override - public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception - { - this.server = server; - - PluginCommands sub = null; - try - { - sub = PluginCommands.valueOf(args[0].toUpperCase()); - } - catch (Exception ex) - { - sender.sendMessage("§cUsage: /plugin [load|reload|enable|disable|list] [PluginName]"); - return; - } - - switch (sub) - { - case LOAD: // All disable functions are broken until - // http://leaky.bukkit.org/issues/641 is fixed. - sender.sendMessage("This function is broken. Performing /reload now."); - server.reload(); - /*if (args.length < 2) return; - User.charge(sender, this); - loadPlugin(args[1], sender);*/ - return; - - case RELOAD: - sender.sendMessage("This function is broken. Performing /reload now."); - server.reload(); - /*if (args.length < 2) return; - User.charge(sender, this); - reloadPlugin(args[1], sender);*/ - return; - - case ENABLE: - sender.sendMessage("This function is broken. Performing /reload now."); - server.reload(); - /*if (args.length < 2) return; - User.charge(sender, this); - enablePlugin(args[1], sender);*/ - return; - - case DISABLE: - sender.sendMessage("This function is broken."); - /*if (args.length < 2) return; - User.charge(sender, this); - disablePlugin(args[1], sender);*/ - return; - - case LIST: - charge(sender); - listPlugins(sender); - return; - } - } - - private void listPlugins(CommandSender player) - { - StringBuilder plugins = new StringBuilder(); - for (Plugin p : server.getPluginManager().getPlugins()) - { - plugins.append(p.isEnabled() ? " §a" : " §c"); - plugins.append(p.getDescription().getName()); - } - - plugins.insert(0, "§7Plugins:§f"); - player.sendMessage(plugins.toString()); - } - - private boolean reloadPlugin(String name, CommandSender player) - { - return disablePlugin(name, player) && enablePlugin(name, player); - } - - private boolean loadPlugin(String name, CommandSender sender) - { - try - { - PluginManager pm = server.getPluginManager(); - pm.loadPlugin(new File("plugins", name + ".jar")); - sender.sendMessage("§7Plugin loaded."); - return enablePlugin(name, sender); - } - catch (Throwable ex) - { - sender.sendMessage("§cCould not load plugin. Is the file named properly?"); - return false; - } - } - - private boolean enablePlugin(String name, CommandSender sender) - { - try - { - final PluginManager pm = server.getPluginManager(); - final Plugin plugin = pm.getPlugin(name); - if (!plugin.isEnabled()) - { - new Thread(new Runnable() - { - public void run() - { - synchronized (pm) - { - pm.enablePlugin(plugin); - } - } - }).start(); - } - sender.sendMessage("§7Plugin enabled."); - return true; - } - catch (Throwable ex) - { - listPlugins(sender); - return false; - } - } - - private boolean disablePlugin(String name, CommandSender sender) - { - try - { - final PluginManager pm = server.getPluginManager(); - final Plugin plugin = pm.getPlugin(name); - if (plugin.isEnabled()) - { - new Thread(new Runnable() - { - public void run() - { - synchronized (pm) - { - pm.disablePlugin(plugin); - } - } - }).start(); - } - sender.sendMessage("§7Plugin disabled."); - return true; - } - catch (Throwable ex) - { - listPlugins(sender); - return false; - } - } - - - private enum PluginCommands - { - LOAD, RELOAD, LIST, ENABLE, DISABLE - } -} diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java b/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java index 4c3d941ae..b4977167f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java @@ -17,25 +17,24 @@ public class Commandpowertool extends EssentialsCommand } @Override - protected void run(Server server, User user, String commandLabel, String[] args) throws Exception + protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { - ItemStack is = user.getItemInHand(); - List<String> powertools = user.getPowertool(is); - if (is == null || is.getType() == Material.AIR) + final ItemStack itemStack = user.getItemInHand(); + if (itemStack == null || itemStack.getType() == Material.AIR) { - user.sendMessage(Util.i18n("powerToolAir")); - return; + throw new Exception(Util.i18n("powerToolAir")); } - String itemName = is.getType().toString().toLowerCase().replaceAll("_", " "); + final String itemName = itemStack.getType().toString().toLowerCase().replaceAll("_", " "); String command = getFinalArg(args, 0); + List<String> powertools = user.getPowertool(itemStack); if (command != null && !command.isEmpty()) { if (command.equalsIgnoreCase("l:")) { if (powertools == null || powertools.isEmpty()) { - user.sendMessage(Util.format("powerToolListEmpty", itemName)); + throw new Exception(Util.format("powerToolListEmpty", itemName)); } else { @@ -50,8 +49,7 @@ public class Commandpowertool extends EssentialsCommand command = command.substring(2); if (!powertools.contains(command)) { - user.sendMessage(Util.format("powerToolNoSuchCommandAssigned", command, itemName)); - return; + throw new Exception(Util.format("powerToolNoSuchCommandAssigned", command, itemName)); } powertools.remove(command); @@ -68,10 +66,9 @@ public class Commandpowertool extends EssentialsCommand if (command.startsWith("a:")) { command = command.substring(2); - if(powertools.contains(command)) + if (powertools.contains(command)) { - user.sendMessage(Util.format("powerToolAlreadySet", command, itemName)); - return; + throw new Exception(Util.format("powerToolAlreadySet", command, itemName)); } } else if (powertools != null && !powertools.isEmpty()) @@ -90,11 +87,13 @@ public class Commandpowertool extends EssentialsCommand } else { - powertools.clear(); + if (powertools != null) + { + powertools.clear(); + } user.sendMessage(Util.format("powerToolRemoveAll", itemName)); } - charge(user); - user.setPowertool(is, powertools); + user.setPowertool(itemStack, powertools); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandr.java b/Essentials/src/com/earth2me/essentials/commands/Commandr.java index d89947500..daf83034a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandr.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandr.java @@ -32,11 +32,9 @@ public class Commandr extends EssentialsCommand if (target == null) { - sender.sendMessage(Util.i18n("foreverAlone")); - return; + throw new Exception(Util.i18n("foreverAlone")); } - charge(sender); sender.sendMessage(Util.format("msgFormat", Util.i18n("me"), targetName, message)); if (target instanceof Player) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java b/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java index e16d59198..5e12c535d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java @@ -22,7 +22,6 @@ public class Commandrealname extends EssentialsCommand throw new NotEnoughArgumentsException(); } final String whois = args[0].toLowerCase(); - charge(user); for (Player p : server.getOnlinePlayers()) { final User u = ess.getUser(p); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandreloadall.java b/Essentials/src/com/earth2me/essentials/commands/Commandreloadall.java index eeee08e11..bd4f59dcc 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandreloadall.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandreloadall.java @@ -15,7 +15,6 @@ public class Commandreloadall extends EssentialsCommand @Override public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception { - charge(sender); server.reload(); sender.sendMessage(Util.i18n("reloadAllPlugins")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java b/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java index d41f5580f..029901867 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandrepair.java @@ -33,28 +33,12 @@ public class Commandrepair extends EssentialsCommand final String itemName = item.getType().toString().toLowerCase(); final Trade charge = new Trade("repair-" + itemName.replace('_', '-'), ess); - try - { - charge.isAffordableFor(user); - } - catch (Exception ex) - { - user.sendMessage(ex.getMessage()); - return; - } + charge.isAffordableFor(user); + + repairItem(item); - try - { - repairItem(item); - } - catch (Exception e) - { - user.sendMessage(e.getMessage()); - return; - } charge.charge(user); - charge(user); user.sendMessage(Util.format("repair", itemName.replace('_', ' '))); } else if (args[0].equalsIgnoreCase("all")) @@ -66,11 +50,10 @@ public class Commandrepair extends EssentialsCommand if (repaired.isEmpty()) { - user.sendMessage(Util.format("repairNone")); + throw new Exception(Util.format("repairNone")); } else { - charge(user); user.sendMessage(Util.format("repair", Util.joinList(repaired))); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrules.java b/Essentials/src/com/earth2me/essentials/commands/Commandrules.java index 1b00bea47..39f7de68e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandrules.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandrules.java @@ -15,7 +15,6 @@ public class Commandrules extends EssentialsCommand @Override public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception { - charge(sender); for (String m : ess.getLines(sender, "rules", Util.i18n("noRules"))) { sender.sendMessage(m); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java index f471364d5..658782b9a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java @@ -145,11 +145,9 @@ public class Commandsell extends EssentialsCommand { user.sendMessage(Util.i18n("itemNotEnough1")); user.sendMessage(Util.i18n("itemNotEnough2")); - user.sendMessage(Util.i18n("itemNotEnough3")); - return; + throw new Exception(Util.i18n("itemNotEnough3")); } - charge(user); final ItemStack ris = new ItemStack(is.getType(), amount, is.getDurability()); InventoryWorkaround.removeItem(user.getInventory(), true, ris); user.updateInventory(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java b/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java index 7f496371f..82d66a71c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java @@ -39,6 +39,9 @@ public class Commandsethome extends EssentialsCommand } } + else { + throw new Exception(Util.format("maxHomes", 1)); + } } else { @@ -66,7 +69,6 @@ public class Commandsethome extends EssentialsCommand { user.setHome(); } - charge(user); user.sendMessage(Util.i18n("homeSet")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java b/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java index 76fe766c3..d9b0eac4d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java @@ -15,12 +15,10 @@ public class Commandsetjail extends EssentialsCommand @Override public void run(Server server, User user, String commandLabel, String[] args) throws Exception { - if (args.length < 1) { throw new NotEnoughArgumentsException(); } - charge(user); ess.getJail().setJail(user.getLocation(), args[0]); user.sendMessage(Util.format("jailSet",args[0])); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java b/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java index 4e799d6c0..ccdacab57 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java @@ -21,7 +21,6 @@ public class Commandsetwarp extends EssentialsCommand throw new NotEnoughArgumentsException(); } - charge(user); Location loc = user.getLocation(); ess.getWarps().setWarp(args[0], loc); user.sendMessage(Util.format("warpSet", args[0])); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java b/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java index e6b741c43..086b1549d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java @@ -22,7 +22,6 @@ public class Commandsetworth extends EssentialsCommand } ItemStack stack = ess.getItemDb().get(args[0]); - charge(user); ess.getWorth().setPrice(stack, Double.parseDouble(args[1])); user.sendMessage(Util.i18n("worthSet")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsocialspy.java b/Essentials/src/com/earth2me/essentials/commands/Commandsocialspy.java index 33efffeef..8e95e8237 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsocialspy.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsocialspy.java @@ -15,9 +15,6 @@ public class Commandsocialspy extends EssentialsCommand @Override public void run(Server server, User user, String commandLabel, String[] args) throws Exception { - - charge(user); user.sendMessage("§7SocialSpy " + (user.toggleSocialSpy() ? Util.i18n("enabled") : Util.i18n("disabled"))); - } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java b/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java index 15f5910af..d3b14970a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java @@ -6,8 +6,7 @@ import com.earth2me.essentials.Util; import org.bukkit.Material; import org.bukkit.Server; import org.bukkit.block.Block; -import org.bukkit.craftbukkit.block.CraftCreatureSpawner; -import org.bukkit.entity.CreatureType; +import org.bukkit.block.CreatureSpawner; public class Commandspawner extends EssentialsCommand @@ -32,7 +31,6 @@ public class Commandspawner extends EssentialsCommand throw new Exception(Util.i18n("mobSpawnTarget")); } - charge(user); try { String name = args[0]; @@ -45,7 +43,7 @@ public class Commandspawner extends EssentialsCommand user.sendMessage(Util.i18n("invalidMob")); return; } - new CraftCreatureSpawner(target).setCreatureType(mob.getType()); + ((CreatureSpawner)target.getState()).setCreatureType(mob.getType()); user.sendMessage(Util.format("setSpawner", mob.name)); } catch (Throwable ex) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java index 17081e349..87a22c59f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java @@ -8,16 +8,13 @@ import com.earth2me.essentials.Mob.MobException; import com.earth2me.essentials.TargetBlock; import com.earth2me.essentials.Util; import java.util.Random; -import net.minecraft.server.EntityWolf; -import net.minecraft.server.PathEntity; import org.bukkit.DyeColor; -import org.bukkit.Material; import org.bukkit.block.Block; -import org.bukkit.craftbukkit.entity.CraftCreeper; -import org.bukkit.craftbukkit.entity.CraftSheep; -import org.bukkit.craftbukkit.entity.CraftSlime; -import org.bukkit.craftbukkit.entity.CraftWolf; +import org.bukkit.entity.Creeper; import org.bukkit.entity.Entity; +import org.bukkit.entity.Sheep; +import org.bukkit.entity.Slime; +import org.bukkit.entity.Wolf; public class Commandspawnmob extends EssentialsCommand @@ -62,8 +59,7 @@ public class Commandspawnmob extends EssentialsCommand if (ess.getSettings().getProtectPreventSpawn(mobType.toLowerCase()) || (mountType != null && ess.getSettings().getProtectPreventSpawn(mountType.toLowerCase()))) { - user.sendMessage(Util.i18n("unableToSpawnMob")); - return; + throw new Exception(Util.i18n("unableToSpawnMob")); } Entity spawnedMob = null; @@ -74,10 +70,8 @@ public class Commandspawnmob extends EssentialsCommand mob = Mob.fromName(mobType); if (mob == null) { - user.sendMessage(Util.i18n("invalidMob")); - return; + throw new Exception(Util.i18n("invalidMob")); } - charge(user); int[] ignore = { 8, 9 @@ -190,7 +184,7 @@ public class Commandspawnmob extends EssentialsCommand { try { - ((CraftSlime)spawned).setSize(Integer.parseInt(data)); + ((Slime)spawned).setSize(Integer.parseInt(data)); } catch (Exception e) { @@ -204,11 +198,11 @@ public class Commandspawnmob extends EssentialsCommand if (data.equalsIgnoreCase("random")) { Random rand = new Random(); - ((CraftSheep)spawned).setColor(DyeColor.values()[rand.nextInt(DyeColor.values().length)]); + ((Sheep)spawned).setColor(DyeColor.values()[rand.nextInt(DyeColor.values().length)]); } else { - ((CraftSheep)spawned).setColor(DyeColor.valueOf(data.toUpperCase())); + ((Sheep)spawned).setColor(DyeColor.valueOf(data.toUpperCase())); } } catch (Exception e) @@ -218,21 +212,18 @@ public class Commandspawnmob extends EssentialsCommand } if ("Wolf".equalsIgnoreCase(type) && data.equalsIgnoreCase("tamed")) { - EntityWolf wolf = ((CraftWolf)spawned).getHandle(); + Wolf wolf = ((Wolf)spawned); wolf.setTamed(true); - wolf.setPathEntity((PathEntity)null); + wolf.setOwner(user); wolf.setSitting(true); - wolf.health = 20; - wolf.setOwnerName(user.getName()); - wolf.world.a(wolf, (byte)7); } if ("Wolf".equalsIgnoreCase(type) && data.equalsIgnoreCase("angry")) { - ((CraftWolf)spawned).setAngry(true); + ((Wolf)spawned).setAngry(true); } if ("Creeper".equalsIgnoreCase(type) && data.equalsIgnoreCase("powered")) { - ((CraftCreeper)spawned).setPowered(true); + ((Creeper)spawned).setPowered(true); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java b/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java index 57e5e3fd5..ca9fee47b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java @@ -15,10 +15,9 @@ public class Commandsuicide extends EssentialsCommand @Override public void run(Server server, User user, String commandLabel, String[] args) throws Exception { - charge(user); user.setHealth(0); user.sendMessage(Util.i18n("suicideMessage")); - ess.broadcastMessage(user.getName(), + ess.broadcastMessage(user, Util.format("suicideSuccess",user.getDisplayName())); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandthunder.java b/Essentials/src/com/earth2me/essentials/commands/Commandthunder.java index b1ffd3f7f..34f5c3fed 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandthunder.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandthunder.java @@ -16,13 +16,11 @@ public class Commandthunder extends EssentialsCommand @Override public void run(Server server, User user, String commandLabel, String[] args) throws Exception { - if (args.length < 1) { throw new NotEnoughArgumentsException(); } - charge(user); World world = user.getWorld(); boolean setThunder = args[0].equalsIgnoreCase("true"); if (args.length > 1) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java b/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java index c4857c57b..625a375d8 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java @@ -44,7 +44,6 @@ public class Commandtogglejail extends EssentialsCommand return; } } - charge(sender); if (!(p.getBase() instanceof OfflinePlayer)) { ess.getJail().sendToJail(p, args[1]); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtop.java b/Essentials/src/com/earth2me/essentials/commands/Commandtop.java index 8c0c687d0..ee5bfbe45 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtop.java @@ -20,7 +20,6 @@ public class Commandtop extends EssentialsCommand int topX = user.getLocation().getBlockX(); int topZ = user.getLocation().getBlockZ(); int topY = user.getWorld().getHighestBlockYAt(topX, topZ); - charge(user); user.getTeleport().teleport(new Location(user.getWorld(), user.getLocation().getX(), topY + 1, user.getLocation().getZ()), new Trade(this.getName(), ess)); user.sendMessage(Util.i18n("teleportTop")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtp.java b/Essentials/src/com/earth2me/essentials/commands/Commandtp.java index c147c5d25..480fb6153 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtp.java @@ -33,7 +33,7 @@ public class Commandtp extends EssentialsCommand Trade charge = new Trade(this.getName(), ess); charge.isAffordableFor(user); user.getTeleport().teleport(p, charge); - break; + throw new NoChargeException(); case 2: if (!user.isAuthorized("essentials.tpohere")) @@ -41,13 +41,12 @@ public class Commandtp extends EssentialsCommand throw new Exception("You need access to /tpohere to teleport other players."); } user.sendMessage(Util.i18n("teleporting")); - charge(user); User target = getPlayer(server, args, 0); User toPlayer = getPlayer(server, args, 1); target.getTeleport().now(toPlayer, false); target.sendMessage(Util.format("teleportAtoB", user.getDisplayName(), toPlayer.getDisplayName())); break; - } + } } @Override @@ -63,5 +62,6 @@ public class Commandtp extends EssentialsCommand User toPlayer = getPlayer(server, args, 1); target.getTeleport().now(toPlayer, false); target.sendMessage(Util.format("teleportAtoB", Console.NAME, toPlayer.getDisplayName())); + return; } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java index f3b7ae505..32cbe3bd9 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java @@ -25,7 +25,6 @@ public class Commandtpa extends EssentialsCommand { throw new Exception(Util.format("teleportDisabled", p.getDisplayName())); } - charge(user); if (!p.isIgnoredPlayer(user.getName())) { p.requestTeleport(user, false); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpaall.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpaall.java index 25c5d2892..97897852f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpaall.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpaall.java @@ -21,7 +21,6 @@ public class Commandtpaall extends EssentialsCommand { if (sender instanceof Player) { - charge(sender); teleportAAllPlayers(server, sender, ess.getUser(sender)); return; } @@ -29,7 +28,6 @@ public class Commandtpaall extends EssentialsCommand } User p = getPlayer(server, args, 0); - charge(sender); teleportAAllPlayers(server, sender, p); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpahere.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpahere.java index 2003bbf73..935721345 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpahere.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpahere.java @@ -25,7 +25,6 @@ public class Commandtpahere extends EssentialsCommand { throw new Exception(Util.format("teleportDisabled", p.getDisplayName())); } - charge(user); p.requestTeleport(user, true); p.sendMessage(Util.format("teleportHereRequest", user.getDisplayName())); p.sendMessage(Util.i18n("typeTpaccept")); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java index cc58944d7..1cb6321ea 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java @@ -21,7 +21,6 @@ public class Commandtpall extends EssentialsCommand { if (sender instanceof Player) { - charge(sender); teleportAllPlayers(server, sender, ess.getUser(sender)); return; } @@ -29,7 +28,6 @@ public class Commandtpall extends EssentialsCommand } User p = getPlayer(server, args, 0); - charge(sender); teleportAllPlayers(server, sender, p); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpdeny.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpdeny.java index e31d7ae3c..5d7764ae6 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpdeny.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpdeny.java @@ -21,7 +21,6 @@ public class Commandtpdeny extends EssentialsCommand throw new Exception(Util.i18n("noPendingRequest")); } - charge(user); user.sendMessage(Util.i18n("requestDenied")); p.sendMessage(Util.format("requestDeniedFrom", user.getDisplayName())); user.requestTeleport(null, false); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java b/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java index 036c4be27..bba8d8743 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java @@ -24,5 +24,6 @@ public class Commandtphere extends EssentialsCommand p.getTeleport().teleport(user, new Trade(this.getName(), ess)); user.sendMessage(Util.i18n("teleporting")); p.sendMessage(Util.i18n("teleporting")); + throw new NoChargeException(); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpo.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpo.java index 18d818ea1..5a4e082e0 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpo.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpo.java @@ -32,7 +32,6 @@ public class Commandtpo extends EssentialsCommand // Verify permission if (!p.isHidden() || user.isAuthorized("essentials.teleport.hidden")) { - charge(user); user.getTeleport().now(p, false); user.sendMessage(Util.i18n("teleporting")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpohere.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpohere.java index 186476a50..7af39854f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpohere.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpohere.java @@ -33,7 +33,6 @@ public class Commandtpohere extends EssentialsCommand // Verify permission if (!p.isHidden() || user.isAuthorized("essentials.teleport.hidden")) { - charge(user); p.getTeleport().now(user, false); user.sendMessage(Util.i18n("teleporting")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java b/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java index 805aefaca..0786f9cb9 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java @@ -30,5 +30,6 @@ public class Commandtppos extends EssentialsCommand charge.isAffordableFor(user); user.sendMessage(Util.i18n("teleporting")); user.getTeleport().teleport(l, charge); + throw new NoChargeException(); } }
\ No newline at end of file diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtptoggle.java b/Essentials/src/com/earth2me/essentials/commands/Commandtptoggle.java index 38236d475..f880c5d34 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtptoggle.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtptoggle.java @@ -15,7 +15,6 @@ public class Commandtptoggle extends EssentialsCommand @Override public void run(Server server, User user, String commandLabel, String[] args) throws Exception { - charge(user); user.sendMessage(user.toggleTeleportEnabled() ? Util.i18n("teleportationEnabled") : Util.i18n("teleportationDisabled")); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtree.java b/Essentials/src/com/earth2me/essentials/commands/Commandtree.java index 81be2a329..8013453ab 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtree.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtree.java @@ -51,7 +51,6 @@ public class Commandtree extends EssentialsCommand final boolean success = user.getWorld().generateTree(safeLocation, (TreeType)tree); if (success) { - charge(user); user.sendMessage(Util.i18n("treeSpawned")); } else diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java b/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java index 122891e02..cebbcaf8c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java @@ -93,8 +93,7 @@ public class Commandunlimited extends EssentialsCommand && !((stack.getType() == Material.WATER_BUCKET || stack.getType() == Material.LAVA_BUCKET) && user.isAuthorized("essentials.unlimited.item-bucket")))) { - user.sendMessage(Util.format("unlimitedItemPermission", itemname)); - return false; + throw new Exception(Util.format("unlimitedItemPermission", itemname)); } String message = "disableUnlimited"; @@ -103,7 +102,6 @@ public class Commandunlimited extends EssentialsCommand { message = "enableUnlimited"; enableUnlimited = true; - charge(user); if (!InventoryWorkaround.containsItem(target.getInventory(), true, stack)) { target.getInventory().addItem(stack); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java b/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java index b93355f5a..36d1d0df0 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java @@ -26,8 +26,7 @@ public class Commandwarp extends EssentialsCommand { if (!user.isAuthorized("essentials.warp.list")) { - user.sendMessage(Util.i18n("warpListPermission")); - return; + throw new Exception(Util.i18n("warpListPermission")); } Warps warps = ess.getWarps(); @@ -56,7 +55,7 @@ public class Commandwarp extends EssentialsCommand } final int warpPage = (page - 1) * WARPS_PER_PAGE; user.sendMessage(Util.joinList(warpNameList.subList(warpPage, warpPage+Math.min(warpNameList.size() - warpPage, WARPS_PER_PAGE)))); - return; + throw new NoChargeException(); } if (args.length > 0) { @@ -66,13 +65,13 @@ public class Commandwarp extends EssentialsCommand otherUser = ess.getUser(server.getPlayer(args[1])); if (otherUser == null) { - user.sendMessage(Util.i18n("playerNotFound")); - return; + throw new Exception(Util.i18n("playerNotFound")); } warpUser(otherUser, args[0]); - return; + throw new NoChargeException(); } warpUser(user, args[0]); + throw new NoChargeException(); } } @@ -87,8 +86,7 @@ public class Commandwarp extends EssentialsCommand user.getTeleport().warp(name, charge); return; } - user.sendMessage(Util.i18n("warpUsePermission")); - return; + throw new Exception(Util.i18n("warpUsePermission")); } user.getTeleport().warp(name, charge); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandweather.java b/Essentials/src/com/earth2me/essentials/commands/Commandweather.java index eec1d9575..45c62d787 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandweather.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandweather.java @@ -23,7 +23,6 @@ public class Commandweather extends EssentialsCommand boolean isStorm = args[0].equalsIgnoreCase("storm"); World world = user.getWorld(); - charge(user); if (args.length > 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java index ef815dd87..1769202f5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java @@ -35,7 +35,6 @@ public class Commandwhois extends EssentialsCommand showhidden = true; } String whois = args[0].toLowerCase(); - charge(sender); int prefixLength = ChatColor.stripColor(ess.getSettings().getNicknamePrefix()).length(); for (Player p : server.getOnlinePlayers()) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandworld.java b/Essentials/src/com/earth2me/essentials/commands/Commandworld.java index 0a315b1d4..77db8e5e3 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandworld.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandworld.java @@ -47,7 +47,7 @@ public class Commandworld extends EssentialsCommand user.sendMessage(Util.i18n("invalidWorld")); user.sendMessage(Util.format("possibleWorlds", server.getWorlds().size() - 1)); user.sendMessage(Util.i18n("typeWorldName")); - return; + throw new NoChargeException(); } } @@ -71,5 +71,6 @@ public class Commandworld extends EssentialsCommand Trade charge = new Trade(this.getName(), ess); charge.isAffordableFor(user); user.getTeleport().teleport(loc, charge); + throw new NoChargeException(); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandworth.java b/Essentials/src/com/earth2me/essentials/commands/Commandworth.java index f2d6ed954..b59070320 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandworth.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandworth.java @@ -43,7 +43,6 @@ public class Commandworth extends EssentialsCommand throw new Exception(Util.i18n("itemCannotBeSold")); } - charge(user); user.sendMessage(is.getDurability() != 0 ? Util.format("worthMeta", is.getType().toString().toLowerCase().replace("_", ""), diff --git a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java index c99cdfdc9..58da18c21 100644 --- a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java +++ b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java @@ -79,7 +79,10 @@ public abstract class EssentialsCommand implements IEssentialsCommand @Override public final void run(final Server server, final User user, final String commandLabel, final Command cmd, final String[] args) throws Exception { + final Trade charge = new Trade(this.getName(), ess); + charge.isAffordableFor(user); run(server, user, commandLabel, args); + charge.charge(user); } protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception @@ -111,13 +114,4 @@ public abstract class EssentialsCommand implements IEssentialsCommand } return bldr.toString(); } - - protected void charge(final CommandSender sender) throws ChargeException - { - if (sender instanceof Player) - { - final Trade charge = new Trade(this.getName(), ess); - charge.charge(ess.getUser((Player)sender)); - } - } } diff --git a/Essentials/src/com/earth2me/essentials/commands/NoChargeException.java b/Essentials/src/com/earth2me/essentials/commands/NoChargeException.java new file mode 100644 index 000000000..bb0088792 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/commands/NoChargeException.java @@ -0,0 +1,10 @@ +package com.earth2me.essentials.commands; + + +public class NoChargeException extends Exception +{ + public NoChargeException() + { + super("Will charge later"); + } +} diff --git a/Essentials/src/com/earth2me/essentials/perm/BPermissionsHandler.java b/Essentials/src/com/earth2me/essentials/perm/BPermissionsHandler.java new file mode 100644 index 000000000..90b905113 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/perm/BPermissionsHandler.java @@ -0,0 +1,51 @@ +package com.earth2me.essentials.perm; + +import de.bananaco.permissions.Permissions; +import de.bananaco.permissions.interfaces.PermissionSet; +import de.bananaco.permissions.worlds.WorldPermissionsManager; +import java.util.List; +import org.bukkit.entity.Player; + + +public class BPermissionsHandler extends SuperpermsHandler +{ + private final transient WorldPermissionsManager wpm; + + public BPermissionsHandler() + { + wpm = Permissions.getWorldPermissionsManager(); + } + + @Override + public String getGroup(final Player base) + { + final List<String> groups = getGroups(base); + if (groups == null || groups.isEmpty()) + { + return null; + } + return groups.get(0); + } + + @Override + public List<String> getGroups(final Player base) + { + final PermissionSet pset = wpm.getPermissionSet(base.getWorld()); + if (pset == null) + { + return null; + } + return pset.getGroups(base); + } + + @Override + public boolean inGroup(final Player base, final String group) + { + final List<String> groups = getGroups(base); + if (groups == null || groups.isEmpty()) + { + return false; + } + return groups.contains(group); + } +} diff --git a/Essentials/src/com/earth2me/essentials/ConfigPermissionsHandler.java b/Essentials/src/com/earth2me/essentials/perm/ConfigPermissionsHandler.java index 200aa34f8..fad479444 100644 --- a/Essentials/src/com/earth2me/essentials/ConfigPermissionsHandler.java +++ b/Essentials/src/com/earth2me/essentials/perm/ConfigPermissionsHandler.java @@ -1,46 +1,61 @@ -package com.earth2me.essentials; +package com.earth2me.essentials.perm; +import com.earth2me.essentials.IEssentials; +import java.util.List; import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; public class ConfigPermissionsHandler implements IPermissionsHandler { private final transient IEssentials ess; - public ConfigPermissionsHandler(final IEssentials ess) + public ConfigPermissionsHandler(final Plugin ess) { - this.ess = ess; + this.ess = (IEssentials)ess; } + @Override public String getGroup(final Player base) { - return "default"; + return null; } + @Override + public List<String> getGroups(final Player base) + { + return null; + } + + @Override public boolean canBuild(final Player base, final String group) { return true; } + @Override public boolean inGroup(final Player base, final String group) { return false; } + @Override public boolean hasPermission(final Player base, final String node) { final String[] cmds = node.split("\\.", 2); - return !ess.getSettings().isCommandRestricted(cmds[cmds.length - 1]) - && ess.getSettings().isPlayerCommand(cmds[cmds.length - 1]); + return !ess.getSettings().isCommandRestricted(cmds[cmds.length - 1]) + && ess.getSettings().isPlayerCommand(cmds[cmds.length - 1]); } + @Override public String getPrefix(final Player base) { - return ""; + return null; } + @Override public String getSuffix(final Player base) { - return ""; + return null; } } diff --git a/Essentials/src/com/earth2me/essentials/IPermissionsHandler.java b/Essentials/src/com/earth2me/essentials/perm/IPermissionsHandler.java index a7bcc80b7..27af48e8c 100644 --- a/Essentials/src/com/earth2me/essentials/IPermissionsHandler.java +++ b/Essentials/src/com/earth2me/essentials/perm/IPermissionsHandler.java @@ -1,13 +1,15 @@ -package com.earth2me.essentials; +package com.earth2me.essentials.perm; +import java.util.List; import org.bukkit.entity.Player; public interface IPermissionsHandler { - String getGroup(Player base); + List<String> getGroups(Player base); + boolean canBuild(Player base, String group); boolean inGroup(Player base, String group); @@ -17,5 +19,4 @@ public interface IPermissionsHandler String getPrefix(Player base); String getSuffix(Player base); - } diff --git a/Essentials/src/com/earth2me/essentials/perm/NullPermissionsHandler.java b/Essentials/src/com/earth2me/essentials/perm/NullPermissionsHandler.java new file mode 100644 index 000000000..b51aeb055 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/perm/NullPermissionsHandler.java @@ -0,0 +1,51 @@ +package com.earth2me.essentials.perm; + +import java.util.Collections; +import java.util.List; +import org.bukkit.entity.Player; + + +public class NullPermissionsHandler implements IPermissionsHandler +{ + @Override + public String getGroup(final Player base) + { + return null; + } + + @Override + public List<String> getGroups(final Player base) + { + return Collections.emptyList(); + } + + @Override + public boolean canBuild(final Player base, final String group) + { + return false; + } + + @Override + public boolean inGroup(final Player base, final String group) + { + return false; + } + + @Override + public boolean hasPermission(final Player base, final String node) + { + return false; + } + + @Override + public String getPrefix(final Player base) + { + return null; + } + + @Override + public String getSuffix(final Player base) + { + return null; + } +} diff --git a/Essentials/src/com/earth2me/essentials/Permissions2Handler.java b/Essentials/src/com/earth2me/essentials/perm/Permissions2Handler.java index 71d7da58b..6b5ff5b73 100644 --- a/Essentials/src/com/earth2me/essentials/Permissions2Handler.java +++ b/Essentials/src/com/earth2me/essentials/perm/Permissions2Handler.java @@ -1,7 +1,9 @@ -package com.earth2me.essentials; +package com.earth2me.essentials.perm; import com.nijiko.permissions.PermissionHandler; import com.nijikokun.bukkit.Permissions.Permissions; +import java.util.Arrays; +import java.util.List; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -10,41 +12,50 @@ public class Permissions2Handler implements IPermissionsHandler { private final transient PermissionHandler permissionHandler; - Permissions2Handler(final Plugin permissionsPlugin) + public Permissions2Handler(final Plugin permissionsPlugin) { permissionHandler = ((Permissions)permissionsPlugin).getHandler(); } + @Override public String getGroup(final Player base) { - final String group = permissionHandler.getGroup(base.getWorld().getName(), base.getName()); - return group == null ? "default" : group; + return permissionHandler.getGroup(base.getWorld().getName(), base.getName()); } + @Override + public List<String> getGroups(final Player base) + { + return Arrays.asList(permissionHandler.getGroups(base.getWorld().getName(), base.getName())); + } + + @Override public boolean canBuild(final Player base, final String group) { return permissionHandler.canGroupBuild(base.getWorld().getName(), getGroup(base)); } + @Override public boolean inGroup(final Player base, final String group) { return permissionHandler.inGroup(base.getWorld().getName(), base.getName(), group); } + @Override public boolean hasPermission(final Player base, final String node) { return permissionHandler.permission(base, node); } + @Override public String getPrefix(final Player base) { - final String prefix = permissionHandler.getGroupPrefix(base.getWorld().getName(), getGroup(base)); - return prefix == null ? "" : prefix; + return permissionHandler.getGroupPrefix(base.getWorld().getName(), getGroup(base)); } + @Override public String getSuffix(final Player base) { - final String suffix = permissionHandler.getGroupSuffix(base.getWorld().getName(), getGroup(base)); - return suffix == null ? "" : suffix; + return permissionHandler.getGroupSuffix(base.getWorld().getName(), getGroup(base)); } } diff --git a/Essentials/src/com/earth2me/essentials/Permissions3Handler.java b/Essentials/src/com/earth2me/essentials/perm/Permissions3Handler.java index 99c95da0a..190d5b8c5 100644 --- a/Essentials/src/com/earth2me/essentials/Permissions3Handler.java +++ b/Essentials/src/com/earth2me/essentials/perm/Permissions3Handler.java @@ -1,7 +1,9 @@ -package com.earth2me.essentials; +package com.earth2me.essentials.perm; import com.nijiko.permissions.PermissionHandler; import com.nijikokun.bukkit.Permissions.Permissions; +import java.util.Arrays; +import java.util.List; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -9,40 +11,51 @@ import org.bukkit.plugin.Plugin; public class Permissions3Handler implements IPermissionsHandler { private final transient PermissionHandler permissionHandler; - - Permissions3Handler(final Plugin permissionsPlugin) + + public Permissions3Handler(final Plugin permissionsPlugin) { permissionHandler = ((Permissions)permissionsPlugin).getHandler(); } + @Override public String getGroup(final Player base) { return permissionHandler.getPrimaryGroup(base.getWorld().getName(), base.getName()); } + @Override + public List<String> getGroups(final Player base) + { + return Arrays.asList(permissionHandler.getGroups(base.getWorld().getName(), base.getName())); + } + + @Override public boolean canBuild(final Player base, final String group) { return permissionHandler.canUserBuild(base.getWorld().getName(), base.getName()); } + @Override public boolean inGroup(final Player base, final String group) { return permissionHandler.inGroup(base.getWorld().getName(), base.getName(), group); } + @Override public boolean hasPermission(final Player base, final String node) { return permissionHandler.has(base, node); } + @Override public String getPrefix(final Player base) { return permissionHandler.getUserPrefix(base.getWorld().getName(), base.getName()); } + @Override public String getSuffix(final Player base) { return permissionHandler.getUserSuffix(base.getWorld().getName(), base.getName()); } - } diff --git a/Essentials/src/com/earth2me/essentials/perm/PermissionsBukkitHandler.java b/Essentials/src/com/earth2me/essentials/perm/PermissionsBukkitHandler.java new file mode 100644 index 000000000..d47c3c8a4 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/perm/PermissionsBukkitHandler.java @@ -0,0 +1,77 @@ +package com.earth2me.essentials.perm; + +import com.platymuus.bukkit.permissions.Group; +import com.platymuus.bukkit.permissions.PermissionInfo; +import com.platymuus.bukkit.permissions.PermissionsPlugin; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + + +public class PermissionsBukkitHandler extends SuperpermsHandler +{ + private final transient PermissionsPlugin plugin; + + public PermissionsBukkitHandler(final Plugin plugin) + { + this.plugin = (PermissionsPlugin)plugin; + } + + @Override + public String getGroup(final Player base) + { + final List<Group> groups = getPBGroups(base); + if (groups == null || groups.isEmpty()) + { + return null; + } + return groups.get(0).getName(); + } + + @Override + public List<String> getGroups(final Player base) + { + final List<Group> groups = getPBGroups(base); + if (groups.size() == 1) + { + return Collections.singletonList(groups.get(0).getName()); + } + final List<String> groupNames = new ArrayList<String>(groups.size()); + for (Group group : groups) + { + groupNames.add(group.getName()); + } + return groupNames; + } + + private List<Group> getPBGroups(final Player base) + { + final PermissionInfo info = plugin.getPlayerInfo(base.getName()); + if (info == null) + { + return Collections.emptyList(); + } + final List<Group> groups = info.getGroups(); + if (groups == null || groups.isEmpty()) + { + return Collections.emptyList(); + } + return groups; + } + + @Override + public boolean inGroup(final Player base, final String group) + { + final List<Group> groups = getPBGroups(base); + for (Group group1 : groups) + { + if (group1.getName().equalsIgnoreCase(group)) + { + return true; + } + } + return false; + } +} diff --git a/Essentials/src/com/earth2me/essentials/PermissionsExHandler.java b/Essentials/src/com/earth2me/essentials/perm/PermissionsExHandler.java index f9151c77e..5b7bb7b81 100644 --- a/Essentials/src/com/earth2me/essentials/PermissionsExHandler.java +++ b/Essentials/src/com/earth2me/essentials/perm/PermissionsExHandler.java @@ -1,12 +1,14 @@ -package com.earth2me.essentials; +package com.earth2me.essentials.perm; +import java.util.Arrays; +import java.util.List; import org.bukkit.entity.Player; import ru.tehkode.permissions.PermissionManager; import ru.tehkode.permissions.PermissionUser; import ru.tehkode.permissions.bukkit.PermissionsEx; -class PermissionsExHandler implements IPermissionsHandler +public class PermissionsExHandler implements IPermissionsHandler { private final transient PermissionManager manager; @@ -15,17 +17,30 @@ class PermissionsExHandler implements IPermissionsHandler manager = PermissionsEx.getPermissionManager(); } - public String getGroup(Player base) + @Override + public String getGroup(final Player base) { final PermissionUser user = manager.getUser(base.getName()); if (user == null) { - return "default"; + return null; } return user.getGroupsNames()[0]; } - public boolean canBuild(Player base, String group) + @Override + public List<String> getGroups(final Player base) + { + final PermissionUser user = manager.getUser(base.getName()); + if (user == null) + { + return null; + } + return Arrays.asList(user.getGroupsNames()); + } + + @Override + public boolean canBuild(final Player base, final String group) { final PermissionUser user = manager.getUser(base.getName()); if (user == null) @@ -36,7 +51,8 @@ class PermissionsExHandler implements IPermissionsHandler return user.getOptionBoolean("build", base.getWorld().getName(), true); } - public boolean inGroup(Player base, String group) + @Override + public boolean inGroup(final Player base, final String group) { final PermissionUser user = manager.getUser(base.getName()); if (user == null) @@ -47,27 +63,30 @@ class PermissionsExHandler implements IPermissionsHandler return user.inGroup(group); } - public boolean hasPermission(Player base, String node) + @Override + public boolean hasPermission(final Player base, final String node) { return manager.has(base.getName(), node, base.getWorld().getName()); } - public String getPrefix(Player base) + @Override + public String getPrefix(final Player base) { final PermissionUser user = manager.getUser(base.getName()); if (user == null) { - return ""; + return null; } return user.getPrefix(); } - public String getSuffix(Player base) + @Override + public String getSuffix(final Player base) { final PermissionUser user = manager.getUser(base.getName()); if (user == null) { - return ""; + return null; } return user.getSuffix(); } diff --git a/Essentials/src/com/earth2me/essentials/perm/PermissionsHandler.java b/Essentials/src/com/earth2me/essentials/perm/PermissionsHandler.java new file mode 100644 index 000000000..8adff346a --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/perm/PermissionsHandler.java @@ -0,0 +1,180 @@ +package com.earth2me.essentials.perm; + +import java.util.Collections; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginManager; + + +public class PermissionsHandler implements IPermissionsHandler +{ + private transient IPermissionsHandler handler = new NullPermissionsHandler(); + private transient String defaultGroup = "default"; + private final transient Plugin plugin; + private final static Logger LOGGER = Logger.getLogger("Minecraft"); + private transient boolean useSuperperms = false; + + public PermissionsHandler(final Plugin plugin) + { + this.plugin = plugin; + } + + public PermissionsHandler(final Plugin plugin, final boolean useSuperperms) + { + this.plugin = plugin; + this.useSuperperms = useSuperperms; + } + + public PermissionsHandler(final Plugin plugin, final String defaultGroup) + { + this.plugin = plugin; + this.defaultGroup = defaultGroup; + } + + @Override + public String getGroup(final Player base) + { + String group = handler.getGroup(base); + if (group == null) + { + group = defaultGroup; + } + return group; + } + + @Override + public List<String> getGroups(final Player base) + { + List<String> groups = handler.getGroups(base); + if (groups == null || groups.isEmpty()) + { + groups = Collections.singletonList(defaultGroup); + } + return Collections.unmodifiableList(groups); + } + + @Override + public boolean canBuild(final Player base, final String group) + { + return handler.canBuild(base, group); + } + + @Override + public boolean inGroup(final Player base, final String group) + { + return handler.inGroup(base, group); + } + + @Override + public boolean hasPermission(final Player base, final String node) + { + return handler.hasPermission(base, node); + } + + @Override + public String getPrefix(final Player base) + { + String prefix = handler.getPrefix(base); + if (prefix == null) + { + prefix = ""; + } + return prefix; + } + + @Override + public String getSuffix(final Player base) + { + String suffix = handler.getSuffix(base); + if (suffix == null) + { + suffix = ""; + } + return suffix; + } + + public void checkPermissions() + { + final PluginManager pluginManager = plugin.getServer().getPluginManager(); + + final Plugin permExPlugin = pluginManager.getPlugin("PermissionsEx"); + if (permExPlugin != null && permExPlugin.isEnabled()) + { + if (!(handler instanceof PermissionsExHandler)) + { + LOGGER.log(Level.INFO, "Essentials: Using PermissionsEx based permissions."); + handler = new PermissionsExHandler(); + } + return; + } + + final Plugin permBukkitPlugin = pluginManager.getPlugin("PermissionsBukkit"); + if (permBukkitPlugin != null && permBukkitPlugin.isEnabled()) + { + if (!(handler instanceof PermissionsBukkitHandler)) + { + LOGGER.log(Level.INFO, "Essentials: Using PermissionsBukkit based permissions."); + handler = new PermissionsBukkitHandler(permBukkitPlugin); + } + return; + } + + final Plugin bPermPlugin = pluginManager.getPlugin("bPermissions"); + if (bPermPlugin != null && bPermPlugin.isEnabled()) + { + if (!(handler instanceof BPermissionsHandler)) + { + LOGGER.log(Level.INFO, "Essentials: Using bPermissions based permissions."); + handler = new BPermissionsHandler(); + } + return; + } + + final Plugin permPlugin = pluginManager.getPlugin("Permissions"); + if (permPlugin != null && permPlugin.isEnabled()) + { + if (permPlugin.getDescription().getVersion().charAt(0) == '3') + { + if (!(handler instanceof Permissions3Handler)) + { + LOGGER.log(Level.INFO, "Essentials: Using Permissions 3 based permissions."); + handler = new Permissions3Handler(permPlugin); + } + } + else + { + if (!(handler instanceof Permissions2Handler)) + { + LOGGER.log(Level.INFO, "Essentials: Using Permissions 2 based permissions."); + handler = new Permissions2Handler(permPlugin); + } + } + return; + } + + if (useSuperperms) + { + if (!(handler instanceof SuperpermsHandler)) + { + LOGGER.log(Level.INFO, "Essentials: Using superperms based permissions."); + handler = new SuperpermsHandler(); + } + } + else + { + if (!(handler instanceof ConfigPermissionsHandler)) + { + LOGGER.log(Level.INFO, "Essentials: Using config based permissions. Enable superperms in config."); + handler = new ConfigPermissionsHandler(plugin); + } + } + } + + public void setUseSuperperms(final boolean useSuperperms) + { + this.useSuperperms = useSuperperms; + } +} diff --git a/Essentials/src/com/earth2me/essentials/perm/SuperpermsHandler.java b/Essentials/src/com/earth2me/essentials/perm/SuperpermsHandler.java new file mode 100644 index 000000000..70a118bcf --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/perm/SuperpermsHandler.java @@ -0,0 +1,66 @@ +package com.earth2me.essentials.perm; + +import java.util.List; +import org.bukkit.entity.Player; + + +public class SuperpermsHandler implements IPermissionsHandler +{ + @Override + public String getGroup(final Player base) + { + return null; + } + + @Override + public List<String> getGroups(final Player base) + { + return null; + } + + @Override + public boolean canBuild(final Player base, final String group) + { + return hasPermission(base, "essentials.build"); + } + + @Override + public boolean inGroup(final Player base, final String group) + { + return false; + } + + @Override + public boolean hasPermission(final Player base, final String node) + { + if (base.hasPermission("-" + node)) + { + return false; + } + final String[] parts = node.split("\\."); + final StringBuilder builder = new StringBuilder(node.length()); + for (String part : parts) + { + builder.append('*'); + if (base.hasPermission(builder.toString())) + { + return true; + } + builder.deleteCharAt(builder.length() - 1); + builder.append(part).append('.'); + } + return base.hasPermission(node); + } + + @Override + public String getPrefix(final Player base) + { + return null; + } + + @Override + public String getSuffix(final Player base) + { + return null; + } +} diff --git a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java index 530bc9c7f..17d7a5993 100644 --- a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java +++ b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java @@ -11,7 +11,6 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; -import org.bukkit.craftbukkit.block.CraftSign; import org.bukkit.entity.Player; import org.bukkit.event.block.SignChangeEvent; import org.bukkit.inventory.ItemStack; @@ -452,7 +451,7 @@ public class EssentialsSign public BlockSign(final Block block) { this.block = block; - this.sign = new CraftSign(block); + this.sign = (Sign)block.getState(); } public final String getLine(final int index) diff --git a/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java b/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java index eb6163d20..7320f27a4 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java @@ -7,7 +7,6 @@ import java.util.logging.Logger; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.Sign; -import org.bukkit.craftbukkit.block.CraftSign; import org.bukkit.entity.Player; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBurnEvent; @@ -48,7 +47,7 @@ public class SignBlockListener extends BlockListener final int mat = block.getTypeId(); if (mat == Material.SIGN_POST.getId() || mat == Material.WALL_SIGN.getId()) { - final Sign csign = new CraftSign(block); + final Sign csign = (Sign)block.getState(); for (Signs signs : Signs.values()) { final EssentialsSign sign = signs.getSign(); diff --git a/Essentials/src/com/earth2me/essentials/signs/SignPlayerListener.java b/Essentials/src/com/earth2me/essentials/signs/SignPlayerListener.java index a97c234fa..5d7900508 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignPlayerListener.java @@ -4,7 +4,6 @@ import com.earth2me.essentials.IEssentials; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.Sign; -import org.bukkit.craftbukkit.block.CraftSign; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerListener; @@ -39,7 +38,7 @@ public class SignPlayerListener extends PlayerListener { return; } - final Sign csign = new CraftSign(block); + final Sign csign = (Sign)block.getState(); for (Signs signs : Signs.values()) { final EssentialsSign sign = signs.getSign(); diff --git a/Essentials/src/com/earth2me/essentials/signs/SignProtection.java b/Essentials/src/com/earth2me/essentials/signs/SignProtection.java index 5dbadd225..1db607606 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignProtection.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignProtection.java @@ -15,7 +15,6 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; -import org.bukkit.craftbukkit.block.CraftSign; import org.bukkit.inventory.ItemStack; @@ -203,7 +202,7 @@ public class SignProtection extends EssentialsSign { if (b.getType() == Material.SIGN_POST || b.getType() == Material.WALL_SIGN) { - final Sign sign = new CraftSign(b); + final Sign sign = (Sign)b.getState(); if (sign.getLine(0).equalsIgnoreCase("§1[Protection]")) { return true; @@ -217,7 +216,7 @@ public class SignProtection extends EssentialsSign { if (a.getType() == Material.SIGN_POST || a.getType() == Material.WALL_SIGN) { - final Sign sign = new CraftSign(a); + final Sign sign = (Sign)a.getState(); if (sign.getLine(0).equalsIgnoreCase("§1[Protection]")) { return true; diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index 6884960c1..d2c12be0e 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -230,12 +230,6 @@ remove-god-on-disconnect: false # This only works if no other permission plugins are installed use-bukkit-permissions: false -# Check for updates -# We do not recommend to disable this unless you are using CraftbukkitUpToDate or Bukget. -# If you don't like the notices in game, remove the permission -# essentials.admin.notices.update from your user. -update-check: true - # Auto-AFK # After this timeout in seconds, the user will be set as afk. # Set to -1 for no timeout. diff --git a/Essentials/src/examples/bpermissions.yml b/Essentials/src/examples/bpermissions.yml new file mode 100644 index 000000000..9ba493fae --- /dev/null +++ b/Essentials/src/examples/bpermissions.yml @@ -0,0 +1,120 @@ +default: Default +groups: + Default: + - essentials.spawn + - essentials.rules + - essentials.motd + - essentials.list + - essentials.helpop + - essentials.help + Builder: + - essentials.build + - essentials.afk + - essentials.back + - essentials.back.ondeath + - essentials.balance + - essentials.balance.others + - essentials.balancetop + - essentials.chat.color + - essentials.chat.shout + - essentials.chat.question + - essentials.compass + - essentials.depth + - essentials.home + - essentials.ignore + - essentials.kit + - essentials.kit.tools + - essentials.mail + - essentials.mail.send + - essentials.me + - essentials.msg + - essentials.nick + - essentials.pay + - essentials.ping + - essentials.portal + - essentials.powertool + - essentials.protect + - essentials.sethome + - essentials.signs.use.* + - essentials.signs.create.disposal + - essentials.signs.create.mail + - essentials.signs.create.protection + - essentials.signs.create.trade + - essentials.signs.break.disposal + - essentials.signs.break.mail + - essentials.signs.break.protection + - essentials.signs.break.trade + - essentials.suicide + - essentials.time + - essentials.tpa + - essentials.tpaccept + - essentials.tpahere + - essentials.tpdeny + - essentials.warp + - essentials.warp.list + - essentials.worth + Moderator: + - essentials.build + - essentials.ban + - essentials.ban.notify + - essentials.banip + - essentials.broadcast + - essentials.clearinventory + - essentials.delwarp + - essentials.eco.loan + - essentials.ext + - essentials.getpos + - essentials.helpop.recieve + - essentials.home.others + - essentials.invsee + - essentials.jails + - essentials.jump + - essentials.kick + - essentials.kick.notify + - essentials.kill + - essentials.mute + - essentials.nick.others + - essentials.realname + - essentials.setwarp + - essentials.signs.create.* + - essentials.signs.break.* + - essentials.spawner + - essentials.thunder + - essentials.time + - essentials.time.set + - essentials.protect.alerts + - essentials.protect.admin + - essentials.protect.ownerinfo + - essentials.ptime + - essentials.ptime.others + - essentials.togglejail + - essentials.top + - essentials.tp + - essentials.tphere + - essentials.tppos + - essentials.tptoggle + - essentials.unban + - essentials.unbanip + - essentials.weather + - essentials.whois + - essentials.world + Admin: + # Since we use essentials.* permission here, we can still disable commands like this + # This is only available for essentials permissions + - -essentials.backup + - -essentials.essentials + - -essentials.setspawn + - -essentials.reloadall + - essentials.* + Owner: + - essentials.* +players: + notch: + - Default + snowleo: + - Admin + - Moderator + - Builder + - Default + KHobbits: + - Owner diff --git a/Essentials/src/examples/permissionsbukkit.yml b/Essentials/src/examples/permissionsbukkit.yml new file mode 100644 index 000000000..243752232 --- /dev/null +++ b/Essentials/src/examples/permissionsbukkit.yml @@ -0,0 +1,135 @@ +users: + snowleo: + groups: + - Admin +groups: + Default: + permissions: + permissions.build: true + essentials.build: false + essentials.spawn: true + essentials.rules: true + essentials.motd: true + essentials.list: true + essentials.helpop: true + essentials.help: true + Builder: + permissions: + permissions.build: true + essentials.build: true + essentials.afk: true + essentials.back: true + essentials.back.ondeath: true + essentials.balance: true + essentials.balance.others: true + essentials.balancetop: true + essentials.chat.color: true + essentials.chat.shout: true + essentials.chat.question: true + essentials.compass: true + essentials.depth: true + essentials.home: true + essentials.ignore: true + essentials.kit: true + essentials.kit.tools: true + essentials.mail: true + essentials.mail.send: true + essentials.me: true + essentials.msg: true + essentials.nick: true + essentials.pay: true + essentials.ping: true + essentials.portal: true + essentials.powertool: true + essentials.protect: true + essentials.sethome: true + essentials.signs.use.*: true + essentials.signs.create.disposal: true + essentials.signs.create.mail: true + essentials.signs.create.protection: true + essentials.signs.create.trade: true + essentials.signs.break.disposal: true + essentials.signs.break.mail: true + essentials.signs.break.protection: true + essentials.signs.break.trade: true + essentials.suicide: true + essentials.time: true + essentials.tpa: true + essentials.tpaccept: true + essentials.tpahere: true + essentials.tpdeny: true + essentials.warp: true + essentials.warp.list: true + essentials.worth: true + inheritance: + - Default + Moderator: + permissions: + essentials.ban: true + essentials.ban.notify: true + essentials.banip: true + essentials.broadcast: true + essentials.clearinventory: true + essentials.delwarp: true + essentials.eco.loan: true + essentials.ext: true + essentials.getpos: true + essentials.helpop.recieve: true + essentials.home.others: true + essentials.invsee: true + essentials.jails: true + essentials.jump: true + essentials.kick: true + essentials.kick.notify: true + essentials.kill: true + essentials.mute: true + essentials.nick.others: true + essentials.realname: true + essentials.setwarp: true + essentials.signs.create.*: true + essentials.signs.break.*: true + essentials.spawner: true + essentials.thunder: true + essentials.time: true + essentials.time.set: true + essentials.protect.alerts: true + essentials.protect.admin: true + essentials.protect.ownerinfo: true + essentials.ptime: true + essentials.ptime.others: true + essentials.togglejail: true + essentials.top: true + essentials.tp: true + essentials.tphere: true + essentials.tppos: true + essentials.tptoggle: true + essentials.unban: true + essentials.unbanip: true + essentials.weather: true + essentials.whois: true + essentials.world: true + inheritance: + - Builder + Admin: + permissions: + permissions.*: true + # Since we use essentials.* permission here, we can still disable commands like this + # This is only available for essentials permissions + -essentials.backup: true + -essentials.essentials: true + -essentials.setspawn: true + -essentials.reloadall: true + essentials.*: true + inheritance: + - Moderator + Owner: + permissions: + # Double negation + -essentials.backup: false + -essentials.essentials: false + -essentials.setspawn: false + -essentials.reloadall: false + inheritance: + - Admin +messages: + build: '&cYou do not have permission to build here.' diff --git a/Essentials/src/examples/permissionsex.yml b/Essentials/src/examples/permissionsex.yml new file mode 100644 index 000000000..47407cd62 --- /dev/null +++ b/Essentials/src/examples/permissionsex.yml @@ -0,0 +1,150 @@ +groups: + Default: + default: true + permissions: + - essentials.spawn + - essentials.rules + - essentials.motd + - essentials.list + - essentials.helpop + - essentials.help + - modifyworld.* + prefix: '&e' + options: + build: false + rank: '1000' + Builder: + permissions: + - essentials.afk + - essentials.back + - essentials.back.ondeath + - essentials.balance + - essentials.balance.others + - essentials.balancetop + - essentials.chat.color + - essentials.chat.shout + - essentials.chat.question + - essentials.compass + - essentials.depth + - essentials.home + - essentials.ignore + - essentials.kit + - essentials.kit.tools + - essentials.mail + - essentials.mail.send + - essentials.me + - essentials.msg + - essentials.nick + - essentials.pay + - essentials.ping + - essentials.portal + - essentials.powertool + - essentials.protect + - essentials.sethome + - essentials.signs.use.* + - essentials.signs.create.disposal + - essentials.signs.create.mail + - essentials.signs.create.protection + - essentials.signs.create.trade + - essentials.signs.break.disposal + - essentials.signs.break.mail + - essentials.signs.break.protection + - essentials.signs.break.trade + - essentials.suicide + - essentials.time + - essentials.tpa + - essentials.tpaccept + - essentials.tpahere + - essentials.tpdeny + - essentials.warp + - essentials.warp.list + - essentials.worth + inheritance: + - default + prefix: '&2' + options: + build: true + rank: '500' + Moderator: + permissions: + - essentials.ban + - essentials.ban.notify + - essentials.banip + - essentials.broadcast + - essentials.clearinventory + - essentials.delwarp + - essentials.eco.loan + - essentials.ext + - essentials.getpos + - essentials.helpop.recieve + - essentials.home.others + - essentials.invsee + - essentials.jails + - essentials.jump + - essentials.kick + - essentials.kick.notify + - essentials.kill + - essentials.mute + - essentials.nick.others + - essentials.realname + - essentials.setwarp + - essentials.signs.create.* + - essentials.signs.break.* + - essentials.spawner + - essentials.thunder + - essentials.time + - essentials.time.set + - essentials.protect.alerts + - essentials.protect.admin + - essentials.protect.ownerinfo + - essentials.ptime + - essentials.ptime.others + - essentials.togglejail + - essentials.top + - essentials.tp + - essentials.tphere + - essentials.tppos + - essentials.tptoggle + - essentials.unban + - essentials.unbanip + - essentials.weather + - essentials.whois + - essentials.world + - permissions.user.promote.default + - permissions.user.demote.default + - permissions.manage.membership + inheritance: + - builder + prefix: '&5' + options: + build: true + rank: '200' + Admin: + permissions: + - -essentials.backup + - -essentials.essentials + - -essentials.setspawn + - -essentials.reloadall + - essentials.* + - permissions.manage.users + - permissions.manage.users.permissions + - permissions.manage.users.permissions.timed + inheritance: + - moderator + prefix: '&c' + options: + build: true + rank: '100' + Owner: + permissions: + - '*' + inheritance: + - admin + prefix: '&4' + options: + build: true + rank: '0' +users: + snowleo: + group: + - Builder diff --git a/Essentials/src/items.csv b/Essentials/src/items.csv index 579042e18..0e5db90d7 100644 --- a/Essentials/src/items.csv +++ b/Essentials/src/items.csv @@ -1,4 +1,4 @@ -#Last updated on 7/9/2011 21:37 (gmt +3) for minecraft version 1.7.3 +#Last updated on 30/8/2011 21:30 (gmt -5) for minecraft version 1.7.3 #item,id,metadata stone,1,0 sstone,1,0 @@ -401,6 +401,58 @@ ntreeleaf,18,0 nlogleaf,18,0 ntrunkleaf,18,0 nwoodleaf,18,0 +pineleaves,18,1 +pineleaf,18,1 +pinetreeleaves,18,1 +pinelogleaves,18,1 +pinetrunkleaves,18,1 +pinewoodleaves,18,1 +ptreeleaves,18,1 +plogleaves,18,1 +ptrunkleaves,18,1 +pwoodleaves,18,1 +pitreeleaves,18,1 +pilogleaves,18,1 +pitrunkleaves,18,1 +piwoodleaves,18,1 +pinetreeleaf,18,1 +pinelogleaf,18,1 +pinetrunkleaf,18,1 +pinewoodleaf,18,1 +ptreeleaf,18,1 +plogleaf,18,1 +ptrunkleaf,18,1 +pwoodleaf,18,1 +pitreeleaf,18,1 +pilogleaf,18,1 +pitrunkleaf,18,1 +piwoodleaf,18,1 +birchleaves,18,2 +birchleaf,18,2 +birchtreeleaves,18,2 +birchlogleaves,18,2 +birchtrunkleaves,18,2 +birchwoodleaves,18,2 +btreeleaves,18,2 +blogleaves,18,2 +btrunkleaves,18,2 +bwoodleaves,18,2 +bitreeleaves,18,2 +bilogleaves,18,2 +bitrunkleaves,18,2 +biwoodleaves,18,2 +birchtreeleaf,18,2 +birchlogleaf,18,2 +birchtrunkleaf,18,2 +birchwoodleaf,18,2 +btreeleaf,18,2 +blogleaf,18,2 +btrunkleaf,18,2 +bwoodleaf,18,2 +bitreeleaf,18,2 +bilogleaf,18,2 +bitrunkleaf,18,2 +biwoodleaf,18,2 sponge,19,0 glass,20,0 lapislazuliore,21,0 @@ -1745,6 +1797,7 @@ gfish,350,0 roastedfish,350,0 roastfish,350,0 rofish,350,0 +dye,351,0 inksack,351,0 inksac,351,0 isack,351,0 @@ -2014,6 +2067,9 @@ cookie,357,0 map,358,0 chart,358,0 shears,359,0 +shear,359,0 +sheers,359,0 +sheer,359,0 goldmusicrecord,2256,0 goldmusicdisk,2256,0 goldmusiccd,2256,0 diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java index d96da20a7..f28fd1185 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java @@ -4,6 +4,8 @@ import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.User; import java.util.HashSet; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; import net.minecraft.server.ChunkPosition; import net.minecraft.server.Packet60Explosion; import org.bukkit.Location; @@ -12,9 +14,6 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftWorld; -import org.bukkit.craftbukkit.entity.CraftFireball; -import org.bukkit.craftbukkit.entity.CraftPlayer; -import org.bukkit.craftbukkit.entity.CraftTNTPrimed; import org.bukkit.entity.Creeper; import org.bukkit.entity.Entity; import org.bukkit.entity.Fireball; @@ -38,13 +37,13 @@ public class EssentialsProtectEntityListener extends EntityListener { private final transient IProtect prot; private final transient IEssentials ess; - + public EssentialsProtectEntityListener(final IProtect prot) { this.prot = prot; this.ess = prot.getEssentials(); } - + @Override public void onEntityDamage(final EntityDamageEvent event) { @@ -57,7 +56,7 @@ public class EssentialsProtectEntityListener extends EntityListener if (event instanceof EntityDamageByBlockEvent) { final DamageCause cause = event.getCause(); - + if (prot.getSettingBool(ProtectConfig.disable_contactdmg) && cause == DamageCause.CONTACT && !(target instanceof Player @@ -86,7 +85,7 @@ public class EssentialsProtectEntityListener extends EntityListener return; } } - + if (event instanceof EntityDamageByEntityEvent) { final EntityDamageByEntityEvent edEvent = (EntityDamageByEntityEvent)event; @@ -111,7 +110,7 @@ public class EssentialsProtectEntityListener extends EntityListener event.setCancelled(true); return; } - + if (eAttack instanceof Creeper && prot.getSettingBool(ProtectConfig.prevent_creeper_playerdmg) && !(target instanceof Player && user.isAuthorized("essentials.protect.damage.creeper") @@ -120,7 +119,7 @@ public class EssentialsProtectEntityListener extends EntityListener event.setCancelled(true); return; } - + if (eAttack instanceof Fireball && prot.getSettingBool(ProtectConfig.prevent_fireball_playerdmg) && !(target instanceof Player && user.isAuthorized("essentials.protect.damage.fireball") @@ -129,7 +128,7 @@ public class EssentialsProtectEntityListener extends EntityListener event.setCancelled(true); return; } - + if (eAttack instanceof TNTPrimed && prot.getSettingBool(ProtectConfig.prevent_tnt_playerdmg) && !(target instanceof Player && user.isAuthorized("essentials.protect.damage.tnt") @@ -138,7 +137,7 @@ public class EssentialsProtectEntityListener extends EntityListener event.setCancelled(true); return; } - + if (edEvent.getDamager() instanceof Projectile && target instanceof Player && ((prot.getSettingBool(ProtectConfig.disable_projectiles) @@ -153,7 +152,7 @@ public class EssentialsProtectEntityListener extends EntityListener return; } } - + final DamageCause cause = event.getCause(); if (target instanceof Player) { @@ -165,7 +164,7 @@ public class EssentialsProtectEntityListener extends EntityListener event.setCancelled(true); return; } - + if (cause == DamageCause.SUFFOCATION && prot.getSettingBool(ProtectConfig.disable_suffocate) && !(user.isAuthorized("essentials.protect.damage.suffocation") @@ -201,7 +200,7 @@ public class EssentialsProtectEntityListener extends EntityListener } } } - + @Override public void onEntityExplode(final EntityExplodeEvent event) { @@ -216,43 +215,50 @@ public class EssentialsProtectEntityListener extends EntityListener || prot.getSettingBool(ProtectConfig.prevent_creeper_blockdmg) || (maxHeight >= 0 && event.getLocation().getBlockY() > maxHeight))) { - final Set<ChunkPosition> set = new HashSet<ChunkPosition>(event.blockList().size()); - final Player[] players = ess.getServer().getOnlinePlayers(); - final Set<ChunkPosition> blocksUnderPlayers = new HashSet<ChunkPosition>(players.length); - final Location loc = event.getLocation(); - for (Player player : players) + try { - if (player.getWorld().equals(loc.getWorld())) + final Set<ChunkPosition> set = new HashSet<ChunkPosition>(event.blockList().size()); + final Player[] players = ess.getServer().getOnlinePlayers(); + final Set<ChunkPosition> blocksUnderPlayers = new HashSet<ChunkPosition>(players.length); + final Location loc = event.getLocation(); + for (Player player : players) { - blocksUnderPlayers.add( - new ChunkPosition( - player.getLocation().getBlockX(), - player.getLocation().getBlockY() - 1, - player.getLocation().getBlockZ())); + if (player.getWorld().equals(loc.getWorld())) + { + blocksUnderPlayers.add( + new ChunkPosition( + player.getLocation().getBlockX(), + player.getLocation().getBlockY() - 1, + player.getLocation().getBlockZ())); + } } - } - ChunkPosition cp; - for (Block block : event.blockList()) - { - cp = new ChunkPosition(block.getX(), block.getY(), block.getZ()); - if (!blocksUnderPlayers.contains(cp)) + ChunkPosition cp; + for (Block block : event.blockList()) { - set.add(cp); + cp = new ChunkPosition(block.getX(), block.getY(), block.getZ()); + if (!blocksUnderPlayers.contains(cp)) + { + set.add(cp); + } } + + ((CraftServer)ess.getServer()).getHandle().sendPacketNearby(loc.getX(), loc.getY(), loc.getZ(), 64.0D, ((CraftWorld)loc.getWorld()).getHandle().worldProvider.dimension, + new Packet60Explosion(loc.getX(), loc.getY(), loc.getZ(), 3.0f, set)); + } + catch (Throwable ex) + { + Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex); } - - ((CraftServer)ess.getServer()).getHandle().sendPacketNearby(loc.getX(), loc.getY(), loc.getZ(), 64.0D, ((CraftWorld)loc.getWorld()).getHandle().worldProvider.dimension, - new Packet60Explosion(loc.getX(), loc.getY(), loc.getZ(), 3.0f, set)); event.setCancelled(true); return; } - else if (event.getEntity() instanceof CraftTNTPrimed + else if (event.getEntity() instanceof TNTPrimed && prot.getSettingBool(ProtectConfig.prevent_tnt_explosion)) { event.setCancelled(true); return; } - else if (event.getEntity() instanceof CraftFireball + else if (event.getEntity() instanceof Fireball && prot.getSettingBool(ProtectConfig.prevent_fireball_explosion)) { event.setCancelled(true); @@ -263,7 +269,12 @@ public class EssentialsProtectEntityListener extends EntityListener for (Block block : event.blockList()) { - if ((block.getType() == Material.RAILS || block.getRelative(BlockFace.UP).getType() == Material.RAILS) + if ((block.getRelative(BlockFace.UP).getType() == Material.RAILS + || block.getType() == Material.RAILS + || block.getRelative(BlockFace.UP).getType() == Material.POWERED_RAIL + || block.getType() == Material.POWERED_RAIL + || block.getRelative(BlockFace.UP).getType() == Material.DETECTOR_RAIL + || block.getType() == Material.DETECTOR_RAIL) && prot.getSettingBool(ProtectConfig.protect_rails)) { event.setCancelled(true); @@ -283,11 +294,11 @@ public class EssentialsProtectEntityListener extends EntityListener } } } - + @Override public void onCreatureSpawn(final CreatureSpawnEvent event) { - if (event.getEntity() instanceof CraftPlayer) + if (event.getEntity() instanceof Player) { return; } @@ -305,7 +316,7 @@ public class EssentialsProtectEntityListener extends EntityListener event.setCancelled(true); } } - + @Override public void onEntityTarget(final EntityTargetEvent event) { @@ -331,11 +342,11 @@ public class EssentialsProtectEntityListener extends EntityListener return; } } - + @Override public void onExplosionPrime(ExplosionPrimeEvent event) { - if (event.getEntity() instanceof CraftFireball + if (event.getEntity() instanceof Fireball && prot.getSettingBool(ProtectConfig.prevent_fireball_fire)) { event.setFire(false); diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java index 6f538ac92..9ffc1c3f0 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java @@ -16,7 +16,6 @@ public class Commandsetspawn extends EssentialsCommand @Override public void run(Server server, User user, String commandLabel, String[] args) throws Exception { - charge(user); final String group = args.length > 0 ? getFinalArg(args, 0) : "default"; ess.getSpawn().setSpawn(user.getLocation(), group); user.sendMessage(Util.format("spawnSet", group)); diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java index 3c85c3661..459eee60a 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java @@ -79,7 +79,7 @@ public class EssentialsSpawnPlayerListener extends PlayerListener if (ess.getSettings().getAnnounceNewPlayers()) { - ess.broadcastMessage(user.getName(), ess.getSettings().getAnnounceNewPlayerFormat(user)); + ess.broadcastMessage(user, ess.getSettings().getAnnounceNewPlayerFormat(user)); } } } diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java index 8ab62cd4d..34f862627 100644 --- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java +++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.xmpp; import com.earth2me.essentials.IEssentials; +import com.earth2me.essentials.IUser; import com.earth2me.essentials.Util; import java.util.List; import java.util.logging.Level; @@ -83,9 +84,10 @@ public class EssentialsXMPP extends JavaPlugin implements IEssentialsXMPP } @Override - public String getUserByAddress(final String address) + public IUser getUserByAddress(final String address) { - return instance.users.getUserByAddress(address); + String username = instance.users.getUserByAddress(address); + return username == null ? null : ess.getUser(username); } @Override @@ -122,9 +124,9 @@ public class EssentialsXMPP extends JavaPlugin implements IEssentialsXMPP } @Override - public void broadcastMessage(final String name, final String message) + public void broadcastMessage(final IUser sender, final String message) { - ess.broadcastMessage(name, message); + ess.broadcastMessage(sender, message); try { for (String address : getSpyUsers()) diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/IEssentialsXMPP.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/IEssentialsXMPP.java index d90bff803..1ed9fa732 100644 --- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/IEssentialsXMPP.java +++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/IEssentialsXMPP.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.xmpp; +import com.earth2me.essentials.IUser; import java.util.List; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -13,7 +14,7 @@ public interface IEssentialsXMPP extends Plugin List<String> getSpyUsers(); - String getUserByAddress(final String address); + IUser getUserByAddress(final String address); boolean sendMessage(final Player user, final String message); @@ -23,5 +24,5 @@ public interface IEssentialsXMPP extends Plugin boolean toggleSpy(final Player user); - void broadcastMessage(final String name, final String message); + void broadcastMessage(final IUser sender, final String message); } diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/UserManager.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/UserManager.java index 6a2a6e80a..9734444ad 100644 --- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/UserManager.java +++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/UserManager.java @@ -47,7 +47,7 @@ public class UserManager implements IConf return username; } } - return search; + return null; } public void setAddress(final String username, final String address) diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/XMPPManager.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/XMPPManager.java index e43844c5b..d7aedb9f4 100644 --- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/XMPPManager.java +++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/XMPPManager.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.xmpp; import com.earth2me.essentials.Console; import com.earth2me.essentials.EssentialsConf; import com.earth2me.essentials.IConf; +import com.earth2me.essentials.IUser; import java.io.File; import java.util.ArrayList; import java.util.Collections; @@ -101,8 +102,8 @@ public class XMPPManager extends Handler implements MessageListener, ChatManager sendCommand(chat, message); break; default: - final String name = parent.getUserByAddress(StringUtils.parseBareAddress(chat.getParticipant())); - parent.broadcastMessage(name, "="+name+": "+ message); + final IUser sender = parent.getUserByAddress(StringUtils.parseBareAddress(chat.getParticipant())); + parent.broadcastMessage(sender, "="+sender.getDisplayName()+": "+ message); } } } diff --git a/lib/PermissionsBukkit-1.2.jar b/lib/PermissionsBukkit-1.2.jar Binary files differnew file mode 100644 index 000000000..3f5caf1b4 --- /dev/null +++ b/lib/PermissionsBukkit-1.2.jar diff --git a/lib/bPermissions.jar b/lib/bPermissions.jar Binary files differnew file mode 100644 index 000000000..b3b38e425 --- /dev/null +++ b/lib/bPermissions.jar |