diff --git a/src/main/java/net/minecraft/server/WorldData.java b/src/main/java/net/minecraft/server/WorldData.java index a562a39b9d..7d88c11eba 100644 --- a/src/main/java/net/minecraft/server/WorldData.java +++ b/src/main/java/net/minecraft/server/WorldData.java @@ -19,7 +19,7 @@ public class WorldData { private int m; private boolean n; private int o; - private int p; + public int p; // CraftBukkit - private -> public private boolean q; public WorldData(NBTTagCompound nbttagcompound) { diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 0038182066..234eced6f2 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -822,10 +822,16 @@ public final class CraftServer implements Server { } public GameMode getDefaultGameMode() { - return GameMode.SURVIVAL; + return GameMode.getByValue(console.worlds.get(0).worldData.p); } public void setDefaultGameMode(GameMode mode) { - throw new UnsupportedOperationException("Not supported yet."); + if (mode == null) { + throw new IllegalArgumentException("Mode cannot be null"); + } + + for (World world : getWorlds()) { + ((CraftWorld)world).getHandle().worldData.p = mode.getValue(); + } } } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java index 9a37697bb5..a46ec12233 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java @@ -19,9 +19,11 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { private CraftInventoryPlayer inventory; protected final PermissibleBase perm = new PermissibleBase(this); private boolean op; + private GameMode mode; public CraftHumanEntity(final CraftServer server, final EntityHuman entity) { super(server, entity); + mode = server.getDefaultGameMode(); this.inventory = new CraftInventoryPlayer(entity.inventory); } @@ -119,10 +121,14 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { } public GameMode getGameMode() { - return GameMode.SURVIVAL; + return mode; } public void setGameMode(GameMode mode) { - throw new UnsupportedOperationException("Not supported yet."); + if (mode == null) { + throw new IllegalArgumentException("Mode cannot be null"); + } + + this.mode = mode; } } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index fda5098b34..9548234b99 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -12,9 +12,11 @@ import net.minecraft.server.Packet53BlockChange; import net.minecraft.server.Packet54PlayNoteBlock; import net.minecraft.server.Packet61; import net.minecraft.server.Packet6SpawnPosition; +import net.minecraft.server.Packet70Bed; import net.minecraft.server.WorldServer; import org.bukkit.Achievement; import org.bukkit.Effect; +import org.bukkit.GameMode; import org.bukkit.Instrument; import org.bukkit.Location; import org.bukkit.Material; @@ -377,4 +379,21 @@ public class CraftPlayer extends CraftHumanEntity implements Player { server.getHandle().l(getName().toLowerCase()); } } + + @Override + public void setGameMode(GameMode mode) { + if (mode == null) { + throw new IllegalArgumentException("Mode cannot be null"); + } + + if (mode != getGameMode()) { + getHandle().itemInWorldManager.a(mode.getValue()); + getHandle().netServerHandler.sendPacket(new Packet70Bed(3, mode.getValue())); + } + } + + @Override + public GameMode getGameMode() { + return GameMode.getByValue(getHandle().itemInWorldManager.a()); + } }