From 711d42d6042e1700abe33b4832eeb75d6e1a9a12 Mon Sep 17 00:00:00 2001 From: snowleo Date: Sun, 8 Apr 2012 00:07:53 +0200 Subject: [PATCH] Server-Layer Part 1 --- .../src/com/earth2me/essentials/Console.java | 8 +- .../com/earth2me/essentials/Essentials.java | 162 +++++--------- .../earth2me/essentials/EssentialsTimer.java | 3 +- .../src/com/earth2me/essentials/I18n.java | 2 +- .../src/com/earth2me/essentials/ItemDb.java | 14 +- .../src/com/earth2me/essentials/Jails.java | 8 +- .../src/com/earth2me/essentials/Kits.java | 2 +- .../src/com/earth2me/essentials/Teleport.java | 35 ++- .../src/com/earth2me/essentials/Warps.java | 11 +- .../essentials/api/ICommandHandler.java | 6 +- .../earth2me/essentials/api/IComponent.java | 13 ++ .../earth2me/essentials/api/IEssentials.java | 37 ++-- .../com/earth2me/essentials/api/IItemDb.java | 2 +- .../earth2me/essentials/api/IPermission.java | 13 +- .../com/earth2me/essentials/api/IReplyTo.java | 6 +- .../com/earth2me/essentials/api/IUser.java | 12 +- .../com/earth2me/essentials/api/IUserMap.java | 2 +- .../com/earth2me/essentials/api/IWarps.java | 2 +- .../com/earth2me/essentials/api/IWorth.java | 3 +- .../essentials/api/server/Enchantment.java | 7 + .../essentials/api/server/ICommandSender.java | 13 ++ .../essentials/api/server/IInventory.java | 19 ++ .../essentials/api/server/IPermission.java | 5 - .../api/server/IPermissionsManager.java | 8 - .../essentials/api/server/IPlayer.java | 5 - .../essentials/api/server/IPlugin.java | 32 +++ .../essentials/api/server/IServer.java | 25 ++- .../essentials/api/server/IWorld.java | 24 +++ .../essentials/api/server/ItemStack.java | 47 ++++ .../essentials/api/server/Location.java | 52 +++++ .../essentials/api/server/Material.java | 37 ++++ .../essentials/api/server/Permission.java | 27 +++ .../essentials/api/server/Player.java | 61 ++++++ .../earth2me/essentials/backup/Backup.java | 20 +- .../essentials/bukkit/BukkitItemStack.java | 62 ++++++ .../essentials/bukkit/BukkitLocation.java | 63 ++++++ .../essentials/bukkit/BukkitMaterial.java | 62 ++++++ .../essentials/bukkit/BukkitPermission.java | 82 +++++++ .../essentials/bukkit/BukkitPlayer.java | 202 ++++++++++++++++++ .../essentials/bukkit/CommandSender.java | 40 ++++ .../essentials/bukkit/EssentialsPlugin.java | 92 +++++++- .../earth2me/essentials/bukkit/Inventory.java | 48 +++++ .../earth2me/essentials/bukkit/Plugin.java | 87 ++++++++ .../earth2me/essentials/bukkit/Server.java | 123 ++++++++++- .../essentials/bukkit/VersionCheck.java | 46 ++++ .../com/earth2me/essentials/bukkit/World.java | 44 ++++ .../essentials/commands/Commandbackup.java | 3 +- .../essentials/commands/Commandbalance.java | 3 +- .../commands/Commandbalancetop.java | 17 +- .../essentials/commands/Commandban.java | 8 +- .../essentials/commands/Commandbanip.java | 3 +- .../essentials/commands/Commandbigtree.java | 2 +- .../essentials/commands/Commandbroadcast.java | 3 +- .../essentials/commands/Commandburn.java | 4 +- .../commands/Commandclearinventory.java | 4 +- .../essentials/commands/Commanddelhome.java | 3 +- .../essentials/commands/Commanddeljail.java | 3 +- .../essentials/commands/Commanddelwarp.java | 3 +- .../essentials/commands/Commandeco.java | 6 +- .../commands/Commandessentials.java | 27 +-- .../essentials/commands/Commandext.java | 6 +- .../essentials/commands/Commandfeed.java | 3 +- .../essentials/commands/Commandgamemode.java | 5 +- .../essentials/commands/Commandgc.java | 6 +- .../essentials/commands/Commandgetpos.java | 3 +- .../essentials/commands/Commandgive.java | 3 +- .../essentials/commands/Commandgod.java | 3 +- .../essentials/commands/Commandheal.java | 6 +- .../essentials/commands/Commandhelp.java | 3 +- .../essentials/commands/Commandhelpop.java | 3 +- .../essentials/commands/Commandinfo.java | 3 +- .../essentials/commands/Commanditem.java | 7 +- .../essentials/commands/Commanditemdb.java | 3 +- .../essentials/commands/Commandjails.java | 3 +- .../essentials/commands/Commandjump.java | 3 +- .../essentials/commands/Commandkick.java | 7 +- .../essentials/commands/Commandkickall.java | 8 +- .../essentials/commands/Commandkill.java | 3 +- .../essentials/commands/Commandkillall.java | 3 +- .../commands/Commandkittycannon.java | 2 +- .../essentials/commands/Commandlightning.java | 3 +- .../essentials/commands/Commandlist.java | 18 +- .../essentials/commands/Commandmail.java | 8 +- .../essentials/commands/Commandmore.java | 1 + .../essentials/commands/Commandmotd.java | 3 +- .../essentials/commands/Commandmsg.java | 5 +- .../essentials/commands/Commandmute.java | 3 +- .../essentials/commands/Commandnear.java | 3 +- .../essentials/commands/Commandnick.java | 3 +- .../essentials/commands/Commandnuke.java | 3 +- .../essentials/commands/Commandptime.java | 3 +- .../essentials/commands/Commandr.java | 7 +- .../essentials/commands/Commandrealname.java | 3 +- .../essentials/commands/Commandremove.java | 3 +- .../essentials/commands/Commandrules.java | 3 +- .../essentials/commands/Commandseen.java | 3 +- .../essentials/commands/Commandsethome.java | 12 +- .../essentials/commands/Commandsetworth.java | 3 +- .../essentials/commands/Commandspawn.java | 3 +- .../essentials/commands/Commandsudo.java | 11 +- .../essentials/commands/Commandsuicide.java | 3 +- .../essentials/commands/Commandtempban.java | 3 +- .../essentials/commands/Commandtime.java | 3 +- .../commands/Commandtogglejail.java | 3 +- .../essentials/commands/Commandtp.java | 3 +- .../essentials/commands/Commandtpaall.java | 3 +- .../essentials/commands/Commandtpall.java | 3 +- .../essentials/commands/Commandunban.java | 3 +- .../essentials/commands/Commandunbanip.java | 3 +- .../essentials/commands/Commandunlimited.java | 10 +- .../essentials/commands/Commandwarp.java | 5 +- .../essentials/commands/Commandweather.java | 10 +- .../essentials/commands/Commandwhois.java | 9 +- .../essentials/commands/Commandworld.java | 14 +- .../essentials/commands/Commandworth.java | 7 +- .../commands/EssentialsCommand.java | 24 +-- .../commands/EssentialsCommandHandler.java | 5 +- .../commands/IEssentialsCommand.java | 4 +- .../essentials/craftbukkit/SetExpFix.java | 6 +- .../essentials/economy/MoneyHolder.java | 2 +- .../earth2me/essentials/economy/Trade.java | 34 ++- .../essentials/economy/WorthHolder.java | 4 +- .../listener/EssentialsBlockListener.java | 2 +- .../AbstractSuperpermsPermission.java | 17 +- .../permissions/BasePermission.java | 2 +- .../permissions/GivePermissions.java | 13 +- .../permissions/ItemPermissions.java | 13 +- .../permissions/KitPermissions.java | 6 +- .../essentials/permissions/Permissions.java | 33 ++- .../permissions/UnlimitedItemPermissions.java | 6 +- .../permissions/WarpPermissions.java | 6 +- .../essentials/ranks/RanksStorage.java | 2 +- .../essentials/ranks/VaultGroups.java | 27 +-- .../earth2me/essentials/settings/Jails.java | 6 +- .../essentials/settings/SettingsHolder.java | 2 +- .../earth2me/essentials/settings/Spawns.java | 6 +- .../essentials/settings/SpawnsHolder.java | 14 +- .../earth2me/essentials/settings/Warp.java | 4 +- .../AbstractDelayedYamlFileReader.java | 10 +- .../AbstractDelayedYamlFileWriter.java | 13 +- .../essentials/storage/BukkitConstructor.java | 22 +- .../essentials/storage/ManagedFile.java | 4 +- .../essentials/storage/StorageObjectMap.java | 9 +- .../{Location.java => StoredLocation.java} | 26 +-- .../essentials/storage/YamlStorageReader.java | 6 +- .../essentials/storage/YamlStorageWriter.java | 14 +- .../essentials/user/IOfflinePlayer.java | 2 +- .../essentials/user/IOfflineUser.java | 2 +- .../com/earth2me/essentials/user/User.java | 48 ++--- .../earth2me/essentials/user/UserBase.java | 123 ++--------- .../earth2me/essentials/user/UserData.java | 13 +- .../com/earth2me/essentials/user/UserMap.java | 1 + .../utils/textreader/KeywordReplacer.java | 24 +-- .../utils/textreader/TextInput.java | 23 +- .../utils/textreader/TextPager.java | 3 +- .../com/earth2me/essentials/EconomyTest.java | 20 +- .../earth2me/essentials/EssentialsTest.java | 26 +++ .../com/earth2me/essentials/StorageTest.java | 26 +-- .../com/earth2me/essentials/UserTest.java | 25 +-- .../com/earth2me/essentials/UtilTest.java | 22 +- .../essentials/testserver/Player.java | 152 +++++++++++++ .../essentials/testserver/Plugin.java | 69 ++++++ .../essentials/testserver/Server.java | 89 ++++++++ .../earth2me/essentials/testserver/World.java | 27 +++ .../essentials/EssentialsUpgrade.java | 18 +- .../earth2me/essentials/xmpp/Commandxmpp.java | 3 +- .../essentials/xmpp/Commandxmppspy.java | 3 +- 167 files changed, 2255 insertions(+), 835 deletions(-) create mode 100644 Essentials/src/com/earth2me/essentials/api/IComponent.java create mode 100644 Essentials/src/com/earth2me/essentials/api/server/Enchantment.java create mode 100644 Essentials/src/com/earth2me/essentials/api/server/ICommandSender.java create mode 100644 Essentials/src/com/earth2me/essentials/api/server/IInventory.java delete mode 100644 Essentials/src/com/earth2me/essentials/api/server/IPermission.java delete mode 100644 Essentials/src/com/earth2me/essentials/api/server/IPermissionsManager.java delete mode 100644 Essentials/src/com/earth2me/essentials/api/server/IPlayer.java create mode 100644 Essentials/src/com/earth2me/essentials/api/server/IPlugin.java create mode 100644 Essentials/src/com/earth2me/essentials/api/server/IWorld.java create mode 100644 Essentials/src/com/earth2me/essentials/api/server/ItemStack.java create mode 100644 Essentials/src/com/earth2me/essentials/api/server/Location.java create mode 100644 Essentials/src/com/earth2me/essentials/api/server/Material.java create mode 100644 Essentials/src/com/earth2me/essentials/api/server/Permission.java create mode 100644 Essentials/src/com/earth2me/essentials/api/server/Player.java create mode 100644 Essentials/src/com/earth2me/essentials/bukkit/BukkitItemStack.java create mode 100644 Essentials/src/com/earth2me/essentials/bukkit/BukkitLocation.java create mode 100644 Essentials/src/com/earth2me/essentials/bukkit/BukkitMaterial.java create mode 100644 Essentials/src/com/earth2me/essentials/bukkit/BukkitPermission.java create mode 100644 Essentials/src/com/earth2me/essentials/bukkit/BukkitPlayer.java create mode 100644 Essentials/src/com/earth2me/essentials/bukkit/CommandSender.java create mode 100644 Essentials/src/com/earth2me/essentials/bukkit/Inventory.java create mode 100644 Essentials/src/com/earth2me/essentials/bukkit/Plugin.java create mode 100644 Essentials/src/com/earth2me/essentials/bukkit/VersionCheck.java create mode 100644 Essentials/src/com/earth2me/essentials/bukkit/World.java rename Essentials/src/com/earth2me/essentials/storage/{Location.java => StoredLocation.java} (67%) create mode 100644 Essentials/test/com/earth2me/essentials/EssentialsTest.java create mode 100644 Essentials/test/com/earth2me/essentials/testserver/Player.java create mode 100644 Essentials/test/com/earth2me/essentials/testserver/Plugin.java create mode 100644 Essentials/test/com/earth2me/essentials/testserver/Server.java create mode 100644 Essentials/test/com/earth2me/essentials/testserver/World.java diff --git a/Essentials/src/com/earth2me/essentials/Console.java b/Essentials/src/com/earth2me/essentials/Console.java index 2e43883cf..304764adf 100644 --- a/Essentials/src/com/earth2me/essentials/Console.java +++ b/Essentials/src/com/earth2me/essentials/Console.java @@ -1,13 +1,13 @@ package com.earth2me.essentials; import com.earth2me.essentials.api.IReplyTo; -import org.bukkit.command.CommandSender; +import com.earth2me.essentials.api.server.ICommandSender; public final class Console implements IReplyTo { private static Console instance = new Console(); - private CommandSender replyTo; + private ICommandSender replyTo; public final static String NAME = "Console"; private Console() @@ -15,13 +15,13 @@ public final class Console implements IReplyTo } @Override - public void setReplyTo(final CommandSender user) + public void setReplyTo(final ICommandSender user) { replyTo = user; } @Override - public CommandSender getReplyTo() + public ICommandSender getReplyTo() { return replyTo; } diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index ccea1ba15..c5503fdf5 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -17,50 +17,43 @@ */ package com.earth2me.essentials; -import com.earth2me.essentials.economy.Trade; -import com.earth2me.essentials.commands.EssentialsCommandHandler; -import com.earth2me.essentials.utils.ExecuteTimer; -import com.earth2me.essentials.economy.WorthHolder; -import com.earth2me.essentials.economy.Economy; -import com.earth2me.essentials.backup.Backup; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.*; -import com.earth2me.essentials.listener.*; +import com.earth2me.essentials.api.server.Player; +import com.earth2me.essentials.api.server.IPlugin; +import com.earth2me.essentials.api.server.IServer; +import com.earth2me.essentials.api.server.IWorld; +import com.earth2me.essentials.backup.Backup; +import com.earth2me.essentials.commands.EssentialsCommandHandler; +import com.earth2me.essentials.economy.Economy; +import com.earth2me.essentials.economy.Trade; +import com.earth2me.essentials.economy.WorthHolder; import com.earth2me.essentials.economy.register.Methods; +import com.earth2me.essentials.listener.*; import com.earth2me.essentials.ranks.RanksStorage; import com.earth2me.essentials.settings.SettingsHolder; import com.earth2me.essentials.settings.SpawnsHolder; import com.earth2me.essentials.user.UserMap; +import com.earth2me.essentials.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 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 = 2015; - private static final Logger LOGGER = Logger.getLogger("Minecraft"); private transient ISettings settings; private final transient TntExplodeListener tntListener = new TntExplodeListener(this); private transient IJails jails; @@ -76,10 +69,26 @@ 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; + + 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() @@ -99,11 +108,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, _("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); @@ -116,36 +124,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())) - { - 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, _("notRecommendedBukkit")); - LOGGER.log(Level.SEVERE, _("requiredBukkit", Integer.toString(BUKKIT_VERSION))); - 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 { @@ -180,19 +161,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, _("essentialsHelp2")); } else { - LOGGER.log(Level.SEVERE, _("essentialsHelp1")); + logger.log(Level.SEVERE, _("essentialsHelp1")); } - LOGGER.log(Level.SEVERE, exception.toString()); + logger.log(Level.SEVERE, exception.toString()); pm.registerEvents(new Listener() { @EventHandler(priority = EventPriority.LOW) @@ -230,12 +211,12 @@ public class Essentials extends JavaPlugin implements IEssentials final EssentialsTimer timer = new EssentialsTimer(this); - getServer().getScheduler().scheduleSyncRepeatingTask(this, timer, 1, 100); + getPlugin().scheduleSyncRepeatingTask(timer, 1, 100); execTimer.mark("RegListeners"); final String timeroutput = execTimer.end(); if (getSettings().isDebug()) { - LOGGER.log(Level.INFO, "Essentials load {0}", timeroutput); + logger.log(Level.INFO, "Essentials load {0}", timeroutput); } } @@ -247,7 +228,7 @@ public class Essentials extends JavaPlugin implements IEssentials } @Override - public void reload() + public void onReload() { Trade.closeLog(); @@ -260,13 +241,6 @@ public class Essentials extends JavaPlugin implements IEssentials i18n.updateLocale(settings.getLocale()); } - @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(), "com.earth2me.essentials.commands.Command", "essentials.", null); - } - @Override public IJails getJails() { @@ -297,12 +271,6 @@ public class Essentials extends JavaPlugin implements IEssentials return backup; } - @Override - public IUser getUser(final Player player) - { - return userMap.getUser(player); - } - @Override public IUser getUser(final String playerName) { @@ -310,7 +278,7 @@ public class Essentials extends JavaPlugin implements IEssentials } @Override - public World getWorld(final String name) + public IWorld getWorld(final String name) { if (name.matches("[0-9]+")) { @@ -346,42 +314,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.getName())) { 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 @@ -404,13 +346,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/com/earth2me/essentials/EssentialsTimer.java b/Essentials/src/com/earth2me/essentials/EssentialsTimer.java index d773b3d43..8bbcb4c66 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsTimer.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsTimer.java @@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.Player; import com.earth2me.essentials.permissions.Permissions; import com.earth2me.essentials.user.UserData.TimestampType; import java.util.HashSet; @@ -33,7 +34,7 @@ public class EssentialsTimer implements Runnable try { - final IUser user = ess.getUser(player); + final IUser user = player.getUser(); onlineUsers.add(user); user.setLastOnlineActivity(currentTime); user.checkActivity(); diff --git a/Essentials/src/com/earth2me/essentials/I18n.java b/Essentials/src/com/earth2me/essentials/I18n.java index 7108254ff..6eb164dd4 100644 --- a/Essentials/src/com/earth2me/essentials/I18n.java +++ b/Essentials/src/com/earth2me/essentials/I18n.java @@ -137,7 +137,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/com/earth2me/essentials/ItemDb.java b/Essentials/src/com/earth2me/essentials/ItemDb.java index cfcc00dd2..479119a31 100644 --- a/Essentials/src/com/earth2me/essentials/ItemDb.java +++ b/Essentials/src/com/earth2me/essentials/ItemDb.java @@ -5,6 +5,8 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IItemDb; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ItemStack; +import com.earth2me.essentials.api.server.Material; import com.earth2me.essentials.permissions.Permissions; import java.util.HashMap; import java.util.List; @@ -12,8 +14,6 @@ import java.util.Locale; import java.util.Map; import java.util.regex.Pattern; import lombok.Cleanup; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; public class ItemDb implements IItemDb @@ -129,9 +129,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 +140,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/com/earth2me/essentials/Jails.java b/Essentials/src/com/earth2me/essentials/Jails.java index 171611a6a..cc95da8aa 100644 --- a/Essentials/src/com/earth2me/essentials/Jails.java +++ b/Essentials/src/com/earth2me/essentials/Jails.java @@ -49,7 +49,7 @@ public class Jails extends AsyncStorageObjectHolder()); + getData().setJails(new HashMap()); } - getData().getJails().put(jailName.toLowerCase(Locale.ENGLISH), new com.earth2me.essentials.storage.Location(loc)); + getData().getJails().put(jailName.toLowerCase(Locale.ENGLISH), new com.earth2me.essentials.storage.StoredLocation(loc)); } finally { diff --git a/Essentials/src/com/earth2me/essentials/Kits.java b/Essentials/src/com/earth2me/essentials/Kits.java index 3c3e61a5d..2f12188eb 100644 --- a/Essentials/src/com/earth2me/essentials/Kits.java +++ b/Essentials/src/com/earth2me/essentials/Kits.java @@ -23,7 +23,7 @@ public class Kits extends AsyncStorageObjectHolder implements IWarps { - private static final Logger logger = Bukkit.getLogger(); - public Warps(IEssentials ess) { super(ess, "warps"); @@ -66,7 +63,7 @@ public class Warps extends StorageObjectMap implements IWarps warp.acquireReadLock(); try { - return warp.getData().getLocation().getBukkitLocation(); + return warp.getData().getLocation().getStoredLocation(); } finally { @@ -77,10 +74,10 @@ public class Warps extends StorageObjectMap implements IWarps @Override public void setWarp(final String name, final Location loc) throws Exception { - setWarp(name, new com.earth2me.essentials.storage.Location(loc)); + setWarp(name, new com.earth2me.essentials.storage.StoredLocation(loc)); } - public void setWarp(final String name, final com.earth2me.essentials.storage.Location loc) throws Exception + public void setWarp(final String name, final com.earth2me.essentials.storage.StoredLocation loc) throws Exception { IWarp warp = getObject(name); if (warp == null) diff --git a/Essentials/src/com/earth2me/essentials/api/ICommandHandler.java b/Essentials/src/com/earth2me/essentials/api/ICommandHandler.java index f756c16c4..ec5d28af9 100644 --- a/Essentials/src/com/earth2me/essentials/api/ICommandHandler.java +++ b/Essentials/src/com/earth2me/essentials/api/ICommandHandler.java @@ -1,8 +1,8 @@ package com.earth2me.essentials.api; +import com.earth2me.essentials.api.server.ICommandSender; import java.util.Map; import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; import org.bukkit.plugin.Plugin; @@ -14,7 +14,7 @@ public interface ICommandHandler extends IReload public void addPlugin(Plugin plugin); - boolean handleCommand(CommandSender sender, Command command, String commandLabel, String[] args); + boolean handleCommand(ICommandSender sender, Command command, String commandLabel, String[] args); - void showCommandError(CommandSender sender, String commandLabel, Throwable exception); + void showCommandError(ICommandSender sender, String commandLabel, Throwable exception); } diff --git a/Essentials/src/com/earth2me/essentials/api/IComponent.java b/Essentials/src/com/earth2me/essentials/api/IComponent.java new file mode 100644 index 000000000..ae3c2a9c2 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/api/IComponent.java @@ -0,0 +1,13 @@ +package com.earth2me.essentials.api; + +public interface IComponent extends IReload { + /** + * Enable the component. + */ + void onEnable(); + + /** + * Disable the component. + */ + void onDisable(); +} diff --git a/Essentials/src/com/earth2me/essentials/api/IEssentials.java b/Essentials/src/com/earth2me/essentials/api/IEssentials.java index 42c9a964d..b662030cf 100644 --- a/Essentials/src/com/earth2me/essentials/api/IEssentials.java +++ b/Essentials/src/com/earth2me/essentials/api/IEssentials.java @@ -1,18 +1,18 @@ package com.earth2me.essentials.api; -import com.earth2me.essentials.listener.TntExplodeListener; +import com.earth2me.essentials.api.server.Player; +import com.earth2me.essentials.api.server.IPlugin; +import com.earth2me.essentials.api.server.IServer; +import com.earth2me.essentials.api.server.IWorld; import com.earth2me.essentials.economy.register.Methods; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; +import com.earth2me.essentials.listener.TntExplodeListener; +import java.util.logging.Logger; -public interface IEssentials extends Plugin +public interface IEssentials extends IComponent { void addReloadListener(IReload listener); - IUser getUser(Player player); - IUser getUser(String playerName); int broadcastMessage(IUser sender, String message); @@ -39,21 +39,16 @@ public interface IEssentials extends Plugin ICommandHandler getCommandHandler(); - World getWorld(String name); + IWorld getWorld(String name); 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); @@ -61,4 +56,10 @@ public interface IEssentials extends Plugin void removeReloadListener(IReload groups); IEconomy getEconomy(); + + IServer getServer(); + + Logger getLogger(); + + IPlugin getPlugin(); } diff --git a/Essentials/src/com/earth2me/essentials/api/IItemDb.java b/Essentials/src/com/earth2me/essentials/api/IItemDb.java index 29f97488c..b792e02d2 100644 --- a/Essentials/src/com/earth2me/essentials/api/IItemDb.java +++ b/Essentials/src/com/earth2me/essentials/api/IItemDb.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.api; -import org.bukkit.inventory.ItemStack; +import com.earth2me.essentials.api.server.ItemStack; public interface IItemDb extends IReload diff --git a/Essentials/src/com/earth2me/essentials/api/IPermission.java b/Essentials/src/com/earth2me/essentials/api/IPermission.java index d388bff47..7a14bd1be 100644 --- a/Essentials/src/com/earth2me/essentials/api/IPermission.java +++ b/Essentials/src/com/earth2me/essentials/api/IPermission.java @@ -1,17 +1,16 @@ package com.earth2me.essentials.api; -import org.bukkit.command.CommandSender; -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionDefault; +import com.earth2me.essentials.api.server.ICommandSender; +import com.earth2me.essentials.api.server.Permission; public interface IPermission { - String getPermission(); + String getPermissionName(); - boolean isAuthorized(CommandSender sender); + boolean isAuthorized(ICommandSender sender); - Permission getBukkitPermission(); + Permission getPermission(); - PermissionDefault getPermissionDefault(); + Permission.Default getPermissionDefault(); } diff --git a/Essentials/src/com/earth2me/essentials/api/IReplyTo.java b/Essentials/src/com/earth2me/essentials/api/IReplyTo.java index 3003ca3df..415c1f4fb 100644 --- a/Essentials/src/com/earth2me/essentials/api/IReplyTo.java +++ b/Essentials/src/com/earth2me/essentials/api/IReplyTo.java @@ -1,11 +1,11 @@ package com.earth2me.essentials.api; -import org.bukkit.command.CommandSender; +import com.earth2me.essentials.api.server.ICommandSender; public interface IReplyTo { - void setReplyTo(CommandSender user); + void setReplyTo(ICommandSender user); - CommandSender getReplyTo(); + ICommandSender getReplyTo(); } diff --git a/Essentials/src/com/earth2me/essentials/api/IUser.java b/Essentials/src/com/earth2me/essentials/api/IUser.java index 091b141df..945483758 100644 --- a/Essentials/src/com/earth2me/essentials/api/IUser.java +++ b/Essentials/src/com/earth2me/essentials/api/IUser.java @@ -1,13 +1,13 @@ package com.earth2me.essentials.api; +import com.earth2me.essentials.api.server.ICommandSender; +import com.earth2me.essentials.api.server.Player; +import com.earth2me.essentials.api.server.ItemStack; +import com.earth2me.essentials.api.server.Location; import com.earth2me.essentials.storage.IStorageObjectHolder; import com.earth2me.essentials.user.CooldownException; import com.earth2me.essentials.user.UserData; import java.util.List; -import org.bukkit.Location; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; public interface IUser extends Player, IStorageObjectHolder, IReload, IReplyTo, Comparable @@ -18,11 +18,11 @@ public interface IUser extends Player, IStorageObjectHolder, IReload, void takeMoney(double value); - void takeMoney(double value, CommandSender initiator); + void takeMoney(double value, ICommandSender initiator); void giveMoney(double value); - void giveMoney(double value, CommandSender initiator); + void giveMoney(double value, ICommandSender initiator); void giveItems(ItemStack itemStack, Boolean canSpew) throws ChargeException; diff --git a/Essentials/src/com/earth2me/essentials/api/IUserMap.java b/Essentials/src/com/earth2me/essentials/api/IUserMap.java index fbe6cfa0e..394f23a97 100644 --- a/Essentials/src/com/earth2me/essentials/api/IUserMap.java +++ b/Essentials/src/com/earth2me/essentials/api/IUserMap.java @@ -1,8 +1,8 @@ package com.earth2me.essentials.api; +import com.earth2me.essentials.api.server.Player; import java.io.File; import java.util.Set; -import org.bukkit.entity.Player; public interface IUserMap extends IReload diff --git a/Essentials/src/com/earth2me/essentials/api/IWarps.java b/Essentials/src/com/earth2me/essentials/api/IWarps.java index 2a98ecc64..3c3c4a2e4 100644 --- a/Essentials/src/com/earth2me/essentials/api/IWarps.java +++ b/Essentials/src/com/earth2me/essentials/api/IWarps.java @@ -1,8 +1,8 @@ package com.earth2me.essentials.api; +import com.earth2me.essentials.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/com/earth2me/essentials/api/IWorth.java b/Essentials/src/com/earth2me/essentials/api/IWorth.java index 4add98771..6a1ba2e9a 100644 --- a/Essentials/src/com/earth2me/essentials/api/IWorth.java +++ b/Essentials/src/com/earth2me/essentials/api/IWorth.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.api; -import org.bukkit.inventory.ItemStack; +import com.earth2me.essentials.api.server.ItemStack; + public interface IWorth extends IReload diff --git a/Essentials/src/com/earth2me/essentials/api/server/Enchantment.java b/Essentials/src/com/earth2me/essentials/api/server/Enchantment.java new file mode 100644 index 000000000..0aff6843a --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/api/server/Enchantment.java @@ -0,0 +1,7 @@ +package com.earth2me.essentials.api.server; + +public abstract class Enchantment { + + public abstract int getMaxLevel(); + +} diff --git a/Essentials/src/com/earth2me/essentials/api/server/ICommandSender.java b/Essentials/src/com/earth2me/essentials/api/server/ICommandSender.java new file mode 100644 index 000000000..6f03a5f9b --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/api/server/ICommandSender.java @@ -0,0 +1,13 @@ +package com.earth2me.essentials.api.server; + +public interface ICommandSender { + boolean isPlayer(); + + void sendMessage(String message); + + boolean isOp(); + + boolean hasPermission(Permission bukkitPermission); + + void sendMessage(String[] string); +} diff --git a/Essentials/src/com/earth2me/essentials/api/server/IInventory.java b/Essentials/src/com/earth2me/essentials/api/server/IInventory.java new file mode 100644 index 000000000..301f040da --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/api/server/IInventory.java @@ -0,0 +1,19 @@ +package com.earth2me.essentials.api.server; + +import java.util.Map; + +public interface IInventory { + + public boolean containsItem(boolean b, boolean b0, ItemStack itemStack); + + public Map addItem(ItemStack itemStack); + + public Map addItem(boolean b, ItemStack itemStack); + + public Map 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/com/earth2me/essentials/api/server/IPermission.java b/Essentials/src/com/earth2me/essentials/api/server/IPermission.java deleted file mode 100644 index 3b5cf2eb4..000000000 --- a/Essentials/src/com/earth2me/essentials/api/server/IPermission.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.earth2me.essentials.api.server; - -public interface IPermission { - -} diff --git a/Essentials/src/com/earth2me/essentials/api/server/IPermissionsManager.java b/Essentials/src/com/earth2me/essentials/api/server/IPermissionsManager.java deleted file mode 100644 index d8f017e20..000000000 --- a/Essentials/src/com/earth2me/essentials/api/server/IPermissionsManager.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.earth2me.essentials.api.server; - -public interface IPermissionsManager { - - IPermission registerPermission(); - - boolean checkPermission(IPlayer player, IPermission perm); -} diff --git a/Essentials/src/com/earth2me/essentials/api/server/IPlayer.java b/Essentials/src/com/earth2me/essentials/api/server/IPlayer.java deleted file mode 100644 index 7d0899e81..000000000 --- a/Essentials/src/com/earth2me/essentials/api/server/IPlayer.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.earth2me.essentials.api.server; - -public interface IPlayer { - -} diff --git a/Essentials/src/com/earth2me/essentials/api/server/IPlugin.java b/Essentials/src/com/earth2me/essentials/api/server/IPlugin.java new file mode 100644 index 000000000..61dadcbd6 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/api/server/IPlugin.java @@ -0,0 +1,32 @@ +package com.earth2me.essentials.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/com/earth2me/essentials/api/server/IServer.java b/Essentials/src/com/earth2me/essentials/api/server/IServer.java index 2c267b6cb..455805796 100644 --- a/Essentials/src/com/earth2me/essentials/api/server/IServer.java +++ b/Essentials/src/com/earth2me/essentials/api/server/IServer.java @@ -1,5 +1,28 @@ package com.earth2me.essentials.api.server; -public interface IServer { +import java.util.Collection; +import java.util.List; + +public interface IServer +{ + List getWorlds(); + + IWorld getWorld(String name); + + int broadcastMessage(String message); + + Collection getOnlinePlayers(); + + ICommandSender getConsoleSender(); + + void dispatchCommand(ICommandSender sender, String command); + + void banIP(String ip); + + T getServiceProvider(Class clazz); + + String getVersion(); + + public void unbanIP(String string); } diff --git a/Essentials/src/com/earth2me/essentials/api/server/IWorld.java b/Essentials/src/com/earth2me/essentials/api/server/IWorld.java new file mode 100644 index 000000000..b457460da --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/api/server/IWorld.java @@ -0,0 +1,24 @@ +package com.earth2me.essentials.api.server; + +import java.util.UUID; +import org.bukkit.TreeType; + +public interface IWorld { + String getName(); + + public boolean generateTree(Location safeLocation, TreeType tree); + + public int getHighestBlockYAt(int topX, int topZ); + + public ItemStack dropItem(Location loc, ItemStack stack); + + public UUID getUID(); + + public Location getSpawnLocation(); + + public void dropItemNaturally(Location location, ItemStack overflowStack); + + public void setStorm(boolean b); + + public void setWeatherDuration(int i); +} diff --git a/Essentials/src/com/earth2me/essentials/api/server/ItemStack.java b/Essentials/src/com/earth2me/essentials/api/server/ItemStack.java new file mode 100644 index 000000000..cb40fafc3 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/api/server/ItemStack.java @@ -0,0 +1,47 @@ +package com.earth2me.essentials.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/com/earth2me/essentials/api/server/Location.java b/Essentials/src/com/earth2me/essentials/api/server/Location.java new file mode 100644 index 000000000..f5ca8599d --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/api/server/Location.java @@ -0,0 +1,52 @@ +package com.earth2me.essentials.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(IWorld 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(IWorld world, double x, double y, double z) { + return factory.create(world, x, y, z, 0, 0); + } + + public static Location create(IWorld 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 IWorld getWorld(); + + public abstract double distanceSquared(Location location); +} diff --git a/Essentials/src/com/earth2me/essentials/api/server/Material.java b/Essentials/src/com/earth2me/essentials/api/server/Material.java new file mode 100644 index 000000000..d8486ef6d --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/api/server/Material.java @@ -0,0 +1,37 @@ +package com.earth2me.essentials.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/com/earth2me/essentials/api/server/Permission.java b/Essentials/src/com/earth2me/essentials/api/server/Permission.java new file mode 100644 index 000000000..71b045d53 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/api/server/Permission.java @@ -0,0 +1,27 @@ +package com.earth2me.essentials.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/com/earth2me/essentials/api/server/Player.java b/Essentials/src/com/earth2me/essentials/api/server/Player.java new file mode 100644 index 000000000..7c188aefd --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/api/server/Player.java @@ -0,0 +1,61 @@ +package com.earth2me.essentials.api.server; + +import com.earth2me.essentials.api.IUser; + + +public interface Player extends ICommandSender +{ + IUser getUser(); + + String getName(); + + String getDisplayName(); + + boolean isOnline(); + + void setBanned(boolean bool); + + void kickPlayer(String reason); + + IWorld 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/com/earth2me/essentials/backup/Backup.java b/Essentials/src/com/earth2me/essentials/backup/Backup.java index 2da391af9..965a71566 100644 --- a/Essentials/src/com/earth2me/essentials/backup/Backup.java +++ b/Essentials/src/com/earth2me/essentials/backup/Backup.java @@ -4,6 +4,8 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IBackup; import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.ISettings; +import com.earth2me.essentials.api.server.ICommandSender; +import com.earth2me.essentials.api.server.IServer; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -19,7 +21,7 @@ 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 +31,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 +51,7 @@ public class Backup implements Runnable, IBackup running.set(false); return; } - taskId = ess.scheduleSyncRepeatingTask(this, interval, interval); + taskId = ess.getPlugin().scheduleSyncRepeatingTask(this, interval, interval); } } @@ -69,11 +71,11 @@ public class Backup implements Runnable, IBackup return; } LOGGER.log(Level.INFO, _("backupStarted")); - final CommandSender consoleSender = server.getConsoleSender(); + final ICommandSender 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 +95,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 @@ -125,7 +127,7 @@ public class Backup implements Runnable, IBackup } finally { - ess.scheduleSyncDelayedTask(new EnableSavingRunner()); + ess.getPlugin().scheduleSyncDelayedTask(new EnableSavingRunner()); } } } @@ -137,12 +139,12 @@ 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); } } diff --git a/Essentials/src/com/earth2me/essentials/bukkit/BukkitItemStack.java b/Essentials/src/com/earth2me/essentials/bukkit/BukkitItemStack.java new file mode 100644 index 000000000..4e8f18185 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/bukkit/BukkitItemStack.java @@ -0,0 +1,62 @@ +package com.earth2me.essentials.bukkit; + +import com.earth2me.essentials.api.server.Enchantment; +import com.earth2me.essentials.api.server.ItemStack; +import com.earth2me.essentials.api.server.Material; +import lombok.Delegate; +import lombok.Getter; + + +public class BukkitItemStack extends com.earth2me.essentials.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/com/earth2me/essentials/bukkit/BukkitLocation.java b/Essentials/src/com/earth2me/essentials/bukkit/BukkitLocation.java new file mode 100644 index 000000000..046522e09 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/bukkit/BukkitLocation.java @@ -0,0 +1,63 @@ +package com.earth2me.essentials.bukkit; + +import com.earth2me.essentials.api.server.IWorld; +import com.earth2me.essentials.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(IWorld world, double x, double y, double z, double yaw, double pitch) + { + return new BukkitLocation(new org.bukkit.Location(((World)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 IWorld getWorld() + { + return new World(bukkitLocation.getWorld()); + } + + @Override + public double distanceSquared(final Location location) + { + return bukkitLocation.distanceSquared(((BukkitLocation)location).getBukkitLocation()); + } + +} diff --git a/Essentials/src/com/earth2me/essentials/bukkit/BukkitMaterial.java b/Essentials/src/com/earth2me/essentials/bukkit/BukkitMaterial.java new file mode 100644 index 000000000..84e485642 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/bukkit/BukkitMaterial.java @@ -0,0 +1,62 @@ +package com.earth2me.essentials.bukkit; + +import com.earth2me.essentials.api.server.Material; +import java.util.EnumMap; +import lombok.Delegate; + + +public class BukkitMaterial extends Material +{ + private static EnumMap materials = new EnumMap(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/com/earth2me/essentials/bukkit/BukkitPermission.java b/Essentials/src/com/earth2me/essentials/bukkit/BukkitPermission.java new file mode 100644 index 000000000..b1cbbe7ca --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/bukkit/BukkitPermission.java @@ -0,0 +1,82 @@ +package com.earth2me.essentials.bukkit; + +import com.earth2me.essentials.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/com/earth2me/essentials/bukkit/BukkitPlayer.java b/Essentials/src/com/earth2me/essentials/bukkit/BukkitPlayer.java new file mode 100644 index 000000000..e66ae2f07 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/bukkit/BukkitPlayer.java @@ -0,0 +1,202 @@ +package com.earth2me.essentials.bukkit; + +import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.*; +import lombok.Delegate; +import lombok.Getter; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.LivingEntity; + + +public class BukkitPlayer extends CommandSender 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 IWorld 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/com/earth2me/essentials/bukkit/CommandSender.java b/Essentials/src/com/earth2me/essentials/bukkit/CommandSender.java new file mode 100644 index 000000000..a06c308c3 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/bukkit/CommandSender.java @@ -0,0 +1,40 @@ +package com.earth2me.essentials.bukkit; + +import com.earth2me.essentials.api.server.ICommandSender; +import com.earth2me.essentials.api.server.Permission; +import lombok.Delegate; +import lombok.Getter; + + +public class CommandSender implements ICommandSender +{ + @Delegate + @Getter + private org.bukkit.command.CommandSender commandSender; + + public CommandSender(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/com/earth2me/essentials/bukkit/EssentialsPlugin.java b/Essentials/src/com/earth2me/essentials/bukkit/EssentialsPlugin.java index f58f2e5b6..533720254 100644 --- a/Essentials/src/com/earth2me/essentials/bukkit/EssentialsPlugin.java +++ b/Essentials/src/com/earth2me/essentials/bukkit/EssentialsPlugin.java @@ -1,7 +1,95 @@ package com.earth2me.essentials.bukkit; +import com.earth2me.essentials.Essentials; +import static com.earth2me.essentials.I18n._; +import com.earth2me.essentials.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) + { + ICommandSender commandSender; + if (sender instanceof org.bukkit.entity.Player) { + commandSender = ((Server)ess.getServer()).getPlayer((org.bukkit.entity.Player)sender); + } else { + commandSender = new CommandSender(sender); + } + return ess.getCommandHandler().handleCommand(commandSender, command, label, args); + } } diff --git a/Essentials/src/com/earth2me/essentials/bukkit/Inventory.java b/Essentials/src/com/earth2me/essentials/bukkit/Inventory.java new file mode 100644 index 000000000..fc33ea619 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/bukkit/Inventory.java @@ -0,0 +1,48 @@ +package com.earth2me.essentials.bukkit; + +import com.earth2me.essentials.api.server.IInventory; +import com.earth2me.essentials.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 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 addItem(boolean b, int oversizedStacksize, ItemStack itemStack) + { + throw new UnsupportedOperationException("Not supported yet."); + } + +} diff --git a/Essentials/src/com/earth2me/essentials/bukkit/Plugin.java b/Essentials/src/com/earth2me/essentials/bukkit/Plugin.java new file mode 100644 index 000000000..3dbb452b6 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/bukkit/Plugin.java @@ -0,0 +1,87 @@ +package com.earth2me.essentials.bukkit; + +import com.earth2me.essentials.api.server.Player; +import com.earth2me.essentials.api.server.IPlugin; +import com.earth2me.essentials.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/com/earth2me/essentials/bukkit/Server.java b/Essentials/src/com/earth2me/essentials/bukkit/Server.java index 1c10d9a7b..06d53522c 100644 --- a/Essentials/src/com/earth2me/essentials/bukkit/Server.java +++ b/Essentials/src/com/earth2me/essentials/bukkit/Server.java @@ -1,9 +1,126 @@ package com.earth2me.essentials.bukkit; +import com.earth2me.essentials.api.IEssentials; +import com.earth2me.essentials.api.server.ICommandSender; +import com.earth2me.essentials.api.server.Player; import com.earth2me.essentials.api.server.IServer; +import com.earth2me.essentials.api.server.IWorld; +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 { - @Delegate - private org.bukkit.Server server; + +public class Server implements IServer, Listener +{ + private IEssentials ess; + private interface Excludes + { + List getWorlds(); + + org.bukkit.World getWorld(String name); + + org.bukkit.entity.Player[] getOnlinePlayers(); + + CommandSender getConsoleSender(); + } + @Delegate(excludes = Excludes.class) + private final org.bukkit.Server server; + @Getter + private List worlds; + private Map worldsMap; + @Getter + private Collection onlinePlayers; + private Map onlinePlayersMap; + @Getter + private ICommandSender consoleSender; + + public Server(final org.bukkit.Server server) + { + this.server = server; + consoleSender = new CommandSender(server.getConsoleSender()); + updateWorlds(); + } + + private void updateWorlds() + { + final ArrayList lworlds = new ArrayList(server.getWorlds().size()); + final HashMap lworldsMap = new HashMap(); + for (org.bukkit.World world : server.getWorlds()) + { + final World w = new World(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 oplayersMap = new HashMap(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 oplayers = new ArrayList(onlinePlayers); + final HashMap oplayersMap = new HashMap(onlinePlayersMap); + oplayersMap.remove(event.getPlayer()); + onlinePlayersMap = Collections.unmodifiableMap(oplayersMap); + onlinePlayers = Collections.unmodifiableCollection(oplayersMap.values()); + } + + @Override + public IWorld getWorld(final String name) + { + final IWorld world = worldsMap.get(name); + if (world == null) + { + return worldsMap.get(name.toLowerCase(Locale.ENGLISH)); + } + return world; + } + + @Override + public void dispatchCommand(final ICommandSender sender, final String command) + { + server.dispatchCommand(((CommandSender)sender).getCommandSender(), command); + } + + @Override + public T getServiceProvider(final Class clazz) + { + final RegisteredServiceProvider 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/com/earth2me/essentials/bukkit/VersionCheck.java b/Essentials/src/com/earth2me/essentials/bukkit/VersionCheck.java new file mode 100644 index 000000000..516514fa8 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/bukkit/VersionCheck.java @@ -0,0 +1,46 @@ +package com.earth2me.essentials.bukkit; + +import static com.earth2me.essentials.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/com/earth2me/essentials/bukkit/World.java b/Essentials/src/com/earth2me/essentials/bukkit/World.java new file mode 100644 index 000000000..9cead97f7 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/bukkit/World.java @@ -0,0 +1,44 @@ +package com.earth2me.essentials.bukkit; + +import com.earth2me.essentials.api.server.IWorld; +import com.earth2me.essentials.api.server.ItemStack; +import com.earth2me.essentials.api.server.Location; +import lombok.Delegate; +import lombok.Getter; +import org.bukkit.TreeType; + +public class World implements IWorld { + @Delegate + @Getter + private final org.bukkit.World bukkitWorld; + + public World(final org.bukkit.World world) + { + this.bukkitWorld = world; + } + + @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/com/earth2me/essentials/commands/Commandbackup.java b/Essentials/src/com/earth2me/essentials/commands/Commandbackup.java index 867135a93..2f7a69662 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbackup.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbackup.java @@ -2,13 +2,14 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IBackup; +import com.earth2me.essentials.api.server.ICommandSender; import org.bukkit.command.CommandSender; public class Commandbackup extends EssentialsCommand { @Override - protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { final IBackup backup = ess.getBackup(); backup.run(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java b/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java index 9e8587be8..b8b12d086 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.utils.Util; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.permissions.Permissions; import org.bukkit.command.CommandSender; @@ -10,7 +11,7 @@ import org.bukkit.command.CommandSender; public class Commandbalance extends EssentialsCommand { @Override - protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java index 1508a134f..0345eb712 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.utils.Util; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.utils.textreader.ArrayListInput; import com.earth2me.essentials.utils.textreader.TextPager; import java.text.DateFormat; @@ -21,7 +22,7 @@ public class Commandbalancetop extends EssentialsCommand private static ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); @Override - protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { int page = 0; boolean force = false; @@ -58,7 +59,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,12 +67,12 @@ 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)); } } - private static void outputCache(final CommandSender sender, int page) + private static void outputCache(final ICommandSender sender, int page) { final Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(cacheage); @@ -139,18 +140,18 @@ public class Commandbalancetop extends EssentialsCommand { lock.writeLock().unlock(); } - ess.scheduleAsyncDelayedTask(viewer); + ess.getPlugin().scheduleAsyncDelayedTask(viewer); } } private class Viewer implements Runnable { - private final transient CommandSender sender; + private final transient ICommandSender sender; private final transient int page; private final transient boolean force; - public Viewer(final CommandSender sender, final int page, final boolean force) + public Viewer(final ICommandSender sender, final int page, final boolean force) { this.sender = sender; this.page = page; @@ -173,7 +174,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/com/earth2me/essentials/commands/Commandban.java b/Essentials/src/com/earth2me/essentials/commands/Commandban.java index 1feffd135..87ce58422 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandban.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandban.java @@ -3,6 +3,8 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; +import com.earth2me.essentials.api.server.Player; import com.earth2me.essentials.permissions.Permissions; import com.earth2me.essentials.user.Ban; import lombok.Cleanup; @@ -13,7 +15,7 @@ import org.bukkit.entity.Player; public class Commandban extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -54,9 +56,9 @@ public class Commandban extends EssentialsCommand user.kickPlayer(banReason); final String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME; - 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/com/earth2me/essentials/commands/Commandbanip.java b/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java index c9d4caa89..f9b49525c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import lombok.Cleanup; import org.bukkit.command.CommandSender; @@ -9,7 +10,7 @@ import org.bukkit.command.CommandSender; public class Commandbanip extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbigtree.java b/Essentials/src/com/earth2me/essentials/commands/Commandbigtree.java index 7c31c87c1..de63fdc29 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbigtree.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbigtree.java @@ -2,8 +2,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.Location; import com.earth2me.essentials.utils.LocationUtil; -import org.bukkit.Location; import org.bukkit.TreeType; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java b/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java index 572da8f67..fb3faabb1 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java @@ -1,13 +1,14 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; +import com.earth2me.essentials.api.server.ICommandSender; import org.bukkit.command.CommandSender; public class Commandbroadcast extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandburn.java b/Essentials/src/com/earth2me/essentials/commands/Commandburn.java index 08b8739b5..fefd61bea 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandburn.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandburn.java @@ -1,14 +1,14 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import org.bukkit.command.CommandSender; +import com.earth2me.essentials.api.server.ICommandSender; import org.bukkit.entity.Player; public class Commandburn extends EssentialsCommand { @Override - protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java b/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java index fea6c024f..09084fee3 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java @@ -2,9 +2,9 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.permissions.Permissions; import java.util.List; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -54,7 +54,7 @@ public class Commandclearinventory extends EssentialsCommand } @Override - protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java b/Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java index 629d00592..aa7024d3d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanddelhome.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.permissions.Permissions; import java.util.Locale; import lombok.Cleanup; @@ -12,7 +13,7 @@ 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 ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanddeljail.java b/Essentials/src/com/earth2me/essentials/commands/Commanddeljail.java index 9daae2fad..0621bbec5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanddeljail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanddeljail.java @@ -1,13 +1,14 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; +import com.earth2me.essentials.api.server.ICommandSender; import org.bukkit.command.CommandSender; public class Commanddeljail extends EssentialsCommand { @Override - protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanddelwarp.java b/Essentials/src/com/earth2me/essentials/commands/Commanddelwarp.java index 482652b15..672a069cd 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanddelwarp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanddelwarp.java @@ -1,13 +1,14 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; +import com.earth2me.essentials.api.server.ICommandSender; 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 ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandeco.java b/Essentials/src/com/earth2me/essentials/commands/Commandeco.java index 3269d2114..664bcd188 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandeco.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandeco.java @@ -3,6 +3,8 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.IUser; import static com.earth2me.essentials.I18n._; +import com.earth2me.essentials.api.server.ICommandSender; +import com.earth2me.essentials.api.server.Player; import java.util.Locale; import lombok.Cleanup; import org.bukkit.command.CommandSender; @@ -12,7 +14,7 @@ import org.bukkit.entity.Player; public class Commandeco extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { @@ -61,7 +63,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/com/earth2me/essentials/commands/Commandessentials.java b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java index 095690374..57fbfba1b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java @@ -1,6 +1,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; +import com.earth2me.essentials.api.server.ICommandSender; +import com.earth2me.essentials.api.server.Player; import java.util.HashMap; import java.util.Map; import org.bukkit.Location; @@ -8,7 +10,6 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.entity.Player; public class Commandessentials extends EssentialsCommand @@ -17,7 +18,7 @@ public class Commandessentials extends EssentialsCommand private final transient Map noteBlocks = new HashMap(); @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length == 0) { @@ -41,9 +42,9 @@ public class Commandessentials extends EssentialsCommand } } - private void run_disabled(final CommandSender sender, final String[] args) throws Exception + private void run_disabled(final ICommandSender sender, final String[] args) throws Exception { - sender.sendMessage("Essentials " + ess.getDescription().getVersion()); + sender.sendMessage("Essentials " + ess.getPlugin().getVersion()); sender.sendMessage("/ "); sender.sendMessage(_("blockList")); final StringBuilder disabledCommands = new StringBuilder(); @@ -58,19 +59,19 @@ public class Commandessentials extends EssentialsCommand sender.sendMessage(disabledCommands.toString()); } - private void run_debug(final CommandSender sender, final String[] args) throws Exception + private void run_debug(final ICommandSender 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[] args) throws Exception + private void run_reload(final ICommandSender sender, final String[] args) throws Exception { ess.reload(); - sender.sendMessage(_("essentialsReload", ess.getDescription().getVersion())); + sender.sendMessage(_("essentialsReload", ess.getPlugin().getVersion())); } - private void run_nya(final CommandSender sender, final String[] args) throws Exception + private void run_nya(final ICommandSender sender, final String[] args) throws Exception { final Map noteMap = new HashMap(); noteMap.put("1F#", (byte)0x0); @@ -117,7 +118,7 @@ public class Commandessentials extends EssentialsCommand player.sendBlockChange(loc, Material.NOTE_BLOCK, (byte)0); } } - taskid = ess.scheduleSyncRepeatingTask(new Runnable() + taskid = ess.getPlugin().scheduleSyncRepeatingTask(new Runnable() { int i = 0; @@ -150,7 +151,7 @@ public class Commandessentials extends EssentialsCommand private void stopTune() { - ess.getServer().getScheduler().cancelTask(taskid); + ess.getPlugin().cancelTask(taskid); for (Block block : noteBlocks.values()) { if (block.getType() == Material.NOTE_BLOCK) @@ -161,9 +162,9 @@ public class Commandessentials extends EssentialsCommand noteBlocks.clear(); } - private void run_moo(final CommandSender sender, final String args[]) + private void run_moo(final ICommandSender sender, final String args[]) { - if(sender instanceof ConsoleCommandSender) + if(sender == ess.getServer().getConsoleSender()) sender.sendMessage(new String[]{" (__)", " (oo)", " /------\\/", " / | ||", " * /\\---/\\", " ~~ ~~", "....\"Have you mooed today?\"..." } ); else sender.sendMessage(new String[]{" (__)", " (oo)", " /------\\/", " / | | |", " * /\\---/\\", " ~~ ~~", "....\"Have you mooed today?\"..." } ); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandext.java b/Essentials/src/com/earth2me/essentials/commands/Commandext.java index 8e689506a..ee8e17de4 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandext.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandext.java @@ -2,14 +2,14 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; -import org.bukkit.command.CommandSender; +import com.earth2me.essentials.api.server.ICommandSender; import org.bukkit.entity.Player; public class Commandext extends EssentialsCommand { @Override - protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -32,7 +32,7 @@ public class Commandext extends EssentialsCommand extinguishPlayers(user, args[0]); } - private void extinguishPlayers(final CommandSender sender, final String name) throws Exception + private void extinguishPlayers(final ICommandSender sender, final String name) throws Exception { for (Player matchPlayer : server.matchPlayer(name)) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandfeed.java b/Essentials/src/com/earth2me/essentials/commands/Commandfeed.java index e7c8f9fe4..cf494b03f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandfeed.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandfeed.java @@ -4,7 +4,6 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.permissions.Permissions; import java.util.List; -import org.bukkit.command.CommandSender; 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 players = server.matchPlayer(name); if (players.isEmpty()) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java b/Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java index 7bccf6df3..f68b8d7d4 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.permissions.Permissions; import java.util.Locale; import org.bukkit.GameMode; @@ -12,7 +13,7 @@ import org.bukkit.entity.Player; public class Commandgamemode extends EssentialsCommand { @Override - protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -35,7 +36,7 @@ public class Commandgamemode extends EssentialsCommand user.sendMessage(_("gameMode", _(user.getGameMode().toString().toLowerCase(Locale.ENGLISH)), user.getDisplayName())); } - private void gamemodeOtherPlayers(final CommandSender sender, final String name) + private void gamemodeOtherPlayers(final ICommandSender sender, final String name) { for (Player matchPlayer : server.matchPlayer(name)) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgc.java b/Essentials/src/com/earth2me/essentials/commands/Commandgc.java index 8c7d2b485..fe23768ba 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgc.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgc.java @@ -1,6 +1,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; +import com.earth2me.essentials.api.server.ICommandSender; +import com.earth2me.essentials.api.server.IWorld; import org.bukkit.World; import org.bukkit.command.CommandSender; @@ -8,13 +10,13 @@ import org.bukkit.command.CommandSender; public class Commandgc extends EssentialsCommand { @Override - protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { sender.sendMessage(_("gcmax", (Runtime.getRuntime().maxMemory() / 1024 / 1024))); sender.sendMessage(_("gctotal", (Runtime.getRuntime().totalMemory() / 1024 / 1024))); sender.sendMessage(_("gcfree", (Runtime.getRuntime().freeMemory() / 1024 / 1024))); - for (World w : server.getWorlds()) + for (IWorld w : server.getWorlds()) { sender.sendMessage( (w.getEnvironment() == World.Environment.NETHER ? "Nether" : "World") + " \"" + w.getName() + "\": " diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java b/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java index 88a817bd3..c518507ae 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgetpos.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.permissions.Permissions; import org.bukkit.Location; import org.bukkit.command.CommandSender; @@ -23,7 +24,7 @@ public class Commandgetpos extends EssentialsCommand } @Override - protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java index 75dce1b3c..b841716b9 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.permissions.GivePermissions; import static com.earth2me.essentials.I18n._; +import com.earth2me.essentials.api.server.ICommandSender; import java.util.Locale; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -16,7 +17,7 @@ public class Commandgive extends EssentialsCommand { //TODO: move these messages to message file @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgod.java b/Essentials/src/com/earth2me/essentials/commands/Commandgod.java index 037c8cb50..32dafae14 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgod.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgod.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.permissions.Permissions; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -10,7 +11,7 @@ import org.bukkit.entity.Player; public class Commandgod extends EssentialsCommand { @Override - protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandheal.java b/Essentials/src/com/earth2me/essentials/commands/Commandheal.java index fe620b390..b6f3199ce 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandheal.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandheal.java @@ -2,10 +2,10 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.permissions.Permissions; import com.earth2me.essentials.user.UserData.TimestampType; import java.util.List; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -31,7 +31,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 ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -41,7 +41,7 @@ public class Commandheal extends EssentialsCommand healOtherPlayers(sender, args[0]); } - private void healOtherPlayers(final CommandSender sender, final String name) + private void healOtherPlayers(final ICommandSender sender, final String name) { final List players = server.matchPlayer(name); if (players.isEmpty()) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java b/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java index 40b99f06f..a0987dd07 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java @@ -8,6 +8,7 @@ import com.earth2me.essentials.utils.textreader.KeywordReplacer; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.utils.Util; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import org.bukkit.command.CommandSender; @@ -43,7 +44,7 @@ public class Commandhelp extends EssentialsCommand } @Override - protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { sender.sendMessage(_("helpConsole")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java b/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java index ece3ef183..33fa81b9e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.utils.Util; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.Player; import com.earth2me.essentials.permissions.Permissions; import java.util.logging.Level; import org.bukkit.entity.Player; @@ -22,7 +23,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/com/earth2me/essentials/commands/Commandinfo.java b/Essentials/src/com/earth2me/essentials/commands/Commandinfo.java index 924e0a74a..89adaf487 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandinfo.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandinfo.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.utils.textreader.IText; import com.earth2me.essentials.utils.textreader.KeywordReplacer; import com.earth2me.essentials.utils.textreader.TextInput; @@ -10,7 +11,7 @@ import org.bukkit.command.CommandSender; public class Commandinfo extends EssentialsCommand { @Override - protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { final IText input = new TextInput(sender, "info", true, ess); final IText output = new KeywordReplacer(input, sender, ess); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanditem.java b/Essentials/src/com/earth2me/essentials/commands/Commanditem.java index 18af6cb78..b66377722 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanditem.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanditem.java @@ -2,11 +2,10 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.Enchantment; +import com.earth2me.essentials.api.server.ItemStack; import com.earth2me.essentials.permissions.ItemPermissions; import java.util.Locale; -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemStack; public class Commanditem extends EssentialsCommand @@ -54,7 +53,7 @@ public class Commanditem extends EssentialsCommand } } - if (stack.getType() == Material.AIR) + if (stack.isAir()) { throw new Exception(_("cantSpawnItem", "Air")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanditemdb.java b/Essentials/src/com/earth2me/essentials/commands/Commanditemdb.java index 6d0a17037..1456b4067 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanditemdb.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanditemdb.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.api.server.ICommandSender; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -8,7 +9,7 @@ import org.bukkit.inventory.ItemStack; public class Commanditemdb extends EssentialsCommand { @Override - protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { ItemStack itemStack = null; if (args.length < 1) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandjails.java b/Essentials/src/com/earth2me/essentials/commands/Commandjails.java index 7e50c78e2..cd28a0520 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandjails.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandjails.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.utils.Util; import org.bukkit.command.CommandSender; @@ -7,7 +8,7 @@ import org.bukkit.command.CommandSender; public class Commandjails extends EssentialsCommand { @Override - protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { sender.sendMessage("§7" + Util.joinList(" ", ess.getJails().getList())); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandjump.java b/Essentials/src/com/earth2me/essentials/commands/Commandjump.java index 8a1fa91d4..ae4832d1d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandjump.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandjump.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.economy.Trade; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ILocation; import com.earth2me.essentials.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/com/earth2me/essentials/commands/Commandkick.java b/Essentials/src/com/earth2me/essentials/commands/Commandkick.java index fe11efcea..bcaad7649 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkick.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkick.java @@ -3,15 +3,16 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; +import com.earth2me.essentials.api.server.Player; import com.earth2me.essentials.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 ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -29,7 +30,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/com/earth2me/essentials/commands/Commandkickall.java b/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java index e460f5cbd..54b5cb27c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkickall.java @@ -1,18 +1,18 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import com.earth2me.essentials.api.server.ICommandSender; +import com.earth2me.essentials.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 ICommandSender 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; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkill.java b/Essentials/src/com/earth2me/essentials/commands/Commandkill.java index e4db6eb1a..43735d34d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkill.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkill.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; +import com.earth2me.essentials.api.server.ICommandSender; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageEvent; @@ -9,7 +10,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 ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkillall.java b/Essentials/src/com/earth2me/essentials/commands/Commandkillall.java index 238dffb58..762c9d736 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkillall.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkillall.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.bukkit.Mob; import java.util.Collections; import java.util.Locale; @@ -15,7 +16,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 ICommandSender sender, final String commandLabel, final String[] args) throws Exception { String type = "all"; int radius = -1; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkittycannon.java b/Essentials/src/com/earth2me/essentials/commands/Commandkittycannon.java index 67a3c9a8b..4c56c81af 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkittycannon.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkittycannon.java @@ -24,7 +24,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/com/earth2me/essentials/commands/Commandlightning.java b/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java index 3eda786c9..6bc3bc428 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.permissions.Permissions; import lombok.Cleanup; import org.bukkit.command.CommandSender; @@ -13,7 +14,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 ICommandSender sender, final String commandLabel, final String[] args) throws Exception { IUser user = null; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java index 5ad079aea..1772cde69 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java @@ -4,6 +4,8 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.utils.Util; import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; +import com.earth2me.essentials.api.server.Player; import com.earth2me.essentials.permissions.Permissions; import java.util.*; import org.bukkit.command.CommandSender; @@ -13,7 +15,7 @@ import org.bukkit.entity.Player; public class Commandlist extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { boolean showhidden = false; if (Permissions.LIST_HIDDEN.isAuthorized(sender)) @@ -23,7 +25,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 +34,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 +57,9 @@ public class Commandlist extends EssentialsCommand if (sortListByGroups) { Map> sort = new HashMap>(); - 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; @@ -115,9 +117,9 @@ public class Commandlist extends EssentialsCommand else { final List users = new ArrayList(); - 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/com/earth2me/essentials/commands/Commandmail.java b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java index 2973acefe..baf087f7b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java @@ -3,9 +3,9 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.utils.Util; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.permissions.Permissions; import java.util.List; -import org.bukkit.command.CommandSender; 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.stripColor(getFinalArg(args, 1)))); + ess.getPlugin().scheduleAsyncDelayedTask(new SendAll(user.getName() + ": " + Util.stripColor(getFinalArg(args, 1)))); user.sendMessage(_("mailSent")); return; } @@ -80,7 +80,7 @@ public class Commandmail extends EssentialsCommand } @Override - protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length >= 1 && "read".equalsIgnoreCase(args[0])) { @@ -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/com/earth2me/essentials/commands/Commandmore.java b/Essentials/src/com/earth2me/essentials/commands/Commandmore.java index bbf9ede4c..fe4985832 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmore.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmore.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ItemStack; import com.earth2me.essentials.permissions.ItemPermissions; import com.earth2me.essentials.permissions.Permissions; import java.util.Locale; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmotd.java b/Essentials/src/com/earth2me/essentials/commands/Commandmotd.java index c1d1e92bf..766c84f6b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmotd.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmotd.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.utils.textreader.IText; import com.earth2me.essentials.utils.textreader.KeywordReplacer; import com.earth2me.essentials.utils.textreader.TextInput; @@ -10,7 +11,7 @@ import org.bukkit.command.CommandSender; public class Commandmotd extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { final IText input = new TextInput(sender, "motd", true, ess); final IText output = new KeywordReplacer(input, sender, ess); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java b/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java index 16879b258..61539db46 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java @@ -5,6 +5,7 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.utils.Util; import com.earth2me.essentials.api.IReplyTo; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.permissions.Permissions; import java.util.List; import lombok.Cleanup; @@ -15,7 +16,7 @@ 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 ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2 || args[0].trim().isEmpty() || args[1].trim().isEmpty()) { @@ -54,7 +55,7 @@ public class Commandmsg extends EssentialsCommand if (args[0].equalsIgnoreCase(Console.NAME)) { sender.sendMessage(_("msgFormat", translatedMe, Console.NAME, message)); - CommandSender cs = server.getConsoleSender(); + ICommandSender cs = server.getConsoleSender(); cs.sendMessage(_("msgFormat", senderName, translatedMe, message)); replyTo.setReplyTo(cs); Console.getConsoleReplyTo().setReplyTo(sender); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmute.java b/Essentials/src/com/earth2me/essentials/commands/Commandmute.java index b537c5a96..f4dfff6e6 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmute.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmute.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.utils.Util; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.permissions.Permissions; import com.earth2me.essentials.user.UserData.TimestampType; import com.earth2me.essentials.utils.DateUtil; @@ -13,7 +14,7 @@ import org.bukkit.command.CommandSender; public class Commandmute extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandnear.java b/Essentials/src/com/earth2me/essentials/commands/Commandnear.java index fc1450445..c6aa2fc85 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandnear.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandnear.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.permissions.Permissions; import org.bukkit.Location; import org.bukkit.World; @@ -56,7 +57,7 @@ public class Commandnear extends EssentialsCommand } @Override - protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length == 0) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java index d514ea2e4..fae568aba 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java @@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.utils.Util; import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.permissions.Permissions; import java.util.Locale; import lombok.Cleanup; @@ -42,7 +43,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 ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandnuke.java b/Essentials/src/com/earth2me/essentials/commands/Commandnuke.java index 4f6e3933a..643e73be6 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandnuke.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandnuke.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; +import com.earth2me.essentials.api.server.ICommandSender; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -14,7 +15,7 @@ import org.bukkit.entity.TNTPrimed; public class Commandnuke extends EssentialsCommand { @Override - protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws NoSuchFieldException, NotEnoughArgumentsException + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws NoSuchFieldException, NotEnoughArgumentsException { List targets; if (args.length > 0) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandptime.java b/Essentials/src/com/earth2me/essentials/commands/Commandptime.java index efc95f6ba..3127f4893 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandptime.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandptime.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.utils.DescParseTickFormat; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.permissions.Permissions; import java.util.*; import org.bukkit.World; @@ -23,7 +24,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 ICommandSender 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/com/earth2me/essentials/commands/Commandr.java b/Essentials/src/com/earth2me/essentials/commands/Commandr.java index e7350ab31..acbae2540 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandr.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandr.java @@ -5,6 +5,7 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.utils.Util; import com.earth2me.essentials.api.IReplyTo; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.permissions.Permissions; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -13,7 +14,7 @@ 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 ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -45,7 +46,7 @@ public class Commandr extends EssentialsCommand senderName = Console.NAME; } - final CommandSender target = replyTo.getReplyTo(); + final ICommandSender target = replyTo.getReplyTo(); final String targetName = target instanceof Player ? ((Player)target).getDisplayName() : Console.NAME; if (target == null || ((target instanceof Player) && !((Player)target).isOnline())) @@ -78,7 +79,7 @@ public class Commandr extends EssentialsCommand } @Override - public String getPermission() + public String getPermissionName() { return "essentials.msg"; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java b/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java index c4ff19dec..355d7b904 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java @@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.utils.Util; import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import java.util.Locale; import lombok.Cleanup; import org.bukkit.command.CommandSender; @@ -13,7 +14,7 @@ import org.bukkit.entity.Player; public class Commandrealname extends EssentialsCommand { @Override - protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandremove.java b/Essentials/src/com/earth2me/essentials/commands/Commandremove.java index 66cdf625d..86faedf4e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandremove.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandremove.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import java.util.Locale; import org.bukkit.Chunk; import org.bukkit.World; @@ -57,7 +58,7 @@ public class Commandremove extends EssentialsCommand } @Override - protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrules.java b/Essentials/src/com/earth2me/essentials/commands/Commandrules.java index da0a3eaec..6d7655693 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandrules.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandrules.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.utils.textreader.IText; import com.earth2me.essentials.utils.textreader.KeywordReplacer; import com.earth2me.essentials.utils.textreader.TextInput; @@ -10,7 +11,7 @@ import org.bukkit.command.CommandSender; public class Commandrules extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { final IText input = new TextInput(sender, "rules", true, ess); final IText output = new KeywordReplacer(input, sender, ess); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandseen.java b/Essentials/src/com/earth2me/essentials/commands/Commandseen.java index 322bde642..7ad9b42f4 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandseen.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandseen.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.utils.Util; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.permissions.Permissions; import com.earth2me.essentials.user.UserData.TimestampType; import com.earth2me.essentials.utils.DateUtil; @@ -13,7 +14,7 @@ import org.bukkit.command.CommandSender; public class Commandseen extends EssentialsCommand { @Override - protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { seen(sender,args,true); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java b/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java index bc2ed632d..0591b152d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java @@ -35,9 +35,9 @@ public class Commandsethome extends EssentialsCommand user.acquireWriteLock(); if (user.getData().getHomes() == null) { - user.getData().setHomes(new HashMap()); + user.getData().setHomes(new HashMap()); } - user.getData().getHomes().put(args[0].toLowerCase(Locale.ENGLISH), new com.earth2me.essentials.storage.Location(user.getLocation())); + user.getData().getHomes().put(args[0].toLowerCase(Locale.ENGLISH), new com.earth2me.essentials.storage.StoredLocation(user.getLocation())); } else { @@ -72,9 +72,9 @@ public class Commandsethome extends EssentialsCommand usersHome.acquireWriteLock(); if (usersHome.getData().getHomes() == null) { - usersHome.getData().setHomes(new HashMap()); + usersHome.getData().setHomes(new HashMap()); } - usersHome.getData().getHomes().put(name, new com.earth2me.essentials.storage.Location(user.getLocation())); + usersHome.getData().getHomes().put(name, new com.earth2me.essentials.storage.StoredLocation(user.getLocation())); } } } @@ -83,9 +83,9 @@ public class Commandsethome extends EssentialsCommand user.acquireWriteLock(); if (user.getData().getHomes() == null) { - user.getData().setHomes(new HashMap()); + user.getData().setHomes(new HashMap()); } - user.getData().getHomes().put("home", new com.earth2me.essentials.storage.Location(user.getLocation())); + user.getData().getHomes().put("home", new com.earth2me.essentials.storage.StoredLocation(user.getLocation())); } user.sendMessage(_("homeSet")); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java b/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java index e6acb1fbe..11ab47433 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import org.bukkit.command.CommandSender; import org.bukkit.inventory.ItemStack; @@ -35,7 +36,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 ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandspawn.java b/Essentials/src/com/earth2me/essentials/commands/Commandspawn.java index 0edcf870c..7dbe51dab 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandspawn.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandspawn.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.economy.Trade; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.permissions.Permissions; import com.earth2me.essentials.settings.SpawnsHolder; import org.bukkit.Location; @@ -34,7 +35,7 @@ public class Commandspawn extends EssentialsCommand } @Override - protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsudo.java b/Essentials/src/com/earth2me/essentials/commands/Commandsudo.java index 9d94bef89..456cdc192 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsudo.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsudo.java @@ -1,17 +1,15 @@ package com.earth2me.essentials.commands; -import com.earth2me.essentials.api.IUser; -import com.earth2me.essentials.permissions.Permissions; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.utils.Util; -import org.bukkit.command.CommandSender; -import org.bukkit.command.PluginCommand; +import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; +import com.earth2me.essentials.permissions.Permissions; public class Commandsudo extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { @@ -33,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/com/earth2me/essentials/commands/Commandsuicide.java b/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java index 147207d39..cf89f1c68 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java @@ -10,8 +10,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(1000); user.setHealth(0); user.sendMessage(_("suicideMessage")); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java b/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java index 4068f8d18..352a5364f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java @@ -4,6 +4,7 @@ import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.utils.Util; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.permissions.Permissions; import com.earth2me.essentials.user.Ban; import com.earth2me.essentials.utils.DateUtil; @@ -15,7 +16,7 @@ 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 ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtime.java b/Essentials/src/com/earth2me/essentials/commands/Commandtime.java index addd6654d..0155f0e08 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtime.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtime.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.utils.DescParseTickFormat; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.permissions.Permissions; import java.util.*; import org.bukkit.World; @@ -13,7 +14,7 @@ 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 ICommandSender sender, final String commandLabel, final String[] args) throws Exception { // Which World(s) are we interested in? String worldSelector = null; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java b/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java index 856a32153..8c975e506 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.utils.Util; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.permissions.Permissions; import com.earth2me.essentials.user.UserData.TimestampType; import com.earth2me.essentials.utils.DateUtil; @@ -14,7 +15,7 @@ import org.bukkit.command.CommandSender; public class Commandtogglejail extends EssentialsCommand { @Override - public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtp.java b/Essentials/src/com/earth2me/essentials/commands/Commandtp.java index 0fbc4a056..c5f0ba687 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtp.java @@ -4,6 +4,7 @@ import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.economy.Trade; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.permissions.Permissions; import lombok.Cleanup; import org.bukkit.command.CommandSender; @@ -49,7 +50,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 ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpaall.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpaall.java index ad3bb0aa5..182165b42 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpaall.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpaall.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import lombok.Cleanup; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -11,7 +12,7 @@ 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 ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java index ee1cd230f..b1f70b8b2 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -10,7 +11,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 ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandunban.java b/Essentials/src/com/earth2me/essentials/commands/Commandunban.java index a18856d66..202bd8971 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandunban.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandunban.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import lombok.Cleanup; import org.bukkit.command.CommandSender; @@ -9,7 +10,7 @@ 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 ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java b/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java index 14d2c8ae6..7e43603d5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import lombok.Cleanup; import org.bukkit.command.CommandSender; @@ -9,7 +10,7 @@ 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 ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java b/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java index a6f6ae477..eedbd054b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java @@ -2,14 +2,14 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ItemStack; +import com.earth2me.essentials.api.server.Material; import com.earth2me.essentials.craftbukkit.InventoryWorkaround; import com.earth2me.essentials.permissions.Permissions; import com.earth2me.essentials.permissions.UnlimitedItemPermissions; import java.util.Locale; import java.util.Set; import lombok.Cleanup; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; public class Commandunlimited extends EssentialsCommand @@ -42,7 +42,7 @@ public class Commandunlimited extends EssentialsCommand final Set itemList = target.getData().getUnlimited(); for(Material mat : itemList) { - toggleUnlimited(user, target, mat.name()); + toggleUnlimited(user, target, mat.getName()); } } @@ -69,7 +69,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 +93,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/com/earth2me/essentials/commands/Commandwarp.java b/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java index d6c3eae72..d81ed4839 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java @@ -5,6 +5,7 @@ import com.earth2me.essentials.economy.Trade; import com.earth2me.essentials.utils.Util; import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IWarps; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.permissions.Permissions; import com.earth2me.essentials.permissions.WarpPermissions; import java.util.ArrayList; @@ -50,7 +51,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 ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2 || args[0].matches("[0-9]+")) { @@ -68,7 +69,7 @@ public class Commandwarp extends EssentialsCommand } //TODO: Use one of the new text classes, like /help ? - private void warpList(final CommandSender sender, final String[] args) throws Exception + private void warpList(final ICommandSender sender, final String[] args) throws Exception { final IWarps warps = ess.getWarps(); if (warps.isEmpty()) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandweather.java b/Essentials/src/com/earth2me/essentials/commands/Commandweather.java index 2df5b1eac..6671bfee3 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandweather.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandweather.java @@ -2,8 +2,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IUser; -import org.bukkit.World; -import org.bukkit.command.CommandSender; +import com.earth2me.essentials.api.server.ICommandSender; +import com.earth2me.essentials.api.server.IWorld; public class Commandweather extends EssentialsCommand @@ -18,7 +18,7 @@ public class Commandweather extends EssentialsCommand } final boolean isStorm = args[0].equalsIgnoreCase("storm"); - final World world = user.getWorld(); + final IWorld world = user.getWorld(); if (args.length > 1) { @@ -39,7 +39,7 @@ public class Commandweather extends EssentialsCommand //TODO: Translate these @Override - protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 2) //running from console means inserting a world arg before other args { @@ -47,7 +47,7 @@ public class Commandweather extends EssentialsCommand } final boolean isStorm = args[1].equalsIgnoreCase("storm"); - final World world = server.getWorld(args[0]); + final IWorld world = server.getWorld(args[0]); if (world == null) { throw new Exception("World named " + args[0] + " not found!"); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java index 8f11b05d7..85b1e9a7b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java @@ -4,19 +4,20 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.utils.Util; import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; +import com.earth2me.essentials.api.server.Player; import com.earth2me.essentials.permissions.Permissions; import com.earth2me.essentials.user.UserData; import com.earth2me.essentials.utils.DateUtil; import java.util.Locale; import lombok.Cleanup; -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 ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { @@ -42,7 +43,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/com/earth2me/essentials/commands/Commandworld.java b/Essentials/src/com/earth2me/essentials/commands/Commandworld.java index 9e2c1b08d..edc019850 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandworld.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandworld.java @@ -3,10 +3,10 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.economy.Trade; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.IWorld; +import com.earth2me.essentials.api.server.Location; import com.earth2me.essentials.permissions.WorldPermissions; import java.util.List; -import org.bukkit.Location; -import org.bukkit.World; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -15,15 +15,15 @@ public class Commandworld extends EssentialsCommand @Override protected void run(final IUser user, final String commandLabel, final String[] args) throws Exception { - World world; + IWorld world; if (args.length < 1) { - World nether = null; + IWorld nether = null; - final List worlds = server.getWorlds(); + final List worlds = server.getWorlds(); - for (World world2 : worlds) + for (IWorld world2 : worlds) { if (world2.getEnvironment() == World.Environment.NETHER) { @@ -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/com/earth2me/essentials/commands/Commandworth.java b/Essentials/src/com/earth2me/essentials/commands/Commandworth.java index 0e1ec1dc1..c5cab92ef 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandworth.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandworth.java @@ -3,9 +3,10 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.utils.Util; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; +import com.earth2me.essentials.api.server.ItemStack; import java.util.Locale; import org.bukkit.command.CommandSender; -import org.bukkit.inventory.ItemStack; public class Commandworth extends EssentialsCommand @@ -14,7 +15,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) @@ -56,7 +57,7 @@ public class Commandworth extends EssentialsCommand } @Override - protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java index e3b25177a..02cc6e7d9 100644 --- a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java +++ b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java @@ -1,18 +1,17 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.economy.Trade; import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IEssentialsModule; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; +import com.earth2me.essentials.api.server.IServer; +import com.earth2me.essentials.api.server.Player; +import com.earth2me.essentials.economy.Trade; import com.earth2me.essentials.permissions.AbstractSuperpermsPermission; import java.util.List; import java.util.logging.Logger; -import org.bukkit.Server; 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,16 +94,16 @@ 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((ICommandSender)user, commandLabel, args); } @Override - public final void run(final CommandSender sender, final Command cmd, final String commandLabel, final String[] args) throws Exception + public final void run(final ICommandSender sender, final Command cmd, final String commandLabel, final String[] args) throws Exception { run(sender, commandLabel, args); } - protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws Exception { throw new Exception(_("onlyPlayers", commandName)); } @@ -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/com/earth2me/essentials/commands/EssentialsCommandHandler.java b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommandHandler.java index f45a55a3f..aa20fd1e2 100644 --- a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommandHandler.java +++ b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommandHandler.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.*; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.commands.EssentialsCommand; import com.earth2me.essentials.commands.IEssentialsCommand; import com.earth2me.essentials.commands.NoChargeException; @@ -53,7 +54,7 @@ public class EssentialsCommandHandler implements ICommandHandler } @Override - public boolean handleCommand(final CommandSender sender, final Command command, final String commandLabel, final String[] args) + public boolean handleCommand(final ICommandSender sender, final Command command, final String commandLabel, final String[] args) { boolean disabled = false; boolean overridden = false; @@ -193,7 +194,7 @@ public class EssentialsCommandHandler implements ICommandHandler } @Override - public void showCommandError(final CommandSender sender, final String commandLabel, final Throwable exception) + public void showCommandError(final ICommandSender sender, final String commandLabel, final Throwable exception) { sender.sendMessage(_("errorWithMessage", exception.getMessage())); if (ess.getSettings().isDebug()) diff --git a/Essentials/src/com/earth2me/essentials/commands/IEssentialsCommand.java b/Essentials/src/com/earth2me/essentials/commands/IEssentialsCommand.java index b4c1b40f8..d7d40775a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/IEssentialsCommand.java +++ b/Essentials/src/com/earth2me/essentials/commands/IEssentialsCommand.java @@ -4,8 +4,8 @@ import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IEssentialsModule; import com.earth2me.essentials.api.IPermission; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; public interface IEssentialsCommand extends IPermission @@ -13,7 +13,7 @@ public interface IEssentialsCommand extends IPermission void run(IUser user, Command cmd, String commandLabel, String[] args) throws Exception; - void run(CommandSender sender, Command cmd, String commandLabel, String[] args) + void run(ICommandSender sender, Command cmd, String commandLabel, String[] args) throws Exception; void init(IEssentials ess, String commandLabel); diff --git a/Essentials/src/com/earth2me/essentials/craftbukkit/SetExpFix.java b/Essentials/src/com/earth2me/essentials/craftbukkit/SetExpFix.java index 5b1161851..d4db5d1a8 100644 --- a/Essentials/src/com/earth2me/essentials/craftbukkit/SetExpFix.java +++ b/Essentials/src/com/earth2me/essentials/craftbukkit/SetExpFix.java @@ -5,7 +5,7 @@ import org.bukkit.entity.Player; public class SetExpFix { - public static void setTotalExperience(final Player player, final int exp) + public static void setTotalExperience(final IPlayer player, final int exp) { if (exp < 0) { @@ -34,7 +34,7 @@ public class SetExpFix } } - private static int getExpToLevel(final Player player) + private static int getExpToLevel(final IPlayer player) { return getExpToLevel(player.getLevel()); } @@ -44,7 +44,7 @@ public class SetExpFix return 7 + (level * 7 >> 1); } - public static int getTotalExperience(final Player player) + public static int getTotalExperience(final IPlayer player) { int exp = (int) (getExpToLevel(player) * player.getExp()); int currentLevel = player.getLevel(); diff --git a/Essentials/src/com/earth2me/essentials/economy/MoneyHolder.java b/Essentials/src/com/earth2me/essentials/economy/MoneyHolder.java index 179e09210..6adfa6c2d 100644 --- a/Essentials/src/com/earth2me/essentials/economy/MoneyHolder.java +++ b/Essentials/src/com/earth2me/essentials/economy/MoneyHolder.java @@ -17,6 +17,6 @@ public class MoneyHolder extends AsyncStorageObjectHolder @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/com/earth2me/essentials/economy/Trade.java b/Essentials/src/com/earth2me/essentials/economy/Trade.java index f2b11ee51..2e217580d 100644 --- a/Essentials/src/com/earth2me/essentials/economy/Trade.java +++ b/Essentials/src/com/earth2me/essentials/economy/Trade.java @@ -5,8 +5,8 @@ import com.earth2me.essentials.api.ChargeException; import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.IUser; -import com.earth2me.essentials.craftbukkit.InventoryWorkaround; -import com.earth2me.essentials.craftbukkit.SetExpFix; +import com.earth2me.essentials.api.server.ItemStack; +import com.earth2me.essentials.api.server.Location; import com.earth2me.essentials.permissions.NoCommandCostPermissions; import com.earth2me.essentials.permissions.Permissions; import java.io.File; @@ -19,9 +19,7 @@ import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import lombok.Cleanup; -import org.bukkit.Location; -import org.bukkit.entity.Item; -import org.bukkit.inventory.ItemStack; + public class Trade @@ -73,7 +71,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("_", " "))); } @@ -92,7 +90,7 @@ public class Trade } if (exp != null && exp > 0 - && SetExpFix.getTotalExperience(user) < exp) + && user.getTotalExperience() < exp) { throw new ChargeException(_("notEnoughExperience")); } @@ -114,37 +112,37 @@ public class Trade { if (dropItems) { - final Map leftOver = InventoryWorkaround.addItem(user.getInventory(), true, getItemStack()); + final Map 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; } @@ -161,11 +159,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() @@ -183,12 +181,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()); } } @@ -221,7 +219,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/com/earth2me/essentials/economy/WorthHolder.java b/Essentials/src/com/earth2me/essentials/economy/WorthHolder.java index 598c22c4c..c49c705f0 100644 --- a/Essentials/src/com/earth2me/essentials/economy/WorthHolder.java +++ b/Essentials/src/com/earth2me/essentials/economy/WorthHolder.java @@ -2,6 +2,7 @@ package com.earth2me.essentials.economy; import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IWorth; +import com.earth2me.essentials.api.server.ItemStack; import com.earth2me.essentials.storage.AsyncStorageObjectHolder; import com.earth2me.essentials.storage.EnchantmentLevel; import java.io.File; @@ -9,7 +10,6 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemStack; import org.bukkit.material.MaterialData; @@ -81,6 +81,6 @@ public class WorthHolder extends AsyncStorageObjectHolder permissions = new EnumMap(Material.class); + private static Map permissions = new HashMap(); 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/com/earth2me/essentials/permissions/ItemPermissions.java b/Essentials/src/com/earth2me/essentials/permissions/ItemPermissions.java index 980af104f..fa4932cca 100644 --- a/Essentials/src/com/earth2me/essentials/permissions/ItemPermissions.java +++ b/Essentials/src/com/earth2me/essentials/permissions/ItemPermissions.java @@ -1,16 +1,17 @@ package com.earth2me.essentials.permissions; import com.earth2me.essentials.api.IPermission; -import java.util.EnumMap; +import com.earth2me.essentials.api.server.Material; +import com.earth2me.essentials.api.server.Permission; +import java.util.HashMap; import java.util.Locale; import java.util.Map; -import org.bukkit.Material; -import org.bukkit.permissions.PermissionDefault; + public class ItemPermissions { - private static Map permissions = new EnumMap(Material.class); + private static Map permissions = new HashMap(); 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/com/earth2me/essentials/permissions/KitPermissions.java b/Essentials/src/com/earth2me/essentials/permissions/KitPermissions.java index b21e0712d..420f1abd5 100644 --- a/Essentials/src/com/earth2me/essentials/permissions/KitPermissions.java +++ b/Essentials/src/com/earth2me/essentials/permissions/KitPermissions.java @@ -1,10 +1,10 @@ package com.earth2me.essentials.permissions; import com.earth2me.essentials.api.IPermission; +import com.earth2me.essentials.api.server.Permission; import java.util.HashMap; import java.util.Locale; import java.util.Map; -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/com/earth2me/essentials/permissions/Permissions.java b/Essentials/src/com/earth2me/essentials/permissions/Permissions.java index 151ed77c9..5c9c29a92 100644 --- a/Essentials/src/com/earth2me/essentials/permissions/Permissions.java +++ b/Essentials/src/com/earth2me/essentials/permissions/Permissions.java @@ -2,10 +2,9 @@ package com.earth2me.essentials.permissions; import com.earth2me.essentials.utils.Util; import com.earth2me.essentials.api.IPermission; +import com.earth2me.essentials.api.server.ICommandSender; +import com.earth2me.essentials.api.server.Permission; import java.util.Locale; -import org.bukkit.command.CommandSender; -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionDefault; public enum Permissions implements IPermission @@ -23,11 +22,11 @@ public enum Permissions implements IPermission CHAT_SPY, CLEARINVENTORY_OTHERS, DELHOME_OTHERS, - ECO_LOAN(PermissionDefault.FALSE), + ECO_LOAN(Permission.Default.FALSE), FEED_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, @@ -50,7 +49,7 @@ public enum Permissions implements IPermission NICK_COLOR, NICK_OTHERS, NOGOD_OVERRIDE, - OVERSIZEDSTACKS(PermissionDefault.FALSE), + OVERSIZEDSTACKS(Permission.Default.FALSE), POWERTOOL_APPEND, PTIME_OTHERS, REPAIR_ARMOR, @@ -73,32 +72,32 @@ public enum Permissions implements IPermission TPAHERE, TPOHERE, UNLIMITED_OTHERS, - WARP_LIST(PermissionDefault.TRUE), + WARP_LIST(Permission.Default.TRUE), WARP_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) { @@ -106,19 +105,19 @@ 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; } @Override - public boolean isAuthorized(CommandSender sender) + public boolean isAuthorized(ICommandSender sender) { - return sender.hasPermission(getBukkitPermission()); + return sender.hasPermission(getPermission()); } } diff --git a/Essentials/src/com/earth2me/essentials/permissions/UnlimitedItemPermissions.java b/Essentials/src/com/earth2me/essentials/permissions/UnlimitedItemPermissions.java index dbe7df95b..2907d77a6 100644 --- a/Essentials/src/com/earth2me/essentials/permissions/UnlimitedItemPermissions.java +++ b/Essentials/src/com/earth2me/essentials/permissions/UnlimitedItemPermissions.java @@ -1,14 +1,14 @@ package com.earth2me.essentials.permissions; import com.earth2me.essentials.api.IPermission; -import java.util.EnumMap; +import com.earth2me.essentials.api.server.Material; +import java.util.HashMap; import java.util.Locale; import java.util.Map; -import org.bukkit.Material; public class UnlimitedItemPermissions { - private static Map permissions = new EnumMap(Material.class); + private static Map permissions = new HashMap(); public static IPermission getPermission(final Material mat) { diff --git a/Essentials/src/com/earth2me/essentials/permissions/WarpPermissions.java b/Essentials/src/com/earth2me/essentials/permissions/WarpPermissions.java index 7f08ad3a2..83c56a881 100644 --- a/Essentials/src/com/earth2me/essentials/permissions/WarpPermissions.java +++ b/Essentials/src/com/earth2me/essentials/permissions/WarpPermissions.java @@ -1,10 +1,10 @@ package com.earth2me.essentials.permissions; import com.earth2me.essentials.api.IPermission; +import com.earth2me.essentials.api.server.Permission; import java.util.HashMap; import java.util.Locale; import java.util.Map; -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/com/earth2me/essentials/ranks/RanksStorage.java b/Essentials/src/com/earth2me/essentials/ranks/RanksStorage.java index 7f6e5dd84..5a38a51aa 100644 --- a/Essentials/src/com/earth2me/essentials/ranks/RanksStorage.java +++ b/Essentials/src/com/earth2me/essentials/ranks/RanksStorage.java @@ -28,7 +28,7 @@ public class RanksStorage extends AsyncStorageObjectHolder implements IRa @Override public File getStorageFile() { - return new File(ess.getDataFolder(), "ranks.yml"); + return new File(ess.getPlugin().getDataFolder(), "ranks.yml"); } public Collection> getGroups(final IUser player) diff --git a/Essentials/src/com/earth2me/essentials/ranks/VaultGroups.java b/Essentials/src/com/earth2me/essentials/ranks/VaultGroups.java index 1d94b6089..51be20432 100644 --- a/Essentials/src/com/earth2me/essentials/ranks/VaultGroups.java +++ b/Essentials/src/com/earth2me/essentials/ranks/VaultGroups.java @@ -23,48 +23,42 @@ public class VaultGroups implements IRanks @Override public double getHealCooldown(IUser player) { - RegisteredServiceProvider 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 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 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 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 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 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 +79,7 @@ public class VaultGroups implements IRanks private String getRawChatFormat(final IUser player) { - RegisteredServiceProvider 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 +95,14 @@ public class VaultGroups implements IRanks @Override public String getMainGroup(IUser player) { - RegisteredServiceProvider 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 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/com/earth2me/essentials/settings/Jails.java b/Essentials/src/com/earth2me/essentials/settings/Jails.java index 3adb4ec1e..5793f7d2c 100644 --- a/Essentials/src/com/earth2me/essentials/settings/Jails.java +++ b/Essentials/src/com/earth2me/essentials/settings/Jails.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.settings; -import com.earth2me.essentials.storage.Location; +import com.earth2me.essentials.storage.StoredLocation; import com.earth2me.essentials.storage.MapValueType; import com.earth2me.essentials.storage.StorageObject; import java.util.HashMap; @@ -13,6 +13,6 @@ import lombok.EqualsAndHashCode; @EqualsAndHashCode(callSuper = false) public class Jails implements StorageObject { - @MapValueType(Location.class) - private Map jails = new HashMap(); + @MapValueType(StoredLocation.class) + private Map jails = new HashMap(); } diff --git a/Essentials/src/com/earth2me/essentials/settings/SettingsHolder.java b/Essentials/src/com/earth2me/essentials/settings/SettingsHolder.java index 434d9b922..22a398a3c 100644 --- a/Essentials/src/com/earth2me/essentials/settings/SettingsHolder.java +++ b/Essentials/src/com/earth2me/essentials/settings/SettingsHolder.java @@ -31,7 +31,7 @@ public class SettingsHolder extends AsyncStorageObjectHolder 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/com/earth2me/essentials/settings/Spawns.java b/Essentials/src/com/earth2me/essentials/settings/Spawns.java index 451ef49b1..c8fcf38b1 100644 --- a/Essentials/src/com/earth2me/essentials/settings/Spawns.java +++ b/Essentials/src/com/earth2me/essentials/settings/Spawns.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.settings; import com.earth2me.essentials.storage.Comment; -import com.earth2me.essentials.storage.Location; +import com.earth2me.essentials.storage.StoredLocation; import com.earth2me.essentials.storage.MapValueType; import com.earth2me.essentials.storage.StorageObject; import java.util.HashMap; @@ -35,6 +35,6 @@ public class Spawns implements StorageObject }) private String newbieSpawn = "none"; @Comment("List of all spawnpoints") - @MapValueType(Location.class) - private Map spawns = new HashMap(); + @MapValueType(StoredLocation.class) + private Map spawns = new HashMap(); } diff --git a/Essentials/src/com/earth2me/essentials/settings/SpawnsHolder.java b/Essentials/src/com/earth2me/essentials/settings/SpawnsHolder.java index 19c9198da..e969b8705 100644 --- a/Essentials/src/com/earth2me/essentials/settings/SpawnsHolder.java +++ b/Essentials/src/com/earth2me/essentials/settings/SpawnsHolder.java @@ -6,7 +6,7 @@ import com.earth2me.essentials.api.IEssentialsModule; import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.storage.AsyncStorageObjectHolder; -import com.earth2me.essentials.storage.Location.WorldNotLoadedException; +import com.earth2me.essentials.storage.StoredLocation.WorldNotLoadedException; import com.earth2me.essentials.utils.textreader.IText; import com.earth2me.essentials.utils.textreader.KeywordReplacer; import com.earth2me.essentials.utils.textreader.SimpleTextInput; @@ -39,7 +39,7 @@ public class SpawnsHolder extends AsyncStorageObjectHolder 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) @@ -49,9 +49,9 @@ public class SpawnsHolder extends AsyncStorageObjectHolder implements IE { if (getData().getSpawns() == null) { - getData().setSpawns(new HashMap()); + getData().setSpawns(new HashMap()); } - getData().getSpawns().put(group.toLowerCase(Locale.ENGLISH), new com.earth2me.essentials.storage.Location(loc)); + getData().getSpawns().put(group.toLowerCase(Locale.ENGLISH), new com.earth2me.essentials.storage.StoredLocation(loc)); } finally { @@ -73,7 +73,7 @@ public class SpawnsHolder extends AsyncStorageObjectHolder implements IE { return getWorldSpawn(); } - final Map spawnMap = getData().getSpawns(); + final Map spawnMap = getData().getSpawns(); String groupName = group.toLowerCase(Locale.ENGLISH); if (!spawnMap.containsKey(groupName)) { @@ -85,7 +85,7 @@ public class SpawnsHolder extends AsyncStorageObjectHolder implements IE } try { - return spawnMap.get(groupName).getBukkitLocation(); + return spawnMap.get(groupName).getStoredLocation(); } catch (WorldNotLoadedException ex) { @@ -260,7 +260,7 @@ public class SpawnsHolder extends AsyncStorageObjectHolder 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/com/earth2me/essentials/settings/Warp.java b/Essentials/src/com/earth2me/essentials/settings/Warp.java index f9c506b58..171f7075f 100644 --- a/Essentials/src/com/earth2me/essentials/settings/Warp.java +++ b/Essentials/src/com/earth2me/essentials/settings/Warp.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.settings; -import com.earth2me.essentials.storage.Location; +import com.earth2me.essentials.storage.StoredLocation; import com.earth2me.essentials.storage.StorageObject; import lombok.Data; import lombok.EqualsAndHashCode; @@ -10,5 +10,5 @@ import lombok.EqualsAndHashCode; public class Warp implements StorageObject { private String name; - private Location location; + private StoredLocation location; } diff --git a/Essentials/src/com/earth2me/essentials/storage/AbstractDelayedYamlFileReader.java b/Essentials/src/com/earth2me/essentials/storage/AbstractDelayedYamlFileReader.java index cad08b8c1..6e342590f 100644 --- a/Essentials/src/com/earth2me/essentials/storage/AbstractDelayedYamlFileReader.java +++ b/Essentials/src/com/earth2me/essentials/storage/AbstractDelayedYamlFileReader.java @@ -15,24 +15,24 @@ import org.bukkit.plugin.Plugin; public abstract class AbstractDelayedYamlFileReader implements Runnable { private final transient Class clazz; - private final transient Plugin plugin; + private final transient IEssentials ess; private final transient ReentrantLock lock = new ReentrantLock(); public AbstractDelayedYamlFileReader(final IEssentials ess, final Class 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); } } @@ -50,7 +50,7 @@ public abstract class AbstractDelayedYamlFileReader 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/com/earth2me/essentials/storage/AbstractDelayedYamlFileWriter.java b/Essentials/src/com/earth2me/essentials/storage/AbstractDelayedYamlFileWriter.java index d3289310e..6e264cad8 100644 --- a/Essentials/src/com/earth2me/essentials/storage/AbstractDelayedYamlFileWriter.java +++ b/Essentials/src/com/earth2me/essentials/storage/AbstractDelayedYamlFileWriter.java @@ -14,24 +14,17 @@ 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/com/earth2me/essentials/storage/BukkitConstructor.java b/Essentials/src/com/earth2me/essentials/storage/BukkitConstructor.java index 93412be56..d05552192 100644 --- a/Essentials/src/com/earth2me/essentials/storage/BukkitConstructor.java +++ b/Essentials/src/com/earth2me/essentials/storage/BukkitConstructor.java @@ -1,17 +1,16 @@ package com.earth2me.essentials.storage; import com.earth2me.essentials.Essentials; +import com.earth2me.essentials.api.server.IPlugin; +import com.earth2me.essentials.api.server.Material; import java.lang.reflect.Field; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.regex.Pattern; -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 +21,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 +68,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 +235,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 +279,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 +418,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/com/earth2me/essentials/storage/ManagedFile.java b/Essentials/src/com/earth2me/essentials/storage/ManagedFile.java index 509783955..aeb9c5dcf 100644 --- a/Essentials/src/com/earth2me/essentials/storage/ManagedFile.java +++ b/Essentials/src/com/earth2me/essentials/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/com/earth2me/essentials/storage/StorageObjectMap.java b/Essentials/src/com/earth2me/essentials/storage/StorageObjectMap.java index d3d118483..3ad231c87 100644 --- a/Essentials/src/com/earth2me/essentials/storage/StorageObjectMap.java +++ b/Essentials/src/com/earth2me/essentials/storage/StorageObjectMap.java @@ -1,8 +1,8 @@ package com.earth2me.essentials.storage; -import com.earth2me.essentials.utils.Util; import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.InvalidNameException; +import com.earth2me.essentials.utils.Util; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; @@ -15,7 +15,6 @@ import java.util.Set; import java.util.concurrent.ConcurrentSkipListSet; import java.util.concurrent.ExecutionException; import java.util.logging.Level; -import org.bukkit.Bukkit; public abstract class StorageObjectMap extends CacheLoader implements IStorageObjectMap @@ -29,7 +28,7 @@ public abstract class StorageObjectMap extends CacheLoader 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 extends CacheLoader 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 extends CacheLoader 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/com/earth2me/essentials/storage/Location.java b/Essentials/src/com/earth2me/essentials/storage/StoredLocation.java similarity index 67% rename from Essentials/src/com/earth2me/essentials/storage/Location.java rename to Essentials/src/com/earth2me/essentials/storage/StoredLocation.java index 6778027d7..7c817de87 100644 --- a/Essentials/src/com/earth2me/essentials/storage/Location.java +++ b/Essentials/src/com/earth2me/essentials/storage/StoredLocation.java @@ -1,14 +1,14 @@ package com.earth2me.essentials.storage; +import com.earth2me.essentials.api.server.IWorld; +import com.earth2me.essentials.api.server.Location; import java.lang.ref.WeakReference; import java.util.UUID; -import org.bukkit.Bukkit; -import org.bukkit.World; -public class Location +public class StoredLocation { - private WeakReference location; + private WeakReference location; private final String worldname; private UUID worldUID = null; private final double x; @@ -17,9 +17,9 @@ public class Location private final float yaw; private final float pitch; - public Location(org.bukkit.Location loc) + public StoredLocation(Location loc) { - location = new WeakReference(loc); + location = new WeakReference(loc); worldname = loc.getWorld().getName(); worldUID = loc.getWorld().getUID(); x = loc.getX(); @@ -29,7 +29,7 @@ public class Location pitch = loc.getPitch(); } - public Location(String worldname, double x, double y, double z, float yaw, float pitch) + public StoredLocation(String worldname, double x, double y, double z, float yaw, float pitch) { this.worldname = worldname; this.x = x; @@ -39,7 +39,7 @@ public class Location this.pitch = pitch; } - public Location(String worldname, double x, double y, double z) + public StoredLocation(String worldname, double x, double y, double z) { this.worldname = worldname; this.x = x; @@ -49,13 +49,13 @@ public class Location this.pitch = 0f; } - public org.bukkit.Location getBukkitLocation() throws WorldNotLoadedException + public Location getStoredLocation() throws WorldNotLoadedException { - org.bukkit.Location loc = location == null ? null : location.get(); + Location loc = location == null ? null : location.get(); if (loc == null) { - World world = null; + IWorld world = null; if (worldUID != null) { world = Bukkit.getWorld(worldUID); @@ -68,8 +68,8 @@ public class Location { throw new WorldNotLoadedException(worldname); } - loc = new org.bukkit.Location(world, getX(), getY(), getZ(), getYaw(), getPitch()); - location = new WeakReference(loc); + loc = Location.create(world, getX(), getY(), getZ(), getYaw(), getPitch()); + location = new WeakReference(loc); } return loc; } diff --git a/Essentials/src/com/earth2me/essentials/storage/YamlStorageReader.java b/Essentials/src/com/earth2me/essentials/storage/YamlStorageReader.java index ee7aa45cd..ea9d193fe 100644 --- a/Essentials/src/com/earth2me/essentials/storage/YamlStorageReader.java +++ b/Essentials/src/com/earth2me/essentials/storage/YamlStorageReader.java @@ -1,10 +1,10 @@ package com.earth2me.essentials.storage; +import com.earth2me.essentials.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 PREPARED_YAMLS = Collections.synchronizedMap(new HashMap()); private transient static final Map LOCKS = new HashMap(); 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/com/earth2me/essentials/storage/YamlStorageWriter.java b/Essentials/src/com/earth2me/essentials/storage/YamlStorageWriter.java index 6e641db69..a693745b2 100644 --- a/Essentials/src/com/earth2me/essentials/storage/YamlStorageWriter.java +++ b/Essentials/src/com/earth2me/essentials/storage/YamlStorageWriter.java @@ -73,9 +73,9 @@ public class YamlStorageWriter implements IStorageWriter { writeCollection((Collection)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)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/com/earth2me/essentials/user/IOfflinePlayer.java b/Essentials/src/com/earth2me/essentials/user/IOfflinePlayer.java index 65304e76a..434113f25 100644 --- a/Essentials/src/com/earth2me/essentials/user/IOfflinePlayer.java +++ b/Essentials/src/com/earth2me/essentials/user/IOfflinePlayer.java @@ -10,7 +10,7 @@ public interface IOfflinePlayer String getDisplayName(); - Location getBedSpawnLocation(); + //Location getBedSpawnLocation(); void setBanned(boolean bln); diff --git a/Essentials/src/com/earth2me/essentials/user/IOfflineUser.java b/Essentials/src/com/earth2me/essentials/user/IOfflineUser.java index d6266df49..144955f57 100644 --- a/Essentials/src/com/earth2me/essentials/user/IOfflineUser.java +++ b/Essentials/src/com/earth2me/essentials/user/IOfflineUser.java @@ -3,7 +3,7 @@ package com.earth2me.essentials.user; import com.earth2me.essentials.storage.IStorageObjectHolder; -public interface IOfflineUser extends IStorageObjectHolder, IOfflinePlayer +public interface IOfflineUser extends IStorageObjectHolder//, IOfflinePlayer { } diff --git a/Essentials/src/com/earth2me/essentials/user/User.java b/Essentials/src/com/earth2me/essentials/user/User.java index 770f1c071..5873e3790 100644 --- a/Essentials/src/com/earth2me/essentials/user/User.java +++ b/Essentials/src/com/earth2me/essentials/user/User.java @@ -1,36 +1,27 @@ package com.earth2me.essentials.user; -import com.earth2me.essentials.api.ChargeException; import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Teleport; -import com.earth2me.essentials.utils.Util; import com.earth2me.essentials.api.*; -import com.earth2me.essentials.craftbukkit.InventoryWorkaround; -import com.earth2me.essentials.permissions.Permissions; +import com.earth2me.essentials.api.server.*; import com.earth2me.essentials.economy.register.Method; +import com.earth2me.essentials.permissions.Permissions; import com.earth2me.essentials.utils.DateUtil; +import com.earth2me.essentials.utils.Util; 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 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; public class User extends UserBase implements IUser { - private CommandSender replyTo = null; + private ICommandSender replyTo = null; @Getter private transient IUser teleportRequester; @Getter @@ -47,7 +38,6 @@ public class User extends UserBase implements IUser @Setter private boolean hidden = 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) @@ -56,12 +46,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 @@ -105,7 +89,7 @@ public class User extends UserBase implements IUser } @Override - public void giveMoney(final double value, final CommandSender initiator) + public void giveMoney(final double value, final ICommandSender initiator) { if (value == 0) @@ -155,7 +139,7 @@ public class User extends UserBase implements IUser } @Override - public void takeMoney(final double value, final CommandSender initiator) + public void takeMoney(final double value, final ICommandSender initiator) { if (value == 0) { @@ -185,7 +169,7 @@ public class User extends UserBase implements IUser acquireWriteLock(); try { - getData().setLastLocation(new com.earth2me.essentials.storage.Location(getLocation())); + getData().setLastLocation(new com.earth2me.essentials.storage.StoredLocation(getLocation())); } finally { @@ -261,7 +245,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."); } } @@ -277,7 +261,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(); } @@ -466,9 +450,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)); @@ -572,13 +556,13 @@ public class User extends UserBase implements IUser } @Override - public void setReplyTo(CommandSender user) + public void setReplyTo(ICommandSender user) { replyTo = user; } @Override - public CommandSender getReplyTo() + public ICommandSender getReplyTo() { return replyTo; } @@ -628,7 +612,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; } @@ -641,11 +625,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/com/earth2me/essentials/user/UserBase.java b/Essentials/src/com/earth2me/essentials/user/UserBase.java index 4e0ab75fb..a48e8dc98 100644 --- a/Essentials/src/com/earth2me/essentials/user/UserBase.java +++ b/Essentials/src/com/earth2me/essentials/user/UserBase.java @@ -4,40 +4,22 @@ import com.earth2me.essentials.utils.Util; import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.InvalidNameException; +import com.earth2me.essentials.api.server.Player; +import com.earth2me.essentials.api.server.Location; import com.earth2me.essentials.storage.AsyncStorageObjectHolder; -import com.earth2me.essentials.storage.Location.WorldNotLoadedException; +import com.earth2me.essentials.storage.IStorageObjectHolder; +import com.earth2me.essentials.storage.StoredLocation.WorldNotLoadedException; import java.io.File; import java.io.IOException; import java.util.*; import lombok.Cleanup; import lombok.Delegate; -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 implements Player, IOfflineUser +public abstract class UserBase extends AsyncStorageObjectHolder implements Player, IStorageObjectHolder { - @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) { @@ -46,13 +28,6 @@ public abstract class UserBase extends AsyncStorageObjectHolder implem onReload(); } - public UserBase(final OfflinePlayer offlinePlayer, final IEssentials ess) - { - super(ess, UserData.class); - this.offlinePlayer = offlinePlayer; - onReload(); - } - public final Player getBase() { return base; @@ -68,87 +43,13 @@ public abstract class UserBase extends AsyncStorageObjectHolder 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() - { - if (isOnlineUser()) - { - return base.getBedSpawnLocation(); - } - else - { - return offlinePlayer.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 { @@ -250,13 +151,13 @@ public abstract class UserBase extends AsyncStorageObjectHolder implem acquireWriteLock(); try { - Map homes = getData().getHomes(); + Map homes = getData().getHomes(); if (homes == null) { - homes = new HashMap(); + homes = new HashMap(); getData().setHomes(homes); } - homes.put(Util.sanitizeKey(name), new com.earth2me.essentials.storage.Location(loc)); + homes.put(Util.sanitizeKey(name), new com.earth2me.essentials.storage.StoredLocation(loc)); } finally { @@ -424,13 +325,13 @@ public abstract class UserBase extends AsyncStorageObjectHolder implem return null; } ArrayList worldHomes = new ArrayList(); - for (com.earth2me.essentials.storage.Location location : getData().getHomes().values()) + for (com.earth2me.essentials.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/com/earth2me/essentials/user/UserData.java b/Essentials/src/com/earth2me/essentials/user/UserData.java index d61d21a49..a7046f588 100644 --- a/Essentials/src/com/earth2me/essentials/user/UserData.java +++ b/Essentials/src/com/earth2me/essentials/user/UserData.java @@ -1,10 +1,11 @@ package com.earth2me.essentials.user; +import com.earth2me.essentials.api.server.Material; import com.earth2me.essentials.storage.*; import java.util.*; import lombok.Data; import lombok.EqualsAndHashCode; -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 homes = new HashMap(); + @MapValueType(StoredLocation.class) + private Map homes = new HashMap(); @ListType(Material.class) private Set unlimited = new HashSet(); @MapValueType(List.class) @MapKeyType(Material.class) private Map> powerTools = new HashMap>(); - private Location lastLocation; + private StoredLocation lastLocation; @MapKeyType(TimestampType.class) @MapValueType(Long.class) private Map timestamps = new HashMap(); @@ -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/com/earth2me/essentials/user/UserMap.java b/Essentials/src/com/earth2me/essentials/user/UserMap.java index 96744da1d..2591b2522 100644 --- a/Essentials/src/com/earth2me/essentials/user/UserMap.java +++ b/Essentials/src/com/earth2me/essentials/user/UserMap.java @@ -4,6 +4,7 @@ import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUserMap; import com.earth2me.essentials.api.InvalidNameException; +import com.earth2me.essentials.api.server.Player; import com.earth2me.essentials.storage.StorageObjectMap; import java.io.File; import java.util.Locale; diff --git a/Essentials/src/com/earth2me/essentials/utils/textreader/KeywordReplacer.java b/Essentials/src/com/earth2me/essentials/utils/textreader/KeywordReplacer.java index 92c7c8a0b..db6849704 100644 --- a/Essentials/src/com/earth2me/essentials/utils/textreader/KeywordReplacer.java +++ b/Essentials/src/com/earth2me/essentials/utils/textreader/KeywordReplacer.java @@ -1,17 +1,17 @@ package com.earth2me.essentials.utils.textreader; -import com.earth2me.essentials.utils.DescParseTickFormat; import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.api.server.ICommandSender; +import com.earth2me.essentials.api.server.Player; +import com.earth2me.essentials.api.server.IWorld; +import com.earth2me.essentials.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 org.bukkit.World; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -21,7 +21,7 @@ public class KeywordReplacer implements IText private final transient List replaced; private final transient IEssentials ess; - public KeywordReplacer(final IText input, final CommandSender sender, final IEssentials ess) + public KeywordReplacer(final IText input, final ICommandSender sender, final IEssentials ess) { this.input = input; this.replaced = new ArrayList(this.input.getLines().size()); @@ -29,16 +29,16 @@ public class KeywordReplacer implements IText replaceKeywords(sender); } - private void replaceKeywords(final CommandSender sender) + private void replaceKeywords(final ICommandSender sender) { String displayName, ipAddress, balance, mails, world; 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(); displayName = user.getDisplayName(); userName = user.getName(); @@ -59,16 +59,16 @@ 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(); - for (World w : ess.getServer().getWorlds()) + for (IWorld w : ess.getServer().getWorlds()) { if (worldsBuilder.length() > 0) { @@ -81,7 +81,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/com/earth2me/essentials/utils/textreader/TextInput.java b/Essentials/src/com/earth2me/essentials/utils/textreader/TextInput.java index 369c0e0e1..513cb6f4f 100644 --- a/Essentials/src/com/earth2me/essentials/utils/textreader/TextInput.java +++ b/Essentials/src/com/earth2me/essentials/utils/textreader/TextInput.java @@ -1,16 +1,15 @@ package com.earth2me.essentials.utils.textreader; -import com.earth2me.essentials.utils.Util; import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.InvalidNameException; +import com.earth2me.essentials.api.server.ICommandSender; +import com.earth2me.essentials.api.server.Player; +import com.earth2me.essentials.utils.Util; import java.io.*; import java.lang.ref.SoftReference; import java.util.*; import java.util.logging.Level; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; public class TextInput implements IText @@ -21,29 +20,29 @@ public class TextInput implements IText private final transient long lastChange; private final static HashMap> cache = new HashMap>(); - public TextInput(final CommandSender sender, final String filename, final boolean createFile, final IEssentials ess) throws IOException + public TextInput(final ICommandSender sender, final String filename, final boolean createFile, final IEssentials ess) throws IOException { 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 +104,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/com/earth2me/essentials/utils/textreader/TextPager.java b/Essentials/src/com/earth2me/essentials/utils/textreader/TextPager.java index 70f68222b..780f4ab1c 100644 --- a/Essentials/src/com/earth2me/essentials/utils/textreader/TextPager.java +++ b/Essentials/src/com/earth2me/essentials/utils/textreader/TextPager.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.utils.textreader; import static com.earth2me.essentials.I18n._; +import com.earth2me.essentials.api.server.ICommandSender; import java.util.List; import java.util.Locale; import java.util.Map; @@ -23,7 +24,7 @@ public class TextPager this.onePage = onePage; } - public void showPage(final String pageStr, final String chapterPageStr, final String commandName, final CommandSender sender) + public void showPage(final String pageStr, final String chapterPageStr, final String commandName, final ICommandSender sender) { List lines = text.getLines(); List chapters = text.getChapters(); diff --git a/Essentials/test/com/earth2me/essentials/EconomyTest.java b/Essentials/test/com/earth2me/essentials/EconomyTest.java index 44d388c3b..dd37c9ea4 100644 --- a/Essentials/test/com/earth2me/essentials/EconomyTest.java +++ b/Essentials/test/com/earth2me/essentials/EconomyTest.java @@ -10,31 +10,15 @@ 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/com/earth2me/essentials/EssentialsTest.java b/Essentials/test/com/earth2me/essentials/EssentialsTest.java new file mode 100644 index 000000000..9f8505c7d --- /dev/null +++ b/Essentials/test/com/earth2me/essentials/EssentialsTest.java @@ -0,0 +1,26 @@ +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; + +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/StorageTest.java b/Essentials/test/com/earth2me/essentials/StorageTest.java index 5a5e12250..3bc3124a1 100644 --- a/Essentials/test/com/earth2me/essentials/StorageTest.java +++ b/Essentials/test/com/earth2me/essentials/StorageTest.java @@ -15,29 +15,11 @@ 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 +81,7 @@ public class StorageTest extends TestCase for (int j = 0; j < 10000; j++) { - userdata.getHomes().put("home", new com.earth2me.essentials.storage.Location(new Location(world, j, j, j))); + userdata.getHomes().put("home", new com.earth2me.essentials.storage.StoredLocation(new Location(world, j, j, j))); } ext.mark("change home 10000 times"); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); diff --git a/Essentials/test/com/earth2me/essentials/UserTest.java b/Essentials/test/com/earth2me/essentials/UserTest.java index 6cffcb4f3..4c2643068 100644 --- a/Essentials/test/com/earth2me/essentials/UserTest.java +++ b/Essentials/test/com/earth2me/essentials/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/com/earth2me/essentials/UtilTest.java b/Essentials/test/com/earth2me/essentials/UtilTest.java index 94cd2877d..ad2c501a1 100644 --- a/Essentials/test/com/earth2me/essentials/UtilTest.java +++ b/Essentials/test/com/earth2me/essentials/UtilTest.java @@ -13,28 +13,12 @@ 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/Essentials/test/com/earth2me/essentials/testserver/Player.java b/Essentials/test/com/earth2me/essentials/testserver/Player.java new file mode 100644 index 000000000..24801f52b --- /dev/null +++ b/Essentials/test/com/earth2me/essentials/testserver/Player.java @@ -0,0 +1,152 @@ +package com.earth2me.essentials.testserver; + +import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.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 IWorld 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..ea27fe79a --- /dev/null +++ b/Essentials/test/com/earth2me/essentials/testserver/Plugin.java @@ -0,0 +1,69 @@ +package com.earth2me.essentials.testserver; + +import com.earth2me.essentials.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..d1da2712b --- /dev/null +++ b/Essentials/test/com/earth2me/essentials/testserver/Server.java @@ -0,0 +1,89 @@ +package com.earth2me.essentials.testserver; + +import com.earth2me.essentials.api.server.ICommandSender; +import com.earth2me.essentials.api.server.Player; +import com.earth2me.essentials.api.server.IServer; +import com.earth2me.essentials.api.server.IWorld; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +public class Server implements IServer { + + public Server() + { + } + + + + @Override + public List getWorlds() + { + return Collections.singletonList(new World()); + } + + @Override + public IWorld getWorld(final String name) + { + final IWorld 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 getOnlinePlayers() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public ICommandSender getConsoleSender() + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void dispatchCommand(ICommandSender sender, String command) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void banIP(String ip) + { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public T getServiceProvider(Class 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..0fe076a39 --- /dev/null +++ b/Essentials/test/com/earth2me/essentials/testserver/World.java @@ -0,0 +1,27 @@ +package com.earth2me.essentials.testserver; + +import com.earth2me.essentials.api.server.IWorld; +import com.earth2me.essentials.api.server.Location; +import org.bukkit.TreeType; + +public class World implements IWorld { + + @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/Essentials2Compat/src/com/earth2me/essentials/EssentialsUpgrade.java b/Essentials2Compat/src/com/earth2me/essentials/EssentialsUpgrade.java index ccaa6e4a4..e9d2b670e 100644 --- a/Essentials2Compat/src/com/earth2me/essentials/EssentialsUpgrade.java +++ b/Essentials2Compat/src/com/earth2me/essentials/EssentialsUpgrade.java @@ -5,7 +5,7 @@ import com.earth2me.essentials.storage.ManagedFile; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.settings.Spawns; -import com.earth2me.essentials.storage.Location; +import com.earth2me.essentials.storage.StoredLocation; import com.earth2me.essentials.storage.YamlStorageWriter; import java.io.*; import java.math.BigInteger; @@ -215,7 +215,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(), @@ -325,14 +325,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 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 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 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/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmpp.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmpp.java index 23bd34170..0c9e8d91c 100644 --- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmpp.java +++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmpp.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.xmpp; import com.earth2me.essentials.Console; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.commands.EssentialsCommand; import com.earth2me.essentials.commands.NotEnoughArgumentsException; import org.bukkit.command.CommandSender; @@ -10,7 +11,7 @@ import org.bukkit.entity.Player; public class Commandxmpp extends EssentialsCommand { @Override - protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws NotEnoughArgumentsException + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws NotEnoughArgumentsException { if (args.length < 2) { diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmppspy.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmppspy.java index 5da4d8f93..c5f846aa2 100644 --- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmppspy.java +++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmppspy.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.xmpp; +import com.earth2me.essentials.api.server.ICommandSender; import com.earth2me.essentials.commands.EssentialsCommand; import com.earth2me.essentials.commands.NotEnoughArgumentsException; import java.util.List; @@ -10,7 +11,7 @@ import org.bukkit.entity.Player; public class Commandxmppspy extends EssentialsCommand { @Override - protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws NotEnoughArgumentsException + protected void run(final ICommandSender sender, final String commandLabel, final String[] args) throws NotEnoughArgumentsException { if (args.length < 1) {