diff options
author | sunkid <sunkid@iminurnetz.com> | 2011-09-16 19:49:56 -0700 |
---|---|---|
committer | Dinnerbone <dinnerbone@dinnerbone.com> | 2011-09-18 00:28:14 +0100 |
commit | 627e2af265cd05b76932b11ed5e2a18996bce9a8 (patch) | |
tree | 12419c76fe7d48afcf0e3371fa48a0fdef51711a | |
parent | 3d04c67ae4ea3dbf05449c951e741beac8388beb (diff) | |
download | bukkit-627e2af265cd05b76932b11ed5e2a18996bce9a8.tar bukkit-627e2af265cd05b76932b11ed5e2a18996bce9a8.tar.gz bukkit-627e2af265cd05b76932b11ed5e2a18996bce9a8.tar.lz bukkit-627e2af265cd05b76932b11ed5e2a18996bce9a8.tar.xz bukkit-627e2af265cd05b76932b11ed5e2a18996bce9a8.zip |
addition of PlayerGameModeChangeEvent
5 files changed, 53 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/command/defaults/GameModeCommand.java b/src/main/java/org/bukkit/command/defaults/GameModeCommand.java index 50fb339d..da52629f 100644 --- a/src/main/java/org/bukkit/command/defaults/GameModeCommand.java +++ b/src/main/java/org/bukkit/command/defaults/GameModeCommand.java @@ -39,6 +39,10 @@ public class GameModeCommand extends VanillaCommand { Command.broadcastCommandMessage(sender, "Setting " + player.getName() + " to game mode " + mode.getValue()); player.setGameMode(mode); + + if (mode != player.getGameMode()) { + Command.broadcastCommandMessage(sender, "The game mode change for " + player.getName() + " was cancelled!"); + } } else { sender.sendMessage(player.getName() + " already has game mode " + mode.getValue()); } diff --git a/src/main/java/org/bukkit/event/Event.java b/src/main/java/org/bukkit/event/Event.java index acfb252c..5066622e 100644 --- a/src/main/java/org/bukkit/event/Event.java +++ b/src/main/java/org/bukkit/event/Event.java @@ -302,6 +302,13 @@ public abstract class Event implements Serializable { PLAYER_FISH(Category.PLAYER), /** + * Called when the game mode of a player is changed + * + * @see org.bukkit.event.player.PlayerGameModeChangeEvent + */ + PLAYER_GAME_MODE_CHANGE(Category.PLAYER), + + /** * BLOCK EVENTS */ diff --git a/src/main/java/org/bukkit/event/player/PlayerGameModeChangeEvent.java b/src/main/java/org/bukkit/event/player/PlayerGameModeChangeEvent.java new file mode 100644 index 00000000..bc160161 --- /dev/null +++ b/src/main/java/org/bukkit/event/player/PlayerGameModeChangeEvent.java @@ -0,0 +1,28 @@ +package org.bukkit.event.player; + +import org.bukkit.GameMode; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; + +public class PlayerGameModeChangeEvent extends PlayerEvent implements Cancellable { + + private boolean cancelled; + private GameMode newGameMode; + + public PlayerGameModeChangeEvent(Player player, GameMode newGameMode) { + super(Type.PLAYER_GAME_MODE_CHANGE, player); + this.newGameMode = newGameMode; + } + + public boolean isCancelled() { + return cancelled; + } + + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + + public GameMode getNewGameMode() { + return newGameMode; + } +} diff --git a/src/main/java/org/bukkit/event/player/PlayerListener.java b/src/main/java/org/bukkit/event/player/PlayerListener.java index 6a5137df..2b634589 100644 --- a/src/main/java/org/bukkit/event/player/PlayerListener.java +++ b/src/main/java/org/bukkit/event/player/PlayerListener.java @@ -191,4 +191,11 @@ public class PlayerListener implements Listener { * @param event Relevant event details */ public void onPlayerFish(PlayerFishEvent event) {} + + /** + * Called when a player's game mode is changed + * + * @param event Relevant event details + */ + public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {} } diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index a320e49e..a5dbf5e7 100644 --- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -419,6 +419,13 @@ public class JavaPluginLoader implements PluginLoader { ((PlayerListener) listener).onPlayerFish((PlayerFishEvent) event); } }; + + case PLAYER_GAME_MODE_CHANGE: + return new EventExecutor() { + public void execute(Listener listener, Event event) { + ((PlayerListener) listener).onPlayerGameModeChange((PlayerGameModeChangeEvent) event); + } + }; // Block Events case BLOCK_PHYSICS: |