mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 08:39:11 +00:00
Command changes (nothing plugin breaking).
This commit is contained in:
@@ -21,7 +21,6 @@ public final class CommandDispatcher {
|
||||
* Creates the command dispatcher and registers a listener for the credits command.
|
||||
*/
|
||||
public CommandDispatcher() {
|
||||
// not in a plugin so it is harder for people to remove!
|
||||
listeners.put("credits", new CreditsCommandListener());
|
||||
}
|
||||
|
||||
@@ -34,7 +33,7 @@ public final class CommandDispatcher {
|
||||
public void dispatch(Player player, Command command) {
|
||||
CommandListener listener = listeners.get(command.getName().toLowerCase());
|
||||
if (listener != null) {
|
||||
listener.execute(player, command);
|
||||
listener.executePrivileged(player, command);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,36 @@
|
||||
package org.apollo.game.command;
|
||||
|
||||
import org.apollo.game.model.Player;
|
||||
import org.apollo.game.model.Player.PrivilegeLevel;
|
||||
|
||||
/**
|
||||
* An interface which should be implemented by classes to listen to {@link Command}s.
|
||||
*
|
||||
* @author Graham
|
||||
* @author Major
|
||||
*/
|
||||
public interface CommandListener {
|
||||
public abstract class CommandListener {
|
||||
|
||||
/**
|
||||
* The minimum privilege level.
|
||||
*/
|
||||
private final PrivilegeLevel level;
|
||||
|
||||
/**
|
||||
* Creates a new command listener with a {@link PrivilegeLevel#STANDARD} requirement.
|
||||
*/
|
||||
public CommandListener() {
|
||||
this(PrivilegeLevel.STANDARD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new command listener.
|
||||
*
|
||||
* @param level The required {@link PrivilegeLevel}.
|
||||
*/
|
||||
public CommandListener(PrivilegeLevel level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the action for this command.
|
||||
@@ -15,6 +38,18 @@ public interface CommandListener {
|
||||
* @param player The player.
|
||||
* @param command The command.
|
||||
*/
|
||||
public void execute(Player player, Command command);
|
||||
public abstract void execute(Player player, Command command);
|
||||
|
||||
/**
|
||||
* Executes a privileged command.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param command The command.
|
||||
*/
|
||||
public final void executePrivileged(Player player, Command command) {
|
||||
if (player.getPrivilegeLevel().toInteger() >= level.toInteger()) {
|
||||
execute(player, command);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import org.apollo.util.plugin.PluginManager;
|
||||
*
|
||||
* @author Graham
|
||||
*/
|
||||
public final class CreditsCommandListener implements CommandListener {
|
||||
public final class CreditsCommandListener extends CommandListener {
|
||||
|
||||
/*
|
||||
* If you are considering removing this command, please bear in mind that Apollo took several people thousands of
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
package org.apollo.game.command;
|
||||
|
||||
import org.apollo.game.model.Player;
|
||||
import org.apollo.game.model.Player.PrivilegeLevel;
|
||||
|
||||
/**
|
||||
* A {@link CommandListener} which checks the {@link PrivilegeLevel} of the {@link Player} executing the command.
|
||||
*
|
||||
* @author Graham
|
||||
*/
|
||||
public abstract class PrivilegedCommandListener implements CommandListener {
|
||||
|
||||
/**
|
||||
* The minimum privilege level.
|
||||
*/
|
||||
private final PrivilegeLevel level;
|
||||
|
||||
/**
|
||||
* Creates the privileged command listener with the specified minimum level.
|
||||
*
|
||||
* @param level The minimum privilege level.
|
||||
*/
|
||||
public PrivilegedCommandListener(PrivilegeLevel level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void execute(Player player, Command command) {
|
||||
if (player.getPrivilegeLevel().toInteger() >= level.toInteger()) {
|
||||
executePrivileged(player, command);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a privileged command.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param command The command.
|
||||
*/
|
||||
public abstract void executePrivileged(Player player, Command command);
|
||||
|
||||
}
|
||||
@@ -57,7 +57,6 @@ public final class EventHandlerChain<E extends Event> {
|
||||
public void breakHandlerChain() {
|
||||
running[0] = false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
for (EventHandler<E> handler : handlers) {
|
||||
@@ -68,4 +67,4 @@ public final class EventHandlerChain<E extends Event> {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user