diff options
author | Andrew Ardill <andrew.ardill@gmail.com> | 2011-08-12 00:37:22 +1000 |
---|---|---|
committer | unknown <user@w.ardill@gmail.com> | 2011-08-15 14:57:25 +1000 |
commit | 12e377501ed7df16ce7e8de2bb99eed41d43fe4e (patch) | |
tree | fee981ec5c1d4d52c53480ebd6f392e1e3c91f31 /src/main/java/net/minecraft/server/WorldServer.java | |
parent | a6c03ded28b65a936003c6f4391923da75c4f7cb (diff) | |
download | craftbukkit-12e377501ed7df16ce7e8de2bb99eed41d43fe4e.tar craftbukkit-12e377501ed7df16ce7e8de2bb99eed41d43fe4e.tar.gz craftbukkit-12e377501ed7df16ce7e8de2bb99eed41d43fe4e.tar.lz craftbukkit-12e377501ed7df16ce7e8de2bb99eed41d43fe4e.tar.xz craftbukkit-12e377501ed7df16ce7e8de2bb99eed41d43fe4e.zip |
Implements interface for changing the view distance.
Uses default view distance if player's view distance is not set
Throws an illegal argument exception if view distance is set too high
or too low.
Pushes notifications of server and world view distance changes to the player.
Move view distance functions from PlayerManger to WorldServer.
Set player minimum view distance to 1 for now.
Reset player's 'last known' position when recalculating visible chunks.
Use per-player view distance in chunk distance checks
Diffstat (limited to 'src/main/java/net/minecraft/server/WorldServer.java')
-rw-r--r-- | src/main/java/net/minecraft/server/WorldServer.java | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java index 2005a9bc..b5f3b8ff 100644 --- a/src/main/java/net/minecraft/server/WorldServer.java +++ b/src/main/java/net/minecraft/server/WorldServer.java @@ -21,6 +21,10 @@ public class WorldServer extends World implements BlockChangeDelegate { public boolean canSave; public final MinecraftServer server; // CraftBukkit - private -> public final private EntityList G = new EntityList(); + // CraftBukkit start - extra variables + private int viewDistance; // keep track of changes to view distance + private boolean viewDistanceSet; // ...and if any changes have been made + // CraftBukkit end // CraftBukkit start - change signature public WorldServer(MinecraftServer minecraftserver, IDataManager idatamanager, String s, int i, long j, org.bukkit.World.Environment env, ChunkGenerator gen) { @@ -29,7 +33,9 @@ public class WorldServer extends World implements BlockChangeDelegate { this.dimension = i; this.pvpMode = minecraftserver.pvpMode; - this.manager = new PlayerManager(minecraftserver, this.dimension, minecraftserver.propertyManager.getInt("view-distance", 10)); + // use view distance from configuration manager, instead of property manager + // TODO allow saving view distance per world + this.manager = new PlayerManager(minecraftserver, this.dimension, minecraftserver.serverConfigurationManager.getViewDistance()); } public final int dimension; @@ -182,4 +188,50 @@ public class WorldServer extends World implements BlockChangeDelegate { // CraftBukkit end } } + + // CraftBukkit start - add getter and setter for view distance + public int getViewDistance() { + if (viewDistanceSet) { + return viewDistance; + } else { + return getServer().getViewDistance(); + } + } + + /** + * This method enforces notchian view distances. Do not set it below 3 or above 15. + * It is possible to set view distance per-player to any positive value. + * @param viewDistance the number of chunks players herein managed can see by default. + * @throws IllegalArgumentException If view distance is less than 3 or greater than 15 + */ + public void setViewDistance(int viewDistance) throws IllegalArgumentException{ + if (viewDistance > 15) { + throw new IllegalArgumentException("Too big view radius!"); + } else if (viewDistance < 3) { + throw new IllegalArgumentException("Too small view radius!"); + } else { + this.viewDistance = viewDistance; + this.viewDistanceSet = true; + updateViewDistance(); + } + } + + public void resetViewDistance() { + viewDistanceSet = false; + updateViewDistance(); + } + + public boolean isViewDistanceSet() { + return viewDistanceSet; + } + + public void updateViewDistance() { + // notify players that they may have to update their view distance + for (Object entityPlayerObject : this.manager.managedPlayers) { + if (entityPlayerObject instanceof EntityPlayer) { + ((EntityPlayer) entityPlayerObject).updateViewDistance(); + } + } + } + // CraftBukkit end } |