From 79bd24a75a6bcd9cc56b1eb6cf4832e7e2c5f15b Mon Sep 17 00:00:00 2001 From: Butzlabben Date: Sun, 16 Dec 2018 14:13:47 +0100 Subject: [PATCH] 2.4.0.3: Multi world choose, bug fix on /ws tp --- WorldSystem/.classpath | 28 ++++- .../org.eclipse.core.resources.prefs | 5 + .../.settings/org.eclipse.jdt.core.prefs | 1 + WorldSystem/pom.xml | 2 +- .../butzlabben/autoupdater/AutoUpdater.java | 16 +-- .../de/butzlabben/inventory/CostumInv.java | 6 +- .../de/butzlabben/inventory/OrcInventory.java | 11 ++ .../java/de/butzlabben/inventory/OrcItem.java | 4 +- .../java/de/butzlabben/world/WorldSystem.java | 3 +- .../world/command/WSAddmemberCommand.java | 2 +- .../world/command/WSConfirmCommand.java | 4 +- .../world/command/WSDelmemberCommand.java | 2 +- .../world/command/WSFireCommand.java | 2 +- .../world/command/WSGetCommand.java | 38 +++++- .../world/command/WSLeaveCommand.java | 4 +- .../world/command/WSResetCommand.java | 113 +++++++++++------- .../butzlabben/world/command/WSTPCommand.java | 4 + .../world/command/WSTnTCommand.java | 2 +- .../world/command/WSToggleBuildCommand.java | 2 +- .../world/command/WSToggleGMCommand.java | 2 +- .../world/command/WSToggleTPCommand.java | 2 +- .../world/config/DependenceConfig.java | 2 +- .../de/butzlabben/world/config/GuiConfig.java | 9 ++ .../world/config/MessageConfig.java | 104 ++++++++-------- .../butzlabben/world/config/PluginConfig.java | 30 +++-- .../world/gui/PlayerOptionsGUI.java | 2 +- .../butzlabben/world/gui/WorldChooseGUI.java | 70 +++++++++++ .../butzlabben/world/gui/WorldOptionsGUI.java | 2 +- .../butzlabben/world/gui/WorldSystemGUI.java | 4 +- .../butzlabben/world/wrapper/SystemWorld.java | 106 ++++++++-------- .../world/wrapper/WorldTemplate.java | 42 +++++++ .../world/wrapper/WorldTemplateProvider.java | 39 ++++++ WorldSystem/src/main/resources/1_13_gui.yml | 43 ++++++- WorldSystem/src/main/resources/config.yml | 15 ++- WorldSystem/src/main/resources/old_gui.yml | 41 ++++++- 35 files changed, 560 insertions(+), 202 deletions(-) create mode 100644 WorldSystem/src/main/java/de/butzlabben/world/gui/WorldChooseGUI.java create mode 100644 WorldSystem/src/main/java/de/butzlabben/world/wrapper/WorldTemplate.java create mode 100644 WorldSystem/src/main/java/de/butzlabben/world/wrapper/WorldTemplateProvider.java diff --git a/WorldSystem/.classpath b/WorldSystem/.classpath index f4288c0..047ca44 100644 --- a/WorldSystem/.classpath +++ b/WorldSystem/.classpath @@ -5,10 +5,30 @@ - - - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/WorldSystem/.settings/org.eclipse.core.resources.prefs b/WorldSystem/.settings/org.eclipse.core.resources.prefs index 715c459..b6b9453 100644 --- a/WorldSystem/.settings/org.eclipse.core.resources.prefs +++ b/WorldSystem/.settings/org.eclipse.core.resources.prefs @@ -1,7 +1,12 @@ eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 encoding//src/main/java/de/butzlabben/world/WorldSystem.java=UTF-8 encoding//src/main/java/de/butzlabben/world/command/WSCommand.java=UTF-8 encoding//src/main/java/de/butzlabben/world/config/GuiConfig.java=Cp1252 encoding//src/main/java/de/butzlabben/world/config/PluginConfig.java=Cp1252 encoding//src/main/java/de/butzlabben/world/gui/clicklistener/ComingSoonClickListener.java=Cp1252 encoding//src/main/java/de/butzlabben/world/wrapper/SystemWorld.java=Cp1252 +encoding//src/main/resources=UTF-8 +encoding//src/test/java=UTF-8 +encoding//src/test/resources=UTF-8 +encoding/=UTF-8 diff --git a/WorldSystem/.settings/org.eclipse.jdt.core.prefs b/WorldSystem/.settings/org.eclipse.jdt.core.prefs index df46a9a..e24b722 100644 --- a/WorldSystem/.settings/org.eclipse.jdt.core.prefs +++ b/WorldSystem/.settings/org.eclipse.jdt.core.prefs @@ -9,4 +9,5 @@ org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.source=1.8 diff --git a/WorldSystem/pom.xml b/WorldSystem/pom.xml index 7921370..fcc39dc 100644 --- a/WorldSystem/pom.xml +++ b/WorldSystem/pom.xml @@ -3,7 +3,7 @@ 4.0.0 de.butzlabben.world WorldSystem - 2.4.0.3-Dev + 2.4.0.3 UTF-8 - diff --git a/WorldSystem/src/main/java/de/butzlabben/autoupdater/AutoUpdater.java b/WorldSystem/src/main/java/de/butzlabben/autoupdater/AutoUpdater.java index 3447d98..9f04dc1 100644 --- a/WorldSystem/src/main/java/de/butzlabben/autoupdater/AutoUpdater.java +++ b/WorldSystem/src/main/java/de/butzlabben/autoupdater/AutoUpdater.java @@ -44,7 +44,7 @@ public class AutoUpdater implements Listener { confirmNeed = PluginConfig.confirmNeed(); UpdateInformations ui = UpdateInformations.getInformations(); if (ui == null) { - Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "§cCouldn't contact autoupdate server"); + Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "§cCouldn't contact autoupdate server"); return; } Plugin plugin = Bukkit.getPluginManager().getPlugin(ui.getPlugin()); @@ -83,18 +83,18 @@ public class AutoUpdater implements Listener { Runtime.getRuntime().addShutdownHook(new Thread(au)); if (!ui.isSilent()) Bukkit.getConsoleSender().sendMessage( - PluginConfig.getPrefix() + "§aAutoupdate confirmed, §crestart §ato apply changes"); + PluginConfig.getPrefix() + "§aAutoupdate confirmed, §crestart §ato apply changes"); confirmed = true; } else { Bukkit.getPluginManager().registerEvents(this, plugin); for (Player p : Bukkit.getOnlinePlayers()) { p.sendMessage( - PluginConfig.getPrefix() + "§aFound new update. Confirm autoupdate with §c/ws confirm"); - p.sendMessage(PluginConfig.getPrefix() + "§aRead changelogs: https://www.spigotmc.org/resources/49756/updates"); + PluginConfig.getPrefix() + "§aFound new update. Confirm autoupdate with §c/ws confirm"); + p.sendMessage(PluginConfig.getPrefix() + "§aRead changelogs: https://www.spigotmc.org/resources/49756/updates"); } Bukkit.getConsoleSender().sendMessage( - PluginConfig.getPrefix() + "§aFound new update. Confirm autoupdate with §c/ws confirm"); - Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "§aRead changelogs: https://www.spigotmc.org/resources/49756/updates"); + PluginConfig.getPrefix() + "§aFound new update. Confirm autoupdate with §c/ws confirm"); + Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "§aRead changelogs: https://www.spigotmc.org/resources/49756/updates"); } } else { confirmNeed = false; @@ -105,8 +105,8 @@ public class AutoUpdater implements Listener { public void on(PlayerJoinEvent e) { if (e.getPlayer().hasPermission("ws.confirm")) { e.getPlayer().sendMessage( - PluginConfig.getPrefix() + "§aFound new update. Confirm autoupdate with §c/ws confirm"); - e.getPlayer().sendMessage(PluginConfig.getPrefix() + "§aRead changelogs: https://www.spigotmc.org/resources/49756/updates"); + PluginConfig.getPrefix() + "§aFound new update. Confirm autoupdate with §c/ws confirm"); + e.getPlayer().sendMessage(PluginConfig.getPrefix() + "§aRead changelogs: https://www.spigotmc.org/resources/49756/updates"); } } diff --git a/WorldSystem/src/main/java/de/butzlabben/inventory/CostumInv.java b/WorldSystem/src/main/java/de/butzlabben/inventory/CostumInv.java index 5a0d143..eea73bd 100644 --- a/WorldSystem/src/main/java/de/butzlabben/inventory/CostumInv.java +++ b/WorldSystem/src/main/java/de/butzlabben/inventory/CostumInv.java @@ -4,9 +4,13 @@ package de.butzlabben.inventory; * @author Butzlabben * @since 28.06.2018 */ -public class CostumInv extends OrcInventory{ +public class CostumInv extends OrcInventory { public CostumInv(String title, int rows) { super(title, rows); } + + public CostumInv(String title, int rows, boolean fill) { + super(title, rows, fill); + } } diff --git a/WorldSystem/src/main/java/de/butzlabben/inventory/OrcInventory.java b/WorldSystem/src/main/java/de/butzlabben/inventory/OrcInventory.java index de26275..784d781 100644 --- a/WorldSystem/src/main/java/de/butzlabben/inventory/OrcInventory.java +++ b/WorldSystem/src/main/java/de/butzlabben/inventory/OrcInventory.java @@ -14,6 +14,7 @@ public abstract class OrcInventory { protected String title; private int rows; private InventoryType type; + private boolean fill = false; protected HashMap items = new HashMap<>(); @@ -28,6 +29,16 @@ public abstract class OrcInventory { throw new IllegalArgumentException("rows cannot be smaller than 1 or bigger than 6"); this.rows = rows; } + + public OrcInventory(String title, int rows, boolean fill) { + this(title, rows); + this.fill = fill; + if(this.fill) { + for (int i = 0; i < rows * 9; i++) { + items.put(i, OrcItem.fill); + } + } + } public OrcInventory(String title, InventoryType type) { this(title); diff --git a/WorldSystem/src/main/java/de/butzlabben/inventory/OrcItem.java b/WorldSystem/src/main/java/de/butzlabben/inventory/OrcItem.java index 5ecf546..50d6c89 100644 --- a/WorldSystem/src/main/java/de/butzlabben/inventory/OrcItem.java +++ b/WorldSystem/src/main/java/de/butzlabben/inventory/OrcItem.java @@ -15,8 +15,8 @@ import de.butzlabben.world.wrapper.WorldPlayer; public class OrcItem { - public static OrcItem enabled, disabled, coming_soon, back, error = new OrcItem(Material.BARRIER, null, - "§cERROR: Item is wrong configured!", "§cPath in config: see Displayname"); + public static OrcItem enabled, disabled, coming_soon, back, fill, error = new OrcItem(Material.BARRIER, null, + "§cERROR: Item is wrong configured!", "§cPath in config: see Displayname"); private ItemStack is; private OrcClickListener listener; diff --git a/WorldSystem/src/main/java/de/butzlabben/world/WorldSystem.java b/WorldSystem/src/main/java/de/butzlabben/world/WorldSystem.java index 1e5f3c2..1f714bb 100644 --- a/WorldSystem/src/main/java/de/butzlabben/world/WorldSystem.java +++ b/WorldSystem/src/main/java/de/butzlabben/world/WorldSystem.java @@ -29,7 +29,6 @@ import de.butzlabben.world.command.WSToggleBuildCommand; import de.butzlabben.world.command.WSToggleGMCommand; import de.butzlabben.world.command.WSToggleTPCommand; import de.butzlabben.world.config.DependenceConfig; -import de.butzlabben.world.config.Entry; import de.butzlabben.world.config.GuiConfig; import de.butzlabben.world.config.MessageConfig; import de.butzlabben.world.config.PluginConfig; @@ -122,7 +121,7 @@ public class WorldSystem extends JavaPlugin { System.setProperty("bstats.relocatecheck", "false"); Metrics m = new Metrics(this); - m.addCustomChart(new Metrics.SingleLineChart("worlds", Entry::entrys)); + m.addCustomChart(new Metrics.SingleLineChart("worlds", DependenceConfig::getHighestID)); AutoUpdater.startAsync(); diff --git a/WorldSystem/src/main/java/de/butzlabben/world/command/WSAddmemberCommand.java b/WorldSystem/src/main/java/de/butzlabben/world/command/WSAddmemberCommand.java index 31e4200..8775770 100644 --- a/WorldSystem/src/main/java/de/butzlabben/world/command/WSAddmemberCommand.java +++ b/WorldSystem/src/main/java/de/butzlabben/world/command/WSAddmemberCommand.java @@ -52,7 +52,7 @@ public class WSAddmemberCommand implements CommandExecutor{ try { wc.save(); } catch (IOException e) { - p.sendMessage(PluginConfig.getPrefix() + "§cSomething went wrong"); + p.sendMessage(PluginConfig.getPrefix() + "§cSomething went wrong"); e.printStackTrace(); } p.sendMessage(MessageConfig.getMemberAdded().replaceAll("%player", a.getName())); diff --git a/WorldSystem/src/main/java/de/butzlabben/world/command/WSConfirmCommand.java b/WorldSystem/src/main/java/de/butzlabben/world/command/WSConfirmCommand.java index 87acb06..c94df61 100644 --- a/WorldSystem/src/main/java/de/butzlabben/world/command/WSConfirmCommand.java +++ b/WorldSystem/src/main/java/de/butzlabben/world/command/WSConfirmCommand.java @@ -16,11 +16,11 @@ public class WSConfirmCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) { if (AutoUpdater.getInstance().confirmed()) { - cs.sendMessage(PluginConfig.getPrefix() + "§cAlready confirmed or no confirm needed"); + cs.sendMessage(PluginConfig.getPrefix() + "§cAlready confirmed or no confirm needed"); return true; } AutoUpdater.getInstance().confirm(); - cs.sendMessage(PluginConfig.getPrefix() + "§aAutoupdate confirmed, §crestart §ato apply changes"); + cs.sendMessage(PluginConfig.getPrefix() + "§aAutoupdate confirmed, §crestart §ato apply changes"); return true; } } diff --git a/WorldSystem/src/main/java/de/butzlabben/world/command/WSDelmemberCommand.java b/WorldSystem/src/main/java/de/butzlabben/world/command/WSDelmemberCommand.java index a6dcb9c..4f7ce24 100644 --- a/WorldSystem/src/main/java/de/butzlabben/world/command/WSDelmemberCommand.java +++ b/WorldSystem/src/main/java/de/butzlabben/world/command/WSDelmemberCommand.java @@ -59,7 +59,7 @@ public class WSDelmemberCommand implements CommandExecutor { try { wc.save(); } catch (IOException e) { - p.sendMessage(PluginConfig.getPrefix() + "§cSomething went wrong"); + p.sendMessage(PluginConfig.getPrefix() + "§cSomething went wrong"); e.printStackTrace(); } p.sendMessage(MessageConfig.getMemberRemoved().replaceAll("%player", a.getName())); diff --git a/WorldSystem/src/main/java/de/butzlabben/world/command/WSFireCommand.java b/WorldSystem/src/main/java/de/butzlabben/world/command/WSFireCommand.java index b247be9..897ede8 100644 --- a/WorldSystem/src/main/java/de/butzlabben/world/command/WSFireCommand.java +++ b/WorldSystem/src/main/java/de/butzlabben/world/command/WSFireCommand.java @@ -38,7 +38,7 @@ public class WSFireCommand implements CommandExecutor { try { wc.save(); } catch (IOException e) { - p.sendMessage(PluginConfig.getPrefix() + "§cSomething went wrong"); + p.sendMessage(PluginConfig.getPrefix() + "§cSomething went wrong"); e.printStackTrace(); } fire = wc.isFire(); diff --git a/WorldSystem/src/main/java/de/butzlabben/world/command/WSGetCommand.java b/WorldSystem/src/main/java/de/butzlabben/world/command/WSGetCommand.java index b3df24c..3ba61cb 100644 --- a/WorldSystem/src/main/java/de/butzlabben/world/command/WSGetCommand.java +++ b/WorldSystem/src/main/java/de/butzlabben/world/command/WSGetCommand.java @@ -9,14 +9,19 @@ import org.bukkit.entity.Player; 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.gui.WorldChooseGUI; import de.butzlabben.world.wrapper.SystemWorld; +import de.butzlabben.world.wrapper.WorldTemplate; +import de.butzlabben.world.wrapper.WorldTemplateProvider; public class WSGetCommand implements CommandExecutor { @Override - public boolean onCommand(CommandSender cs, Command arg1, String arg2, String[] arg3) { + public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) { if (!(cs instanceof Player)) return true; + Player p = (Player) cs; // create New Entry DependenceConfig dc = new DependenceConfig(p); @@ -24,11 +29,34 @@ public class WSGetCommand implements CommandExecutor { p.sendMessage(MessageConfig.getWorldAlreadyExists()); return true; } - Bukkit.getScheduler().runTask(WorldSystem.getInstance(), () -> { - if (SystemWorld.create(p)) - p.sendMessage(MessageConfig.getSettingUpWorld()); - }); + + if (PluginConfig.isMultiChoose()) { + if (args.length >= 2) { + String key = args[1]; + WorldTemplate template = WorldTemplateProvider.getInstace().getTemplate(key); + if (template != null) { + create(p, template); + return true; + } + } + p.openInventory(new WorldChooseGUI().getInventory(p)); + } else { + WorldTemplate template = WorldTemplateProvider.getInstace() + .getTemplate(PluginConfig.getDefaultWorldTemplate()); + if(template != null) + create(p, template); + else { + p.sendMessage(PluginConfig.getPrefix() + "§cError in config at \"worldtemplates.default\""); + p.sendMessage(PluginConfig.getPrefix() + "§cPlease contact an administrator"); + } + } return true; } + private void create(Player p, WorldTemplate template) { + Bukkit.getScheduler().runTask(WorldSystem.getInstance(), () -> { + if (SystemWorld.create(p, template)) + p.sendMessage(MessageConfig.getSettingUpWorld()); + }); + } } diff --git a/WorldSystem/src/main/java/de/butzlabben/world/command/WSLeaveCommand.java b/WorldSystem/src/main/java/de/butzlabben/world/command/WSLeaveCommand.java index 69345e8..397a4ff 100644 --- a/WorldSystem/src/main/java/de/butzlabben/world/command/WSLeaveCommand.java +++ b/WorldSystem/src/main/java/de/butzlabben/world/command/WSLeaveCommand.java @@ -31,8 +31,8 @@ public class WSLeaveCommand implements CommandExecutor { if (wp.isOnSystemWorld()) { // Extra safety for #2 if (PluginConfig.getSpawn().getWorld() == null) { - Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "§cThe spawn is not properly set"); - cs.sendMessage(PluginConfig.getPrefix() + "§cThe spawn is not properly set"); + Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "§cThe spawn is not properly set"); + cs.sendMessage(PluginConfig.getPrefix() + "§cThe spawn is not properly set"); return true; } diff --git a/WorldSystem/src/main/java/de/butzlabben/world/command/WSResetCommand.java b/WorldSystem/src/main/java/de/butzlabben/world/command/WSResetCommand.java index dcf29eb..bd984fd 100644 --- a/WorldSystem/src/main/java/de/butzlabben/world/command/WSResetCommand.java +++ b/WorldSystem/src/main/java/de/butzlabben/world/command/WSResetCommand.java @@ -20,7 +20,10 @@ import de.butzlabben.world.config.MessageConfig; import de.butzlabben.world.config.PluginConfig; import de.butzlabben.world.config.WorldConfig; import de.butzlabben.world.event.WorldResetEvent; +import de.butzlabben.world.gui.WorldChooseGUI; import de.butzlabben.world.wrapper.SystemWorld; +import de.butzlabben.world.wrapper.WorldTemplate; +import de.butzlabben.world.wrapper.WorldTemplateProvider; public class WSResetCommand implements CommandExecutor { @@ -61,51 +64,26 @@ public class WSResetCommand implements CommandExecutor { } File f = new File(PluginConfig.getWorlddir() + "/" + worldname); - File[] files = f.listFiles(); - for (File file : files) { - if (file.getName().equals("worldconfig.yml")) - continue; - FileUtils.deleteQuietly(file); - } - File exampleworld = new File( - "plugins//WorldSystem//worldsources//" + PluginConfig.getExampleWorldName()); - try { - FileUtils.copyDirectory(exampleworld, f); - toConfirm.remove(p); - - FileUtils.moveDirectoryToDirectory(f, Bukkit.getWorldContainer(), false); - - WorldConfig config = WorldConfig.getWorldConfig(worldname); - config.setHome(null); - config.save(); - - p.sendMessage(MessageConfig.getWorldReseted()); - - // For fast worldcreating after reset - WorldCreator creator = new WorldCreator(worldname); - long seed = PluginConfig.getSeed(); - Environment env = PluginConfig.getEnvironment(); - WorldType type = PluginConfig.getWorldType(); - if (seed != 0) - creator.seed(seed); - creator.type(type); - creator.environment(env); - String generator = PluginConfig.getGenerator(); - if (!generator.trim().isEmpty()) - creator.generator(generator); - - sw.setCreating(true); - // For #16 - WorldSystem.getInstance().getAdapter().create(creator, sw, () -> { - if (p != null && p.isOnline()) - p.sendMessage(MessageConfig.getWorldCreated()); + if (!PluginConfig.isMultiChoose()) { + WorldTemplate template = WorldTemplateProvider.getInstace() + .getTemplate(PluginConfig.getDefaultWorldTemplate()); + if (template != null) + createWorld(p, worldname, f, new File(template.getPath()), sw); + else { + p.sendMessage(PluginConfig.getPrefix() + "§cError in config at \"worldtemplates.default\""); + p.sendMessage(PluginConfig.getPrefix() + "§cPlease contact an administrator"); + } + } else { + WorldChooseGUI.letChoose(p, (template) -> { + if (template != null) + createWorld(p, worldname, f, new File(template.getPath()), sw); + else { + p.sendMessage(PluginConfig.getPrefix() + "§cError in config at \"worldtemplates.default\""); + p.sendMessage(PluginConfig.getPrefix() + "§cPlease contact an administrator"); + } }); - - } catch (IOException e) { - e.printStackTrace(); - p.sendMessage(MessageConfig.getUnknownError()); - System.err.println("Couldn't reset world of " + p.getName()); } + } else { p.sendMessage(MessageConfig.getInvalidInput().replaceAll("input", args[0])); return true; @@ -132,4 +110,53 @@ public class WSResetCommand implements CommandExecutor { } return true; } + + private void createWorld(Player p, String worldname, File f, File exampleworld, SystemWorld sw) { + + File[] files = f.listFiles(); + for (File file : files) { + if (file.getName().equals("worldconfig.yml")) + continue; + FileUtils.deleteQuietly(file); + } + + try { + if (exampleworld.isDirectory()) + FileUtils.copyDirectory(exampleworld, f); + toConfirm.remove(p); + + FileUtils.moveDirectoryToDirectory(f, Bukkit.getWorldContainer(), false); + + WorldConfig config = WorldConfig.getWorldConfig(worldname); + config.setHome(null); + config.save(); + + p.sendMessage(MessageConfig.getWorldReseted()); + + // For fast worldcreating after reset + WorldCreator creator = new WorldCreator(worldname); + long seed = PluginConfig.getSeed(); + Environment env = PluginConfig.getEnvironment(); + WorldType type = PluginConfig.getWorldType(); + if (seed != 0) + creator.seed(seed); + creator.type(type); + creator.environment(env); + String generator = PluginConfig.getGenerator(); + if (!generator.trim().isEmpty()) + creator.generator(generator); + + sw.setCreating(true); + // For #16 + WorldSystem.getInstance().getAdapter().create(creator, sw, () -> { + if (p != null && p.isOnline()) + p.sendMessage(MessageConfig.getWorldCreated()); + }); + + } catch (IOException e) { + e.printStackTrace(); + p.sendMessage(MessageConfig.getUnknownError()); + System.err.println("Couldn't reset world of " + p.getName()); + } + } } diff --git a/WorldSystem/src/main/java/de/butzlabben/world/command/WSTPCommand.java b/WorldSystem/src/main/java/de/butzlabben/world/command/WSTPCommand.java index b1e619b..ad8b519 100644 --- a/WorldSystem/src/main/java/de/butzlabben/world/command/WSTPCommand.java +++ b/WorldSystem/src/main/java/de/butzlabben/world/command/WSTPCommand.java @@ -24,10 +24,14 @@ public class WSTPCommand implements CommandExecutor { WorldSystem.getInstance().getCommand("ws tp").getUsage())); return true; } + + // There where some problems with /ws tp if(args[1].equalsIgnoreCase(p.getName()) || args[1].equalsIgnoreCase(p.getUniqueId().toString())) { p.chat("/ws home"); return true; } + + DependenceConfig dc = new DependenceConfig(args[1]); String worldname = dc.getWorldNamebyOfflinePlayer(); if (!dc.hasWorld()) { diff --git a/WorldSystem/src/main/java/de/butzlabben/world/command/WSTnTCommand.java b/WorldSystem/src/main/java/de/butzlabben/world/command/WSTnTCommand.java index f812ba3..0d7a8a5 100644 --- a/WorldSystem/src/main/java/de/butzlabben/world/command/WSTnTCommand.java +++ b/WorldSystem/src/main/java/de/butzlabben/world/command/WSTnTCommand.java @@ -38,7 +38,7 @@ public class WSTnTCommand implements CommandExecutor { try { wc.save(); } catch (IOException e) { - p.sendMessage(PluginConfig.getPrefix() + "§cSomething went wrong"); + p.sendMessage(PluginConfig.getPrefix() + "§cSomething went wrong"); e.printStackTrace(); } tnt = wc.isTnt(); diff --git a/WorldSystem/src/main/java/de/butzlabben/world/command/WSToggleBuildCommand.java b/WorldSystem/src/main/java/de/butzlabben/world/command/WSToggleBuildCommand.java index 18b3ed8..57b3053 100644 --- a/WorldSystem/src/main/java/de/butzlabben/world/command/WSToggleBuildCommand.java +++ b/WorldSystem/src/main/java/de/butzlabben/world/command/WSToggleBuildCommand.java @@ -40,7 +40,7 @@ public class WSToggleBuildCommand implements CommandExecutor { } WorldPlayer wp = new WorldPlayer(a, dc.getWorldname()); if (wp.isOwnerofWorld()) { - p.sendMessage(PluginConfig.getPrefix() + "§cYou are the owner"); + p.sendMessage(PluginConfig.getPrefix() + "§cYou are the owner"); return true; } if (wp.toggleBuild()) { diff --git a/WorldSystem/src/main/java/de/butzlabben/world/command/WSToggleGMCommand.java b/WorldSystem/src/main/java/de/butzlabben/world/command/WSToggleGMCommand.java index f43b2a3..70ece52 100644 --- a/WorldSystem/src/main/java/de/butzlabben/world/command/WSToggleGMCommand.java +++ b/WorldSystem/src/main/java/de/butzlabben/world/command/WSToggleGMCommand.java @@ -40,7 +40,7 @@ public class WSToggleGMCommand implements CommandExecutor { } WorldPlayer wp = new WorldPlayer(a, dc.getWorldname()); if (wp.isOwnerofWorld()) { - p.sendMessage(PluginConfig.getPrefix() + "§cYou are the owner"); + p.sendMessage(PluginConfig.getPrefix() + "§cYou are the owner"); return true; } if (wp.toggleGamemode()) { diff --git a/WorldSystem/src/main/java/de/butzlabben/world/command/WSToggleTPCommand.java b/WorldSystem/src/main/java/de/butzlabben/world/command/WSToggleTPCommand.java index 6d6dcd7..70e140c 100644 --- a/WorldSystem/src/main/java/de/butzlabben/world/command/WSToggleTPCommand.java +++ b/WorldSystem/src/main/java/de/butzlabben/world/command/WSToggleTPCommand.java @@ -40,7 +40,7 @@ public class WSToggleTPCommand implements CommandExecutor { } WorldPlayer wp = new WorldPlayer(a, dc.getWorldname()); if (wp.isOwnerofWorld()) { - p.sendMessage(PluginConfig.getPrefix() + "§cYou are the owner"); + p.sendMessage(PluginConfig.getPrefix() + "§cYou are the owner"); return true; } if (wp.toggleTeleport()) { diff --git a/WorldSystem/src/main/java/de/butzlabben/world/config/DependenceConfig.java b/WorldSystem/src/main/java/de/butzlabben/world/config/DependenceConfig.java index 1ff74d7..09d602a 100644 --- a/WorldSystem/src/main/java/de/butzlabben/world/config/DependenceConfig.java +++ b/WorldSystem/src/main/java/de/butzlabben/world/config/DependenceConfig.java @@ -125,7 +125,7 @@ public class DependenceConfig { } } - public int getHighestID() { + public static int getHighestID() { File dconfig = new File("plugins//WorldSystem//dependence.yml"); YamlConfiguration dcfg = YamlConfiguration.loadConfiguration(dconfig); return dcfg.getInt("HighestID"); diff --git a/WorldSystem/src/main/java/de/butzlabben/world/config/GuiConfig.java b/WorldSystem/src/main/java/de/butzlabben/world/config/GuiConfig.java index e6987d4..b7cd04b 100644 --- a/WorldSystem/src/main/java/de/butzlabben/world/config/GuiConfig.java +++ b/WorldSystem/src/main/java/de/butzlabben/world/config/GuiConfig.java @@ -49,6 +49,7 @@ public class GuiConfig { OrcItem.disabled = getDisabled(); OrcItem.coming_soon = getComingSoon(); OrcItem.back = getBack(); + OrcItem.fill = getFill(); } public static YamlConfiguration getConfig() { @@ -137,6 +138,14 @@ public class GuiConfig { private static OrcItem getBack() { return getItem("options.back"); } + + private static OrcItem getFill() { + return getItem("options.fill"); + } + + public static boolean isFill(String path) { + return getConfig().getBoolean(path + ".fill"); + } public static Material getSkullItem() { return getMaterial(getConfig(), "options.players.playerhead"); diff --git a/WorldSystem/src/main/java/de/butzlabben/world/config/MessageConfig.java b/WorldSystem/src/main/java/de/butzlabben/world/config/MessageConfig.java index 3f5778c..24fd4d1 100644 --- a/WorldSystem/src/main/java/de/butzlabben/world/config/MessageConfig.java +++ b/WorldSystem/src/main/java/de/butzlabben/world/config/MessageConfig.java @@ -25,19 +25,19 @@ public class MessageConfig { private static List defaultCmdHelp = new ArrayList<>(20); { - defaultCmdHelp.add("/ws get §8- §7Will give you a World"); - defaultCmdHelp.add("/ws home §8- §7Teleports you on your World"); - defaultCmdHelp.add("/ws sethome §8- §7Sets a specific home"); - defaultCmdHelp.add("/ws tp §8- §7Teleports you on a specific World"); - defaultCmdHelp.add("/ws addmember §8- §7Adds a player to your World"); - defaultCmdHelp.add("/ws delmember§8 - §7Removes a player from your World"); - defaultCmdHelp.add("/ws tnt §8- §7Allows/Denys TNT on your World"); - defaultCmdHelp.add("/ws fire §8- §7Allows/Denys Fire on your World"); - defaultCmdHelp.add("/ws togglechgm §8- §7Allows/Denys a player changing gamemode"); - defaultCmdHelp.add("/ws togglebuild §8- §7Allows/Denys a player building"); - defaultCmdHelp.add("/ws toggletp §8- §7Allows/Denys a player teleporting"); - defaultCmdHelp.add("/ws info §8- §7Shows information about the World"); - defaultCmdHelp.add("/ws reset §8- §7Will reset your World"); + defaultCmdHelp.add("/ws get §8- §7Will give you a World"); + defaultCmdHelp.add("/ws home §8- §7Teleports you on your World"); + defaultCmdHelp.add("/ws sethome §8- §7Sets a specific home"); + defaultCmdHelp.add("/ws tp §8- §7Teleports you on a specific World"); + defaultCmdHelp.add("/ws addmember §8- §7Adds a player to your World"); + defaultCmdHelp.add("/ws delmember§8 - §7Removes a player from your World"); + defaultCmdHelp.add("/ws tnt §8- §7Allows/Denys TNT on your World"); + defaultCmdHelp.add("/ws fire §8- §7Allows/Denys Fire on your World"); + defaultCmdHelp.add("/ws togglechgm §8- §7Allows/Denys a player changing gamemode"); + defaultCmdHelp.add("/ws togglebuild §8- §7Allows/Denys a player building"); + defaultCmdHelp.add("/ws toggletp §8- §7Allows/Denys a player teleporting"); + defaultCmdHelp.add("/ws info §8- §7Shows information about the World"); + defaultCmdHelp.add("/ws reset §8- §7Will reset your World"); } private static File file; @@ -78,11 +78,11 @@ public class MessageConfig { } public static String getNoPermission() { - return getMessage("nopermission", "§cYou don't have permissions!"); + return getMessage("nopermission", "§cYou don't have permissions!"); } public static String getSettingUpWorld() { - return getMessage("world.setting_up", "§aSetting up world..."); + return getMessage("world.setting_up", "§aSetting up world..."); } public static String getPlayerList() { @@ -90,27 +90,27 @@ public class MessageConfig { } public static String getLagDetection() { - return getMessage("lagdetection", "Lagdetection in world from: §c%world"); + return getMessage("lagdetection", "Lagdetection in world from: §c%world"); } public static String getWrongUsage() { - return getMessage("wrong_usage", "§c%usage"); + return getMessage("wrong_usage", "§c%usage"); } public static String getNoWorldOwn() { - return getMessage("world.does_not_exists.own", "§cYou don't have a world!"); + return getMessage("world.does_not_exists.own", "§cYou don't have a world!"); } public static String getNoWorldOther() { - return getMessage("world.does_not_exists.other", "§cThis player doesn't has a world!"); + return getMessage("world.does_not_exists.other", "§cThis player doesn't has a world!"); } public static String getNotRegistered() { - return getMessage("not_registered", "§cThis player hasn't joined yet!"); + return getMessage("not_registered", "§cThis player hasn't joined yet!"); } public static String getAlreadyMember() { - return getMessage("member.already_added", "§cThis player is already a member!"); + return getMessage("member.already_added", "§cThis player is already a member!"); } public static String getMemberAdded() { @@ -118,51 +118,51 @@ public class MessageConfig { } public static String getUnknownError() { - return getMessage("unknown_error", "§cSomething went wrong..."); + return getMessage("unknown_error", "§cSomething went wrong..."); } public static String getDeleteWorldOwn() { - return getMessage("world.delete.own", "§cYour world was deleted!"); + return getMessage("world.delete.own", "§cYour world was deleted!"); } public static String getDeleteWorldOther() { - return getMessage("world.delete.other", "You deleted the world of §c%player§6!"); + return getMessage("world.delete.other", "You deleted the world of §c%player§6!"); } public static String getNoMemberOwn() { - return getMessage("member.not_added.own", "§cThis player isn't a member!"); + return getMessage("member.not_added.own", "§cThis player isn't a member!"); } public static String getMemberRemoved() { - return getMessage("member.removed", "You removed §c%player§6 from your world!"); + return getMessage("member.removed", "You removed §c%player§6 from your world!"); } public static String getNoMemberAdded() { - return getMessage("member.no_one_added", "§cThere are no members added"); + return getMessage("member.no_one_added", "§cThere are no members added"); } public static String getWorldAlreadyExists() { - return getMessage("world.already_exists", "§cYou already have a world!"); + return getMessage("world.already_exists", "§cYou already have a world!"); } public static String getWorldCreated() { - return getMessage("world.created", "Your world is now ready. Get there with §a/ws home"); + return getMessage("world.created", "Your world is now ready. Get there with §a/ws home"); } public static String getWorldStillCreating() { - return getMessage("world.still_creating", "§cWorld is still creating"); + return getMessage("world.still_creating", "§cWorld is still creating"); } public static String getNotOnWorld() { - return getMessage("world.not_on", "§cYou are not on a world!"); + return getMessage("world.not_on", "§cYou are not on a world!"); } public static String getWorldStillLoaded() { - return getMessage("world.still_loaded", "§cYour world is still loaded!"); + return getMessage("world.still_loaded", "§cYour world is still loaded!"); } public static String getNoRequestSend() { - return getMessage("request.not_sent", "§cYou didn't send a request!"); + return getMessage("request.not_sent", "§cYou didn't send a request!"); } public static String getWorldReseted() { @@ -170,27 +170,27 @@ public class MessageConfig { } public static String getInvalidInput() { - return getMessage("request.invalid_input", "§c%input is not a valid input!"); + return getMessage("request.invalid_input", "§c%input is not a valid input!"); } public static String getRequestAlreadySent() { - return getMessage("request.already_sent", "§cYou already sent a request!"); + return getMessage("request.already_sent", "§cYou already sent a request!"); } public static String getRequestExpired() { - return getMessage("request.expired", "§cYou request is expired!"); + return getMessage("request.expired", "§cYou request is expired!"); } public static String getTimeUntilExpires() { - return getMessage("request.until_expire", "§cYour request expires in %time seconds!"); + return getMessage("request.until_expire", "§cYour request expires in %time seconds!"); } public static String getConfirmRequest() { - return getMessage("request.confirm", "§cPlease confirm reset of your world: %command"); + return getMessage("request.confirm", "§cPlease confirm reset of your world: %command"); } public static String getNoMemberOther() { - return getMessage("member.not_added.other", "§cYou are not added to this world!"); + return getMessage("member.not_added.other", "§cYou are not added to this world!"); } public static String getInfoOwner() { @@ -214,55 +214,55 @@ public class MessageConfig { } public static String getInfoEnabled() { - return getRawMessage("info.enabled", "§aOn"); + return getRawMessage("info.enabled", "§aOn"); } public static String getInfoDisabled() { - return getRawMessage("info.disabled", "§cOff"); + return getRawMessage("info.disabled", "§cOff"); } public static String getToggleGameModeEnabled() { - return getMessage("toggle.gamemode.enabled", "§a%player§6 can now change his gamemode!"); + return getMessage("toggle.gamemode.enabled", "§a%player§6 can now change his gamemode!"); } public static String getToggleGameModeDisabled() { - return getMessage("toggle.gamemode.disabled", "§c%player§6 can no longer change his gamemode!"); + return getMessage("toggle.gamemode.disabled", "§c%player§6 can no longer change his gamemode!"); } public static String getToggleTeleportEnabled() { - return getMessage("toggle.teleport.enabled", "§a%player§6 can now teleport!"); + return getMessage("toggle.teleport.enabled", "§a%player§6 can now teleport!"); } public static String getToggleTeleportDisabled() { - return getMessage("toggle.teleport.disabled", "§c%player§6 can no longer teleport!"); + return getMessage("toggle.teleport.disabled", "§c%player§6 can no longer teleport!"); } public static String getToggleBuildEnabled() { - return getMessage("toggle.build.enabled", "§a%player§6 can now build!"); + return getMessage("toggle.build.enabled", "§a%player§6 can now build!"); } public static String getToggleBuildDisabled() { - return getMessage("toggle.build.disabled", "§c%player§6 can no longer build!"); + return getMessage("toggle.build.disabled", "§c%player§6 can no longer build!"); } public static String getToggleFireEnabled() { - return getMessage("toggle.fire.enabled", "§aYou activated fire!"); + return getMessage("toggle.fire.enabled", "§aYou activated fire!"); } public static String getToggleFireDisabled() { - return getMessage("toggle.fire.disabled", "§cYou deactivated fire!"); + return getMessage("toggle.fire.disabled", "§cYou deactivated fire!"); } public static String getToggleTntEnabled() { - return getMessage("toggle.tnt.enabled", "§aYou activated TNT-Damage!"); + return getMessage("toggle.tnt.enabled", "§aYou activated TNT-Damage!"); } public static String getToggleTntDisabled() { - return getMessage("toggle.tnt.disabled", "§cYou deactivated TNT-Damage!"); + return getMessage("toggle.tnt.disabled", "§cYou deactivated TNT-Damage!"); } public static String getDeleteCommandHelp() { - return getMessage("command_help.delete_command", "/ws delete §8- §7Will delete a World"); + return getMessage("command_help.delete_command", "/ws delete §8- §7Will delete a World"); } public static List getCommandHelp() { diff --git a/WorldSystem/src/main/java/de/butzlabben/world/config/PluginConfig.java b/WorldSystem/src/main/java/de/butzlabben/world/config/PluginConfig.java index a78f0c0..8ac7e4a 100644 --- a/WorldSystem/src/main/java/de/butzlabben/world/config/PluginConfig.java +++ b/WorldSystem/src/main/java/de/butzlabben/world/config/PluginConfig.java @@ -36,12 +36,13 @@ public class PluginConfig { file = f; if (file.exists()) { YamlConfiguration cfg = getConfig(); - if (false == (cfg.isString("worldfolder") && cfg.isString("worldsource") && cfg.isInt("unloadingtime") + if (false == (cfg.isString("worldfolder") && cfg.isInt("unloadingtime") && cfg.isBoolean("survival") && cfg.isString("language") && cfg.isString("prefix") && cfg.isInt("request_expires") && cfg.isBoolean("need_confirm") - && cfg.isBoolean("contact_authserver") && cfg.isBoolean("spawn_teleportation") - && cfg.isInt("delete_after") && - + && cfg.isBoolean("contact_authserver") && cfg.isBoolean("spawn_teleportation") + && cfg.isInt("delete_after") && cfg.isBoolean("worldtemplates.multi_choose") + && cfg.isString("worldtemplates.default") && + cfg.isInt("lagsystem.period_in_seconds") && cfg.isInt("lagsystem.entities_per_world") && cfg.isBoolean("lagsystem.garbagecollector.use") && cfg.isInt("lagsystem.garbagecollector.period_in_minutes") && @@ -91,9 +92,10 @@ public class PluginConfig { } } - private static YamlConfiguration getConfig() { + public static YamlConfiguration getConfig() { try { - return YamlConfiguration.loadConfiguration(new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8"))); + return YamlConfiguration + .loadConfiguration(new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8"))); } catch (FileNotFoundException e) { e.printStackTrace(); } @@ -139,8 +141,12 @@ public class PluginConfig { return getConfig().getString("worldfolder", "plugins/WorldSystem/Worlds") + "/"; } - public static String getExampleWorldName() { - return getConfig().getString("worldsource", ""); + public static boolean isMultiChoose() { + return getConfig().getBoolean("worldtemplates.multi_choose", false); + } + + public static String getDefaultWorldTemplate() { + return getConfig().getString("worldtemplates.default", ""); } public static String getLanguage() { @@ -209,19 +215,19 @@ public class PluginConfig { public static boolean contactAuth() { return getConfig().getBoolean("contact_authserver", true); } - + public static boolean spawnTeleportation() { return getConfig().getBoolean("spawn_teleportation", true); } - + public static boolean shouldDelete() { return getConfig().getInt("delete_after") != -1; } - + public static long deleteAfter() { return getConfig().getLong("delete_after"); } - + public static WorldCreator getWorldCreator(String worldname) { WorldCreator creator = new WorldCreator(worldname); long seed = PluginConfig.getSeed(); diff --git a/WorldSystem/src/main/java/de/butzlabben/world/gui/PlayerOptionsGUI.java b/WorldSystem/src/main/java/de/butzlabben/world/gui/PlayerOptionsGUI.java index 1b87a66..491c3a1 100644 --- a/WorldSystem/src/main/java/de/butzlabben/world/gui/PlayerOptionsGUI.java +++ b/WorldSystem/src/main/java/de/butzlabben/world/gui/PlayerOptionsGUI.java @@ -21,7 +21,7 @@ public class PlayerOptionsGUI extends OrcInventory { private final static String path = "options.player."; public PlayerOptionsGUI(Player loader, String otherPlayer, UUID other) { - super(GuiConfig.getTitle(GuiConfig.getConfig(), "options.player").replace("%player", otherPlayer), GuiConfig.getRows("options.player")); + super(GuiConfig.getTitle(GuiConfig.getConfig(), "options.player").replace("%player", otherPlayer), GuiConfig.getRows("options.player"), GuiConfig.isFill("options.player")); WorldPlayer wp = new WorldPlayer(Bukkit.getOfflinePlayer(other), loader.getWorld().getName()); loadItem("build", "/ws togglebuild " + otherPlayer, new BuildStatus(wp)); loadItem("gamemode", "/ws togglegm " + otherPlayer, new GamemodeStatus(wp)); diff --git a/WorldSystem/src/main/java/de/butzlabben/world/gui/WorldChooseGUI.java b/WorldSystem/src/main/java/de/butzlabben/world/gui/WorldChooseGUI.java new file mode 100644 index 0000000..6536b8e --- /dev/null +++ b/WorldSystem/src/main/java/de/butzlabben/world/gui/WorldChooseGUI.java @@ -0,0 +1,70 @@ +package de.butzlabben.world.gui; + +import java.util.function.Consumer; + +import org.bukkit.entity.Player; +import de.butzlabben.inventory.OrcClickListener; +import de.butzlabben.inventory.OrcInventory; +import de.butzlabben.inventory.OrcItem; +import de.butzlabben.world.config.GuiConfig; +import de.butzlabben.world.wrapper.WorldTemplate; +import de.butzlabben.world.wrapper.WorldTemplateProvider; + +/** + * @author Butzlabben + * @since 15.12.2018 + */ +public class WorldChooseGUI extends OrcInventory { + + private final static String path = "worldchoose."; + + public WorldChooseGUI() { + this(null); + } + + public WorldChooseGUI(Consumer onClick) { + super(GuiConfig.getTitle(GuiConfig.getConfig(), "worldchoose"), GuiConfig.getRows("worldchoose"), + GuiConfig.isFill("worldchoose")); + + for (WorldTemplate template : WorldTemplateProvider.getInstace().getTemplates()) { + OrcItem icon = template.getIcon(); + if(onClick != null) + icon.setOnClick((p, inv, item) -> { + p.closeInventory(); + onClick.accept(template); + }); + int slot = template.getSlot(); + addItem(slot, icon); + } + + if (GuiConfig.isEnabled(path + "back")) { + OrcItem back = OrcItem.back.clone(); + back.setOnClick((p, inv, item) -> { + p.closeInventory(); + }); + addItem(GuiConfig.getSlot(path + "back"), back); + } + } + + public static void letChoose(Player player, Consumer template) { + player.openInventory(new WorldChooseGUI(template).getInventory(player)); + } + + public void loadItem(String subpath, OrcClickListener listener) { + if (GuiConfig.isEnabled(path + subpath) == false) + return; + OrcItem item = GuiConfig.getItem(path + subpath); + if (item != null) { + item.setOnClick(listener); + addItem(GuiConfig.getSlot(path + subpath), item); + } + } + + public void loadItem(String subpath) { + loadItem(subpath, null); + } + + public boolean canOpen(Player p) { + return true; + } +} \ No newline at end of file diff --git a/WorldSystem/src/main/java/de/butzlabben/world/gui/WorldOptionsGUI.java b/WorldSystem/src/main/java/de/butzlabben/world/gui/WorldOptionsGUI.java index 4fc57f3..8dd9849 100644 --- a/WorldSystem/src/main/java/de/butzlabben/world/gui/WorldOptionsGUI.java +++ b/WorldSystem/src/main/java/de/butzlabben/world/gui/WorldOptionsGUI.java @@ -23,7 +23,7 @@ public class WorldOptionsGUI extends OrcInventory { public final static HashMap data = new HashMap<>(); public WorldOptionsGUI() { - super(GuiConfig.getTitle(GuiConfig.getConfig(), "options.world"), GuiConfig.getRows("options.world")); + super(GuiConfig.getTitle(GuiConfig.getConfig(), "options.world"), GuiConfig.getRows("options.world"), GuiConfig.isFill("options.world")); loadItem("fire", "/ws fire", true, new FireStatus()); loadItem("tnt", "/ws tnt", true, new TntStatus()); diff --git a/WorldSystem/src/main/java/de/butzlabben/world/gui/WorldSystemGUI.java b/WorldSystem/src/main/java/de/butzlabben/world/gui/WorldSystemGUI.java index 039d9d8..3549c60 100644 --- a/WorldSystem/src/main/java/de/butzlabben/world/gui/WorldSystemGUI.java +++ b/WorldSystem/src/main/java/de/butzlabben/world/gui/WorldSystemGUI.java @@ -16,7 +16,7 @@ public class WorldSystemGUI extends OrcInventory { public WorldSystemGUI() { - super(GuiConfig.getTitle(GuiConfig.getConfig(), "worldsystem"), GuiConfig.getRows("worldsystem")); + super(GuiConfig.getTitle(GuiConfig.getConfig(), "worldsystem"), GuiConfig.getRows("worldsystem"), GuiConfig.isFill("worldsystem")); loadItem("playeroptions", (p, inv, item) -> { p.closeInventory(); @@ -57,4 +57,4 @@ public class WorldSystemGUI extends OrcInventory { public boolean canOpen(Player p) { return true; } -} +} \ No newline at end of file diff --git a/WorldSystem/src/main/java/de/butzlabben/world/wrapper/SystemWorld.java b/WorldSystem/src/main/java/de/butzlabben/world/wrapper/SystemWorld.java index 6b1701f..0e2e23b 100644 --- a/WorldSystem/src/main/java/de/butzlabben/world/wrapper/SystemWorld.java +++ b/WorldSystem/src/main/java/de/butzlabben/world/wrapper/SystemWorld.java @@ -204,7 +204,7 @@ public class SystemWorld { unloading = false; p.sendMessage(MessageConfig.getSettingUpWorld()); - + // Move World into Server dir String worlddir = PluginConfig.getWorlddir(); File world = new File(worlddir + "/" + worldname); @@ -260,11 +260,12 @@ public class SystemWorld { * @param p Player to create the world for * @return whether it succesfull or not */ - public static boolean create(Player p) { + public static boolean create(Player p, WorldTemplate template) { + DependenceConfig dc = new DependenceConfig(p); String uuid = p.getUniqueId().toString(); - int id = dc.getHighestID() + 1; + int id = DependenceConfig.getHighestID() + 1; String worldname = "ID" + id + "-" + uuid; WorldCreator creator = PluginConfig.getWorldCreator(worldname); @@ -277,67 +278,68 @@ public class SystemWorld { dc.createNewEntry(); String worlddir = PluginConfig.getWorlddir(); - File exampleworld = new File("plugins//WorldSystem//worldsources//" + PluginConfig.getExampleWorldName()); - if (new File("plugins//WorldSystem//worldsources//" + PluginConfig.getExampleWorldName() + "/uid.dat") - .exists()) { - new File("plugins//WorldSystem//worldsources//" + PluginConfig.getExampleWorldName() + "/uid.dat").delete(); + File exampleworld = new File(template.getPath()); + if (new File(template.getPath() + "/uid.dat").exists()) { + new File(template.getPath() + "/uid.dat").delete(); } File newworld = new File(worlddir + "/" + worldname); - try { - FileUtils.copyDirectory(exampleworld, newworld); - } catch (IOException e) { - System.err.println("Couldn't create world for " + p.getName()); - e.printStackTrace(); - } + + if (exampleworld.isDirectory()) + try { + FileUtils.copyDirectory(exampleworld, newworld); + } catch (IOException e) { + System.err.println("Couldn't create world for " + p.getName()); + e.printStackTrace(); + } + else + newworld.mkdirs(); WorldConfig.create(p); - if (PluginConfig.getExampleWorldName() == null || PluginConfig.getExampleWorldName().equals("") - || !exampleworld.exists()) { - // Move World into Server dir - File world = new File(worlddir + "/" + worldname); - if (!world.exists()) { - world = new File(Bukkit.getWorldContainer(), worldname); - } else { - if (new File(Bukkit.getWorldContainer(), worldname).exists() - && new File(PluginConfig.getWorlddir() + "/" + worldname).exists()) { - try { - FileUtils.deleteDirectory(new File(Bukkit.getWorldContainer(), worldname)); - } catch (IOException e) { - e.printStackTrace(); - } - } + // Move World into Server dir + File world = new File(worlddir + "/" + worldname); + if (!world.exists()) { + world = new File(Bukkit.getWorldContainer(), worldname); + } else { + if (new File(Bukkit.getWorldContainer(), worldname).exists() + && new File(PluginConfig.getWorlddir() + "/" + worldname).exists()) { try { - FileUtils.moveDirectoryToDirectory(world, Bukkit.getWorldContainer(), false); + FileUtils.deleteDirectory(new File(Bukkit.getWorldContainer(), worldname)); } catch (IOException e) { - p.sendMessage(PluginConfig.getPrefix() + "§cError: " + e.getMessage()); - System.err.println("Couldn't load world of " + p.getName()); e.printStackTrace(); - return false; } } - - SystemWorld sw = SystemWorld.getSystemWorld(worldname); - sw.setCreating(true); - - //Run in scheduler so method returns without delay - new BukkitRunnable() { - @Override - public void run() { - // For #16 - WorldSystem.getInstance().getAdapter().create(event.getWorldCreator(), sw, () -> { - if (p != null && p.isOnline()) { - p.sendMessage(MessageConfig.getWorldCreated()); - SettingsConfig.getCommandsonGet().stream() - .map(s -> s.replace("%player", p.getName()).replace("%world", sw.getName()).replace("%uuid", - p.getUniqueId().toString())) - .forEach(s -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), s)); - } - }); - } - }.runTaskLater(WorldSystem.getInstance(), 1); + try { + FileUtils.moveDirectoryToDirectory(world, Bukkit.getWorldContainer(), false); + } catch (IOException e) { + p.sendMessage(PluginConfig.getPrefix() + "§cError: " + e.getMessage()); + System.err.println("Couldn't load world of " + p.getName()); + e.printStackTrace(); + return false; + } } + + SystemWorld sw = SystemWorld.getSystemWorld(worldname); + sw.setCreating(true); + + // Run in scheduler so method returns without delay + new BukkitRunnable() { + @Override + public void run() { + // For #16 + WorldSystem.getInstance().getAdapter().create(event.getWorldCreator(), sw, () -> { + if (p != null && p.isOnline()) { + p.sendMessage(MessageConfig.getWorldCreated()); + SettingsConfig.getCommandsonGet().stream() + .map(s -> s.replace("%player", p.getName()).replace("%world", sw.getName()) + .replace("%uuid", p.getUniqueId().toString())) + .forEach(s -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), s)); + } + }); + } + }.runTaskLater(WorldSystem.getInstance(), 1); + return true; } diff --git a/WorldSystem/src/main/java/de/butzlabben/world/wrapper/WorldTemplate.java b/WorldSystem/src/main/java/de/butzlabben/world/wrapper/WorldTemplate.java new file mode 100644 index 0000000..8909d4a --- /dev/null +++ b/WorldSystem/src/main/java/de/butzlabben/world/wrapper/WorldTemplate.java @@ -0,0 +1,42 @@ +package de.butzlabben.world.wrapper; + +import de.butzlabben.inventory.OrcItem; +import de.butzlabben.world.config.GuiConfig; + +/** + * @author Butzlabben + * @since 15.12.2018 + */ +public class WorldTemplate { + + private final String name; + private final OrcItem icon; + private final int slot; + + public WorldTemplate(String name) { + this.name = name; + this.icon = GuiConfig.getItem("worldchoose." + name); + this.slot = GuiConfig.getSlot("worldchoose." + name); + + icon.setOnClick((p, inv, item) -> { + p.closeInventory(); + p.chat("/ws get " + name); + }); + } + + public int getSlot() { + return slot; + } + + public OrcItem getIcon() { + return icon; + } + + public String getName() { + return name; + } + + public String getPath() { + return "plugins/WorldSystem/worldsources/" + name; + } +} diff --git a/WorldSystem/src/main/java/de/butzlabben/world/wrapper/WorldTemplateProvider.java b/WorldSystem/src/main/java/de/butzlabben/world/wrapper/WorldTemplateProvider.java new file mode 100644 index 0000000..919c194 --- /dev/null +++ b/WorldSystem/src/main/java/de/butzlabben/world/wrapper/WorldTemplateProvider.java @@ -0,0 +1,39 @@ +package de.butzlabben.world.wrapper; + +import java.util.Collection; +import java.util.HashMap; + +import org.bukkit.configuration.ConfigurationSection; + +import de.butzlabben.world.config.PluginConfig; + +/** + * @author Butzlabben + * @since 16.12.2018 + */ +public class WorldTemplateProvider { + + private static WorldTemplateProvider instance = new WorldTemplateProvider(); + + public static WorldTemplateProvider getInstace() { + return instance; + } + + private HashMap templates = new HashMap<>(); + + private WorldTemplateProvider() { + ConfigurationSection section = PluginConfig.getConfig().getConfigurationSection("worldtemplates.templates"); + for(String key: section.getKeys(false)) { + String name = section.getString(key + ".name"); + templates.put(name, new WorldTemplate(name)); + } + } + + public WorldTemplate getTemplate(String key) { + return templates.get(key); + } + + public Collection getTemplates() { + return templates.values(); + } +} diff --git a/WorldSystem/src/main/resources/1_13_gui.yml b/WorldSystem/src/main/resources/1_13_gui.yml index 9358e6e..7489770 100644 --- a/WorldSystem/src/main/resources/1_13_gui.yml +++ b/WorldSystem/src/main/resources/1_13_gui.yml @@ -26,8 +26,14 @@ options: material: BARRIER display: '&cBack' + # When filling of an inventory is true, how the item should look like + fill: + material: GRAY_STAINED_GLASS_PANE + display: '' + # WorldoptionsGUI world: + fill: false # What the title of the Inv should be title: 'World Options' @@ -122,6 +128,7 @@ options: # PlayerGUI for managing one player on a world player: + fill: false title: 'Player options for %player' back: @@ -239,6 +246,7 @@ options: # WorldsystemGUI worldsystem: + fill: false title: 'WorldSystem' rows: 1 @@ -262,4 +270,37 @@ worldsystem: row: 1 col: 9 material: GRASS_BLOCK - display: '&eWorld Options' \ No newline at end of file + display: '&eWorld Options' + +# GUI for choosing world template +worldchoose: + fill: false + title: 'Choose world template' + + back: + enabled: true + slot: + row: 4 + col: 5 + + rows: 4 + + # The key must be named exactly as in the config.yml + template_default: + enabled: true + slot: + row: 2 + col: 3 + material: GRASS_BLOCK + display: '&aDefault template' + + another_template: + enabled: true + slot: + row: 2 + col: 7 + material: STONE_BLOCK + display: '&aAnother template' + + + \ No newline at end of file diff --git a/WorldSystem/src/main/resources/config.yml b/WorldSystem/src/main/resources/config.yml index 6dbf4c1..6ec27c4 100644 --- a/WorldSystem/src/main/resources/config.yml +++ b/WorldSystem/src/main/resources/config.yml @@ -12,8 +12,19 @@ # Path where the worlds will be saved worldfolder: 'plugins/WorldSystem/Worlds' -# Name of the template world -worldsource: '' +worldtemplates: + # Wheter players can decide on different templates + multi_choose: false + # If multi_choose is disabled, which template should be choosen + default: 'template_default' + templates: + # The "1" can be any key + 1: + # Name of directory in plugins/WorldSystem/worldsources + # e.g. this would be plugins/WorldSystem/worldsources/template_default + name: 'template_default' + 2: + name: 'another_template' # If a confirm is needed before auto-update need_confirm: true diff --git a/WorldSystem/src/main/resources/old_gui.yml b/WorldSystem/src/main/resources/old_gui.yml index 3f64ca3..8266e19 100644 --- a/WorldSystem/src/main/resources/old_gui.yml +++ b/WorldSystem/src/main/resources/old_gui.yml @@ -30,8 +30,15 @@ options: material: BARRIER display: '&cBack' + # When filling of an inventory is true, how the item should look like + fill: + material: STAINED_GLASS_PANE + data: 7 + display: '' + # WorldoptionsGUI world: + fill: false # What the title of the Inv should be title: 'World Options' @@ -120,6 +127,7 @@ options: # PlayerGUI for managing one player on a world player: + fill: false title: 'Player options for %player' back: @@ -237,6 +245,7 @@ options: # WorldsystemGUI worldsystem: + fill: false title: 'WorldSystem' rows: 1 @@ -260,4 +269,34 @@ worldsystem: row: 1 col: 9 material: GRASS - display: '&eWorld Options' \ No newline at end of file + display: '&eWorld Options' + +# GUI for choosing world template +worldchoose: + fill: false + title: 'Choose world template' + + back: + enabled: true + slot: + row: 4 + col: 5 + + rows: 4 + + # The key must be named exactly as in the config.yml + template_default: + enabled: true + slot: + row: 2 + col: 3 + material: GRASS + display: '&aDefault template' + + another_template: + enabled: true + slot: + row: 2 + col: 7 + material: STONE + display: '&aAnother template' \ No newline at end of file