@@ -0,0 +1,66 @@
|
||||
|
||||
package org.bukkit.event.player;
|
||||
|
||||
import org.bukkit.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
|
||||
/**
|
||||
* Holds information for player chat and commands
|
||||
*/
|
||||
public class PlayerChatEvent extends PlayerEvent implements Cancellable {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the player that this message will display as, or command will be
|
||||
* executed as
|
||||
*
|
||||
* @param player New player which this event will execute as
|
||||
*/
|
||||
public void setPlayer(final Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
package org.bukkit.event.player;
|
||||
|
||||
import org.bukkit.Player;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
/**
|
||||
* Represents a player related event
|
||||
*/
|
||||
public class PlayerEvent extends Event {
|
||||
protected Player player;
|
||||
|
||||
public PlayerEvent(final Event.Type type, final Player who) {
|
||||
super(type);
|
||||
player = who;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the player involved in this event
|
||||
* @return Player who is involved in this event
|
||||
*/
|
||||
public final Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
|
||||
package org.bukkit.event.player;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
/**
|
||||
* Handles all events thrown in relation to a Player
|
||||
*/
|
||||
public class PlayerListener implements Listener {
|
||||
public PlayerListener() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player joins a server
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onPlayerJoin(PlayerEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player attempts to move location in a world
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player attempts to teleport to a new location in a world
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onPlayerTeleport(PlayerMoveEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player attempts to log in to the server
|
||||
*
|
||||
* @param event Relevant event details
|
||||
*/
|
||||
public void onPlayerLogin(PlayerLoginEvent event) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
|
||||
package org.bukkit.event.player;
|
||||
|
||||
import org.bukkit.Player;
|
||||
|
||||
/**
|
||||
* Stores details for players attempting to log in
|
||||
*/
|
||||
public class PlayerLoginEvent extends PlayerEvent {
|
||||
private Result result;
|
||||
private String message;
|
||||
|
||||
public PlayerLoginEvent(final Type type, final Player player) {
|
||||
super(type, player);
|
||||
this.result = Result.ALLOWED;
|
||||
this.message = "";
|
||||
}
|
||||
|
||||
public PlayerLoginEvent(final Type type, final Player player, final Result result, final String message) {
|
||||
super(type, player);
|
||||
this.result = result;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current result of the login, as an enum
|
||||
*
|
||||
* @return Current Result of the login
|
||||
*/
|
||||
public Result getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new result of the login, as an enum
|
||||
*
|
||||
* @param result New result to set
|
||||
*/
|
||||
public void setResult(final Result result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current kick message that will be used if getResult() != Result.ALLOWED
|
||||
*
|
||||
* @return Current kick message
|
||||
*/
|
||||
public String getKickMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the kick message to display if getResult() != Result.ALLOWED
|
||||
*
|
||||
* @param message New kick message
|
||||
*/
|
||||
public void setKickMessage(final String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows the player to log in
|
||||
*/
|
||||
public void allow() {
|
||||
result = Result.ALLOWED;
|
||||
message = "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Disallows the player from logging in, with the given reason
|
||||
*
|
||||
* @param result New result for disallowing the player
|
||||
* @param message Kick message to display to the user
|
||||
*/
|
||||
public void disallow(final Result result, final String message) {
|
||||
this.result = result;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic kick reasons for communicating to plugins
|
||||
*/
|
||||
public enum Result {
|
||||
/**
|
||||
* The player is allowed to log in
|
||||
*/
|
||||
ALLOWED,
|
||||
|
||||
/**
|
||||
* The player is not allowed to log in, due to the server being full
|
||||
*/
|
||||
KICK_FULL,
|
||||
|
||||
/**
|
||||
* The player is not allowed to log in, due to them being banned
|
||||
*/
|
||||
KICK_BANNED,
|
||||
|
||||
/**
|
||||
* The player is not allowed to log in, for reasons undefined
|
||||
*/
|
||||
KICK_OTHER
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
|
||||
package org.bukkit.event.player;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
/**
|
||||
* Holds information for player movement and teleportation events
|
||||
*/
|
||||
public class PlayerMoveEvent extends PlayerEvent implements Cancellable {
|
||||
private boolean cancel = false;
|
||||
private Location from;
|
||||
private Location to;
|
||||
|
||||
public PlayerMoveEvent(final Event.Type type, final Player player, final Location from, final Location to) {
|
||||
super(type, player);
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cancellation state of this event. A cancelled event will not
|
||||
* be executed in the server, but will still pass to other plugins
|
||||
*
|
||||
* If a move or teleport event is cancelled, the player will be moved or
|
||||
* teleported back to the Location as defined by getFrom(). This will not
|
||||
* fire an event
|
||||
*
|
||||
* @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
|
||||
*
|
||||
* If a move or teleport event is cancelled, the player will be moved or
|
||||
* teleported back to the Location as defined by getFrom(). This will not
|
||||
* fire an event
|
||||
*
|
||||
* @param cancel true if you wish to cancel this event
|
||||
*/
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the location this player moved from
|
||||
*
|
||||
* @return Location the player moved from
|
||||
*/
|
||||
public Location getFrom() {
|
||||
return from;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the location to mark as where the player moved from
|
||||
*
|
||||
* @param from New location to mark as the players previous location
|
||||
*/
|
||||
public void setFrom(Location from) {
|
||||
this.from = from;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the location this player moved to
|
||||
*
|
||||
* @return Location the player moved to
|
||||
*/
|
||||
public Location getTo() {
|
||||
return to;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the location that this player will move to
|
||||
*
|
||||
* @param to New Location this player will move to
|
||||
*/
|
||||
public void setTo(Location to) {
|
||||
this.to = to;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user