From 07c2162118ad34d16e85679b293b702f87aa6934 Mon Sep 17 00:00:00 2001 From: TheCutter Date: Sat, 13 Dec 2014 00:51:31 +0100 Subject: [PATCH] Implement WorldBorder API --- .../org/bukkit/craftbukkit/CraftWorld.java | 11 ++ .../bukkit/craftbukkit/CraftWorldBorder.java | 111 ++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 src/main/java/org/bukkit/craftbukkit/CraftWorldBorder.java diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index a7d3e5fa59..ad05e07318 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -22,6 +22,7 @@ import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.TreeType; import org.bukkit.World; +import org.bukkit.WorldBorder; import org.bukkit.block.Biome; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -56,6 +57,7 @@ public class CraftWorld implements World { public static final int CUSTOM_DIMENSION_OFFSET = 10; private final WorldServer world; + private WorldBorder worldBorder; private Environment environment; private final CraftServer server = (CraftServer) Bukkit.getServer(); private final ChunkGenerator generator; @@ -1282,6 +1284,15 @@ public class CraftWorld implements World { return getHandle().getGameRules().contains(rule); } + @Override + public WorldBorder getWorldBorder() { + if (this.worldBorder == null) { + this.worldBorder = new CraftWorldBorder(this); + } + + return this.worldBorder; + } + public void processChunkGC() { chunkGCTickCount++; diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorldBorder.java b/src/main/java/org/bukkit/craftbukkit/CraftWorldBorder.java new file mode 100644 index 0000000000..f44e234895 --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorldBorder.java @@ -0,0 +1,111 @@ +package org.bukkit.craftbukkit; + +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.WorldBorder; + +public class CraftWorldBorder implements WorldBorder { + + private final World world; + private final net.minecraft.server.WorldBorder handle; + + public CraftWorldBorder(CraftWorld world) { + this.world = world; + this.handle = world.getHandle().af(); // PAIL: Rename + } + + @Override + public void reset() { + this.setSize(6.0E7D); + this.setDamageAmount(0.2D); + this.setDamageBuffer(5.0D); + this.setWarningDistance(5); + this.setWarningTime(15); + this.setCenter(0, 0); + } + + @Override + public double getSize() { + return this.handle.h(); // PAIL: Rename + } + + @Override + public void setSize(double newSize) { + this.setSize(newSize, 0L); + } + + @Override + public void setSize(double newSize, long time) { + // PAIL: TODO: Magic Values + newSize = Math.min(6.0E7D, Math.max(1.0D, newSize)); + time = Math.min(9223372036854775L, Math.max(0L, time)); + + if (time > 0L) { + this.handle.a(this.handle.h(), newSize, time * 1000L); // PAIL: Rename + } else { + this.handle.a(newSize); // PAIL: Rename + } + } + + @Override + public Location getCenter() { + double x = this.handle.f(); // PAIL: Rename + double z = this.handle.g(); // PAIL: Rename + + return new Location(this.world, x, 0, z); + } + + @Override + public void setCenter(double x, double z) { + // PAIL: TODO: Magic Values + x = Math.min(3.0E7D, Math.max(-3.0E7D, x)); + z = Math.min(3.0E7D, Math.max(-3.0E7D, z)); + + this.handle.c(x, z); // PAIL: Rename + } + + @Override + public void setCenter(Location location) { + this.setCenter(location.getX(), location.getZ()); + } + + @Override + public double getDamageBuffer() { + return this.handle.m(); // PAIL: Rename + } + + @Override + public void setDamageBuffer(double blocks) { + this.handle.b(blocks); // PAIL: Rename + } + + @Override + public double getDamageAmount() { + return this.handle.n(); // PAIL: Rename + } + + @Override + public void setDamageAmount(double damage) { + this.handle.c(damage); // PAIL: Rename + } + + @Override + public int getWarningTime() { + return this.handle.p(); // PAIL: Rename + } + + @Override + public void setWarningTime(int time) { + this.handle.b(time); // PAIL: Rename + } + + @Override + public int getWarningDistance() { + return this.handle.q(); // PAIL: Rename + } + + @Override + public void setWarningDistance(int distance) { + this.handle.c(distance); // PAIL: Rename + } +}