From 1726bb60ef7a91a3c599dcffc1c0ac7f077a5780 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sun, 12 Aug 2018 14:30:43 +0200 Subject: [PATCH] GUI complete rewritten. Added changelog at autoupdater --- .../org.eclipse.core.resources.prefs | 1 - WorldSystem/bin/plugin.yml | 2 +- WorldSystem/src/1_13_gui.yml | 68 ++++++-- .../butzlabben/autoupdater/AutoUpdater.java | 7 +- .../de/butzlabben/inventory/CostumInv.java | 12 ++ .../de/butzlabben/inventory/OrcInventory.java | 66 ++----- .../src/de/butzlabben/inventory/OrcItem.java | 70 ++++---- .../de/butzlabben/inventory/OrcListener.java | 55 ++++++ .../inventory/PageClickListener.java | 11 -- .../inventory/pages/InventoryPage.java | 74 ++++++++ .../inventory/pages/ItemConverter.java | 13 ++ .../inventory/pages/PageGUICreator.java | 65 +++++++ .../butzlabben/world/GameProfileBuilder.java | 13 +- .../src/de/butzlabben/world/WorldSystem.java | 15 +- .../de/butzlabben/world/config/GuiConfig.java | 13 +- .../de/butzlabben/world/gui/GuiCommand.java | 5 +- .../world/gui/PlayerOptionsGUI.java | 52 ++---- .../world/gui/PlayersGUIManager.java | 70 -------- .../butzlabben/world/gui/PlayersPageGUI.java | 164 +++++++----------- .../butzlabben/world/gui/WorldOptionsGUI.java | 16 +- .../butzlabben/world/gui/WorldSystemGUI.java | 33 ++-- .../CommandExecutorClickListener.java | 4 +- .../InventoryOpenClickListener.java | 2 +- .../world/gui/playeroption/BuildStatus.java | 14 +- .../gui/playeroption/GamemodeStatus.java | 14 +- .../gui/playeroption/TeleportStatus.java | 18 +- .../world/gui/worldoption/FireStatus.java | 2 +- .../world/gui/worldoption/TntStatus.java | 2 +- WorldSystem/src/old_gui.yml | 59 ++++++- WorldSystem/src/plugin.yml | 2 +- 30 files changed, 554 insertions(+), 388 deletions(-) create mode 100644 WorldSystem/src/de/butzlabben/inventory/CostumInv.java create mode 100644 WorldSystem/src/de/butzlabben/inventory/OrcListener.java delete mode 100644 WorldSystem/src/de/butzlabben/inventory/PageClickListener.java create mode 100644 WorldSystem/src/de/butzlabben/inventory/pages/InventoryPage.java create mode 100644 WorldSystem/src/de/butzlabben/inventory/pages/ItemConverter.java create mode 100644 WorldSystem/src/de/butzlabben/inventory/pages/PageGUICreator.java delete mode 100644 WorldSystem/src/de/butzlabben/world/gui/PlayersGUIManager.java diff --git a/WorldSystem/.settings/org.eclipse.core.resources.prefs b/WorldSystem/.settings/org.eclipse.core.resources.prefs index 325dc0b..d330e34 100644 --- a/WorldSystem/.settings/org.eclipse.core.resources.prefs +++ b/WorldSystem/.settings/org.eclipse.core.resources.prefs @@ -1,5 +1,4 @@ eclipse.preferences.version=1 -encoding//src/de/butzlabben/inventory/OrcItem.java=Cp1252 encoding//src/de/butzlabben/world/WorldSystem.java=UTF-8 encoding//src/de/butzlabben/world/command/WSCommand.java=UTF-8 encoding//src/de/butzlabben/world/config/GuiConfig.java=Cp1252 diff --git a/WorldSystem/bin/plugin.yml b/WorldSystem/bin/plugin.yml index 75e7831..8fd86f4 100644 --- a/WorldSystem/bin/plugin.yml +++ b/WorldSystem/bin/plugin.yml @@ -1,5 +1,5 @@ name: WorldSystem -version: 2.3.0 +version: 2.3.1 author: Butzlabben main: de.butzlabben.world.WorldSystem diff --git a/WorldSystem/src/1_13_gui.yml b/WorldSystem/src/1_13_gui.yml index f90554d..9358e6e 100644 --- a/WorldSystem/src/1_13_gui.yml +++ b/WorldSystem/src/1_13_gui.yml @@ -20,11 +20,27 @@ options: coming_soon: material: ORANGE_DYE display: '&6Coming soon...' + + # How the back item should look like + back: + material: BARRIER + display: '&cBack' # WorldoptionsGUI world: + # What the title of the Inv should be + title: 'World Options' + # Rows - rows: 2 + rows: 3 + + # Where the back item should be + back: + enabled: true + slot: + row: 3 + col: 5 + # Reset button reset: # If feature should be enabled or not @@ -60,41 +76,62 @@ options: col: 5 material: TNT display: '&eToggle TNT-Explosion' + + back: + enabled: true + slot: + row: 3 + col: 5 players: + title: 'Players added to this world' - skull_item: - material: PLAYER_HEAD + back: + enabled: true + slot: + row: 6 + col: 6 rows: 6 + nextpage: enabled: true slot: row: 6 - col: 9 + col: 8 material: PAPER display: '&eNext Page' pagebefore: enabled: true slot: row: 6 - col: 1 + col: 2 material: PAPER display: '&ePage before' currentpage: enabled: true slot: row: 6 - col: 5 + col: 4 material: SUNFLOWER - display: '&eCurrent page: &a%page' - player_list_to_row: 4 + display: '&eCurrent page: &a%page' + playerhead: + material: PLAYER_HEAD display: '&e%player' # PlayerGUI for managing one player on a world player: - rows: 2 + title: 'Player options for %player' + + back: + slot: + enabled: true + row: 3 + col: 5 + + rows: 3 + build: enabled: true slot: @@ -202,18 +239,27 @@ options: # WorldsystemGUI worldsystem: + title: 'WorldSystem' + rows: 1 + + back: + slot: + enabled: true + row: 1 + col: 5 + playeroptions: enabled: true slot: row: 1 - col: 4 + col: 1 material: LEATHER_HELMET display: '&ePlayer Options' worldoptions: enabled: true slot: row: 1 - col: 6 + col: 9 material: GRASS_BLOCK display: '&eWorld Options' \ No newline at end of file diff --git a/WorldSystem/src/de/butzlabben/autoupdater/AutoUpdater.java b/WorldSystem/src/de/butzlabben/autoupdater/AutoUpdater.java index fa9b1a4..3447d98 100644 --- a/WorldSystem/src/de/butzlabben/autoupdater/AutoUpdater.java +++ b/WorldSystem/src/de/butzlabben/autoupdater/AutoUpdater.java @@ -53,10 +53,10 @@ public class AutoUpdater implements Listener { String v = plugin.getDescription().getVersion(); if (!ui.getVersion().equals(plugin.getDescription().getVersion())) { - if (!ui.isSilent()) + if (!ui.isSilent()) { Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "Found new version. Current: " + v + ", Available: " + ui.getVersion()); - + } // Get jar file Method getFileMethod = null; try { @@ -90,9 +90,11 @@ public class AutoUpdater implements Listener { 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"); } 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"); } } else { confirmNeed = false; @@ -104,6 +106,7 @@ public class AutoUpdater implements Listener { 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"); } } diff --git a/WorldSystem/src/de/butzlabben/inventory/CostumInv.java b/WorldSystem/src/de/butzlabben/inventory/CostumInv.java new file mode 100644 index 0000000..5a0d143 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/inventory/CostumInv.java @@ -0,0 +1,12 @@ +package de.butzlabben.inventory; + +/** + * @author Butzlabben + * @since 28.06.2018 + */ +public class CostumInv extends OrcInventory{ + + public CostumInv(String title, int rows) { + super(title, rows); + } +} diff --git a/WorldSystem/src/de/butzlabben/inventory/OrcInventory.java b/WorldSystem/src/de/butzlabben/inventory/OrcInventory.java index cbda9da..de26275 100644 --- a/WorldSystem/src/de/butzlabben/inventory/OrcInventory.java +++ b/WorldSystem/src/de/butzlabben/inventory/OrcInventory.java @@ -6,43 +6,31 @@ import java.util.Objects; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; -import org.bukkit.plugin.java.JavaPlugin; -import de.butzlabben.world.WorldSystem; -import de.butzlabben.world.wrapper.WorldPlayer; +public abstract class OrcInventory { -public abstract class OrcInventory implements Listener { - - private String title; + protected String title; private int rows; private InventoryType type; - private final boolean isStatic; - private HashMap items = new HashMap<>(); + protected HashMap items = new HashMap<>(); - public OrcInventory(String title, boolean isStatic) { - this.isStatic = isStatic; + public OrcInventory(String title) { Objects.requireNonNull(title, "title cannot be null"); this.title = title; - Bukkit.getPluginManager().registerEvents(this, JavaPlugin.getPlugin(WorldSystem.class)); } - public OrcInventory(String title, int rows, boolean isStatic) { - this(title, isStatic); + public OrcInventory(String title, int rows) { + this(title); if (rows <= 0 || rows > 6) throw new IllegalArgumentException("rows cannot be smaller than 1 or bigger than 6"); this.rows = rows; } - public OrcInventory(String title, InventoryType type, boolean isStatic) { - this(title, isStatic); + public OrcInventory(String title, InventoryType type) { + this(title); if (type == null || type == InventoryType.CHEST) { this.type = null; rows = 3; @@ -74,10 +62,13 @@ public abstract class OrcInventory implements Listener { public Inventory getInventory(Player p) { return getInventory(p, title); } + + public void redraw(Player p) { + p.closeInventory(); + p.openInventory(getInventory(p)); + } public Inventory getInventory(Player p, String title) { - if (canOpen(p) == false) - return null; Inventory inv; int size; if (type == null) { @@ -87,16 +78,17 @@ public abstract class OrcInventory implements Listener { inv = Bukkit.createInventory(null, type, title); size = type.getDefaultSize(); } - WorldPlayer wp = new WorldPlayer(p); for (Entry entry : items.entrySet()) { if (entry.getKey() >= 0 && entry.getKey() < size) { - inv.setItem(entry.getKey(), entry.getValue().getItemStack(p, wp)); + inv.setItem(entry.getKey(), entry.getValue().getItemStack(p)); } else { - System.err.println("[WorldSystem] There is a problem with a configured Item!"); + System.err.println("There is a problem with a configured Item!"); } } + OrcListener.getInstance().register(p.getUniqueId(), this); + return inv; } @@ -107,28 +99,4 @@ public abstract class OrcInventory implements Listener { public String getTitle() { return title; } - - @EventHandler - public void on(InventoryClickEvent e) { - if (e.getClickedInventory() != null && e.getClickedInventory().getTitle().equals(title)) { - e.setCancelled(true); - OrcItem item = items.get(e.getSlot()); - if (item != null) - item.onClick((Player) e.getWhoClicked(), this); - } - } - - @EventHandler - public void on(InventoryCloseEvent e) { - if (e.getInventory() != null && e.getInventory().getTitle().equals(title) && !isStatic) { - unregister(); - } - } - - public void unregister() { - HandlerList.unregisterAll(this); - } - - public abstract boolean canOpen(Player p); - } diff --git a/WorldSystem/src/de/butzlabben/inventory/OrcItem.java b/WorldSystem/src/de/butzlabben/inventory/OrcItem.java index 098ad2c..0e0117a 100644 --- a/WorldSystem/src/de/butzlabben/inventory/OrcItem.java +++ b/WorldSystem/src/de/butzlabben/inventory/OrcItem.java @@ -7,6 +7,7 @@ import java.util.Objects; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -14,12 +15,17 @@ import de.butzlabben.world.wrapper.WorldPlayer; public class OrcItem { - public static OrcItem enabled, disabled, coming_soon, error = new OrcItem(Material.BARRIER, null, + public static OrcItem enabled, disabled, coming_soon, back, error = new OrcItem(Material.BARRIER, null, "§cERROR: Item is wrong configured!", "§cPath in config: see Displayname"); private ItemStack is; private OrcClickListener listener; private DependListener depend; + private Runnable callback; + + public void setCallback(Runnable r) { + callback = r; + } public OrcItem(Material mat, String display, String... lore) { setItemStack(mat, display, lore); @@ -30,50 +36,36 @@ public class OrcItem { } public OrcItem(Material mat, String display, List lore) { - setItemStack(mat, display, lore); + setItemStack(mat, (byte) 0, display, lore); } -// public OrcItem(int id, byte data, String display, List lore) { -// setItemStack(id, data, display, lore); -// } - -// @SuppressWarnings("deprecation") -// public OrcItem setItemStack(int id, byte data, String display, List lore) { -// is = new ItemStack(id, 1, data); -// ItemMeta meta = is.getItemMeta(); -// if (meta != null) { -// meta.setDisplayName(display); -// meta.setLore(lore); -// is.setItemMeta(meta); -// } -// return this; -// } - -// public OrcItem(int id, byte data, String display, String... lore) { -// setItemStack(id, data, display, lore); -// } - -// public OrcItem setItemStack(int id, byte data, String display, String[] lore) { -// return setItemStack(id, data, display, Arrays.asList(lore)); -// } + public OrcItem(Material mat) { + this(new ItemStack(mat)); + } public OrcItem(Material material, byte data, String display, ArrayList lore) { - is = new ItemStack(material, 1, data); - ItemMeta meta = is.getItemMeta(); - meta.setDisplayName(display); - meta.setLore(lore); - is.setItemMeta(meta); + setItemStack(material, data, display, lore); } - public OrcItem setItemStack(Material mat, String display, List lore) { - is = new ItemStack(mat); + public OrcItem setItemStack(Material mat, byte data, String display, List lore) { + is = new ItemStack(mat, 1 , data); ItemMeta meta = is.getItemMeta(); meta.setDisplayName(display); meta.setLore(lore); + meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); is.setItemMeta(meta); return this; } + public ItemStack getItemStack(Player p) { + if (p != null && depend != null) { + ItemStack is = depend.getItemStack(p, new WorldPlayer(p)); + if (is != null) + return is; + } + return is; + } + public ItemStack getItemStack(Player p, WorldPlayer wp) { if (p != null && depend != null) { ItemStack is = depend.getItemStack(p, wp); @@ -83,14 +75,21 @@ public class OrcItem { return is; } + public ItemStack getItemStack() { + return is; + } + public OrcItem setOnClick(OrcClickListener listener) { this.listener = listener; return this; } public OrcItem onClick(Player p, OrcInventory inv) { - if (listener != null) + if (listener != null) { listener.onClick(p, inv, this); + } + if (callback != null) + callback.run(); return this; } @@ -118,11 +117,14 @@ public class OrcItem { public OrcItem setItemStack(ItemStack is) { Objects.requireNonNull(is, "ItemStack cannot be null"); this.is = is; + ItemMeta meta = is.getItemMeta(); + meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); + is.setItemMeta(meta); return this; } public OrcItem setItemStack(Material mat, String display, String... lore) { - return setItemStack(mat, display, Arrays.asList(lore)); + return setItemStack(mat, (byte) 0, display, Arrays.asList(lore)); } public OrcItem setDepend(DependListener listener) { diff --git a/WorldSystem/src/de/butzlabben/inventory/OrcListener.java b/WorldSystem/src/de/butzlabben/inventory/OrcListener.java new file mode 100644 index 0000000..495ed31 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/inventory/OrcListener.java @@ -0,0 +1,55 @@ +package de.butzlabben.inventory; + +import java.util.HashMap; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; + +import de.butzlabben.world.WorldSystem; + +/** + * @author Butzlabben + * @since 10.06.2018 + */ +public class OrcListener implements Listener { + + private static OrcListener instance; + + private HashMap invs = new HashMap<>(); + + public static synchronized OrcListener getInstance() { + if (instance == null) + instance = new OrcListener(); + return instance; + } + + private OrcListener() { + Bukkit.getPluginManager().registerEvents(this, WorldSystem.getInstance()); + } + + @EventHandler + public void on(InventoryClickEvent e) { + if (e.getClickedInventory() != null && invs.containsKey(e.getWhoClicked().getUniqueId())) { + e.setCancelled(true); + OrcItem item = invs.get(e.getWhoClicked().getUniqueId()).items.get(e.getSlot()); + if (item != null) + item.onClick((Player) e.getWhoClicked(), invs.get(e.getWhoClicked().getUniqueId())); + } + } + + public void register(UUID uuid, OrcInventory inv) { + invs.put(uuid, inv); + } + + @EventHandler + public void on(InventoryCloseEvent e) { + if (e.getInventory() != null && invs.containsKey(e.getPlayer().getUniqueId())) { + invs.remove(e.getPlayer().getUniqueId()); + } + } +} diff --git a/WorldSystem/src/de/butzlabben/inventory/PageClickListener.java b/WorldSystem/src/de/butzlabben/inventory/PageClickListener.java deleted file mode 100644 index efb1e46..0000000 --- a/WorldSystem/src/de/butzlabben/inventory/PageClickListener.java +++ /dev/null @@ -1,11 +0,0 @@ -package de.butzlabben.inventory; - -/** - * @author Butzlabben - * @since 20.04.2018 - */ -public interface PageClickListener { - - public int getPageAfter(); - public int getPageBefore(); -} diff --git a/WorldSystem/src/de/butzlabben/inventory/pages/InventoryPage.java b/WorldSystem/src/de/butzlabben/inventory/pages/InventoryPage.java new file mode 100644 index 0000000..af72dc8 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/inventory/pages/InventoryPage.java @@ -0,0 +1,74 @@ +package de.butzlabben.inventory.pages; + +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; + +import de.butzlabben.inventory.OrcInventory; +import de.butzlabben.inventory.OrcItem; +import de.butzlabben.world.config.GuiConfig; + +/** + * @author Butzlabben + * @since 20.05.2018 + */ +public class InventoryPage extends OrcInventory { + + InventoryPage next, before = null; + + public InventoryPage(String title, int page, int pages) { + super(title, 6); + + YamlConfiguration cfg = GuiConfig.getConfig(); + String path = "options.players.currentpage"; + + OrcItem oi = new OrcItem(GuiConfig.getMaterial(cfg, path), GuiConfig.getData(cfg, path), + GuiConfig.getDisplay(cfg, path).replaceAll("%page", "" + page), GuiConfig.getLore(cfg, path)); + addItem(GuiConfig.getSlot(path), oi); + + path = "options.players.pagebefore"; + oi = GuiConfig.getItem(path); + oi.setOnClick((p, inv, item) -> { + p.closeInventory(); + p.openInventory(this.before.getInventory(p)); + }); + addItem(GuiConfig.getSlot(path), oi); + + path = "options.players.nextpage"; + oi = GuiConfig.getItem(path); + oi.setOnClick((p, inv, item) -> { + p.closeInventory(); + p.openInventory(this.next.getInventory(p)); + }); + addItem(GuiConfig.getSlot(path), oi); + } + + private int i = 0; + + @Override + public Inventory getInventory(Player p) { + return super.getInventory(p); + } + + public void addItem(OrcItem item) { + if (i > 36) { + System.err.println("More items than allowed in page view"); + return; + } + addItem(i, item); + i++; + } + + @EventHandler + public void on(InventoryClickEvent e) { + if (e.getClickedInventory() != null && e.getClickedInventory().getTitle() != null + && e.getClickedInventory().getTitle().equals(title)) { + e.setCancelled(true); + OrcItem item = items.get(e.getSlot()); + if (item != null) + item.onClick((Player) e.getWhoClicked(), this); + } + } +} diff --git a/WorldSystem/src/de/butzlabben/inventory/pages/ItemConverter.java b/WorldSystem/src/de/butzlabben/inventory/pages/ItemConverter.java new file mode 100644 index 0000000..8925faf --- /dev/null +++ b/WorldSystem/src/de/butzlabben/inventory/pages/ItemConverter.java @@ -0,0 +1,13 @@ +package de.butzlabben.inventory.pages; + +import de.butzlabben.inventory.OrcItem; + +/** + * @author Butzlabben + * @since 21.05.2018 + */ +public interface ItemConverter { + + public OrcItem convert(T element); + +} diff --git a/WorldSystem/src/de/butzlabben/inventory/pages/PageGUICreator.java b/WorldSystem/src/de/butzlabben/inventory/pages/PageGUICreator.java new file mode 100644 index 0000000..acf42a6 --- /dev/null +++ b/WorldSystem/src/de/butzlabben/inventory/pages/PageGUICreator.java @@ -0,0 +1,65 @@ +package de.butzlabben.inventory.pages; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + +import org.bukkit.entity.Player; + +import de.butzlabben.inventory.OrcItem; + +/** + * @author Butzlabben + * @since 21.05.2018 + */ +public class PageGUICreator { + + private final int elementsPerPage; + private List invpages; + + public void create(String title, Collection elements, ItemConverter converter) { + List items = elements.stream().map(r -> converter.convert(r)).collect(Collectors.toList()); + if (items == null || items.size() == 0) + return; + + int pages = (int) (Math.ceil((double) (items.size() / (double) elementsPerPage) < 1 ? 1 : Math.ceil((double) items.size() / (double) elementsPerPage))); + + invpages = new ArrayList<>(pages); + + for (int i = 1; i < pages + 1; i++) { + int start = i == 1 ? 0 : elementsPerPage * (i - 1); + int end = items.size() < elementsPerPage * i ? items.size() : elementsPerPage * i; + List page = items.subList(start, end); + + InventoryPage invpage = new InventoryPage(title, i, pages); + page.forEach(invpage::addItem); + invpages.add(invpage); + } + + for (int i = 0; i < invpages.size(); i++) { + + int beforeIndex = i == 0 ? invpages.size() - 1 : i - 1; + int nextIndex = i == invpages.size() - 1 ? 0 : i + 1; + + invpages.get(i).before = invpages.get(beforeIndex); + invpages.get(i).next = invpages.get(nextIndex); + } + } + + public void show(Player p) { + p.openInventory(invpages.get(0).getInventory(p)); + } + + public PageGUICreator() { + this(4 * 9); + } + + public List getInvPages() { + return invpages; + } + + public PageGUICreator(int elementsPerPage) { + this.elementsPerPage = elementsPerPage; + } +} diff --git a/WorldSystem/src/de/butzlabben/world/GameProfileBuilder.java b/WorldSystem/src/de/butzlabben/world/GameProfileBuilder.java index a811ce8..0e22719 100644 --- a/WorldSystem/src/de/butzlabben/world/GameProfileBuilder.java +++ b/WorldSystem/src/de/butzlabben/world/GameProfileBuilder.java @@ -40,6 +40,7 @@ public class GameProfileBuilder { .registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()).create(); private static HashMap cache = new HashMap<>(); private static long cacheTime = -1L; + private static Object sync = new Object(); public static GameProfile fetch(UUID uuid) throws IOException { return fetch(uuid, false); @@ -49,10 +50,14 @@ public class GameProfileBuilder { if ((!forceNew) && (cache.containsKey(uuid)) && (((CachedProfile) cache.get(uuid)).isValid())) { return ((CachedProfile) cache.get(uuid)).profile; } - HttpURLConnection connection = (HttpURLConnection) new URL( - String.format("https://sessionserver.mojang.com/session/minecraft/profile/%s?unsigned=false", - new Object[] { UUIDTypeAdapter.fromUUID(uuid) })).openConnection(); - connection.setReadTimeout(5000); + + HttpURLConnection connection; + synchronized (sync) { + connection = (HttpURLConnection) new URL( + String.format("https://sessionserver.mojang.com/session/minecraft/profile/%s?unsigned=false", + new Object[] { UUIDTypeAdapter.fromUUID(uuid) })).openConnection(); + connection.setReadTimeout(5000); + } if (connection.getResponseCode() == 200) { String json = new BufferedReader(new InputStreamReader(connection.getInputStream())).readLine(); diff --git a/WorldSystem/src/de/butzlabben/world/WorldSystem.java b/WorldSystem/src/de/butzlabben/world/WorldSystem.java index 521cd2d..3933268 100644 --- a/WorldSystem/src/de/butzlabben/world/WorldSystem.java +++ b/WorldSystem/src/de/butzlabben/world/WorldSystem.java @@ -13,7 +13,6 @@ import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import de.butzlabben.autoupdater.AutoUpdater; -import de.butzlabben.inventory.OrcInventory; import de.butzlabben.world.command.WSAddmemberCommand; import de.butzlabben.world.command.WSCommand; import de.butzlabben.world.command.WSConfirmCommand; @@ -37,9 +36,6 @@ import de.butzlabben.world.config.MessageConfig; import de.butzlabben.world.config.PluginConfig; import de.butzlabben.world.config.SettingsConfig; import de.butzlabben.world.gui.GuiCommand; -import de.butzlabben.world.gui.PlayerOptionsGUI; -import de.butzlabben.world.gui.WorldOptionsGUI; -import de.butzlabben.world.gui.WorldSystemGUI; import de.butzlabben.world.listener.BlockListener; import de.butzlabben.world.listener.CommandListener; import de.butzlabben.world.listener.PlayerDeathListener; @@ -59,7 +55,6 @@ public class WorldSystem extends JavaPlugin { public static HashMap deathLocations = new HashMap<>(); final private String version = this.getDescription().getVersion(); - public static OrcInventory mainGUI; public static CreatorAdapter creator; @@ -125,9 +120,7 @@ public class WorldSystem extends JavaPlugin { getCommand("ws confirm").setExecutor(new WSConfirmCommand()); getCommand("ws gui").setExecutor(new GuiCommand()); - - mainGUI = new WorldSystemGUI(); - + System.setProperty("bstats.relocatecheck", "false"); Metrics m = new Metrics(this); m.addCustomChart(new Metrics.SingleLineChart("worlds", Entry::entrys)); @@ -167,9 +160,7 @@ public class WorldSystem extends JavaPlugin { sw.directUnload(w); } } - mainGUI.unregister(); - PlayerOptionsGUI.instance.unregister(); - WorldOptionsGUI.instance.unregister(); + Bukkit.getConsoleSender() .sendMessage(PluginConfig.getPrefix() + "Succesfully disabled WorldSystem v" + version); } @@ -222,7 +213,7 @@ public class WorldSystem extends JavaPlugin { return JavaPlugin.getPlugin(WorldSystem.class); } - public static boolean isIs1_13() { + public static boolean is1_13() { return is1_13; } } diff --git a/WorldSystem/src/de/butzlabben/world/config/GuiConfig.java b/WorldSystem/src/de/butzlabben/world/config/GuiConfig.java index 01ef3b8..e6987d4 100644 --- a/WorldSystem/src/de/butzlabben/world/config/GuiConfig.java +++ b/WorldSystem/src/de/butzlabben/world/config/GuiConfig.java @@ -33,7 +33,7 @@ public class GuiConfig { if (file.exists() == false) { try { String guiFileResource; - if (WorldSystem.isIs1_13()) { + if (WorldSystem.is1_13()) { guiFileResource = "1_13_gui.yml"; } else { guiFileResource = "old_gui.yml"; @@ -48,6 +48,7 @@ public class GuiConfig { OrcItem.enabled = getEnabled(); OrcItem.disabled = getDisabled(); OrcItem.coming_soon = getComingSoon(); + OrcItem.back = getBack(); } public static YamlConfiguration getConfig() { @@ -94,6 +95,10 @@ public class GuiConfig { public static byte getData(FileConfiguration cfg, String path) { return (byte) cfg.getInt(path + ".data", 0); } + + public static String getTitle(FileConfiguration cfg, String path) { + return cfg.getString(path + ".title"); + } public static Material getMaterial(FileConfiguration cfg, String path) { try { @@ -128,8 +133,12 @@ public class GuiConfig { public static OrcItem getComingSoon() { return getItem("options.coming_soon"); } + + private static OrcItem getBack() { + return getItem("options.back"); + } public static Material getSkullItem() { - return getMaterial(getConfig(), "options.players.skull_item"); + return getMaterial(getConfig(), "options.players.playerhead"); } } diff --git a/WorldSystem/src/de/butzlabben/world/gui/GuiCommand.java b/WorldSystem/src/de/butzlabben/world/gui/GuiCommand.java index 7e73ac2..6c2f194 100644 --- a/WorldSystem/src/de/butzlabben/world/gui/GuiCommand.java +++ b/WorldSystem/src/de/butzlabben/world/gui/GuiCommand.java @@ -5,7 +5,6 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import de.butzlabben.world.WorldSystem; import de.butzlabben.world.config.MessageConfig; import de.butzlabben.world.wrapper.WorldPlayer; @@ -18,7 +17,7 @@ public class GuiCommand implements CommandExecutor { return true; } WorldPlayer wp = new WorldPlayer((Player) sender); - if(!wp.isOnSystemWorld()) { + if (!wp.isOnSystemWorld()) { sender.sendMessage(MessageConfig.getNotOnWorld()); return true; } @@ -26,7 +25,7 @@ public class GuiCommand implements CommandExecutor { sender.sendMessage(MessageConfig.getNoPermission()); return true; } - ((Player) sender).openInventory(WorldSystem.mainGUI.getInventory((Player) sender)); + ((Player) sender).openInventory(new WorldSystemGUI().getInventory((Player) sender)); return true; } diff --git a/WorldSystem/src/de/butzlabben/world/gui/PlayerOptionsGUI.java b/WorldSystem/src/de/butzlabben/world/gui/PlayerOptionsGUI.java index 4264299..1b87a66 100644 --- a/WorldSystem/src/de/butzlabben/world/gui/PlayerOptionsGUI.java +++ b/WorldSystem/src/de/butzlabben/world/gui/PlayerOptionsGUI.java @@ -1,10 +1,9 @@ package de.butzlabben.world.gui; -import java.util.HashMap; import java.util.UUID; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; import de.butzlabben.inventory.DependListener; import de.butzlabben.inventory.OrcInventory; @@ -19,26 +18,28 @@ import de.butzlabben.world.wrapper.WorldPlayer; public class PlayerOptionsGUI extends OrcInventory { - public static PlayerOptionsGUI instance; - private final static String path = "options.player."; - - public final static HashMap data = new HashMap<>(); - - public PlayerOptionsGUI() { - super("Player Options", GuiConfig.getRows("options.player"), true); - loadItem("build", "/ws togglebuild %data", new BuildStatus()); - loadItem("gamemode", "/ws togglegm %data", new GamemodeStatus()); - loadItem("teleport", "/ws toggletp %data", new TeleportStatus()); + + public PlayerOptionsGUI(Player loader, String otherPlayer, UUID other) { + super(GuiConfig.getTitle(GuiConfig.getConfig(), "options.player").replace("%player", otherPlayer), GuiConfig.getRows("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)); + loadItem("teleport", "/ws toggletp " + otherPlayer, new TeleportStatus(wp)); loadItem("time"); loadItem("addmember"); loadItem("delmember"); - loadItem("worldborder"); loadItem("setpermissions"); loadItem("administrateworld"); - if (instance != null) - instance.unregister(); - instance = this; + + if (GuiConfig.isEnabled(path + "back")) { + OrcItem back = OrcItem.back.clone(); + back.setOnClick((p, inv, i) -> { + p.closeInventory(); + PlayersPageGUI.openGUI(p); + }); + addItem(GuiConfig.getSlot(path + "back"), back); + } } public void loadItem(String subpath, String message, DependListener depend) { @@ -67,23 +68,4 @@ public class PlayerOptionsGUI extends OrcInventory { public void loadItem(String subpath) { loadItem(subpath, null); } - - @Override - public Inventory getInventory(Player p, String title) { - if (data.containsKey(p.getUniqueId())) - return super.getInventory(p, title.replaceAll("%data", data.get(p.getUniqueId()))); - return super.getInventory(p, title); - } - - @Override - public Inventory getInventory(Player p) { - if (data.containsKey(p.getUniqueId())) - return super.getInventory(p, getTitle().replaceAll("%data", data.get(p.getUniqueId()))); - return super.getInventory(p, getTitle()); - } - - @Override - public boolean canOpen(Player p) { - return new WorldPlayer(p).isOwnerofWorld(); - } } diff --git a/WorldSystem/src/de/butzlabben/world/gui/PlayersGUIManager.java b/WorldSystem/src/de/butzlabben/world/gui/PlayersGUIManager.java deleted file mode 100644 index 6494fae..0000000 --- a/WorldSystem/src/de/butzlabben/world/gui/PlayersGUIManager.java +++ /dev/null @@ -1,70 +0,0 @@ -package de.butzlabben.world.gui; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.UUID; - -import org.bukkit.entity.Player; - -import de.butzlabben.world.config.GuiConfig; -import de.butzlabben.world.config.WorldConfig; -import de.butzlabben.world.wrapper.SystemWorld; - -/** - * @author Butzlabben - * @since 20.04.2018 - */ -public class PlayersGUIManager { - - private static final int headsPerInv = GuiConfig.getConfig().getInt("options.players.player_list_to_row") * 9; - - private PlayersGUIManager() { - } - - public static PlayersPageGUI getFirstPage(Player p) { - return getPage(p, 1); - } - - public static PlayersPageGUI getPage(Player p, int page) { - String worldname = p.getWorld().getName(); - SystemWorld sw = SystemWorld.getSystemWorld(worldname); - if (sw != null) { - HashMap members = WorldConfig.getWorldConfig(worldname).getMembersWithNames(); - if (members == null || members.size() == 0) - return null; - int pages = Math.round(members.size() / headsPerInv) < 1 ? 1 : Math.round(members.size() / headsPerInv); - if (page > pages) - return null; - return getPage(p, page, pages); - } - return null; - } - - public static PlayersPageGUI getPage(Player p, int page, int pages) { - String worldname = p.getWorld().getName(); - SystemWorld sw = SystemWorld.getSystemWorld(worldname); - if (sw != null) { - HashMap members = WorldConfig.getWorldConfig(worldname).getMembersWithNames(); - if (members == null || members.size() == 0) - return null; - - - - int startPos = pages == 1 ? 0 : headsPerInv * (page - 1); - int length = pages == 1 ? members.size() : headsPerInv; - - ArrayList list = new ArrayList<>(members.keySet()); - HashMap uuids = new HashMap<>(); - for (int i = startPos; i < startPos + length; i++) { - uuids.put(list.get(i), members.get(list.get(i))); - } - - int pageBefore = page == 1 ? pages : page - 1; - int nextPage = pages == page ? 1 : page + 1; - - PlayersPageGUI ppg = new PlayersPageGUI(page, p.getUniqueId(), uuids, nextPage, pageBefore); - return ppg; - } - return null; - } -} diff --git a/WorldSystem/src/de/butzlabben/world/gui/PlayersPageGUI.java b/WorldSystem/src/de/butzlabben/world/gui/PlayersPageGUI.java index 579c745..dc07455 100644 --- a/WorldSystem/src/de/butzlabben/world/gui/PlayersPageGUI.java +++ b/WorldSystem/src/de/butzlabben/world/gui/PlayersPageGUI.java @@ -1,125 +1,91 @@ package de.butzlabben.world.gui; +import java.util.ArrayList; import java.util.HashMap; +import java.util.Map.Entry; import java.util.UUID; -import org.apache.commons.lang3.tuple.Pair; -import org.bukkit.Material; -import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.SkullMeta; -import org.bukkit.scheduler.BukkitRunnable; - -import de.butzlabben.inventory.OrcClickListener; -import de.butzlabben.inventory.OrcInventory; import de.butzlabben.inventory.OrcItem; +import de.butzlabben.inventory.pages.PageGUICreator; import de.butzlabben.world.config.GuiConfig; -import de.butzlabben.world.wrapper.WorldPlayer; +import de.butzlabben.world.config.MessageConfig; +import de.butzlabben.world.config.WorldConfig; /** * @author Butzlabben * @since 20.04.2018 */ -public class PlayersPageGUI extends OrcInventory { - - private final static String path = "options.players."; - private static HashMap> pages = new HashMap<>(); +public class PlayersPageGUI { @SuppressWarnings("deprecation") - public PlayersPageGUI(int page, UUID ex, HashMap players, int next, int before) { - super("Players added to this world", GuiConfig.getRows("options.players"), false); - pages.put(ex, Pair.of(next, before)); + public static void openGUI(Player p) { + WorldConfig config = WorldConfig.getWorldConfig(p.getWorld().getName()); - loadItem("nextpage", (p, inv, orcitem) -> { - p.closeInventory(); - new BukkitRunnable() { - @Override - public void run() { - p.closeInventory(); + HashMap members = config.getMembersWithNames(); - inv.unregister(); - int nextPage = pages.get(p.getUniqueId()).getLeft(); - pages.remove(p.getUniqueId()); - - p.openInventory(PlayersGUIManager.getPage(p, nextPage).getInventory(p)); - } - }.run(); - }); - - loadItem("pagebefore", (p, inv, orcitem) -> { - p.closeInventory(); - new BukkitRunnable() { - @Override - public void run() { - p.closeInventory(); - int pageBefore = pages.get(p.getUniqueId()).getRight(); - pages.remove(p.getUniqueId()); - inv.unregister(); - p.openInventory(PlayersGUIManager.getPage(p, pageBefore).getInventory(p)); - } - }.run(); - }); - - String subpath = "currentpage"; - String path = PlayersPageGUI.path + subpath; - YamlConfiguration cfg = GuiConfig.getConfig(); - OrcItem oi = null; - try { - oi = new OrcItem(GuiConfig.getMaterial(cfg, path), GuiConfig.getData(cfg, path), - GuiConfig.getDisplay(cfg, path).replaceAll("%page", "" + page), GuiConfig.getLore(cfg, path)); - } catch (Exception e) { - } - try { - oi = new OrcItem(GuiConfig.getMaterial(cfg, path), - GuiConfig.getDisplay(cfg, path).replaceAll("%page", "" + page), GuiConfig.getLore(cfg, path)); - } catch (Exception e) { - } - addItem(GuiConfig.getSlot(path), oi); - - // Load players - int i = 0; - for (UUID uuid : players.keySet()) { - String name = players.get(uuid); - Material skullItem = GuiConfig.getSkullItem(); - ItemStack is = new ItemStack(skullItem, 1, (short) 3); - SkullMeta sm = (SkullMeta) is.getItemMeta(); - sm.setOwner(name); - sm.setDisplayName( - GuiConfig.getDisplay(cfg, PlayersPageGUI.path + "playerhead").replaceAll("%player", name)); - is.setItemMeta(sm); - OrcItem item = new OrcItem(is); - item.setOnClick((p, inv, orcitem) -> { - p.closeInventory(); - PlayerOptionsGUI.data.put(ex, name); - pages.remove(p.getUniqueId()); - p.openInventory(PlayerOptionsGUI.instance.getInventory(p)); - }); - addItem(i, item); - i++; - - } - } - - public void loadItem(String subpath, OrcClickListener depend) { - if (GuiConfig.isEnabled(path + subpath) == false) + if (members.size() == 0) { + p.sendMessage(MessageConfig.getNoMemberAdded()); return; - OrcItem item = GuiConfig.getItem(path + subpath); - if (item != null) { - - item.setOnClick(depend); - - addItem(GuiConfig.getSlot(path + subpath), item); } + + PageGUICreator> creator = new PageGUICreator<>(GuiConfig.getRows("options.players")); + + creator.create(GuiConfig.getTitle(GuiConfig.getConfig(), "options.players"), members.entrySet(), (entry) -> { + String name = entry.getValue(); + OrcItem oi = new OrcItem(GuiConfig.getSkullItem(), GuiConfig + .getDisplay(GuiConfig.getConfig(), "options.players.playerhead").replaceAll("%player", name)); + SkullMeta sm = (SkullMeta) oi.getItemStack().getItemMeta(); + sm.setOwner(name); + oi.getItemStack().setItemMeta(sm); + oi.setOnClick((player, inv, item) -> { + player.closeInventory(); + PlayerOptionsGUI gui = new PlayerOptionsGUI(player, name, entry.getKey()); + player.openInventory(gui.getInventory(p)); + }); + return oi; + }); + + if (GuiConfig.isEnabled("options.players.back")) { + OrcItem back = OrcItem.back.clone(); + back.setOnClick((player, inv, i) -> { + player.closeInventory(); + player.openInventory(new WorldSystemGUI().getInventory(p)); + }); + creator.getInvPages().forEach((oi) -> {oi.addItem(GuiConfig.getSlot("options.players.back"), back);}); + } + + creator.show(p); } - public void loadItem(String subpath) { - loadItem(subpath, null); - } + @SuppressWarnings("deprecation") + public static void preloadPlayers(WorldConfig config) { + new Thread(() -> { + int headsPerInv = GuiConfig.getRows("options.players") * 9; + HashMap members = config.getMembersWithNames(); + if (members == null || members.size() == 0) + return; + int pages = Math.round(members.size() / headsPerInv) < 1 ? 1 : Math.round(members.size() / headsPerInv); + for (int page = 0; page < pages; page++) { + int startPos = pages == 1 ? 0 : headsPerInv * (page - 1); + int length = pages == 1 ? members.size() : headsPerInv; - @Override - public boolean canOpen(Player p) { - return new WorldPlayer(p).isOwnerofWorld(); - } + ArrayList list = new ArrayList<>(members.keySet()); + Inventory inv = Bukkit.createInventory(null, headsPerInv); + for (int i = startPos; i < startPos + length; i++) { + String name = members.get(list.get(i)); + ItemStack is = new ItemStack(GuiConfig.getSkullItem(), 1, (short) 3); + SkullMeta sm = (SkullMeta) is.getItemMeta(); + sm.setOwner(name); + is.setItemMeta(sm); + inv.addItem(is); + } + } + }).start(); + } } diff --git a/WorldSystem/src/de/butzlabben/world/gui/WorldOptionsGUI.java b/WorldSystem/src/de/butzlabben/world/gui/WorldOptionsGUI.java index f599dc9..4fc57f3 100644 --- a/WorldSystem/src/de/butzlabben/world/gui/WorldOptionsGUI.java +++ b/WorldSystem/src/de/butzlabben/world/gui/WorldOptionsGUI.java @@ -21,18 +21,16 @@ public class WorldOptionsGUI extends OrcInventory { private final static String path = "options.world."; public final static HashMap data = new HashMap<>(); - public static WorldOptionsGUI instance; public WorldOptionsGUI() { - super("World Options", GuiConfig.getRows("options.world"), true); - if (instance != null) - return; + super(GuiConfig.getTitle(GuiConfig.getConfig(), "options.world"), GuiConfig.getRows("options.world")); loadItem("fire", "/ws fire", true, new FireStatus()); loadItem("tnt", "/ws tnt", true, new TntStatus()); if (GuiConfig.isEnabled(path + "reset") == false) return; + OrcItem item = GuiConfig.getItem(path + "reset"); if (item != null) { item.setOnClick((p, inv, i) -> { @@ -42,7 +40,14 @@ public class WorldOptionsGUI extends OrcInventory { addItem(GuiConfig.getSlot(path + "reset"), item); } - instance = this; + if (GuiConfig.isEnabled(path + "back")) { + OrcItem back = OrcItem.back.clone(); + back.setOnClick((p, inv, i) -> { + p.closeInventory(); + p.openInventory(new WorldSystemGUI().getInventory(p)); + }); + addItem(GuiConfig.getSlot(path + "back"), back); + } } public void loadItem(String subpath, String message, boolean state, DependListener depend) { @@ -88,7 +93,6 @@ public class WorldOptionsGUI extends OrcInventory { return super.getInventory(p, getTitle()); } - @Override public boolean canOpen(Player p) { return new WorldPlayer(p).isOwnerofWorld(); } diff --git a/WorldSystem/src/de/butzlabben/world/gui/WorldSystemGUI.java b/WorldSystem/src/de/butzlabben/world/gui/WorldSystemGUI.java index 5be5ace..039d9d8 100644 --- a/WorldSystem/src/de/butzlabben/world/gui/WorldSystemGUI.java +++ b/WorldSystem/src/de/butzlabben/world/gui/WorldSystemGUI.java @@ -1,12 +1,13 @@ package de.butzlabben.world.gui; import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; 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.config.MessageConfig; +import de.butzlabben.world.config.WorldConfig; import de.butzlabben.world.gui.clicklistener.InventoryOpenClickListener; public class WorldSystemGUI extends OrcInventory { @@ -14,19 +15,29 @@ public class WorldSystemGUI extends OrcInventory { private final static String path = "worldsystem."; public WorldSystemGUI() { - super("WorldSystem", GuiConfig.getRows("worldsystem"), true); - new WorldOptionsGUI(); - new PlayerOptionsGUI(); + + super(GuiConfig.getTitle(GuiConfig.getConfig(), "worldsystem"), GuiConfig.getRows("worldsystem")); loadItem("playeroptions", (p, inv, item) -> { p.closeInventory(); - PlayersPageGUI ppg = PlayersGUIManager.getFirstPage(p); - if (ppg != null) - p.openInventory(ppg.getInventory(p)); - else - p.sendMessage(MessageConfig.getNoMemberAdded()); + PlayersPageGUI.openGUI(p); }); - loadItem("worldoptions", new InventoryOpenClickListener(WorldOptionsGUI.instance)); + + loadItem("worldoptions", new InventoryOpenClickListener(new WorldOptionsGUI())); + + if (GuiConfig.isEnabled(path + "back")) { + OrcItem back = OrcItem.back.clone(); + back.setOnClick((p, inv, item) -> { + p.closeInventory(); + }); + addItem(GuiConfig.getSlot(path + "back"), back); + } + } + + @Override + public Inventory getInventory(Player player) { + PlayersPageGUI.preloadPlayers(WorldConfig.getWorldConfig(player.getWorld().getName())); + return super.getInventory(player); } public void loadItem(String subpath, OrcClickListener listener) { @@ -43,9 +54,7 @@ public class WorldSystemGUI extends OrcInventory { loadItem(subpath, null); } - @Override public boolean canOpen(Player p) { return true; } - } diff --git a/WorldSystem/src/de/butzlabben/world/gui/clicklistener/CommandExecutorClickListener.java b/WorldSystem/src/de/butzlabben/world/gui/clicklistener/CommandExecutorClickListener.java index 6ddf59b..ded3bb9 100644 --- a/WorldSystem/src/de/butzlabben/world/gui/clicklistener/CommandExecutorClickListener.java +++ b/WorldSystem/src/de/butzlabben/world/gui/clicklistener/CommandExecutorClickListener.java @@ -5,7 +5,6 @@ import org.bukkit.entity.Player; import de.butzlabben.inventory.OrcClickListener; import de.butzlabben.inventory.OrcInventory; import de.butzlabben.inventory.OrcItem; -import de.butzlabben.world.gui.PlayerOptionsGUI; public class CommandExecutorClickListener implements OrcClickListener { @@ -19,8 +18,7 @@ public class CommandExecutorClickListener implements OrcClickListener { public void onClick(Player p, OrcInventory inv, OrcItem item) { p.closeInventory(); String msg = message; - if(PlayerOptionsGUI.data.containsKey(p.getUniqueId())) - msg = message.replaceAll("%data", PlayerOptionsGUI.data.get(p.getUniqueId())); p.chat(msg); + inv.redraw(p); } } diff --git a/WorldSystem/src/de/butzlabben/world/gui/clicklistener/InventoryOpenClickListener.java b/WorldSystem/src/de/butzlabben/world/gui/clicklistener/InventoryOpenClickListener.java index 9622083..afcd92e 100644 --- a/WorldSystem/src/de/butzlabben/world/gui/clicklistener/InventoryOpenClickListener.java +++ b/WorldSystem/src/de/butzlabben/world/gui/clicklistener/InventoryOpenClickListener.java @@ -18,8 +18,8 @@ public class InventoryOpenClickListener implements OrcClickListener { @Override public void onClick(Player p, OrcInventory inv, OrcItem item) { + p.closeInventory(); if (open == null) { - p.closeInventory(); return; } Inventory to = open.getInventory(p); diff --git a/WorldSystem/src/de/butzlabben/world/gui/playeroption/BuildStatus.java b/WorldSystem/src/de/butzlabben/world/gui/playeroption/BuildStatus.java index 5bdfed2..f6fe65d 100644 --- a/WorldSystem/src/de/butzlabben/world/gui/playeroption/BuildStatus.java +++ b/WorldSystem/src/de/butzlabben/world/gui/playeroption/BuildStatus.java @@ -1,20 +1,22 @@ package de.butzlabben.world.gui.playeroption; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import de.butzlabben.inventory.DependListener; import de.butzlabben.inventory.OrcItem; -import de.butzlabben.world.gui.PlayerOptionsGUI; import de.butzlabben.world.wrapper.WorldPlayer; public class BuildStatus implements DependListener { + + private final WorldPlayer wp; + + public BuildStatus(WorldPlayer wp) { + this.wp = wp; + } - @SuppressWarnings("deprecation") @Override - public ItemStack getItemStack(Player p, WorldPlayer wp) { - wp = new WorldPlayer(Bukkit.getOfflinePlayer(PlayerOptionsGUI.data.get(p.getUniqueId())), p.getWorld().getName()); - return wp.canBuild() ? OrcItem.enabled.getItemStack(p, wp) : null; + public ItemStack getItemStack(Player p, WorldPlayer player) { + return wp.canBuild() ? OrcItem.enabled.getItemStack(p, wp) : OrcItem.disabled.getItemStack(p, wp); } } diff --git a/WorldSystem/src/de/butzlabben/world/gui/playeroption/GamemodeStatus.java b/WorldSystem/src/de/butzlabben/world/gui/playeroption/GamemodeStatus.java index be83cb2..1b72cf1 100644 --- a/WorldSystem/src/de/butzlabben/world/gui/playeroption/GamemodeStatus.java +++ b/WorldSystem/src/de/butzlabben/world/gui/playeroption/GamemodeStatus.java @@ -1,20 +1,22 @@ package de.butzlabben.world.gui.playeroption; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import de.butzlabben.inventory.DependListener; import de.butzlabben.inventory.OrcItem; -import de.butzlabben.world.gui.PlayerOptionsGUI; import de.butzlabben.world.wrapper.WorldPlayer; public class GamemodeStatus implements DependListener { - @SuppressWarnings("deprecation") + private final WorldPlayer wp; + + public GamemodeStatus(WorldPlayer wp) { + this.wp = wp; + } + @Override - public ItemStack getItemStack(Player p, WorldPlayer wp) { - wp = new WorldPlayer(Bukkit.getOfflinePlayer(PlayerOptionsGUI.data.get(p.getUniqueId())), p.getWorld().getName()); - return wp.canChangeGamemode() ? OrcItem.enabled.getItemStack(p, wp) : null; + public ItemStack getItemStack(Player p, WorldPlayer player) { + return wp.canChangeGamemode() ? OrcItem.enabled.getItemStack(p, wp) : OrcItem.disabled.getItemStack(p, wp); } } \ No newline at end of file diff --git a/WorldSystem/src/de/butzlabben/world/gui/playeroption/TeleportStatus.java b/WorldSystem/src/de/butzlabben/world/gui/playeroption/TeleportStatus.java index 15a9255..e39aaaa 100644 --- a/WorldSystem/src/de/butzlabben/world/gui/playeroption/TeleportStatus.java +++ b/WorldSystem/src/de/butzlabben/world/gui/playeroption/TeleportStatus.java @@ -1,20 +1,22 @@ package de.butzlabben.world.gui.playeroption; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import de.butzlabben.inventory.DependListener; import de.butzlabben.inventory.OrcItem; -import de.butzlabben.world.gui.PlayerOptionsGUI; import de.butzlabben.world.wrapper.WorldPlayer; -public class TeleportStatus implements DependListener { - - @SuppressWarnings("deprecation") +public class TeleportStatus implements DependListener { + + private final WorldPlayer wp; + + public TeleportStatus(WorldPlayer wp) { + this.wp = wp; + } + @Override - public ItemStack getItemStack(Player p, WorldPlayer wp) { - wp = new WorldPlayer(Bukkit.getOfflinePlayer(PlayerOptionsGUI.data.get(p.getUniqueId())), p.getWorld().getName()); - return wp.canTeleport() ? OrcItem.enabled.getItemStack(p, wp) : null; + public ItemStack getItemStack(Player p, WorldPlayer player) { + return wp.canTeleport() ? OrcItem.enabled.getItemStack(p, wp) : OrcItem.disabled.getItemStack(p, wp); } } \ No newline at end of file diff --git a/WorldSystem/src/de/butzlabben/world/gui/worldoption/FireStatus.java b/WorldSystem/src/de/butzlabben/world/gui/worldoption/FireStatus.java index 9977dfe..827182b 100644 --- a/WorldSystem/src/de/butzlabben/world/gui/worldoption/FireStatus.java +++ b/WorldSystem/src/de/butzlabben/world/gui/worldoption/FireStatus.java @@ -25,7 +25,7 @@ public class FireStatus implements DependListener { YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); boolean b = cfg.getBoolean("Settings.Fire"); if (b) - return OrcItem.enabled.getItemStack(p, wp); + return OrcItem.enabled.getItemStack(p); return null; // TODO wenn enabled, dann return OrcItem.enabled.getItemStack(p, wp); diff --git a/WorldSystem/src/de/butzlabben/world/gui/worldoption/TntStatus.java b/WorldSystem/src/de/butzlabben/world/gui/worldoption/TntStatus.java index f48ef0c..1303bd0 100644 --- a/WorldSystem/src/de/butzlabben/world/gui/worldoption/TntStatus.java +++ b/WorldSystem/src/de/butzlabben/world/gui/worldoption/TntStatus.java @@ -25,7 +25,7 @@ public class TntStatus implements DependListener { YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); boolean b = cfg.getBoolean("Settings.TNTDamage"); if (b) - return OrcItem.enabled.getItemStack(p, wp); + return OrcItem.enabled.getItemStack(p); return null; // TODO wenn enabled, dann return OrcItem.enabled.getItemStack(p, wp); diff --git a/WorldSystem/src/old_gui.yml b/WorldSystem/src/old_gui.yml index 9a25f8e..3f64ca3 100644 --- a/WorldSystem/src/old_gui.yml +++ b/WorldSystem/src/old_gui.yml @@ -24,11 +24,27 @@ options: material: INK_SACK data: 14 display: '&6Coming soon...' + + # How the back item should look like + back: + material: BARRIER + display: '&cBack' # WorldoptionsGUI world: + # What the title of the Inv should be + title: 'World Options' + # Rows - rows: 2 + rows: 3 + + # Where the back item should be + back: + enabled: true + slot: + row: 3 + col: 5 + # Reset button reset: # If feature should be enabled or not @@ -66,38 +82,54 @@ options: display: '&eToggle TNT-Explosion' players: - skull_item: - material: SKULL_ITEM + title: 'Players added to this world' + + back: + enabled: true + slot: + row: 6 + col: 6 rows: 6 + nextpage: enabled: true slot: row: 6 - col: 9 + col: 8 material: PAPER display: '&eNext Page' pagebefore: enabled: true slot: row: 6 - col: 1 + col: 2 material: PAPER display: '&ePage before' currentpage: enabled: true slot: row: 6 - col: 5 + col: 4 material: DOUBLE_PLANT display: '&eCurrent page: &a%page' player_list_to_row: 4 playerhead: + material: SKULL_ITEM display: '&e%player' # PlayerGUI for managing one player on a world player: - rows: 2 + title: 'Player options for %player' + + back: + enabled: true + slot: + row: 3 + col: 5 + + rows: 3 + build: enabled: true slot: @@ -205,18 +237,27 @@ options: # WorldsystemGUI worldsystem: + title: 'WorldSystem' + rows: 1 + + back: + enabled: true + slot: + row: 1 + col: 5 + playeroptions: enabled: true slot: row: 1 - col: 4 + col: 1 material: LEATHER_HELMET display: '&ePlayer Options' worldoptions: enabled: true slot: row: 1 - col: 6 + col: 9 material: GRASS display: '&eWorld Options' \ No newline at end of file diff --git a/WorldSystem/src/plugin.yml b/WorldSystem/src/plugin.yml index 75e7831..8fd86f4 100644 --- a/WorldSystem/src/plugin.yml +++ b/WorldSystem/src/plugin.yml @@ -1,5 +1,5 @@ name: WorldSystem -version: 2.3.0 +version: 2.3.1 author: Butzlabben main: de.butzlabben.world.WorldSystem