From 363d5d3f2215240bbb6461f05732c2965f717c21 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Fri, 12 Aug 2011 00:37:22 +1000 Subject: [PATCH] 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 By: Andrew Ardill --- .../org/bukkit/craftbukkit/CraftServer.java | 20 +++++++++++++---- .../org/bukkit/craftbukkit/CraftWorld.java | 20 +++++++++++++++++ .../craftbukkit/entity/CraftPlayer.java | 22 +++++++++++++++++-- 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 5eb2bd5368..ec5dbb77ff 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -275,10 +275,6 @@ public final class CraftServer implements Server { return this.getConfigInt("server-port", 25565); } - public int getViewDistance() { - return this.getConfigInt("view-distance", 10); - } - public String getIp() { return this.getConfigString("server-ip", ""); } @@ -754,6 +750,22 @@ public final class CraftServer implements Server { return this.console.allowFlight; } + public int getViewDistance() { + return server.getViewDistance(); + } + + public void setViewDistance(int viewDistance) throws IllegalArgumentException{ + server.setViewDistance(viewDistance); + updateViewDistance(); + server.saveViewDistance(); + } + + public void updateViewDistance() { + for (World world : worlds.values()) { + ((CraftWorld) world).updateViewDistance(); + } + } + public ChunkGenerator getGenerator(String world) { ConfigurationNode node = configuration.getNode("worlds"); ChunkGenerator result = null; diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index ed09f0f33d..b527515f83 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -811,4 +811,24 @@ public class CraftWorld implements World { } } } + + public int getViewDistance() { + return world.getViewDistance(); + } + + public void setViewDistance(int viewDistance) throws IllegalArgumentException{ + world.setViewDistance(viewDistance); + } + + public void resetViewDistance(){ + world.resetViewDistance(); + } + + public boolean isViewDistanceSet() { + return world.isViewDistanceSet(); + } + + public void updateViewDistance() { + world.updateViewDistance(); + } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index c86d7e5c99..f363535779 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -1,7 +1,5 @@ package org.bukkit.craftbukkit.entity; -import java.net.InetSocketAddress; -import java.net.SocketAddress; import net.minecraft.server.EntityHuman; import net.minecraft.server.EntityPlayer; import net.minecraft.server.Packet131; @@ -28,7 +26,11 @@ import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.map.MapView; +import java.net.InetSocketAddress; +import java.net.SocketAddress; + public class CraftPlayer extends CraftHumanEntity implements Player { + public CraftPlayer(CraftServer server, EntityPlayer entity) { super(server, entity); } @@ -345,4 +347,20 @@ public class CraftPlayer extends CraftHumanEntity implements Player { public void resetPlayerTime() { setPlayerTime(0, true); } + + public void setViewDistance(int viewDistance) { + getHandle().setViewDistance(viewDistance); + } + + public int getViewDistance() { + return getHandle().getViewDistance(); + } + + public void resetViewDistance() { + getHandle().resetViewDistance(); + } + + public boolean isViewDistanceSet() { + return getHandle().isViewDistanceSet(); + } }