From 965fb782cd3c4d35396b0a6e4919fb053235684e Mon Sep 17 00:00:00 2001 From: BuildTools Date: Wed, 15 Aug 2018 23:10:15 +0200 Subject: [PATCH] Removed generator, rework of PlayerDeathListener, documented Events --- WorldSystem/bin/plugin.yml | 3 +- .../butzlabben/event/WorldAddmemberEvent.java | 12 +++- .../de/butzlabben/event/WorldCreateEvent.java | 10 ++++ .../de/butzlabben/event/WorldDeleteEvent.java | 8 ++- .../de/butzlabben/event/WorldLoadEvent.java | 6 ++ .../event/WorldRemovememberEvent.java | 9 +++ .../de/butzlabben/event/WorldResetEvent.java | 12 ++++ .../event/WorldToggleFireEvent.java | 16 +++++ .../butzlabben/event/WorldToggleTntEvent.java | 17 +++++- .../de/butzlabben/event/WorldUnloadEvent.java | 5 +- .../src/de/butzlabben/world/WorldSystem.java | 10 ++-- .../world/command/WSResetCommand.java | 7 ++- .../butzlabben/world/config/WorldConfig.java | 2 + .../CommandExecutorClickListener.java | 1 + .../world/listener/PlayerDeathListener.java | 30 +++++++--- .../butzlabben/world/wrapper/SystemWorld.java | 2 +- .../jubeki/generator/AbstractGenerator.java | 49 --------------- .../de/jubeki/generator/FlatGenerator.java | 52 ---------------- .../de/jubeki/generator/GridGenerator.java | 59 ------------------- .../de/jubeki/generator/VoidGenerator.java | 16 ----- WorldSystem/src/plugin.yml | 3 +- 21 files changed, 131 insertions(+), 198 deletions(-) delete mode 100644 WorldSystem/src/de/jubeki/generator/AbstractGenerator.java delete mode 100644 WorldSystem/src/de/jubeki/generator/FlatGenerator.java delete mode 100644 WorldSystem/src/de/jubeki/generator/GridGenerator.java delete mode 100644 WorldSystem/src/de/jubeki/generator/VoidGenerator.java diff --git a/WorldSystem/bin/plugin.yml b/WorldSystem/bin/plugin.yml index cf46d4e..38d81ab 100644 --- a/WorldSystem/bin/plugin.yml +++ b/WorldSystem/bin/plugin.yml @@ -1,5 +1,5 @@ name: WorldSystem -version: 2.3.1.1 +version: 2.3.1.4 author: Butzlabben main: de.butzlabben.world.WorldSystem @@ -59,6 +59,7 @@ permissions: children: ws.tp.*: true ws.get: true + ws.sethome: true ws.tp.world: true ws.tp.toother: true ws.tp.other: true diff --git a/WorldSystem/src/de/butzlabben/event/WorldAddmemberEvent.java b/WorldSystem/src/de/butzlabben/event/WorldAddmemberEvent.java index ce45de9..c83720f 100644 --- a/WorldSystem/src/de/butzlabben/event/WorldAddmemberEvent.java +++ b/WorldSystem/src/de/butzlabben/event/WorldAddmemberEvent.java @@ -6,6 +6,8 @@ import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; /** + * Event for adding somebody to a world + * * @author Butzlabben * @since 09.05.2018 */ @@ -21,14 +23,23 @@ public class WorldAddmemberEvent extends WorldEvent { this.adder = adder; } + /** + * @return player who adds somebody + */ public Player getAdding() { return adder; } + /** + * @return UUID of player who gets added + */ public UUID getUUID() { return uuid; } + /** + * @return worldname for which it happens + */ public String getWorldname() { return worldname; } @@ -38,6 +49,5 @@ public class WorldAddmemberEvent extends WorldEvent { return handlers; } - public final static HandlerList handlers = new HandlerList(); } diff --git a/WorldSystem/src/de/butzlabben/event/WorldCreateEvent.java b/WorldSystem/src/de/butzlabben/event/WorldCreateEvent.java index f0a0192..bfe9845 100644 --- a/WorldSystem/src/de/butzlabben/event/WorldCreateEvent.java +++ b/WorldSystem/src/de/butzlabben/event/WorldCreateEvent.java @@ -4,6 +4,13 @@ import org.bukkit.WorldCreator; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; +/** + * Event if a SystemWorld gets created. + * Do mix up with the WorldCreateEvent from Bukkit + * + * @author Butzlabben + * @since 09.05.2018 + */ public class WorldCreateEvent extends WorldEvent { private final Player owner; @@ -14,6 +21,9 @@ public class WorldCreateEvent extends WorldEvent { this.setWorldCreator(creator); } + /** + * @return owner of world that gets created + */ public Player getOwner() { return owner; } diff --git a/WorldSystem/src/de/butzlabben/event/WorldDeleteEvent.java b/WorldSystem/src/de/butzlabben/event/WorldDeleteEvent.java index 7ccc933..661c375 100644 --- a/WorldSystem/src/de/butzlabben/event/WorldDeleteEvent.java +++ b/WorldSystem/src/de/butzlabben/event/WorldDeleteEvent.java @@ -5,6 +5,12 @@ import org.bukkit.event.HandlerList; import de.butzlabben.world.wrapper.SystemWorld; +/** + * Event if a systemworld gets deleted + * + * @author Butzlabben + * @since 09.05.2018 + */ public class WorldDeleteEvent extends WorldEvent { private final SystemWorld world; @@ -29,8 +35,6 @@ public class WorldDeleteEvent extends WorldEvent { return executor; } - - public final static HandlerList handlers = new HandlerList(); public final static HandlerList getHandlerList() { diff --git a/WorldSystem/src/de/butzlabben/event/WorldLoadEvent.java b/WorldSystem/src/de/butzlabben/event/WorldLoadEvent.java index 7f917b7..282e694 100644 --- a/WorldSystem/src/de/butzlabben/event/WorldLoadEvent.java +++ b/WorldSystem/src/de/butzlabben/event/WorldLoadEvent.java @@ -5,6 +5,12 @@ import org.bukkit.event.HandlerList; import de.butzlabben.world.wrapper.SystemWorld; +/** + * Event for loading a world + * + * @author Butzlabben + * @since 09.05.2018 + */ public class WorldLoadEvent extends WorldEvent { private final Player owner; diff --git a/WorldSystem/src/de/butzlabben/event/WorldRemovememberEvent.java b/WorldSystem/src/de/butzlabben/event/WorldRemovememberEvent.java index 91fa51a..7ec8706 100644 --- a/WorldSystem/src/de/butzlabben/event/WorldRemovememberEvent.java +++ b/WorldSystem/src/de/butzlabben/event/WorldRemovememberEvent.java @@ -21,14 +21,23 @@ public class WorldRemovememberEvent extends WorldEvent { this.remover = remover; } + /** + * @return player who removes somebody + */ public Player getRemoving() { return remover; } + /** + * @return uuid of player who gets removed + */ public UUID getUUID() { return uuid; } + /** + * @return worldname for which it happens + */ public String getWorldname() { return worldname; } diff --git a/WorldSystem/src/de/butzlabben/event/WorldResetEvent.java b/WorldSystem/src/de/butzlabben/event/WorldResetEvent.java index 48b362b..d8ce9ca 100644 --- a/WorldSystem/src/de/butzlabben/event/WorldResetEvent.java +++ b/WorldSystem/src/de/butzlabben/event/WorldResetEvent.java @@ -5,6 +5,12 @@ import org.bukkit.event.HandlerList; import de.butzlabben.world.wrapper.SystemWorld; +/** + * Event when a world gets reset + * + * @author Butzlabben + * @since 09.05.2018 + */ public class WorldResetEvent extends WorldEvent { private final SystemWorld world; @@ -15,10 +21,16 @@ public class WorldResetEvent extends WorldEvent { this.world = world; } + /** + * @return world which gets reset + */ public SystemWorld getWorld() { return world; } + /** + * @return Executor of the command + */ public CommandSender getExecutor() { return executor; } diff --git a/WorldSystem/src/de/butzlabben/event/WorldToggleFireEvent.java b/WorldSystem/src/de/butzlabben/event/WorldToggleFireEvent.java index ca5ca60..3480a22 100644 --- a/WorldSystem/src/de/butzlabben/event/WorldToggleFireEvent.java +++ b/WorldSystem/src/de/butzlabben/event/WorldToggleFireEvent.java @@ -5,6 +5,10 @@ import org.bukkit.event.HandlerList; import de.butzlabben.world.wrapper.SystemWorld; +/** + * @author Butzlabben + * @since 09.05.2018 + */ public class WorldToggleFireEvent extends WorldEvent { private final SystemWorld world; @@ -17,18 +21,30 @@ public class WorldToggleFireEvent extends WorldEvent { this.value = value; } + /** + * @return if fire now gets enabled or disabled + */ public boolean getValue() { return value; } + /** + * @param val if fire should be enabled or disabled + */ public void setValue(boolean val) { value = val; } + /** + * @return world get world + */ public SystemWorld getWorld() { return world; } + /** + * @return get executor who toggles fire + */ public CommandSender getExecutor() { return executor; } diff --git a/WorldSystem/src/de/butzlabben/event/WorldToggleTntEvent.java b/WorldSystem/src/de/butzlabben/event/WorldToggleTntEvent.java index c6cb669..607ceac 100644 --- a/WorldSystem/src/de/butzlabben/event/WorldToggleTntEvent.java +++ b/WorldSystem/src/de/butzlabben/event/WorldToggleTntEvent.java @@ -5,6 +5,10 @@ import org.bukkit.event.HandlerList; import de.butzlabben.world.wrapper.SystemWorld; +/** + * @author Butzlabben + * @since 09.05.2018 + */ public class WorldToggleTntEvent extends WorldEvent { private final SystemWorld world; @@ -17,24 +21,35 @@ public class WorldToggleTntEvent extends WorldEvent { this.value = value; } + /** + * @return if tnt now gets enabled or disabled + */ public boolean getValue() { return value; } + /** + * @param val if tnt should be enabled or disabled + */ public void setValue(boolean val) { value = val; } + /** + * @return world get world + */ public SystemWorld getWorld() { return world; } + /** + * @return get executor who toggles tnt + */ public CommandSender getExecutor() { return executor; } - public final static HandlerList handlers = new HandlerList(); public final static HandlerList getHandlerList() { diff --git a/WorldSystem/src/de/butzlabben/event/WorldUnloadEvent.java b/WorldSystem/src/de/butzlabben/event/WorldUnloadEvent.java index ddd870c..180d4ab 100644 --- a/WorldSystem/src/de/butzlabben/event/WorldUnloadEvent.java +++ b/WorldSystem/src/de/butzlabben/event/WorldUnloadEvent.java @@ -6,7 +6,7 @@ import de.butzlabben.world.wrapper.SystemWorld; /** * @author Butzlabben - * @since 2017 + * @since 09.05.2018 */ public class WorldUnloadEvent extends WorldEvent { @@ -16,6 +16,9 @@ public class WorldUnloadEvent extends WorldEvent { this.world = world; } + /** + * @return world which gets unloaded + */ public SystemWorld getWorld() { return world; } diff --git a/WorldSystem/src/de/butzlabben/world/WorldSystem.java b/WorldSystem/src/de/butzlabben/world/WorldSystem.java index 51b36cf..1e5f3c2 100644 --- a/WorldSystem/src/de/butzlabben/world/WorldSystem.java +++ b/WorldSystem/src/de/butzlabben/world/WorldSystem.java @@ -2,13 +2,11 @@ package de.butzlabben.world; import java.io.File; import java.io.IOException; -import java.util.HashMap; import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -53,11 +51,9 @@ import de.butzlabben.world.wrapper.SystemWorld; */ public class WorldSystem extends JavaPlugin { - public static HashMap deathLocations = new HashMap<>(); - final private String version = this.getDescription().getVersion(); - public static CreatorAdapter creator; + private CreatorAdapter creator; private static boolean is1_13 = false; @@ -215,6 +211,10 @@ public class WorldSystem extends JavaPlugin { public static WorldSystem getInstance() { return JavaPlugin.getPlugin(WorldSystem.class); } + + public CreatorAdapter getAdapter() { + return creator; + } public static boolean is1_13() { return is1_13; diff --git a/WorldSystem/src/de/butzlabben/world/command/WSResetCommand.java b/WorldSystem/src/de/butzlabben/world/command/WSResetCommand.java index e764f43..0f37945 100644 --- a/WorldSystem/src/de/butzlabben/world/command/WSResetCommand.java +++ b/WorldSystem/src/de/butzlabben/world/command/WSResetCommand.java @@ -19,6 +19,7 @@ import de.butzlabben.world.WorldSystem; import de.butzlabben.world.config.DependenceConfig; import de.butzlabben.world.config.MessageConfig; import de.butzlabben.world.config.PluginConfig; +import de.butzlabben.world.config.WorldConfig; import de.butzlabben.world.wrapper.SystemWorld; public class WSResetCommand implements CommandExecutor { @@ -73,6 +74,10 @@ public class WSResetCommand implements CommandExecutor { toConfirm.remove(p); FileUtils.moveDirectoryToDirectory(f, Bukkit.getWorldContainer(), false); + + WorldConfig config = WorldConfig.getWorldConfig(worldname); + config.setHome(null); + config.save(); p.sendMessage(MessageConfig.getWorldReseted()); @@ -91,7 +96,7 @@ public class WSResetCommand implements CommandExecutor { sw.setCreating(true); // For #16 - WorldSystem.creator.create(creator, sw, () -> { + WorldSystem.getInstance().getAdapter().create(creator, sw, () -> { if (p != null && p.isOnline()) p.sendMessage(MessageConfig.getWorldCreated()); }); diff --git a/WorldSystem/src/de/butzlabben/world/config/WorldConfig.java b/WorldSystem/src/de/butzlabben/world/config/WorldConfig.java index 4e8aff4..e143dd9 100644 --- a/WorldSystem/src/de/butzlabben/world/config/WorldConfig.java +++ b/WorldSystem/src/de/butzlabben/world/config/WorldConfig.java @@ -438,6 +438,8 @@ public class WorldConfig { cfg.set("Settings.home.z", home.getZ()); cfg.set("Settings.home.yaw", home.getYaw()); cfg.set("Settings.home.pitch", home.getPitch()); + } else { + cfg.set("Settings.home", null); } cfg.set("Members", null); diff --git a/WorldSystem/src/de/butzlabben/world/gui/clicklistener/CommandExecutorClickListener.java b/WorldSystem/src/de/butzlabben/world/gui/clicklistener/CommandExecutorClickListener.java index ded3bb9..ed0041e 100644 --- a/WorldSystem/src/de/butzlabben/world/gui/clicklistener/CommandExecutorClickListener.java +++ b/WorldSystem/src/de/butzlabben/world/gui/clicklistener/CommandExecutorClickListener.java @@ -19,6 +19,7 @@ public class CommandExecutorClickListener implements OrcClickListener { p.closeInventory(); String msg = message; p.chat(msg); + // Fix for #9 inv.redraw(p); } } diff --git a/WorldSystem/src/de/butzlabben/world/listener/PlayerDeathListener.java b/WorldSystem/src/de/butzlabben/world/listener/PlayerDeathListener.java index 829b291..a3c055f 100644 --- a/WorldSystem/src/de/butzlabben/world/listener/PlayerDeathListener.java +++ b/WorldSystem/src/de/butzlabben/world/listener/PlayerDeathListener.java @@ -1,25 +1,29 @@ package de.butzlabben.world.listener; -import org.bukkit.Location; +import java.util.HashMap; +import java.util.UUID; + +import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerRespawnEvent; -import de.butzlabben.world.WorldSystem; import de.butzlabben.world.config.PluginConfig; +import de.butzlabben.world.config.WorldConfig; import de.butzlabben.world.wrapper.WorldPlayer; public class PlayerDeathListener implements Listener { + private HashMap deathLocations = new HashMap<>(); + @EventHandler public void onDie(PlayerDeathEvent e) { - e.setDeathMessage(null); Player p = e.getEntity(); WorldPlayer wp = new WorldPlayer(p, p.getWorld().getName()); if (wp.isOnSystemWorld()) { - WorldSystem.deathLocations.put(p, p.getLocation().getWorld()); + deathLocations.put(p.getUniqueId(), p.getLocation().getWorld()); } else { p.setGameMode(PluginConfig.getSpawnGamemode()); } @@ -28,10 +32,20 @@ public class PlayerDeathListener implements Listener { @EventHandler public void onRespawn(PlayerRespawnEvent e) { Player p = e.getPlayer(); - if (WorldSystem.deathLocations.containsKey(p)) { - Location loc =PluginConfig.getWorldSpawn(WorldSystem.deathLocations.get(p)); - e.setRespawnLocation(loc); - WorldSystem.deathLocations.remove(p); + if (deathLocations.containsKey(p.getUniqueId())) { + World world = deathLocations.remove(p.getUniqueId()); + + WorldConfig config = WorldConfig.getWorldConfig(world.getName()); + + if (config.getHome() != null) { + e.setRespawnLocation(config.getHome()); + } else { + if (PluginConfig.useWorldSpawn()) { + e.setRespawnLocation(PluginConfig.getWorldSpawn(world)); + } else { + e.setRespawnLocation(world.getSpawnLocation()); + } + } } } } diff --git a/WorldSystem/src/de/butzlabben/world/wrapper/SystemWorld.java b/WorldSystem/src/de/butzlabben/world/wrapper/SystemWorld.java index a1e159e..0494483 100644 --- a/WorldSystem/src/de/butzlabben/world/wrapper/SystemWorld.java +++ b/WorldSystem/src/de/butzlabben/world/wrapper/SystemWorld.java @@ -328,7 +328,7 @@ public class SystemWorld { SystemWorld sw = SystemWorld.getSystemWorld(worldname); sw.setCreating(true); // For #16 - WorldSystem.creator.create(event.getWorldCreator(), sw, () -> { + WorldSystem.getInstance().getAdapter().create(event.getWorldCreator(), sw, () -> { if (p != null && p.isOnline()) p.sendMessage(MessageConfig.getWorldCreated()); }); diff --git a/WorldSystem/src/de/jubeki/generator/AbstractGenerator.java b/WorldSystem/src/de/jubeki/generator/AbstractGenerator.java deleted file mode 100644 index 7e3efac..0000000 --- a/WorldSystem/src/de/jubeki/generator/AbstractGenerator.java +++ /dev/null @@ -1,49 +0,0 @@ -package de.jubeki.generator; - -import org.bukkit.Material; -import org.bukkit.block.Biome; -import org.bukkit.generator.ChunkGenerator; - -abstract class AbstractGenerator extends ChunkGenerator { - - void checkHeight(byte[][] result, int y) { - if (result[y >> 4] == null) { - result[y >> 4] = new byte[4096]; - } - } - - @SuppressWarnings("deprecation") - void setBlock(byte[][] result, int x, int y, int z, Material mat) { - result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = (byte) mat.getId(); - } - - byte[][] createDefaultResult() { - byte[][] result = new byte[16][]; - checkHeight(result, 0); - for (int x = 0; x < 16; x++) { - for (int z = 0; z < 16; z++) { - setBlock(result, x, 0, z, Material.BEDROCK); - } - } - return result; - } - - void setMaterial(byte[][] result, int min, int max, Material mat) { - for (int y = min; y <= max; y++) { - checkHeight(result, y); - for (int x = 0; x < 16; x++) { - for (int z = 0; z < 16; z++) { - setBlock(result, x, 0, z, mat); - } - } - } - } - - void setBiome(BiomeGrid biomes, Biome biome) { - for (int x = 0; x < 16; x++) { - for (int z = 0; z < 16; z++) { - biomes.setBiome(x, z, biome); - } - } - } -} diff --git a/WorldSystem/src/de/jubeki/generator/FlatGenerator.java b/WorldSystem/src/de/jubeki/generator/FlatGenerator.java deleted file mode 100644 index 60ad30c..0000000 --- a/WorldSystem/src/de/jubeki/generator/FlatGenerator.java +++ /dev/null @@ -1,52 +0,0 @@ -package de.jubeki.generator; - -import java.util.Random; - -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Biome; - -public class FlatGenerator extends AbstractGenerator { - - private final byte[][] result = createDefaultResult(); - - public FlatGenerator() { - this(3); - } - - public FlatGenerator(int height) { - if(height < 1) { - height = 1; - } - setDirt(height); - setGrass(height); - } - - public byte[][] generateBlockSections(World world, Random random, int x, int z, BiomeGrid biomes) { - setBiome(biomes, Biome.PLAINS); - return result; - } - - private void setGrass(int height) { - checkHeight(result, height); - for(int x = 0; x < 16; x++) { - for(int z = 0; z < 16; z++) { - setBlock(result, x, height, z, Material.GRASS); - } - } - } - - private void setDirt(int height) { - for(int y = 1; y < height; y++) { - checkHeight(result, y); - for(int x = 0; x < 16; x++) { - for(int z = 0; z < 16; z++) { - setBlock(result, x, y, z, Material.DIRT); - } - } - } - } - - - -} diff --git a/WorldSystem/src/de/jubeki/generator/GridGenerator.java b/WorldSystem/src/de/jubeki/generator/GridGenerator.java deleted file mode 100644 index 0b379e2..0000000 --- a/WorldSystem/src/de/jubeki/generator/GridGenerator.java +++ /dev/null @@ -1,59 +0,0 @@ -package de.jubeki.generator; - -import java.util.Random; - -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Biome; - -public class GridGenerator extends AbstractGenerator { - - public GridGenerator() { - this(3, 15); - } - - public GridGenerator(int grid) { - this(3, grid); - } - - private final int height, grid; - private final byte[][] result = createDefaultResult(); - - public GridGenerator(int height, int grid) { - this.height = height < 1 ? 1 : height; - this.grid = (grid < 1 ? 2 : grid+1); - setMaterial(result, 1, height-1, Material.DIRT); - if(grid == 16) { - for(int i = 0; i < 16; i++) { - for(int k = 0; k < 16; k++) { - if(i == 0 || k == 0) { - setBlock(result, i, height, k, Material.BEDROCK); - } else { - setBlock(result, i, height, k, Material.GRASS); - } - } - } - } - } - - public byte[][] generateBlockSections(World world, Random random, int x, int z, BiomeGrid biomes) { - setBiome(biomes, Biome.PLAINS); - if(grid == 16) { - return result; - } - int diffx = 16*x; - int diffz = 16*z; - for(int i = 0; i < 16; i++) { - boolean set = (diffx + i) % grid == 0; - for(int k = 0; k < 16; k++) { - if(set || (diffz + k) % grid == 0) { - setBlock(result, i, height, k, Material.BEDROCK); - } else { - setBlock(result, i, height, k, Material.GRASS); - } - } - } - return result; - } - -} diff --git a/WorldSystem/src/de/jubeki/generator/VoidGenerator.java b/WorldSystem/src/de/jubeki/generator/VoidGenerator.java deleted file mode 100644 index bf8486b..0000000 --- a/WorldSystem/src/de/jubeki/generator/VoidGenerator.java +++ /dev/null @@ -1,16 +0,0 @@ -package de.jubeki.generator; - -import java.util.Random; - -import org.bukkit.World; - -public class VoidGenerator extends AbstractGenerator { - - private final byte[][] result = new byte[16][]; - - public byte[][] generateBlockSections(World world, Random random, int x, int z, BiomeGrid biomes) { -// setBiome(biomes, Biome.VOID); - return result; - } - -} diff --git a/WorldSystem/src/plugin.yml b/WorldSystem/src/plugin.yml index cf46d4e..38d81ab 100644 --- a/WorldSystem/src/plugin.yml +++ b/WorldSystem/src/plugin.yml @@ -1,5 +1,5 @@ name: WorldSystem -version: 2.3.1.1 +version: 2.3.1.4 author: Butzlabben main: de.butzlabben.world.WorldSystem @@ -59,6 +59,7 @@ permissions: children: ws.tp.*: true ws.get: true + ws.sethome: true ws.tp.world: true ws.tp.toother: true ws.tp.other: true