From 5610b9cf9e600d42633fc6e00d002fbbaa31aa23 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Fri, 8 Jun 2018 20:09:37 +0200 Subject: [PATCH] See 2.1.2.1 and 2.1.2.2 --- WorldSystem/.classpath | 5 +- WorldSystem/bin/plugin.yml | 3 +- .../src/de/butzlabben/world/WorldSystem.java | 21 ++++++- .../world/command/WSToggleBuildCommand.java | 2 +- .../world/command/WSToggleGMCommand.java | 2 +- .../world/command/WSToggleTPCommand.java | 2 +- .../butzlabben/world/config/WorldConfig.java | 2 +- .../world/listener/BlockListener.java | 57 +++++++------------ .../world/wrapper/AsyncCreatorAdapter.java | 37 ++++++++++++ .../world/wrapper/CreatorAdapter.java | 12 ++++ .../butzlabben/world/wrapper/SystemWorld.java | 13 +++-- WorldSystem/src/plugin.yml | 3 +- 12 files changed, 108 insertions(+), 51 deletions(-) create mode 100644 WorldSystem/src/de/butzlabben/world/wrapper/AsyncCreatorAdapter.java create mode 100644 WorldSystem/src/de/butzlabben/world/wrapper/CreatorAdapter.java diff --git a/WorldSystem/.classpath b/WorldSystem/.classpath index 21ebb60..4046165 100644 --- a/WorldSystem/.classpath +++ b/WorldSystem/.classpath @@ -1,8 +1,9 @@ - - + + + diff --git a/WorldSystem/bin/plugin.yml b/WorldSystem/bin/plugin.yml index f278f33..3691ebd 100644 --- a/WorldSystem/bin/plugin.yml +++ b/WorldSystem/bin/plugin.yml @@ -1,7 +1,8 @@ name: WorldSystem -version: 2.1.2 +version: 2.1.2.2 author: Butzlabben main: de.butzlabben.world.WorldSystem +loadbefore: [FastAsyncWorldEdit, WorldEdit] commands: ws: diff --git a/WorldSystem/src/de/butzlabben/world/WorldSystem.java b/WorldSystem/src/de/butzlabben/world/WorldSystem.java index 03611e8..c6f1323 100644 --- a/WorldSystem/src/de/butzlabben/world/WorldSystem.java +++ b/WorldSystem/src/de/butzlabben/world/WorldSystem.java @@ -44,6 +44,8 @@ import de.butzlabben.world.listener.BlockListener; import de.butzlabben.world.listener.CommandListener; import de.butzlabben.world.listener.PlayerDeathListener; import de.butzlabben.world.listener.PlayerLeaveListener; +import de.butzlabben.world.wrapper.AsyncCreatorAdapter; +import de.butzlabben.world.wrapper.CreatorAdapter; import de.butzlabben.world.wrapper.SystemWorld; /** @@ -60,6 +62,8 @@ public class WorldSystem extends JavaPlugin { final private String version = this.getDescription().getVersion(); public static OrcInventory mainGUI; + public static CreatorAdapter creator; + @Override public void onEnable() { createConfigs(); @@ -126,7 +130,7 @@ public class WorldSystem extends JavaPlugin { getCommand("ws togglegm").setExecutor(new WSToggleGMCommand()); getCommand("ws togglebuild").setExecutor(new WSToggleBuildCommand()); getCommand("ws delete").setExecutor(new WSDeleteCommand()); - + getCommand("ws confirm").setExecutor(new WSConfirmCommand()); getCommand("ws gui").setExecutor(new GuiCommand()); @@ -136,9 +140,20 @@ public class WorldSystem extends JavaPlugin { System.setProperty("bstats.relocatecheck", "false"); Metrics m = new Metrics(this); m.addCustomChart(new Metrics.SingleLineChart("worlds", Entry::entrys)); - + AutoUpdater.startAsync(); - + + //Choose right creatoradapter for #16 + if (Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null + && Bukkit.getPluginManager().getPlugin("WorldEdit") != null) { + creator = new AsyncCreatorAdapter(); + Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "Found FAWE! Try now to create worlds async"); + } else { + creator = (c) -> { + Bukkit.getWorlds().add(c.createWorld()); + }; + } + Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "Succesfully enabled WorldSystem v" + version); } diff --git a/WorldSystem/src/de/butzlabben/world/command/WSToggleBuildCommand.java b/WorldSystem/src/de/butzlabben/world/command/WSToggleBuildCommand.java index affebad..62428e4 100644 --- a/WorldSystem/src/de/butzlabben/world/command/WSToggleBuildCommand.java +++ b/WorldSystem/src/de/butzlabben/world/command/WSToggleBuildCommand.java @@ -33,7 +33,7 @@ public class WSToggleBuildCommand implements CommandExecutor { @SuppressWarnings("deprecation") OfflinePlayer a = Bukkit.getOfflinePlayer(args[1]); WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname()); - if (wc.isMember(a.getUniqueId())) { + if (!wc.isMember(a.getUniqueId())) { p.sendMessage(MessageConfig.getNoMemberOwn()); return true; } diff --git a/WorldSystem/src/de/butzlabben/world/command/WSToggleGMCommand.java b/WorldSystem/src/de/butzlabben/world/command/WSToggleGMCommand.java index ea02f3d..bccbc23 100644 --- a/WorldSystem/src/de/butzlabben/world/command/WSToggleGMCommand.java +++ b/WorldSystem/src/de/butzlabben/world/command/WSToggleGMCommand.java @@ -33,7 +33,7 @@ public class WSToggleGMCommand implements CommandExecutor { @SuppressWarnings("deprecation") OfflinePlayer a = Bukkit.getOfflinePlayer(args[1]); WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname()); - if (wc.isMember(a.getUniqueId())) { + if (!wc.isMember(a.getUniqueId())) { p.sendMessage(MessageConfig.getNoMemberOwn()); return true; } diff --git a/WorldSystem/src/de/butzlabben/world/command/WSToggleTPCommand.java b/WorldSystem/src/de/butzlabben/world/command/WSToggleTPCommand.java index aee4ada..67c327d 100644 --- a/WorldSystem/src/de/butzlabben/world/command/WSToggleTPCommand.java +++ b/WorldSystem/src/de/butzlabben/world/command/WSToggleTPCommand.java @@ -33,7 +33,7 @@ public class WSToggleTPCommand implements CommandExecutor { @SuppressWarnings("deprecation") OfflinePlayer a = Bukkit.getOfflinePlayer(args[1]); WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname()); - if (wc.isMember(a.getUniqueId())) { + if (!wc.isMember(a.getUniqueId())) { p.sendMessage(MessageConfig.getNoMemberOwn()); return true; } diff --git a/WorldSystem/src/de/butzlabben/world/config/WorldConfig.java b/WorldSystem/src/de/butzlabben/world/config/WorldConfig.java index df4f591..7565bdf 100644 --- a/WorldSystem/src/de/butzlabben/world/config/WorldConfig.java +++ b/WorldSystem/src/de/butzlabben/world/config/WorldConfig.java @@ -27,7 +27,7 @@ import de.butzlabben.world.GameProfileBuilder; */ public class WorldConfig { - private static File getWorldFile(String worldname) { + public static File getWorldFile(String worldname) { File worldconfig = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); if (!worldconfig.exists()) { worldconfig = new File(PluginConfig.getWorlddir() + "/" + worldname + "/worldconfig.yml"); diff --git a/WorldSystem/src/de/butzlabben/world/listener/BlockListener.java b/WorldSystem/src/de/butzlabben/world/listener/BlockListener.java index 6f98eb3..ff5fada 100644 --- a/WorldSystem/src/de/butzlabben/world/listener/BlockListener.java +++ b/WorldSystem/src/de/butzlabben/world/listener/BlockListener.java @@ -2,9 +2,6 @@ package de.butzlabben.world.listener; import java.io.File; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -14,20 +11,18 @@ import org.bukkit.event.block.BlockIgniteEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.EntityExplodeEvent; +import de.butzlabben.world.config.WorldConfig; import de.butzlabben.world.wrapper.WorldPlayer; public class BlockListener implements Listener { @EventHandler public void onExplode(EntityExplodeEvent e) { - World w = e.getLocation().getWorld(); - File file = new File(Bukkit.getWorldContainer(), w.getName() + "/worldconfig.yml"); - if (file.exists()) { - e.setCancelled(true); - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); - boolean b = cfg.getBoolean("Settings.TNTDamage"); - e.setCancelled(!b); - } + File file = WorldConfig.getWorldFile(e.getLocation().getWorld().getName()); + if(!file.exists()) + return; + WorldConfig wc = WorldConfig.getWorldConfig(e.getLocation().getWorld().getName()); + e.setCancelled(!wc.isTnt()); } @EventHandler @@ -39,12 +34,10 @@ public class BlockListener implements Listener { WorldPlayer wp = new WorldPlayer(p, worldname); if (!wp.isOnSystemWorld()) return; + if(!wp.isMember()) + return; if (!wp.isOwnerofWorld()) { - File file = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); - String uuid = p.getUniqueId().toString(); - boolean b = cfg.getBoolean("Members." + uuid + ".Permissions.CanBuild"); - e.setCancelled(!b); + e.setCancelled(!wp.canBuild()); } } @@ -57,33 +50,27 @@ public class BlockListener implements Listener { WorldPlayer wp = new WorldPlayer(p, worldname); if (!wp.isOnSystemWorld()) return; + if(!wp.isMember()) + return; if (!wp.isOwnerofWorld()) { - File file = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); - String uuid = p.getUniqueId().toString(); - boolean b = cfg.getBoolean("Members." + uuid + ".Permissions.CanBuild"); - e.setCancelled(!b); + e.setCancelled(!wp.canBuild()); } } @EventHandler public void onFire(BlockIgniteEvent e) { - World w = e.getBlock().getWorld(); - File file = new File(Bukkit.getWorldContainer(), w.getName() + "/worldconfig.yml"); - if (file.exists()) { - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); - boolean b = cfg.getBoolean("Settings.Fire"); - e.setCancelled(!b); - } + File file = WorldConfig.getWorldFile(e.getBlock().getWorld().getName()); + if(!file.exists()) + return; + WorldConfig wc = WorldConfig.getWorldConfig(e.getBlock().getWorld().getName()); + e.setCancelled(!wc.isFire()); } @EventHandler public void onFire(BlockBurnEvent e) { - World w = e.getBlock().getWorld(); - File file = new File(Bukkit.getWorldContainer(), w.getName() + "/worldconfig.yml"); - if (file.exists()) { - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); - boolean b = cfg.getBoolean("Settings.Fire"); - e.setCancelled(!b); - } + File file = WorldConfig.getWorldFile(e.getBlock().getWorld().getName()); + if(!file.exists()) + return; + WorldConfig wc = WorldConfig.getWorldConfig(e.getBlock().getWorld().getName()); + e.setCancelled(!wc.isFire()); } } diff --git a/WorldSystem/src/de/butzlabben/world/wrapper/AsyncCreatorAdapter.java b/WorldSystem/src/de/butzlabben/world/wrapper/AsyncCreatorAdapter.java new file mode 100644 index 0000000..4018eb2 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/wrapper/AsyncCreatorAdapter.java @@ -0,0 +1,37 @@ +package de.butzlabben.world.wrapper; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.WorldCreator; +import org.bukkit.block.Block; + +import com.boydti.fawe.bukkit.wrapper.AsyncWorld; +import com.boydti.fawe.util.TaskManager; + +/** + * @author Butzlabben + * @since 08.06.2018 + */ +public class AsyncCreatorAdapter implements CreatorAdapter{ + + // Create worlds async to close #16 + @Override + public void create(WorldCreator creator) { + TaskManager.IMP.async(new Runnable() { + @Override + public void run() { + // Create or load a world async with the provided WorldCreator settings + AsyncWorld world = AsyncWorld.create(creator); + // AsyncWorld world = AsyncWorld.wrap(bukkitWorld); // Or wrap existing world + Block block = world.getBlockAt(0, 0, 0); + block.setType(Material.BEDROCK); + // When you are done + world.commit(); + + Bukkit.getWorlds().add(world); + } + }); + return; + } + +} diff --git a/WorldSystem/src/de/butzlabben/world/wrapper/CreatorAdapter.java b/WorldSystem/src/de/butzlabben/world/wrapper/CreatorAdapter.java new file mode 100644 index 0000000..e201362 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/wrapper/CreatorAdapter.java @@ -0,0 +1,12 @@ +package de.butzlabben.world.wrapper; + +import org.bukkit.WorldCreator; + +/** + * @author Butzlabben + * @since 07.06.2018 + */ +public interface CreatorAdapter { + + public void create(WorldCreator creator); +} diff --git a/WorldSystem/src/de/butzlabben/world/wrapper/SystemWorld.java b/WorldSystem/src/de/butzlabben/world/wrapper/SystemWorld.java index 4006181..54df214 100644 --- a/WorldSystem/src/de/butzlabben/world/wrapper/SystemWorld.java +++ b/WorldSystem/src/de/butzlabben/world/wrapper/SystemWorld.java @@ -212,8 +212,9 @@ public class SystemWorld { world.renameTo(new File(Bukkit.getWorldContainer(), myName.toString())); worldname = myName.toString(); } - // Teleport the Player - + // For #16 + WorldSystem.creator.create(new WorldCreator(worldname)); + World worldinserver = Bukkit.createWorld(new WorldCreator(worldname)); Bukkit.getServer().getWorlds().add(worldinserver); w = worldinserver; @@ -307,9 +308,11 @@ public class SystemWorld { e.printStackTrace(); } } - World worldinserver = Bukkit.createWorld(event.getWorldCreator()); - Bukkit.getServer().getWorlds().add(worldinserver); - + //For #16 + WorldSystem.creator.create(event.getWorldCreator()); + +// World worldinserver = Bukkit.createWorld(event.getWorldCreator()); +// Bukkit.getServer().getWorlds().add(worldinserver); } return true; } diff --git a/WorldSystem/src/plugin.yml b/WorldSystem/src/plugin.yml index f278f33..3691ebd 100644 --- a/WorldSystem/src/plugin.yml +++ b/WorldSystem/src/plugin.yml @@ -1,7 +1,8 @@ name: WorldSystem -version: 2.1.2 +version: 2.1.2.2 author: Butzlabben main: de.butzlabben.world.WorldSystem +loadbefore: [FastAsyncWorldEdit, WorldEdit] commands: ws: