Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions patches/org/bukkit/GameMode.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,22 @@
* Creative mode may fly, build instantly, become invulnerable and create
* free items.
*/
@@ -25,8 +31,17 @@
/**
* Adventure mode cannot break blocks, use chat, use buckets, etc.
*/
- ADVENTURE(2);
+ ADVENTURE(2),

+ // Crucible start - plugins built against 1.8+ APIs reference SPECTATOR directly
+ /**
+ * Spectator mode cannot interact with the world and is invisible to
+ * other players. Only available when a mod adds the spectator game type;
+ * otherwise the server refuses to switch to it.
+ */
+ SPECTATOR(3);
+ // Crucible end
+
private final int value;
private final static Map<Integer, GameMode> BY_ID = Maps.newHashMap();

39 changes: 38 additions & 1 deletion patches/org/bukkit/command/defaults/GameModeCommand.java.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
--- ../src-base/minecraft/org/bukkit/command/defaults/GameModeCommand.java
+++ ../src-work/minecraft/org/bukkit/command/defaults/GameModeCommand.java
@@ -50,7 +50,7 @@
@@ -9,13 +9,14 @@
import org.bukkit.GameMode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
+import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; // Crucible
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;

import com.google.common.collect.ImmutableList;

public class GameModeCommand extends VanillaCommand {
- private static final List<String> GAMEMODE_NAMES = ImmutableList.of("adventure", "creative", "survival");
+ private static final List<String> GAMEMODE_NAMES = ImmutableList.of("adventure", "creative", "survival", "spectator"); // Crucible

public GameModeCommand() {
super("gamemode");
@@ -50,16 +51,28 @@

GameMode mode = GameMode.getByValue(value);

Expand All @@ -9,3 +25,24 @@
if (modeArg.equalsIgnoreCase("creative") || modeArg.equalsIgnoreCase("c")) {
mode = GameMode.CREATIVE;
} else if (modeArg.equalsIgnoreCase("adventure") || modeArg.equalsIgnoreCase("a")) {
mode = GameMode.ADVENTURE;
+ // Crucible start
+ } else if (modeArg.equalsIgnoreCase("spectator") || modeArg.equalsIgnoreCase("sp")) {
+ mode = GameMode.SPECTATOR;
+ // Crucible end
} else {
mode = GameMode.SURVIVAL;
}
}

+ // Crucible start
+ if (!CraftPlayer.isGameModeAvailable(mode)) {
+ sender.sendMessage(ChatColor.RED + "Game mode " + mode + " is not available on this server: no installed mod adds it. "
+ + "Install a mod that does (suggestion: Et Futurum Requiem) to use it.");
+ return true;
+ }
+ // Crucible end
+
if (mode != player.getGameMode()) {
player.setGameMode(mode);

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.item.Item;
import net.minecraft.network.play.server.*;
import net.minecraft.world.WorldServer;
import net.minecraft.world.WorldSettings;
import org.apache.commons.lang.NotImplementedException;
import org.apache.commons.lang.Validate;
import org.bukkit.*;
Expand Down Expand Up @@ -859,6 +860,15 @@ public GameMode getGameMode() {
return GameMode.getByValue(getHandle().theItemInWorldManager.getGameType().getID());
}

/**
* Whether the server has a game type for {@code mode}. SPECTATOR exists in the API for newer plugins,
* but only becomes available when a mod registers the spectator game type.
*/
public static boolean isGameModeAvailable(GameMode mode) {
// GameType.getByID falls back to SURVIVAL for an id no one registered
return WorldSettings.GameType.getByID(mode.getValue()).getID() == mode.getValue();
}

@Override
public void setGameMode(GameMode mode) {
if (getHandle().playerNetServerHandler == null) return;
Expand All @@ -867,6 +877,12 @@ public void setGameMode(GameMode mode) {
throw new IllegalArgumentException("Mode cannot be null");
}

if (!isGameModeAvailable(mode)) {
server.getLogger().warning("Game mode of " + getName() + " left unchanged at " + getGameMode() + ": " + mode
+ " is not available because no installed mod adds that game type. Install one that does, or pick another mode.");
return;
}

if (mode != getGameMode()) {
PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(this, mode);
server.getPluginManager().callEvent(event);
Expand Down
Loading