mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-17 23:01:01 +01:00
Removed onPlayerCommand (PLAYER_COMMAND) (and fixed Fillr to stop using it)
By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
parent
1da9ef3c9f
commit
1595230d40
9 changed files with 63 additions and 105 deletions
|
@ -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
|
||||
*
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
|
||||
package org.bukkit.event.player;
|
||||
|
||||
import java.util.IllegalFormatException;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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!");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 <name>");
|
||||
} else {
|
||||
new Updater(getServer()).update(args[0], sender);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (commandLabel.equalsIgnoreCase("get")) {
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage("Usage is /get <name>");
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <name>");
|
||||
} 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 <name>");
|
||||
} else {
|
||||
try {
|
||||
new Getter(server).get(split[1], player);
|
||||
} catch (Exception e) {
|
||||
player.sendMessage("There was an error downloading "
|
||||
+ split[1]);
|
||||
}
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
|
|
Loading…
Reference in a new issue