From 1595230d40c1af7caa16c2d34405a4d9767da1ed Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Sat, 26 Feb 2011 19:08:12 +0000 Subject: [PATCH] Removed onPlayerCommand (PLAYER_COMMAND) (and fixed Fillr to stop using it) By: Dinnerbone --- .../src/main/java/org/bukkit/event/Event.java | 7 --- .../bukkit/event/player/PlayerChatEvent.java | 1 - .../bukkit/event/player/PlayerListener.java | 9 ---- .../main/java/org/bukkit/fillr/Checker.java | 19 ++++---- .../src/main/java/org/bukkit/fillr/Fillr.java | 43 +++++++++++++---- .../java/org/bukkit/fillr/FillrListener.java | 46 ------------------- .../main/java/org/bukkit/fillr/Getter.java | 11 +++-- .../main/java/org/bukkit/fillr/Updater.java | 27 +++++------ .../bukkit/plugin/java/JavaPluginLoader.java | 5 -- 9 files changed, 63 insertions(+), 105 deletions(-) delete mode 100644 paper-api/src/main/java/org/bukkit/fillr/FillrListener.java diff --git a/paper-api/src/main/java/org/bukkit/event/Event.java b/paper-api/src/main/java/org/bukkit/event/Event.java index 37ac072c1f..70ec47671a 100644 --- a/paper-api/src/main/java/org/bukkit/event/Event.java +++ b/paper-api/src/main/java/org/bukkit/event/Event.java @@ -173,13 +173,6 @@ public abstract class Event implements Serializable { */ PLAYER_CHAT (Category.PLAYER), - /** - * Called when a player attempts to use a command - * - * @see org.bukkit.event.player.PlayerChatEvent - */ - PLAYER_COMMAND (Category.PLAYER), - /** * Called when a player early in the command handling process * diff --git a/paper-api/src/main/java/org/bukkit/event/player/PlayerChatEvent.java b/paper-api/src/main/java/org/bukkit/event/player/PlayerChatEvent.java index 28c894f2db..a4de140771 100644 --- a/paper-api/src/main/java/org/bukkit/event/player/PlayerChatEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/player/PlayerChatEvent.java @@ -1,7 +1,6 @@ package org.bukkit.event.player; -import java.util.IllegalFormatException; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; diff --git a/paper-api/src/main/java/org/bukkit/event/player/PlayerListener.java b/paper-api/src/main/java/org/bukkit/event/player/PlayerListener.java index 4b1d00352d..3d00bd34c6 100644 --- a/paper-api/src/main/java/org/bukkit/event/player/PlayerListener.java +++ b/paper-api/src/main/java/org/bukkit/event/player/PlayerListener.java @@ -42,15 +42,6 @@ public class PlayerListener implements Listener { public void onPlayerChat(PlayerChatEvent event) { } - /** - * Called when a player attempts to use a command. - * - * @param event Relevant event details - */ - @Deprecated - public void onPlayerCommand(PlayerChatEvent event) { - } - /** * Called early in the command handling process. This event is only * for very exceptional cases and you should not normally use it. diff --git a/paper-api/src/main/java/org/bukkit/fillr/Checker.java b/paper-api/src/main/java/org/bukkit/fillr/Checker.java index 248652386c..2066c10f8a 100644 --- a/paper-api/src/main/java/org/bukkit/fillr/Checker.java +++ b/paper-api/src/main/java/org/bukkit/fillr/Checker.java @@ -4,6 +4,7 @@ import org.bukkit.entity.Player; import java.io.*; import java.util.jar.*; import org.bukkit.*; +import org.bukkit.command.CommandSender; import org.bukkit.plugin.*; public class Checker { @@ -12,22 +13,22 @@ public class Checker { /** * Checks all the plugins in plugins/ for updates * - * @param player + * @param sender * The player to send info to */ - void check(Player player) { + void check(CommandSender sender) { File folder = new File(DIRECTORY); File[] files = folder.listFiles(new PluginFilter()); if (files.length == 0) { - player.sendMessage("No plugins to update."); + sender.sendMessage("No plugins to update."); } else { - player.sendMessage("Status for " + files.length + " plugins:"); + sender.sendMessage("Status for " + files.length + " plugins:"); for (File file : files) { PluginDescriptionFile pdfFile = Checker.getPDF(file); if (pdfFile == null) { continue; } - checkForUpdate(file, player); + checkForUpdate(file, sender); } } } @@ -37,16 +38,16 @@ public class Checker { * * @param file * The plugin file to check for an update - * @param player + * @param sender * The player to send info to */ - private void checkForUpdate(File file, Player player) { + private void checkForUpdate(File file, CommandSender sender) { PluginDescriptionFile pdfFile = Checker.getPDF(file); FillReader reader = needsUpdate(pdfFile); if (reader != null) { - player.sendMessage(ChatColor.RED + reader.getName() + " " + pdfFile.getVersion() + " has an update to " + reader.getCurrVersion()); + sender.sendMessage(ChatColor.RED + reader.getName() + " " + pdfFile.getVersion() + " has an update to " + reader.getCurrVersion()); } else { - player.sendMessage(pdfFile.getName() + " " + pdfFile.getVersion() + " is up to date!"); + sender.sendMessage(pdfFile.getName() + " " + pdfFile.getVersion() + " is up to date!"); } } diff --git a/paper-api/src/main/java/org/bukkit/fillr/Fillr.java b/paper-api/src/main/java/org/bukkit/fillr/Fillr.java index d192a3d001..0fd40de59c 100644 --- a/paper-api/src/main/java/org/bukkit/fillr/Fillr.java +++ b/paper-api/src/main/java/org/bukkit/fillr/Fillr.java @@ -1,14 +1,10 @@ package org.bukkit.fillr; -import org.bukkit.*; -import org.bukkit.plugin.*; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; import org.bukkit.plugin.java.*; -import org.bukkit.event.*; - -import java.io.File; public class Fillr extends JavaPlugin { - private FillrListener listener; public static final String NAME = "Fillr"; public static final String VERSION = "1.0"; public static final String DIRECTORY = "plugins"; @@ -17,11 +13,38 @@ public class Fillr extends JavaPlugin { } public void onEnable() { - registerEvents(); } - private void registerEvents() { - listener = new FillrListener(getServer()); - getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND, listener, Event.Priority.Normal, this); + @Override + public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { + if (commandLabel.equalsIgnoreCase("check")) { + new Checker().check(sender); + return true; + } else if (commandLabel.equalsIgnoreCase("updateAll")) { + new Updater(getServer()).updateAll(sender); + return true; + } else if (commandLabel.equalsIgnoreCase("update")) { + if (args.length == 0) { + sender.sendMessage("Usage is /update "); + } else { + new Updater(getServer()).update(args[0], sender); + } + + return true; + } else if (commandLabel.equalsIgnoreCase("get")) { + if (args.length == 0) { + sender.sendMessage("Usage is /get "); + } else { + try { + new Getter(getServer()).get(args[0], sender); + } catch (Exception e) { + sender.sendMessage("There was an error downloading " + args[0]); + } + } + + return true; + } + + return false; } } diff --git a/paper-api/src/main/java/org/bukkit/fillr/FillrListener.java b/paper-api/src/main/java/org/bukkit/fillr/FillrListener.java deleted file mode 100644 index a6c22ff4a5..0000000000 --- a/paper-api/src/main/java/org/bukkit/fillr/FillrListener.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.bukkit.fillr; - -import org.bukkit.entity.Player; -import org.bukkit.*; -import org.bukkit.event.player.*; - -public class FillrListener extends PlayerListener { - - private final Server server; - - public FillrListener(Server server) { - this.server = server; - } - - public void onPlayerCommand(PlayerChatEvent event) { - String[] split = event.getMessage().split(" "); - Player player = event.getPlayer(); - - if (split[0].equalsIgnoreCase("/check")) { - new Checker().check(player); - event.setCancelled(true); - } else if (split[0].equalsIgnoreCase("/updateAll")) { - new Updater(server).updateAll(player); - event.setCancelled(true); - } else if (split[0].equalsIgnoreCase("/update")) { - if (split.length == 1) { - player.sendMessage("Usage is /update "); - } else { - new Updater(server).update(split[1], player); - } - event.setCancelled(true); - } else if (split[0].equalsIgnoreCase("/get")) { - if (split.length == 1) { - player.sendMessage("Usage is /get "); - } else { - try { - new Getter(server).get(split[1], player); - } catch (Exception e) { - player.sendMessage("There was an error downloading " - + split[1]); - } - } - event.setCancelled(true); - } - } -} diff --git a/paper-api/src/main/java/org/bukkit/fillr/Getter.java b/paper-api/src/main/java/org/bukkit/fillr/Getter.java index 8e1b35adcc..8a0541894e 100644 --- a/paper-api/src/main/java/org/bukkit/fillr/Getter.java +++ b/paper-api/src/main/java/org/bukkit/fillr/Getter.java @@ -5,6 +5,7 @@ import java.io.File; import java.util.logging.Level; import org.bukkit.*; +import org.bukkit.command.CommandSender; import org.bukkit.plugin.InvalidDescriptionException; import org.bukkit.plugin.InvalidPluginException; @@ -16,18 +17,18 @@ public class Getter { this.server = server; } - public void get(String string, Player player) { + public void get(String string, CommandSender sender) { FillReader reader = new FillReader(string); - player.sendMessage("Downloading " + reader.getName() + " " + sender.sendMessage("Downloading " + reader.getName() + " " + reader.getCurrVersion()); try { Downloader.downloadJar(reader.getFile()); if (reader.getNotes() != null && !reader.getNotes().equals("")) { - player.sendMessage("Notes: " + reader.getNotes()); + sender.sendMessage("Notes: " + reader.getNotes()); } - player.sendMessage("Finished Download!"); + sender.sendMessage("Finished Download!"); enablePlugin(reader); - player.sendMessage("Loading " + reader.getName()); + sender.sendMessage("Loading " + reader.getName()); } catch (Exception ex) { server.getLogger().log(Level.SEVERE, null, ex); } diff --git a/paper-api/src/main/java/org/bukkit/fillr/Updater.java b/paper-api/src/main/java/org/bukkit/fillr/Updater.java index 61d62fd237..5479fbd556 100644 --- a/paper-api/src/main/java/org/bukkit/fillr/Updater.java +++ b/paper-api/src/main/java/org/bukkit/fillr/Updater.java @@ -6,6 +6,7 @@ import org.bukkit.plugin.*; import java.io.File; import java.util.logging.Level; +import org.bukkit.command.CommandSender; public class Updater { public static String DIRECTORY = Fillr.DIRECTORY; @@ -18,16 +19,16 @@ public class Updater { /** * Checks and updates the plugins * - * @param player + * @param sender * The player to send info to */ - void updateAll(Player player) { + void updateAll(CommandSender sender) { File folder = new File(DIRECTORY); File[] files = folder.listFiles(new PluginFilter()); if (files.length == 0) { - player.sendMessage("No plugins to update."); + sender.sendMessage("No plugins to update."); } else { - player.sendMessage("Updating " + sender.sendMessage("Updating " + files.length + " plugins:"); for (File file : files) { PluginDescriptionFile pdfFile = Checker.getPDF(file); @@ -36,7 +37,7 @@ public class Updater { } FillReader reader = Checker.needsUpdate(pdfFile); if (reader != null) { - update(reader, player); + update(reader, sender); } } } @@ -50,7 +51,7 @@ public class Updater { * @param player * The player to send info to */ - void update(String string, Player player) { + void update(String string, CommandSender player) { //TODO so much .jars File file = new File(DIRECTORY, string + ".jar"); if (file.exists()) { @@ -71,21 +72,21 @@ public class Updater { * * @param update * The FillReader with all the plugin info - * @param player The player to send info to + * @param sender The player to send info to */ - private void update(FillReader update, Player player) { + private void update(FillReader update, CommandSender sender) { disablePlugin(update); - player.sendMessage("Disabling " + update.getName() + " for update"); - player.sendMessage("Downloading " + update.getName() + " " + sender.sendMessage("Disabling " + update.getName() + " for update"); + sender.sendMessage("Downloading " + update.getName() + " " + update.getCurrVersion()); try { Downloader.downloadJar(update.getFile()); if (update.getNotes() != null && !update.getNotes().equals("")) { - player.sendMessage("Notes: " + update.getNotes()); + sender.sendMessage("Notes: " + update.getNotes()); } - player.sendMessage("Finished Download!"); + sender.sendMessage("Finished Download!"); enablePlugin(update); - player.sendMessage("Loading " + update.getName()); + sender.sendMessage("Loading " + update.getName()); } catch (Exception e) { e.printStackTrace(); } diff --git a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index b400d7a038..18fdfa90bb 100644 --- a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -140,11 +140,6 @@ public final class JavaPluginLoader implements PluginLoader { ((PlayerListener)listener).onPlayerKick( (PlayerKickEvent)event ); } }; - case PLAYER_COMMAND: - return new EventExecutor() { public void execute( Listener listener, Event event ) { - ((PlayerListener)listener).onPlayerCommand( (PlayerChatEvent)event ); - } - }; case PLAYER_COMMAND_PREPROCESS: return new EventExecutor() { public void execute( Listener listener, Event event ) { ((PlayerListener)listener).onPlayerCommandPreprocess( (PlayerChatEvent)event );