Added onPlayerChat and onPlayerCommand

By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
Bukkit/Spigot 2010-12-28 16:41:37 +00:00
parent de10dba640
commit e61f164e8b
5 changed files with 81 additions and 3 deletions

View file

@ -0,0 +1,55 @@
package org.bukkit.event.player;
import org.bukkit.Player;
/**
* Holds information for player chat and commands
*/
public class PlayerChatEvent extends PlayerEvent {
private boolean cancel = false;
private String message;
public PlayerChatEvent(final Type type, final Player player, final String message) {
super(type, player);
this.message = message;
}
/**
* Gets the cancellation state of this event. A cancelled event will not
* be executed in the server, but will still pass to other plugins
*
* @return true if this event is cancelled
*/
public boolean isCancelled() {
return cancel;
}
/**
* Sets the cancellation state of this event. A cancelled event will not
* be executed in the server, but will still pass to other plugins
*
* @param cancel true if you wish to cancel this event
*/
public void setCancelled(boolean cancel) {
this.cancel = cancel;
}
/**
* Gets the message that the player is attempting to send
*
* @return Message the player is attempting to send
*/
public String getMessage() {
return message;
}
/**
* Sets the message that the player will send
*
* @param message New message that the player will send
*/
public void setMessage(String message) {
this.message = message;
}
}

View file

@ -12,6 +12,7 @@ public class PlayerListener implements Listener {
/**
* Called when a player joins a server
*
* @param event Relevant event details
*/
public void onPlayerJoin(PlayerEvent event) {
@ -19,8 +20,25 @@ public class PlayerListener implements Listener {
/**
* Called when a player leaves a server
*
* @param event Relevant event details
*/
public void onPlayerQuit(PlayerEvent event) {
}
/**
* Called when a player sends a chat message
*
* @param event Relevant event details
*/
public void onPlayerChat(PlayerChatEvent event) {
}
/**
* Called when a player attempts to use a command
*
* @param event Relevant event details
*/
public void onPlayerCommand(PlayerChatEvent event) {
}
}

View file

@ -76,7 +76,7 @@ public interface PluginManager {
public void callEvent(Event event);
/**
* Registers the given player event to the specified listener
* Registers the given event to the specified listener
*
* @param type EventType to register
* @param listener Listener to register

View file

@ -183,7 +183,7 @@ public final class SimplePluginManager implements PluginManager {
}
/**
* Registers the given player event to the specified listener
* Registers the given event to the specified listener
*
* @param type EventType to register
* @param listener PlayerListener to register

View file

@ -8,7 +8,6 @@ import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Map;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.regex.Pattern;
@ -88,6 +87,12 @@ public final class JavaPluginLoader implements PluginLoader {
case PLAYER_QUIT:
trueListener.onPlayerQuit((PlayerEvent)event);
break;
case PLAYER_COMMAND:
trueListener.onPlayerCommand((PlayerChatEvent)event);
break;
case PLAYER_CHAT:
trueListener.onPlayerChat((PlayerChatEvent)event);
break;
}
}
}