From e42c5be1dc154db68ed71af294d02a25718b2d9a Mon Sep 17 00:00:00 2001 From: timafh Date: Fri, 4 Sep 2015 20:20:27 +0200 Subject: [PATCH] Adding WorldBorder Events --- .../Events/WorldBorderFillFinishedEvent.java | 37 +++++++++++++++++++ .../Events/WorldBorderTrimFinishedEvent.java | 37 +++++++++++++++++++ .../com/wimbli/WorldBorder/WorldFillTask.java | 15 +++++--- .../com/wimbli/WorldBorder/WorldTrimTask.java | 16 +++++--- 4 files changed, 94 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/wimbli/WorldBorder/Events/WorldBorderFillFinishedEvent.java create mode 100644 src/main/java/com/wimbli/WorldBorder/Events/WorldBorderTrimFinishedEvent.java diff --git a/src/main/java/com/wimbli/WorldBorder/Events/WorldBorderFillFinishedEvent.java b/src/main/java/com/wimbli/WorldBorder/Events/WorldBorderFillFinishedEvent.java new file mode 100644 index 0000000..06b262d --- /dev/null +++ b/src/main/java/com/wimbli/WorldBorder/Events/WorldBorderFillFinishedEvent.java @@ -0,0 +1,37 @@ +package com.wimbli.WorldBorder.Events; + +import org.bukkit.World; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +/** + * Created by timafh on 04.09.2015. + */ +public class WorldBorderFillFinishedEvent extends Event { + + private static final HandlerList handlers = new HandlerList(); + private World world; + private long totalChunks; + + public WorldBorderFillFinishedEvent(World world, long totalChunks) { + this.world = world; + this.totalChunks = totalChunks; + } + + + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + public World getWorld() { + return world; + } + + public long getTotalChunks() { + return totalChunks; + } +} diff --git a/src/main/java/com/wimbli/WorldBorder/Events/WorldBorderTrimFinishedEvent.java b/src/main/java/com/wimbli/WorldBorder/Events/WorldBorderTrimFinishedEvent.java new file mode 100644 index 0000000..e983d4f --- /dev/null +++ b/src/main/java/com/wimbli/WorldBorder/Events/WorldBorderTrimFinishedEvent.java @@ -0,0 +1,37 @@ +package com.wimbli.WorldBorder.Events; + +import org.bukkit.World; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +/** + * Created by timafh on 04.09.2015. + */ +public class WorldBorderTrimFinishedEvent extends Event { + + private static final HandlerList handlers = new HandlerList(); + private World world; + private long totalChunks; + + public WorldBorderTrimFinishedEvent(World world, long totalChunks) { + this.world = world; + this.totalChunks = totalChunks; + } + + + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + public World getWorld() { + return world; + } + + public long getTotalChunks() { + return totalChunks; + } +} \ No newline at end of file diff --git a/src/main/java/com/wimbli/WorldBorder/WorldFillTask.java b/src/main/java/com/wimbli/WorldBorder/WorldFillTask.java index 7a669ff..360318d 100644 --- a/src/main/java/com/wimbli/WorldBorder/WorldFillTask.java +++ b/src/main/java/com/wimbli/WorldBorder/WorldFillTask.java @@ -1,14 +1,16 @@ package com.wimbli.WorldBorder; -import java.util.HashSet; -import java.util.List; -import java.util.LinkedList; -import java.util.Set; - +import com.wimbli.WorldBorder.Events.WorldBorderFillFinishedEvent; +import org.bukkit.Bukkit; import org.bukkit.Chunk; -import org.bukkit.entity.Player; import org.bukkit.Server; import org.bukkit.World; +import org.bukkit.entity.Player; + +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; public class WorldFillTask implements Runnable @@ -312,6 +314,7 @@ public class WorldFillTask implements Runnable this.paused = true; reportProgress(); world.save(); + Bukkit.getServer().getPluginManager().callEvent(new WorldBorderFillFinishedEvent(world, reportTotal)); sendMessage("task successfully completed for world \"" + refWorld() + "\"!"); this.stop(); } diff --git a/src/main/java/com/wimbli/WorldBorder/WorldTrimTask.java b/src/main/java/com/wimbli/WorldBorder/WorldTrimTask.java index e2f5f6b..4797ccb 100644 --- a/src/main/java/com/wimbli/WorldBorder/WorldTrimTask.java +++ b/src/main/java/com/wimbli/WorldBorder/WorldTrimTask.java @@ -1,12 +1,17 @@ package com.wimbli.WorldBorder; -import java.io.*; -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.entity.Player; +import com.wimbli.WorldBorder.Events.WorldBorderTrimFinishedEvent; +import org.bukkit.Bukkit; import org.bukkit.Server; import org.bukkit.World; +import org.bukkit.entity.Player; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.util.ArrayList; +import java.util.List; public class WorldTrimTask implements Runnable @@ -334,6 +339,7 @@ public class WorldTrimTask implements Runnable { reportTotal = reportTarget; reportProgress(); + Bukkit.getServer().getPluginManager().callEvent(new WorldBorderTrimFinishedEvent(world, reportTotal)); sendMessage("task successfully completed!"); this.stop(); }