diff options
188 files changed, 2939 insertions, 1394 deletions
diff --git a/Essentials/src/net/ess3/Console.java b/Essentials/src/net/ess3/Console.java index 93c638a77..4639a531a 100644 --- a/Essentials/src/net/ess3/Console.java +++ b/Essentials/src/net/ess3/Console.java @@ -1,7 +1,7 @@ package net.ess3; import net.ess3.api.IReplyTo; -import org.bukkit.command.CommandSender; +import net.ess3.api.server.CommandSender; public final class Console implements IReplyTo diff --git a/Essentials/src/net/ess3/Essentials.java b/Essentials/src/net/ess3/Essentials.java index 92c8f90f9..56b59b47e 100644 --- a/Essentials/src/net/ess3/Essentials.java +++ b/Essentials/src/net/ess3/Essentials.java @@ -17,15 +17,30 @@ */ package net.ess3; +import net.ess3.api.*; +import net.ess3.api.server.Player; +import net.ess3.api.server.IPlugin; +import net.ess3.api.server.IServer; +import net.ess3.api.server.World; +import net.ess3.backup.Backup; +import net.ess3.commands.EssentialsCommandHandler; +import net.ess3.economy.Economy; +import net.ess3.economy.Trade; +import net.ess3.economy.WorthHolder; +import net.ess3.economy.register.Methods; +import net.ess3.listener.*; +import net.ess3.ranks.RanksStorage; +import net.ess3.settings.SettingsHolder; +import net.ess3.settings.SpawnsHolder; +import net.ess3.user.UserMap; +import net.ess3.utils.ExecuteTimer; import java.io.File; -import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import lombok.Getter; import lombok.Getter; import static net.ess3.I18n._; import net.ess3.api.*; @@ -45,26 +60,16 @@ import net.ess3.settings.SpawnsHolder; import net.ess3.user.UserMap; import net.ess3.utils.ExecuteTimer; import org.bukkit.Server; -import org.bukkit.World; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.plugin.InvalidDescriptionException; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginDescriptionFile; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.java.JavaPlugin; import org.yaml.snakeyaml.error.YAMLException; -public class Essentials extends JavaPlugin implements IEssentials +public class Essentials implements IEssentials { - public static final int BUKKIT_VERSION = 2149; - private static final Logger LOGGER = Logger.getLogger("Minecraft"); private transient ISettings settings; private final transient TntExplodeListener tntListener = new TntExplodeListener(this); private transient IJails jails; @@ -80,16 +85,32 @@ public class Essentials extends JavaPlugin implements IEssentials //private transient PermissionsHandler permissionsHandler; private transient IUserMap userMap; private transient ExecuteTimer execTimer; - private transient I18n i18n; + @Getter + private final I18n i18n; private transient ICommandHandler commandHandler; private transient Economy economy; - public transient boolean testing; + @Getter + private final IServer server; + @Getter + private final Logger logger; + @Getter + private final IPlugin plugin; + public static boolean testing; private transient Metrics metrics; @Getter private transient EssentialsTimer timer; @Getter private transient List<String> vanishedPlayers = new ArrayList<String>(); + public Essentials(final IServer server, final Logger logger, final IPlugin plugin) + { + this.server = server; + this.logger = logger; + this.plugin = plugin; + this.i18n = new I18n(this); + i18n.onEnable(); + } + @Override public ISettings getSettings() { @@ -108,11 +129,10 @@ public class Essentials extends JavaPlugin implements IEssentials { throw new IOException(); } - i18n = new I18n(this); - i18n.onEnable(); - LOGGER.log(Level.INFO, _("usingTempFolderForTesting")); - LOGGER.log(Level.INFO, dataFolder.toString()); - this.initialize(null, server, new PluginDescriptionFile(new FileReader(new File("src" + File.separator + "plugin.yml"))), dataFolder, null, null); + + logger.log(Level.INFO, I18n._("usingTempFolderForTesting")); + logger.log(Level.INFO, dataFolder.toString()); + //this.initialize(null, server, new PluginDescriptionFile(new FileReader(new File("src" + File.separator + "plugin.yml"))), dataFolder, null, null); settings = new SettingsHolder(this); i18n.updateLocale("en"); userMap = new UserMap(this); @@ -125,39 +145,9 @@ public class Essentials extends JavaPlugin implements IEssentials { execTimer = new ExecuteTimer(); execTimer.start(); - i18n = new I18n(this); - i18n.onEnable(); + execTimer.mark("I18n1"); - final PluginManager pm = getServer().getPluginManager(); - for (Plugin plugin : pm.getPlugins()) - { - if (plugin.getDescription().getName().startsWith("Essentials") - && !plugin.getDescription().getVersion().equals(this.getDescription().getVersion()) - && !plugin.getDescription().getName().equals("EssentialsAntiCheat")) - { - LOGGER.log(Level.WARNING, _("versionMismatch", plugin.getDescription().getName())); - } - } - final Matcher versionMatch = Pattern.compile("git-Bukkit-(?:(?:[0-9]+)\\.)+[0-9]+-R[\\.0-9]+-(?:[0-9]+-g[0-9a-f]+-)?b([0-9]+)jnks.*").matcher(getServer().getVersion()); - if (versionMatch.matches()) - { - final int versionNumber = Integer.parseInt(versionMatch.group(1)); - if (versionNumber < BUKKIT_VERSION && versionNumber > 100) - { - LOGGER.log(Level.SEVERE, " * ! * ! * ! * ! * ! * ! * ! * ! * ! * ! * ! * ! *"); - LOGGER.log(Level.SEVERE, _("notRecommendedBukkit")); - LOGGER.log(Level.SEVERE, _("requiredBukkit", Integer.toString(BUKKIT_VERSION))); - LOGGER.log(Level.SEVERE, " * ! * ! * ! * ! * ! * ! * ! * ! * ! * ! * ! * ! *"); - this.setEnabled(false); - return; - } - } - else - { - LOGGER.log(Level.INFO, _("bukkitFormatChanged")); - LOGGER.log(Level.INFO, getServer().getVersion()); - LOGGER.log(Level.INFO, getServer().getBukkitVersion()); - } + execTimer.mark("BukkitCheck"); try { @@ -192,19 +182,19 @@ public class Essentials extends JavaPlugin implements IEssentials reloadList.add(economy); spawns = new SpawnsHolder(this); reloadList.add(spawns); - reload(); + onReload(); } catch (YAMLException exception) { if (pm.getPlugin("EssentialsUpdate") != null) { - LOGGER.log(Level.SEVERE, _("essentialsHelp2")); + logger.log(Level.SEVERE, I18n._("essentialsHelp2")); } else { - LOGGER.log(Level.SEVERE, _("essentialsHelp1")); + logger.log(Level.SEVERE, I18n._("essentialsHelp1")); } - LOGGER.log(Level.SEVERE, exception.toString()); + logger.log(Level.SEVERE, exception.toString()); pm.registerEvents(new Listener() { @EventHandler(priority = EventPriority.LOW) @@ -242,7 +232,7 @@ public class Essentials extends JavaPlugin implements IEssentials timer = new EssentialsTimer(this); - getServer().getScheduler().scheduleSyncRepeatingTask(this, timer, 1, 100); + getPlugin().scheduleSyncRepeatingTask(timer, 1, 100); execTimer.mark("RegListeners"); final MetricsStarter metricsStarter = new MetricsStarter(this); @@ -259,7 +249,7 @@ public class Essentials extends JavaPlugin implements IEssentials final String timeroutput = execTimer.end(); if (getSettings().isDebug()) { - LOGGER.log(Level.INFO, "Essentials load {0}", timeroutput); + logger.log(Level.INFO, "Essentials load {0}", timeroutput); } } @@ -280,7 +270,7 @@ public class Essentials extends JavaPlugin implements IEssentials } @Override - public void reload() + public void onReload() { Trade.closeLog(); @@ -294,13 +284,6 @@ public class Essentials extends JavaPlugin implements IEssentials } @Override - public boolean onCommand(final CommandSender sender, final Command command, final String commandLabel, final String[] args) - { - return commandHandler.handleCommand(sender, command, commandLabel, args); - //return onCommandEssentials(sender, command, commandLabel, args, Essentials.class.getClassLoader(), "net.ess3.commands.Command", "essentials.", null); - } - - @Override public IJails getJails() { return jails; @@ -391,42 +374,16 @@ public class Essentials extends JavaPlugin implements IEssentials { return 0; } - final Player[] players = getServer().getOnlinePlayers(); - - for (Player player : players) + for (Player player : getServer().getOnlinePlayers()) { - final IUser user = getUser(player); + final IUser user = player.getUser(); if (!user.isIgnoringPlayer(sender)) { player.sendMessage(message); } } - return players.length; - } - - @Override - public int scheduleAsyncDelayedTask(final Runnable run) - { - return this.getServer().getScheduler().scheduleAsyncDelayedTask(this, run); - } - - @Override - public int scheduleSyncDelayedTask(final Runnable run) - { - return this.getServer().getScheduler().scheduleSyncDelayedTask(this, run); - } - - @Override - public int scheduleSyncDelayedTask(final Runnable run, final long delay) - { - return this.getServer().getScheduler().scheduleSyncDelayedTask(this, run, delay); - } - - @Override - public int scheduleSyncRepeatingTask(final Runnable run, final long delay, final long period) - { - return this.getServer().getScheduler().scheduleSyncRepeatingTask(this, run, delay, period); + return getServer().getOnlinePlayers().size(); } @Override @@ -449,13 +406,7 @@ public class Essentials extends JavaPlugin implements IEssentials { return userMap; } - - @Override - public I18n getI18n() - { - return i18n; - } - + @Override public IRanks getRanks() { diff --git a/Essentials/src/net/ess3/EssentialsTimer.java b/Essentials/src/net/ess3/EssentialsTimer.java index a144fe3c7..82e708047 100644 --- a/Essentials/src/net/ess3/EssentialsTimer.java +++ b/Essentials/src/net/ess3/EssentialsTimer.java @@ -8,7 +8,6 @@ import net.ess3.api.ISettings; import net.ess3.api.IUser; import net.ess3.permissions.Permissions; import net.ess3.user.UserData.TimestampType; -import org.bukkit.entity.Player; public class EssentialsTimer implements Runnable @@ -47,7 +46,7 @@ public class EssentialsTimer implements Runnable try { - final IUser user = ess.getUser(player); + final IUser user = player.getUser(); if (user == null) { continue; } @@ -72,7 +71,7 @@ public class EssentialsTimer implements Runnable final List<String> mail = user.getMails(); if (mail != null && !mail.isEmpty()) { - user.sendMessage(_("youHaveNewMail", mail.size())); + user.sendMessage(I18n._("youHaveNewMail", mail.size())); } } } diff --git a/Essentials/src/net/ess3/I18n.java b/Essentials/src/net/ess3/I18n.java index 949c0754a..9387c3eda 100644 --- a/Essentials/src/net/ess3/I18n.java +++ b/Essentials/src/net/ess3/I18n.java @@ -138,7 +138,7 @@ public class I18n implements II18n public FileResClassLoader(final ClassLoader classLoader, final IEssentials ess) { super(classLoader); - this.dataFolder = ess.getDataFolder(); + this.dataFolder = ess.getPlugin().getDataFolder(); } @Override diff --git a/Essentials/src/net/ess3/ItemDb.java b/Essentials/src/net/ess3/ItemDb.java index 1513c85cf..a47286c3e 100644 --- a/Essentials/src/net/ess3/ItemDb.java +++ b/Essentials/src/net/ess3/ItemDb.java @@ -1,5 +1,7 @@ package net.ess3; +import net.ess3.api.server.ItemStack; +import net.ess3.api.server.Material; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -129,9 +131,9 @@ public class ItemDb implements IItemDb metaData = (short)((item >> 32) & 0xffffL); } } - else if (Material.getMaterial(itemname) != null) + else if (Material.get(itemname) != null) { - itemid = Material.getMaterial(itemname).getId(); + itemid = Material.get(itemname).getId(); metaData = 0; } else @@ -140,14 +142,12 @@ public class ItemDb implements IItemDb } } - final Material mat = Material.getMaterial(itemid); + final Material mat = Material.get(itemid); if (mat == null) { throw new Exception(_("unknownItemId", itemid)); } - final ItemStack retval = new ItemStack(mat); - retval.setAmount(mat.getMaxStackSize()); - retval.setDurability(metaData); + final ItemStack retval = ItemStack.create(mat, mat.getMaxStackSize(), metaData); return retval; } } diff --git a/Essentials/src/net/ess3/Jails.java b/Essentials/src/net/ess3/Jails.java index d6612475a..2c3f31bca 100644 --- a/Essentials/src/net/ess3/Jails.java +++ b/Essentials/src/net/ess3/Jails.java @@ -1,28 +1,23 @@ package net.ess3; -import java.io.File; -import java.util.*; -import java.util.logging.Level; -import java.util.logging.Logger; -import lombok.Cleanup; import static net.ess3.I18n._; import net.ess3.api.IEssentials; import net.ess3.api.IJails; import net.ess3.api.IUser; import net.ess3.storage.AsyncStorageObjectHolder; +import java.io.File; +import java.util.*; +import java.util.logging.Level; +import java.util.logging.Logger; +import lombok.Cleanup; import org.bukkit.Bukkit; import org.bukkit.Location; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockDamageEvent; import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerRespawnEvent; @@ -34,44 +29,27 @@ import org.bukkit.plugin.PluginManager; public class Jails extends AsyncStorageObjectHolder<net.ess3.settings.Jails> implements IJails { private static final transient Logger LOGGER = Bukkit.getLogger(); - private static transient boolean enabled = false; public Jails(final IEssentials ess) { super(ess, net.ess3.settings.Jails.class); onReload(); + registerListeners(); } private void registerListeners() { - enabled = true; final PluginManager pluginManager = ess.getServer().getPluginManager(); - final JailListener blockListener = new JailListener(); + final JailBlockListener blockListener = new JailBlockListener(); + final JailPlayerListener playerListener = new JailPlayerListener(); pluginManager.registerEvents(blockListener, ess); + pluginManager.registerEvents(playerListener, ess); } @Override public File getStorageFile() { - return new File(ess.getDataFolder(), "jail.yml"); - } - - @Override - public void finishRead() - { - if (enabled == false && getCount() > 0) - { - registerListeners(); - } - } - - @Override - public void finishWrite() - { - if (enabled == false) - { - registerListeners(); - } + return new File(ess.getPlugin().getDataFolder(), "jail.yml"); } @Override @@ -85,7 +63,7 @@ public class Jails extends AsyncStorageObjectHolder<net.ess3.settings.Jails> imp { throw new Exception(_("jailNotExist")); } - Location loc = getData().getJails().get(jailName.toLowerCase(Locale.ENGLISH)).getBukkitLocation(); + Location loc = getData().getJails().get(jailName.toLowerCase(Locale.ENGLISH)).getStoredLocation(); if (loc == null || loc.getWorld() == null) { throw new Exception(_("jailNotExist")); @@ -169,9 +147,9 @@ public class Jails extends AsyncStorageObjectHolder<net.ess3.settings.Jails> imp { if (getData().getJails() == null) { - getData().setJails(new HashMap<String, net.ess3.storage.Location>()); + getData().setJails(new HashMap<String, net.ess3.storage.StoredLocation>()); } - getData().getJails().put(jailName.toLowerCase(Locale.ENGLISH), new net.ess3.storage.Location(loc)); + getData().getJails().put(jailName.toLowerCase(Locale.ENGLISH), new net.ess3.storage.StoredLocation(loc)); } finally { @@ -179,21 +157,8 @@ public class Jails extends AsyncStorageObjectHolder<net.ess3.settings.Jails> imp } } - @Override - public int getCount() - { - try - { - return getList().size(); - } - catch (Exception ex) - { - return 0; - } - } - - private class JailListener implements Listener + private class JailBlockListener implements Listener { @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onBlockBreak(final BlockBreakEvent event) @@ -230,125 +195,107 @@ public class Jails extends AsyncStorageObjectHolder<net.ess3.settings.Jails> imp event.setCancelled(true); } } + } + + private class JailPlayerListener implements Listener + { @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) - public void onEntityDamageByEntity(final EntityDamageByEntityEvent event) + public void onPlayerInteract(final PlayerInteractEvent event) { - if (event.getCause() != DamageCause.ENTITY_ATTACK || event.getEntity().getType() != EntityType.PLAYER) - { - return; - } - final Entity damager = event.getDamager(); - if (damager.getType() == EntityType.PLAYER) + @Cleanup + final IUser user = ess.getUser(event.getPlayer()); + user.acquireReadLock(); + if (user.getData().isJailed()) { - final IUser user = ess.getUser((Player)damager); - if (user != null && user.getData().isJailed()) - { - event.setCancelled(true); - } + event.setCancelled(true); } } - - private class JailPlayerListener implements Listener + @EventHandler(priority = EventPriority.HIGHEST) + public void onPlayerRespawn(final PlayerRespawnEvent event) { - @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) - public void onPlayerInteract(final PlayerInteractEvent event) + @Cleanup + final IUser user = ess.getUser(event.getPlayer()); + user.acquireReadLock(); + if (!user.getData().isJailed() || user.getData().getJail() == null || user.getData().getJail().isEmpty()) { - @Cleanup - final IUser user = ess.getUser(event.getPlayer()); - user.acquireReadLock(); - if (user.getData().isJailed()) - { - event.setCancelled(true); - } + return; } - @EventHandler(priority = EventPriority.HIGHEST) - public void onPlayerRespawn(final PlayerRespawnEvent event) + try { - @Cleanup - final IUser user = ess.getUser(event.getPlayer()); - user.acquireReadLock(); - if (!user.getData().isJailed() || user.getData().getJail() == null || user.getData().getJail().isEmpty()) - { - return; - } - - try + event.setRespawnLocation(getJail(user.getData().getJail())); + } + catch (Exception ex) + { + if (ess.getSettings().isDebug()) { - event.setRespawnLocation(getJail(user.getData().getJail())); + LOGGER.log(Level.INFO, _("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex); } - catch (Exception ex) + else { - if (ess.getSettings().isDebug()) - { - LOGGER.log(Level.INFO, _("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex); - } - else - { - LOGGER.log(Level.INFO, _("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())); - } + LOGGER.log(Level.INFO, _("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())); } } + } - @EventHandler(priority = EventPriority.HIGH) - public void onPlayerTeleport(final PlayerTeleportEvent event) + @EventHandler(priority = EventPriority.HIGH) + public void onPlayerTeleport(final PlayerTeleportEvent event) + { + @Cleanup + final IUser user = ess.getUser(event.getPlayer()); + user.acquireReadLock(); + if (!user.getData().isJailed() || user.getData().getJail() == null || user.getData().getJail().isEmpty()) { - @Cleanup - final IUser user = ess.getUser(event.getPlayer()); - user.acquireReadLock(); - if (!user.getData().isJailed() || user.getData().getJail() == null || user.getData().getJail().isEmpty()) - { - return; - } + return; + } - try + try + { + event.setTo(getJail(user.getData().getJail())); + } + catch (Exception ex) + { + if (ess.getSettings().isDebug()) { - event.setTo(getJail(user.getData().getJail())); + LOGGER.log(Level.INFO, _("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex); } - catch (Exception ex) + else { - if (ess.getSettings().isDebug()) - { - LOGGER.log(Level.INFO, _("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex); - } - else - { - LOGGER.log(Level.INFO, _("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())); - } + LOGGER.log(Level.INFO, _("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())); } - user.sendMessage(_("jailMessage")); } + user.sendMessage(_("jailMessage")); + } - @EventHandler(priority = EventPriority.HIGHEST) - public void onPlayerJoin(final PlayerJoinEvent event) + @EventHandler(priority = EventPriority.HIGHEST) + public void onPlayerJoin(final PlayerJoinEvent event) + { + @Cleanup + final IUser user = ess.getUser(event.getPlayer()); + user.acquireReadLock(); + if (!user.getData().isJailed() || user.getData().getJail() == null || user.getData().getJail().isEmpty()) { - @Cleanup - final IUser user = ess.getUser(event.getPlayer()); - user.acquireReadLock(); - if (!user.getData().isJailed() || user.getData().getJail() == null || user.getData().getJail().isEmpty()) - { - return; - } + return; + } - try + try + { + sendToJail(user, user.getData().getJail()); + } + catch (Exception ex) + { + if (ess.getSettings().isDebug()) { - sendToJail(user, user.getData().getJail()); + LOGGER.log(Level.INFO, _("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex); } - catch (Exception ex) + else { - if (ess.getSettings().isDebug()) - { - LOGGER.log(Level.INFO, _("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex); - } - else - { - LOGGER.log(Level.INFO, _("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())); - } + LOGGER.log(Level.INFO, _("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())); } - user.sendMessage(_("jailMessage")); } + user.sendMessage(_("jailMessage")); } } } diff --git a/Essentials/src/net/ess3/Kits.java b/Essentials/src/net/ess3/Kits.java index e979ade5f..e286eb847 100644 --- a/Essentials/src/net/ess3/Kits.java +++ b/Essentials/src/net/ess3/Kits.java @@ -1,17 +1,14 @@ package net.ess3; -import java.io.File; -import java.io.IOException; -import java.util.*; import static net.ess3.I18n._; import net.ess3.api.IEssentials; import net.ess3.api.IKits; import net.ess3.api.IUser; -import net.ess3.commands.NoChargeException; import net.ess3.settings.Kit; import net.ess3.storage.AsyncStorageObjectHolder; -import net.ess3.user.UserData.TimestampType; -import net.ess3.utils.DateUtil; +import java.io.File; +import java.io.IOException; +import java.util.*; import org.bukkit.inventory.ItemStack; @@ -26,7 +23,7 @@ public class Kits extends AsyncStorageObjectHolder<net.ess3.settings.Kits> imple @Override public File getStorageFile() throws IOException { - return new File(ess.getDataFolder(), "kits.yml"); + return new File(ess.getPlugin().getDataFolder(), "kits.yml"); } @Override @@ -63,8 +60,8 @@ public class Kits extends AsyncStorageObjectHolder<net.ess3.settings.Kits> imple @Override public void sendKit(IUser user, Kit kit) throws Exception { - final List<ItemStack> itemList = kit.getItems(); - user.giveItems(itemList, true); + final List<ItemStack> itemList = kit.getItems(); + user.giveItems(itemList, true); } @Override @@ -90,50 +87,4 @@ public class Kits extends AsyncStorageObjectHolder<net.ess3.settings.Kits> imple { return getData().getKits().isEmpty(); } - - @Override - public void finishRead() - { - } - - @Override - public void finishWrite() - { - } - - @Override - public void checkTime(final IUser user, Kit kit) throws NoChargeException - { - final Calendar time = new GregorianCalendar(); - // Take the current time, and remove the delay from it. - final double delay = kit.getDelay(); - final Calendar earliestTime = new GregorianCalendar(); - earliestTime.add(Calendar.SECOND, -(int)delay); - earliestTime.add(Calendar.MILLISECOND, -(int)((delay * 1000.0) % 1000.0)); - - // This value contains the most recent time a kit could have been used that would allow another use. - - final long earliestLong = earliestTime.getTimeInMillis(); - - // When was the last kit used? - final Long lastTime = user.getTimestamp(TimestampType.KIT); - if (lastTime == null || lastTime < earliestLong) - { - user.setTimestamp(TimestampType.KIT, time.getTimeInMillis()); - } - else if (lastTime > time.getTimeInMillis()) - { - // This is to make sure time didn't get messed up on last kit use. - // If this happens, let's give the user the benifit of the doubt. - user.setTimestamp(TimestampType.KIT, time.getTimeInMillis()); - } - else - { - time.setTimeInMillis(lastTime); - time.add(Calendar.SECOND, (int)delay); - time.add(Calendar.MILLISECOND, (int)((delay * 1000.0) % 1000.0)); - user.sendMessage(_("kitTimed", DateUtil.formatDateDiff(time.getTimeInMillis()))); - throw new NoChargeException(); - } - } } diff --git a/Essentials/src/net/ess3/Teleport.java b/Essentials/src/net/ess3/Teleport.java index 0d25e47bc..04e47e493 100644 --- a/Essentials/src/net/ess3/Teleport.java +++ b/Essentials/src/net/ess3/Teleport.java @@ -1,22 +1,21 @@ package net.ess3; -import java.util.Calendar; -import java.util.GregorianCalendar; -import java.util.logging.Logger; import static net.ess3.I18n._; import net.ess3.api.IEssentials; import net.ess3.api.ITeleport; import net.ess3.api.IUser; +import net.ess3.api.server.Player; +import net.ess3.api.server.Location; +import net.ess3.commands.NotEnoughArgumentsException; import net.ess3.economy.Trade; import net.ess3.permissions.Permissions; import net.ess3.user.CooldownException; import net.ess3.user.UserData.TimestampType; import net.ess3.utils.DateUtil; import net.ess3.utils.LocationUtil; -import org.bukkit.Location; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerRespawnEvent; +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.logging.Logger; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -29,7 +28,7 @@ public class Teleport implements Runnable, ITeleport private static class Target { private final Location location; - private final Entity entity; + private final Player entity; public Target(Location location) { @@ -37,7 +36,7 @@ public class Teleport implements Runnable, ITeleport this.entity = null; } - public Target(Entity entity) + public Target(Player entity) { this.entity = entity; this.location = null; @@ -120,7 +119,7 @@ public class Teleport implements Runnable, ITeleport } catch (Throwable ex) { - ess.getCommandHandler().showCommandError(user.getBase(), "teleport", ex); + ess.getCommandHandler().showCommandError(user, "teleport", ex); } } catch (Exception ex) @@ -139,11 +138,9 @@ public class Teleport implements Runnable, ITeleport @Override public void respawn(final Trade chargeFor, TeleportCause cause) throws Exception { - final Player player = user.getBase(); - final Location bed = player.getBedSpawnLocation(); - final PlayerRespawnEvent pre = new PlayerRespawnEvent(player, bed == null ? player.getWorld().getSpawnLocation() : bed, bed != null); - ess.getServer().getPluginManager().callEvent(pre); - teleport(new Target(pre.getRespawnLocation()), chargeFor, cause); + final Location bed = user.getBedSpawnLocation(); + final Location respawnLoc = ess.getPlugin().callRespawnEvent(user, bed == null ? user.getWorld().getSpawnLocation() : bed, bed != null); + teleport(new Target(respawnLoc), chargeFor, cause); } @Override @@ -175,7 +172,7 @@ public class Teleport implements Runnable, ITeleport } try { - ess.getServer().getScheduler().cancelTask(teleTimer); + ess.getPlugin().cancelTask(teleTimer); if (notifyUser) { user.sendMessage(_("pendingTeleportCancelled")); @@ -203,8 +200,7 @@ public class Teleport implements Runnable, ITeleport teleport(new Target(loc), chargeFor, cause); } - @Override - public void teleport(Entity entity, Trade chargeFor, TeleportCause cause) throws Exception + public void teleport(Player entity, Trade chargeFor, TeleportCause cause) throws Exception { teleport(new Target(entity), chargeFor, cause); } @@ -236,7 +232,7 @@ public class Teleport implements Runnable, ITeleport user.sendMessage(_("dontMoveMessage", DateUtil.formatDateDiff(c.getTimeInMillis()))); initTimer((long)(tDelay * 1000.0), target, chargeFor, cause); - teleTimer = ess.scheduleSyncRepeatingTask(this, 10, 10); + teleTimer = ess.getPlugin().scheduleSyncRepeatingTask(this, 10, 10); } private void now(Target target, TeleportCause cause) throws Exception @@ -263,8 +259,7 @@ public class Teleport implements Runnable, ITeleport now(new Target(loc), cause); } - @Override - public void now(Entity entity, boolean cooldown, TeleportCause cause) throws Exception + public void now(Player entity, boolean cooldown, TeleportCause cause) throws Exception { if (cooldown) { @@ -279,7 +274,7 @@ public class Teleport implements Runnable, ITeleport user.acquireReadLock(); try { - teleport(new Target(user.getData().getLastLocation().getBukkitLocation()), chargeFor, TeleportCause.COMMAND); + teleport(new Target(user.getData().getLastLocation().getStoredLocation()), chargeFor, TeleportCause.COMMAND); } finally { @@ -293,7 +288,7 @@ public class Teleport implements Runnable, ITeleport user.acquireReadLock(); try { - now(new Target(user.getData().getLastLocation().getBukkitLocation()), TeleportCause.COMMAND); + now(new Target(user.getData().getLastLocation().getStoredLocation()), TeleportCause.COMMAND); } finally { diff --git a/Essentials/src/net/ess3/Warps.java b/Essentials/src/net/ess3/Warps.java index feca7fe49..08398b8e1 100644 --- a/Essentials/src/net/ess3/Warps.java +++ b/Essentials/src/net/ess3/Warps.java @@ -1,24 +1,20 @@ package net.ess3; -import java.io.File; -import java.util.*; -import java.util.logging.Logger; import static net.ess3.I18n._; import net.ess3.api.IEssentials; import net.ess3.api.IWarp; import net.ess3.api.IWarps; import net.ess3.api.InvalidNameException; +import net.ess3.api.server.Location; import net.ess3.commands.WarpNotFoundException; import net.ess3.settings.WarpHolder; import net.ess3.storage.StorageObjectMap; -import org.bukkit.Bukkit; -import org.bukkit.Location; +import java.io.File; +import java.util.*; public class Warps extends StorageObjectMap<IWarp> implements IWarps { - private static final Logger logger = Bukkit.getLogger(); - public Warps(IEssentials ess) { super(ess, "warps"); @@ -66,7 +62,7 @@ public class Warps extends StorageObjectMap<IWarp> implements IWarps warp.acquireReadLock(); try { - return warp.getData().getLocation().getBukkitLocation(); + return warp.getData().getLocation().getStoredLocation(); } finally { @@ -77,10 +73,10 @@ public class Warps extends StorageObjectMap<IWarp> implements IWarps @Override public void setWarp(final String name, final Location loc) throws Exception { - setWarp(name, new net.ess3.storage.Location(loc)); + setWarp(name, new net.ess3.storage.StoredLocation(loc)); } - public void setWarp(final String name, final net.ess3.storage.Location loc) throws Exception + public void setWarp(final String name, final net.ess3.storage.StoredLocation loc) throws Exception { IWarp warp = getObject(name); if (warp == null) diff --git a/Essentials/src/net/ess3/api/Economy.java b/Essentials/src/net/ess3/api/Economy.java new file mode 100644 index 000000000..b16db0556 --- /dev/null +++ b/Essentials/src/net/ess3/api/Economy.java @@ -0,0 +1,231 @@ +package net.ess3.api; + +import net.ess3.utils.Util; + + +/** + * Instead of using this api directly, we recommend to use the register plugin: + * http://bit.ly/RegisterMethod + */ +public final class Economy +{ + private Economy() + { + } + private static IEssentials ess; + private static final String noCallBeforeLoad = "Essentials API is called before Essentials is loaded."; + + /** + * Returns the balance of a user + * @param name Name of the user + * @return balance + * @throws UserDoesNotExistException + */ + public static double getMoney(String name) throws UserDoesNotExistException + { + if (ess == null) + { + throw new RuntimeException(noCallBeforeLoad); + } + return ess.getEconomy().getMoney(name); + } + + /** + * Sets the balance of a user + * @param name Name of the user + * @param balance The balance you want to set + * @throws UserDoesNotExistException If a user by that name does not exists + * @throws NoLoanPermittedException If the user is not allowed to have a negative balance + */ + public static void setMoney(String name, double balance) throws UserDoesNotExistException, NoLoanPermittedException + { + if (ess == null) + { + throw new RuntimeException(noCallBeforeLoad); + } + ess.getEconomy().setMoney(name, balance); + } + + /** + * Adds money to the balance of a user + * @param name Name of the user + * @param amount The money you want to add + * @throws UserDoesNotExistException If a user by that name does not exists + * @throws NoLoanPermittedException If the user is not allowed to have a negative balance + */ + public static void add(String name, double amount) throws UserDoesNotExistException, NoLoanPermittedException + { + double result = getMoney(name) + amount; + setMoney(name, result); + } + + /** + * Substracts money from the balance of a user + * @param name Name of the user + * @param amount The money you want to substract + * @throws UserDoesNotExistException If a user by that name does not exists + * @throws NoLoanPermittedException If the user is not allowed to have a negative balance + */ + public static void subtract(String name, double amount) throws UserDoesNotExistException, NoLoanPermittedException + { + double result = getMoney(name) - amount; + setMoney(name, result); + } + + /** + * Divides the balance of a user by a value + * @param name Name of the user + * @param value The balance is divided by this value + * @throws UserDoesNotExistException If a user by that name does not exists + * @throws NoLoanPermittedException If the user is not allowed to have a negative balance + */ + public static void divide(String name, double value) throws UserDoesNotExistException, NoLoanPermittedException + { + double result = getMoney(name) / value; + setMoney(name, result); + } + + /** + * Multiplies the balance of a user by a value + * @param name Name of the user + * @param value The balance is multiplied by this value + * @throws UserDoesNotExistException If a user by that name does not exists + * @throws NoLoanPermittedException If the user is not allowed to have a negative balance + */ + public static void multiply(String name, double value) throws UserDoesNotExistException, NoLoanPermittedException + { + double result = getMoney(name) * value; + setMoney(name, result); + } + + /** + * Resets the balance of a user to the starting balance + * @param name Name of the user + * @throws UserDoesNotExistException If a user by that name does not exists + * @throws NoLoanPermittedException If the user is not allowed to have a negative balance + */ + public static void resetBalance(String name) throws UserDoesNotExistException, NoLoanPermittedException + { + if (ess == null) + { + throw new RuntimeException(noCallBeforeLoad); + } + ess.getEconomy().resetBalance(name); + } + + /** + * @param name Name of the user + * @param amount The amount of money the user should have + * @return true, if the user has more or an equal amount of money + * @throws UserDoesNotExistException If a user by that name does not exists + */ + public static boolean hasEnough(String name, double amount) throws UserDoesNotExistException + { + return amount <= getMoney(name); + } + + /** + * @param name Name of the user + * @param amount The amount of money the user should have + * @return true, if the user has more money + * @throws UserDoesNotExistException If a user by that name does not exists + */ + public static boolean hasMore(String name, double amount) throws UserDoesNotExistException + { + return amount < getMoney(name); + } + + /** + * @param name Name of the user + * @param amount The amount of money the user should not have + * @return true, if the user has less money + * @throws UserDoesNotExistException If a user by that name does not exists + */ + public static boolean hasLess(String name, double amount) throws UserDoesNotExistException + { + return amount > getMoney(name); + } + + /** + * Test if the user has a negative balance + * @param name Name of the user + * @return true, if the user has a negative balance + * @throws UserDoesNotExistException If a user by that name does not exists + */ + public static boolean isNegative(String name) throws UserDoesNotExistException + { + return getMoney(name) < 0.0; + } + + /** + * Formats the amount of money like all other Essentials functions. + * Example: $100000 or $12345.67 + * @param amount The amount of money + * @return Formatted money + */ + public static String format(double amount) + { + if (ess == null) + { + throw new RuntimeException(noCallBeforeLoad); + } + return Util.displayCurrency(amount, ess); + } + + /** + * Test if a player exists to avoid the UserDoesNotExistException + * @param name Name of the user + * @return true, if the user exists + */ + public static boolean playerExists(String name) + { + if (ess == null) + { + throw new RuntimeException(noCallBeforeLoad); + } + return ess.getEconomy().playerExists(name); + } + + /** + * Test if a player is a npc + * @param name Name of the player + * @return true, if it's a npc + * @throws UserDoesNotExistException + */ + public static boolean isNPC(String name) throws UserDoesNotExistException + { + if (ess == null) + { + throw new RuntimeException(noCallBeforeLoad); + } + return ess.getEconomy().isNPC(name); + } + + /** + * Creates dummy files for a npc, if there is no player yet with that name. + * @param name Name of the player + * @return true, if a new npc was created + */ + public static boolean createNPC(String name) + { + if (ess == null) + { + throw new RuntimeException(noCallBeforeLoad); + } + return ess.getEconomy().createNPC(name); + } + + /** + * Deletes a user, if it is marked as npc. + * @param name Name of the player + * @throws UserDoesNotExistException + */ + public static void removeNPC(String name) throws UserDoesNotExistException + { + if (ess == null) + { + throw new RuntimeException(noCallBeforeLoad); + } + ess.getEconomy().removeNPC(name); + } +} diff --git a/Essentials/src/net/ess3/api/ICommandHandler.java b/Essentials/src/net/ess3/api/ICommandHandler.java index 33093d4bd..be7a9e6c4 100644 --- a/Essentials/src/net/ess3/api/ICommandHandler.java +++ b/Essentials/src/net/ess3/api/ICommandHandler.java @@ -1,8 +1,8 @@ package net.ess3.api; +import net.ess3.api.server.CommandSender; import java.util.Map; import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; import org.bukkit.plugin.Plugin; diff --git a/Essentials/src/net/ess3/api/IComponent.java b/Essentials/src/net/ess3/api/IComponent.java new file mode 100644 index 000000000..a25a19f81 --- /dev/null +++ b/Essentials/src/net/ess3/api/IComponent.java @@ -0,0 +1,13 @@ +package net.ess3.api; + +public interface IComponent extends IReload { + /** + * Enable the component. + */ + void onEnable(); + + /** + * Disable the component. + */ + void onDisable(); +} diff --git a/Essentials/src/net/ess3/api/IEssentials.java b/Essentials/src/net/ess3/api/IEssentials.java index bc9ccfb6e..c6cdc8739 100644 --- a/Essentials/src/net/ess3/api/IEssentials.java +++ b/Essentials/src/net/ess3/api/IEssentials.java @@ -1,24 +1,22 @@ package net.ess3.api; +import net.ess3.api.server.IPlugin; +import net.ess3.api.server.IServer; +import net.ess3.api.server.World; +import net.ess3.economy.register.Methods; +import net.ess3.listener.TntExplodeListener; +import java.util.logging.Logger; import java.util.List; import net.ess3.EssentialsTimer; import net.ess3.economy.register.Methods; import net.ess3.listener.TntExplodeListener; import net.ess3.metrics.Metrics; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; -public interface IEssentials extends Plugin +public interface IEssentials extends IComponent { void addReloadListener(IReload listener); - //IUser getUser(final Object base); - IUser getUser(final Player player); - - IUser getUser(final String playerName); - int broadcastMessage(IUser sender, String message); II18n getI18n(); @@ -47,17 +45,12 @@ public interface IEssentials extends Plugin Methods getPaymentMethod(); - int scheduleAsyncDelayedTask(Runnable run); - - int scheduleSyncDelayedTask(Runnable run); - - int scheduleSyncDelayedTask(Runnable run, long delay); - - int scheduleSyncRepeatingTask(Runnable run, long delay, long period); - + //int scheduleAsyncDelayedTask(Runnable run); + //int scheduleSyncDelayedTask(Runnable run); + //int scheduleSyncDelayedTask(Runnable run, long delay); + //int scheduleSyncRepeatingTask(Runnable run, long delay, long period); //IPermissionsHandler getPermissionsHandler(); - void reload(); - + //void reload(); TntExplodeListener getTNTListener(); void setRanks(IRanks groups); @@ -65,6 +58,12 @@ public interface IEssentials extends Plugin void removeReloadListener(IReload groups); IEconomy getEconomy(); + + IServer getServer(); + + Logger getLogger(); + + IPlugin getPlugin(); List<String> getVanishedPlayers(); diff --git a/Essentials/src/net/ess3/api/IItemDb.java b/Essentials/src/net/ess3/api/IItemDb.java index 8a20c85a1..fa9e1d868 100644 --- a/Essentials/src/net/ess3/api/IItemDb.java +++ b/Essentials/src/net/ess3/api/IItemDb.java @@ -1,6 +1,6 @@ package net.ess3.api; -import org.bukkit.inventory.ItemStack; +import net.ess3.api.server.ItemStack; public interface IItemDb extends IReload diff --git a/Essentials/src/net/ess3/api/IReplyTo.java b/Essentials/src/net/ess3/api/IReplyTo.java index b1393d22f..6e96166bb 100644 --- a/Essentials/src/net/ess3/api/IReplyTo.java +++ b/Essentials/src/net/ess3/api/IReplyTo.java @@ -1,6 +1,6 @@ package net.ess3.api; -import org.bukkit.command.CommandSender; +import net.ess3.api.server.CommandSender; public interface IReplyTo diff --git a/Essentials/src/net/ess3/api/IUser.java b/Essentials/src/net/ess3/api/IUser.java index 4a15050d5..257c971cb 100644 --- a/Essentials/src/net/ess3/api/IUser.java +++ b/Essentials/src/net/ess3/api/IUser.java @@ -1,13 +1,13 @@ package net.ess3.api; -import java.util.List; +import net.ess3.api.server.CommandSender; +import net.ess3.api.server.Player; +import net.ess3.api.server.ItemStack; +import net.ess3.api.server.Location; import net.ess3.storage.IStorageObjectHolder; import net.ess3.user.CooldownException; import net.ess3.user.UserData; -import org.bukkit.Location; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; +import java.util.List; public interface IUser extends Player, IStorageObjectHolder<UserData>, IReload, IReplyTo, Comparable<IUser> diff --git a/Essentials/src/net/ess3/api/IUserMap.java b/Essentials/src/net/ess3/api/IUserMap.java index 1184bd1c5..887791f7b 100644 --- a/Essentials/src/net/ess3/api/IUserMap.java +++ b/Essentials/src/net/ess3/api/IUserMap.java @@ -1,8 +1,9 @@ package net.ess3.api; +import net.ess3.api.server.Player; +import net.ess3.user.TooManyMatchesException; import java.io.File; import java.util.Set; -import org.bukkit.entity.Player; public interface IUserMap extends IReload @@ -20,4 +21,8 @@ public interface IUserMap extends IReload int getUniqueUsers(); File getUserFile(final String name) throws InvalidNameException; + + IUser matchUser(final String name, final boolean includeHidden, final boolean onlineOnly) throws TooManyMatchesException; + + Set<IUser> matchUsers(final String name, final boolean includeHidden, final boolean onlineOnly); } diff --git a/Essentials/src/net/ess3/api/IWarps.java b/Essentials/src/net/ess3/api/IWarps.java index 908994486..00939ff7e 100644 --- a/Essentials/src/net/ess3/api/IWarps.java +++ b/Essentials/src/net/ess3/api/IWarps.java @@ -1,8 +1,8 @@ package net.ess3.api; +import net.ess3.api.server.Location; import java.io.File; import java.util.Collection; -import org.bukkit.Location; public interface IWarps extends IReload diff --git a/Essentials/src/net/ess3/api/IWorth.java b/Essentials/src/net/ess3/api/IWorth.java index ffc38a203..770170c31 100644 --- a/Essentials/src/net/ess3/api/IWorth.java +++ b/Essentials/src/net/ess3/api/IWorth.java @@ -1,6 +1,7 @@ package net.ess3.api; -import org.bukkit.inventory.ItemStack; +import net.ess3.api.server.ItemStack; + public interface IWorth extends IReload diff --git a/Essentials/src/net/ess3/api/server/CommandSender.java b/Essentials/src/net/ess3/api/server/CommandSender.java new file mode 100644 index 000000000..768dde9bb --- /dev/null +++ b/Essentials/src/net/ess3/api/server/CommandSender.java @@ -0,0 +1,13 @@ +package net.ess3.api.server; + +public interface CommandSender { + boolean isPlayer(); + + void sendMessage(String message); + + boolean isOp(); + + boolean hasPermission(Permission bukkitPermission); + + void sendMessage(String[] string); +} diff --git a/Essentials/src/net/ess3/api/server/Enchantment.java b/Essentials/src/net/ess3/api/server/Enchantment.java new file mode 100644 index 000000000..3e7baa0cf --- /dev/null +++ b/Essentials/src/net/ess3/api/server/Enchantment.java @@ -0,0 +1,7 @@ +package net.ess3.api.server; + +public abstract class Enchantment { + + public abstract int getMaxLevel(); + +} diff --git a/Essentials/src/net/ess3/api/server/IInventory.java b/Essentials/src/net/ess3/api/server/IInventory.java new file mode 100644 index 000000000..783495864 --- /dev/null +++ b/Essentials/src/net/ess3/api/server/IInventory.java @@ -0,0 +1,19 @@ +package net.ess3.api.server; + +import java.util.Map; + +public interface IInventory { + + public boolean containsItem(boolean b, boolean b0, ItemStack itemStack); + + public Map<Integer, ItemStack> addItem(ItemStack itemStack); + + public Map<Integer, ItemStack> addItem(boolean b, ItemStack itemStack); + + public Map<Integer, ItemStack> addItem(boolean b, int oversizedStacksize, ItemStack itemStack); + + public boolean addAllItems(boolean b, ItemStack itemStack); + + public void removeItem(boolean b, boolean b0, ItemStack itemStack); + +} diff --git a/Essentials/src/net/ess3/api/server/IPermissionsManager.java b/Essentials/src/net/ess3/api/server/IPermissionsManager.java deleted file mode 100644 index d422868b4..000000000 --- a/Essentials/src/net/ess3/api/server/IPermissionsManager.java +++ /dev/null @@ -1,8 +0,0 @@ -package net.ess3.api.server; - -public interface IPermissionsManager { - - IPermission registerPermission(); - - boolean checkPermission(IPlayer player, IPermission perm); -} diff --git a/Essentials/src/net/ess3/api/server/IPlugin.java b/Essentials/src/net/ess3/api/server/IPlugin.java new file mode 100644 index 000000000..d1f8719f1 --- /dev/null +++ b/Essentials/src/net/ess3/api/server/IPlugin.java @@ -0,0 +1,32 @@ +package net.ess3.api.server; + +import java.io.File; +import java.io.InputStream; + + +public interface IPlugin +{ + int scheduleAsyncDelayedTask(final Runnable run); + + int scheduleSyncDelayedTask(final Runnable run); + + int scheduleSyncDelayedTask(final Runnable run, final long delay); + + int scheduleSyncRepeatingTask(final Runnable run, final long delay, final long period); + + File getRootFolder(); + + File getDataFolder(); + + void cancelTask(int taskId); + + String getVersion(); + + Class getClassByName(String name); + + InputStream getResource(String string); + + Location callRespawnEvent(Player player, Location loc, boolean bedSpawn); + + void callSuicideEvent(Player player); +} diff --git a/Essentials/src/net/ess3/api/server/IServer.java b/Essentials/src/net/ess3/api/server/IServer.java index efb5d1415..8bd23bb9d 100644 --- a/Essentials/src/net/ess3/api/server/IServer.java +++ b/Essentials/src/net/ess3/api/server/IServer.java @@ -1,5 +1,28 @@ package net.ess3.api.server; -public interface IServer { +import java.util.Collection; +import java.util.List; + +public interface IServer +{ + List<World> getWorlds(); + + World getWorld(String name); + + int broadcastMessage(String message); + + Collection<Player> getOnlinePlayers(); + + CommandSender getConsoleSender(); + + void dispatchCommand(CommandSender sender, String command); + + void banIP(String ip); + + <T> T getServiceProvider(Class<T> clazz); + + String getVersion(); + + public void unbanIP(String string); } diff --git a/Essentials/src/net/ess3/api/server/ItemStack.java b/Essentials/src/net/ess3/api/server/ItemStack.java new file mode 100644 index 000000000..d8315974c --- /dev/null +++ b/Essentials/src/net/ess3/api/server/ItemStack.java @@ -0,0 +1,47 @@ +package net.ess3.api.server; + + +public abstract class ItemStack implements Cloneable +{ + public interface ItemStackFactory + { + ItemStack create(int id, int amount, int data); + ItemStack clone(ItemStack stack); + } + private static ItemStackFactory factory; + + public static void setFactory(final ItemStackFactory factory) + { + ItemStack.factory = factory; + } + + public static ItemStack create(int id, int amount, int data) + { + return factory.create(id, amount, data); + } + + public static ItemStack create(Material mat, int amount, int data) + { + return factory.create(mat.getId(), amount, data); + } + + public abstract Material getType(); + + public abstract int getAmount(); + + public abstract void setAmount(int value); + + public abstract short getDurability(); + + public abstract int getMaxStackSize(); + + public abstract boolean isAir(); + + public abstract void addEnchantment(Enchantment enchantment, int level); + + @Override + public ItemStack clone() + { + return factory.clone(this); + } +} diff --git a/Essentials/src/net/ess3/api/server/Location.java b/Essentials/src/net/ess3/api/server/Location.java new file mode 100644 index 000000000..825e2f814 --- /dev/null +++ b/Essentials/src/net/ess3/api/server/Location.java @@ -0,0 +1,52 @@ +package net.ess3.api.server; + + +public abstract class Location +{ + public interface LocationFactory { + Location create(String worldName, double x, double y, double z, double yaw, double pitch); + Location create(World world, double x, double y, double z, double yaw, double pitch); + } + private static LocationFactory factory; + + public static void setFactory(final LocationFactory factory) { + Location.factory = factory; + } + + public static Location create(String worldName, double x, double y, double z) { + return factory.create(worldName, x, y, z, 0, 0); + } + + public static Location create(String worldName, double x, double y, double z, double yaw, double pitch) { + return factory.create(worldName, x, y, z, yaw, pitch); + } + + public static Location create(World world, double x, double y, double z) { + return factory.create(world, x, y, z, 0, 0); + } + + public static Location create(World world, double x, double y, double z, double yaw, double pitch) { + return factory.create(world, x, y, z, yaw, pitch); + } + + + public abstract double getX(); + + public abstract double getY(); + + public abstract double getZ(); + + public abstract float getYaw(); + + public abstract float getPitch(); + + public abstract int getBlockX(); + + public abstract int getBlockY(); + + public abstract int getBlockZ(); + + public abstract World getWorld(); + + public abstract double distanceSquared(Location location); +} diff --git a/Essentials/src/net/ess3/api/server/Material.java b/Essentials/src/net/ess3/api/server/Material.java new file mode 100644 index 000000000..bfda30775 --- /dev/null +++ b/Essentials/src/net/ess3/api/server/Material.java @@ -0,0 +1,37 @@ +package net.ess3.api.server; + +public abstract class Material { + + private static Material instance; + + public static void setInstance(final Material instance) { + Material.instance = instance; + } + + public static Material get(final int id) { + return instance.getMaterialById(id); + } + + public static Material get(final String name) { + return instance.getMaterialByName(name); + } + + public static Material match(String string) + { + return instance.matchMaterial(string); + } + + protected abstract Material getMaterialByName(String name); + + protected abstract Material getMaterialById(int id); + + public abstract int getId(); + + public abstract String getName(); + + public abstract int getMaxStackSize(); + + public abstract int getMaxDurability(); + + protected abstract Material matchMaterial(String string); +} diff --git a/Essentials/src/net/ess3/api/server/Permission.java b/Essentials/src/net/ess3/api/server/Permission.java new file mode 100644 index 000000000..f4fb37cc4 --- /dev/null +++ b/Essentials/src/net/ess3/api/server/Permission.java @@ -0,0 +1,27 @@ +package net.ess3.api.server; + + +public abstract class Permission +{ + public enum Default + { + TRUE, FALSE, OP, NOT_OP; + } + + + public interface PermissionFactory + { + Permission create(String name, Permission.Default defaultPermission); + } + private static PermissionFactory factory; + + public static void setFactory(final PermissionFactory factory) + { + Permission.factory = factory; + } + + public static Permission create(final String name, Permission.Default defaultPermission) + { + return factory.create(name, defaultPermission); + } +} diff --git a/Essentials/src/net/ess3/api/server/Player.java b/Essentials/src/net/ess3/api/server/Player.java new file mode 100644 index 000000000..152c3f0c8 --- /dev/null +++ b/Essentials/src/net/ess3/api/server/Player.java @@ -0,0 +1,61 @@ +package net.ess3.api.server; + +import net.ess3.api.IUser; + + +public interface Player extends CommandSender +{ + IUser getUser(); + + String getName(); + + String getDisplayName(); + + boolean isOnline(); + + void setBanned(boolean bool); + + void kickPlayer(String reason); + + World getWorld(); + + Location getLocation(); + + Location getEyeLocation(); + + void setFireTicks(int value); + + void setFoodLevel(int value); + + void setSaturation(float value); + + int getHealth(); + + void setHealth(int value); + + void updateInventory(); + + ItemStack getItemInHand(); + + Location getBedSpawnLocation(); + + boolean hasPlayedBefore(); + + IInventory getInventory(); + + void setTotalExperience(final int exp); + + int getTotalExperience(); + + void setDisplayName(String name); + + void setPlayerListName(String name); + + void setSleepingIgnored(boolean b); + + boolean isBanned(); + + void setCompassTarget(Location loc); + + void damage(int value); +} diff --git a/Essentials/src/net/ess3/api/server/World.java b/Essentials/src/net/ess3/api/server/World.java new file mode 100644 index 000000000..ecd129609 --- /dev/null +++ b/Essentials/src/net/ess3/api/server/World.java @@ -0,0 +1,26 @@ +package net.ess3.api.server; + +import java.util.UUID; +import org.bukkit.TreeType; + +public interface World { + String getName(); + + boolean generateTree(Location safeLocation, TreeType tree); + + int getHighestBlockYAt(int topX, int topZ); + + ItemStack dropItem(Location loc, ItemStack stack); + + UUID getUID(); + + Location getSpawnLocation(); + + void dropItemNaturally(Location location, ItemStack overflowStack); + + void setStorm(boolean b); + + void setWeatherDuration(int i); + + long getTime(); +} diff --git a/Essentials/src/net/ess3/backup/Backup.java b/Essentials/src/net/ess3/backup/Backup.java index 17301ed92..3aea269e4 100644 --- a/Essentials/src/net/ess3/backup/Backup.java +++ b/Essentials/src/net/ess3/backup/Backup.java @@ -1,25 +1,22 @@ package net.ess3.backup; +import static net.ess3.I18n._; +import net.ess3.api.IBackup; +import net.ess3.api.IEssentials; +import net.ess3.api.ISettings; +import net.ess3.api.server.CommandSender; +import net.ess3.api.server.IServer; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Level; -import java.util.logging.Logger; import lombok.Cleanup; -import static net.ess3.I18n._; -import net.ess3.api.IBackup; -import net.ess3.api.IEssentials; -import net.ess3.api.ISettings; -import org.bukkit.Bukkit; -import org.bukkit.Server; -import org.bukkit.command.CommandSender; public class Backup implements Runnable, IBackup { - private static final Logger LOGGER = Bukkit.getLogger(); - private transient final Server server; + private transient final IServer server; private transient final IEssentials ess; private transient final AtomicBoolean running = new AtomicBoolean(false); private transient int taskId = -1; @@ -29,7 +26,7 @@ public class Backup implements Runnable, IBackup { this.ess = ess; server = ess.getServer(); - if (server.getOnlinePlayers().length > 0) + if (!server.getOnlinePlayers().isEmpty()) { startTask(); } @@ -49,7 +46,7 @@ public class Backup implements Runnable, IBackup running.set(false); return; } - taskId = ess.scheduleSyncRepeatingTask(this, interval, interval); + taskId = ess.getPlugin().scheduleSyncRepeatingTask(this, interval, interval); } } @@ -68,12 +65,12 @@ public class Backup implements Runnable, IBackup { return; } - LOGGER.log(Level.INFO, _("backupStarted")); + ess.getLogger().log(Level.INFO, _("backupStarted")); final CommandSender consoleSender = server.getConsoleSender(); server.dispatchCommand(consoleSender, "save-all"); server.dispatchCommand(consoleSender, "save-off"); - ess.scheduleAsyncDelayedTask(new BackupRunner(command)); + ess.getPlugin().scheduleAsyncDelayedTask(new BackupRunner(command)); } @@ -93,7 +90,7 @@ public class Backup implements Runnable, IBackup { final ProcessBuilder childBuilder = new ProcessBuilder(command); childBuilder.redirectErrorStream(true); - childBuilder.directory(ess.getDataFolder().getParentFile().getParentFile()); + childBuilder.directory(ess.getPlugin().getRootFolder()); final Process child = childBuilder.start(); final BufferedReader reader = new BufferedReader(new InputStreamReader(child.getInputStream())); try @@ -105,7 +102,7 @@ public class Backup implements Runnable, IBackup line = reader.readLine(); if (line != null) { - LOGGER.log(Level.INFO, line); + ess.getLogger().log(Level.INFO, line); } } while (line != null); @@ -117,15 +114,15 @@ public class Backup implements Runnable, IBackup } catch (InterruptedException ex) { - LOGGER.log(Level.SEVERE, null, ex); + ess.getLogger().log(Level.SEVERE, null, ex); } catch (IOException ex) { - LOGGER.log(Level.SEVERE, null, ex); + ess.getLogger().log(Level.SEVERE, null, ex); } finally { - ess.scheduleSyncDelayedTask(new EnableSavingRunner()); + ess.getPlugin().scheduleSyncDelayedTask(new EnableSavingRunner()); } } } @@ -137,17 +134,17 @@ public class Backup implements Runnable, IBackup public void run() { server.dispatchCommand(server.getConsoleSender(), "save-on"); - if (server.getOnlinePlayers().length == 0) + if (server.getOnlinePlayers().isEmpty()) { running.set(false); if (taskId != -1) { - server.getScheduler().cancelTask(taskId); + ess.getPlugin().cancelTask(taskId); } } active.set(false); - LOGGER.log(Level.INFO, _("backupFinished")); + ess.getLogger().log(Level.INFO, _("backupFinished")); } } } diff --git a/Essentials/src/net/ess3/bukkit/BukkitCommandSender.java b/Essentials/src/net/ess3/bukkit/BukkitCommandSender.java new file mode 100644 index 000000000..60302badc --- /dev/null +++ b/Essentials/src/net/ess3/bukkit/BukkitCommandSender.java @@ -0,0 +1,40 @@ +package net.ess3.bukkit; + +import net.ess3.api.server.CommandSender; +import net.ess3.api.server.Permission; +import lombok.Delegate; +import lombok.Getter; + + +public class BukkitCommandSender implements CommandSender +{ + @Delegate + @Getter + private org.bukkit.command.CommandSender commandSender; + + public BukkitCommandSender(org.bukkit.command.CommandSender commandSender) + { + this.commandSender = commandSender; + } + + @Override + public boolean isPlayer() + { + return false; + } + + @Override + public boolean isOp() + { + return commandSender.isOp(); + } + + public boolean hasPermission(Permission permission) + { + if (commandSender == null) { + return false; + } else { + return commandSender.hasPermission(((BukkitPermission)permission).getBukkitPermission()); + } + } +} diff --git a/Essentials/src/net/ess3/bukkit/BukkitItemStack.java b/Essentials/src/net/ess3/bukkit/BukkitItemStack.java new file mode 100644 index 000000000..819cc734b --- /dev/null +++ b/Essentials/src/net/ess3/bukkit/BukkitItemStack.java @@ -0,0 +1,62 @@ +package net.ess3.bukkit; + +import net.ess3.api.server.Enchantment; +import net.ess3.api.server.ItemStack; +import net.ess3.api.server.Material; +import lombok.Delegate; +import lombok.Getter; + + +public class BukkitItemStack extends net.ess3.api.server.ItemStack +{ + public static class BukkitItemStackFactory implements ItemStackFactory + { + @Override + public ItemStack create(int id, int amount, int data) + { + return new BukkitItemStack(new org.bukkit.inventory.ItemStack(id, amount, (short)data)); + } + + @Override + public ItemStack clone(final ItemStack stack) + { + return new BukkitItemStack(((BukkitItemStack)stack).getItemStack().clone()); + } + } + + + private interface Excludes + { + org.bukkit.Material getType(); + } + @Delegate(excludes = + { + Excludes.class + }) + @Getter + private final org.bukkit.inventory.ItemStack itemStack; + + public BukkitItemStack(final org.bukkit.inventory.ItemStack itemStack) + { + super(); + this.itemStack = itemStack; + } + + @Override + public void addEnchantment(Enchantment enchantment, int level) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Material getType() + { + return Material.get(itemStack.getTypeId()); + } + + @Override + public boolean isAir() + { + return itemStack.getTypeId() == 0; + } +} diff --git a/Essentials/src/net/ess3/bukkit/BukkitLocation.java b/Essentials/src/net/ess3/bukkit/BukkitLocation.java new file mode 100644 index 000000000..21021873c --- /dev/null +++ b/Essentials/src/net/ess3/bukkit/BukkitLocation.java @@ -0,0 +1,63 @@ +package net.ess3.bukkit; + +import net.ess3.api.server.World; +import net.ess3.api.server.Location; +import lombok.Delegate; +import lombok.Getter; + + +public class BukkitLocation extends Location +{ + public static class BukkitLocationFactory implements LocationFactory + { + private final org.bukkit.Server server; + + public BukkitLocationFactory(org.bukkit.Server server) + { + this.server = server; + } + + @Override + public Location create(String worldName, double x, double y, double z, double yaw, double pitch) + { + org.bukkit.World world = server.getWorld(worldName); + return new BukkitLocation(new org.bukkit.Location(world, x, y, z, (float)yaw, (float)pitch)); + } + + @Override + public Location create(World world, double x, double y, double z, double yaw, double pitch) + { + return new BukkitLocation(new org.bukkit.Location(((BukkitWorld)world).getBukkitWorld(), x, y, z, (float)yaw, (float)pitch)); + } + } + + + private interface Excludes + { + org.bukkit.World getWorld(); + } + @Delegate(excludes = + { + Excludes.class + }) + @Getter + private final org.bukkit.Location bukkitLocation; + + public BukkitLocation(org.bukkit.Location bukkitLocation) + { + this.bukkitLocation = bukkitLocation; + } + + @Override + public World getWorld() + { + return new BukkitWorld(bukkitLocation.getWorld()); + } + + @Override + public double distanceSquared(final Location location) + { + return bukkitLocation.distanceSquared(((BukkitLocation)location).getBukkitLocation()); + } + +} diff --git a/Essentials/src/net/ess3/bukkit/BukkitMaterial.java b/Essentials/src/net/ess3/bukkit/BukkitMaterial.java new file mode 100644 index 000000000..b01d68754 --- /dev/null +++ b/Essentials/src/net/ess3/bukkit/BukkitMaterial.java @@ -0,0 +1,62 @@ +package net.ess3.bukkit; + +import net.ess3.api.server.Material; +import java.util.EnumMap; +import lombok.Delegate; + + +public class BukkitMaterial extends Material +{ + private static EnumMap<org.bukkit.Material, BukkitMaterial> materials = new EnumMap<org.bukkit.Material, BukkitMaterial>(org.bukkit.Material.class); + + static + { + for (org.bukkit.Material material : org.bukkit.Material.values()) + { + materials.put(material, new BukkitMaterial(material)); + } + } + private interface Excludes { + short getMaxDurability(); + } + @Delegate(excludes={Excludes.class}) + private final org.bukkit.Material material; + + private BukkitMaterial(final org.bukkit.Material material) + { + this.material = material; + } + + @Override + protected Material getMaterialByName(final String name) + { + final org.bukkit.Material mat = org.bukkit.Material.getMaterial(name); + return materials.get(mat); + } + + @Override + protected Material getMaterialById(final int id) + { + final org.bukkit.Material mat = org.bukkit.Material.getMaterial(id); + return materials.get(mat); + } + + @Override + protected Material matchMaterial(String string) + { + final org.bukkit.Material mat = org.bukkit.Material.matchMaterial(string); + return materials.get(mat); + } + + @Override + public String getName() + { + return this.material.toString(); + } + + @Override + public int getMaxDurability() + { + return (short)this.material.getMaxDurability(); + } +} diff --git a/Essentials/src/net/ess3/bukkit/BukkitPermission.java b/Essentials/src/net/ess3/bukkit/BukkitPermission.java new file mode 100644 index 000000000..49f705ccc --- /dev/null +++ b/Essentials/src/net/ess3/bukkit/BukkitPermission.java @@ -0,0 +1,82 @@ +package net.ess3.bukkit; + +import net.ess3.api.server.Permission; +import java.util.regex.Pattern; +import lombok.Delegate; +import lombok.Getter; +import org.bukkit.Bukkit; +import org.bukkit.permissions.PermissionDefault; +import org.bukkit.plugin.PluginManager; + + +public class BukkitPermission extends Permission +{ + public static class BukkitPermissionFactory implements PermissionFactory + { + private static transient final Pattern DOT_PATTERN = Pattern.compile("\\."); + + @Override + public Permission create(String permission, Permission.Default defaultPerm) + { + final PluginManager pluginManager = Bukkit.getServer().getPluginManager(); + final String[] parts = DOT_PATTERN.split(permission); + final StringBuilder builder = new StringBuilder(permission.length()); + org.bukkit.permissions.Permission parent = null; + for (int i = 0; i < parts.length - 1; i++) + { + builder.append(parts[i]).append(".*"); + String permString = builder.toString(); + org.bukkit.permissions.Permission perm = pluginManager.getPermission(permString); + if (perm == null) + { + perm = new org.bukkit.permissions.Permission(permString, PermissionDefault.FALSE); + pluginManager.addPermission(perm); + if (parent != null) + { + parent.getChildren().put(perm.getName(), Boolean.TRUE); + } + parent = perm; + } + builder.deleteCharAt(builder.length() - 1); + } + org.bukkit.permissions.Permission perm = pluginManager.getPermission(permission); + if (perm == null) + { + perm = new org.bukkit.permissions.Permission(permission, getBukkitDefaultPermission(defaultPerm)); + pluginManager.addPermission(perm); + if (parent != null) + { + parent.getChildren().put(perm.getName(), Boolean.TRUE); + } + parent = perm; + } + perm.recalculatePermissibles(); + return new BukkitPermission(perm); + } + } + @Delegate + @Getter + private final org.bukkit.permissions.Permission bukkitPermission; + + public BukkitPermission(org.bukkit.permissions.Permission bukkitPermission) + { + this.bukkitPermission = bukkitPermission; + } + + public static PermissionDefault getBukkitDefaultPermission(final Permission.Default defaultPerm) + { + switch (defaultPerm) + { + case TRUE: + return PermissionDefault.TRUE; + case OP: + return PermissionDefault.OP; + case NOT_OP: + return PermissionDefault.NOT_OP; + case FALSE: + return PermissionDefault.FALSE; + default: + return PermissionDefault.FALSE; + } + } +} diff --git a/Essentials/src/net/ess3/bukkit/BukkitPlayer.java b/Essentials/src/net/ess3/bukkit/BukkitPlayer.java new file mode 100644 index 000000000..588ad242d --- /dev/null +++ b/Essentials/src/net/ess3/bukkit/BukkitPlayer.java @@ -0,0 +1,202 @@ +package net.ess3.bukkit; + +import net.ess3.api.IUser; +import net.ess3.api.server.*; +import lombok.Delegate; +import lombok.Getter; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.LivingEntity; + + +public class BukkitPlayer extends BukkitCommandSender implements Player +{ + private interface Excludes + { + org.bukkit.World getWorld(); + + org.bukkit.Location getLocation(); + + org.bukkit.Location getEyeLocation(); + + org.bukkit.inventory.ItemStack getItemInHand(); + + org.bukkit.Location getBedSpawnLocation(); + + org.bukkit.inventory.Inventory getInventory(); + + void setTotalExperience(int i); + + int getTotalExperience(); + } + @Delegate(types = + { + org.bukkit.entity.Player.class, LivingEntity.class + }, excludes = + { + OfflinePlayer.class, org.bukkit.command.CommandSender.class, Excludes.class + }) + @Getter + private transient org.bukkit.entity.Player onlinePlayer; + /** + * a set of data and methods common to both offline and online players. + */ + @Delegate(excludes = + { + Excludes.class + }) + @Getter + private transient OfflinePlayer safePlayer; + private final transient IServer server; + + public BukkitPlayer(final OfflinePlayer player, final IServer server) + { + super(player.getPlayer()); + this.server = server; + if (player.isOnline()) + { + + setOnlinePlayer(player.getPlayer()); + } + else + { + setOfflinePlayer(player); + } + } + + public final void setOfflinePlayer(final OfflinePlayer offlinePlayer) + { + safePlayer = offlinePlayer; + onlinePlayer = null; + } + + public final void setOnlinePlayer(final org.bukkit.entity.Player onlinePlayer) + { + safePlayer = this.onlinePlayer = onlinePlayer; + } + + public String getSafeDisplayName() + { + return onlinePlayer == null ? getName() : getDisplayName(); + } + + @Override + public IUser getUser() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean isPlayer() + { + return true; + } + + @Override + public World getWorld() + { + return server.getWorld(onlinePlayer.getWorld().getName()); + } + + @Override + public Location getLocation() + { + return new BukkitLocation(onlinePlayer.getLocation()); + } + + @Override + public Location getEyeLocation() + { + return new BukkitLocation(onlinePlayer.getEyeLocation()); + } + + @Override + public BukkitItemStack getItemInHand() + { + return new BukkitItemStack(onlinePlayer.getItemInHand()); + } + + @Override + public Location getBedSpawnLocation() + { + return new BukkitLocation(onlinePlayer.getBedSpawnLocation()); + } + + @Override + public IInventory getInventory() + { + return new Inventory(onlinePlayer.getInventory()); + } + + @Override + public void setTotalExperience(final int exp) + { + if (exp < 0) + { + throw new IllegalArgumentException("Experience is negative!"); + } + onlinePlayer.setExp(0); + onlinePlayer.setLevel(0); + onlinePlayer.setTotalExperience(0); + int amount = exp; + while (amount > 0) + { + final int expToLevel = getExpToLevel(); + amount -= expToLevel; + if (amount >= 0) + { + // give until next level + onlinePlayer.giveExp(expToLevel); + } + else + { + // give the rest + amount += expToLevel; + onlinePlayer.giveExp(amount); + amount = 0; + } + } + } + + private int getExpToLevel() + { + return getExpToLevel(onlinePlayer.getLevel()); + } + + private static int getExpToLevel(final int level) + { + return 7 + (level * 7 >> 1); + } + + @Override + public int getTotalExperience() + { + int exp = (int) (getExpToLevel() * onlinePlayer.getExp()); + int currentLevel = onlinePlayer.getLevel(); + + while (currentLevel > 0) { + currentLevel--; + exp += getExpToLevel(currentLevel); + } + return exp; + } + + + @Override + public void sendMessage(final String message) + { + onlinePlayer.sendMessage(message); + } + + @Override + public void sendMessage(final String[] string) + { + onlinePlayer.sendMessage(string); + } + + + @Override + public void setCompassTarget(final Location loc) + { + onlinePlayer.setCompassTarget(((BukkitLocation)loc).getBukkitLocation()); + } +} diff --git a/Essentials/src/net/ess3/bukkit/BukkitWorld.java b/Essentials/src/net/ess3/bukkit/BukkitWorld.java new file mode 100644 index 000000000..d754de4c9 --- /dev/null +++ b/Essentials/src/net/ess3/bukkit/BukkitWorld.java @@ -0,0 +1,45 @@ +package net.ess3.bukkit; + +import net.ess3.api.server.World; +import net.ess3.api.server.ItemStack; +import net.ess3.api.server.Location; +import lombok.Delegate; +import lombok.Getter; +import org.bukkit.TreeType; + +public class BukkitWorld implements World { + @Delegate + @Getter + private final org.bukkit.World bukkitWorld; + + public BukkitWorld(final org.bukkit.World world) + { + this.bukkitWorld = world; + world.getT + } + + @Override + public boolean generateTree(Location safeLocation, TreeType tree) + { + return bukkitWorld.generateTree(((BukkitLocation)safeLocation).getBukkitLocation(), tree); + } + + @Override + public ItemStack dropItem(Location loc, ItemStack stack) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Location getSpawnLocation() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void dropItemNaturally(Location location, ItemStack overflowStack) + { + throw new UnsupportedOperationException("Not supported yet."); + } + +} diff --git a/Essentials/src/net/ess3/bukkit/EssentialsPlugin.java b/Essentials/src/net/ess3/bukkit/EssentialsPlugin.java index 44d821bf1..4f262f329 100644 --- a/Essentials/src/net/ess3/bukkit/EssentialsPlugin.java +++ b/Essentials/src/net/ess3/bukkit/EssentialsPlugin.java @@ -1,7 +1,95 @@ package net.ess3.bukkit; +import net.ess3.Essentials; +import static net.ess3.I18n._; +import net.ess3.api.server.*; +import java.util.logging.Level; +import org.bukkit.command.Command; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; -public class EssentialsPlugin extends JavaPlugin { - //TODO + +public class EssentialsPlugin extends JavaPlugin +{ + private transient Essentials ess; + + public EssentialsPlugin() + { + Material.setInstance(BukkitMaterial.get(0)); + ItemStack.setFactory(new BukkitItemStack.BukkitItemStackFactory()); + Location.setFactory(new BukkitLocation.BukkitLocationFactory(getServer())); + Permission.setFactory(new BukkitPermission.BukkitPermissionFactory()); + } + + @Override + public void onEnable() + { + + Server server = new Server(getServer()); + final PluginManager pm = this.getServer().getPluginManager(); + pm.registerEvents(server, this); + ess = new Essentials(server, getLogger(), new Plugin(this)); + if (VersionCheck.checkVersion(this)) + { + try + { + ess.onEnable(); + } + catch (RuntimeException ex) + { + if (pm.getPlugin("EssentialsUpdate") == null) + { + getLogger().log(Level.SEVERE, _("essentialsHelp1")); + } + else + { + getLogger().log(Level.SEVERE, _("essentialsHelp2")); + } + getLogger().log(Level.SEVERE, ex.toString()); + pm.registerEvents(new Listener() + { + @EventHandler(priority = EventPriority.LOW) + public void onPlayerJoin(final PlayerJoinEvent event) + { + event.getPlayer().sendMessage("Essentials failed to load, read the log file."); + } + }, this); + for (Player player : getServer().getOnlinePlayers()) + { + player.sendMessage("Essentials failed to load, read the log file."); + } + this.setEnabled(false); + } + } + else + { + this.setEnabled(false); + } + } + + @Override + public void onDisable() + { + if (ess != null) + { + ess.onDisable(); + } + } + + @Override + public boolean onCommand(final org.bukkit.command.CommandSender sender, final Command command, final String label, final String[] args) + { + CommandSender commandSender; + if (sender instanceof org.bukkit.entity.Player) { + commandSender = ((Server)ess.getServer()).getPlayer((org.bukkit.entity.Player)sender); + } else { + commandSender = new BukkitCommandSender(sender); + } + return ess.getCommandHandler().handleCommand(commandSender, command, label, args); + } } diff --git a/Essentials/src/net/ess3/bukkit/Inventory.java b/Essentials/src/net/ess3/bukkit/Inventory.java new file mode 100644 index 000000000..30ddaae52 --- /dev/null +++ b/Essentials/src/net/ess3/bukkit/Inventory.java @@ -0,0 +1,48 @@ +package net.ess3.bukkit; + +import net.ess3.api.server.IInventory; +import net.ess3.api.server.ItemStack; +import java.util.Map; +import lombok.Delegate; +import org.bukkit.inventory.PlayerInventory; + +public class Inventory implements IInventory { + @Delegate + private org.bukkit.inventory.PlayerInventory inventory; + + Inventory(PlayerInventory inventory) + { + this.inventory = inventory; + } + + @Override + public boolean containsItem(boolean b, boolean b0, ItemStack itemStack) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Map<Integer, ItemStack> addItem(boolean b, ItemStack itemStack) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean addAllItems(boolean b, ItemStack itemStack) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void removeItem(boolean b, boolean b0, ItemStack itemStack) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Map<Integer, ItemStack> addItem(boolean b, int oversizedStacksize, ItemStack itemStack) + { + throw new UnsupportedOperationException("Not supported yet."); + } + +} diff --git a/Essentials/src/net/ess3/bukkit/Plugin.java b/Essentials/src/net/ess3/bukkit/Plugin.java new file mode 100644 index 000000000..ea3f85366 --- /dev/null +++ b/Essentials/src/net/ess3/bukkit/Plugin.java @@ -0,0 +1,87 @@ +package net.ess3.bukkit; + +import net.ess3.api.server.Player; +import net.ess3.api.server.IPlugin; +import net.ess3.api.server.Location; +import java.io.File; +import lombok.Delegate; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.plugin.java.JavaPluginLoader; + + +public class Plugin implements IPlugin +{ + @Delegate + private final org.bukkit.plugin.Plugin plugin; + + public Plugin(final org.bukkit.plugin.Plugin plugin) + { + this.plugin = plugin; + } + + @Override + public int scheduleAsyncDelayedTask(final Runnable run) + { + return plugin.getServer().getScheduler().scheduleAsyncDelayedTask(plugin, run); + } + + @Override + public int scheduleSyncDelayedTask(final Runnable run) + { + return plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, run); + } + + @Override + public int scheduleSyncDelayedTask(final Runnable run, final long delay) + { + return plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, run, delay); + } + + @Override + public int scheduleSyncRepeatingTask(final Runnable run, final long delay, final long period) + { + return plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, run, delay, period); + } + + @Override + public File getRootFolder() + { + return plugin.getDataFolder().getParentFile().getParentFile(); + } + + @Override + public void cancelTask(final int taskId) + { + plugin.getServer().getScheduler().cancelTask(taskId); + } + + @Override + public String getVersion() + { + return plugin.getDescription().getVersion(); + } + + @Override + public Class getClassByName(final String name) + { + final JavaPluginLoader jpl = (JavaPluginLoader)plugin.getPluginLoader(); + return jpl.getClassByName(name); + } + + @Override + public Location callRespawnEvent(Player player, Location loc, boolean bedSpawn) + { + final PlayerRespawnEvent pre = new PlayerRespawnEvent(((BukkitPlayer)player).getOnlinePlayer(), ((BukkitLocation)loc).getBukkitLocation() , bedSpawn); + getServer().getPluginManager().callEvent(pre); + return new BukkitLocation(pre.getRespawnLocation()); + } + + @Override + public void callSuicideEvent(Player player) + { + EntityDamageEvent ede = new EntityDamageEvent(((BukkitPlayer)player).getOnlinePlayer(), EntityDamageEvent.DamageCause.SUICIDE, 1000); + getServer().getPluginManager().callEvent(ede); + } + +} diff --git a/Essentials/src/net/ess3/bukkit/Server.java b/Essentials/src/net/ess3/bukkit/Server.java index b13ce62fb..e59d7d4f9 100644 --- a/Essentials/src/net/ess3/bukkit/Server.java +++ b/Essentials/src/net/ess3/bukkit/Server.java @@ -1,9 +1,126 @@ package net.ess3.bukkit; -import lombok.Delegate; +import net.ess3.api.IEssentials; +import net.ess3.api.server.CommandSender; +import net.ess3.api.server.Player; import net.ess3.api.server.IServer; +import net.ess3.api.server.World; +import java.util.*; +import lombok.Delegate; +import lombok.Getter; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerLoginEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.world.WorldLoadEvent; +import org.bukkit.event.world.WorldUnloadEvent; +import org.bukkit.plugin.RegisteredServiceProvider; + + +public class Server implements IServer, Listener +{ + private IEssentials ess; + private interface Excludes + { + List<org.bukkit.World> getWorlds(); + + org.bukkit.World getWorld(String name); + + org.bukkit.entity.Player[] getOnlinePlayers(); + + BukkitCommandSender getConsoleSender(); + } + @Delegate(excludes = Excludes.class) + private final org.bukkit.Server server; + @Getter + private List<World> worlds; + private Map<String, World> worldsMap; + @Getter + private Collection<Player> onlinePlayers; + private Map<org.bukkit.entity.Player, Player> onlinePlayersMap; + @Getter + private CommandSender consoleSender; + + public Server(final org.bukkit.Server server) + { + this.server = server; + consoleSender = new BukkitCommandSender(server.getConsoleSender()); + updateWorlds(); + } + + private void updateWorlds() + { + final ArrayList<World> lworlds = new ArrayList<World>(server.getWorlds().size()); + final HashMap<String, World> lworldsMap = new HashMap<String, World>(); + for (org.bukkit.World world : server.getWorlds()) + { + final BukkitWorld w = new BukkitWorld(world); + lworlds.add(w); + lworldsMap.put(world.getName(), w); + lworldsMap.put(world.getName().toLowerCase(Locale.ENGLISH), w); + } + this.worlds = Collections.unmodifiableList(lworlds); + this.worldsMap = Collections.unmodifiableMap(lworldsMap); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public synchronized void onWorldLoadEvent(final WorldLoadEvent event) + { + updateWorlds(); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public synchronized void onWorldUnloadEvent(final WorldUnloadEvent event) + { + updateWorlds(); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public synchronized void onPlayerLoginEvent(final PlayerLoginEvent event) + { + final HashMap<org.bukkit.entity.Player, Player> oplayersMap = new HashMap<org.bukkit.entity.Player, Player>(onlinePlayersMap); + BukkitPlayer p = new BukkitPlayer(event.getPlayer(), this); + oplayersMap.put(event.getPlayer(), p); + onlinePlayersMap = Collections.unmodifiableMap(oplayersMap); + onlinePlayers = Collections.unmodifiableCollection(oplayersMap.values()); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public synchronized void onPlayerQuitEvent(final PlayerQuitEvent event) + { + final ArrayList<Player> oplayers = new ArrayList<Player>(onlinePlayers); + final HashMap<org.bukkit.entity.Player, Player> oplayersMap = new HashMap<org.bukkit.entity.Player, Player>(onlinePlayersMap); + oplayersMap.remove(event.getPlayer()); + onlinePlayersMap = Collections.unmodifiableMap(oplayersMap); + onlinePlayers = Collections.unmodifiableCollection(oplayersMap.values()); + } -public class Server implements IServer { - @Delegate - private org.bukkit.Server server; + @Override + public World getWorld(final String name) + { + final World world = worldsMap.get(name); + if (world == null) + { + return worldsMap.get(name.toLowerCase(Locale.ENGLISH)); + } + return world; + } + + @Override + public void dispatchCommand(final CommandSender sender, final String command) + { + server.dispatchCommand(((BukkitCommandSender)sender).getCommandSender(), command); + } + + @Override + public <T> T getServiceProvider(final Class<T> clazz) + { + final RegisteredServiceProvider<T> rsp = server.getServicesManager().getRegistration(clazz); + return rsp.getProvider(); + } + + public Player getPlayer(final org.bukkit.entity.Player player) { + return onlinePlayersMap.get(player); + } } diff --git a/Essentials/src/net/ess3/bukkit/VersionCheck.java b/Essentials/src/net/ess3/bukkit/VersionCheck.java new file mode 100644 index 000000000..0413e15ba --- /dev/null +++ b/Essentials/src/net/ess3/bukkit/VersionCheck.java @@ -0,0 +1,46 @@ +package net.ess3.bukkit; + +import static net.ess3.I18n._; +import java.util.logging.Level; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.bukkit.plugin.PluginManager; + + +public class VersionCheck +{ + public static final int BUKKIT_VERSION = 2015; + private static final Pattern bukkitVersionPattern = Pattern.compile("git-Bukkit-(?:(?:[0-9]+)\\.)+[0-9]+-R[\\.0-9]+-(?:[0-9]+-g[0-9a-f]+-)?b([0-9]+)jnks.*"); + + public static boolean checkVersion(final org.bukkit.plugin.Plugin plugin) + { + final PluginManager pm = plugin.getServer().getPluginManager(); + final String pluginVersion = plugin.getDescription().getVersion(); + for (org.bukkit.plugin.Plugin p : pm.getPlugins()) + { + if (p.getDescription().getName().startsWith("Essentials") + && !p.getDescription().getVersion().equals(pluginVersion)) + { + p.getLogger().log(Level.WARNING, _("versionMismatch", p.getDescription().getName())); + } + } + final Matcher versionMatch = bukkitVersionPattern.matcher(plugin.getServer().getVersion()); + if (versionMatch.matches()) + { + final int versionNumber = Integer.parseInt(versionMatch.group(1)); + if (versionNumber < BUKKIT_VERSION && versionNumber > 100) + { + plugin.getLogger().log(Level.SEVERE, _("notRecommendedBukkit")); + plugin.getLogger().log(Level.SEVERE, _("requiredBukkit", Integer.toString(BUKKIT_VERSION))); + return false; + } + } + else + { + plugin.getLogger().log(Level.INFO, _("bukkitFormatChanged")); + plugin.getLogger().log(Level.INFO, plugin.getServer().getVersion()); + plugin.getLogger().log(Level.INFO, plugin.getServer().getBukkitVersion()); + } + return true; + } +} diff --git a/Essentials/src/net/ess3/commands/Commandback.java b/Essentials/src/net/ess3/commands/Commandback.java index ef785b11a..58537fa11 100644 --- a/Essentials/src/net/ess3/commands/Commandback.java +++ b/Essentials/src/net/ess3/commands/Commandback.java @@ -1,9 +1,8 @@ package net.ess3.commands; import static net.ess3.I18n._; -import net.ess3.api.IUser; import net.ess3.economy.Trade; -import net.ess3.permissions.WorldPermissions; +import net.ess3.api.IUser; public class Commandback extends EssentialsCommand @@ -11,14 +10,7 @@ public class Commandback extends EssentialsCommand @Override protected void run(final IUser user, final String commandLabel, final String[] args) throws Exception { - final String worldName = user.getData().getLastLocation().getWorldName(); - if (user.getWorld() != user.getData().getLastLocation().getBukkitLocation().getWorld() && ess.getSettings().getData().getGeneral().isWorldTeleportPermissions() - && WorldPermissions.getPermission(worldName).isAuthorized(user)) - { - throw new Exception(_("noPerm", "essentials.world." + worldName)); - } - //tod - verify - final Trade charge = new Trade(this.toString(), ess); + final Trade charge = new Trade(commandName, ess); charge.isAffordableFor(user); user.sendMessage(_("backUsageMsg")); user.getTeleport().back(charge); diff --git a/Essentials/src/net/ess3/commands/Commandbackup.java b/Essentials/src/net/ess3/commands/Commandbackup.java index c93ff4169..38f57ee2c 100644 --- a/Essentials/src/net/ess3/commands/Commandbackup.java +++ b/Essentials/src/net/ess3/commands/Commandbackup.java @@ -1,10 +1,7 @@ package net.ess3.commands; -import lombok.Cleanup; import static net.ess3.I18n._; import net.ess3.api.IBackup; -import net.ess3.api.ISettings; -import org.bukkit.command.CommandSender; public class Commandbackup extends EssentialsCommand @@ -13,19 +10,6 @@ public class Commandbackup extends EssentialsCommand protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { final IBackup backup = ess.getBackup(); - if (backup == null) - { - throw new Exception(_("backupDisabled")); - } - - @Cleanup - ISettings settings = ess.getSettings(); - settings.acquireReadLock(); - final String command = settings.getData().getGeneral().getBackup().getCommand(); - if (command == null || "".equals(command) || "save-all".equalsIgnoreCase(command)) - { - throw new Exception(_("backupDisabled")); - } backup.run(); sender.sendMessage(_("backupStarted")); } diff --git a/Essentials/src/net/ess3/commands/Commandbalance.java b/Essentials/src/net/ess3/commands/Commandbalance.java index 401323d48..d910dfda4 100644 --- a/Essentials/src/net/ess3/commands/Commandbalance.java +++ b/Essentials/src/net/ess3/commands/Commandbalance.java @@ -1,10 +1,9 @@ package net.ess3.commands; import static net.ess3.I18n._; +import net.ess3.utils.Util; import net.ess3.api.IUser; import net.ess3.permissions.Permissions; -import net.ess3.utils.Util; -import org.bukkit.command.CommandSender; public class Commandbalance extends EssentialsCommand diff --git a/Essentials/src/net/ess3/commands/Commandbalancetop.java b/Essentials/src/net/ess3/commands/Commandbalancetop.java index 02da6d78a..e72ef955e 100644 --- a/Essentials/src/net/ess3/commands/Commandbalancetop.java +++ b/Essentials/src/net/ess3/commands/Commandbalancetop.java @@ -1,15 +1,14 @@ package net.ess3.commands; -import java.text.DateFormat; -import java.util.*; -import java.util.Map.Entry; -import java.util.concurrent.locks.ReentrantReadWriteLock; import static net.ess3.I18n._; -import net.ess3.api.IUser; import net.ess3.utils.Util; +import net.ess3.api.IUser; import net.ess3.utils.textreader.ArrayListInput; import net.ess3.utils.textreader.TextPager; -import org.bukkit.command.CommandSender; +import java.text.DateFormat; +import java.util.*; +import java.util.Map.Entry; +import java.util.concurrent.locks.ReentrantReadWriteLock; public class Commandbalancetop extends EssentialsCommand @@ -58,7 +57,7 @@ public class Commandbalancetop extends EssentialsCommand { lock.readLock().unlock(); } - ess.scheduleAsyncDelayedTask(new Viewer(sender, page, force)); + ess.getPlugin().scheduleAsyncDelayedTask(new Viewer(sender, page, force)); } else { @@ -66,7 +65,7 @@ public class Commandbalancetop extends EssentialsCommand { sender.sendMessage(_("orderBalances", ess.getUserMap().getUniqueUsers())); } - ess.scheduleAsyncDelayedTask(new Viewer(sender, page, force)); + ess.getPlugin().scheduleAsyncDelayedTask(new Viewer(sender, page, force)); } } @@ -139,7 +138,7 @@ public class Commandbalancetop extends EssentialsCommand { lock.writeLock().unlock(); } - ess.scheduleAsyncDelayedTask(viewer); + ess.getPlugin().scheduleAsyncDelayedTask(viewer); } } @@ -173,7 +172,7 @@ public class Commandbalancetop extends EssentialsCommand { lock.readLock().unlock(); } - ess.scheduleAsyncDelayedTask(new Calculator(new Viewer(sender, page, force), force)); + ess.getPlugin().scheduleAsyncDelayedTask(new Calculator(new Viewer(sender, page, force), force)); } } } diff --git a/Essentials/src/net/ess3/commands/Commandban.java b/Essentials/src/net/ess3/commands/Commandban.java index f5cdae710..a250b6aeb 100644 --- a/Essentials/src/net/ess3/commands/Commandban.java +++ b/Essentials/src/net/ess3/commands/Commandban.java @@ -1,19 +1,17 @@ package net.ess3.commands; -import lombok.Cleanup; import net.ess3.Console; import static net.ess3.I18n._; import net.ess3.api.IUser; import net.ess3.permissions.Permissions; import net.ess3.user.Ban; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import lombok.Cleanup; public class Commandban extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -56,9 +54,9 @@ public class Commandban extends EssentialsCommand user.setBanned(true); user.kickPlayer(banReason); - for (Player onlinePlayer : server.getOnlinePlayers()) + for (IPlayer onlinePlayer : server.getOnlinePlayers()) { - final IUser player = ess.getUser(onlinePlayer); + final IUser player = onlinePlayer.getUser(); if (Permissions.BAN_NOTIFY.isAuthorized(player)) { onlinePlayer.sendMessage(_("playerBanned", senderName, user.getName(), banReason)); diff --git a/Essentials/src/net/ess3/commands/Commandbanip.java b/Essentials/src/net/ess3/commands/Commandbanip.java index 1123050da..97f61167d 100644 --- a/Essentials/src/net/ess3/commands/Commandbanip.java +++ b/Essentials/src/net/ess3/commands/Commandbanip.java @@ -1,15 +1,14 @@ package net.ess3.commands; -import lombok.Cleanup; import static net.ess3.I18n._; import net.ess3.api.IUser; -import org.bukkit.command.CommandSender; +import lombok.Cleanup; public class Commandbanip extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/net/ess3/commands/Commandbigtree.java b/Essentials/src/net/ess3/commands/Commandbigtree.java index fda8b8fb5..6d9919753 100644 --- a/Essentials/src/net/ess3/commands/Commandbigtree.java +++ b/Essentials/src/net/ess3/commands/Commandbigtree.java @@ -2,8 +2,8 @@ package net.ess3.commands; import static net.ess3.I18n._; import net.ess3.api.IUser; +import net.ess3.api.server.Location; import net.ess3.utils.LocationUtil; -import org.bukkit.Location; import org.bukkit.TreeType; diff --git a/Essentials/src/net/ess3/commands/Commandbreak.java b/Essentials/src/net/ess3/commands/Commandbreak.java index 766eb04e1..996d2a2f8 100644 --- a/Essentials/src/net/ess3/commands/Commandbreak.java +++ b/Essentials/src/net/ess3/commands/Commandbreak.java @@ -1,8 +1,8 @@ package net.ess3.commands; -import static net.ess3.I18n._; import net.ess3.api.IUser; import net.ess3.permissions.Permissions; +import static net.ess3.I18n._; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.event.block.BlockBreakEvent; diff --git a/Essentials/src/net/ess3/commands/Commandburn.java b/Essentials/src/net/ess3/commands/Commandburn.java index af0b91599..098538feb 100644 --- a/Essentials/src/net/ess3/commands/Commandburn.java +++ b/Essentials/src/net/ess3/commands/Commandburn.java @@ -1,7 +1,7 @@ package net.ess3.commands; import static net.ess3.I18n._; -import org.bukkit.command.CommandSender; +import net.ess3.api.server.CommandSender; import org.bukkit.entity.Player; diff --git a/Essentials/src/net/ess3/commands/Commandclearinventory.java b/Essentials/src/net/ess3/commands/Commandclearinventory.java index ea6179357..e5599a91f 100644 --- a/Essentials/src/net/ess3/commands/Commandclearinventory.java +++ b/Essentials/src/net/ess3/commands/Commandclearinventory.java @@ -1,10 +1,10 @@ package net.ess3.commands; -import java.util.List; import static net.ess3.I18n._; import net.ess3.api.IUser; +import net.ess3.api.server.CommandSender; import net.ess3.permissions.Permissions; -import org.bukkit.command.CommandSender; +import java.util.List; import org.bukkit.entity.Player; diff --git a/Essentials/src/net/ess3/commands/Commanddelhome.java b/Essentials/src/net/ess3/commands/Commanddelhome.java index 4cfdf85d6..7b0e85c50 100644 --- a/Essentials/src/net/ess3/commands/Commanddelhome.java +++ b/Essentials/src/net/ess3/commands/Commanddelhome.java @@ -1,18 +1,17 @@ package net.ess3.commands; -import java.util.Locale; -import lombok.Cleanup; import static net.ess3.I18n._; import net.ess3.api.IUser; import net.ess3.permissions.Permissions; -import org.bukkit.command.CommandSender; +import java.util.Locale; +import lombok.Cleanup; import org.bukkit.entity.Player; public class Commanddelhome extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/net/ess3/commands/Commanddeljail.java b/Essentials/src/net/ess3/commands/Commanddeljail.java index 4aa7c479e..f8fdc8594 100644 --- a/Essentials/src/net/ess3/commands/Commanddeljail.java +++ b/Essentials/src/net/ess3/commands/Commanddeljail.java @@ -1,7 +1,6 @@ package net.ess3.commands; import static net.ess3.I18n._; -import org.bukkit.command.CommandSender; public class Commanddeljail extends EssentialsCommand diff --git a/Essentials/src/net/ess3/commands/Commanddelwarp.java b/Essentials/src/net/ess3/commands/Commanddelwarp.java index a97514886..9e3ec97fb 100644 --- a/Essentials/src/net/ess3/commands/Commanddelwarp.java +++ b/Essentials/src/net/ess3/commands/Commanddelwarp.java @@ -1,13 +1,12 @@ package net.ess3.commands; import static net.ess3.I18n._; -import org.bukkit.command.CommandSender; public class Commanddelwarp extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/net/ess3/commands/Commandeco.java b/Essentials/src/net/ess3/commands/Commandeco.java index 724160509..a5a9fbce0 100644 --- a/Essentials/src/net/ess3/commands/Commandeco.java +++ b/Essentials/src/net/ess3/commands/Commandeco.java @@ -1,18 +1,17 @@ package net.ess3.commands; -import java.util.Locale; -import lombok.Cleanup; -import static net.ess3.I18n._; import net.ess3.api.ISettings; import net.ess3.api.IUser; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import static net.ess3.I18n._; + +import java.util.Locale; +import lombok.Cleanup; public class Commandeco extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { @@ -61,7 +60,7 @@ public class Commandeco extends EssentialsCommand { for (Player onlinePlayer : server.getOnlinePlayers()) { - final IUser player = ess.getUser(onlinePlayer); + final IUser player = onlinePlayer.getUser(); switch (cmd) { case GIVE: diff --git a/Essentials/src/net/ess3/commands/Commandenchant.java b/Essentials/src/net/ess3/commands/Commandenchant.java index f34ad6a70..9ab4b1db9 100644 --- a/Essentials/src/net/ess3/commands/Commandenchant.java +++ b/Essentials/src/net/ess3/commands/Commandenchant.java @@ -1,5 +1,10 @@ package net.ess3.commands; +import net.ess3.bukkit.Enchantments; +import static net.ess3.I18n._; +import net.ess3.utils.Util; +import net.ess3.api.IUser; +import net.ess3.permissions.EnchantPermissions; import java.util.Locale; import java.util.Map; import java.util.Set; diff --git a/Essentials/src/net/ess3/commands/Commandessentials.java b/Essentials/src/net/ess3/commands/Commandessentials.java index 3ad56f82e..44cf8536c 100644 --- a/Essentials/src/net/ess3/commands/Commandessentials.java +++ b/Essentials/src/net/ess3/commands/Commandessentials.java @@ -1,38 +1,48 @@ package net.ess3.commands; -import java.io.IOException; -import java.util.Map; import static net.ess3.I18n._; -import net.ess3.metrics.Metrics; -import org.bukkit.command.CommandSender; + +import net.ess3.api.server.Player; +import java.util.HashMap; +import java.util.Map; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; public class Commandessentials extends EssentialsCommand { + private transient int taskid; + private final transient Map<Player, Block> noteBlocks = new HashMap<Player, Block>(); + @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length == 0) { - run_disabled(sender, commandLabel, args); + run_disabled(sender, args); } else if (args[0].equalsIgnoreCase("debug")) { - run_debug(sender, commandLabel, args); + run_debug(sender, args); + } + else if (args[0].equalsIgnoreCase("nya")) + { + run_nya(sender, args); } - else if (args[0].equalsIgnoreCase("opt-out")) + else if (args[0].equalsIgnoreCase("moo")) { - run_optout(sender, commandLabel, args); + run_moo(sender, args); } else { - run_reload(sender, commandLabel, args); + run_reload(sender, args); } } - private void run_disabled(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + private void run_disabled(final CommandSender sender, final String[] args) throws Exception { - sender.sendMessage("Essentials " + ess.getDescription().getVersion()); + sender.sendMessage("Essentials " + ess.getPlugin().getVersion()); sender.sendMessage("/<command> <reload/debug>"); sender.sendMessage(_("blockList")); final StringBuilder disabledCommands = new StringBuilder(); @@ -44,45 +54,117 @@ public class Commandessentials extends EssentialsCommand } disabledCommands.append(entry.getKey()).append(" => ").append(entry.getValue()); } - - if (disabledCommands.length() > 0) - { - sender.sendMessage(_("blockList")); - sender.sendMessage(disabledCommands.toString()); - } + sender.sendMessage(disabledCommands.toString()); } - private void run_debug(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + private void run_debug(final CommandSender sender, final String[] args) throws Exception { ess.getSettings().setDebug(!ess.getSettings().isDebug()); - sender.sendMessage("Essentials " + ess.getDescription().getVersion() + " debug mode " + (ess.getSettings().isDebug() ? "enabled" : "disabled")); + sender.sendMessage("Essentials " + ess.getPlugin().getVersion() + " debug mode " + (ess.getSettings().isDebug() ? "enabled" : "disabled")); } - private void run_reload(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + private void run_reload(final CommandSender sender, final String[] args) throws Exception { ess.reload(); - sender.sendMessage(_("essentialsReload", ess.getDescription().getVersion())); + sender.sendMessage(_("essentialsReload", ess.getPlugin().getVersion())); } - private void run_optout(final CommandSender sender, final String command, final String args[]) + private void run_nya(final CommandSender sender, final String[] args) throws Exception { - final Metrics metrics = ess.getMetrics(); - try + final Map<String, Byte> noteMap = new HashMap<String, Byte>(); + noteMap.put("1F#", (byte)0x0); + noteMap.put("1G", (byte)0x1); + noteMap.put("1G#", (byte)0x2); + noteMap.put("1A", (byte)0x3); + noteMap.put("1A#", (byte)0x4); + noteMap.put("1B", (byte)0x5); + noteMap.put("1C", (byte)0x6); + noteMap.put("1C#", (byte)0x7); + noteMap.put("1D", (byte)0x8); + noteMap.put("1D#", (byte)0x9); + noteMap.put("1E", (byte)0xA); + noteMap.put("1F", (byte)0xB); + noteMap.put("2F#", (byte)(0x0 + 0xC)); + noteMap.put("2G", (byte)(0x1 + 0xC)); + noteMap.put("2G#", (byte)(0x2 + 0xC)); + noteMap.put("2A", (byte)(0x3 + 0xC)); + noteMap.put("2A#", (byte)(0x4 + 0xC)); + noteMap.put("2B", (byte)(0x5 + 0xC)); + noteMap.put("2C", (byte)(0x6 + 0xC)); + noteMap.put("2C#", (byte)(0x7 + 0xC)); + noteMap.put("2D", (byte)(0x8 + 0xC)); + noteMap.put("2D#", (byte)(0x9 + 0xC)); + noteMap.put("2E", (byte)(0xA + 0xC)); + noteMap.put("2F", (byte)(0xB + 0xC)); + if (!noteBlocks.isEmpty()) { - sender.sendMessage("Essentials collects simple metrics to highlight which features to concentrate work on in the future."); - if (metrics.isOptOut()) + return; + } + final String tuneStr = "1D#,1E,2F#,,2A#,1E,1D#,1E,2F#,2B,2D#,2E,2D#,2A#,2B,,2F#,,1D#,1E,2F#,2B,2C#,2A#,2B,2C#,2E,2D#,2E,2C#,,2F#,,2G#,,1D,1D#,,1C#,1D,1C#,1B,,1B,,1C#,,1D,,1D,1C#,1B,1C#,1D#,2F#,2G#,1D#,2F#,1C#,1D#,1B,1C#,1B,1D#,,2F#,,2G#,1D#,2F#,1C#,1D#,1B,1D,1D#,1D,1C#,1B,1C#,1D,,1B,1C#,1D#,2F#,1C#,1D,1C#,1B,1C#,,1B,,1C#,,2F#,,2G#,,1D,1D#,,1C#,1D,1C#,1B,,1B,,1C#,,1D,,1D,1C#,1B,1C#,1D#,2F#,2G#,1D#,2F#,1C#,1D#,1B,1C#,1B,1D#,,2F#,,2G#,1D#,2F#,1C#,1D#,1B,1D,1D#,1D,1C#,1B,1C#,1D,,1B,1C#,1D#,2F#,1C#,1D,1C#,1B,1C#,,1B,,1B,,1B,,1F#,1G#,1B,,1F#,1G#,1B,1C#,1D#,1B,1E,1D#,1E,2F#,1B,,1B,,1F#,1G#,1B,1E,1D#,1C#,1B,,,,1F#,1B,,1F#,1G#,1B,,1F#,1G#,1B,1B,1C#,1D#,1B,1F#,1G#,1F#,1B,,1B,1A#,1B,1F#,1G#,1B,1E,1D#,1E,2F#,1B,,1A#,,1B,,1F#,1G#,1B,,1F#,1G#,1B,1C#,1D#,1B,1E,1D#,1E,2F#,1B,,1B,,1F#,1G#,1B,1F#,1E,1D#,1C#,1B,,,,1F#,1B,,1F#,1G#,1B,,1F#,1G#,1B,1B,1C#,1D#,1B,1F#,1G#,1F#,1B,,1B,1A#,1B,1F#,1G#,1B,1E,1D#,1E,2F#,1B,,1A#,,1B,,1F#,1G#,1B,,1F#,1G#,1B,1C#,1D#,1B,1E,1D#,1E,2F#,1B,,1B,,1F#,1G#,1B,1F#,1E,1D#,1C#,1B,,,,1F#,1B,,1F#,1G#,1B,,1F#,1G#,1B,1B,1C#,1D#,1B,1F#,1G#,1F#,1B,,1B,1A#,1B,1F#,1G#,1B,1E,1D#,1E,2F#,1B,,1A#,,1B,,1F#,1G#,1B,,1F#,1G#,1B,1C#,1D#,1B,1E,1D#,1E,2F#,1B,,1B,,1F#,1G#,1B,1F#,1E,1D#,1C#,1B,,,,1F#,1B,,1F#,1G#,1B,,1F#,1G#,1B,1B,1C#,1D#,1B,1F#,1G#,1F#,1B,,1B,1A#,1B,1F#,1G#,1B,1E,1D#,1E,2F#,1B,,1A#,,1B,,1F#,1G#,1B,,1F#,1G#,1B,1C#,1D#,1B,1E,1D#,1E,2F#,1B,,1B,,1F#,1G#,1B,1F#,1E,1D#,1C#,1B,,,,1F#,1B,,1F#,1G#,1B,,1F#,1G#,1B,1B,1C#,1D#,1B,1F#,1G#,1F#,1B,,1B,1A#,1B,1F#,1G#,1B,1E,1D#,1E,2F#,1B,,1B,,"; + final String[] tune = tuneStr.split(","); + for (Player player : server.getOnlinePlayers()) + { + final Location loc = player.getLocation(); + loc.add(0, 3, 0); + while (loc.getBlockY() < player.getLocation().getBlockY() + 10 && loc.getBlock().getTypeId() != 0) { - metrics.enable(); + loc.add(0, 1, 0); } - else + if (loc.getBlock().getTypeId() == 0) { - metrics.disable(); + noteBlocks.put(player, loc.getBlock()); + player.sendBlockChange(loc, Material.NOTE_BLOCK, (byte)0); } - sender.sendMessage("Anonymous Metrics are now: " + (metrics.isOptOut() ? "disabled" : "enabled")); } - catch (IOException ex) + taskid = ess.getPlugin().scheduleSyncRepeatingTask(new Runnable() { - sender.sendMessage("Unable to modify 'plugins/PluginMetrics/config.yml': " + ex.getMessage()); + int i = 0; + + @Override + public void run() + { + final String note = tune[i]; + i++; + if (i >= tune.length) + { + Commandessentials.this.stopTune(); + } + if (note.isEmpty()) + { + return; + } + Map<Player, Block> noteBlocks = Commandessentials.this.noteBlocks; + for (Player onlinePlayer : server.getOnlinePlayers()) + { + final Block block = noteBlocks.get(onlinePlayer); + if (block == null || block.getType() != Material.NOTE_BLOCK) + { + continue; + } + onlinePlayer.playNote(block.getLocation(), (byte)0, noteMap.get(note)); + } + } + }, 20, 2); + } + + private void stopTune() + { + ess.getPlugin().cancelTask(taskid); + for (Block block : noteBlocks.values()) + { + if (block.getType() == Material.NOTE_BLOCK) + { + block.setType(Material.AIR); + } } + noteBlocks.clear(); + } + + private void run_moo(final CommandSender sender, final String args[]) + { + if(sender == ess.getServer().getConsoleSender()) + sender.sendMessage(new String[]{" (__)", " (oo)", " /------\\/", " / | ||", " * /\\---/\\", " ~~ ~~", "....\"Have you mooed today?\"..." } ); + else + sender.sendMessage(new String[]{" (__)", " (oo)", " /------\\/", " / | | |", " * /\\---/\\", " ~~ ~~", "....\"Have you mooed today?\"..." } ); } -}
\ No newline at end of file +} diff --git a/Essentials/src/net/ess3/commands/Commandext.java b/Essentials/src/net/ess3/commands/Commandext.java index f3413f0fd..1f7c1a51b 100644 --- a/Essentials/src/net/ess3/commands/Commandext.java +++ b/Essentials/src/net/ess3/commands/Commandext.java @@ -2,7 +2,7 @@ package net.ess3.commands; import static net.ess3.I18n._; import net.ess3.api.IUser; -import org.bukkit.command.CommandSender; +import net.ess3.api.server.CommandSender; import org.bukkit.entity.Player; diff --git a/Essentials/src/net/ess3/commands/Commandfeed.java b/Essentials/src/net/ess3/commands/Commandfeed.java index 31f12f9b7..21e47682f 100644 --- a/Essentials/src/net/ess3/commands/Commandfeed.java +++ b/Essentials/src/net/ess3/commands/Commandfeed.java @@ -1,10 +1,9 @@ package net.ess3.commands; -import java.util.List; import static net.ess3.I18n._; import net.ess3.api.IUser; import net.ess3.permissions.Permissions; -import org.bukkit.command.CommandSender; +import java.util.List; import org.bukkit.entity.Player; @@ -25,7 +24,7 @@ public class Commandfeed extends EssentialsCommand } } - private void feedOtherPlayers(final CommandSender sender, final String name) + private void feedOtherPlayers(final ICommandSender sender, final String name) { final List<Player> players = server.matchPlayer(name); if (players.isEmpty()) diff --git a/Essentials/src/net/ess3/commands/Commandgamemode.java b/Essentials/src/net/ess3/commands/Commandgamemode.java index cfa4c796b..30f56e1ba 100644 --- a/Essentials/src/net/ess3/commands/Commandgamemode.java +++ b/Essentials/src/net/ess3/commands/Commandgamemode.java @@ -5,7 +5,6 @@ import static net.ess3.I18n._; import net.ess3.api.IUser; import net.ess3.permissions.Permissions; import org.bukkit.GameMode; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/Essentials/src/net/ess3/commands/Commandgc.java b/Essentials/src/net/ess3/commands/Commandgc.java index dfb2917c7..415527af3 100644 --- a/Essentials/src/net/ess3/commands/Commandgc.java +++ b/Essentials/src/net/ess3/commands/Commandgc.java @@ -1,6 +1,7 @@ package net.ess3.commands; import static net.ess3.I18n._; +//TODO - Remove bukkit refs import org.bukkit.ChatColor; import org.bukkit.World; import org.bukkit.command.CommandSender; diff --git a/Essentials/src/net/ess3/commands/Commandgetpos.java b/Essentials/src/net/ess3/commands/Commandgetpos.java index e4ac2b4fe..cd02b661b 100644 --- a/Essentials/src/net/ess3/commands/Commandgetpos.java +++ b/Essentials/src/net/ess3/commands/Commandgetpos.java @@ -3,7 +3,6 @@ package net.ess3.commands; import net.ess3.api.IUser; import net.ess3.permissions.Permissions; import org.bukkit.Location; -import org.bukkit.command.CommandSender; public class Commandgetpos extends EssentialsCommand diff --git a/Essentials/src/net/ess3/commands/Commandgive.java b/Essentials/src/net/ess3/commands/Commandgive.java index 6512959d6..abd8695b2 100644 --- a/Essentials/src/net/ess3/commands/Commandgive.java +++ b/Essentials/src/net/ess3/commands/Commandgive.java @@ -7,7 +7,6 @@ import net.ess3.permissions.GivePermissions; import net.ess3.utils.Util; import org.bukkit.ChatColor; import org.bukkit.Material; -import org.bukkit.command.CommandSender; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -16,7 +15,7 @@ import org.bukkit.inventory.ItemStack; public class Commandgive extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { diff --git a/Essentials/src/net/ess3/commands/Commandgod.java b/Essentials/src/net/ess3/commands/Commandgod.java index 7cb424d81..c280472ef 100644 --- a/Essentials/src/net/ess3/commands/Commandgod.java +++ b/Essentials/src/net/ess3/commands/Commandgod.java @@ -3,7 +3,6 @@ package net.ess3.commands; import static net.ess3.I18n._; import net.ess3.api.IUser; import net.ess3.permissions.Permissions; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/Essentials/src/net/ess3/commands/Commandheal.java b/Essentials/src/net/ess3/commands/Commandheal.java index 41a744163..087947fd6 100644 --- a/Essentials/src/net/ess3/commands/Commandheal.java +++ b/Essentials/src/net/ess3/commands/Commandheal.java @@ -3,9 +3,9 @@ package net.ess3.commands; import java.util.List; import static net.ess3.I18n._; import net.ess3.api.IUser; +import net.ess3.api.server.CommandSender; import net.ess3.permissions.Permissions; import net.ess3.user.UserData.TimestampType; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -32,7 +32,7 @@ public class Commandheal extends EssentialsCommand } @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/net/ess3/commands/Commandhelp.java b/Essentials/src/net/ess3/commands/Commandhelp.java index 25f9640c2..78c1691b0 100644 --- a/Essentials/src/net/ess3/commands/Commandhelp.java +++ b/Essentials/src/net/ess3/commands/Commandhelp.java @@ -5,7 +5,7 @@ import static net.ess3.I18n._; import net.ess3.api.IUser; import net.ess3.utils.Util; import net.ess3.utils.textreader.*; -import org.bukkit.command.CommandSender; + public class Commandhelp extends EssentialsCommand diff --git a/Essentials/src/net/ess3/commands/Commandhelpop.java b/Essentials/src/net/ess3/commands/Commandhelpop.java index 195c4b15e..a4bae3b44 100644 --- a/Essentials/src/net/ess3/commands/Commandhelpop.java +++ b/Essentials/src/net/ess3/commands/Commandhelpop.java @@ -1,11 +1,6 @@ package net.ess3.commands; import java.util.logging.Level; -import static net.ess3.I18n._; -import net.ess3.api.IUser; -import net.ess3.permissions.Permissions; -import net.ess3.utils.Util; -import org.bukkit.entity.Player; public class Commandhelpop extends EssentialsCommand @@ -22,7 +17,7 @@ public class Commandhelpop extends EssentialsCommand logger.log(Level.INFO, message); for (Player onlinePlayer : server.getOnlinePlayers()) { - final IUser player = ess.getUser(onlinePlayer); + final IUser player = onlinePlayer.getUser(); if (!Permissions.HELPOP_RECEIVE.isAuthorized(player)) { continue; diff --git a/Essentials/src/net/ess3/commands/Commandinfo.java b/Essentials/src/net/ess3/commands/Commandinfo.java index cf8d90818..c38039b55 100644 --- a/Essentials/src/net/ess3/commands/Commandinfo.java +++ b/Essentials/src/net/ess3/commands/Commandinfo.java @@ -4,7 +4,6 @@ import net.ess3.utils.textreader.IText; import net.ess3.utils.textreader.KeywordReplacer; import net.ess3.utils.textreader.TextInput; import net.ess3.utils.textreader.TextPager; -import org.bukkit.command.CommandSender; public class Commandinfo extends EssentialsCommand diff --git a/Essentials/src/net/ess3/commands/Commandinvsee.java b/Essentials/src/net/ess3/commands/Commandinvsee.java index cf0b18ea6..4fa7ceb90 100644 --- a/Essentials/src/net/ess3/commands/Commandinvsee.java +++ b/Essentials/src/net/ess3/commands/Commandinvsee.java @@ -1,6 +1,10 @@ package net.ess3.commands; +import static net.ess3.I18n._; import net.ess3.api.IUser; +import net.ess3.user.Inventory; +import java.util.Arrays; +import org.bukkit.inventory.ItemStack; public class Commandinvsee extends EssentialsCommand @@ -8,12 +12,41 @@ public class Commandinvsee extends EssentialsCommand @Override protected void run(final IUser user, final String commandLabel, final String[] args) throws Exception { - if (args.length < 1) + + if (args.length < 1 && user.getData().getInventory() == null) { throw new NotEnoughArgumentsException(); } - final IUser invUser = getPlayer(args, 0); - user.setInvSee(true); - user.openInventory(invUser.getInventory()); + IUser invUser = user; + if (args.length == 1) + { + invUser = getPlayer(args, 0); + } + user.acquireWriteLock(); + if (invUser == user && user.getData().getInventory() != null) + { + invUser.getInventory().setContents(user.getData().getInventory().getBukkitInventory()); + user.getData().setInventory(null); + user.sendMessage(_("invRestored")); + throw new NoChargeException(); + } + if (user.getData().getInventory() == null) + { + user.getData().setInventory(new Inventory(user.getInventory().getContents())); + } + ItemStack[] invUserStack = invUser.getInventory().getContents(); + final int userStackLength = user.getInventory().getContents().length; + if (invUserStack.length < userStackLength) + { + invUserStack = Arrays.copyOf(invUserStack, userStackLength); + } + if (invUserStack.length > userStackLength) + { + throw new Exception(_("invBigger")); + } + user.getInventory().setContents(invUserStack); + user.sendMessage(_("invSee", invUser.getDisplayName())); + user.sendMessage(_("invSeeHelp")); + throw new NoChargeException(); } } diff --git a/Essentials/src/net/ess3/commands/Commanditem.java b/Essentials/src/net/ess3/commands/Commanditem.java index a2339e976..132e1d4aa 100644 --- a/Essentials/src/net/ess3/commands/Commanditem.java +++ b/Essentials/src/net/ess3/commands/Commanditem.java @@ -1,13 +1,11 @@ package net.ess3.commands; -import java.util.Locale; import static net.ess3.I18n._; import net.ess3.api.IUser; +import net.ess3.api.server.Enchantment; +import net.ess3.api.server.ItemStack; import net.ess3.permissions.ItemPermissions; -import net.ess3.permissions.Permissions; -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemStack; +import java.util.Locale; public class Commanditem extends EssentialsCommand @@ -27,49 +25,35 @@ public class Commanditem extends EssentialsCommand throw new Exception(_("cantSpawnItem", itemname)); } - try + if (args.length > 1 && Integer.parseInt(args[1]) > 0) { - if (args.length > 1 && Integer.parseInt(args[1]) > 0) - { - stack.setAmount(Integer.parseInt(args[1])); - } - else if (ess.getSettings().getData().getGeneral().getDefaultStacksize() > 0) - { - stack.setAmount(ess.getSettings().getData().getGeneral().getDefaultStacksize()); - } - else if (ess.getSettings().getData().getGeneral().getOversizedStacksize()> 0 && Permissions.OVERSIZEDSTACKS.isAuthorized(user)) - { - stack.setAmount(ess.getSettings().getData().getGeneral().getOversizedStacksize()); - } - if (args.length > 2) + stack.setAmount(Integer.parseInt(args[1])); + } + + if (args.length > 2) + { + for (int i = 2; i < args.length; i++) { - for (int i = 2; i < args.length; i++) + final String[] split = args[i].split("[:+',;.]", 2); + if (split.length < 1) + { + continue; + } + final Enchantment enchantment = Commandenchant.getEnchantment(split[0], user); + int level; + if (split.length > 1) + { + level = Integer.parseInt(split[1]); + } + else { - final String[] split = args[i].split("[:+',;.]", 2); - if (split.length < 1) - { - continue; - } - final Enchantment enchantment = Commandenchant.getEnchantment(split[0], user); - int level; - if (split.length > 1) - { - level = Integer.parseInt(split[1]); - } - else - { - level = enchantment.getMaxLevel(); - } - stack.addEnchantment(enchantment, level); + level = enchantment.getMaxLevel(); } + stack.addEnchantment(enchantment, level); } } - catch (NumberFormatException e) - { - throw new NotEnoughArgumentsException(); - } - if (stack.getType() == Material.AIR) + if (stack.isAir()) { throw new Exception(_("cantSpawnItem", "Air")); } diff --git a/Essentials/src/net/ess3/commands/Commanditemdb.java b/Essentials/src/net/ess3/commands/Commanditemdb.java index ca869e61d..e298df0d7 100644 --- a/Essentials/src/net/ess3/commands/Commanditemdb.java +++ b/Essentials/src/net/ess3/commands/Commanditemdb.java @@ -1,5 +1,6 @@ package net.ess3.commands; +//TODO - replace alll the bukkit imports import static net.ess3.I18n._; import org.bukkit.Material; import org.bukkit.command.CommandSender; diff --git a/Essentials/src/net/ess3/commands/Commandjails.java b/Essentials/src/net/ess3/commands/Commandjails.java index 6a68c1e91..ae443e19d 100644 --- a/Essentials/src/net/ess3/commands/Commandjails.java +++ b/Essentials/src/net/ess3/commands/Commandjails.java @@ -1,7 +1,6 @@ package net.ess3.commands; import net.ess3.utils.Util; -import org.bukkit.command.CommandSender; public class Commandjails extends EssentialsCommand diff --git a/Essentials/src/net/ess3/commands/Commandjump.java b/Essentials/src/net/ess3/commands/Commandjump.java index e8dff4eab..46c7b488c 100644 --- a/Essentials/src/net/ess3/commands/Commandjump.java +++ b/Essentials/src/net/ess3/commands/Commandjump.java @@ -1,8 +1,9 @@ package net.ess3.commands; import static net.ess3.I18n._; -import net.ess3.api.IUser; import net.ess3.economy.Trade; +import net.ess3.api.IUser; +import net.ess3.api.server.ILocation; import net.ess3.utils.LocationUtil; import org.bukkit.Location; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -14,7 +15,7 @@ public class Commandjump extends EssentialsCommand public void run(final IUser user, final String commandLabel, final String[] args) throws Exception { Location loc; - final Location cloc = user.getLocation(); + final ILocation cloc = user.getLocation(); try { diff --git a/Essentials/src/net/ess3/commands/Commandkick.java b/Essentials/src/net/ess3/commands/Commandkick.java index af29700c2..b4164f46e 100644 --- a/Essentials/src/net/ess3/commands/Commandkick.java +++ b/Essentials/src/net/ess3/commands/Commandkick.java @@ -3,15 +3,14 @@ package net.ess3.commands; import net.ess3.Console; import static net.ess3.I18n._; import net.ess3.api.IUser; +import net.ess3.api.server.CommandSender; import net.ess3.permissions.Permissions; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; public class Commandkick extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -29,7 +28,7 @@ public class Commandkick extends EssentialsCommand for (Player onlinePlayer : server.getOnlinePlayers()) { - final IUser player = ess.getUser(onlinePlayer); + final IUser player = onlinePlayer.getUser(); if (Permissions.KICK_NOTIFY.isAuthorized(player)) { onlinePlayer.sendMessage(_("playerKicked", senderName, user.getName(), kickReason)); diff --git a/Essentials/src/net/ess3/commands/Commandkickall.java b/Essentials/src/net/ess3/commands/Commandkickall.java index 3de05b71f..e66409f69 100644 --- a/Essentials/src/net/ess3/commands/Commandkickall.java +++ b/Essentials/src/net/ess3/commands/Commandkickall.java @@ -1,18 +1,18 @@ package net.ess3.commands; import static net.ess3.I18n._; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import net.ess3.api.server.CommandSender; +import net.ess3.api.server.Player; public class Commandkickall extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { for (Player onlinePlayer : server.getOnlinePlayers()) { - if (sender instanceof Player && onlinePlayer.getName().equalsIgnoreCase(((Player)sender).getName())) + if (sender.isPlayer() && onlinePlayer.getName().equalsIgnoreCase(((Player)sender).getName())) { continue; } @@ -21,6 +21,5 @@ public class Commandkickall extends EssentialsCommand onlinePlayer.kickPlayer(args.length > 0 ? getFinalArg(args, 0) : _("kickDefault")); } } - sender.sendMessage(_("kickedAll")); } } diff --git a/Essentials/src/net/ess3/commands/Commandkill.java b/Essentials/src/net/ess3/commands/Commandkill.java index 6f5560b1e..0ab789af4 100644 --- a/Essentials/src/net/ess3/commands/Commandkill.java +++ b/Essentials/src/net/ess3/commands/Commandkill.java @@ -1,7 +1,7 @@ package net.ess3.commands; import static net.ess3.I18n._; -import org.bukkit.command.CommandSender; + import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageEvent; @@ -9,7 +9,7 @@ import org.bukkit.event.entity.EntityDamageEvent; public class Commandkill extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/net/ess3/commands/Commandkillall.java b/Essentials/src/net/ess3/commands/Commandkillall.java index ec624915a..7e6f8a2b1 100644 --- a/Essentials/src/net/ess3/commands/Commandkillall.java +++ b/Essentials/src/net/ess3/commands/Commandkillall.java @@ -1,12 +1,14 @@ package net.ess3.commands; +import static net.ess3.I18n._; + +import net.ess3.bukkit.Mob; import java.util.Collections; import java.util.Locale; import static net.ess3.I18n._; import net.ess3.bukkit.Mob; import org.bukkit.Chunk; import org.bukkit.World; -import org.bukkit.command.CommandSender; import org.bukkit.entity.*; import org.bukkit.event.entity.EntityDeathEvent; @@ -15,7 +17,7 @@ public class Commandkillall extends EssentialsCommand { //TODO: Tidy - missed this during command cleanup @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { String type = "all"; int radius = -1; diff --git a/Essentials/src/net/ess3/commands/Commandkit.java b/Essentials/src/net/ess3/commands/Commandkit.java index 9856bdb1a..f3ea78ce1 100644 --- a/Essentials/src/net/ess3/commands/Commandkit.java +++ b/Essentials/src/net/ess3/commands/Commandkit.java @@ -1,14 +1,13 @@ package net.ess3.commands; -import java.util.Collection; -import java.util.Locale; import static net.ess3.I18n._; -import net.ess3.api.IUser; import net.ess3.economy.Trade; +import net.ess3.utils.Util; +import net.ess3.api.IUser; import net.ess3.permissions.KitPermissions; import net.ess3.settings.Kit; -import net.ess3.utils.Util; -import org.bukkit.command.CommandSender; +import java.util.Collection; +import java.util.Locale; public class Commandkit extends EssentialsCommand @@ -36,64 +35,28 @@ public class Commandkit extends EssentialsCommand } throw new NoChargeException(); } - else if (args.length > 1 && KitPermissions.getPermission("others").isAuthorized(user)) - { - final IUser userTo = getPlayer(args, 1, true); - final String kitName = Util.sanitizeString(args[0].toLowerCase(Locale.ENGLISH)); - giveKit(userTo, user, kitName); - - } else { - final String kitName = Util.sanitizeString(args[0].toLowerCase(Locale.ENGLISH)); - giveKit(user, user, kitName); - - } - } - - @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception - { - if (args.length < 2) - { - listKits(sender); - throw new NoChargeException(); - } - { - final IUser userTo = getPlayer(args, 1, true); final String kitName = args[0].toLowerCase(Locale.ENGLISH); final Kit kit = ess.getKits().getKit(kitName); - ess.getKits().sendKit(userTo, kit); - sender.sendMessage(_("kitGive", kitName)); - } - } - private void listKits(CommandSender sender) throws Exception - { - Collection<String> kitList = ess.getKits().getList(); - if (kitList.isEmpty()) - { - sender.sendMessage(_("kits", kitList)); - } - else - { - sender.sendMessage(_("kits", Util.joinList(kitList))); - } - } + if (!KitPermissions.getPermission(kitName).isAuthorized(user)) + { + throw new Exception(_("noKitPermission", "essentials.kit." + kitName)); + } + + //TODO: Check kit delay + + final Trade charge = new Trade("kit-" + kitName, ess); + charge.isAffordableFor(user); + + ess.getKits().sendKit(user, kit); + + //TODO: Merge kit changes from 2.9 + + charge.charge(user); + user.sendMessage(_("kitGive", kitName)); - private void giveKit(IUser userTo, IUser userFrom, String kitName) throws Exception - { - if (!KitPermissions.getPermission(kitName).isAuthorized(userFrom)) - { - throw new Exception(_("noKitPermission", "essentials.kit." + kitName)); } - final Kit kit = ess.getKits().getKit(kitName); - ess.getKits().checkTime(userFrom, kit); - final Trade charge = new Trade("kit-" + kitName, ess); - charge.isAffordableFor(userFrom); - ess.getKits().sendKit(userTo, kit); - charge.charge(userFrom); - userTo.sendMessage(_("kitGive", kitName)); } } - diff --git a/Essentials/src/net/ess3/commands/Commandkittycannon.java b/Essentials/src/net/ess3/commands/Commandkittycannon.java index f8b12dfdf..72dede652 100644 --- a/Essentials/src/net/ess3/commands/Commandkittycannon.java +++ b/Essentials/src/net/ess3/commands/Commandkittycannon.java @@ -25,7 +25,7 @@ public class Commandkittycannon extends EssentialsCommand ocelot.setCatType(Ocelot.Type.values()[i]); ocelot.setTamed(true); ocelot.setVelocity(user.getEyeLocation().getDirection().multiply(2)); - ess.scheduleSyncDelayedTask(new Runnable() + ess.getPlugin().scheduleSyncDelayedTask(new Runnable() { @Override public void run() diff --git a/Essentials/src/net/ess3/commands/Commandlightning.java b/Essentials/src/net/ess3/commands/Commandlightning.java index f66cfa642..8fe876cf9 100644 --- a/Essentials/src/net/ess3/commands/Commandlightning.java +++ b/Essentials/src/net/ess3/commands/Commandlightning.java @@ -1,11 +1,10 @@ package net.ess3.commands; -import lombok.Cleanup; import static net.ess3.I18n._; import net.ess3.api.ISettings; import net.ess3.api.IUser; import net.ess3.permissions.Permissions; -import org.bukkit.command.CommandSender; +import lombok.Cleanup; import org.bukkit.entity.LightningStrike; import org.bukkit.entity.Player; @@ -13,7 +12,7 @@ import org.bukkit.entity.Player; public class Commandlightning extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { IUser user = null; diff --git a/Essentials/src/net/ess3/commands/Commandlist.java b/Essentials/src/net/ess3/commands/Commandlist.java index ea4deeefc..64e352731 100644 --- a/Essentials/src/net/ess3/commands/Commandlist.java +++ b/Essentials/src/net/ess3/commands/Commandlist.java @@ -1,19 +1,17 @@ package net.ess3.commands; -import java.util.*; import static net.ess3.I18n._; +import net.ess3.utils.Util; import net.ess3.api.ISettings; import net.ess3.api.IUser; import net.ess3.permissions.Permissions; -import net.ess3.utils.Util; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import java.util.*; public class Commandlist extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { boolean showhidden = false; if (Permissions.LIST_HIDDEN.isAuthorized(sender)) @@ -23,7 +21,7 @@ public class Commandlist extends EssentialsCommand int playerHidden = 0; for (Player onlinePlayer : server.getOnlinePlayers()) { - if (ess.getUser(onlinePlayer).isHidden()) + if (onlinePlayer.getUser().isHidden()) { playerHidden++; } @@ -32,11 +30,11 @@ public class Commandlist extends EssentialsCommand String online; if (showhidden && playerHidden > 0) { - online = _("listAmountHidden", server.getOnlinePlayers().length - playerHidden, playerHidden, server.getMaxPlayers()); + online = _("listAmountHidden", server.getOnlinePlayers().size() - playerHidden, playerHidden, server.getMaxPlayers()); } else { - online = _("listAmount", server.getOnlinePlayers().length - playerHidden, server.getMaxPlayers()); + online = _("listAmount", server.getOnlinePlayers().size() - playerHidden, server.getMaxPlayers()); } sender.sendMessage(online); @@ -55,9 +53,9 @@ public class Commandlist extends EssentialsCommand if (sortListByGroups) { Map<String, List<IUser>> sort = new HashMap<String, List<IUser>>(); - for (Player OnlinePlayer : server.getOnlinePlayers()) + for (Player onlinePlayer : server.getOnlinePlayers()) { - final IUser player = ess.getUser(OnlinePlayer); + final IUser player = onlinePlayer.getUser(); if (player.isHidden() && !showhidden) { continue; @@ -116,9 +114,9 @@ public class Commandlist extends EssentialsCommand else { final List<IUser> users = new ArrayList<IUser>(); - for (Player OnlinePlayer : server.getOnlinePlayers()) + for (Player onlinePlayer : server.getOnlinePlayers()) { - final IUser player = ess.getUser(OnlinePlayer); + final IUser player =onlinePlayer.getUser(); if (player.isHidden() && !showhidden) { continue; diff --git a/Essentials/src/net/ess3/commands/Commandmail.java b/Essentials/src/net/ess3/commands/Commandmail.java index 17f1aac49..98a9a8ad9 100644 --- a/Essentials/src/net/ess3/commands/Commandmail.java +++ b/Essentials/src/net/ess3/commands/Commandmail.java @@ -1,11 +1,11 @@ package net.ess3.commands; -import java.util.List; import static net.ess3.I18n._; +import net.ess3.utils.Util; import net.ess3.api.IUser; +import net.ess3.api.server.CommandSender; import net.ess3.permissions.Permissions; -import net.ess3.utils.Util; -import org.bukkit.command.CommandSender; +import java.util.List; import org.bukkit.entity.Player; @@ -65,7 +65,7 @@ public class Commandmail extends EssentialsCommand { throw new Exception(_("noPerm", "essentials.mail.sendall")); } - ess.scheduleAsyncDelayedTask(new SendAll(user.getName() + ": " + Util.stripFormat(getFinalArg(args, 1)))); + ess.getPlugin().scheduleAsyncDelayedTask(new SendAll(user.getName() + ": " + Util.stripColor(getFinalArg(args, 1)))); user.sendMessage(_("mailSent")); return; } @@ -112,7 +112,7 @@ public class Commandmail extends EssentialsCommand } else if (args.length >= 1 && "sendall".equalsIgnoreCase(args[0])) { - ess.scheduleAsyncDelayedTask(new SendAll("Server: " + getFinalArg(args, 2))); + ess.getPlugin().scheduleAsyncDelayedTask(new SendAll("Server: " + getFinalArg(args, 2))); } else if (args.length >= 2) { diff --git a/Essentials/src/net/ess3/commands/Commandme.java b/Essentials/src/net/ess3/commands/Commandme.java index 1c6666d2b..fb62ec234 100644 --- a/Essentials/src/net/ess3/commands/Commandme.java +++ b/Essentials/src/net/ess3/commands/Commandme.java @@ -1,9 +1,9 @@ package net.ess3.commands; import static net.ess3.I18n._; +import net.ess3.utils.Util; import net.ess3.api.IUser; import net.ess3.permissions.Permissions; -import net.ess3.utils.Util; public class Commandme extends EssentialsCommand diff --git a/Essentials/src/net/ess3/commands/Commandmore.java b/Essentials/src/net/ess3/commands/Commandmore.java index 519c723c7..78269a022 100644 --- a/Essentials/src/net/ess3/commands/Commandmore.java +++ b/Essentials/src/net/ess3/commands/Commandmore.java @@ -1,12 +1,11 @@ package net.ess3.commands; -import java.util.Locale; import static net.ess3.I18n._; import net.ess3.api.ISettings; import net.ess3.api.IUser; import net.ess3.permissions.ItemPermissions; import net.ess3.permissions.Permissions; -import org.bukkit.inventory.ItemStack; +import java.util.Locale; public class Commandmore extends EssentialsCommand diff --git a/Essentials/src/net/ess3/commands/Commandmsg.java b/Essentials/src/net/ess3/commands/Commandmsg.java index 431720ba2..a1d0b614d 100644 --- a/Essentials/src/net/ess3/commands/Commandmsg.java +++ b/Essentials/src/net/ess3/commands/Commandmsg.java @@ -1,21 +1,21 @@ package net.ess3.commands; -import java.util.List; -import lombok.Cleanup; import net.ess3.Console; import static net.ess3.I18n._; + +import net.ess3.utils.Util; import net.ess3.api.IReplyTo; import net.ess3.api.IUser; import net.ess3.permissions.Permissions; -import net.ess3.utils.Util; -import org.bukkit.command.CommandSender; +import java.util.List; +import lombok.Cleanup; import org.bukkit.entity.Player; public class Commandmsg extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2 || args[0].trim().length() < 3 || args[1].trim().isEmpty()) { diff --git a/Essentials/src/net/ess3/commands/Commandmute.java b/Essentials/src/net/ess3/commands/Commandmute.java index bf574f961..abbe78d9c 100644 --- a/Essentials/src/net/ess3/commands/Commandmute.java +++ b/Essentials/src/net/ess3/commands/Commandmute.java @@ -1,18 +1,18 @@ package net.ess3.commands; -import lombok.Cleanup; import static net.ess3.I18n._; + import net.ess3.api.IUser; import net.ess3.permissions.Permissions; import net.ess3.user.UserData.TimestampType; import net.ess3.utils.DateUtil; -import org.bukkit.command.CommandSender; +import lombok.Cleanup; public class Commandmute extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/net/ess3/commands/Commandnear.java b/Essentials/src/net/ess3/commands/Commandnear.java index 248adfa7f..1ea933474 100644 --- a/Essentials/src/net/ess3/commands/Commandnear.java +++ b/Essentials/src/net/ess3/commands/Commandnear.java @@ -5,7 +5,6 @@ import net.ess3.api.IUser; import net.ess3.permissions.Permissions; import org.bukkit.Location; import org.bukkit.World; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/Essentials/src/net/ess3/commands/Commandnick.java b/Essentials/src/net/ess3/commands/Commandnick.java index 3f51b6f1c..19c89fef8 100644 --- a/Essentials/src/net/ess3/commands/Commandnick.java +++ b/Essentials/src/net/ess3/commands/Commandnick.java @@ -7,8 +7,8 @@ import net.ess3.api.ISettings; import net.ess3.api.IUser; import net.ess3.permissions.Permissions; import net.ess3.utils.Util; +//TODO - Remove bukkit import org.bukkit.Server; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -42,7 +42,7 @@ public class Commandnick extends EssentialsCommand } @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { diff --git a/Essentials/src/net/ess3/commands/Commandnuke.java b/Essentials/src/net/ess3/commands/Commandnuke.java index e5259f134..0154e3dc2 100644 --- a/Essentials/src/net/ess3/commands/Commandnuke.java +++ b/Essentials/src/net/ess3/commands/Commandnuke.java @@ -6,7 +6,6 @@ import java.util.List; import static net.ess3.I18n._; import org.bukkit.Location; import org.bukkit.World; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; diff --git a/Essentials/src/net/ess3/commands/Commandpay.java b/Essentials/src/net/ess3/commands/Commandpay.java index 76a3e6c0e..d60f6ea18 100644 --- a/Essentials/src/net/ess3/commands/Commandpay.java +++ b/Essentials/src/net/ess3/commands/Commandpay.java @@ -1,8 +1,8 @@ package net.ess3.commands; import static net.ess3.I18n._; -import net.ess3.api.IUser; import net.ess3.economy.Trade; +import net.ess3.api.IUser; import org.bukkit.entity.Player; diff --git a/Essentials/src/net/ess3/commands/Commandping.java b/Essentials/src/net/ess3/commands/Commandping.java index 13e99b912..1aebfa971 100644 --- a/Essentials/src/net/ess3/commands/Commandping.java +++ b/Essentials/src/net/ess3/commands/Commandping.java @@ -1,8 +1,8 @@ package net.ess3.commands; import static net.ess3.I18n._; -import net.ess3.api.IUser; import net.ess3.utils.Util; +import net.ess3.api.IUser; public class Commandping extends EssentialsCommand diff --git a/Essentials/src/net/ess3/commands/Commandpowertool.java b/Essentials/src/net/ess3/commands/Commandpowertool.java index 461e335cc..35ccae49a 100644 --- a/Essentials/src/net/ess3/commands/Commandpowertool.java +++ b/Essentials/src/net/ess3/commands/Commandpowertool.java @@ -7,6 +7,7 @@ import static net.ess3.I18n._; import net.ess3.api.IUser; import net.ess3.permissions.Permissions; import net.ess3.utils.Util; +//TODO remove bukkit import org.bukkit.Material; import org.bukkit.inventory.ItemStack; diff --git a/Essentials/src/net/ess3/commands/Commandptime.java b/Essentials/src/net/ess3/commands/Commandptime.java index 0399682df..1ba413407 100644 --- a/Essentials/src/net/ess3/commands/Commandptime.java +++ b/Essentials/src/net/ess3/commands/Commandptime.java @@ -5,8 +5,8 @@ import static net.ess3.I18n._; import net.ess3.api.IUser; import net.ess3.permissions.Permissions; import net.ess3.utils.DescParseTickFormat; +//TODO - Remove bukkit import org.bukkit.World; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -23,7 +23,7 @@ public class Commandptime extends EssentialsCommand } @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { // Which Players(s) / Users(s) are we interested in? String userSelector = null; diff --git a/Essentials/src/net/ess3/commands/Commandr.java b/Essentials/src/net/ess3/commands/Commandr.java index 166232041..1f428432d 100644 --- a/Essentials/src/net/ess3/commands/Commandr.java +++ b/Essentials/src/net/ess3/commands/Commandr.java @@ -2,18 +2,18 @@ package net.ess3.commands; import net.ess3.Console; import static net.ess3.I18n._; +import net.ess3.utils.Util; import net.ess3.api.IReplyTo; import net.ess3.api.IUser; import net.ess3.permissions.Permissions; -import net.ess3.utils.Util; -import org.bukkit.command.CommandSender; +//TODO - Remove bukkit import org.bukkit.entity.Player; public class Commandr extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -78,7 +78,7 @@ public class Commandr extends EssentialsCommand } @Override - public String getPermission() + public String getPermissionName() { return "essentials.msg"; } diff --git a/Essentials/src/net/ess3/commands/Commandrealname.java b/Essentials/src/net/ess3/commands/Commandrealname.java index 0f2e60f7b..bcbdd6ae1 100644 --- a/Essentials/src/net/ess3/commands/Commandrealname.java +++ b/Essentials/src/net/ess3/commands/Commandrealname.java @@ -6,8 +6,7 @@ import static net.ess3.I18n._; import net.ess3.api.ISettings; import net.ess3.api.IUser; import net.ess3.utils.Util; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +//TODO - Remove bukkitimport org.bukkit.entity.Player; public class Commandrealname extends EssentialsCommand diff --git a/Essentials/src/net/ess3/commands/Commandremove.java b/Essentials/src/net/ess3/commands/Commandremove.java index f8b171259..897d90e37 100644 --- a/Essentials/src/net/ess3/commands/Commandremove.java +++ b/Essentials/src/net/ess3/commands/Commandremove.java @@ -5,7 +5,6 @@ import static net.ess3.I18n._; import net.ess3.api.IUser; import org.bukkit.Chunk; import org.bukkit.World; -import org.bukkit.command.CommandSender; import org.bukkit.entity.*; //Todo: Fix this up diff --git a/Essentials/src/net/ess3/commands/Commandseen.java b/Essentials/src/net/ess3/commands/Commandseen.java index d48ede62b..9c5889bdd 100644 --- a/Essentials/src/net/ess3/commands/Commandseen.java +++ b/Essentials/src/net/ess3/commands/Commandseen.java @@ -1,13 +1,12 @@ package net.ess3.commands; -import lombok.Cleanup; import static net.ess3.I18n._; + import net.ess3.api.IUser; import net.ess3.permissions.Permissions; -import net.ess3.storage.Location; import net.ess3.user.UserData.TimestampType; import net.ess3.utils.DateUtil; -import org.bukkit.command.CommandSender; +import lombok.Cleanup; public class Commandseen extends EssentialsCommand @@ -15,16 +14,16 @@ public class Commandseen extends EssentialsCommand @Override protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { - seen(sender,args,true, true); + seen(sender,args,true); } @Override protected void run(final IUser user, final String commandLabel, final String[] args) throws Exception { - seen(user,args,Permissions.SEEN_BANREASON.isAuthorized(user), Permissions.SEEN_EXTRA.isAuthorized(user)); + seen(user,args,Permissions.SEEN_BANREASON.isAuthorized(user)); } - protected void seen (final CommandSender sender, final String[] args, final boolean showBan, final boolean extra) throws Exception + protected void seen (final CommandSender sender, final String[] args, final boolean show) throws Exception { if (args.length < 1) { @@ -32,36 +31,22 @@ public class Commandseen extends EssentialsCommand } try { - IUser player = getPlayer(args, 0); - player.setDisplayNick(); - sender.sendMessage(_("seenOnline", player.getDisplayName(), DateUtil.formatDateDiff(player.getTimestamp(TimestampType.LOGIN)))); - if (extra) - { - sender.sendMessage(_("whoisIPAddress", player.getAddress().getAddress().toString())); - } + IUser u = getPlayer(args, 0); + sender.sendMessage(_("seenOnline", u.getDisplayName(), DateUtil.formatDateDiff(u.getTimestamp(TimestampType.LOGIN)))); } catch (NoSuchFieldException e) { @Cleanup - IUser player = ess.getUser(args[0]); - player.acquireReadLock(); - if (player == null) + IUser u = ess.getUser(args[0]); + u.acquireReadLock(); + if (u == null) { throw new Exception(_("playerNotFound")); } - player.setDisplayNick(); - sender.sendMessage(_("seenOffline", player.getName(), DateUtil.formatDateDiff(player.getTimestamp(TimestampType.LOGOUT)))); - if (player.isBanned()) - { - sender.sendMessage(_("whoisBanned", showBan ? player.getData().getBan().getReason() : _("true"))); - } - if (extra) + sender.sendMessage(_("seenOffline", u.getDisplayName(), DateUtil.formatDateDiff(u.getTimestamp(TimestampType.LOGOUT)))); + if (u.isBanned()) { - sender.sendMessage(_("whoisIPAddress", player.getData().getIpAddress())); - final Location loc = player.getData().getLastLocation(); - if (loc != null) { - sender.sendMessage(_("whoisLocation", loc.getWorldName(), loc.getX(), loc.getY(), loc.getZ())); - } + sender.sendMessage(_("whoisBanned", show ? u.getData().getBan().getReason() : _("true"))); } } } diff --git a/Essentials/src/net/ess3/commands/Commandsethome.java b/Essentials/src/net/ess3/commands/Commandsethome.java index d140f3d2e..00e3a0170 100644 --- a/Essentials/src/net/ess3/commands/Commandsethome.java +++ b/Essentials/src/net/ess3/commands/Commandsethome.java @@ -36,9 +36,9 @@ public class Commandsethome extends EssentialsCommand user.acquireWriteLock(); if (user.getData().getHomes() == null) { - user.getData().setHomes(new HashMap<String, net.ess3.storage.Location>()); + user.getData().setHomes(new HashMap<String, net.ess3.storage.StoredLocation>()); } - user.getData().getHomes().put(args[0].toLowerCase(Locale.ENGLISH), new net.ess3.storage.Location(user.getLocation())); + user.getData().getHomes().put(args[0].toLowerCase(Locale.ENGLISH), new net.ess3.storage.StoredLocation(user.getLocation())); } else { @@ -74,9 +74,9 @@ public class Commandsethome extends EssentialsCommand usersHome.acquireWriteLock(); if (usersHome.getData().getHomes() == null) { - usersHome.getData().setHomes(new HashMap<String, net.ess3.storage.Location>()); + usersHome.getData().setHomes(new HashMap<String, net.ess3.storage.StoredLocation>()); } - usersHome.getData().getHomes().put(name, new net.ess3.storage.Location(user.getLocation())); + usersHome.getData().getHomes().put(name, new net.ess3.storage.StoredLocation(user.getLocation())); } } } @@ -85,9 +85,9 @@ public class Commandsethome extends EssentialsCommand user.acquireWriteLock(); if (user.getData().getHomes() == null) { - user.getData().setHomes(new HashMap<String, net.ess3.storage.Location>()); + user.getData().setHomes(new HashMap<String, net.ess3.storage.StoredLocation>()); } - user.getData().getHomes().put("home", new net.ess3.storage.Location(user.getLocation())); + user.getData().getHomes().put("home", new net.ess3.storage.StoredLocation(user.getLocation())); } user.sendMessage(_("homeSet", user.getLocation().getWorld().getName(), user.getLocation().getBlockX(), user.getLocation().getBlockY(), user.getLocation().getBlockZ())); diff --git a/Essentials/src/net/ess3/commands/Commandsetwarp.java b/Essentials/src/net/ess3/commands/Commandsetwarp.java index 18f0a9701..97387b80c 100644 --- a/Essentials/src/net/ess3/commands/Commandsetwarp.java +++ b/Essentials/src/net/ess3/commands/Commandsetwarp.java @@ -4,6 +4,7 @@ import static net.ess3.I18n._; import net.ess3.api.IUser; import net.ess3.api.IWarps; import net.ess3.permissions.WarpPermissions; +//TODO - Remove bukkit import org.bukkit.Location; @@ -34,7 +35,6 @@ public class Commandsetwarp extends EssentialsCommand { } - //todo permissions if (warpLoc == null || WarpPermissions.getPermission("overwrite." + args[0]).isAuthorized(user)) { diff --git a/Essentials/src/net/ess3/commands/Commandsetworth.java b/Essentials/src/net/ess3/commands/Commandsetworth.java index 68fb2481e..d93c3c0cb 100644 --- a/Essentials/src/net/ess3/commands/Commandsetworth.java +++ b/Essentials/src/net/ess3/commands/Commandsetworth.java @@ -2,7 +2,6 @@ package net.ess3.commands; import static net.ess3.I18n._; import net.ess3.api.IUser; -import org.bukkit.command.CommandSender; import org.bukkit.inventory.ItemStack; @@ -35,7 +34,7 @@ public class Commandsetworth extends EssentialsCommand } @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { diff --git a/Essentials/src/net/ess3/commands/Commandspawn.java b/Essentials/src/net/ess3/commands/Commandspawn.java index 74e15ea6a..f1bb51b74 100644 --- a/Essentials/src/net/ess3/commands/Commandspawn.java +++ b/Essentials/src/net/ess3/commands/Commandspawn.java @@ -6,7 +6,6 @@ import net.ess3.economy.Trade; import net.ess3.permissions.Permissions; import net.ess3.settings.SpawnsHolder; import org.bukkit.Location; -import org.bukkit.command.CommandSender; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; diff --git a/Essentials/src/net/ess3/commands/Commandspawner.java b/Essentials/src/net/ess3/commands/Commandspawner.java index b7d98a6e3..8d0993cb1 100644 --- a/Essentials/src/net/ess3/commands/Commandspawner.java +++ b/Essentials/src/net/ess3/commands/Commandspawner.java @@ -1,15 +1,13 @@ package net.ess3.commands; -import java.util.Locale; -import lombok.Cleanup; import static net.ess3.I18n._; -import net.ess3.api.ISettings; -import net.ess3.api.IUser; import net.ess3.bukkit.Mob; import net.ess3.economy.Trade; +import net.ess3.api.IUser; import net.ess3.permissions.SpawnerPermissions; import net.ess3.utils.LocationUtil; import net.ess3.utils.Util; +import java.util.Locale; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.CreatureSpawner; @@ -31,38 +29,30 @@ public class Commandspawner extends EssentialsCommand throw new Exception(_("mobSpawnTarget")); } - String name = args[0]; - - Mob mob = null; - mob = Mob.fromName(name); - if (mob == null) - { - throw new Exception(_("invalidMob")); - } - @Cleanup - ISettings settings = ess.getSettings(); - settings.acquireReadLock(); - if (settings.getData().getWorldOptions(user.getWorld().getName()).getPreventSpawn(mob.getType().toString().toLowerCase(Locale.ENGLISH))) - { - throw new Exception(_("disabledToSpawnMob")); - } - if (!SpawnerPermissions.getPermission(mob.name.toLowerCase(Locale.ENGLISH)).isAuthorized(user)) - { - throw new Exception(_("noPermToSpawnMob")); - } - final Trade charge = new Trade("spawner-" + mob.name.toLowerCase(Locale.ENGLISH), ess); - charge.isAffordableFor(user); try { + String name = args[0]; + + Mob mob = null; + mob = Mob.fromName(name); + if (mob == null) + { + user.sendMessage(_("invalidMob")); + return; + } + if (!SpawnerPermissions.getPermission(mob.name).isAuthorized(user)) + { + throw new Exception(_("unableToSpawnMob")); + } + final Trade charge = new Trade("spawner-" + mob.name.toLowerCase(Locale.ENGLISH), ess); + charge.isAffordableFor(user); ((CreatureSpawner)target.getBlock().getState()).setSpawnedType(mob.getType()); - + charge.charge(user); + user.sendMessage(_("setSpawner", mob.name)); } catch (Throwable ex) { throw new Exception(_("mobSpawnError"), ex); } - charge.charge(user); - user.sendMessage(_("setSpawner", mob.name)); - } } diff --git a/Essentials/src/net/ess3/commands/Commandspawnmob.java b/Essentials/src/net/ess3/commands/Commandspawnmob.java index 00b1abd00..8c2a9bee0 100644 --- a/Essentials/src/net/ess3/commands/Commandspawnmob.java +++ b/Essentials/src/net/ess3/commands/Commandspawnmob.java @@ -18,7 +18,7 @@ import org.bukkit.block.Block; import org.bukkit.entity.Villager.Profession; import org.bukkit.entity.*; import org.bukkit.material.Colorable; - +//TODO - Bukkit cleanup public class Commandspawnmob extends EssentialsCommand { diff --git a/Essentials/src/net/ess3/commands/Commandsudo.java b/Essentials/src/net/ess3/commands/Commandsudo.java index 45d9d5ced..d77241348 100644 --- a/Essentials/src/net/ess3/commands/Commandsudo.java +++ b/Essentials/src/net/ess3/commands/Commandsudo.java @@ -2,15 +2,14 @@ package net.ess3.commands; import static net.ess3.I18n._; import net.ess3.api.IUser; +import net.ess3.api.server.CommandSender; import net.ess3.permissions.Permissions; -import org.bukkit.command.CommandSender; -import org.bukkit.command.PluginCommand; public class Commandsudo extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { @@ -32,6 +31,7 @@ public class Commandsudo extends EssentialsCommand sender.sendMessage(_("sudoRun", user.getDisplayName(), command, getFinalArg(arguments, 0))); + ess.getServer().dispatchCommand(user, command); final PluginCommand execCommand = ess.getServer().getPluginCommand(command); if (execCommand != null) { diff --git a/Essentials/src/net/ess3/commands/Commandsuicide.java b/Essentials/src/net/ess3/commands/Commandsuicide.java index 979341053..c9598ee3e 100644 --- a/Essentials/src/net/ess3/commands/Commandsuicide.java +++ b/Essentials/src/net/ess3/commands/Commandsuicide.java @@ -2,7 +2,6 @@ package net.ess3.commands; import static net.ess3.I18n._; import net.ess3.api.IUser; -import org.bukkit.event.entity.EntityDamageEvent; public class Commandsuicide extends EssentialsCommand @@ -10,8 +9,7 @@ public class Commandsuicide extends EssentialsCommand @Override public void run(final IUser user, final String commandLabel, final String[] args) throws Exception { - EntityDamageEvent ede = new EntityDamageEvent(user.getBase(), EntityDamageEvent.DamageCause.SUICIDE, 1000); - server.getPluginManager().callEvent(ede); + ess.getPlugin().callSuicideEvent(user.getBase()); user.damage(Short.MAX_VALUE); user.sendMessage(_("suicideMessage")); user.setDisplayNick(); diff --git a/Essentials/src/net/ess3/commands/Commandtempban.java b/Essentials/src/net/ess3/commands/Commandtempban.java index 610759b7a..209ab8098 100644 --- a/Essentials/src/net/ess3/commands/Commandtempban.java +++ b/Essentials/src/net/ess3/commands/Commandtempban.java @@ -2,18 +2,18 @@ package net.ess3.commands; import net.ess3.Console; import static net.ess3.I18n._; + import net.ess3.api.IUser; import net.ess3.permissions.Permissions; import net.ess3.user.Ban; import net.ess3.utils.DateUtil; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; public class Commandtempban extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { diff --git a/Essentials/src/net/ess3/commands/Commandtime.java b/Essentials/src/net/ess3/commands/Commandtime.java index 29cfda36a..5a1a5b410 100644 --- a/Essentials/src/net/ess3/commands/Commandtime.java +++ b/Essentials/src/net/ess3/commands/Commandtime.java @@ -7,14 +7,13 @@ import net.ess3.permissions.Permissions; import net.ess3.utils.DescParseTickFormat; import net.ess3.utils.Util; import org.bukkit.World; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; public class Commandtime extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { boolean add = false; final List<String> argList = new ArrayList<String>(Arrays.asList(args)); diff --git a/Essentials/src/net/ess3/commands/Commandtogglejail.java b/Essentials/src/net/ess3/commands/Commandtogglejail.java index 04d4609a8..ca781c23f 100644 --- a/Essentials/src/net/ess3/commands/Commandtogglejail.java +++ b/Essentials/src/net/ess3/commands/Commandtogglejail.java @@ -1,18 +1,18 @@ package net.ess3.commands; -import lombok.Cleanup; import static net.ess3.I18n._; + import net.ess3.api.IUser; import net.ess3.permissions.Permissions; import net.ess3.user.UserData.TimestampType; import net.ess3.utils.DateUtil; -import org.bukkit.command.CommandSender; +import lombok.Cleanup; public class Commandtogglejail extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/net/ess3/commands/Commandtop.java b/Essentials/src/net/ess3/commands/Commandtop.java index c45ca0864..66c142120 100644 --- a/Essentials/src/net/ess3/commands/Commandtop.java +++ b/Essentials/src/net/ess3/commands/Commandtop.java @@ -1,8 +1,8 @@ package net.ess3.commands; import static net.ess3.I18n._; -import net.ess3.api.IUser; import net.ess3.economy.Trade; +import net.ess3.api.IUser; import org.bukkit.Location; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; diff --git a/Essentials/src/net/ess3/commands/Commandtp.java b/Essentials/src/net/ess3/commands/Commandtp.java index 606b2b4d6..27744d571 100644 --- a/Essentials/src/net/ess3/commands/Commandtp.java +++ b/Essentials/src/net/ess3/commands/Commandtp.java @@ -8,7 +8,6 @@ import net.ess3.api.IUser; import net.ess3.economy.Trade; import net.ess3.permissions.Permissions; import net.ess3.permissions.WorldPermissions; -import org.bukkit.command.CommandSender; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -77,7 +76,7 @@ public class Commandtp extends EssentialsCommand } @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { diff --git a/Essentials/src/net/ess3/commands/Commandtpaall.java b/Essentials/src/net/ess3/commands/Commandtpaall.java index 7b81f2b8b..5517fad6d 100644 --- a/Essentials/src/net/ess3/commands/Commandtpaall.java +++ b/Essentials/src/net/ess3/commands/Commandtpaall.java @@ -5,14 +5,13 @@ import static net.ess3.I18n._; import net.ess3.api.ISettings; import net.ess3.api.IUser; import net.ess3.permissions.WorldPermissions; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; public class Commandtpaall extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/net/ess3/commands/Commandtpaccept.java b/Essentials/src/net/ess3/commands/Commandtpaccept.java index 330cf0f70..7aaa58f3e 100644 --- a/Essentials/src/net/ess3/commands/Commandtpaccept.java +++ b/Essentials/src/net/ess3/commands/Commandtpaccept.java @@ -1,12 +1,10 @@ package net.ess3.commands; -import lombok.Cleanup; import static net.ess3.I18n._; +import net.ess3.economy.Trade; import net.ess3.api.ISettings; import net.ess3.api.IUser; -import net.ess3.economy.Trade; import net.ess3.permissions.Permissions; -import net.ess3.permissions.WorldPermissions; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -15,30 +13,45 @@ public class Commandtpaccept extends EssentialsCommand @Override public void run(final IUser user, final String commandLabel, final String[] args) throws Exception { + if (user.getTeleportRequester() == null) + { + throw new Exception(_("noPendingRequest")); + } + final IUser target = user.getTeleportRequester(); - @Cleanup + if (target == null + || !target.isOnline() + || (user.isTeleportRequestHere() && !Permissions.TPAHERE.isAuthorized(target)) + || (!user.isTeleportRequestHere() && !Permissions.TPA.isAuthorized(target) && !Permissions.TPAALL.isAuthorized(target))) + { + throw new Exception(_("noPendingRequest")); + } + + if (args.length > 0 && !target.getName().contains(args[0])) + { + throw new Exception(_("noPendingRequest")); + } + + int tpaAcceptCancellation = 0; ISettings settings = ess.getSettings(); settings.acquireReadLock(); - if (target == null || !target.isOnline() - || (args.length > 0 && !target.getName().contains(args[0])) - || (user.isTpRequestHere() && !Permissions.TPAHERE.isAuthorized(target)) - || (!user.isTpRequestHere() && ((!Permissions.TPA.isAuthorized(target) && !Permissions.TPAALL.isAuthorized(target)) - || (user.getWorld() != target.getWorld() - && settings.getData().getGeneral().isWorldTeleportPermissions() - && !WorldPermissions.getPermission(user.getWorld().getName()).isAuthorized(user))))) + try { - throw new Exception(_("noPendingRequest")); + tpaAcceptCancellation = settings.getData().getCommands().getTpa().getTimeout(); + } + finally + { + settings.unlock(); } - long timeout = settings.getData().getCommands().getTpa().getTimeout(); - if (timeout != 0 && (System.currentTimeMillis() - user.getTeleportRequestTime()) / 1000 > timeout) + if (tpaAcceptCancellation != 0 && (System.currentTimeMillis() - user.getTeleportRequestTime()) / 1000 > tpaAcceptCancellation) { user.requestTeleport(null, false); throw new Exception(_("requestTimedOut")); } - final Trade charge = new Trade(this.commandName, ess); - if (user.isTpRequestHere()) + final Trade charge = new Trade(commandName, ess); + if (user.isTeleportRequestHere()) { charge.isAffordableFor(user); } @@ -49,7 +62,7 @@ public class Commandtpaccept extends EssentialsCommand user.sendMessage(_("requestAccepted")); target.sendMessage(_("requestAcceptedFrom", user.getDisplayName())); - if (user.isTpRequestHere()) + if (user.isTeleportRequestHere()) { user.getTeleport().teleport(target, charge, TeleportCause.COMMAND); } diff --git a/Essentials/src/net/ess3/commands/Commandtpall.java b/Essentials/src/net/ess3/commands/Commandtpall.java index df5f7d526..2926b4a8c 100644 --- a/Essentials/src/net/ess3/commands/Commandtpall.java +++ b/Essentials/src/net/ess3/commands/Commandtpall.java @@ -13,7 +13,7 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; public class Commandtpall extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/net/ess3/commands/Commandtphere.java b/Essentials/src/net/ess3/commands/Commandtphere.java index 78f4cd748..c628c3519 100644 --- a/Essentials/src/net/ess3/commands/Commandtphere.java +++ b/Essentials/src/net/ess3/commands/Commandtphere.java @@ -1,11 +1,9 @@ package net.ess3.commands; -import lombok.Cleanup; import static net.ess3.I18n._; -import net.ess3.api.ISettings; -import net.ess3.api.IUser; import net.ess3.economy.Trade; -import net.ess3.permissions.WorldPermissions; +import net.ess3.api.IUser; +import lombok.Cleanup; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -21,15 +19,7 @@ public class Commandtphere extends EssentialsCommand { throw new Exception(_("teleportDisabled", player.getDisplayName())); } - @Cleanup - ISettings settings = ess.getSettings(); - settings.acquireReadLock(); - if (user.getWorld() != player.getWorld() && settings.getData().getGeneral().isWorldTeleportPermissions() - && !WorldPermissions.getPermission(user.getWorld().getName()).isAuthorized(user)) - { - throw new Exception(_("noPerm", "essentials.world." + user.getWorld().getName())); - } - player.getTeleport().teleport(user, new Trade(this.commandName, ess), TeleportCause.COMMAND); + player.getTeleport().teleport(user, new Trade(commandName, ess), TeleportCause.COMMAND); user.sendMessage(_("teleporting")); player.sendMessage(_("teleporting")); throw new NoChargeException(); diff --git a/Essentials/src/net/ess3/commands/Commandtpo.java b/Essentials/src/net/ess3/commands/Commandtpo.java index 7eba0262f..529fbd8f8 100644 --- a/Essentials/src/net/ess3/commands/Commandtpo.java +++ b/Essentials/src/net/ess3/commands/Commandtpo.java @@ -1,11 +1,8 @@ package net.ess3.commands; -import lombok.Cleanup; import static net.ess3.I18n._; -import net.ess3.api.ISettings; import net.ess3.api.IUser; import net.ess3.permissions.Permissions; -import net.ess3.permissions.WorldPermissions; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -14,54 +11,28 @@ public class Commandtpo extends EssentialsCommand @Override public void run(final IUser user, final String commandLabel, final String[] args) throws Exception { - @Cleanup - ISettings settings = ess.getSettings(); - switch (args.length) + if (args.length < 1) { - case 0: throw new NotEnoughArgumentsException(); + } - case 1: - final IUser player = getPlayer(args, 0, true); - if (!player.isOnline() || (player.isHidden() && !Permissions.TELEPORT_HIDDEN.isAuthorized(player))) - { - throw new NoSuchFieldException(_("playerNotFound")); - } - settings.acquireReadLock(); - if (user.getWorld() != player.getWorld() && settings.getData().getGeneral().isWorldTeleportPermissions() - && !WorldPermissions.getPermission(player.getWorld().getName()).isAuthorized(player)) - { - throw new Exception(_("noPerm", "essentials.world." + player.getWorld().getName())); - } + //Just basically the old tp command + final IUser player = getPlayer(args, 0, true); + // Check if user is offline + if (!player.isOnline()) + { + throw new NoSuchFieldException(_("playerNotFound")); + } - user.sendMessage(_("teleporting")); + // Verify permission + if (!player.isHidden() || Permissions.TELEPORT_HIDDEN.isAuthorized(user)) + { user.getTeleport().now(player, false, TeleportCause.COMMAND); - break; - - default: - if (!Permissions.TELEPORT_OTHERS.isAuthorized(user)) - { - throw new Exception(_("noPerm", "essentials.tp.others")); - } user.sendMessage(_("teleporting")); - final IUser target = getPlayer(args, 0, true); - final IUser toPlayer = getPlayer(args, 1, true); - - if (!target.isOnline() || !toPlayer.isOnline() - || ((target.isHidden() || toPlayer.isHidden()) && !Permissions.TELEPORT_HIDDEN.isAuthorized(user))) - { - throw new NoSuchFieldException(_("playerNotFound")); - } - settings.acquireReadLock(); - if (target.getWorld() != toPlayer.getWorld() && settings.getData().getGeneral().isWorldTeleportPermissions() - && !WorldPermissions.getPermission(toPlayer.getWorld().getName()).isAuthorized(user)) - { - throw new Exception(_("noPerm", "essentials.world." + toPlayer.getWorld().getName())); - } - - target.getTeleport().now(toPlayer, false, TeleportCause.COMMAND); - target.sendMessage(_("teleportAtoB", user.getDisplayName(), toPlayer.getDisplayName())); - break; + } + else + { + throw new NoSuchFieldException(_("playerNotFound")); } } } diff --git a/Essentials/src/net/ess3/commands/Commandtppos.java b/Essentials/src/net/ess3/commands/Commandtppos.java index bbd0777ca..907292b8e 100644 --- a/Essentials/src/net/ess3/commands/Commandtppos.java +++ b/Essentials/src/net/ess3/commands/Commandtppos.java @@ -4,7 +4,6 @@ import static net.ess3.I18n._; import net.ess3.api.IUser; import net.ess3.economy.Trade; import org.bukkit.Location; -import org.bukkit.command.CommandSender; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; diff --git a/Essentials/src/net/ess3/commands/Commandunban.java b/Essentials/src/net/ess3/commands/Commandunban.java index 9843deb8f..4f2fe8fb6 100644 --- a/Essentials/src/net/ess3/commands/Commandunban.java +++ b/Essentials/src/net/ess3/commands/Commandunban.java @@ -3,13 +3,12 @@ package net.ess3.commands; import lombok.Cleanup; import static net.ess3.I18n._; import net.ess3.api.IUser; -import org.bukkit.command.CommandSender; public class Commandunban extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/net/ess3/commands/Commandunbanip.java b/Essentials/src/net/ess3/commands/Commandunbanip.java index d4c6570c9..4c5975eb5 100644 --- a/Essentials/src/net/ess3/commands/Commandunbanip.java +++ b/Essentials/src/net/ess3/commands/Commandunbanip.java @@ -3,13 +3,12 @@ package net.ess3.commands; import lombok.Cleanup; import static net.ess3.I18n._; import net.ess3.api.IUser; -import org.bukkit.command.CommandSender; public class Commandunbanip extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/net/ess3/commands/Commandunlimited.java b/Essentials/src/net/ess3/commands/Commandunlimited.java index 6c5ff22a6..88115ab64 100644 --- a/Essentials/src/net/ess3/commands/Commandunlimited.java +++ b/Essentials/src/net/ess3/commands/Commandunlimited.java @@ -1,15 +1,14 @@ package net.ess3.commands; -import java.util.Locale; -import java.util.Set; -import lombok.Cleanup; import static net.ess3.I18n._; import net.ess3.api.IUser; -import net.ess3.craftbukkit.InventoryWorkaround; +import net.ess3.api.server.ItemStack; +import net.ess3.api.server.Material; import net.ess3.permissions.Permissions; import net.ess3.permissions.UnlimitedItemPermissions; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; +import java.util.Locale; +import java.util.Set; +import lombok.Cleanup; public class Commandunlimited extends EssentialsCommand @@ -42,7 +41,7 @@ public class Commandunlimited extends EssentialsCommand final Set<Material> itemList = target.getData().getUnlimited(); for(Material mat : itemList) { - toggleUnlimited(user, target, mat.name()); + toggleUnlimited(user, target, mat.getName()); } } @@ -69,7 +68,7 @@ public class Commandunlimited extends EssentialsCommand output.append(", "); } first = false; - final String matname = mater.name().toLowerCase(Locale.ENGLISH).replace("_", ""); + final String matname = mater.getName().toLowerCase(Locale.ENGLISH).replace("_", ""); output.append(matname); } @@ -93,7 +92,7 @@ public class Commandunlimited extends EssentialsCommand { message = "enableUnlimited"; enableUnlimited = true; - if (!InventoryWorkaround.containsItem(target.getInventory(), true, true, stack)) + if (!target.getInventory().containsItem(true, true, stack)) { target.getInventory().addItem(stack); } diff --git a/Essentials/src/net/ess3/commands/Commandwarp.java b/Essentials/src/net/ess3/commands/Commandwarp.java index 6176280f6..c01bc8354 100644 --- a/Essentials/src/net/ess3/commands/Commandwarp.java +++ b/Essentials/src/net/ess3/commands/Commandwarp.java @@ -1,17 +1,17 @@ package net.ess3.commands; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; import static net.ess3.I18n._; +import net.ess3.economy.Trade; +import net.ess3.utils.Util; import net.ess3.api.IUser; import net.ess3.api.IWarps; -import net.ess3.economy.Trade; import net.ess3.permissions.Permissions; import net.ess3.permissions.WarpPermissions; -import net.ess3.utils.Util; -import org.bukkit.command.CommandSender; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; + import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -50,7 +50,7 @@ public class Commandwarp extends EssentialsCommand } @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2 || args[0].matches("[0-9]+")) { diff --git a/Essentials/src/net/ess3/commands/Commandweather.java b/Essentials/src/net/ess3/commands/Commandweather.java index eb4f2b707..7ed487873 100644 --- a/Essentials/src/net/ess3/commands/Commandweather.java +++ b/Essentials/src/net/ess3/commands/Commandweather.java @@ -2,8 +2,8 @@ package net.ess3.commands; import static net.ess3.I18n._; import net.ess3.api.IUser; -import org.bukkit.World; -import org.bukkit.command.CommandSender; +import net.ess3.api.server.CommandSender; +import net.ess3.api.server.World; public class Commandweather extends EssentialsCommand diff --git a/Essentials/src/net/ess3/commands/Commandwhois.java b/Essentials/src/net/ess3/commands/Commandwhois.java index 98084479e..dee99fdc7 100644 --- a/Essentials/src/net/ess3/commands/Commandwhois.java +++ b/Essentials/src/net/ess3/commands/Commandwhois.java @@ -1,5 +1,7 @@ package net.ess3.commands; +import net.ess3.api.server.CommandSender; +import net.ess3.api.server.Player; import java.util.Locale; import lombok.Cleanup; import static net.ess3.I18n._; @@ -10,14 +12,13 @@ import net.ess3.permissions.Permissions; import net.ess3.user.UserData; import net.ess3.utils.DateUtil; import net.ess3.utils.Util; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; + public class Commandwhois extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -44,7 +45,7 @@ public class Commandwhois extends EssentialsCommand for (Player onlinePlayer : server.getOnlinePlayers()) { @Cleanup - final IUser user = ess.getUser(onlinePlayer); + final IUser user = onlinePlayer.getUser(); if (user.isHidden() && !showhidden) { diff --git a/Essentials/src/net/ess3/commands/Commandworld.java b/Essentials/src/net/ess3/commands/Commandworld.java index 50c5886d7..261b2914e 100644 --- a/Essentials/src/net/ess3/commands/Commandworld.java +++ b/Essentials/src/net/ess3/commands/Commandworld.java @@ -1,12 +1,12 @@ package net.ess3.commands; -import java.util.List; import static net.ess3.I18n._; -import net.ess3.api.IUser; import net.ess3.economy.Trade; +import net.ess3.api.IUser; +import net.ess3.api.server.World; +import net.ess3.api.server.Location; import net.ess3.permissions.WorldPermissions; -import org.bukkit.Location; -import org.bukkit.World; +import java.util.List; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -71,7 +71,7 @@ public class Commandworld extends EssentialsCommand } final Location loc = user.getLocation(); - final Location target = new Location(world, loc.getBlockX() * factor + .5, loc.getBlockY(), loc.getBlockZ() * factor + .5); + final Location target = Location.create(world, loc.getBlockX() * factor + .5, loc.getBlockY(), loc.getBlockZ() * factor + .5); final Trade charge = new Trade(commandName, ess); charge.isAffordableFor(user); diff --git a/Essentials/src/net/ess3/commands/Commandworth.java b/Essentials/src/net/ess3/commands/Commandworth.java index 10ea2c25e..9b0939f8f 100644 --- a/Essentials/src/net/ess3/commands/Commandworth.java +++ b/Essentials/src/net/ess3/commands/Commandworth.java @@ -1,11 +1,10 @@ package net.ess3.commands; -import java.util.Locale; import static net.ess3.I18n._; -import net.ess3.api.IUser; import net.ess3.utils.Util; -import org.bukkit.command.CommandSender; -import org.bukkit.inventory.ItemStack; +import net.ess3.api.IUser; +import net.ess3.api.server.ItemStack; +import java.util.Locale; public class Commandworth extends EssentialsCommand @@ -14,7 +13,7 @@ public class Commandworth extends EssentialsCommand @Override public void run(final IUser user, final String commandLabel, final String[] args) throws Exception { - ItemStack iStack = user.getInventory().getItemInHand(); + ItemStack iStack = user.getItemInHand(); int amount = iStack.getAmount(); if (args.length > 0) diff --git a/Essentials/src/net/ess3/commands/EssentialsCommand.java b/Essentials/src/net/ess3/commands/EssentialsCommand.java index cca9e1103..d54e3d309 100644 --- a/Essentials/src/net/ess3/commands/EssentialsCommand.java +++ b/Essentials/src/net/ess3/commands/EssentialsCommand.java @@ -1,18 +1,17 @@ package net.ess3.commands; -import java.util.List; -import java.util.logging.Logger; import static net.ess3.I18n._; import net.ess3.api.IEssentials; import net.ess3.api.IEssentialsModule; import net.ess3.api.IUser; +import net.ess3.api.server.CommandSender; +import net.ess3.api.server.IServer; +import net.ess3.api.server.Player; import net.ess3.economy.Trade; import net.ess3.permissions.AbstractSuperpermsPermission; -import org.bukkit.Server; +import java.util.List; +import java.util.logging.Logger; import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.Permission; public abstract class EssentialsCommand extends AbstractSuperpermsPermission implements IEssentialsCommand @@ -20,10 +19,9 @@ public abstract class EssentialsCommand extends AbstractSuperpermsPermission imp protected transient String commandName; protected transient IEssentials ess; protected transient IEssentialsModule module; - protected transient Server server; + protected transient IServer server; protected transient Logger logger; private transient String permission; - private transient Permission bukkitPerm; public void init(final IEssentials ess, final String commandName) { @@ -70,13 +68,13 @@ public abstract class EssentialsCommand extends AbstractSuperpermsPermission imp { for (Player player : matches) { - final IUser userMatch = ess.getUser(player); + final IUser userMatch = player.getUser(); if (userMatch.getDisplayName().startsWith(args[pos]) && (getOffline || !userMatch.isHidden())) { return userMatch; } } - final IUser userMatch = ess.getUser(matches.get(0)); + final IUser userMatch = matches.get(0).getUser(); if (getOffline || !userMatch.isHidden()) { return userMatch; @@ -96,7 +94,7 @@ public abstract class EssentialsCommand extends AbstractSuperpermsPermission imp protected void run(final IUser user, final String commandLabel, final String[] args) throws Exception { - run((CommandSender)user.getBase(), commandLabel, args); + run((CommandSender)user, commandLabel, args); } @Override @@ -125,7 +123,7 @@ public abstract class EssentialsCommand extends AbstractSuperpermsPermission imp } @Override - public String getPermission() + public String getPermissionName() { return permission; } diff --git a/Essentials/src/net/ess3/commands/EssentialsCommandHandler.java b/Essentials/src/net/ess3/commands/EssentialsCommandHandler.java index 21d18d706..db2b63c3e 100644 --- a/Essentials/src/net/ess3/commands/EssentialsCommandHandler.java +++ b/Essentials/src/net/ess3/commands/EssentialsCommandHandler.java @@ -8,7 +8,6 @@ import net.ess3.api.*; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommandYamlParser; import org.bukkit.entity.Player; diff --git a/Essentials/src/net/ess3/commands/IEssentialsCommand.java b/Essentials/src/net/ess3/commands/IEssentialsCommand.java index 34f1ba020..2466b4c55 100644 --- a/Essentials/src/net/ess3/commands/IEssentialsCommand.java +++ b/Essentials/src/net/ess3/commands/IEssentialsCommand.java @@ -4,8 +4,8 @@ import net.ess3.api.IEssentials; import net.ess3.api.IEssentialsModule; import net.ess3.api.IPermission; import net.ess3.api.IUser; +import net.ess3.api.server.CommandSender; import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; public interface IEssentialsCommand extends IPermission diff --git a/Essentials/src/net/ess3/craftbukkit/SetExpFix.java b/Essentials/src/net/ess3/craftbukkit/SetExpFix.java index 17efe7514..90962bfcb 100644 --- a/Essentials/src/net/ess3/craftbukkit/SetExpFix.java +++ b/Essentials/src/net/ess3/craftbukkit/SetExpFix.java @@ -1,13 +1,11 @@ package net.ess3.craftbukkit; -import org.bukkit.entity.Player; - public class SetExpFix { //This method is used to update both the recorded total experience and displayed total experience. //We reset both types to prevent issues. - public static void setTotalExperience(final Player player, final int exp) + public static void setTotalExperience(final IPlayer player, final int exp) { if (exp < 0) { @@ -39,7 +37,7 @@ public class SetExpFix } } - private static int getExpToLevel(final Player player) + private static int getExpToLevel(final IPlayer player) { return getExpToLevel(player.getLevel()); } @@ -51,7 +49,7 @@ public class SetExpFix //This method is required because the bukkit player.getTotalExperience() method, shows exp that has been 'spent'. //Without this people would be able to use exp and then still sell it. - public static int getTotalExperience(final Player player) + public static int getTotalExperience(final IPlayer player) { int exp = (int)Math.round(getExpToLevel(player) * player.getExp()); int currentLevel = player.getLevel(); diff --git a/Essentials/src/net/ess3/economy/MoneyHolder.java b/Essentials/src/net/ess3/economy/MoneyHolder.java index c313e9645..386dae7af 100644 --- a/Essentials/src/net/ess3/economy/MoneyHolder.java +++ b/Essentials/src/net/ess3/economy/MoneyHolder.java @@ -31,6 +31,6 @@ public class MoneyHolder extends AsyncStorageObjectHolder<Money> @Override public File getStorageFile() throws IOException { - return new File(ess.getDataFolder(), "economy_npcs.yml"); + return new File(ess.getPlugin().getDataFolder(), "economy_npcs.yml"); } } diff --git a/Essentials/src/net/ess3/economy/Trade.java b/Essentials/src/net/ess3/economy/Trade.java index 7b527d46e..85d8e53f3 100644 --- a/Essentials/src/net/ess3/economy/Trade.java +++ b/Essentials/src/net/ess3/economy/Trade.java @@ -1,5 +1,14 @@ package net.ess3.economy; +import static net.ess3.I18n._; +import net.ess3.api.ChargeException; +import net.ess3.api.IEssentials; +import net.ess3.api.ISettings; +import net.ess3.api.IUser; +import net.ess3.api.server.ItemStack; +import net.ess3.api.server.Location; +import net.ess3.permissions.NoCommandCostPermissions; +import net.ess3.permissions.Permissions; import java.io.File; import java.io.FileWriter; import java.io.IOException; @@ -10,18 +19,7 @@ import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import lombok.Cleanup; -import static net.ess3.I18n._; -import net.ess3.api.ChargeException; -import net.ess3.api.IEssentials; -import net.ess3.api.ISettings; -import net.ess3.api.IUser; -import net.ess3.craftbukkit.InventoryWorkaround; -import net.ess3.craftbukkit.SetExpFix; -import net.ess3.permissions.NoCommandCostPermissions; -import net.ess3.permissions.Permissions; -import org.bukkit.Location; -import org.bukkit.entity.Item; -import org.bukkit.inventory.ItemStack; + public class Trade @@ -79,7 +77,7 @@ public class Trade } if (getItemStack() != null - && !InventoryWorkaround.containsItem(user.getInventory(), true, true, itemStack)) + && !user.getInventory().containsItem(true, true, itemStack)) { throw new ChargeException(_("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase(Locale.ENGLISH).replace("_", " "))); } @@ -97,7 +95,7 @@ public class Trade } if (exp != null && exp > 0 - && SetExpFix.getTotalExperience(user) < exp) + && user.getTotalExperience() < exp) { throw new ChargeException(_("notEnoughExperience")); } @@ -119,37 +117,37 @@ public class Trade { if (dropItems) { - final Map<Integer, ItemStack> leftOver = InventoryWorkaround.addItem(user.getInventory(), true, getItemStack()); + final Map<Integer, ItemStack> leftOver = user.getInventory().addItem(true, getItemStack()); final Location loc = user.getLocation(); for (ItemStack dropStack : leftOver.values()) { final int maxStackSize = dropStack.getType().getMaxStackSize(); final int stacks = dropStack.getAmount() / maxStackSize; final int leftover = dropStack.getAmount() % maxStackSize; - final Item[] itemStacks = new Item[stacks + (leftover > 0 ? 1 : 0)]; + final ItemStack[] itemStacks = new ItemStack[stacks + (leftover > 0 ? 1 : 0)]; for (int i = 0; i < stacks; i++) { final ItemStack stack = dropStack.clone(); stack.setAmount(maxStackSize); - itemStacks[i] = loc.getWorld().dropItem(loc, stack); + itemStacks[i] = user.getWorld().dropItem(loc, stack); } if (leftover > 0) { final ItemStack stack = dropStack.clone(); stack.setAmount(leftover); - itemStacks[stacks] = loc.getWorld().dropItem(loc, stack); + itemStacks[stacks] = user.getWorld().dropItem(loc, stack); } } } else { - success = InventoryWorkaround.addAllItems(user.getInventory(), true, getItemStack()); + success = user.getInventory().addAllItems(true, getItemStack()); } user.updateInventory(); } if (getExperience() != null) { - SetExpFix.setTotalExperience(user, SetExpFix.getTotalExperience(user) + getExperience()); + user.setTotalExperience(user.getTotalExperience() + getExperience()); } return success; } @@ -166,11 +164,11 @@ public class Trade } if (getItemStack() != null) { - if (!InventoryWorkaround.containsItem(user.getInventory(), true, true, itemStack)) + if (!user.getInventory().containsItem(true, true, itemStack)) { throw new ChargeException(_("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase(Locale.ENGLISH).replace("_", " "))); } - InventoryWorkaround.removeItem(user.getInventory(), true, true, getItemStack()); + user.getInventory().removeItem(true, true, getItemStack()); user.updateInventory(); } if (command != null && !command.isEmpty() @@ -188,12 +186,12 @@ public class Trade } if (getExperience() != null) { - final int experience = SetExpFix.getTotalExperience(user); + final int experience = user.getTotalExperience(); if (experience < getExperience() && getExperience() > 0) { throw new ChargeException(_("notEnoughExperience")); } - SetExpFix.setTotalExperience(user, experience - getExperience()); + user.setTotalExperience(experience - getExperience()); } } @@ -242,7 +240,7 @@ public class Trade { try { - fw = new FileWriter(new File(ess.getDataFolder(), "trade.log"), true); + fw = new FileWriter(new File(ess.getPlugin().getDataFolder(), "trade.log"), true); } catch (IOException ex) { diff --git a/Essentials/src/net/ess3/economy/WorthHolder.java b/Essentials/src/net/ess3/economy/WorthHolder.java index dfa3a28a1..fbd20360c 100644 --- a/Essentials/src/net/ess3/economy/WorthHolder.java +++ b/Essentials/src/net/ess3/economy/WorthHolder.java @@ -1,5 +1,6 @@ package net.ess3.economy; +import net.ess3.api.server.ItemStack; import java.io.File; import java.io.IOException; import java.util.HashMap; @@ -9,7 +10,6 @@ import net.ess3.api.IWorth; import net.ess3.storage.AsyncStorageObjectHolder; import net.ess3.storage.EnchantmentLevel; import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemStack; import org.bukkit.material.MaterialData; @@ -95,6 +95,6 @@ public class WorthHolder extends AsyncStorageObjectHolder<net.ess3.economy.Worth @Override public File getStorageFile() throws IOException { - return new File(ess.getDataFolder(), "worth.yml"); + return new File(ess.getPlugin().getDataFolder(), "worth.yml"); } } diff --git a/Essentials/src/net/ess3/listener/EssentialsBlockListener.java b/Essentials/src/net/ess3/listener/EssentialsBlockListener.java index 7f5f55c6e..5faaeeb3b 100644 --- a/Essentials/src/net/ess3/listener/EssentialsBlockListener.java +++ b/Essentials/src/net/ess3/listener/EssentialsBlockListener.java @@ -35,7 +35,7 @@ public class EssentialsBlockListener implements Listener final boolean unlimitedForUser = user.getData().hasUnlimited(itemstack.getType()); if (unlimitedForUser && user.getGameMode() == GameMode.SURVIVAL) { - ess.scheduleSyncDelayedTask( + ess.getPlugin().scheduleSyncDelayedTask( new Runnable() { @Override diff --git a/Essentials/src/net/ess3/listener/EssentialsEntityListener.java b/Essentials/src/net/ess3/listener/EssentialsEntityListener.java index a09078438..6677005bd 100644 --- a/Essentials/src/net/ess3/listener/EssentialsEntityListener.java +++ b/Essentials/src/net/ess3/listener/EssentialsEntityListener.java @@ -1,5 +1,10 @@ package net.ess3.listener; +import static net.ess3.I18n._; +import net.ess3.api.IEssentials; +import net.ess3.api.ISettings; +import net.ess3.api.IUser; +import net.ess3.permissions.Permissions; import java.util.List; import lombok.Cleanup; import static net.ess3.I18n._; diff --git a/Essentials/src/net/ess3/permissions/BasePermission.java b/Essentials/src/net/ess3/permissions/BasePermission.java index 71b18c034..c8198c1e2 100644 --- a/Essentials/src/net/ess3/permissions/BasePermission.java +++ b/Essentials/src/net/ess3/permissions/BasePermission.java @@ -9,7 +9,7 @@ public class BasePermission extends AbstractSuperpermsPermission { this.permission = base + permission; } - public String getPermission() + public String getPermissionName() { return permission; } diff --git a/Essentials/src/net/ess3/permissions/GivePermissions.java b/Essentials/src/net/ess3/permissions/GivePermissions.java index a4cdeb5f6..a3ced5155 100644 --- a/Essentials/src/net/ess3/permissions/GivePermissions.java +++ b/Essentials/src/net/ess3/permissions/GivePermissions.java @@ -1,14 +1,15 @@ package net.ess3.permissions; -import java.util.EnumMap; +import net.ess3.api.IPermission; +import net.ess3.api.server.Material; +import net.ess3.api.server.Permission; +import java.util.HashMap; import java.util.Locale; import java.util.Map; -import net.ess3.api.IPermission; -import org.bukkit.Material; -import org.bukkit.permissions.PermissionDefault; + public class GivePermissions { - private static Map<Material, IPermission> permissions = new EnumMap<Material, IPermission>(Material.class); + private static Map<Material, IPermission> permissions = new HashMap<Material, IPermission>(); public static IPermission getPermission(final Material mat) { @@ -18,9 +19,9 @@ public class GivePermissions { perm = new BasePermission("essentials.give.item-", mat.toString().toLowerCase(Locale.ENGLISH).replace("_", "")) { @Override - public PermissionDefault getPermissionDefault() + public Permission.Default getPermissionDefault() { - return PermissionDefault.TRUE; + return Permission.Default.TRUE; } }; permissions.put(mat, perm); diff --git a/Essentials/src/net/ess3/permissions/ItemPermissions.java b/Essentials/src/net/ess3/permissions/ItemPermissions.java index bcc77ef34..c0d4b587d 100644 --- a/Essentials/src/net/ess3/permissions/ItemPermissions.java +++ b/Essentials/src/net/ess3/permissions/ItemPermissions.java @@ -1,16 +1,17 @@ package net.ess3.permissions; -import java.util.EnumMap; +import net.ess3.api.IPermission; +import net.ess3.api.server.Material; +import net.ess3.api.server.Permission; +import java.util.HashMap; import java.util.Locale; import java.util.Map; -import net.ess3.api.IPermission; -import org.bukkit.Material; -import org.bukkit.permissions.PermissionDefault; + public class ItemPermissions { - private static Map<Material, IPermission> permissions = new EnumMap<Material, IPermission>(Material.class); + private static Map<Material, IPermission> permissions = new HashMap<Material, IPermission>(); public static IPermission getPermission(final Material mat) { @@ -20,9 +21,9 @@ public class ItemPermissions perm = new BasePermission("essentials.itemspawn.item-", mat.toString().toLowerCase(Locale.ENGLISH).replace("_", "")) { @Override - public PermissionDefault getPermissionDefault() + public Permission.Default getPermissionDefault() { - return PermissionDefault.TRUE; + return Permission.Default.TRUE; } }; permissions.put(mat, perm); diff --git a/Essentials/src/net/ess3/permissions/KitPermissions.java b/Essentials/src/net/ess3/permissions/KitPermissions.java index 00365aeac..fb02392c0 100644 --- a/Essentials/src/net/ess3/permissions/KitPermissions.java +++ b/Essentials/src/net/ess3/permissions/KitPermissions.java @@ -1,10 +1,10 @@ package net.ess3.permissions; +import net.ess3.api.IPermission; +import net.ess3.api.server.Permission; import java.util.HashMap; import java.util.Locale; import java.util.Map; -import net.ess3.api.IPermission; -import org.bukkit.permissions.PermissionDefault; public class KitPermissions @@ -19,9 +19,9 @@ public class KitPermissions perm = new BasePermission("essentials.kit.", kitName.toLowerCase(Locale.ENGLISH)) { @Override - public PermissionDefault getPermissionDefault() + public Permission.Default getPermissionDefault() { - return PermissionDefault.TRUE; + return Permission.Default.TRUE; } }; permissions.put(kitName, perm); diff --git a/Essentials/src/net/ess3/permissions/Permissions.java b/Essentials/src/net/ess3/permissions/Permissions.java index 05e971041..34fe88be4 100644 --- a/Essentials/src/net/ess3/permissions/Permissions.java +++ b/Essentials/src/net/ess3/permissions/Permissions.java @@ -1,11 +1,6 @@ package net.ess3.permissions; import java.util.Locale; -import net.ess3.api.IPermission; -import net.ess3.utils.Util; -import org.bukkit.command.CommandSender; -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionDefault; public enum Permissions implements IPermission @@ -24,7 +19,7 @@ public enum Permissions implements IPermission CHAT_SPY, CLEARINVENTORY_OTHERS, DELHOME_OTHERS, - ECO_LOAN(PermissionDefault.FALSE), + ECO_LOAN(Permission.Default.FALSE), EXP_GIVE, EXP_GIVE_OTHERS, EXP_SET, @@ -33,8 +28,8 @@ public enum Permissions implements IPermission FEED_OTHERS, FLY_OTHERS, GAMEMODE_OTHERS, - GEOIP_HIDE(PermissionDefault.FALSE), - GEOIP_SHOW(PermissionDefault.TRUE), + GEOIP_HIDE(Permission.Default.FALSE), + GEOIP_SHOW(Permission.Default.TRUE), GETPOS_OTHERS, GOD_OTHERS, HEAL_COOLDOWN_BYPASS, @@ -60,7 +55,7 @@ public enum Permissions implements IPermission NICK_COLOR, NICK_OTHERS, NOGOD_OVERRIDE, - OVERSIZEDSTACKS(PermissionDefault.FALSE), + OVERSIZEDSTACKS(Permission.Default.FALSE), POWERTOOL_APPEND, PTIME_OTHERS, PVPDELAY_EXEMPT, @@ -86,33 +81,33 @@ public enum Permissions implements IPermission TPAHERE, TPOHERE, UNLIMITED_OTHERS, - WARP_LIST(PermissionDefault.TRUE), + WARP_LIST(Permission.Default.TRUE), WARP_OTHERS, VANISH_SEE_OTHERS; private static final String base = "essentials."; private final String permission; - private final PermissionDefault defaultPerm; + private final Permission.Default defaultPerm; private transient Permission bukkitPerm = null; private Permissions() { - this(PermissionDefault.OP); + this(Permission.Default.OP); } - private Permissions(final PermissionDefault defaultPerm) + private Permissions(final Permission.Default defaultPerm) { permission = base + toString().toLowerCase(Locale.ENGLISH).replace('_', '.'); this.defaultPerm = defaultPerm; } @Override - public String getPermission() + public String getPermissionName() { return permission; } @Override - public Permission getBukkitPermission() + public Permission getPermission() { if (bukkitPerm != null) { @@ -120,12 +115,12 @@ public enum Permissions implements IPermission } else { - return Util.registerPermission(getPermission(), getPermissionDefault()); + return Permission.create(getPermissionName(), getPermissionDefault()); } } @Override - public PermissionDefault getPermissionDefault() + public Permission.Default getPermissionDefault() { return this.defaultPerm; } @@ -133,6 +128,6 @@ public enum Permissions implements IPermission @Override public boolean isAuthorized(CommandSender sender) { - return sender.hasPermission(getBukkitPermission()); + return sender.hasPermission(getPermission()); } } diff --git a/Essentials/src/net/ess3/permissions/UnlimitedItemPermissions.java b/Essentials/src/net/ess3/permissions/UnlimitedItemPermissions.java index e6c1b3bff..4387e6ba2 100644 --- a/Essentials/src/net/ess3/permissions/UnlimitedItemPermissions.java +++ b/Essentials/src/net/ess3/permissions/UnlimitedItemPermissions.java @@ -1,14 +1,14 @@ package net.ess3.permissions; -import java.util.EnumMap; +import net.ess3.api.IPermission; +import net.ess3.api.server.Material; +import java.util.HashMap; import java.util.Locale; import java.util.Map; -import net.ess3.api.IPermission; -import org.bukkit.Material; public class UnlimitedItemPermissions { - private static Map<Material, IPermission> permissions = new EnumMap<Material, IPermission>(Material.class); + private static Map<Material, IPermission> permissions = new HashMap<Material, IPermission>(); public static IPermission getPermission(final Material mat) { diff --git a/Essentials/src/net/ess3/permissions/WarpPermissions.java b/Essentials/src/net/ess3/permissions/WarpPermissions.java index c87d78437..fe977ccce 100644 --- a/Essentials/src/net/ess3/permissions/WarpPermissions.java +++ b/Essentials/src/net/ess3/permissions/WarpPermissions.java @@ -1,10 +1,10 @@ package net.ess3.permissions; +import net.ess3.api.IPermission; +import net.ess3.api.server.Permission; import java.util.HashMap; import java.util.Locale; import java.util.Map; -import net.ess3.api.IPermission; -import org.bukkit.permissions.PermissionDefault; public class WarpPermissions @@ -19,9 +19,9 @@ public class WarpPermissions perm = new BasePermission("essentials.warp.", warpName.toLowerCase(Locale.ENGLISH)) { @Override - public PermissionDefault getPermissionDefault() + public Permission.Default getPermissionDefault() { - return PermissionDefault.TRUE; + return Permission.Default.TRUE; } }; permissions.put(warpName, perm); diff --git a/Essentials/src/net/ess3/ranks/RanksStorage.java b/Essentials/src/net/ess3/ranks/RanksStorage.java index b4293bedf..c99deb535 100644 --- a/Essentials/src/net/ess3/ranks/RanksStorage.java +++ b/Essentials/src/net/ess3/ranks/RanksStorage.java @@ -40,7 +40,7 @@ public class RanksStorage extends AsyncStorageObjectHolder<Ranks> implements IRa @Override public File getStorageFile() { - return new File(ess.getDataFolder(), "ranks.yml"); + return new File(ess.getPlugin().getDataFolder(), "ranks.yml"); } public Collection<Entry<String, RankOptions>> getGroups(final IUser player) diff --git a/Essentials/src/net/ess3/ranks/VaultGroups.java b/Essentials/src/net/ess3/ranks/VaultGroups.java index c0710517c..d9558d62f 100644 --- a/Essentials/src/net/ess3/ranks/VaultGroups.java +++ b/Essentials/src/net/ess3/ranks/VaultGroups.java @@ -8,7 +8,6 @@ import net.ess3.api.ISettings; import net.ess3.api.IUser; import net.ess3.utils.Util; import net.milkbowl.vault.chat.Chat; -import org.bukkit.plugin.RegisteredServiceProvider; public class VaultGroups implements IRanks @@ -23,48 +22,42 @@ public class VaultGroups implements IRanks @Override public double getHealCooldown(IUser player) { - RegisteredServiceProvider<Chat> rsp = ess.getServer().getServicesManager().getRegistration(Chat.class); - Chat chat = rsp.getProvider(); + Chat chat = ess.getServer().getServiceProvider(Chat.class); return chat.getPlayerInfoDouble(player.getBase(), "healcooldown", 0); } @Override public double getTeleportCooldown(IUser player) { - RegisteredServiceProvider<Chat> rsp = ess.getServer().getServicesManager().getRegistration(Chat.class); - Chat chat = rsp.getProvider(); + Chat chat = ess.getServer().getServiceProvider(Chat.class); return chat.getPlayerInfoDouble(player.getBase(), "teleportcooldown", 0); } @Override public double getTeleportDelay(IUser player) { - RegisteredServiceProvider<Chat> rsp = ess.getServer().getServicesManager().getRegistration(Chat.class); - Chat chat = rsp.getProvider(); + Chat chat = ess.getServer().getServiceProvider(Chat.class); return chat.getPlayerInfoDouble(player.getBase(), "teleportdelay", 0); } @Override public String getPrefix(IUser player) { - RegisteredServiceProvider<Chat> rsp = ess.getServer().getServicesManager().getRegistration(Chat.class); - Chat chat = rsp.getProvider(); + Chat chat = ess.getServer().getServiceProvider(Chat.class); return chat.getPlayerPrefix(player.getBase()); } @Override public String getSuffix(IUser player) { - RegisteredServiceProvider<Chat> rsp = ess.getServer().getServicesManager().getRegistration(Chat.class); - Chat chat = rsp.getProvider(); + Chat chat = ess.getServer().getServiceProvider(Chat.class); return chat.getPlayerSuffix(player.getBase()); } @Override public int getHomeLimit(IUser player) { - RegisteredServiceProvider<Chat> rsp = ess.getServer().getServicesManager().getRegistration(Chat.class); - Chat chat = rsp.getProvider(); + Chat chat = ess.getServer().getServiceProvider(Chat.class); return chat.getPlayerInfoInteger(player.getBase(), "homes", 0); } @@ -85,8 +78,7 @@ public class VaultGroups implements IRanks private String getRawChatFormat(final IUser player) { - RegisteredServiceProvider<Chat> rsp = ess.getServer().getServicesManager().getRegistration(Chat.class); - Chat chat = rsp.getProvider(); + Chat chat = ess.getServer().getServiceProvider(Chat.class); String chatformat = chat.getPlayerInfoString(player.getBase(), "chatformat", ""); if (chatformat != null && !chatformat.isEmpty()) { @@ -102,16 +94,14 @@ public class VaultGroups implements IRanks @Override public String getMainGroup(IUser player) { - RegisteredServiceProvider<Chat> rsp = ess.getServer().getServicesManager().getRegistration(Chat.class); - Chat chat = rsp.getProvider(); + Chat chat = ess.getServer().getServiceProvider(Chat.class); return chat.getPrimaryGroup(player.getBase()); } @Override public boolean inGroup(IUser player, String groupname) { - RegisteredServiceProvider<Chat> rsp = ess.getServer().getServicesManager().getRegistration(Chat.class); - Chat chat = rsp.getProvider(); + Chat chat = ess.getServer().getServiceProvider(Chat.class); for (String group : chat.getPlayerGroups(player.getBase())) { if (group.equalsIgnoreCase(groupname)) diff --git a/Essentials/src/net/ess3/settings/General.java b/Essentials/src/net/ess3/settings/General.java index ccb91c0f2..caf8a15c2 100644 --- a/Essentials/src/net/ess3/settings/General.java +++ b/Essentials/src/net/ess3/settings/General.java @@ -92,6 +92,7 @@ public class General implements StorageObject return loginAttackDelay * 1000; } public boolean metricsEnabled = true; +//todo remove this @Comment("Prevent creatures spawning") private Map<EntityType, Boolean> creatureSpawn = new HashMap<EntityType, Boolean>(); diff --git a/Essentials/src/net/ess3/settings/SettingsHolder.java b/Essentials/src/net/ess3/settings/SettingsHolder.java index f12baa823..f161c2580 100644 --- a/Essentials/src/net/ess3/settings/SettingsHolder.java +++ b/Essentials/src/net/ess3/settings/SettingsHolder.java @@ -43,7 +43,7 @@ public class SettingsHolder extends AsyncStorageObjectHolder<Settings> implement @Override public File getStorageFile() { - return new File(ess.getDataFolder(), "settings.yml"); + return new File(ess.getPlugin().getDataFolder(), "settings.yml"); } @Override diff --git a/Essentials/src/net/ess3/settings/Spawns.java b/Essentials/src/net/ess3/settings/Spawns.java index 4c0239101..91dab36f9 100644 --- a/Essentials/src/net/ess3/settings/Spawns.java +++ b/Essentials/src/net/ess3/settings/Spawns.java @@ -35,6 +35,6 @@ public class Spawns implements StorageObject }) private String newbieSpawn = "none"; @Comment("List of all spawnpoints") - @MapValueType(Location.class) - private Map<String, Location> spawns = new HashMap<String, Location>(); + @MapValueType(StoredLocation.class) + private Map<String, StoredLocation> spawns = new HashMap<String, StoredLocation>(); } diff --git a/Essentials/src/net/ess3/settings/SpawnsHolder.java b/Essentials/src/net/ess3/settings/SpawnsHolder.java index cc63d98c8..4f43e5ab9 100644 --- a/Essentials/src/net/ess3/settings/SpawnsHolder.java +++ b/Essentials/src/net/ess3/settings/SpawnsHolder.java @@ -52,7 +52,7 @@ public class SpawnsHolder extends AsyncStorageObjectHolder<Spawns> implements IE @Override public File getStorageFile() { - return new File(ess.getDataFolder(), "spawn.yml"); + return new File(ess.getPlugin().getDataFolder(), "spawn.yml"); } public void setSpawn(final Location loc, final String group) @@ -62,9 +62,9 @@ public class SpawnsHolder extends AsyncStorageObjectHolder<Spawns> implements IE { if (getData().getSpawns() == null) { - getData().setSpawns(new HashMap<String, net.ess3.storage.Location>()); + getData().setSpawns(new HashMap<String, net.ess3.storage.StoredLocation>()); } - getData().getSpawns().put(group.toLowerCase(Locale.ENGLISH), new net.ess3.storage.Location(loc)); + getData().getSpawns().put(group.toLowerCase(Locale.ENGLISH), new net.ess3.storage.StoredLocation(loc)); } finally { @@ -86,7 +86,7 @@ public class SpawnsHolder extends AsyncStorageObjectHolder<Spawns> implements IE { return getWorldSpawn(); } - final Map<String, net.ess3.storage.Location> spawnMap = getData().getSpawns(); + final Map<String, net.ess3.storage.StoredLocation> spawnMap = getData().getSpawns(); String groupName = group.toLowerCase(Locale.ENGLISH); if (!spawnMap.containsKey(groupName)) { @@ -98,7 +98,7 @@ public class SpawnsHolder extends AsyncStorageObjectHolder<Spawns> implements IE } try { - return spawnMap.get(groupName).getBukkitLocation(); + return spawnMap.get(groupName).getStoredLocation(); } catch (WorldNotLoadedException ex) { @@ -273,7 +273,7 @@ public class SpawnsHolder extends AsyncStorageObjectHolder<Spawns> implements IE if (spawns.getNewbieSpawn() != null) { - ess.scheduleSyncDelayedTask(new NewPlayerTeleport(user), 1L); + ess.getPlugin().scheduleSyncDelayedTask(new NewPlayerTeleport(user), 1L); } if (spawns.getAnnounceNewPlayers()) diff --git a/Essentials/src/net/ess3/settings/WorldOptions.java b/Essentials/src/net/ess3/settings/WorldOptions.java index fe6cbaa8e..cc75a0e63 100644 --- a/Essentials/src/net/ess3/settings/WorldOptions.java +++ b/Essentials/src/net/ess3/settings/WorldOptions.java @@ -1,48 +1,14 @@ package net.ess3.settings; -import java.util.HashMap; -import java.util.Map; -import lombok.Data; -import lombok.EqualsAndHashCode; import net.ess3.storage.Comment; import net.ess3.storage.StorageObject; -import org.bukkit.entity.EntityType; - +import lombok.Data; +import lombok.EqualsAndHashCode; @Data @EqualsAndHashCode(callSuper = false) public class WorldOptions implements StorageObject { - public WorldOptions() - { - //Populate creature spawn values - for (EntityType t : EntityType.values()) - { - if (t.isAlive()) - { - creatureSpawn.put(t, false); - } - } - } - @Comment("Disables godmode for all players if they teleport to this world.") - private boolean godmode = true; - - @Comment("Prevent creatures spawning") - private Map<EntityType, Boolean> creatureSpawn = new HashMap<EntityType, Boolean>(); - - public boolean getPreventSpawn(String creatureName) - { - return getPreventSpawn(EntityType.fromName(creatureName)); - } - - public boolean getPreventSpawn(EntityType creature) - { - if (creatureSpawn == null) - { - return false; - } - return creatureSpawn.get(creature); - } - + private boolean godmode = true; } diff --git a/Essentials/src/net/ess3/settings/geoip/Database.java b/Essentials/src/net/ess3/settings/geoip/Database.java index 06c3821f8..3573a9e16 100644 --- a/Essentials/src/net/ess3/settings/geoip/Database.java +++ b/Essentials/src/net/ess3/settings/geoip/Database.java @@ -1,16 +1,16 @@ package net.ess3.settings.geoip; +import net.ess3.storage.StorageObject; import lombok.Data; import lombok.EqualsAndHashCode; -import net.ess3.storage.StorageObject; @Data @EqualsAndHashCode(callSuper = false) public class Database implements StorageObject { - private boolean showCities = false; - private boolean downloadIfMissing = true; - private String downloadUrlCity = "http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz"; - private String downloadUrl = "http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz"; + boolean showCities = false; + boolean downloadIfMissing = true; + String downloadUrlCity = "http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz"; + String downloadUrl = "http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz"; } diff --git a/Essentials/src/net/ess3/settings/protect/Prevent.java b/Essentials/src/net/ess3/settings/protect/Prevent.java index f99c43d21..7b50be568 100644 --- a/Essentials/src/net/ess3/settings/protect/Prevent.java +++ b/Essentials/src/net/ess3/settings/protect/Prevent.java @@ -1,12 +1,11 @@ package net.ess3.settings.protect; +import net.ess3.storage.*; +import java.util.HashMap; import java.util.HashSet; import java.util.Set; import lombok.Data; import lombok.EqualsAndHashCode; -import net.ess3.storage.Comment; -import net.ess3.storage.ListType; -import net.ess3.storage.StorageObject; import org.bukkit.Material; diff --git a/Essentials/src/net/ess3/storage/AbstractDelayedYamlFileReader.java b/Essentials/src/net/ess3/storage/AbstractDelayedYamlFileReader.java index 58fcb6020..47d6bf85a 100644 --- a/Essentials/src/net/ess3/storage/AbstractDelayedYamlFileReader.java +++ b/Essentials/src/net/ess3/storage/AbstractDelayedYamlFileReader.java @@ -15,24 +15,24 @@ public abstract class AbstractDelayedYamlFileReader<T extends StorageObject> imp { private final transient Class<T> clazz; - protected final transient IEssentials plugin; + private final transient IEssentials ess; private final transient ReentrantLock lock = new ReentrantLock(); public AbstractDelayedYamlFileReader(final IEssentials ess, final Class<T> clazz) { this.clazz = clazz; - this.plugin = ess; + this.ess = ess; } public void schedule(boolean instant) { - if (instant || ((Essentials)plugin).testing) + if (instant) { run(); } else { - plugin.getServer().getScheduler().scheduleAsyncDelayedTask(plugin, this); + ess.getPlugin().scheduleAsyncDelayedTask(this); } } @@ -51,7 +51,7 @@ public abstract class AbstractDelayedYamlFileReader<T extends StorageObject> imp final FileReader reader = new FileReader(file); try { - final T object = new YamlStorageReader(reader, plugin).load(clazz); + final T object = new YamlStorageReader(reader, ess.getPlugin()).load(clazz); onSuccess(object); } finally diff --git a/Essentials/src/net/ess3/storage/AbstractDelayedYamlFileWriter.java b/Essentials/src/net/ess3/storage/AbstractDelayedYamlFileWriter.java index bc8a0f18a..f728ff7a0 100644 --- a/Essentials/src/net/ess3/storage/AbstractDelayedYamlFileWriter.java +++ b/Essentials/src/net/ess3/storage/AbstractDelayedYamlFileWriter.java @@ -9,29 +9,21 @@ import java.util.logging.Level; import net.ess3.Essentials; import net.ess3.api.IEssentials; import org.bukkit.Bukkit; -import org.bukkit.plugin.Plugin; public abstract class AbstractDelayedYamlFileWriter implements Runnable { - private final transient Plugin plugin; + private final transient IEssentials ess; private final transient ReentrantLock lock = new ReentrantLock(); public AbstractDelayedYamlFileWriter(final IEssentials ess) { - this.plugin = ess; + this.ess = ess; } public void schedule() { - if (((Essentials)plugin).testing) - { - run(); - } - else - { - plugin.getServer().getScheduler().scheduleAsyncDelayedTask(plugin, this); - } + ess.getPlugin().scheduleAsyncDelayedTask(this); } public abstract File getFile() throws IOException; diff --git a/Essentials/src/net/ess3/storage/BukkitConstructor.java b/Essentials/src/net/ess3/storage/BukkitConstructor.java index 36dc209c1..81fe3daa2 100644 --- a/Essentials/src/net/ess3/storage/BukkitConstructor.java +++ b/Essentials/src/net/ess3/storage/BukkitConstructor.java @@ -5,13 +5,9 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.regex.Pattern; -import net.ess3.Essentials; -import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; import org.bukkit.material.MaterialData; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.java.JavaPluginLoader; import org.yaml.snakeyaml.TypeDescription; import org.yaml.snakeyaml.constructor.Constructor; import org.yaml.snakeyaml.error.YAMLException; @@ -22,9 +18,9 @@ import org.yaml.snakeyaml.nodes.*; public class BukkitConstructor extends Constructor { private final transient Pattern NUMPATTERN = Pattern.compile("\\d+"); - private final transient Plugin plugin; + private final transient IPlugin plugin; - public BukkitConstructor(final Class clazz, final Plugin plugin) + public BukkitConstructor(final Class clazz, final IPlugin plugin) { super(clazz); this.plugin = plugin; @@ -69,11 +65,11 @@ public class BukkitConstructor extends Constructor if (NUMPATTERN.matcher(split[0]).matches()) { final int typeId = Integer.parseInt(split[0]); - mat = Material.getMaterial(typeId); + mat = Material.get(typeId); } else { - mat = Material.matchMaterial(split[0]); + mat = Material.match(split[0]); } if (mat == null) { @@ -236,7 +232,7 @@ public class BukkitConstructor extends Constructor @Override public Object construct(final Node node) { - if (node.getType().equals(Location.class)) + if (node.getType().equals(StoredLocation.class)) { //TODO: NPE checks final MappingNode mnode = (MappingNode)node; @@ -280,7 +276,7 @@ public class BukkitConstructor extends Constructor { return null; } - return new Location(worldName, x, y, z, yaw, pitch); + return new StoredLocation(worldName, x, y, z, yaw, pitch); } return super.construct(node); } @@ -419,14 +415,13 @@ public class BukkitConstructor extends Constructor { Class<?> clazz; final String name = node.getTag().getClassName(); - if (plugin == null || (plugin instanceof Essentials && ((Essentials)plugin).testing)) + if (Essentials.testing) { clazz = super.getClassForNode(node); } else { - final JavaPluginLoader jpl = (JavaPluginLoader)plugin.getPluginLoader(); - clazz = jpl.getClassByName(name); + clazz = plugin.getClassByName(name); } if (clazz == null) diff --git a/Essentials/src/net/ess3/storage/ManagedFile.java b/Essentials/src/net/ess3/storage/ManagedFile.java index ee66f524d..c6e23e6b8 100644 --- a/Essentials/src/net/ess3/storage/ManagedFile.java +++ b/Essentials/src/net/ess3/storage/ManagedFile.java @@ -22,13 +22,13 @@ public class ManagedFile public ManagedFile(final String filename, final IEssentials ess) { - file = new File(ess.getDataFolder(), filename); + file = new File(ess.getPlugin().getDataFolder(), filename); if (file.exists()) { try { - if (checkForVersion(file, ess.getDescription().getVersion()) && !file.delete()) + if (checkForVersion(file, ess.getPlugin().getVersion()) && !file.delete()) { throw new IOException("Could not delete file " + file.toString()); } diff --git a/Essentials/src/net/ess3/storage/StorageObjectMap.java b/Essentials/src/net/ess3/storage/StorageObjectMap.java index 168e59754..1e88a8fd3 100644 --- a/Essentials/src/net/ess3/storage/StorageObjectMap.java +++ b/Essentials/src/net/ess3/storage/StorageObjectMap.java @@ -15,7 +15,6 @@ import java.util.logging.Level; import net.ess3.api.IEssentials; import net.ess3.api.InvalidNameException; import net.ess3.utils.Util; -import org.bukkit.Bukkit; public abstract class StorageObjectMap<I> extends CacheLoader<String, I> implements IStorageObjectMap<I> @@ -29,7 +28,7 @@ public abstract class StorageObjectMap<I> extends CacheLoader<String, I> impleme { super(); this.ess = ess; - this.folder = new File(ess.getDataFolder(), folderName); + this.folder = new File(ess.getPlugin().getDataFolder(), folderName); if (!folder.exists()) { folder.mkdirs(); @@ -39,7 +38,7 @@ public abstract class StorageObjectMap<I> extends CacheLoader<String, I> impleme private void loadAllObjectsAsync() { - ess.scheduleAsyncDelayedTask(new Runnable() + ess.getPlugin().scheduleAsyncDelayedTask(new Runnable() { @Override public void run() @@ -63,7 +62,7 @@ public abstract class StorageObjectMap<I> extends CacheLoader<String, I> impleme } catch (InvalidNameException ex) { - Bukkit.getLogger().log(Level.WARNING, "Invalid filename: " + string, ex); + ess.getLogger().log(Level.WARNING, "Invalid filename: " + string, ex); } } } diff --git a/Essentials/src/net/ess3/storage/StoredLocation.java b/Essentials/src/net/ess3/storage/StoredLocation.java new file mode 100644 index 000000000..00ace6791 --- /dev/null +++ b/Essentials/src/net/ess3/storage/StoredLocation.java @@ -0,0 +1,115 @@ +package net.ess3.storage; + +import net.ess3.api.server.World; +import net.ess3.api.server.Location; +import java.lang.ref.WeakReference; +import java.util.UUID; + + +public class StoredLocation +{ + private WeakReference<Location> location; + private final String worldname; + private UUID worldUID = null; + private final double x; + private final double y; + private final double z; + private final float yaw; + private final float pitch; + + public StoredLocation(Location loc) + { + location = new WeakReference<Location>(loc); + worldname = loc.getWorld().getName(); + worldUID = loc.getWorld().getUID(); + x = loc.getX(); + y = loc.getY(); + z = loc.getZ(); + yaw = loc.getYaw(); + pitch = loc.getPitch(); + } + + public StoredLocation(String worldname, double x, double y, double z, float yaw, float pitch) + { + this.worldname = worldname; + this.x = x; + this.y = y; + this.z = z; + this.yaw = yaw; + this.pitch = pitch; + } + + public StoredLocation(String worldname, double x, double y, double z) + { + this.worldname = worldname; + this.x = x; + this.y = y; + this.z = z; + this.yaw = 0f; + this.pitch = 0f; + } + + public Location getStoredLocation() throws WorldNotLoadedException + { + + Location loc = location == null ? null : location.get(); + if (loc == null) + { + World world = null; + if (worldUID != null) + { + world = Bukkit.getWorld(worldUID); + } + if (world == null) + { + world = Bukkit.getWorld(worldname); + } + if (world == null) + { + throw new WorldNotLoadedException(worldname); + } + loc = Location.create(world, getX(), getY(), getZ(), getYaw(), getPitch()); + location = new WeakReference<Location>(loc); + } + return loc; + } + + public String getWorldName() + { + return worldname; + } + + public double getX() + { + return x; + } + + public double getY() + { + return y; + } + + public double getZ() + { + return z; + } + + public float getYaw() + { + return yaw; + } + + public float getPitch() + { + return pitch; + } + + + public static class WorldNotLoadedException extends Exception + { + public WorldNotLoadedException(String worldname) + { + super("World " + worldname + " is not loaded."); + } + } +} diff --git a/Essentials/src/net/ess3/storage/YamlStorageReader.java b/Essentials/src/net/ess3/storage/YamlStorageReader.java index 957902ee6..dc5c24d91 100644 --- a/Essentials/src/net/ess3/storage/YamlStorageReader.java +++ b/Essentials/src/net/ess3/storage/YamlStorageReader.java @@ -1,10 +1,10 @@ package net.ess3.storage; +import net.ess3.api.server.IPlugin; import java.io.Reader; import java.lang.reflect.Field; import java.util.*; import java.util.concurrent.locks.ReentrantLock; -import org.bukkit.plugin.Plugin; import org.yaml.snakeyaml.TypeDescription; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.Constructor; @@ -15,9 +15,9 @@ public class YamlStorageReader implements IStorageReader private transient static final Map<Class, Yaml> PREPARED_YAMLS = Collections.synchronizedMap(new HashMap<Class, Yaml>()); private transient static final Map<Class, ReentrantLock> LOCKS = new HashMap<Class, ReentrantLock>(); private transient final Reader reader; - private transient final Plugin plugin; + private transient final IPlugin plugin; - public YamlStorageReader(final Reader reader, final Plugin plugin) + public YamlStorageReader(final Reader reader, final IPlugin plugin) { this.reader = reader; this.plugin = plugin; diff --git a/Essentials/src/net/ess3/storage/YamlStorageWriter.java b/Essentials/src/net/ess3/storage/YamlStorageWriter.java index 1a57fffdd..40ac71464 100644 --- a/Essentials/src/net/ess3/storage/YamlStorageWriter.java +++ b/Essentials/src/net/ess3/storage/YamlStorageWriter.java @@ -73,9 +73,9 @@ public class YamlStorageWriter implements IStorageWriter { writeCollection((Collection<Object>)data, depth + 1); } - else if (data instanceof Location) + else if (data instanceof StoredLocation) { - writeLocation((Location)data, depth + 1); + writeLocation((StoredLocation)data, depth + 1); } else { @@ -150,9 +150,9 @@ public class YamlStorageWriter implements IStorageWriter writer.println(); writeToFile(entry, depth + 1, entry.getClass()); } - else if (entry instanceof Location) + else if (entry instanceof StoredLocation) { - writeLocation((Location)entry, depth + 1); + writeLocation((StoredLocation)entry, depth + 1); } else { @@ -187,9 +187,9 @@ public class YamlStorageWriter implements IStorageWriter { writeCollection((Collection<Object>)value, depth + 1); } - else if (value instanceof Location) + else if (value instanceof StoredLocation) { - writeLocation((Location)value, depth + 1); + writeLocation((StoredLocation)value, depth + 1); } else { @@ -323,7 +323,7 @@ public class YamlStorageWriter implements IStorageWriter writer.print(enchLevel.getValue()); } - private void writeLocation(final Location entry, final int depth) + private void writeLocation(final StoredLocation entry, final int depth) { writer.println(); writeIndention(depth); diff --git a/Essentials/src/net/ess3/user/IOfflinePlayer.java b/Essentials/src/net/ess3/user/IOfflinePlayer.java index dc1ae0979..94b626ab7 100644 --- a/Essentials/src/net/ess3/user/IOfflinePlayer.java +++ b/Essentials/src/net/ess3/user/IOfflinePlayer.java @@ -1,6 +1,5 @@ package net.ess3.user; -import org.bukkit.Location; import org.bukkit.permissions.Permission; @@ -10,7 +9,7 @@ public interface IOfflinePlayer String getDisplayName(); - Location getBedSpawnLocation(); + //Location getBedSpawnLocation(); void setBanned(boolean bln); diff --git a/Essentials/src/net/ess3/user/IOfflineUser.java b/Essentials/src/net/ess3/user/IOfflineUser.java index 60756957c..19431d982 100644 --- a/Essentials/src/net/ess3/user/IOfflineUser.java +++ b/Essentials/src/net/ess3/user/IOfflineUser.java @@ -3,7 +3,7 @@ package net.ess3.user; import net.ess3.storage.IStorageObjectHolder; -public interface IOfflineUser extends IStorageObjectHolder<UserData>, IOfflinePlayer +public interface IOfflineUser extends IStorageObjectHolder<UserData>//, IOfflinePlayer { } diff --git a/Essentials/src/net/ess3/user/TooManyMatchesException.java b/Essentials/src/net/ess3/user/TooManyMatchesException.java new file mode 100644 index 000000000..d55e6b6c4 --- /dev/null +++ b/Essentials/src/net/ess3/user/TooManyMatchesException.java @@ -0,0 +1,5 @@ +package net.ess3.user; + +public class TooManyMatchesException extends Exception { + +} diff --git a/Essentials/src/net/ess3/user/User.java b/Essentials/src/net/ess3/user/User.java index 615415349..061f006db 100644 --- a/Essentials/src/net/ess3/user/User.java +++ b/Essentials/src/net/ess3/user/User.java @@ -1,30 +1,22 @@ package net.ess3.user; -import java.util.Calendar; -import java.util.GregorianCalendar; -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.logging.Logger; -import lombok.Cleanup; -import lombok.Getter; -import lombok.Setter; import net.ess3.Console; import static net.ess3.I18n._; import net.ess3.Teleport; import net.ess3.api.*; -import net.ess3.craftbukkit.InventoryWorkaround; +import net.ess3.api.server.*; import net.ess3.economy.register.Method; import net.ess3.permissions.Permissions; import net.ess3.utils.DateUtil; import net.ess3.utils.Util; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.OfflinePlayer; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; +import lombok.Cleanup; +import lombok.Getter; +import lombok.Setter; public class User extends UserBase implements IUser @@ -51,7 +43,6 @@ public class User extends UserBase implements IUser @Setter private boolean invSee = false; private transient Location afkPosition; - private static final Logger logger = Bukkit.getLogger(); private AtomicBoolean gotMailInfo = new AtomicBoolean(false); public User(final Player base, final IEssentials ess) @@ -60,12 +51,6 @@ public class User extends UserBase implements IUser teleport = new Teleport(this, ess); } - public User(final OfflinePlayer offlinePlayer, final IEssentials ess) - { - super(offlinePlayer, ess); - teleport = new Teleport(this, ess); - } - public void example() { // Cleanup will call close at the end of the function @@ -205,7 +190,7 @@ public class User extends UserBase implements IUser acquireWriteLock(); try { - getData().setLastLocation(new net.ess3.storage.Location(getLocation())); + getData().setLastLocation(new net.ess3.storage.StoredLocation(getLocation())); } finally { @@ -274,7 +259,7 @@ public class User extends UserBase implements IUser } catch (IllegalArgumentException e) { - logger.info("Playerlist for " + name + " was not updated. Use a shorter displayname prefix."); + ess.getLogger().info("Playerlist for " + name + " was not updated. Use a shorter displayname prefix."); } } @@ -290,7 +275,7 @@ public class User extends UserBase implements IUser @Cleanup final ISettings settings = ess.getSettings(); settings.acquireReadLock(); - if (isOnlineUser() && settings.getData().getChat().getChangeDisplayname()) + if (isOnline() && settings.getData().getChat().getChangeDisplayname()) { setDisplayNick(); } @@ -484,9 +469,9 @@ public class User extends UserBase implements IUser kickPlayer(kickReason); - for (Player player : ess.getServer().getOnlinePlayers()) + for (IPlayer player : ess.getServer().getOnlinePlayers()) { - final IUser user = ess.getUser(player); + final IUser user = player.getUser(); if (Permissions.KICK_NOTIFY.isAuthorized(user)) { player.sendMessage(_("playerKicked", Console.NAME, getName(), kickReason)); @@ -629,7 +614,7 @@ public class User extends UserBase implements IUser { boolean spew = false; - if (itemStack == null || itemStack.getType() == Material.AIR) + if (itemStack == null || itemStack.isAir()) { return spew; } @@ -642,11 +627,11 @@ public class User extends UserBase implements IUser settings.acquireReadLock(); int oversizedStackSize = settings.getData().getGeneral().getOversizedStacksize(); - overfilled = InventoryWorkaround.addItem(getInventory(), true, oversizedStackSize, itemStack); + overfilled = getInventory().addItem(true, oversizedStackSize, itemStack); } else { - overfilled = InventoryWorkaround.addItem(getInventory(), true, itemStack); + overfilled = getInventory().addItem(true, itemStack); } if (canSpew) { diff --git a/Essentials/src/net/ess3/user/UserBase.java b/Essentials/src/net/ess3/user/UserBase.java index 5c975119d..9d0598fd1 100644 --- a/Essentials/src/net/ess3/user/UserBase.java +++ b/Essentials/src/net/ess3/user/UserBase.java @@ -1,45 +1,25 @@ package net.ess3.user; +import net.ess3.utils.Util; +import net.ess3.api.IEssentials; +import net.ess3.api.ISettings; +import net.ess3.api.InvalidNameException; +import net.ess3.api.server.Player; +import net.ess3.api.server.Location; +import net.ess3.storage.AsyncStorageObjectHolder; +import net.ess3.storage.IStorageObjectHolder; +import net.ess3.storage.StoredLocation.WorldNotLoadedException; import java.io.File; import java.io.IOException; import java.util.*; import lombok.Cleanup; import lombok.Delegate; -import net.ess3.api.IEssentials; -import net.ess3.api.ISettings; -import net.ess3.api.IUser; -import net.ess3.api.InvalidNameException; -import net.ess3.permissions.Permissions; -import net.ess3.storage.AsyncStorageObjectHolder; -import net.ess3.storage.Location.WorldNotLoadedException; -import net.ess3.utils.Util; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.OfflinePlayer; -import org.bukkit.command.CommandSender; -import org.bukkit.configuration.serialization.ConfigurationSerializable; -import org.bukkit.entity.Entity; -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.permissions.Permissible; -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.ServerOperator; -public abstract class UserBase extends AsyncStorageObjectHolder<UserData> implements Player, IOfflineUser +public abstract class UserBase extends AsyncStorageObjectHolder<UserData> implements Player, IStorageObjectHolder<UserData> { - @Delegate(types = - { - Player.class, Entity.class, CommandSender.class, ServerOperator.class, - HumanEntity.class, ConfigurationSerializable.class, LivingEntity.class, - Permissible.class - }, excludes = - { - IOfflinePlayer.class - }) + @Delegate protected Player base; - protected transient OfflinePlayer offlinePlayer; public UserBase(final Player base, final IEssentials ess) { @@ -48,13 +28,6 @@ public abstract class UserBase extends AsyncStorageObjectHolder<UserData> implem onReload(); } - public UserBase(final OfflinePlayer offlinePlayer, final IEssentials ess) - { - super(ess, UserData.class); - this.offlinePlayer = offlinePlayer; - onReload(); - } - public final Player getBase() { return base; @@ -70,80 +43,13 @@ public abstract class UserBase extends AsyncStorageObjectHolder<UserData> implem setBase(base); } - public void update(final OfflinePlayer offlinePlayer) - { - this.offlinePlayer = offlinePlayer; - } + public void dispose() { - this.offlinePlayer = Bukkit.getOfflinePlayer(base.getName()); this.base = null; } - public boolean isOnlineUser() - { - return base != null; - } - - @Override - public String getName() - { - if (isOnlineUser()) - { - return base.getName(); - } - else - { - return offlinePlayer.getName(); - } - } - - @Override - public String getDisplayName() - { - if (isOnlineUser()) - { - return base.getDisplayName(); - } - else - { - return offlinePlayer.getName(); - } - } - - @Override - public Location getBedSpawnLocation() - { - return base.getBedSpawnLocation(); - } - - @Override - public void setBanned(boolean bln) - { - if (isOnlineUser()) - { - base.setBanned(bln); - } - else - { - offlinePlayer.setBanned(bln); - } - } - - @Override - public boolean hasPermission(Permission prmsn) - { - if (isOnlineUser()) - { - return base.hasPermission(prmsn); - } - else - { - return false; - } - } - @Override public File getStorageFile() throws IOException { @@ -245,13 +151,13 @@ public abstract class UserBase extends AsyncStorageObjectHolder<UserData> implem acquireWriteLock(); try { - Map<String, net.ess3.storage.Location> homes = getData().getHomes(); + Map<String, net.ess3.storage.StoredLocation> homes = getData().getHomes(); if (homes == null) { - homes = new HashMap<String, net.ess3.storage.Location>(); + homes = new HashMap<String, net.ess3.storage.StoredLocation>(); getData().setHomes(homes); } - homes.put(Util.sanitizeKey(name), new net.ess3.storage.Location(loc)); + homes.put(Util.sanitizeKey(name), new net.ess3.storage.StoredLocation(loc)); } finally { @@ -439,13 +345,13 @@ public abstract class UserBase extends AsyncStorageObjectHolder<UserData> implem return null; } ArrayList<Location> worldHomes = new ArrayList<Location>(); - for (net.ess3.storage.Location location : getData().getHomes().values()) + for (net.ess3.storage.StoredLocation location : getData().getHomes().values()) { if (location.getWorldName().equals(loc.getWorld().getName())) { try { - worldHomes.add(location.getBukkitLocation()); + worldHomes.add(location.getStoredLocation()); } catch (WorldNotLoadedException ex) { diff --git a/Essentials/src/net/ess3/user/UserData.java b/Essentials/src/net/ess3/user/UserData.java index 04a8d7879..3582eaa89 100644 --- a/Essentials/src/net/ess3/user/UserData.java +++ b/Essentials/src/net/ess3/user/UserData.java @@ -1,10 +1,11 @@ package net.ess3.user; +import net.ess3.api.server.Material; +import net.ess3.storage.*; import java.util.*; import lombok.Data; import lombok.EqualsAndHashCode; -import net.ess3.storage.*; -import org.bukkit.Material; + @Data @@ -17,14 +18,14 @@ public class UserData implements StorageObject } private String nickname; private Double money; - @MapValueType(Location.class) - private Map<String, Location> homes = new HashMap<String, Location>(); + @MapValueType(StoredLocation.class) + private Map<String, StoredLocation> homes = new HashMap<String, StoredLocation>(); @ListType(Material.class) private Set<Material> unlimited = new HashSet<Material>(); @MapValueType(List.class) @MapKeyType(Material.class) private Map<Material, List<String>> powerTools = new HashMap<Material, List<String>>(); - private Location lastLocation; + private StoredLocation lastLocation; @MapKeyType(TimestampType.class) @MapValueType(Long.class) private Map<TimestampType, Long> timestamps = new HashMap<TimestampType, Long>(); @@ -49,10 +50,6 @@ public class UserData implements StorageObject public UserData() { - unlimited.add(Material.AIR); - unlimited.add(Material.ARROW); - unlimited.add(Material.APPLE); - powerTools.put(Material.DEAD_BUSH, Collections.singletonList("test")); timestamps.put(TimestampType.JAIL, Long.MIN_VALUE); } diff --git a/Essentials/src/net/ess3/utils/textreader/KeywordReplacer.java b/Essentials/src/net/ess3/utils/textreader/KeywordReplacer.java index a3d7ef322..5b0a5066f 100644 --- a/Essentials/src/net/ess3/utils/textreader/KeywordReplacer.java +++ b/Essentials/src/net/ess3/utils/textreader/KeywordReplacer.java @@ -1,17 +1,17 @@ package net.ess3.utils.textreader; +import net.ess3.api.IEssentials; +import net.ess3.api.IUser; +import net.ess3.api.server.CommandSender; +import net.ess3.api.server.Player; +import net.ess3.api.server.World; +import net.ess3.utils.DescParseTickFormat; import java.text.DateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; import lombok.Cleanup; -import net.ess3.api.IEssentials; -import net.ess3.api.IUser; -import net.ess3.utils.DescParseTickFormat; -import org.bukkit.World; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -35,10 +35,10 @@ public class KeywordReplacer implements IText String worlds, online, unique, playerlist, date, time; String worldTime12, worldTime24, worldDate, plugins; String userName, address, version; - if (sender instanceof Player) + if (sender.isPlayer()) { @Cleanup - final IUser user = ess.getUser((Player)sender); + final IUser user = ((Player)sender).getUser(); user.acquireReadLock(); user.setDisplayNick(); displayName = user.getDisplayName(); @@ -60,12 +60,12 @@ public class KeywordReplacer implements IText int playerHidden = 0; for (Player p : ess.getServer().getOnlinePlayers()) { - if (ess.getUser(p).isHidden()) + if (p.getUser().isHidden()) { playerHidden++; } } - online = Integer.toString(ess.getServer().getOnlinePlayers().length - playerHidden); + online = Integer.toString(ess.getServer().getOnlinePlayers().size() - playerHidden); unique = Integer.toString(ess.getUserMap().getUniqueUsers()); final StringBuilder worldsBuilder = new StringBuilder(); @@ -82,7 +82,7 @@ public class KeywordReplacer implements IText final StringBuilder playerlistBuilder = new StringBuilder(); for (Player p : ess.getServer().getOnlinePlayers()) { - if (ess.getUser(p).isHidden()) + if (p.getUser().isHidden()) { continue; } diff --git a/Essentials/src/net/ess3/utils/textreader/TextInput.java b/Essentials/src/net/ess3/utils/textreader/TextInput.java index 6cb251e93..b0a0707af 100644 --- a/Essentials/src/net/ess3/utils/textreader/TextInput.java +++ b/Essentials/src/net/ess3/utils/textreader/TextInput.java @@ -4,13 +4,6 @@ import java.io.*; import java.lang.ref.SoftReference; import java.util.*; import java.util.logging.Level; -import net.ess3.api.IEssentials; -import net.ess3.api.IUser; -import net.ess3.api.InvalidNameException; -import net.ess3.utils.Util; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; public class TextInput implements IText @@ -25,25 +18,25 @@ public class TextInput implements IText { File file = null; - if (sender instanceof Player) + if (sender.isPlayer()) { try { - final IUser user = ess.getUser((Player)sender); - file = new File(ess.getDataFolder(), filename + "_" + Util.sanitizeFileName(user.getName()) + ".txt"); + final IUser user = ((Player)sender).getUser(); + file = new File(ess.getPlugin().getDataFolder(), filename + "_" + Util.sanitizeFileName(user.getName()) + ".txt"); if (!file.exists()) { - file = new File(ess.getDataFolder(), filename + "_" + Util.sanitizeFileName(ess.getRanks().getMainGroup(user)) + ".txt"); + file = new File(ess.getPlugin().getDataFolder(), filename + "_" + Util.sanitizeFileName(ess.getRanks().getMainGroup(user)) + ".txt"); } } catch (InvalidNameException ex) { - Bukkit.getLogger().log(Level.WARNING, ex.getMessage(), ex); + ess.getLogger().log(Level.WARNING, ex.getMessage(), ex); } } if (file == null || !file.exists()) { - file = new File(ess.getDataFolder(), filename + ".txt"); + file = new File(ess.getPlugin().getDataFolder(), filename + ".txt"); } if (file.exists()) { @@ -105,7 +98,7 @@ public class TextInput implements IText bookmarks = Collections.emptyMap(); if (createFile) { - final InputStream input = ess.getResource(filename + ".txt"); + final InputStream input = ess.getPlugin().getResource(filename + ".txt"); final OutputStream output = new FileOutputStream(file); try { diff --git a/Essentials/src/net/ess3/utils/textreader/TextPager.java b/Essentials/src/net/ess3/utils/textreader/TextPager.java index 88f00125c..c1ca8e939 100644 --- a/Essentials/src/net/ess3/utils/textreader/TextPager.java +++ b/Essentials/src/net/ess3/utils/textreader/TextPager.java @@ -3,9 +3,6 @@ package net.ess3.utils.textreader; import java.util.List; import java.util.Locale; import java.util.Map; -import net.ess3.I18n; -import static net.ess3.I18n._; -import org.bukkit.command.CommandSender; public class TextPager diff --git a/Essentials/test/com/earth2me/essentials/EssentialsTest.java b/Essentials/test/com/earth2me/essentials/EssentialsTest.java new file mode 100644 index 000000000..39ce92d25 --- /dev/null +++ b/Essentials/test/com/earth2me/essentials/EssentialsTest.java @@ -0,0 +1,27 @@ +package com.earth2me.essentials; + +import com.earth2me.essentials.testserver.Plugin; +import com.earth2me.essentials.testserver.Server; +import java.util.logging.Logger; +import junit.framework.TestCase; +import net.ess3.Essentials; + +public abstract class EssentialsTest extends TestCase { + protected final transient Server server; + protected final transient Plugin plugin; + protected final transient Logger logger; + protected final transient Essentials ess; + + + public EssentialsTest(final String testName) + { + super(testName); + logger = Logger.getLogger(this.getName()); + server = new Server(); + plugin = new Plugin(); + ess = new Essentials(server, logger, plugin); + Essentials.testing = true; + ess.onEnable(); + } + +} diff --git a/Essentials/test/com/earth2me/essentials/testserver/Player.java b/Essentials/test/com/earth2me/essentials/testserver/Player.java new file mode 100644 index 000000000..6e18abb88 --- /dev/null +++ b/Essentials/test/com/earth2me/essentials/testserver/Player.java @@ -0,0 +1,152 @@ +package com.earth2me.essentials.testserver; + +import net.ess3.api.IUser; +import net.ess3.api.server.*; + +public class Player implements Player { + + @Override + public IUser getUser() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String getName() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String getDisplayName() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean isOnline() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void setBanned(boolean bool) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void kickPlayer(String reason) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public World getWorld() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Location getLocation() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Location getEyeLocation() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void setFireTicks(int value) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void setFoodLevel(int value) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void setSaturation(float value) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public int getHealth() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void setHealth(int value) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void updateInventory() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public ItemStack getItemInHand() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Location getBedSpawnLocation() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean hasPlayedBefore() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public IInventory getInventory() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean isPlayer() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void sendMessage(String message) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean isOp() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean hasPermission(Permission bukkitPermission) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void sendMessage(String[] string) + { + throw new UnsupportedOperationException("Not supported yet."); + } + +} diff --git a/Essentials/test/com/earth2me/essentials/testserver/Plugin.java b/Essentials/test/com/earth2me/essentials/testserver/Plugin.java new file mode 100644 index 000000000..cb5334da5 --- /dev/null +++ b/Essentials/test/com/earth2me/essentials/testserver/Plugin.java @@ -0,0 +1,69 @@ +package com.earth2me.essentials.testserver; + +import net.ess3.api.server.IPlugin; +import java.io.File; +import java.io.InputStream; + +public class Plugin implements IPlugin { + + @Override + public int scheduleAsyncDelayedTask(Runnable run) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public int scheduleSyncDelayedTask(Runnable run) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public int scheduleSyncDelayedTask(Runnable run, long delay) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public int scheduleSyncRepeatingTask(Runnable run, long delay, long period) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public File getRootFolder() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public File getDataFolder() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void cancelTask(int taskId) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String getVersion() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Class getClassByName(String name) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public InputStream getResource(String string) + { + throw new UnsupportedOperationException("Not supported yet."); + } + +} diff --git a/Essentials/test/com/earth2me/essentials/testserver/Server.java b/Essentials/test/com/earth2me/essentials/testserver/Server.java new file mode 100644 index 000000000..eb9a74bdb --- /dev/null +++ b/Essentials/test/com/earth2me/essentials/testserver/Server.java @@ -0,0 +1,89 @@ +package com.earth2me.essentials.testserver; + +import net.ess3.api.server.CommandSender; +import net.ess3.api.server.Player; +import net.ess3.api.server.IServer; +import net.ess3.api.server.World; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +public class Server implements IServer { + + public Server() + { + } + + + + @Override + public List<World> getWorlds() + { + return Collections.<World>singletonList(new World()); + } + + @Override + public World getWorld(final String name) + { + final World world = getWorlds().get(0); + if (name.equals(world.getName())) { + return world; + } else { + return null; + } + } + + public void addPlayer(final String name) + { + + } + + @Override + public int broadcastMessage(String message) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Collection<Player> getOnlinePlayers() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public CommandSender getConsoleSender() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void dispatchCommand(CommandSender sender, String command) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void banIP(String ip) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public <T> T getServiceProvider(Class<T> clazz) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String getVersion() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void unbanIP(String string) + { + throw new UnsupportedOperationException("Not supported yet."); + } + +} diff --git a/Essentials/test/com/earth2me/essentials/testserver/World.java b/Essentials/test/com/earth2me/essentials/testserver/World.java new file mode 100644 index 000000000..d1994c479 --- /dev/null +++ b/Essentials/test/com/earth2me/essentials/testserver/World.java @@ -0,0 +1,26 @@ +package com.earth2me.essentials.testserver; + +import net.ess3.api.server.Location; +import org.bukkit.TreeType; + +public class World implements World { + + @Override + public String getName() + { + return "TestWorld"; + } + + @Override + public boolean generateTree(Location safeLocation, TreeType tree) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public int getHighestBlockYAt(int topX, int topZ) + { + throw new UnsupportedOperationException("Not supported yet."); + } + +} diff --git a/Essentials/test/net/ess3/EconomyTest.java b/Essentials/test/net/ess3/EconomyTest.java index e6cb6bde5..21669d7e6 100644 --- a/Essentials/test/net/ess3/EconomyTest.java +++ b/Essentials/test/net/ess3/EconomyTest.java @@ -1,40 +1,19 @@ package net.ess3; -import java.io.IOException; -import junit.framework.TestCase; import net.ess3.api.NoLoanPermittedException; import net.ess3.api.UserDoesNotExistException; -import net.ess3.user.User; -import org.bukkit.World.Environment; -import org.bukkit.plugin.InvalidDescriptionException; import org.junit.Test; -public class EconomyTest extends TestCase +public class EconomyTest extends EssentialsTest { - private final transient Essentials ess; private final static String NPCNAME = "npc1"; private final static String PLAYERNAME = "TestPlayer1"; public EconomyTest(final String testName) { super(testName); - ess = new Essentials(); - final FakeServer server = new FakeServer(); - server.createWorld("testWorld", Environment.NORMAL); - try - { - ess.setupForTesting(server); - } - catch (InvalidDescriptionException ex) - { - fail("InvalidDescriptionException"); - } - catch (IOException ex) - { - fail("IOException"); - } - server.addPlayer(new User(new FakeOfflinePlayer(PLAYERNAME), ess)); + server.addPlayer(PLAYERNAME); } // only one big test, since we use static instances diff --git a/Essentials/test/net/ess3/StorageTest.java b/Essentials/test/net/ess3/StorageTest.java index ea37e123b..aac394bf6 100644 --- a/Essentials/test/net/ess3/StorageTest.java +++ b/Essentials/test/net/ess3/StorageTest.java @@ -1,7 +1,7 @@ package net.ess3; import java.io.*; -import junit.framework.TestCase; + import net.ess3.settings.Settings; import net.ess3.storage.ObjectLoadException; import net.ess3.storage.StorageObject; @@ -11,33 +11,14 @@ import net.ess3.utils.ExecuteTimer; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.World.Environment; -import org.bukkit.plugin.InvalidDescriptionException; import org.junit.Test; -public class StorageTest extends TestCase +public class StorageTest extends EssentialsTest { - Essentials ess; - FakeServer server; - World world; - - public StorageTest() + public StorageTest(final String name) { - ess = new Essentials(); - server = new FakeServer(); - world = server.createWorld("testWorld", Environment.NORMAL); - try - { - ess.setupForTesting(server); - } - catch (InvalidDescriptionException ex) - { - fail("InvalidDescriptionException"); - } - catch (IOException ex) - { - fail("IOException"); - } + super(name); } @Test @@ -99,7 +80,7 @@ public class StorageTest extends TestCase for (int j = 0; j < 10000; j++) { - userdata.getHomes().put("home", new net.ess3.storage.Location(new Location(world, j, j, j))); + userdata.getHomes().put("home", new net.ess3.storage.StoredLocation(new Location(world, j, j, j))); } ext.mark("change home 10000 times"); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); diff --git a/Essentials/test/net/ess3/UserTest.java b/Essentials/test/net/ess3/UserTest.java index ec05174d3..3baa420df 100644 --- a/Essentials/test/net/ess3/UserTest.java +++ b/Essentials/test/net/ess3/UserTest.java @@ -8,33 +8,16 @@ import org.bukkit.World.Environment; import org.bukkit.plugin.InvalidDescriptionException; -public class UserTest extends TestCase +public class UserTest extends EssentialsTest { private final IUser base1; - private final Essentials ess; - private final FakeServer server; public UserTest(String testName) { super(testName); - ess = new Essentials(); - server = new FakeServer(); - server.createWorld("testWorld", Environment.NORMAL); - try - { - ess.setupForTesting(server); - } - catch (InvalidDescriptionException ex) - { - fail("InvalidDescriptionException"); - } - catch (IOException ex) - { - fail("IOException"); - } - base1 = new User(new FakeOfflinePlayer("testPlayer1"), ess); - server.addPlayer(base1); - ess.getUser(base1); + + server.addPlayer("testPlayer1"); + base1 = ess.getUser("testPlayer1"); } private void should(String what) diff --git a/Essentials/test/net/ess3/UtilTest.java b/Essentials/test/net/ess3/UtilTest.java index 131828d46..dc7dc7b66 100644 --- a/Essentials/test/net/ess3/UtilTest.java +++ b/Essentials/test/net/ess3/UtilTest.java @@ -1,40 +1,21 @@ package net.ess3; -import java.io.IOException; +import net.ess3.api.InvalidNameException; +import net.ess3.utils.DateUtil; +import net.ess3.utils.Util; + import java.util.Calendar; import java.util.GregorianCalendar; import java.util.logging.Level; import java.util.logging.Logger; -import junit.framework.TestCase; -import net.ess3.api.InvalidNameException; -import net.ess3.utils.DateUtil; -import net.ess3.utils.Util; -import org.bukkit.World.Environment; -import org.bukkit.plugin.InvalidDescriptionException; -public class UtilTest extends TestCase +public class UtilTest extends EssentialsTest { - private final Essentials ess; - private final FakeServer server; - public UtilTest() + public UtilTest(String name) { - ess = new Essentials(); - server = new FakeServer(); - server.createWorld("testWorld", Environment.NORMAL); - try - { - ess.setupForTesting(server); - } - catch (InvalidDescriptionException ex) - { - fail("InvalidDescriptionException"); - } - catch (IOException ex) - { - fail("IOException"); - } + super(name); } public void testFDDnow() diff --git a/Essentials2Compat/src/com/earth2me/essentials/EssentialsUpgrade.java b/Essentials2Compat/src/com/earth2me/essentials/EssentialsUpgrade.java index cbc6f5982..605262151 100644 --- a/Essentials2Compat/src/com/earth2me/essentials/EssentialsUpgrade.java +++ b/Essentials2Compat/src/com/earth2me/essentials/EssentialsUpgrade.java @@ -1,12 +1,12 @@ package com.earth2me.essentials; -import net.ess3.economy.WorthHolder; import net.ess3.Warps; +import net.ess3.economy.WorthHolder; import net.ess3.storage.ManagedFile; import static net.ess3.I18n._; import net.ess3.api.IEssentials; import net.ess3.settings.Spawns; -import net.ess3.storage.Location; +import net.ess3.storage.StoredLocation; import net.ess3.storage.YamlStorageWriter; import java.io.*; import java.math.BigInteger; @@ -216,7 +216,7 @@ public class EssentialsUpgrade World world = ess.getServer().getWorlds().get(0); if (world != null) { - final Location loc = new Location( + final StoredLocation loc = new StoredLocation( (String)vals.get(5), ((Number)vals.get(0)).doubleValue(), ((Number)vals.get(1)).doubleValue(), @@ -326,14 +326,14 @@ public class EssentialsUpgrade { @SuppressWarnings("unchecked") final String defworld = (String)config.getProperty("home.default"); - final Location defloc = getFakeLocation(config, "home.worlds." + defworld); + final StoredLocation defloc = getFakeLocation(config, "home.worlds." + defworld); if (defloc != null) { config.setProperty("homes.home", defloc); } Set<String> worlds = config.getConfigurationSection("home.worlds").getKeys(false); - Location loc; + StoredLocation loc; String worldName; if (worlds == null) @@ -443,7 +443,7 @@ public class EssentialsUpgrade } if (worldName != null) { - final Location loc = new Location(worldName, x, y, z, yaw, pitch); + final StoredLocation loc = new StoredLocation(worldName, x, y, z, yaw, pitch); ((Warps)ess.getWarps()).setWarp(filename.substring(0, filename.length() - 4), loc); if (!listOfFiles[i].renameTo(new File(warpsFolder, filename + ".old"))) { @@ -534,14 +534,14 @@ public class EssentialsUpgrade * World.Environment.NORMAL); } return null; } */ - public Location getFakeLocation(EssentialsConf config, String path) + public StoredLocation getFakeLocation(EssentialsConf config, String path) { String worldName = config.getString((path != null ? path + "." : "") + "world"); if (worldName == null || worldName.isEmpty()) { return null; } - return new Location(worldName, + return new StoredLocation(worldName, config.getDouble((path != null ? path + "." : "") + "x", 0), config.getDouble((path != null ? path + "." : "") + "y", 0), config.getDouble((path != null ? path + "." : "") + "z", 0), @@ -616,7 +616,7 @@ public class EssentialsUpgrade Set<String> keys = config.getKeys(false); for (String group : keys) { - Location loc = getFakeLocation(config, group); + StoredLocation loc = getFakeLocation(config, group); spawns.getSpawns().put(group.toLowerCase(Locale.ENGLISH), loc); } if (!configFile.renameTo(new File(ess.getDataFolder(), "spawn.yml.old"))) @@ -663,7 +663,7 @@ public class EssentialsUpgrade Set<String> keys = config.getKeys(false); for (String jailName : keys) { - Location loc = getFakeLocation(config, jailName); + StoredLocation loc = getFakeLocation(config, jailName); jails.getJails().put(jailName.toLowerCase(Locale.ENGLISH), loc); } if (!configFile.renameTo(new File(ess.getDataFolder(), "jail.yml.old"))) diff --git a/EssentialsChat/src/net/ess3/chat/EssentialsLocalChatEventListener.java b/EssentialsChat/src/net/ess3/chat/EssentialsLocalChatEventListener.java index 29bd7e8e8..be7b20ba6 100644 --- a/EssentialsChat/src/net/ess3/chat/EssentialsLocalChatEventListener.java +++ b/EssentialsChat/src/net/ess3/chat/EssentialsLocalChatEventListener.java @@ -3,6 +3,8 @@ package net.ess3.chat; import static net.ess3.I18n._; import net.ess3.api.IEssentials; import net.ess3.api.IUser; +import net.ess3.permissions.Permissions; +import java.util.logging.Logger; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.World; @@ -65,4 +67,4 @@ public class EssentialsLocalChatEventListener implements Listener user.sendMessage(message); } } -} +}
\ No newline at end of file diff --git a/EssentialsChat/src/net/ess3/chat/listenerlevel/EssentialsChatPlayerListenerHighest.java b/EssentialsChat/src/net/ess3/chat/listenerlevel/EssentialsChatPlayerListenerHighest.java index 21f3a188e..46dc2af82 100644 --- a/EssentialsChat/src/net/ess3/chat/listenerlevel/EssentialsChatPlayerListenerHighest.java +++ b/EssentialsChat/src/net/ess3/chat/listenerlevel/EssentialsChatPlayerListenerHighest.java @@ -2,7 +2,6 @@ package net.ess3.chat.listenerlevel; import net.ess3.api.IEssentials; import net.ess3.chat.ChatStore; -import net.ess3.chat.ChatStore; import net.ess3.chat.EssentialsChatPlayer; import java.util.Map; import org.bukkit.Server; diff --git a/EssentialsChat/src/net/ess3/chat/listenerlevel/EssentialsChatPlayerListenerLowest.java b/EssentialsChat/src/net/ess3/chat/listenerlevel/EssentialsChatPlayerListenerLowest.java index eb75e3680..dfe96df35 100644 --- a/EssentialsChat/src/net/ess3/chat/listenerlevel/EssentialsChatPlayerListenerLowest.java +++ b/EssentialsChat/src/net/ess3/chat/listenerlevel/EssentialsChatPlayerListenerLowest.java @@ -5,8 +5,6 @@ import net.ess3.api.IUser; import net.ess3.chat.ChatStore; import net.ess3.chat.EssentialsChatPlayer; import java.util.Map; - -import net.ess3.chat.EssentialsChatPlayer; import org.bukkit.Server; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; diff --git a/EssentialsProtect/src/net/ess3/protect/EssentialsProtectBlockListener.java b/EssentialsProtect/src/net/ess3/protect/EssentialsProtectBlockListener.java index ecfee8e20..77bb472c7 100644 --- a/EssentialsProtect/src/net/ess3/protect/EssentialsProtectBlockListener.java +++ b/EssentialsProtect/src/net/ess3/protect/EssentialsProtectBlockListener.java @@ -1,7 +1,8 @@ package net.ess3.protect; import static net.ess3.I18n._; -import net.ess3.protect.data.IProtectedBlock; +import net.ess3.api.IEssentials; +import com.earth2me.essentials.protect.data.IProtectedBlock; import java.util.ArrayList; import java.util.List; diff --git a/EssentialsProtect/src/net/ess3/protect/EssentialsProtectEntityListener.java b/EssentialsProtect/src/net/ess3/protect/EssentialsProtectEntityListener.java index d8c882acc..f4146c5bb 100644 --- a/EssentialsProtect/src/net/ess3/protect/EssentialsProtectEntityListener.java +++ b/EssentialsProtect/src/net/ess3/protect/EssentialsProtectEntityListener.java @@ -1,5 +1,6 @@ package net.ess3.protect; +import net.ess3.api.IEssentials; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; diff --git a/EssentialsProtect/src/net/ess3/protect/EssentialsProtectPlayerListener.java b/EssentialsProtect/src/net/ess3/protect/EssentialsProtectPlayerListener.java index 64e4a529b..8022df16d 100644 --- a/EssentialsProtect/src/net/ess3/protect/EssentialsProtectPlayerListener.java +++ b/EssentialsProtect/src/net/ess3/protect/EssentialsProtectPlayerListener.java @@ -1,6 +1,7 @@ package net.ess3.protect; import static net.ess3.I18n._; +import net.ess3.api.IEssentials; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; diff --git a/EssentialsSigns/src/net/ess3/signs/EssentialsSign.java b/EssentialsSigns/src/net/ess3/signs/EssentialsSign.java index 272f14252..59c733981 100644 --- a/EssentialsSigns/src/net/ess3/signs/EssentialsSign.java +++ b/EssentialsSigns/src/net/ess3/signs/EssentialsSign.java @@ -1,4 +1,8 @@ +<<<<<<< HEAD:EssentialsSigns/src/com/earth2me/essentials/signs/EssentialsSign.java +package com.earth2me.essentials.signs; +======= package net.ess3.signs; +>>>>>>> master:EssentialsSigns/src/net/ess3/signs/EssentialsSign.java import net.ess3.api.ChargeException; import static net.ess3.I18n._; diff --git a/EssentialsXMPP/src/net/ess3/xmpp/Commandxmpp.java b/EssentialsXMPP/src/net/ess3/xmpp/Commandxmpp.java index 854a91d96..88e1d9810 100644 --- a/EssentialsXMPP/src/net/ess3/xmpp/Commandxmpp.java +++ b/EssentialsXMPP/src/net/ess3/xmpp/Commandxmpp.java @@ -3,7 +3,6 @@ package net.ess3.xmpp; import net.ess3.Console; import net.ess3.commands.EssentialsCommand; import net.ess3.commands.NotEnoughArgumentsException; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/EssentialsXMPP/src/net/ess3/xmpp/Commandxmppspy.java b/EssentialsXMPP/src/net/ess3/xmpp/Commandxmppspy.java index 0c59910f4..dcace3b7d 100644 --- a/EssentialsXMPP/src/net/ess3/xmpp/Commandxmppspy.java +++ b/EssentialsXMPP/src/net/ess3/xmpp/Commandxmppspy.java @@ -3,7 +3,7 @@ package net.ess3.xmpp; import net.ess3.commands.EssentialsCommand; import net.ess3.commands.NotEnoughArgumentsException; import java.util.List; -import org.bukkit.command.CommandSender; + import org.bukkit.entity.Player; |