From a7f6bb5cd4c18da6f365c3a43c97bf08424ba603 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Fri, 16 Sep 2011 19:49:56 -0700 Subject: [PATCH] addition of PlayerGameModeChangeEvent By: sunkid --- .../command/defaults/GameModeCommand.java | 4 +++ .../src/main/java/org/bukkit/event/Event.java | 7 +++++ .../player/PlayerGameModeChangeEvent.java | 28 +++++++++++++++++++ .../bukkit/event/player/PlayerListener.java | 7 +++++ .../bukkit/plugin/java/JavaPluginLoader.java | 7 +++++ 5 files changed, 53 insertions(+) create mode 100644 paper-api/src/main/java/org/bukkit/event/player/PlayerGameModeChangeEvent.java diff --git a/paper-api/src/main/java/org/bukkit/command/defaults/GameModeCommand.java b/paper-api/src/main/java/org/bukkit/command/defaults/GameModeCommand.java index 50fb339dd4..da52629f50 100644 --- a/paper-api/src/main/java/org/bukkit/command/defaults/GameModeCommand.java +++ b/paper-api/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/paper-api/src/main/java/org/bukkit/event/Event.java b/paper-api/src/main/java/org/bukkit/event/Event.java index acfb252cf2..5066622e9e 100644 --- a/paper-api/src/main/java/org/bukkit/event/Event.java +++ b/paper-api/src/main/java/org/bukkit/event/Event.java @@ -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 */ diff --git a/paper-api/src/main/java/org/bukkit/event/player/PlayerGameModeChangeEvent.java b/paper-api/src/main/java/org/bukkit/event/player/PlayerGameModeChangeEvent.java new file mode 100644 index 0000000000..bc160161e5 --- /dev/null +++ b/paper-api/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/paper-api/src/main/java/org/bukkit/event/player/PlayerListener.java b/paper-api/src/main/java/org/bukkit/event/player/PlayerListener.java index 6a5137df21..2b634589a6 100644 --- a/paper-api/src/main/java/org/bukkit/event/player/PlayerListener.java +++ b/paper-api/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/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index a320e49eea..a5dbf5e71f 100644 --- a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/paper-api/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: