diff options
Diffstat (limited to 'EssentialsXMPP/src/com/earth2me/essentials')
8 files changed, 52 insertions, 56 deletions
diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandsetxmpp.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandsetxmpp.java index e0bf9827c..4fe9283df 100644 --- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandsetxmpp.java +++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandsetxmpp.java @@ -1,20 +1,14 @@ package com.earth2me.essentials.xmpp; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.commands.EssentialsCommand; import com.earth2me.essentials.commands.NotEnoughArgumentsException; -import org.bukkit.Server; public class Commandsetxmpp extends EssentialsCommand { - public Commandsetxmpp() - { - super("setxmpp"); - } - @Override - protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws NotEnoughArgumentsException + protected void run(final IUser user, final String commandLabel, final String[] args) throws NotEnoughArgumentsException { if (args.length < 1) { diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmpp.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmpp.java index e7dd01670..23bd34170 100644 --- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmpp.java +++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmpp.java @@ -3,20 +3,14 @@ package com.earth2me.essentials.xmpp; import com.earth2me.essentials.Console; import com.earth2me.essentials.commands.EssentialsCommand; import com.earth2me.essentials.commands.NotEnoughArgumentsException; -import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; public class Commandxmpp extends EssentialsCommand { - public Commandxmpp() - { - super("xmpp"); - } - @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws NotEnoughArgumentsException + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws NotEnoughArgumentsException { if (args.length < 2) { @@ -31,7 +25,7 @@ public class Commandxmpp extends EssentialsCommand else { final String message = getFinalArg(args, 1); - final String senderName = sender instanceof Player ? ess.getUser(sender).getDisplayName() : Console.NAME; + final String senderName = sender instanceof Player ? ess.getUser((Player)sender).getDisplayName() : Console.NAME; sender.sendMessage("[" + senderName + ">" + address + "] " + message); if (!EssentialsXMPP.getInstance().sendMessage(address, "[" + senderName + "] " + message)) { diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmppspy.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmppspy.java index 4f276c3b9..5da4d8f93 100644 --- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmppspy.java +++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/Commandxmppspy.java @@ -3,20 +3,14 @@ package com.earth2me.essentials.xmpp; import com.earth2me.essentials.commands.EssentialsCommand; import com.earth2me.essentials.commands.NotEnoughArgumentsException; import java.util.List; -import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; public class Commandxmppspy extends EssentialsCommand { - public Commandxmppspy() - { - super("xmppspy"); - } - @Override - protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws NotEnoughArgumentsException + protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws NotEnoughArgumentsException { if (args.length < 1) { diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java index b5c011e55..fea8dd2e2 100644 --- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java +++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java @@ -1,8 +1,10 @@ package com.earth2me.essentials.xmpp; +import com.earth2me.essentials.commands.EssentialsCommandHandler; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.IEssentials; -import com.earth2me.essentials.IUser; +import com.earth2me.essentials.api.ICommandHandler; +import com.earth2me.essentials.api.IEssentials; +import com.earth2me.essentials.api.IUser; import java.util.List; import java.util.Locale; import java.util.logging.Level; @@ -21,6 +23,7 @@ public class EssentialsXMPP extends JavaPlugin implements IEssentialsXMPP private transient UserManager users; private transient XMPPManager xmpp; private transient IEssentials ess; + private transient ICommandHandler commandHandler; public static IEssentialsXMPP getInstance() { @@ -33,7 +36,7 @@ public class EssentialsXMPP extends JavaPlugin implements IEssentialsXMPP instance = this; final PluginManager pluginManager = getServer().getPluginManager(); - ess = (IEssentials)pluginManager.getPlugin("Essentials"); + ess = (IEssentials)pluginManager.getPlugin("Essentials3"); if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) { LOGGER.log(Level.WARNING, _("versionMismatchAll")); @@ -52,6 +55,8 @@ public class EssentialsXMPP extends JavaPlugin implements IEssentialsXMPP ess.addReloadListener(users); ess.addReloadListener(xmpp); + + commandHandler = new EssentialsCommandHandler(EssentialsXMPP.class.getClassLoader(), "com.earth2me.essentials.xmpp.Command", "essentials.", ess); } @Override @@ -67,7 +72,7 @@ public class EssentialsXMPP extends JavaPlugin implements IEssentialsXMPP @Override public boolean onCommand(final CommandSender sender, final Command command, final String commandLabel, final String[] args) { - return ess.onCommandEssentials(sender, command, commandLabel, args, EssentialsXMPP.class.getClassLoader(), "com.earth2me.essentials.xmpp.Command", "essentials.", null); + return commandHandler.handleCommand(sender, command, commandLabel, args); } @Override diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPPPlayerListener.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPPPlayerListener.java index 1fa5a243c..b6daf8114 100644 --- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPPPlayerListener.java +++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPPPlayerListener.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.xmpp; -import com.earth2me.essentials.IEssentials; -import com.earth2me.essentials.User; +import com.earth2me.essentials.api.IEssentials; +import com.earth2me.essentials.api.IUser; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -23,21 +23,21 @@ class EssentialsXMPPPlayerListener implements Listener @EventHandler(priority= EventPriority.MONITOR) public void onPlayerJoin(final PlayerJoinEvent event) { - final User user = ess.getUser(event.getPlayer()); + final IUser user = ess.getUser(event.getPlayer()); sendMessageToSpyUsers("Player " + user.getDisplayName() + " joined the game"); } @EventHandler(priority= EventPriority.MONITOR) public void onPlayerChat(final PlayerChatEvent event) { - final User user = ess.getUser(event.getPlayer()); + final IUser user = ess.getUser(event.getPlayer()); sendMessageToSpyUsers(String.format(event.getFormat(), user.getDisplayName(), event.getMessage())); } @EventHandler(priority= EventPriority.MONITOR) public void onPlayerQuit(final PlayerQuitEvent event) { - final User user = ess.getUser(event.getPlayer()); + final IUser user = ess.getUser(event.getPlayer()); sendMessageToSpyUsers("Player " + user.getDisplayName() + " left the game"); } diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/IEssentialsXMPP.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/IEssentialsXMPP.java index 0635ca131..83851d055 100644 --- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/IEssentialsXMPP.java +++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/IEssentialsXMPP.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.xmpp; -import com.earth2me.essentials.IUser; +import com.earth2me.essentials.api.IUser; import java.util.List; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/UserManager.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/UserManager.java index a35312129..0f17e8660 100644 --- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/UserManager.java +++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/UserManager.java @@ -1,22 +1,26 @@ package com.earth2me.essentials.xmpp; -import com.earth2me.essentials.EssentialsConf; -import com.earth2me.essentials.IConf; +import com.earth2me.essentials.api.IReload; import java.io.File; +import java.io.IOException; import java.util.*; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.bukkit.configuration.file.YamlConfiguration; -public class UserManager implements IConf +public class UserManager implements IReload { - private final transient EssentialsConf users; + private transient YamlConfiguration users; + private final transient File folder; private final transient List<String> spyusers = new ArrayList<String>(); private final static String ADDRESS = "address"; private final static String SPY = "spy"; public UserManager(final File folder) { - users = new EssentialsConf(new File(folder, "users.yml")); - reloadConfig(); + this.folder = folder; + onReload(); } public final boolean isSpy(final String username) @@ -63,15 +67,22 @@ public class UserManager implements IConf final Map<String, Object> userdata = new HashMap<String, Object>(); userdata.put(ADDRESS, address); userdata.put(SPY, spy); - users.setProperty(username, userdata); - users.save(); - reloadConfig(); + users.set(username, userdata); + try + { + users.save(new File(folder, "users.yml")); + } + catch (IOException ex) + { + Logger.getLogger(UserManager.class.getName()).log(Level.SEVERE, null, ex); + } + onReload(); } @Override - public final void reloadConfig() + public final void onReload() { - users.load(); + users = YamlConfiguration.loadConfiguration(new File(folder, "users.yml")); spyusers.clear(); final Set<String> keys = users.getKeys(false); for (String key : keys) diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/XMPPManager.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/XMPPManager.java index bb44d3127..64dd5aff2 100644 --- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/XMPPManager.java +++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/XMPPManager.java @@ -1,15 +1,14 @@ package com.earth2me.essentials.xmpp; -import com.earth2me.essentials.Console; -import com.earth2me.essentials.EssentialsConf; -import com.earth2me.essentials.IConf; -import com.earth2me.essentials.IUser; +import com.earth2me.essentials.api.IReload; +import com.earth2me.essentials.api.IUser; import java.io.File; import java.util.*; import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.Logger; +import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.jivesoftware.smack.Roster.SubscriptionMode; import org.jivesoftware.smack.*; @@ -18,10 +17,10 @@ import org.jivesoftware.smack.packet.Presence; import org.jivesoftware.smack.util.StringUtils; -public class XMPPManager extends Handler implements MessageListener, ChatManagerListener, IConf +public class XMPPManager extends Handler implements MessageListener, ChatManagerListener, IReload { private static final Logger LOGGER = Logger.getLogger("Minecraft"); - private final transient EssentialsConf config; + private transient YamlConfiguration config = null; private transient XMPPConnection connection; private transient ChatManager chatManager; private final transient Map<String, Chat> chats = Collections.synchronizedMap(new HashMap<String, Chat>()); @@ -37,9 +36,8 @@ public class XMPPManager extends Handler implements MessageListener, ChatManager { super(); this.parent = parent; - config = new EssentialsConf(new File(parent.getDataFolder(), "config.yml")); - config.setTemplateName("/config.yml", EssentialsXMPP.class); - reloadConfig(); + // config.setTemplateName("/config.yml", EssentialsXMPP.class); + onReload(); } public boolean sendMessage(final String address, final String message) @@ -166,10 +164,10 @@ public class XMPPManager extends Handler implements MessageListener, ChatManager } @Override - public final void reloadConfig() + public final void onReload() { LOGGER.removeHandler(this); - config.load(); + config = YamlConfiguration.loadConfiguration(new File(parent.getDataFolder(), "config.yml")); synchronized (chats) { disconnect(); @@ -355,7 +353,7 @@ public class XMPPManager extends Handler implements MessageListener, ChatManager { try { - parent.getServer().dispatchCommand(Console.getCommandSender(parent.getServer()), message.substring(1)); + parent.getServer().dispatchCommand(parent.getServer().getConsoleSender(), message.substring(1)); } catch (Exception ex) { |