3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-19 04:50:06 +01:00

Implemented gamemode methods

Dieser Commit ist enthalten in:
Dinnerbone 2011-09-15 02:22:20 +01:00
Ursprung 5b2c774edc
Commit a9b3a90dc9
4 geänderte Dateien mit 36 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -19,7 +19,7 @@ public class WorldData {
private int m; private int m;
private boolean n; private boolean n;
private int o; private int o;
private int p; public int p; // CraftBukkit - private -> public
private boolean q; private boolean q;
public WorldData(NBTTagCompound nbttagcompound) { public WorldData(NBTTagCompound nbttagcompound) {

Datei anzeigen

@ -822,10 +822,16 @@ public final class CraftServer implements Server {
} }
public GameMode getDefaultGameMode() { public GameMode getDefaultGameMode() {
return GameMode.SURVIVAL; return GameMode.getByValue(console.worlds.get(0).worldData.p);
} }
public void setDefaultGameMode(GameMode mode) { 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();
}
} }
} }

Datei anzeigen

@ -19,9 +19,11 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
private CraftInventoryPlayer inventory; private CraftInventoryPlayer inventory;
protected final PermissibleBase perm = new PermissibleBase(this); protected final PermissibleBase perm = new PermissibleBase(this);
private boolean op; private boolean op;
private GameMode mode;
public CraftHumanEntity(final CraftServer server, final EntityHuman entity) { public CraftHumanEntity(final CraftServer server, final EntityHuman entity) {
super(server, entity); super(server, entity);
mode = server.getDefaultGameMode();
this.inventory = new CraftInventoryPlayer(entity.inventory); this.inventory = new CraftInventoryPlayer(entity.inventory);
} }
@ -119,10 +121,14 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
} }
public GameMode getGameMode() { public GameMode getGameMode() {
return GameMode.SURVIVAL; return mode;
} }
public void setGameMode(GameMode 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;
} }
} }

Datei anzeigen

@ -12,9 +12,11 @@ import net.minecraft.server.Packet53BlockChange;
import net.minecraft.server.Packet54PlayNoteBlock; import net.minecraft.server.Packet54PlayNoteBlock;
import net.minecraft.server.Packet61; import net.minecraft.server.Packet61;
import net.minecraft.server.Packet6SpawnPosition; import net.minecraft.server.Packet6SpawnPosition;
import net.minecraft.server.Packet70Bed;
import net.minecraft.server.WorldServer; import net.minecraft.server.WorldServer;
import org.bukkit.Achievement; import org.bukkit.Achievement;
import org.bukkit.Effect; import org.bukkit.Effect;
import org.bukkit.GameMode;
import org.bukkit.Instrument; import org.bukkit.Instrument;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -377,4 +379,21 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
server.getHandle().l(getName().toLowerCase()); 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());
}
} }