diff options
author | snowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb> | 2011-03-19 22:39:51 +0000 |
---|---|---|
committer | snowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb> | 2011-03-19 22:39:51 +0000 |
commit | a3ebd254f2897951a2ce31fdd90b6944c582d82b (patch) | |
tree | 11c8670882eed130d7ff1b33cc7c65e496f1bbac /EssentialsServerlist/src/net/mcserverlist/bukkit/Mcsl.java | |
parent | 487577f2fa856a61077594ad6677f0bdd7150fcd (diff) | |
download | Essentials-a3ebd254f2897951a2ce31fdd90b6944c582d82b.tar Essentials-a3ebd254f2897951a2ce31fdd90b6944c582d82b.tar.gz Essentials-a3ebd254f2897951a2ce31fdd90b6944c582d82b.tar.lz Essentials-a3ebd254f2897951a2ce31fdd90b6944c582d82b.tar.xz Essentials-a3ebd254f2897951a2ce31fdd90b6944c582d82b.zip |
Moving all files to trunk.
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@969 e251c2fe-e539-e718-e476-b85c1f46cddb
Diffstat (limited to 'EssentialsServerlist/src/net/mcserverlist/bukkit/Mcsl.java')
-rw-r--r-- | EssentialsServerlist/src/net/mcserverlist/bukkit/Mcsl.java | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/EssentialsServerlist/src/net/mcserverlist/bukkit/Mcsl.java b/EssentialsServerlist/src/net/mcserverlist/bukkit/Mcsl.java new file mode 100644 index 000000000..c9b234fd7 --- /dev/null +++ b/EssentialsServerlist/src/net/mcserverlist/bukkit/Mcsl.java @@ -0,0 +1,149 @@ +package net.mcserverlist.bukkit; + +import com.earth2me.essentials.Essentials; +import java.io.*; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.event.Event; +import org.bukkit.event.Event.Priority; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginDescriptionFile; +import org.bukkit.plugin.java.JavaPlugin; + + +public class Mcsl extends JavaPlugin +{ + private static final Logger logger = Logger.getLogger("Minecraft"); + private McslPlayerListener playerListener; + public final String author; + + public Mcsl() throws IOException + { + + PluginDescriptionFile desc = this.getDescription(); + + // Compile author list + List<String> authors = new ArrayList<String>(); + authors.add("Vimae Development"); + int alen = authors.size(); + if (alen == 1) + { + author = " by " + authors.get(0); + } + else if (alen > 1) + { + int i = 0; + StringBuilder bldr = new StringBuilder(); + for (String a : desc.getAuthors()) + { + if (i + 1 == alen) + { + if (alen > 2) bldr.append(","); + bldr.append(" and "); + } + else if (i++ > 0) + { + bldr.append(", "); + } + bldr.append(a); + } + bldr.insert(0, " by "); + author = bldr.toString(); + } + else + { + author = ""; + } + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) + { + McslCommands mcslCmd; + try + { + switch (McslCommands.valueOf(cmd.getName().toUpperCase())) + { + case WHITELIST: + whitelist(sender, WhitelistCommands.valueOf(args[0].toUpperCase()), args); + return true; + + default: + return false; + } + } + catch (IllegalArgumentException ex) + { + return false; + } + catch (Exception ex) + { + logger.log(Level.WARNING, "MCSL encountered an unknown error.", ex); + sender.sendMessage("MCSL encountered an unknown error."); + return true; + } + } + + @SuppressWarnings("LoggerStringConcat") + public void onEnable() + { + Plugin p = this.getServer().getPluginManager().getPlugin("Essentials"); + if (p != null) { + if (!this.getServer().getPluginManager().isPluginEnabled(p)) { + this.getServer().getPluginManager().enablePlugin(p); + } + } + playerListener = new McslPlayerListener(this); + getServer().getPluginManager().registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Monitor, this); + getServer().getPluginManager().registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Monitor, this); + getServer().getPluginManager().registerEvent(Event.Type.PLAYER_LOGIN, playerListener, Priority.Lowest, this); + + if (!this.getDescription().getVersion().equals(Essentials.getStatic().getDescription().getVersion())) { + logger.log(Level.WARNING, "Version mismatch! Please update all Essentials jars to the same version."); + } + logger.info(getDescription().getName() + " version " + getDescription().getVersion() + author + " enabled."); + } + + @SuppressWarnings("LoggerStringConcat") + public void onDisable() + { + logger.info(getDescription().getName() + " version " + getDescription().getVersion() + " disabled."); + } + + private void whitelist(CommandSender sender, WhitelistCommands cmd, String[] args) + { + if (!playerListener.isWhitelistEnabled()) + { + sender.sendMessage("§cThe whitelist is disabled."); + return; + } + + if (!sender.isOp()) + { + sender.sendMessage("§cYou must be an operator to manage the whitelist."); + return; + } + + switch (cmd) + { + case RELOAD: + playerListener.whitelistReload(); + sender.sendMessage("A whitelist updated has been queued."); + break; + } + } + + private enum McslCommands + { + WHITELIST + } + + private enum WhitelistCommands + { + RELOAD + } +} |