addition of PlayerGameModeChangeEvent

By: sunkid <sunkid@iminurnetz.com>
This commit is contained in:
Bukkit/Spigot 2011-09-16 19:49:56 -07:00
parent 6d19165044
commit a7f6bb5cd4
5 changed files with 53 additions and 0 deletions

View File

@ -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());
}

View File

@ -301,6 +301,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
*/

View File

@ -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;
}
}

View File

@ -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) {}
}

View File

@ -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: