diff --git a/pom.xml b/pom.xml index 39f9b16..5048816 100644 --- a/pom.xml +++ b/pom.xml @@ -1,9 +1,9 @@ - 4.0.0 de.butzlabben.world WorldSystem - 2.4.6.2 + 2.4.6.3 UTF-8 diff --git a/src/main/java/de/butzlabben/inventory/CostumInv.java b/src/main/java/de/butzlabben/inventory/CostumInv.java index 4553008..a5472f8 100644 --- a/src/main/java/de/butzlabben/inventory/CostumInv.java +++ b/src/main/java/de/butzlabben/inventory/CostumInv.java @@ -6,11 +6,11 @@ package de.butzlabben.inventory; */ 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); - } + public CostumInv(String title, int rows) { + super(title, rows); + } + + public CostumInv(String title, int rows, boolean fill) { + super(title, rows, fill); + } } diff --git a/src/main/java/de/butzlabben/inventory/DependListener.java b/src/main/java/de/butzlabben/inventory/DependListener.java index aed1a9b..e8946db 100644 --- a/src/main/java/de/butzlabben/inventory/DependListener.java +++ b/src/main/java/de/butzlabben/inventory/DependListener.java @@ -5,7 +5,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; public interface DependListener { - - ItemStack getItemStack(Player p, WorldPlayer wp); + + ItemStack getItemStack(Player p, WorldPlayer wp); } diff --git a/src/main/java/de/butzlabben/inventory/OrcClickListener.java b/src/main/java/de/butzlabben/inventory/OrcClickListener.java index 07329b4..1da2d87 100644 --- a/src/main/java/de/butzlabben/inventory/OrcClickListener.java +++ b/src/main/java/de/butzlabben/inventory/OrcClickListener.java @@ -3,7 +3,7 @@ package de.butzlabben.inventory; import org.bukkit.entity.Player; public interface OrcClickListener { - - void onClick(Player p, OrcInventory inv, OrcItem item); + + void onClick(Player p, OrcInventory inv, OrcItem item); } diff --git a/src/main/java/de/butzlabben/inventory/OrcInventory.java b/src/main/java/de/butzlabben/inventory/OrcInventory.java index 12a96f3..f551fe7 100644 --- a/src/main/java/de/butzlabben/inventory/OrcInventory.java +++ b/src/main/java/de/butzlabben/inventory/OrcInventory.java @@ -11,101 +11,100 @@ import java.util.Objects; public abstract class OrcInventory { - protected String title; - private int rows; - private InventoryType type; - protected final HashMap items = new HashMap<>(); + protected String title; + private int rows; + private InventoryType type; - public OrcInventory(String title) { - Objects.requireNonNull(title, "title cannot be null"); - this.title = title; - } + public OrcInventory(String title) { + Objects.requireNonNull(title, "title cannot be null"); + this.title = title; + } - 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, int rows, boolean fill) { - this(title, rows); - if(fill) { - for (int i = 0; i < rows * 9; i++) { - items.put(i, OrcItem.fill); - } - } - } + 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) { - this(title); - if (type == null || type == InventoryType.CHEST) { - this.type = null; - rows = 3; - } else { - this.type = type; - } - } + public OrcInventory(String title, int rows, boolean fill) { + this(title, rows); + if (fill) { + for (int i = 0; i < rows * 9; i++) { + items.put(i, OrcItem.fill); + } + } + } - public void addItem(int slot, OrcItem item) { - if (item == null) { - removeItem(slot); - } else { - items.put(slot, item); - } - } + public OrcInventory(String title, InventoryType type) { + this(title); + if (type == null || type == InventoryType.CHEST) { + this.type = null; + rows = 3; + } else { + this.type = type; + } + } - public void addItem(int row, int col, OrcItem item) { - addItem(row * 9 + col, item); - } + public void addItem(int slot, OrcItem item) { + if (item == null) { + removeItem(slot); + } else { + items.put(slot, item); + } + } - public void removeItem(int slot) { - items.remove(slot); - } + public void addItem(int row, int col, OrcItem item) { + addItem(row * 9 + col, item); + } - public void removeItem(int row, int col) { - removeItem(row * 9 + col); - } + public void removeItem(int slot) { + items.remove(slot); + } - public Inventory getInventory(Player p) { - return getInventory(p, title); - } - - public void redraw(Player p) { - p.closeInventory(); - p.openInventory(getInventory(p)); - } + public void removeItem(int row, int col) { + removeItem(row * 9 + col); + } - public Inventory getInventory(Player p, String title) { - Inventory inv; - int size; - if (type == null) { - inv = Bukkit.createInventory(null, rows * 9, title); - size = rows * 9; - } else { - inv = Bukkit.createInventory(null, type, title); - size = type.getDefaultSize(); - } + public Inventory getInventory(Player p) { + return getInventory(p, title); + } - for (Entry entry : items.entrySet()) { - if (entry.getKey() >= 0 && entry.getKey() < size) { - inv.setItem(entry.getKey(), entry.getValue().getItemStack(p)); - } else { - System.err.println("There is a problem with a configured Item!"); - } - } + public void redraw(Player p) { + p.closeInventory(); + p.openInventory(getInventory(p)); + } - OrcListener.getInstance().register(p.getUniqueId(), this); - - return inv; - } + public Inventory getInventory(Player p, String title) { + Inventory inv; + int size; + if (type == null) { + inv = Bukkit.createInventory(null, rows * 9, title); + size = rows * 9; + } else { + inv = Bukkit.createInventory(null, type, title); + size = type.getDefaultSize(); + } - public void setTitle(String title) { - this.title = title; - } + for (Entry entry : items.entrySet()) { + if (entry.getKey() >= 0 && entry.getKey() < size) { + inv.setItem(entry.getKey(), entry.getValue().getItemStack(p)); + } else { + System.err.println("There is a problem with a configured Item!"); + } + } - public String getTitle() { - return title; - } + OrcListener.getInstance().register(p.getUniqueId(), this); + + return inv; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } } diff --git a/src/main/java/de/butzlabben/inventory/OrcItem.java b/src/main/java/de/butzlabben/inventory/OrcItem.java index 26f741c..6459d7a 100644 --- a/src/main/java/de/butzlabben/inventory/OrcItem.java +++ b/src/main/java/de/butzlabben/inventory/OrcItem.java @@ -14,130 +14,129 @@ import java.util.Objects; public class OrcItem { - public static OrcItem enabled; - public static OrcItem disabled; - public static OrcItem coming_soon; - public static OrcItem back; - public static OrcItem fill; - public static final OrcItem error = new OrcItem(Material.BARRIER, null, - "§cERROR: Item is wrong configured!", "§cPath in config: see Displayname"); + public static final OrcItem error = new OrcItem(Material.BARRIER, null, + "§cERROR: Item is wrong configured!", "§cPath in config: see Displayname"); + public static OrcItem enabled; + public static OrcItem disabled; + public static OrcItem coming_soon; + public static OrcItem back; + public static OrcItem fill; + private ItemStack is; + private OrcClickListener listener; + private DependListener depend; + private Runnable callback; - private ItemStack is; - private OrcClickListener listener; - private DependListener depend; - private Runnable callback; + public OrcItem(Material mat, String display, String... lore) { + setItemStack(mat, display, lore); + } - public void setCallback(Runnable r) { - callback = r; - } + public OrcItem(ItemStack is) { + setItemStack(is); + } - public OrcItem(Material mat, String display, String... lore) { - setItemStack(mat, display, lore); - } + public OrcItem(Material mat, String display, List lore) { + setItemStack(mat, (byte) 0, display, lore); + } - public OrcItem(ItemStack is) { - setItemStack(is); - } + public OrcItem(Material mat) { + this(new ItemStack(mat)); + } - public OrcItem(Material mat, String display, List lore) { - setItemStack(mat, (byte) 0, display, lore); - } + public OrcItem(Material material, byte data, String display, ArrayList lore) { + setItemStack(material, data, display, lore); + } - public OrcItem(Material mat) { - this(new ItemStack(mat)); - } + public void setCallback(Runnable r) { + callback = r; + } - public OrcItem(Material material, byte data, String display, ArrayList lore) { - setItemStack(material, data, display, lore); - } + @SuppressWarnings("deprecation") + 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; + } - @SuppressWarnings("deprecation") - 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) { - 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); - 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); + if (is != null) + return is; + } + return is; + } - public ItemStack getItemStack() { - return is; - } + public ItemStack getItemStack() { + return is; + } - public OrcItem setOnClick(OrcClickListener listener) { - this.listener = listener; - return this; - } + 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 onClick(Player p, OrcInventory inv) { - if (listener != null) { - listener.onClick(p, inv, this); - } - if (callback != null) - callback.run(); - return this; - } + public OrcItem setOnClick(OrcClickListener listener) { + this.listener = listener; + return this; + } - public OrcItem setDisplay(String display) { - ItemMeta meta = is.getItemMeta(); - meta.setDisplayName(display); - is.setItemMeta(meta); - return this; - } + public OrcItem onClick(Player p, OrcInventory inv) { + if (listener != null) { + listener.onClick(p, inv, this); + } + if (callback != null) + callback.run(); + return this; + } - public OrcItem setLore(String... lore) { - ItemMeta meta = is.getItemMeta(); - meta.setLore(Arrays.asList(lore)); - is.setItemMeta(meta); - return this; - } + public OrcItem setDisplay(String display) { + ItemMeta meta = is.getItemMeta(); + meta.setDisplayName(display); + is.setItemMeta(meta); + return this; + } - public OrcItem removeLore() { - ItemMeta meta = is.getItemMeta(); - meta.setLore(null); - is.setItemMeta(meta); - return this; - } + public OrcItem setLore(String... lore) { + ItemMeta meta = is.getItemMeta(); + meta.setLore(Arrays.asList(lore)); + is.setItemMeta(meta); + return this; + } - 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 removeLore() { + ItemMeta meta = is.getItemMeta(); + meta.setLore(null); + is.setItemMeta(meta); + return this; + } - public OrcItem setItemStack(Material mat, String display, String... lore) { - return setItemStack(mat, (byte) 0, display, Arrays.asList(lore)); - } + public OrcItem setItemStack(Material mat, String display, String... lore) { + return setItemStack(mat, (byte) 0, display, Arrays.asList(lore)); + } - public OrcItem setDepend(DependListener listener) { - depend = listener; - return this; - } + public OrcItem setDepend(DependListener listener) { + depend = listener; + return this; + } - public OrcItem clone() { - return new OrcItem(is); - } + public OrcItem clone() { + return new OrcItem(is); + } } diff --git a/src/main/java/de/butzlabben/inventory/OrcListener.java b/src/main/java/de/butzlabben/inventory/OrcListener.java index 661c419..34ecc84 100644 --- a/src/main/java/de/butzlabben/inventory/OrcListener.java +++ b/src/main/java/de/butzlabben/inventory/OrcListener.java @@ -17,38 +17,38 @@ import java.util.UUID; */ public class OrcListener implements Listener { - private static OrcListener instance; - - private final HashMap invs = new HashMap<>(); + private static OrcListener instance; - public static synchronized OrcListener getInstance() { - if (instance == null) - instance = new OrcListener(); - return instance; - } + private final HashMap invs = new HashMap<>(); - 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.remove(e.getPlayer().getUniqueId()); - } - } + private OrcListener() { + Bukkit.getPluginManager().registerEvents(this, WorldSystem.getInstance()); + } + + public static synchronized OrcListener getInstance() { + if (instance == null) + instance = new OrcListener(); + return instance; + } + + @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.remove(e.getPlayer().getUniqueId()); + } + } } diff --git a/src/main/java/de/butzlabben/inventory/pages/InventoryPage.java b/src/main/java/de/butzlabben/inventory/pages/InventoryPage.java index 16d50b3..26fcdf8 100644 --- a/src/main/java/de/butzlabben/inventory/pages/InventoryPage.java +++ b/src/main/java/de/butzlabben/inventory/pages/InventoryPage.java @@ -13,48 +13,47 @@ import org.bukkit.inventory.Inventory; */ public class InventoryPage extends OrcInventory { - InventoryPage next, before = null; + InventoryPage next, before = null; + private int i = 0; - public InventoryPage(String title, int page, int pages) { - super(title, 6); + public InventoryPage(String title, int page, int pages) { + super(title, 6); - YamlConfiguration cfg = GuiConfig.getConfig(); - String path = "options.players.currentpage"; + 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); + 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.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); - } + 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); + } - @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++; - } + public void addItem(OrcItem item) { + if (i > 36) { + System.err.println("More items than allowed in page view"); + return; + } + addItem(i, item); + i++; + } } diff --git a/src/main/java/de/butzlabben/inventory/pages/ItemConverter.java b/src/main/java/de/butzlabben/inventory/pages/ItemConverter.java index a0addbb..b5c3875 100644 --- a/src/main/java/de/butzlabben/inventory/pages/ItemConverter.java +++ b/src/main/java/de/butzlabben/inventory/pages/ItemConverter.java @@ -8,6 +8,6 @@ import de.butzlabben.inventory.OrcItem; */ public interface ItemConverter { - OrcItem convert(T element); - + OrcItem convert(T element); + } diff --git a/src/main/java/de/butzlabben/inventory/pages/PageGUICreator.java b/src/main/java/de/butzlabben/inventory/pages/PageGUICreator.java index 4dcfbc0..22a1cb8 100644 --- a/src/main/java/de/butzlabben/inventory/pages/PageGUICreator.java +++ b/src/main/java/de/butzlabben/inventory/pages/PageGUICreator.java @@ -14,51 +14,51 @@ import java.util.stream.Collectors; */ public class PageGUICreator { - private final int elementsPerPage; - private List invpages; + 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; + public PageGUICreator() { + this(4 * 9); + } - int pages = (int) (Math.ceil((items.size() / (double) elementsPerPage) < 1 ? 1 : Math.ceil((double) items.size() / (double) elementsPerPage))); + public PageGUICreator(int elementsPerPage) { + this.elementsPerPage = elementsPerPage; + } - invpages = new ArrayList<>(pages); + 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; - 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); + int pages = (int) (Math.ceil((items.size() / (double) elementsPerPage) < 1 ? 1 : Math.ceil((double) items.size() / (double) elementsPerPage))); - InventoryPage invpage = new InventoryPage(title, i, pages); - page.forEach(invpage::addItem); - invpages.add(invpage); - } + invpages = new ArrayList<>(pages); - for (int i = 0; i < invpages.size(); i++) { + 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); - 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); - } - } + InventoryPage invpage = new InventoryPage(title, i, pages); + page.forEach(invpage::addItem); + invpages.add(invpage); + } - public void show(Player p) { - p.openInventory(invpages.get(0).getInventory(p)); - } + for (int i = 0; i < invpages.size(); i++) { - public PageGUICreator() { - this(4 * 9); - } - - public List getInvPages() { - return invpages; - } + int beforeIndex = i == 0 ? invpages.size() - 1 : i - 1; + int nextIndex = i == invpages.size() - 1 ? 0 : i + 1; - public PageGUICreator(int elementsPerPage) { - this.elementsPerPage = elementsPerPage; - } + 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 List getInvPages() { + return invpages; + } } diff --git a/src/main/java/de/butzlabben/world/GCRunnable.java b/src/main/java/de/butzlabben/world/GCRunnable.java index 9249633..68d5697 100644 --- a/src/main/java/de/butzlabben/world/GCRunnable.java +++ b/src/main/java/de/butzlabben/world/GCRunnable.java @@ -2,8 +2,8 @@ package de.butzlabben.world; public class GCRunnable implements Runnable { - @Override - public void run() { - new Thread(() -> System.gc()).start(); - } + @Override + public void run() { + new Thread(() -> System.gc()).start(); + } } diff --git a/src/main/java/de/butzlabben/world/GameProfileBuilder.java b/src/main/java/de/butzlabben/world/GameProfileBuilder.java index 9ce5ba0..c1a9bcd 100644 --- a/src/main/java/de/butzlabben/world/GameProfileBuilder.java +++ b/src/main/java/de/butzlabben/world/GameProfileBuilder.java @@ -21,113 +21,113 @@ import java.util.*; */ public class GameProfileBuilder { - private static final Gson gson = new GsonBuilder().disableHtmlEscaping() - .registerTypeAdapter(UUID.class, new UUIDTypeAdapter()) - .registerTypeAdapter(GameProfile.class, new GameProfileSerializer()) - .registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()).create(); - private static final HashMap cache = new HashMap<>(); - private static long cacheTime = -1L; - private static final Object sync = new Object(); + private static final Gson gson = new GsonBuilder().disableHtmlEscaping() + .registerTypeAdapter(UUID.class, new UUIDTypeAdapter()) + .registerTypeAdapter(GameProfile.class, new GameProfileSerializer()) + .registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()).create(); + private static final HashMap cache = new HashMap<>(); + private static final Object sync = new Object(); + private static long cacheTime = -1L; - public static GameProfile fetch(UUID uuid) throws IOException { - return fetch(uuid, false); - } + public static GameProfile fetch(UUID uuid) throws IOException { + return fetch(uuid, false); + } - public static GameProfile fetch(UUID uuid, boolean forceNew) throws IOException { - if ((!forceNew) && (cache.containsKey(uuid)) && (cache.get(uuid).isValid())) { - return cache.get(uuid).profile; - } - - HttpURLConnection connection; - synchronized (sync) { - connection = (HttpURLConnection) new URL( - String.format("https://sessionserver.mojang.com/session/minecraft/profile/%s?unsigned=false", - UUIDTypeAdapter.fromUUID(uuid))).openConnection(); - connection.setReadTimeout(5000); - } - if (connection.getResponseCode() == 200) { - String json = new BufferedReader(new InputStreamReader(connection.getInputStream())).readLine(); + public static GameProfile fetch(UUID uuid, boolean forceNew) throws IOException { + if ((!forceNew) && (cache.containsKey(uuid)) && (cache.get(uuid).isValid())) { + return cache.get(uuid).profile; + } - GameProfile result = gson.fromJson(json, GameProfile.class); - cache.put(uuid, new CachedProfile(result)); - return result; - } - if ((!forceNew) && (cache.containsKey(uuid))) { - return cache.get(uuid).profile; - } - throw new IOException("Could not connect to mojang servers for unknown player: " + uuid.toString()); - } + HttpURLConnection connection; + synchronized (sync) { + connection = (HttpURLConnection) new URL( + String.format("https://sessionserver.mojang.com/session/minecraft/profile/%s?unsigned=false", + UUIDTypeAdapter.fromUUID(uuid))).openConnection(); + connection.setReadTimeout(5000); + } + if (connection.getResponseCode() == 200) { + String json = new BufferedReader(new InputStreamReader(connection.getInputStream())).readLine(); - public static GameProfile getProfile(UUID uuid, String name, String skin) { - return getProfile(uuid, name, skin, null); - } + GameProfile result = gson.fromJson(json, GameProfile.class); + cache.put(uuid, new CachedProfile(result)); + return result; + } + if ((!forceNew) && (cache.containsKey(uuid))) { + return cache.get(uuid).profile; + } + throw new IOException("Could not connect to mojang servers for unknown player: " + uuid.toString()); + } - public static GameProfile getProfile(UUID uuid, String name, String skinUrl, String capeUrl) { - GameProfile profile = new GameProfile(uuid, name); - boolean cape = (capeUrl != null) && (!capeUrl.isEmpty()); + public static GameProfile getProfile(UUID uuid, String name, String skin) { + return getProfile(uuid, name, skin, null); + } - List args = new ArrayList<>(); - args.add(Long.valueOf(System.currentTimeMillis())); - args.add(UUIDTypeAdapter.fromUUID(uuid)); - args.add(name); - args.add(skinUrl); - if (cape) { - args.add(capeUrl); - } - profile.getProperties().put("textures", - new Property("textures", - Base64Coder.encodeString(String.format( - cape ? "{\"timestamp\":%d,\"profileId\":\"%s\",\"profileName\":\"%s\",\"isPublic\":true,\"textures\":{\"SKIN\":{\"url\":\"%s\"},\"CAPE\":{\"url\":\"%s\"}}}" - : "{\"timestamp\":%d,\"profileId\":\"%s\",\"profileName\":\"%s\",\"isPublic\":true,\"textures\":{\"SKIN\":{\"url\":\"%s\"}}}", - args.toArray(new Object[0]))))); - return profile; - } + public static GameProfile getProfile(UUID uuid, String name, String skinUrl, String capeUrl) { + GameProfile profile = new GameProfile(uuid, name); + boolean cape = (capeUrl != null) && (!capeUrl.isEmpty()); - public static void setCacheTime(long time) { - cacheTime = time; - } + List args = new ArrayList<>(); + args.add(Long.valueOf(System.currentTimeMillis())); + args.add(UUIDTypeAdapter.fromUUID(uuid)); + args.add(name); + args.add(skinUrl); + if (cape) { + args.add(capeUrl); + } + profile.getProperties().put("textures", + new Property("textures", + Base64Coder.encodeString(String.format( + cape ? "{\"timestamp\":%d,\"profileId\":\"%s\",\"profileName\":\"%s\",\"isPublic\":true,\"textures\":{\"SKIN\":{\"url\":\"%s\"},\"CAPE\":{\"url\":\"%s\"}}}" + : "{\"timestamp\":%d,\"profileId\":\"%s\",\"profileName\":\"%s\",\"isPublic\":true,\"textures\":{\"SKIN\":{\"url\":\"%s\"}}}", + args.toArray(new Object[0]))))); + return profile; + } - private static class GameProfileSerializer implements JsonSerializer, JsonDeserializer { + public static void setCacheTime(long time) { + cacheTime = time; + } - public GameProfile deserialize(JsonElement json, Type type, JsonDeserializationContext context) - throws JsonParseException { - JsonObject object = (JsonObject) json; - UUID id = object.has("id") ? (UUID) context.deserialize(object.get("id"), UUID.class) : null; - String name = object.has("name") ? object.getAsJsonPrimitive("name").getAsString() : null; - GameProfile profile = new GameProfile(id, name); - if (object.has("properties")) { - for (Map.Entry prop : ((PropertyMap) context.deserialize(object.get("properties"), - PropertyMap.class)).entries()) { - profile.getProperties().put(prop.getKey(), prop.getValue()); - } - } - return profile; - } + private static class GameProfileSerializer implements JsonSerializer, JsonDeserializer { - public JsonElement serialize(GameProfile profile, Type type, JsonSerializationContext context) { - JsonObject result = new JsonObject(); - if (profile.getId() != null) { - result.add("id", context.serialize(profile.getId())); - } - if (profile.getName() != null) { - result.addProperty("name", profile.getName()); - } - if (!profile.getProperties().isEmpty()) { - result.add("properties", context.serialize(profile.getProperties())); - } - return result; - } - } + public GameProfile deserialize(JsonElement json, Type type, JsonDeserializationContext context) + throws JsonParseException { + JsonObject object = (JsonObject) json; + UUID id = object.has("id") ? (UUID) context.deserialize(object.get("id"), UUID.class) : null; + String name = object.has("name") ? object.getAsJsonPrimitive("name").getAsString() : null; + GameProfile profile = new GameProfile(id, name); + if (object.has("properties")) { + for (Map.Entry prop : ((PropertyMap) context.deserialize(object.get("properties"), + PropertyMap.class)).entries()) { + profile.getProperties().put(prop.getKey(), prop.getValue()); + } + } + return profile; + } - private static class CachedProfile { - private final GameProfile profile; + public JsonElement serialize(GameProfile profile, Type type, JsonSerializationContext context) { + JsonObject result = new JsonObject(); + if (profile.getId() != null) { + result.add("id", context.serialize(profile.getId())); + } + if (profile.getName() != null) { + result.addProperty("name", profile.getName()); + } + if (!profile.getProperties().isEmpty()) { + result.add("properties", context.serialize(profile.getProperties())); + } + return result; + } + } - public CachedProfile(GameProfile profile) { - this.profile = profile; - } + private static class CachedProfile { + private final GameProfile profile; - public boolean isValid() { - return GameProfileBuilder.cacheTime < 0L; - } - } + public CachedProfile(GameProfile profile) { + this.profile = profile; + } + + public boolean isValid() { + return GameProfileBuilder.cacheTime < 0L; + } + } } diff --git a/src/main/java/de/butzlabben/world/WorldCheckerRunnable.java b/src/main/java/de/butzlabben/world/WorldCheckerRunnable.java index 7e09a14..78a1054 100644 --- a/src/main/java/de/butzlabben/world/WorldCheckerRunnable.java +++ b/src/main/java/de/butzlabben/world/WorldCheckerRunnable.java @@ -11,38 +11,38 @@ import org.bukkit.entity.Player; public class WorldCheckerRunnable implements Runnable { - @Override - public void run() { - for (World world : Bukkit.getWorlds()) { - if (SystemWorld.getSystemWorld(world.getName()) == null || !SystemWorld.getSystemWorld(world.getName()).isLoaded()) - continue; - int other = world.getEntities().size() - world.getPlayers().size(); - if (other > PluginConfig.getEntitysPerWorld()) { - String worldname = world.getName(); - for (Entity e : world.getEntities()) { - if (!(e instanceof Player)) { - e.remove(); - } - } - String ownerofWorld = null; - for (OfflinePlayer p : Bukkit.getOfflinePlayers()) { - if (p.getUniqueId().toString() - .equals(worldname.substring(worldname.length() - 36))) - ownerofWorld = p.getName(); - } - StringBuilder members = new StringBuilder(); - for (Player p : world.getPlayers()) { - members.append(p.getName()).append(" "); - } - for (Player p : Bukkit.getOnlinePlayers()) { - if (!p.hasPermission("ws.lag")) - continue; - p.sendMessage(MessageConfig.getLagDetection().replaceAll("%world", - ownerofWorld + " ( ID: " + world.getName().substring(2, worldname.length() - 37) + " )")); - p.sendMessage(MessageConfig.getPlayerList().replaceAll("%players", members.toString())); + @Override + public void run() { + for (World world : Bukkit.getWorlds()) { + if (SystemWorld.getSystemWorld(world.getName()) == null || !SystemWorld.getSystemWorld(world.getName()).isLoaded()) + continue; + int other = world.getEntities().size() - world.getPlayers().size(); + if (other > PluginConfig.getEntitysPerWorld()) { + String worldname = world.getName(); + for (Entity e : world.getEntities()) { + if (!(e instanceof Player)) { + e.remove(); + } + } + String ownerofWorld = null; + for (OfflinePlayer p : Bukkit.getOfflinePlayers()) { + if (p.getUniqueId().toString() + .equals(worldname.substring(worldname.length() - 36))) + ownerofWorld = p.getName(); + } + StringBuilder members = new StringBuilder(); + for (Player p : world.getPlayers()) { + members.append(p.getName()).append(" "); + } + for (Player p : Bukkit.getOnlinePlayers()) { + if (!p.hasPermission("ws.lag")) + continue; + p.sendMessage(MessageConfig.getLagDetection().replaceAll("%world", + ownerofWorld + " ( ID: " + world.getName().substring(2, worldname.length() - 37) + " )")); + p.sendMessage(MessageConfig.getPlayerList().replaceAll("%players", members.toString())); - } - } - } - } + } + } + } + } } diff --git a/src/main/java/de/butzlabben/world/WorldSystem.java b/src/main/java/de/butzlabben/world/WorldSystem.java index d121270..434a8fe 100644 --- a/src/main/java/de/butzlabben/world/WorldSystem.java +++ b/src/main/java/de/butzlabben/world/WorldSystem.java @@ -31,11 +31,62 @@ import java.io.IOException; */ public class WorldSystem extends JavaPlugin { + private static boolean is1_13Plus = false; final private String version = this.getDescription().getVersion(); - private CreatorAdapter creator; - private static boolean is1_13Plus = false; + public static void createConfigs() { + File dir = new File(JavaPlugin.getPlugin(WorldSystem.class).getDataFolder() + "/worldsources"); + File config = new File(JavaPlugin.getPlugin(WorldSystem.class).getDataFolder(), "config.yml"); + File dconfig = new File(JavaPlugin.getPlugin(WorldSystem.class).getDataFolder(), "dependence.yml"); + File languages = new File(JavaPlugin.getPlugin(WorldSystem.class).getDataFolder() + "/languages"); + File gui = new File(JavaPlugin.getPlugin(WorldSystem.class).getDataFolder(), "gui.yml"); + if (!dir.exists()) { + dir.mkdirs(); + } + if (!languages.exists()) + languages.mkdirs(); + PluginConfig.checkConfig(config); + + // Done with #6 + MessageConfig.checkConfig(new File(languages, "en.yml")); + + MessageConfig.checkConfig(new File(languages, "de.yml")); + MessageConfig.checkConfig(new File(languages, "hu.yml")); + MessageConfig.checkConfig(new File(languages, "nl.yml")); + MessageConfig.checkConfig(new File(languages, "pl.yml")); + MessageConfig.checkConfig(new File(languages, "es.yml")); + MessageConfig.checkConfig(new File(languages, "ru.yml")); + MessageConfig.checkConfig(new File(languages, "fi.yml")); + // Here we are for #5 + MessageConfig.checkConfig(new File(languages, "zh.yml")); + MessageConfig.checkConfig(new File(languages, "fr.yml")); + MessageConfig.checkConfig(new File(languages, PluginConfig.getLanguage() + ".yml")); + if (!dconfig.exists()) { + try { + dconfig.createNewFile(); + } catch (IOException e) { + System.err.println("Wasn't able to create DependenceConfig"); + e.printStackTrace(); + } + new DependenceConfig(); + } + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(config); + SettingsConfig.checkConfig(); + File worlddir = new File(cfg.getString("worldfolder")); + if (!worlddir.exists()) { + worlddir.mkdirs(); + } + GuiConfig.checkConfig(gui); + } + + public static WorldSystem getInstance() { + return JavaPlugin.getPlugin(WorldSystem.class); + } + + public static boolean is1_13() { + return is1_13Plus; + } @Override public void onEnable() { @@ -117,7 +168,7 @@ public class WorldSystem extends JavaPlugin { DependenceConfig.checkWorlds(); } - if(Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) + if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) new PapiExtension().register(); Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "Succesfully enabled WorldSystem v" + version); @@ -139,60 +190,7 @@ public class WorldSystem extends JavaPlugin { .sendMessage(PluginConfig.getPrefix() + "Succesfully disabled WorldSystem v" + version); } - public static void createConfigs() { - File dir = new File(JavaPlugin.getPlugin(WorldSystem.class).getDataFolder() + "/worldsources"); - File config = new File(JavaPlugin.getPlugin(WorldSystem.class).getDataFolder(), "config.yml"); - File dconfig = new File(JavaPlugin.getPlugin(WorldSystem.class).getDataFolder(), "dependence.yml"); - File languages = new File(JavaPlugin.getPlugin(WorldSystem.class).getDataFolder() + "/languages"); - File gui = new File(JavaPlugin.getPlugin(WorldSystem.class).getDataFolder(), "gui.yml"); - if (!dir.exists()) { - dir.mkdirs(); - } - if (!languages.exists()) - languages.mkdirs(); - PluginConfig.checkConfig(config); - - // Done with #6 - MessageConfig.checkConfig(new File(languages, "en.yml")); - - MessageConfig.checkConfig(new File(languages, "de.yml")); - MessageConfig.checkConfig(new File(languages, "hu.yml")); - MessageConfig.checkConfig(new File(languages, "nl.yml")); - MessageConfig.checkConfig(new File(languages, "pl.yml")); - MessageConfig.checkConfig(new File(languages, "es.yml")); - MessageConfig.checkConfig(new File(languages, "ru.yml")); - MessageConfig.checkConfig(new File(languages, "fi.yml")); - // Here we are for #5 - MessageConfig.checkConfig(new File(languages, "zh.yml")); - MessageConfig.checkConfig(new File(languages, "fr.yml")); - MessageConfig.checkConfig(new File(languages, PluginConfig.getLanguage() + ".yml")); - if (!dconfig.exists()) { - try { - dconfig.createNewFile(); - } catch (IOException e) { - System.err.println("Wasn't able to create DependenceConfig"); - e.printStackTrace(); - } - new DependenceConfig(); - } - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(config); - SettingsConfig.checkConfig(); - File worlddir = new File(cfg.getString("worldfolder")); - if (!worlddir.exists()) { - worlddir.mkdirs(); - } - GuiConfig.checkConfig(gui); - } - - public static WorldSystem getInstance() { - return JavaPlugin.getPlugin(WorldSystem.class); - } - public CreatorAdapter getAdapter() { return creator; } - - public static boolean is1_13() { - return is1_13Plus; - } } diff --git a/src/main/java/de/butzlabben/world/autoupdater/AutoUpdate.java b/src/main/java/de/butzlabben/world/autoupdater/AutoUpdate.java index 8c8cd8b..040bde5 100644 --- a/src/main/java/de/butzlabben/world/autoupdater/AutoUpdate.java +++ b/src/main/java/de/butzlabben/world/autoupdater/AutoUpdate.java @@ -13,41 +13,41 @@ import java.nio.channels.ReadableByteChannel; */ public class AutoUpdate implements Runnable { - private final UpdateInformations ui; - private final String jar; + private final UpdateInformations ui; + private final String jar; - protected AutoUpdate(UpdateInformations ui, String jar) { - this.ui = ui; - this.jar = jar; - } + protected AutoUpdate(UpdateInformations ui, String jar) { + this.ui = ui; + this.jar = jar; + } - @Override - public void run() { - FileChannel out = null; - FileOutputStream outStream = null; - try { - - ReadableByteChannel in = Channels - .newChannel(new URL(ui.getURL()).openStream()); - outStream = new FileOutputStream(jar); - out = outStream.getChannel(); - out.transferFrom(in, 0, Long.MAX_VALUE); - } catch (Exception e) { - e.printStackTrace(); - } finally { - if (out != null) - try { - out.close(); - } catch (IOException e) { - e.printStackTrace(); - } - if (outStream != null) { - try { - outStream.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - } + @Override + public void run() { + FileChannel out = null; + FileOutputStream outStream = null; + try { + + ReadableByteChannel in = Channels + .newChannel(new URL(ui.getURL()).openStream()); + outStream = new FileOutputStream(jar); + out = outStream.getChannel(); + out.transferFrom(in, 0, Long.MAX_VALUE); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (out != null) + try { + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } + if (outStream != null) { + try { + outStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } } diff --git a/src/main/java/de/butzlabben/world/autoupdater/AutoUpdater.java b/src/main/java/de/butzlabben/world/autoupdater/AutoUpdater.java index bdc615b..d5de5e5 100644 --- a/src/main/java/de/butzlabben/world/autoupdater/AutoUpdater.java +++ b/src/main/java/de/butzlabben/world/autoupdater/AutoUpdater.java @@ -20,107 +20,107 @@ import java.lang.reflect.Method; */ public class AutoUpdater implements Listener { - private boolean confirmed; - private boolean confirmNeed; - private static AutoUpdater instance; - private AutoUpdate au; + private static AutoUpdater instance; + private boolean confirmed; + private boolean confirmNeed; + private AutoUpdate au; - public static void startAsync() { - Thread t = new Thread(() -> { - getInstance(); - }); - t.setName("update-thread-worldsystem"); - t.start(); - } + private AutoUpdater() { + confirmNeed = PluginConfig.confirmNeed(); + UpdateInformations ui = UpdateInformations.getInformations(); + if (ui == null) { + Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "§cCouldn't contact autoupdate server"); + return; + } + Plugin plugin = Bukkit.getPluginManager().getPlugin(ui.getPlugin()); + if (plugin == null) + return; + String v = plugin.getDescription().getVersion(); + if (!ui.getVersion().equals(plugin.getDescription().getVersion())) { - public static synchronized AutoUpdater getInstance() { - if (instance == null) - instance = new AutoUpdater(); - return instance; - } + if (!ui.isSilent()) { + Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "Found new version. Current: " + v + + ", Available: " + ui.getVersion()); + } + // Get jar file + Method getFileMethod; + try { + getFileMethod = JavaPlugin.class.getDeclaredMethod("getFile"); + } catch (NoSuchMethodException | SecurityException e1) { + e1.printStackTrace(); + return; + } + getFileMethod.setAccessible(true); + File file; - private AutoUpdater() { - confirmNeed = PluginConfig.confirmNeed(); - UpdateInformations ui = UpdateInformations.getInformations(); - if (ui == null) { - Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "§cCouldn't contact autoupdate server"); - return; - } - Plugin plugin = Bukkit.getPluginManager().getPlugin(ui.getPlugin()); - if (plugin == null) - return; - String v = plugin.getDescription().getVersion(); - if (!ui.getVersion().equals(plugin.getDescription().getVersion())) { + try { + file = (File) getFileMethod.invoke(plugin); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + e.printStackTrace(); + return; + } - if (!ui.isSilent()) { - Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "Found new version. Current: " + v - + ", Available: " + ui.getVersion()); - } - // Get jar file - Method getFileMethod; - try { - getFileMethod = JavaPlugin.class.getDeclaredMethod("getFile"); - } catch (NoSuchMethodException | SecurityException e1) { - e1.printStackTrace(); - return; - } - getFileMethod.setAccessible(true); - File file; + getFileMethod.setAccessible(false); - try { - file = (File) getFileMethod.invoke(plugin); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - e.printStackTrace(); - return; - } + String jar = file.getAbsolutePath(); + au = new AutoUpdate(ui, jar); + if (ui.isSilent() || !confirmNeed) { + Runtime.getRuntime().addShutdownHook(new Thread(au)); + if (!ui.isSilent()) + Bukkit.getConsoleSender().sendMessage( + 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"); + } + 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; + } + } - getFileMethod.setAccessible(false); + public static void startAsync() { + Thread t = new Thread(() -> { + getInstance(); + }); + t.setName("update-thread-worldsystem"); + t.start(); + } - String jar = file.getAbsolutePath(); - au = new AutoUpdate(ui, jar); - if (ui.isSilent() || !confirmNeed) { - Runtime.getRuntime().addShutdownHook(new Thread(au)); - if (!ui.isSilent()) - Bukkit.getConsoleSender().sendMessage( - 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"); - } - 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; - } - } + public static synchronized AutoUpdater getInstance() { + if (instance == null) + instance = new AutoUpdater(); + return instance; + } - @EventHandler - 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"); - } - } + @EventHandler + 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"); + } + } - public boolean confirm() { - if (confirmNeed && !confirmed) { - Runtime.getRuntime().addShutdownHook(new Thread(au)); - confirmed = true; - HandlerList.unregisterAll(this); - return true; - } - return false; - } + public boolean confirm() { + if (confirmNeed && !confirmed) { + Runtime.getRuntime().addShutdownHook(new Thread(au)); + confirmed = true; + HandlerList.unregisterAll(this); + return true; + } + return false; + } - public boolean confirmed() { - return confirmed; - } + public boolean confirmed() { + return confirmed; + } } diff --git a/src/main/java/de/butzlabben/world/autoupdater/UpdateInformations.java b/src/main/java/de/butzlabben/world/autoupdater/UpdateInformations.java index 2646fb7..7013abb 100644 --- a/src/main/java/de/butzlabben/world/autoupdater/UpdateInformations.java +++ b/src/main/java/de/butzlabben/world/autoupdater/UpdateInformations.java @@ -19,6 +19,13 @@ public class UpdateInformations { private final String version, url, plugin; private final boolean silent; + public UpdateInformations(String version, String url, String plugin, boolean silent) { + this.version = version; + this.url = url; + this.plugin = plugin; + this.silent = silent; + } + protected static synchronized UpdateInformations getInformations() { String json = callURL("https://zendilu.net/butzlabben/worldsystem/info.php?version=" + WorldSystem.getInstance().getDescription().getVersion()); Gson gson = new GsonBuilder().create(); @@ -73,11 +80,4 @@ public class UpdateInformations { public boolean isSilent() { return silent; } - - public UpdateInformations(String version, String url, String plugin, boolean silent) { - this.version = version; - this.url = url; - this.plugin = plugin; - this.silent = silent; - } } diff --git a/src/main/java/de/butzlabben/world/command/WorldSettingsCommands.java b/src/main/java/de/butzlabben/world/command/WorldSettingsCommands.java index 264265f..3043226 100644 --- a/src/main/java/de/butzlabben/world/command/WorldSettingsCommands.java +++ b/src/main/java/de/butzlabben/world/command/WorldSettingsCommands.java @@ -29,7 +29,7 @@ public class WorldSettingsCommands { private final ArrayList toConfirm = new ArrayList<>(); - @Command(name="ws.reset", inGameOnly = true, usage = "/ws reset [confirm]") + @Command(name = "ws.reset", inGameOnly = true, usage = "/ws reset [confirm]") public void resetCommand(CommandArgs args) { Player p = args.getSender(Player.class); @@ -124,7 +124,7 @@ public class WorldSettingsCommands { return; } - if(!p.hasPermission("ws.sethome")) { + if (!p.hasPermission("ws.sethome")) { p.sendMessage(MessageConfig.getNoPermission()); return; } @@ -196,11 +196,15 @@ public class WorldSettingsCommands { private void createWorld(Player p, String worldname, File f, WorldTemplate template, SystemWorld sw) { - File[] files = f.listFiles(); - for (File file : files) { - if (file.getName().equals("worldconfig.yml")) - continue; - FileUtils.deleteQuietly(file); + if (f != null) { + File[] files = f.listFiles(); + if (files != null) { + for (File file : files) { + if (file.getName().equals("worldconfig.yml")) + continue; + FileUtils.deleteQuietly(file); + } + } } try { diff --git a/src/main/java/de/butzlabben/world/config/DependenceConfig.java b/src/main/java/de/butzlabben/world/config/DependenceConfig.java index 76833d8..990f4a6 100644 --- a/src/main/java/de/butzlabben/world/config/DependenceConfig.java +++ b/src/main/java/de/butzlabben/world/config/DependenceConfig.java @@ -11,149 +11,149 @@ import java.util.UUID; public class DependenceConfig { - private OfflinePlayer op; + private OfflinePlayer op; - public DependenceConfig() { - setConfig(); - } + public DependenceConfig() { + setConfig(); + } - @SuppressWarnings("deprecation") - public DependenceConfig(String s) { - OfflinePlayer op = null; - try { - op = Bukkit.getOfflinePlayer(UUID.fromString(s)); - } catch (Exception ignored) { - } - if (op == null) { - op = Bukkit.getOfflinePlayer(s); - } - this.op = op; - } + @SuppressWarnings("deprecation") + public DependenceConfig(String s) { + OfflinePlayer op = null; + try { + op = Bukkit.getOfflinePlayer(UUID.fromString(s)); + } catch (Exception ignored) { + } + if (op == null) { + op = Bukkit.getOfflinePlayer(s); + } + this.op = op; + } - private void setConfig() { - File dconfig = new File("plugins//WorldSystem//dependence.yml"); - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig); - cfg.set("HighestID", -1); - try { - cfg.save(dconfig); - } catch (IOException e) { - e.printStackTrace(); - } - } + public DependenceConfig(Player p) { + this.op = p; + refreshName(); + } - public DependenceConfig(Player p) { - this.op = p; - refreshName(); - } + public DependenceConfig(OfflinePlayer p) { + this.op = p; + refreshName(); + } - public DependenceConfig(OfflinePlayer p) { - this.op = p; - refreshName(); - } + public static int getHighestID() { + File dconfig = new File("plugins//WorldSystem//dependence.yml"); + YamlConfiguration dcfg = YamlConfiguration.loadConfiguration(dconfig); + return dcfg.getInt("HighestID"); + } - public void refreshName() { - if (hasWorld()) { - File dconfig = new File("plugins//WorldSystem//dependence.yml"); - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig); - String uuid = this.op.getUniqueId().toString(); - cfg.set("Dependences." + uuid + ".ActualName", op.getName()); - try { - cfg.save(dconfig); - } catch (IOException e) { - e.printStackTrace(); - } - } - } + public static void checkWorlds() { + File dconfig = new File("plugins//WorldSystem//dependence.yml"); + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig); - public void createNewEntry() { - File dconfig = new File("plugins//WorldSystem//dependence.yml"); - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig); - String uuid = this.op.getUniqueId().toString(); - int id = cfg.getInt("HighestID"); - id++; - cfg.set("HighestID", id); - cfg.set("Dependences." + uuid + ".ID", id); - cfg.set("Dependences." + uuid + ".ActualName", op.getName()); - try { - cfg.save(dconfig); - } catch (IOException e) { - e.printStackTrace(); - } - } + long deleteTime = 1000 * 60 * 60 * 24 * PluginConfig.deleteAfter(); + long now = System.currentTimeMillis(); + for (String s : cfg.getConfigurationSection("Dependences").getKeys(false)) { + if (!cfg.isLong("Dependences." + s + ".last_loaded") && !cfg.isInt("Dependences." + s + ".last_loaded")) + continue; + long lastLoaded = cfg.getLong("Dependences." + s + ".last_loaded"); + long diff = now - lastLoaded; + if (diff > deleteTime) { + Bukkit.getConsoleSender().sendMessage( + PluginConfig.getPrefix() + "World of " + s + " was not loaded for too long. Deleting!"); + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "ws delete " + s); + } + } + } - public boolean hasWorld() { - File dconfig = new File("plugins//WorldSystem//dependence.yml"); - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig); - String uuid = op.getUniqueId().toString(); - //Fix for #40 + private void setConfig() { + File dconfig = new File("plugins//WorldSystem//dependence.yml"); + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig); + cfg.set("HighestID", -1); + try { + cfg.save(dconfig); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void refreshName() { + if (hasWorld()) { + File dconfig = new File("plugins//WorldSystem//dependence.yml"); + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig); + String uuid = this.op.getUniqueId().toString(); + cfg.set("Dependences." + uuid + ".ActualName", op.getName()); + try { + cfg.save(dconfig); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + public void createNewEntry() { + File dconfig = new File("plugins//WorldSystem//dependence.yml"); + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig); + String uuid = this.op.getUniqueId().toString(); + int id = cfg.getInt("HighestID"); + id++; + cfg.set("HighestID", id); + cfg.set("Dependences." + uuid + ".ID", id); + cfg.set("Dependences." + uuid + ".ActualName", op.getName()); + try { + cfg.save(dconfig); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public boolean hasWorld() { + File dconfig = new File("plugins//WorldSystem//dependence.yml"); + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig); + String uuid = op.getUniqueId().toString(); + //Fix for #40 return cfg.isInt("Dependences." + uuid + ".ID"); } - public String getWorldname() { - File dconfig = new File("plugins//WorldSystem//dependence.yml"); - YamlConfiguration dcfg = YamlConfiguration.loadConfiguration(dconfig); - String uuid = op.getUniqueId().toString(); - int id = dcfg.getInt("Dependences." + uuid + ".ID"); - return "ID" + id + "-" + uuid; - } + public String getWorldname() { + File dconfig = new File("plugins//WorldSystem//dependence.yml"); + YamlConfiguration dcfg = YamlConfiguration.loadConfiguration(dconfig); + String uuid = op.getUniqueId().toString(); + int id = dcfg.getInt("Dependences." + uuid + ".ID"); + return "ID" + id + "-" + uuid; + } - public String getWorldNamebyOfflinePlayer() { - String name; - String uuid = op.getUniqueId().toString(); - File dconfig = new File("plugins//WorldSystem//dependence.yml"); - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig); - if (cfg.getString("Dependences." + uuid + ".ActualName") == null) { - name = "n"; - } else { - name = "ID" + cfg.getInt("Dependences." + uuid + ".ID") + "-" + uuid; - } - return name; - } + public String getWorldNamebyOfflinePlayer() { + String name; + String uuid = op.getUniqueId().toString(); + File dconfig = new File("plugins//WorldSystem//dependence.yml"); + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig); + if (cfg.getString("Dependences." + uuid + ".ActualName") == null) { + name = "n"; + } else { + name = "ID" + cfg.getInt("Dependences." + uuid + ".ID") + "-" + uuid; + } + return name; + } - public void setLastLoaded() { - File dconfig = new File("plugins//WorldSystem//dependence.yml"); - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig); - String uuid = op.getUniqueId().toString(); - cfg.set("Dependences." + uuid + ".last_loaded", System.currentTimeMillis()); - try { - cfg.save(dconfig); - } catch (IOException e) { - e.printStackTrace(); - } - } + public void setLastLoaded() { + File dconfig = new File("plugins//WorldSystem//dependence.yml"); + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig); + String uuid = op.getUniqueId().toString(); + cfg.set("Dependences." + uuid + ".last_loaded", System.currentTimeMillis()); + try { + cfg.save(dconfig); + } catch (IOException e) { + e.printStackTrace(); + } + } - public static int getHighestID() { - File dconfig = new File("plugins//WorldSystem//dependence.yml"); - YamlConfiguration dcfg = YamlConfiguration.loadConfiguration(dconfig); - return dcfg.getInt("HighestID"); - } + public int getID() { + File dconfig = new File("plugins//WorldSystem//dependence.yml"); + YamlConfiguration dcfg = YamlConfiguration.loadConfiguration(dconfig); + return dcfg.getInt("Dependences." + op.getUniqueId().toString() + ".ID"); + } - public int getID() { - File dconfig = new File("plugins//WorldSystem//dependence.yml"); - YamlConfiguration dcfg = YamlConfiguration.loadConfiguration(dconfig); - return dcfg.getInt("Dependences." + op.getUniqueId().toString() + ".ID"); - } - - public OfflinePlayer getOwner() { - return op; - } - - public static void checkWorlds() { - File dconfig = new File("plugins//WorldSystem//dependence.yml"); - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig); - - long deleteTime = 1000 * 60 * 60 * 24 * PluginConfig.deleteAfter(); - long now = System.currentTimeMillis(); - for (String s : cfg.getConfigurationSection("Dependences").getKeys(false)) { - if (!cfg.isLong("Dependences." + s + ".last_loaded") && !cfg.isInt("Dependences." + s + ".last_loaded")) - continue; - long lastLoaded = cfg.getLong("Dependences." + s + ".last_loaded"); - long diff = now - lastLoaded; - if (diff > deleteTime) { - Bukkit.getConsoleSender().sendMessage( - PluginConfig.getPrefix() + "World of " + s + " was not loaded for too long. Deleting!"); - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "ws delete " + s); - } - } - } + public OfflinePlayer getOwner() { + return op; + } } diff --git a/src/main/java/de/butzlabben/world/config/Entry.java b/src/main/java/de/butzlabben/world/config/Entry.java index b83ee55..516717e 100644 --- a/src/main/java/de/butzlabben/world/config/Entry.java +++ b/src/main/java/de/butzlabben/world/config/Entry.java @@ -8,46 +8,46 @@ import java.io.File; public class Entry { - private final OfflinePlayer op; - private int id; - private final String worldname; - - public static int entrys() { - int entrys = 0; - for(OfflinePlayer op : Bukkit.getOfflinePlayers()) { - Entry e = new Entry(op); - if(e.hasWorld()) - ++entrys; - } - return entrys; - } - - protected OfflinePlayer getOfflinePlayer() { - return op; - } - - protected int getID() { - return id; - } - - protected String getWorldname() { - return worldname; - } + private final OfflinePlayer op; + private final String worldname; + private int id; - protected boolean hasWorld() { + protected Entry(OfflinePlayer op) { + String uuid = op.getUniqueId().toString(); + this.op = op; + File dconfig = new File("plugins//WorldSystem//dependence.yml"); + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig); + if (cfg.getString("Dependences." + uuid + ".ActualName") == null) { + worldname = "n"; + } else { + worldname = "ID" + cfg.getInt("Dependences." + uuid + ".ID") + " " + uuid; + id = cfg.getInt("Dependences." + uuid + ".ID"); + } + } + + public static int entrys() { + int entrys = 0; + for (OfflinePlayer op : Bukkit.getOfflinePlayers()) { + Entry e = new Entry(op); + if (e.hasWorld()) + ++entrys; + } + return entrys; + } + + protected OfflinePlayer getOfflinePlayer() { + return op; + } + + protected int getID() { + return id; + } + + protected String getWorldname() { + return worldname; + } + + protected boolean hasWorld() { return !"n".equals(worldname); } - - protected Entry(OfflinePlayer op) { - String uuid = op.getUniqueId().toString(); - this.op = op; - File dconfig = new File("plugins//WorldSystem//dependence.yml"); - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig); - if (cfg.getString("Dependences." + uuid + ".ActualName") == null) { - worldname = "n"; - } else { - worldname = "ID" + cfg.getInt("Dependences." + uuid + ".ID") + " " + uuid; - id = cfg.getInt("Dependences." + uuid + ".ID"); - } - } } diff --git a/src/main/java/de/butzlabben/world/config/GuiConfig.java b/src/main/java/de/butzlabben/world/config/GuiConfig.java index 384a9ea..0c2bfb5 100644 --- a/src/main/java/de/butzlabben/world/config/GuiConfig.java +++ b/src/main/java/de/butzlabben/world/config/GuiConfig.java @@ -17,131 +17,131 @@ import java.util.List; public class GuiConfig { - private GuiConfig() { - } + private static File file; - private static File file; + private GuiConfig() { + } - public static void checkConfig(File f) { - file = f; - if (!file.exists()) { - try { - String guiFileResource; - if (WorldSystem.is1_13()) { - guiFileResource = "1_13_gui.yml"; - } else { - guiFileResource = "old_gui.yml"; - } - InputStream in = JavaPlugin.getPlugin(WorldSystem.class).getResource(guiFileResource); - Files.copy(in, file.toPath()); - } catch (IOException e) { - System.err.println("Wasn't able to create Config"); - e.printStackTrace(); - } - } - OrcItem.enabled = getEnabled(); - OrcItem.disabled = getDisabled(); - OrcItem.coming_soon = getComingSoon(); - OrcItem.back = getBack(); - OrcItem.fill = getFill(); - } + public static void checkConfig(File f) { + file = f; + if (!file.exists()) { + try { + String guiFileResource; + if (WorldSystem.is1_13()) { + guiFileResource = "1_13_gui.yml"; + } else { + guiFileResource = "old_gui.yml"; + } + InputStream in = JavaPlugin.getPlugin(WorldSystem.class).getResource(guiFileResource); + Files.copy(in, file.toPath()); + } catch (IOException e) { + System.err.println("Wasn't able to create Config"); + e.printStackTrace(); + } + } + OrcItem.enabled = getEnabled(); + OrcItem.disabled = getDisabled(); + OrcItem.coming_soon = getComingSoon(); + OrcItem.back = getBack(); + OrcItem.fill = getFill(); + } - public static YamlConfiguration getConfig() { - try { - return YamlConfiguration - .loadConfiguration(new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8"))); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - return null; - } + public static YamlConfiguration getConfig() { + try { + return YamlConfiguration + .loadConfiguration(new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8"))); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + return null; + } - public static int getSlot(String path) { - YamlConfiguration cfg = getConfig(); - return (cfg.getInt(path + ".slot.row") - 1) * 9 + cfg.getInt(path + ".slot.col") - 1; - } + public static int getSlot(String path) { + YamlConfiguration cfg = getConfig(); + return (cfg.getInt(path + ".slot.row") - 1) * 9 + cfg.getInt(path + ".slot.col") - 1; + } - public static int getState(String path) { - YamlConfiguration cfg = getConfig(); - return (cfg.getInt(path + ".state.row") - 1) * 9 + cfg.getInt(path + ".state.col") - 1; - } + public static int getState(String path) { + YamlConfiguration cfg = getConfig(); + return (cfg.getInt(path + ".state.row") - 1) * 9 + cfg.getInt(path + ".state.col") - 1; + } - public static boolean isEnabled(String path) { - return getConfig().getBoolean(path + ".enabled", true); - } + public static boolean isEnabled(String path) { + return getConfig().getBoolean(path + ".enabled", true); + } - public static int getRows(String path) { - return getConfig().getInt(path + ".rows", 1); - } + public static int getRows(String path) { + return getConfig().getInt(path + ".rows", 1); + } - public static String getDisplay(FileConfiguration cfg, String path) { - return ChatColor.translateAlternateColorCodes('&', cfg.getString(path + ".display")); - } + public static String getDisplay(FileConfiguration cfg, String path) { + return ChatColor.translateAlternateColorCodes('&', cfg.getString(path + ".display")); + } - public static ArrayList getLore(FileConfiguration cfg, String path) { - List list = cfg.getStringList(path + ".lore"); - ArrayList colored = new ArrayList<>(list.size()); - for (String s : list) { - colored.add(ChatColor.translateAlternateColorCodes('&', s)); - } - return colored; - } + public static ArrayList getLore(FileConfiguration cfg, String path) { + List list = cfg.getStringList(path + ".lore"); + ArrayList colored = new ArrayList<>(list.size()); + for (String s : list) { + colored.add(ChatColor.translateAlternateColorCodes('&', s)); + } + return colored; + } - 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 byte getData(FileConfiguration cfg, String path) { + return (byte) cfg.getInt(path + ".data", 0); + } - public static Material getMaterial(FileConfiguration cfg, String path) { - try { - return Material.valueOf(cfg.getString(path + ".material").toUpperCase()); - } catch (IllegalArgumentException ex) { - Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "§cUnknown material: " + path); - return null; - } - } + public static String getTitle(FileConfiguration cfg, String path) { + return cfg.getString(path + ".title"); + } - public static OrcItem getItem(String path) { - YamlConfiguration cfg = getConfig(); - try { - return new OrcItem(getMaterial(cfg, path), getData(cfg, path), getDisplay(cfg, path), getLore(cfg, path)); - } catch (Exception ignored) { - } - try { - return new OrcItem(getMaterial(cfg, path), getDisplay(cfg, path), getLore(cfg, path)); - } catch (Exception ignored) { - } - return OrcItem.error.clone().setDisplay("§c" + path); - } + public static Material getMaterial(FileConfiguration cfg, String path) { + try { + return Material.valueOf(cfg.getString(path + ".material").toUpperCase()); + } catch (IllegalArgumentException ex) { + Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "§cUnknown material: " + path); + return null; + } + } - public static OrcItem getEnabled() { - return getItem("options.enabled"); - } + public static OrcItem getItem(String path) { + YamlConfiguration cfg = getConfig(); + try { + return new OrcItem(getMaterial(cfg, path), getData(cfg, path), getDisplay(cfg, path), getLore(cfg, path)); + } catch (Exception ignored) { + } + try { + return new OrcItem(getMaterial(cfg, path), getDisplay(cfg, path), getLore(cfg, path)); + } catch (Exception ignored) { + } + return OrcItem.error.clone().setDisplay("§c" + path); + } - public static OrcItem getDisabled() { - return getItem("options.disabled"); - } + public static OrcItem getEnabled() { + return getItem("options.enabled"); + } - public static OrcItem getComingSoon() { - return getItem("options.coming_soon"); - } - - 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 OrcItem getDisabled() { + return getItem("options.disabled"); + } - public static Material getSkullItem() { - return getMaterial(getConfig(), "options.players.playerhead"); - } + public static OrcItem getComingSoon() { + return getItem("options.coming_soon"); + } + + 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/src/main/java/de/butzlabben/world/config/MessageConfig.java b/src/main/java/de/butzlabben/world/config/MessageConfig.java index 9e94c22..429114e 100644 --- a/src/main/java/de/butzlabben/world/config/MessageConfig.java +++ b/src/main/java/de/butzlabben/world/config/MessageConfig.java @@ -14,10 +14,8 @@ import java.util.stream.Collectors; public class MessageConfig { - private MessageConfig() { - } - private static final List defaultCmdHelp = new ArrayList<>(20); + private static File file; static { defaultCmdHelp.add("/ws get §8- §7Will give you a World"); @@ -35,7 +33,8 @@ public class MessageConfig { defaultCmdHelp.add("/ws reset §8- §7Will reset your World"); } - private static File file; + private MessageConfig() { + } // private static HashMap languages = new HashMap<>(); public static void checkConfig(File f) { diff --git a/src/main/java/de/butzlabben/world/config/PluginConfig.java b/src/main/java/de/butzlabben/world/config/PluginConfig.java index ec7a2f2..fcd0619 100644 --- a/src/main/java/de/butzlabben/world/config/PluginConfig.java +++ b/src/main/java/de/butzlabben/world/config/PluginConfig.java @@ -20,13 +20,12 @@ import java.util.Date; public class PluginConfig { - private PluginConfig() { - } - - private static File file; - private final static GameMode[] gameModes = new GameMode[]{GameMode.SURVIVAL, GameMode.CREATIVE, GameMode.ADVENTURE, GameMode.SPECTATOR}; + private static File file; + + private PluginConfig() { + } public static void checkConfig(File f) { file = f; diff --git a/src/main/java/de/butzlabben/world/config/SettingsConfig.java b/src/main/java/de/butzlabben/world/config/SettingsConfig.java index 4d3238f..3fdfb6f 100644 --- a/src/main/java/de/butzlabben/world/config/SettingsConfig.java +++ b/src/main/java/de/butzlabben/world/config/SettingsConfig.java @@ -19,171 +19,171 @@ import java.util.UUID; public class SettingsConfig { - private static final HashMap borderSizes = new HashMap<>(); + private static final HashMap borderSizes = new HashMap<>(); - private static File file; + private static File file; - @SuppressWarnings("deprecation") - public static void editWorld(World w) { - YamlConfiguration cfg = getConfig(); + private SettingsConfig() { + } - SystemWorld sw = SystemWorld.getSystemWorld(w.getName()); + @SuppressWarnings("deprecation") + public static void editWorld(World w) { + YamlConfiguration cfg = getConfig(); - boolean shouldChange = cfg.getBoolean("worldborder.should_change", false); - if (shouldChange) { - long size = cfg.getLong("worldborder.normal", 1000); - if (sw != null && sw.isLoaded()) { - String worldname = w.getName(); - UUID uuid = UUID.fromString(worldname.substring(worldname.length() - 36)); - Player p = Bukkit.getPlayer(uuid); - if (p != null && p.isOnline()) { - for (String string : borderSizes.keySet()) { - if (p.hasPermission(string) && size < borderSizes.get(string)) { - size = borderSizes.get(string); - } - } - } - } + SystemWorld sw = SystemWorld.getSystemWorld(w.getName()); - w.getWorldBorder().setSize(size); + boolean shouldChange = cfg.getBoolean("worldborder.should_change", false); + if (shouldChange) { + long size = cfg.getLong("worldborder.normal", 1000); + if (sw != null && sw.isLoaded()) { + String worldname = w.getName(); + UUID uuid = UUID.fromString(worldname.substring(worldname.length() - 36)); + Player p = Bukkit.getPlayer(uuid); + if (p != null && p.isOnline()) { + for (String string : borderSizes.keySet()) { + if (p.hasPermission(string) && size < borderSizes.get(string)) { + size = borderSizes.get(string); + } + } + } + } - if (cfg.getBoolean("worldborder.center.as_spawn", true)) { - if (PluginConfig.useWorldSpawn()) { - w.getWorldBorder().setCenter(PluginConfig.getWorldSpawn(w)); - } else { - w.getWorldBorder().setCenter(w.getSpawnLocation()); - } - } else { - Location loc = new Location(w, cfg.getDouble("worldborder.center.x", 0), - cfg.getDouble("worldborder.center.y", 20), cfg.getDouble("worldborder.center.z", 0)); - w.getWorldBorder().setCenter(loc); - } - if (cfg.getBoolean("worldborder.center.as_home")) { - WorldConfig config = WorldConfig.getWorldConfig(w.getName()); - if (config.getHome() != null) - w.getWorldBorder().setCenter(config.getHome()); - } - } + w.getWorldBorder().setSize(size); - // Fix for #17 - String diff = cfg.getString("difficulty"); - try { - Difficulty difficulty = Difficulty.valueOf(diff.toUpperCase()); - w.setDifficulty(difficulty); - } catch (IllegalArgumentException e) { - Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "§cUnknown difficulty \"" + diff + "\" in settings.yml"); - } + if (cfg.getBoolean("worldborder.center.as_spawn", true)) { + if (PluginConfig.useWorldSpawn()) { + w.getWorldBorder().setCenter(PluginConfig.getWorldSpawn(w)); + } else { + w.getWorldBorder().setCenter(w.getSpawnLocation()); + } + } else { + Location loc = new Location(w, cfg.getDouble("worldborder.center.x", 0), + cfg.getDouble("worldborder.center.y", 20), cfg.getDouble("worldborder.center.z", 0)); + w.getWorldBorder().setCenter(loc); + } + if (cfg.getBoolean("worldborder.center.as_home")) { + WorldConfig config = WorldConfig.getWorldConfig(w.getName()); + if (config.getHome() != null) + w.getWorldBorder().setCenter(config.getHome()); + } + } - if (w.isGameRule("announceAdvancements")) - w.setGameRuleValue("announceAdvancements", cfg.getString("announceAdvancements")); + // Fix for #17 + String diff = cfg.getString("difficulty"); + try { + Difficulty difficulty = Difficulty.valueOf(diff.toUpperCase()); + w.setDifficulty(difficulty); + } catch (IllegalArgumentException e) { + Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "§cUnknown difficulty \"" + diff + "\" in settings.yml"); + } - if (w.isGameRule("commandBlockOutput")) - w.setGameRuleValue("commandBlockOutput", cfg.getString("commandBlockOutput")); + if (w.isGameRule("announceAdvancements")) + w.setGameRuleValue("announceAdvancements", cfg.getString("announceAdvancements")); - if (w.isGameRule("disableElytraMovementCheck")) - w.setGameRuleValue("disableElytraMovementCheck", cfg.getString("disableElytraMovementCheck")); + if (w.isGameRule("commandBlockOutput")) + w.setGameRuleValue("commandBlockOutput", cfg.getString("commandBlockOutput")); - if (w.isGameRule("doDaylightCycle")) - w.setGameRuleValue("doDaylightCycle", cfg.getString("doDaylightCycle")); + if (w.isGameRule("disableElytraMovementCheck")) + w.setGameRuleValue("disableElytraMovementCheck", cfg.getString("disableElytraMovementCheck")); - if (w.isGameRule("doEntityDrops")) - w.setGameRuleValue("doEntityDrops", cfg.getString("doEntityDrops")); + if (w.isGameRule("doDaylightCycle")) + w.setGameRuleValue("doDaylightCycle", cfg.getString("doDaylightCycle")); - if (w.isGameRule("doFireTick")) - w.setGameRuleValue("doFireTick", cfg.getString("doFireTick")); + if (w.isGameRule("doEntityDrops")) + w.setGameRuleValue("doEntityDrops", cfg.getString("doEntityDrops")); - if (w.isGameRule("doLimitedCrafting")) - w.setGameRuleValue("doLimitedCrafting", cfg.getString("doLimitedCrafting")); + if (w.isGameRule("doFireTick")) + w.setGameRuleValue("doFireTick", cfg.getString("doFireTick")); - if (w.isGameRule("doMobLoot")) - w.setGameRuleValue("doMobLoot", cfg.getString("doMobLoot")); + if (w.isGameRule("doLimitedCrafting")) + w.setGameRuleValue("doLimitedCrafting", cfg.getString("doLimitedCrafting")); - if (w.isGameRule("doMobSpawning")) - w.setGameRuleValue("doMobSpawning", cfg.getString("doMobSpawning")); + if (w.isGameRule("doMobLoot")) + w.setGameRuleValue("doMobLoot", cfg.getString("doMobLoot")); - if (w.isGameRule("doTileDrops")) - w.setGameRuleValue("doTileDrops", cfg.getString("doTileDrops")); + if (w.isGameRule("doMobSpawning")) + w.setGameRuleValue("doMobSpawning", cfg.getString("doMobSpawning")); - if (w.isGameRule("doWeatherCycle")) - w.setGameRuleValue("doWeatherCycle", cfg.getString("doWeatherCycle")); + if (w.isGameRule("doTileDrops")) + w.setGameRuleValue("doTileDrops", cfg.getString("doTileDrops")); - if (w.isGameRule("gameLoopFunction")) - w.setGameRuleValue("gameLoopFunction", cfg.getString("gameLoopFunction")); + if (w.isGameRule("doWeatherCycle")) + w.setGameRuleValue("doWeatherCycle", cfg.getString("doWeatherCycle")); - if (w.isGameRule("keepInventory")) - w.setGameRuleValue("keepInventory", cfg.getString("keepInventory")); + if (w.isGameRule("gameLoopFunction")) + w.setGameRuleValue("gameLoopFunction", cfg.getString("gameLoopFunction")); - if (w.isGameRule("logAdminCommands")) - w.setGameRuleValue("logAdminCommands", cfg.getString("logAdminCommands")); + if (w.isGameRule("keepInventory")) + w.setGameRuleValue("keepInventory", cfg.getString("keepInventory")); - if (w.isGameRule("maxCommandChainLength")) - w.setGameRuleValue("maxCommandChainLength", cfg.getString("maxCommandChainLength")); + if (w.isGameRule("logAdminCommands")) + w.setGameRuleValue("logAdminCommands", cfg.getString("logAdminCommands")); - if (w.isGameRule("maxEntityCramming")) - w.setGameRuleValue("maxEntityCramming", cfg.getString("maxEntityCramming")); + if (w.isGameRule("maxCommandChainLength")) + w.setGameRuleValue("maxCommandChainLength", cfg.getString("maxCommandChainLength")); - if (w.isGameRule("mobGriefing")) - w.setGameRuleValue("mobGriefing", cfg.getString("mobGriefing")); + if (w.isGameRule("maxEntityCramming")) + w.setGameRuleValue("maxEntityCramming", cfg.getString("maxEntityCramming")); - if (w.isGameRule("naturalRegeneration")) - w.setGameRuleValue("naturalRegeneration", cfg.getString("naturalRegeneration")); + if (w.isGameRule("mobGriefing")) + w.setGameRuleValue("mobGriefing", cfg.getString("mobGriefing")); - if (w.isGameRule("randomTickSpeed")) - w.setGameRuleValue("randomTickSpeed", cfg.getString("randomTickSpeed")); + if (w.isGameRule("naturalRegeneration")) + w.setGameRuleValue("naturalRegeneration", cfg.getString("naturalRegeneration")); - if (w.isGameRule("reducedDebugInfo")) - w.setGameRuleValue("reducedDebugInfo", cfg.getString("reducedDebugInfo")); + if (w.isGameRule("randomTickSpeed")) + w.setGameRuleValue("randomTickSpeed", cfg.getString("randomTickSpeed")); - if (w.isGameRule("sendCommandFeedback")) - w.setGameRuleValue("sendCommandFeedback", cfg.getString("sendCommandFeedback")); + if (w.isGameRule("reducedDebugInfo")) + w.setGameRuleValue("reducedDebugInfo", cfg.getString("reducedDebugInfo")); - if (w.isGameRule("showDeathMessages")) - w.setGameRuleValue("showDeathMessages", cfg.getString("showDeathMessages")); + if (w.isGameRule("sendCommandFeedback")) + w.setGameRuleValue("sendCommandFeedback", cfg.getString("sendCommandFeedback")); - if (w.isGameRule("spawnRadius")) - w.setGameRuleValue("spawnRadius", cfg.getString("spawnRadius")); + if (w.isGameRule("showDeathMessages")) + w.setGameRuleValue("showDeathMessages", cfg.getString("showDeathMessages")); - if (w.isGameRule("spectatorsGenerateChunks")) - w.setGameRuleValue("spectatorsGenerateChunks", cfg.getString("spectatorsGenerateChunks")); - } + if (w.isGameRule("spawnRadius")) + w.setGameRuleValue("spawnRadius", cfg.getString("spawnRadius")); - private static YamlConfiguration getConfig() { - try { - return YamlConfiguration - .loadConfiguration(new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8"))); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - return null; - } + if (w.isGameRule("spectatorsGenerateChunks")) + w.setGameRuleValue("spectatorsGenerateChunks", cfg.getString("spectatorsGenerateChunks")); + } - public static void checkConfig() { - File file = new File(WorldSystem.getInstance().getDataFolder(), "settings.yml"); - SettingsConfig.file = file; - if (!file.exists()) { - try { - InputStream in = JavaPlugin.getPlugin(WorldSystem.class).getResource("settings.yml"); - Files.copy(in, file.toPath()); - } catch (IOException e) { - System.err.println("Wasn't able to create Config"); - e.printStackTrace(); - } - } - YamlConfiguration cfg = getConfig(); - for (String s : cfg.getConfigurationSection("worldborder.ranks").getKeys(true)) { - if (cfg.isInt("worldborder.ranks." + s) || cfg.isLong("worldborder.ranks." + s)) - borderSizes.put(s, cfg.getLong("worldborder.ranks." + s)); - } - } + private static YamlConfiguration getConfig() { + try { + return YamlConfiguration + .loadConfiguration(new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8"))); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + return null; + } - /** - * @return the commands specified in settings.yml on /ws get - */ - public static List getCommandsonGet() { - YamlConfiguration cfg = getConfig(); - return cfg.getStringList("commands_on_get"); - } + public static void checkConfig() { + File file = new File(WorldSystem.getInstance().getDataFolder(), "settings.yml"); + SettingsConfig.file = file; + if (!file.exists()) { + try { + InputStream in = JavaPlugin.getPlugin(WorldSystem.class).getResource("settings.yml"); + Files.copy(in, file.toPath()); + } catch (IOException e) { + System.err.println("Wasn't able to create Config"); + e.printStackTrace(); + } + } + YamlConfiguration cfg = getConfig(); + for (String s : cfg.getConfigurationSection("worldborder.ranks").getKeys(true)) { + if (cfg.isInt("worldborder.ranks." + s) || cfg.isLong("worldborder.ranks." + s)) + borderSizes.put(s, cfg.getLong("worldborder.ranks." + s)); + } + } - private SettingsConfig() { - } + /** + * @return the commands specified in settings.yml on /ws get + */ + public static List getCommandsonGet() { + YamlConfiguration cfg = getConfig(); + return cfg.getStringList("commands_on_get"); + } } diff --git a/src/main/java/de/butzlabben/world/config/WorldConfig.java b/src/main/java/de/butzlabben/world/config/WorldConfig.java index 3dfe707..1f3b6e0 100644 --- a/src/main/java/de/butzlabben/world/config/WorldConfig.java +++ b/src/main/java/de/butzlabben/world/config/WorldConfig.java @@ -37,6 +37,13 @@ public class WorldConfig { private Location home = null; + private WorldConfig(String worldname) { + if (!exists(worldname)) + throw new IllegalArgumentException("WorldConfig doesn't exist"); + owner = UUID.fromString(worldname.substring(worldname.length() - 36)); + id = Integer.parseInt(worldname.split("-")[0].substring(2)); + } + public static File getWorldFile(String worldname) { File worldconfig = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); if (!worldconfig.exists()) { @@ -71,13 +78,6 @@ public class WorldConfig { return instances.get(worldname).load(); } - private WorldConfig(String worldname) { - if (!exists(worldname)) - throw new IllegalArgumentException("WorldConfig doesn't exist"); - owner = UUID.fromString(worldname.substring(worldname.length() - 36)); - id = Integer.parseInt(worldname.split("-")[0].substring(2)); - } - public static void create(Player p, WorldTemplate template) { DependenceConfig dc = new DependenceConfig(p); String worldname = dc.getWorldname(); @@ -480,13 +480,6 @@ public class WorldConfig { return name != null; } - /** - * @param loc the new home of the world - */ - public void setHome(Location loc) { - home = loc; - } - /** * @return the home of the world. If not set returns null */ @@ -497,6 +490,13 @@ public class WorldConfig { home.getPitch()); } + /** + * @param loc the new home of the world + */ + public void setHome(Location loc) { + home = loc; + } + public String getOwnerName() { return ownerName; } diff --git a/src/main/java/de/butzlabben/world/config/WorldPerm.java b/src/main/java/de/butzlabben/world/config/WorldPerm.java index cd17722..f14b3a8 100644 --- a/src/main/java/de/butzlabben/world/config/WorldPerm.java +++ b/src/main/java/de/butzlabben/world/config/WorldPerm.java @@ -1,23 +1,23 @@ package de.butzlabben.world.config; public enum WorldPerm { - - MEMBER("ws.member"), - GAMEMODE("ws.gamemode"), BUILD("ws.build"), TELEPORT("ws.teleport"), - EDITMEMBERS("ws.edit"), ADMINISTRATEMEMBERS, ADMINISTRATEWORLD, WORLDEDIT("ws.worldedit"); - - private final String opPerm; - - WorldPerm() { - this("ws.*"); - } - - WorldPerm(String opPerm) { - this.opPerm = opPerm; - } - - public String getOpPerm() { - return opPerm; - } + + MEMBER("ws.member"), + GAMEMODE("ws.gamemode"), BUILD("ws.build"), TELEPORT("ws.teleport"), + EDITMEMBERS("ws.edit"), ADMINISTRATEMEMBERS, ADMINISTRATEWORLD, WORLDEDIT("ws.worldedit"); + + private final String opPerm; + + WorldPerm() { + this("ws.*"); + } + + WorldPerm(String opPerm) { + this.opPerm = opPerm; + } + + public String getOpPerm() { + return opPerm; + } } diff --git a/src/main/java/de/butzlabben/world/event/WorldAddmemberEvent.java b/src/main/java/de/butzlabben/world/event/WorldAddmemberEvent.java index 1c36ba3..fc59de9 100644 --- a/src/main/java/de/butzlabben/world/event/WorldAddmemberEvent.java +++ b/src/main/java/de/butzlabben/world/event/WorldAddmemberEvent.java @@ -7,47 +7,46 @@ import java.util.UUID; /** * Event for adding somebody to a world - * + * * @author Butzlabben * @since 09.05.2018 */ public class WorldAddmemberEvent extends WorldEvent { - private final String worldname; - private final UUID uuid; - private final Player adder; - - public WorldAddmemberEvent(UUID uuid, String worldname, Player adder) { - this.uuid = uuid; - this.worldname = worldname; - this.adder = adder; - } - - /** - * @return player who adds somebody - */ - public Player getAdding() { - return adder; - } - - /** - * @return UUID of player who gets added - */ - public UUID getUUID() { - return uuid; - } - - /** - * @return worldname for which it happens - */ - public String getWorldname() { - return worldname; - } - - @Override - public HandlerList getHandlers() { - return handlers; - } + public final static HandlerList handlers = new HandlerList(); + private final String worldname; + private final UUID uuid; + private final Player adder; - public final static HandlerList handlers = new HandlerList(); + public WorldAddmemberEvent(UUID uuid, String worldname, Player adder) { + this.uuid = uuid; + this.worldname = worldname; + this.adder = adder; + } + + /** + * @return player who adds somebody + */ + public Player getAdding() { + return adder; + } + + /** + * @return UUID of player who gets added + */ + public UUID getUUID() { + return uuid; + } + + /** + * @return worldname for which it happens + */ + public String getWorldname() { + return worldname; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } } diff --git a/src/main/java/de/butzlabben/world/event/WorldCreateEvent.java b/src/main/java/de/butzlabben/world/event/WorldCreateEvent.java index e3d9d93..f7e7600 100644 --- a/src/main/java/de/butzlabben/world/event/WorldCreateEvent.java +++ b/src/main/java/de/butzlabben/world/event/WorldCreateEvent.java @@ -7,47 +7,46 @@ import org.bukkit.event.HandlerList; /** * Event if a SystemWorld gets created. * Do mix up with the WorldCreateEvent from Bukkit - * + * * @author Butzlabben * @since 09.05.2018 */ public class WorldCreateEvent extends WorldEvent { - private final Player owner; - private WorldCreator worldCreator; + public final static HandlerList handlers = new HandlerList(); + private final Player owner; + private WorldCreator worldCreator; - public WorldCreateEvent(Player owner, WorldCreator creator) { - this.owner = owner; - this.setWorldCreator(creator); - } + public WorldCreateEvent(Player owner, WorldCreator creator) { + this.owner = owner; + this.setWorldCreator(creator); + } - /** - * @return owner of world that gets created - */ - public Player getOwner() { - return owner; - } + public final static HandlerList getHandlerList() { + return handlers; + } - public final static HandlerList handlers = new HandlerList(); + /** + * @return owner of world that gets created + */ + public Player getOwner() { + return owner; + } - public final static HandlerList getHandlerList() { - return handlers; - } + @Override + public final HandlerList getHandlers() { + return handlers; + } - @Override - public final HandlerList getHandlers() { - return handlers; - } + /** + * @return the worldcreator which will be used + */ + public WorldCreator getWorldCreator() { + return worldCreator; + } - /** - * @return the worldcreator which will be used - */ - public WorldCreator getWorldCreator() { - return worldCreator; - } - - public void setWorldCreator(WorldCreator worldCreator) { - this.worldCreator = worldCreator; - } + public void setWorldCreator(WorldCreator worldCreator) { + this.worldCreator = worldCreator; + } } diff --git a/src/main/java/de/butzlabben/world/event/WorldDeleteEvent.java b/src/main/java/de/butzlabben/world/event/WorldDeleteEvent.java index 4a7ab9d..c6c0563 100644 --- a/src/main/java/de/butzlabben/world/event/WorldDeleteEvent.java +++ b/src/main/java/de/butzlabben/world/event/WorldDeleteEvent.java @@ -6,43 +6,42 @@ import org.bukkit.event.HandlerList; /** * Event if a systemworld gets deleted - * + * * @author Butzlabben * @since 09.05.2018 */ public class WorldDeleteEvent extends WorldEvent { - - private final SystemWorld world; - private final CommandSender executor; - - public WorldDeleteEvent(CommandSender executor, SystemWorld world) { - this.executor = executor; - this.world = world; - } - - /** - * @return get the world which will be deleted - */ - public SystemWorld getWorld() { - return world; - } - - /** - * @return get the executor of the command - */ - public CommandSender getExecutor() { - return executor; - } - - public final static HandlerList handlers = new HandlerList(); - - public static HandlerList getHandlerList() { - return handlers; - } - - @Override - public final HandlerList getHandlers() { - return handlers; - } + + public final static HandlerList handlers = new HandlerList(); + private final SystemWorld world; + private final CommandSender executor; + + public WorldDeleteEvent(CommandSender executor, SystemWorld world) { + this.executor = executor; + this.world = world; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + /** + * @return get the world which will be deleted + */ + public SystemWorld getWorld() { + return world; + } + + /** + * @return get the executor of the command + */ + public CommandSender getExecutor() { + return executor; + } + + @Override + public final HandlerList getHandlers() { + return handlers; + } } diff --git a/src/main/java/de/butzlabben/world/event/WorldEvent.java b/src/main/java/de/butzlabben/world/event/WorldEvent.java index fc935db..a424cd0 100644 --- a/src/main/java/de/butzlabben/world/event/WorldEvent.java +++ b/src/main/java/de/butzlabben/world/event/WorldEvent.java @@ -5,23 +5,23 @@ import org.bukkit.event.Event; public abstract class WorldEvent extends Event implements Cancellable { - private boolean cancelled; + private boolean cancelled; - public WorldEvent() { - } + public WorldEvent() { + } - public WorldEvent(boolean cancel) { - setCancelled(cancel); - } + public WorldEvent(boolean cancel) { + setCancelled(cancel); + } - @Override - public boolean isCancelled() { - return cancelled; - } + @Override + public boolean isCancelled() { + return cancelled; + } - @Override - public void setCancelled(boolean cancel) { - cancelled = cancel; - } + @Override + public void setCancelled(boolean cancel) { + cancelled = cancel; + } } diff --git a/src/main/java/de/butzlabben/world/event/WorldLoadEvent.java b/src/main/java/de/butzlabben/world/event/WorldLoadEvent.java index 61a976b..890c24f 100644 --- a/src/main/java/de/butzlabben/world/event/WorldLoadEvent.java +++ b/src/main/java/de/butzlabben/world/event/WorldLoadEvent.java @@ -6,43 +6,42 @@ import org.bukkit.event.HandlerList; /** * Event for loading a world - * + * * @author Butzlabben * @since 09.05.2018 */ public class WorldLoadEvent extends WorldEvent { - private final Player owner; - private final SystemWorld world; + public final static HandlerList handlers = new HandlerList(); + private final Player owner; + private final SystemWorld world; - public WorldLoadEvent(Player owner, SystemWorld systemWorld) { - this.owner = owner; - this.world = systemWorld; - } + public WorldLoadEvent(Player owner, SystemWorld systemWorld) { + this.owner = owner; + this.world = systemWorld; + } - /** - * @return get the world which will be loaded - */ - public SystemWorld getWorld() { - return world; - } + public static HandlerList getHandlerList() { + return handlers; + } - /** - * @return get person which intiziated the loading - */ - public Player getOwner() { - return owner; - } + /** + * @return get the world which will be loaded + */ + public SystemWorld getWorld() { + return world; + } - public final static HandlerList handlers = new HandlerList(); + /** + * @return get person which intiziated the loading + */ + public Player getOwner() { + return owner; + } - public static HandlerList getHandlerList() { - return handlers; - } - - @Override - public final HandlerList getHandlers() { - return handlers; - } + @Override + public final HandlerList getHandlers() { + return handlers; + } } diff --git a/src/main/java/de/butzlabben/world/event/WorldRemovememberEvent.java b/src/main/java/de/butzlabben/world/event/WorldRemovememberEvent.java index cca87f4..498739b 100644 --- a/src/main/java/de/butzlabben/world/event/WorldRemovememberEvent.java +++ b/src/main/java/de/butzlabben/world/event/WorldRemovememberEvent.java @@ -11,42 +11,40 @@ import java.util.UUID; */ public class WorldRemovememberEvent extends WorldEvent { - private final String worldname; - private final UUID uuid; - private final Player remover; - - public WorldRemovememberEvent(UUID uuid, String worldname, Player remover) { - this.uuid = uuid; - this.worldname = worldname; - this.remover = remover; - } - - /** - * @return player who removes somebody - */ - public Player getRemoving() { - return remover; - } - - /** - * @return uuid of player who gets removed - */ - public UUID getUUID() { - return uuid; - } - - /** - * @return worldname for which it happens - */ - public String getWorldname() { - return worldname; - } - - @Override - public HandlerList getHandlers() { - return handlers; - } + public final static HandlerList handlers = new HandlerList(); + private final String worldname; + private final UUID uuid; + private final Player remover; + public WorldRemovememberEvent(UUID uuid, String worldname, Player remover) { + this.uuid = uuid; + this.worldname = worldname; + this.remover = remover; + } - public final static HandlerList handlers = new HandlerList(); + /** + * @return player who removes somebody + */ + public Player getRemoving() { + return remover; + } + + /** + * @return uuid of player who gets removed + */ + public UUID getUUID() { + return uuid; + } + + /** + * @return worldname for which it happens + */ + public String getWorldname() { + return worldname; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } } diff --git a/src/main/java/de/butzlabben/world/event/WorldResetEvent.java b/src/main/java/de/butzlabben/world/event/WorldResetEvent.java index 8d87314..b7462b1 100644 --- a/src/main/java/de/butzlabben/world/event/WorldResetEvent.java +++ b/src/main/java/de/butzlabben/world/event/WorldResetEvent.java @@ -6,44 +6,41 @@ import org.bukkit.event.HandlerList; /** * Event when a world gets reset - * + * * @author Butzlabben * @since 09.05.2018 */ public class WorldResetEvent extends WorldEvent { - - private final SystemWorld world; - private final CommandSender executor; - - public WorldResetEvent(CommandSender executor, SystemWorld world) { - this.executor = executor; - this.world = world; - } - - /** - * @return world which gets reset - */ - public SystemWorld getWorld() { - return world; - } - - /** - * @return Executor of the command - */ - public CommandSender getExecutor() { - return executor; - } - - - - public final static HandlerList handlers = new HandlerList(); - - public static HandlerList getHandlerList() { - return handlers; - } - - @Override - public final HandlerList getHandlers() { - return handlers; - } + + public final static HandlerList handlers = new HandlerList(); + private final SystemWorld world; + private final CommandSender executor; + + public WorldResetEvent(CommandSender executor, SystemWorld world) { + this.executor = executor; + this.world = world; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + /** + * @return world which gets reset + */ + public SystemWorld getWorld() { + return world; + } + + /** + * @return Executor of the command + */ + public CommandSender getExecutor() { + return executor; + } + + @Override + public final HandlerList getHandlers() { + return handlers; + } } diff --git a/src/main/java/de/butzlabben/world/event/WorldToggleFireEvent.java b/src/main/java/de/butzlabben/world/event/WorldToggleFireEvent.java index 1a6ba16..8d581a0 100644 --- a/src/main/java/de/butzlabben/world/event/WorldToggleFireEvent.java +++ b/src/main/java/de/butzlabben/world/event/WorldToggleFireEvent.java @@ -9,55 +9,52 @@ import org.bukkit.event.HandlerList; * @since 09.05.2018 */ public class WorldToggleFireEvent extends WorldEvent { - - private final SystemWorld world; - private final CommandSender executor; - private boolean value; - - public WorldToggleFireEvent(CommandSender executor, SystemWorld world, boolean value) { - this.executor = executor; - this.world = world; - this.value = value; - } - - /** - * @return if fire now gets enabled or disabled - */ - public boolean getValue() { - return value; - } - - /** - * @param val if fire should be enabled or disabled - */ - public void setValue(boolean val) { - value = val; - } - - /** - * @return world get world - */ - public SystemWorld getWorld() { - return world; - } - - /** - * @return get executor who toggles fire - */ - public CommandSender getExecutor() { - return executor; - } - - - - public final static HandlerList handlers = new HandlerList(); - - public static HandlerList getHandlerList() { - return handlers; - } - - @Override - public final HandlerList getHandlers() { - return handlers; - } + + public final static HandlerList handlers = new HandlerList(); + private final SystemWorld world; + private final CommandSender executor; + private boolean value; + + public WorldToggleFireEvent(CommandSender executor, SystemWorld world, boolean value) { + this.executor = executor; + this.world = world; + this.value = value; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + /** + * @return if fire now gets enabled or disabled + */ + public boolean getValue() { + return value; + } + + /** + * @param val if fire should be enabled or disabled + */ + public void setValue(boolean val) { + value = val; + } + + /** + * @return world get world + */ + public SystemWorld getWorld() { + return world; + } + + /** + * @return get executor who toggles fire + */ + public CommandSender getExecutor() { + return executor; + } + + @Override + public final HandlerList getHandlers() { + return handlers; + } } diff --git a/src/main/java/de/butzlabben/world/event/WorldToggleTntEvent.java b/src/main/java/de/butzlabben/world/event/WorldToggleTntEvent.java index 1165175..1e51906 100644 --- a/src/main/java/de/butzlabben/world/event/WorldToggleTntEvent.java +++ b/src/main/java/de/butzlabben/world/event/WorldToggleTntEvent.java @@ -9,55 +9,53 @@ import org.bukkit.event.HandlerList; * @since 09.05.2018 */ public class WorldToggleTntEvent extends WorldEvent { - - private final SystemWorld world; - private final CommandSender executor; - private boolean value; - - public WorldToggleTntEvent(CommandSender executor, SystemWorld world, boolean value) { - this.executor = executor; - this.world = world; - this.value = value; - } - - /** - * @return if tnt now gets enabled or disabled - */ - public boolean getValue() { - return value; - } - - /** - * @param val if tnt should be enabled or disabled - */ - public void setValue(boolean val) { - value = val; - } - - /** - * @return world get world - */ - public SystemWorld getWorld() { - return world; - } - - /** - * @return get executor who toggles tnt - */ - public CommandSender getExecutor() { - return executor; - } - - - public final static HandlerList handlers = new HandlerList(); - - public static HandlerList getHandlerList() { - return handlers; - } - - @Override - public final HandlerList getHandlers() { - return handlers; - } + + public final static HandlerList handlers = new HandlerList(); + private final SystemWorld world; + private final CommandSender executor; + private boolean value; + + public WorldToggleTntEvent(CommandSender executor, SystemWorld world, boolean value) { + this.executor = executor; + this.world = world; + this.value = value; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + /** + * @return if tnt now gets enabled or disabled + */ + public boolean getValue() { + return value; + } + + /** + * @param val if tnt should be enabled or disabled + */ + public void setValue(boolean val) { + value = val; + } + + /** + * @return world get world + */ + public SystemWorld getWorld() { + return world; + } + + /** + * @return get executor who toggles tnt + */ + public CommandSender getExecutor() { + return executor; + } + + @Override + public final HandlerList getHandlers() { + return handlers; + } } diff --git a/src/main/java/de/butzlabben/world/event/WorldUnloadEvent.java b/src/main/java/de/butzlabben/world/event/WorldUnloadEvent.java index f1b3e0d..6455274 100644 --- a/src/main/java/de/butzlabben/world/event/WorldUnloadEvent.java +++ b/src/main/java/de/butzlabben/world/event/WorldUnloadEvent.java @@ -9,28 +9,27 @@ import org.bukkit.event.HandlerList; */ public class WorldUnloadEvent extends WorldEvent { - private final SystemWorld world; - - public WorldUnloadEvent(SystemWorld world) { - this.world = world; - } - - /** - * @return world which gets unloaded - */ - public SystemWorld getWorld() { - return world; - } - - public final static HandlerList handlers = new HandlerList(); - - public static HandlerList getHandlerList() { - return handlers; - } - - @Override - public final HandlerList getHandlers() { - return handlers; - } + public final static HandlerList handlers = new HandlerList(); + private final SystemWorld world; + + public WorldUnloadEvent(SystemWorld world) { + this.world = world; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + /** + * @return world which gets unloaded + */ + public SystemWorld getWorld() { + return world; + } + + @Override + public final HandlerList getHandlers() { + return handlers; + } } diff --git a/src/main/java/de/butzlabben/world/gui/GuiCommand.java b/src/main/java/de/butzlabben/world/gui/GuiCommand.java index 88bbb83..7db2dfe 100644 --- a/src/main/java/de/butzlabben/world/gui/GuiCommand.java +++ b/src/main/java/de/butzlabben/world/gui/GuiCommand.java @@ -9,23 +9,23 @@ import org.bukkit.entity.Player; public class GuiCommand implements CommandExecutor { - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!(sender instanceof Player)) { - sender.sendMessage("You are not a player"); - return true; - } - WorldPlayer wp = new WorldPlayer((Player) sender); - if (!wp.isOnSystemWorld()) { - sender.sendMessage(MessageConfig.getNotOnWorld()); - return true; - } - if (!wp.isOwnerofWorld()) { - sender.sendMessage(MessageConfig.getNoPermission()); - return true; - } - ((Player) sender).openInventory(new WorldSystemGUI().getInventory((Player) sender)); - return true; - } + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage("You are not a player"); + return true; + } + WorldPlayer wp = new WorldPlayer((Player) sender); + if (!wp.isOnSystemWorld()) { + sender.sendMessage(MessageConfig.getNotOnWorld()); + return true; + } + if (!wp.isOwnerofWorld()) { + sender.sendMessage(MessageConfig.getNoPermission()); + return true; + } + ((Player) sender).openInventory(new WorldSystemGUI().getInventory((Player) sender)); + return true; + } } diff --git a/src/main/java/de/butzlabben/world/gui/PlayerOptionsGUI.java b/src/main/java/de/butzlabben/world/gui/PlayerOptionsGUI.java index 1426cb0..228a67f 100644 --- a/src/main/java/de/butzlabben/world/gui/PlayerOptionsGUI.java +++ b/src/main/java/de/butzlabben/world/gui/PlayerOptionsGUI.java @@ -18,55 +18,55 @@ import java.util.UUID; 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"), 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)); - loadItem("teleport", "/ws toggletp " + otherPlayer, new TeleportStatus(wp)); - loadItem("worldedit", "/ws togglewe " + otherPlayer, new WorldEditStatus(wp)); - loadItem("time"); - loadItem("addmember"); - loadItem("delmember"); - loadItem("setpermissions"); - loadItem("administrateworld"); - - 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); - } - } + private final static String path = "options.player."; - public void loadItem(String subpath, String message, DependListener depend) { - if (!GuiConfig.isEnabled(path + subpath)) - return; - OrcItem item = GuiConfig.getItem(path + subpath); - if (item != null) { - if (message == null) { - item.setOnClick(new ComingSoonClickListener()); - } else { - item.setOnClick(new CommandExecutorClickListener(message)); - } - addItem(GuiConfig.getSlot(path + subpath), item); - if (depend == null) { - addItem(GuiConfig.getState(path + subpath), OrcItem.coming_soon.clone()); - } else { - addItem(GuiConfig.getState(path + subpath), OrcItem.disabled.clone().setDepend(depend)); - } - } - } + public PlayerOptionsGUI(Player loader, String otherPlayer, UUID other) { + 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)); + loadItem("teleport", "/ws toggletp " + otherPlayer, new TeleportStatus(wp)); + loadItem("worldedit", "/ws togglewe " + otherPlayer, new WorldEditStatus(wp)); + loadItem("time"); + loadItem("addmember"); + loadItem("delmember"); + loadItem("setpermissions"); + loadItem("administrateworld"); - public void loadItem(String subpath, String message) { - loadItem(subpath, message, null); - } + 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) { - loadItem(subpath, null); - } + public void loadItem(String subpath, String message, DependListener depend) { + if (!GuiConfig.isEnabled(path + subpath)) + return; + OrcItem item = GuiConfig.getItem(path + subpath); + if (item != null) { + if (message == null) { + item.setOnClick(new ComingSoonClickListener()); + } else { + item.setOnClick(new CommandExecutorClickListener(message)); + } + addItem(GuiConfig.getSlot(path + subpath), item); + if (depend == null) { + addItem(GuiConfig.getState(path + subpath), OrcItem.coming_soon.clone()); + } else { + addItem(GuiConfig.getState(path + subpath), OrcItem.disabled.clone().setDepend(depend)); + } + } + } + + public void loadItem(String subpath, String message) { + loadItem(subpath, message, null); + } + + public void loadItem(String subpath) { + loadItem(subpath, null); + } } diff --git a/src/main/java/de/butzlabben/world/gui/PlayersPageGUI.java b/src/main/java/de/butzlabben/world/gui/PlayersPageGUI.java index 3362daa..4039916 100644 --- a/src/main/java/de/butzlabben/world/gui/PlayersPageGUI.java +++ b/src/main/java/de/butzlabben/world/gui/PlayersPageGUI.java @@ -22,70 +22,72 @@ import java.util.UUID; */ public class PlayersPageGUI { - @SuppressWarnings("deprecation") - public static void openGUI(Player p) { - WorldConfig config = WorldConfig.getWorldConfig(p.getWorld().getName()); + @SuppressWarnings("deprecation") + public static void openGUI(Player p) { + WorldConfig config = WorldConfig.getWorldConfig(p.getWorld().getName()); - HashMap members = config.getMembersWithNames(); + HashMap members = config.getMembersWithNames(); - if (members.size() == 0) { - p.sendMessage(MessageConfig.getNoMemberAdded()); - return; - } + if (members.size() == 0) { + p.sendMessage(MessageConfig.getNoMemberAdded()); + return; + } - PageGUICreator> creator = new PageGUICreator<>(GuiConfig.getRows("options.players")); + 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; - }); + 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);}); - } + 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); - } + creator.show(p); + } - @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; + @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; - ArrayList list = new ArrayList<>(members.keySet()); + 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(); - } + 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/src/main/java/de/butzlabben/world/gui/WorldOptionsGUI.java b/src/main/java/de/butzlabben/world/gui/WorldOptionsGUI.java index e4ceb1e..c1354a0 100644 --- a/src/main/java/de/butzlabben/world/gui/WorldOptionsGUI.java +++ b/src/main/java/de/butzlabben/world/gui/WorldOptionsGUI.java @@ -17,83 +17,82 @@ import java.util.UUID; public class WorldOptionsGUI extends OrcInventory { - private final static String path = "options.world."; + public final static HashMap data = new HashMap<>(); + private final static String path = "options.world."; - public final static HashMap data = new HashMap<>(); + public WorldOptionsGUI() { + super(GuiConfig.getTitle(GuiConfig.getConfig(), "options.world"), GuiConfig.getRows("options.world"), GuiConfig.isFill("options.world")); - public WorldOptionsGUI() { - 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()); - loadItem("fire", "/ws fire", true, new FireStatus()); - loadItem("tnt", "/ws tnt", true, new TntStatus()); + if (!GuiConfig.isEnabled(path + "reset")) + return; - if (!GuiConfig.isEnabled(path + "reset")) - return; + OrcItem item = GuiConfig.getItem(path + "reset"); + if (item != null) { + item.setOnClick((p, inv, i) -> { + p.closeInventory(); + p.chat("/ws reset"); + }); + addItem(GuiConfig.getSlot(path + "reset"), item); + } - OrcItem item = GuiConfig.getItem(path + "reset"); - if (item != null) { - item.setOnClick((p, inv, i) -> { - p.closeInventory(); - p.chat("/ws reset"); - }); - addItem(GuiConfig.getSlot(path + "reset"), item); - } + 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); + } + } - 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) { + if (!GuiConfig.isEnabled(path + subpath)) + return; + OrcItem item = GuiConfig.getItem(path + subpath); + if (item != null) { + if (message == null) { + item.setOnClick(new ComingSoonClickListener()); + } else { + item.setOnClick(new CommandExecutorClickListener(message)); + } + if (state) { + if (depend == null) { + addItem(GuiConfig.getState(path + subpath), OrcItem.coming_soon.clone()); + } else { + addItem(GuiConfig.getState(path + subpath), OrcItem.disabled.clone().setDepend(depend)); + } + } + addItem(GuiConfig.getSlot(path + subpath), item); + } + } - public void loadItem(String subpath, String message, boolean state, DependListener depend) { - if (!GuiConfig.isEnabled(path + subpath)) - return; - OrcItem item = GuiConfig.getItem(path + subpath); - if (item != null) { - if (message == null) { - item.setOnClick(new ComingSoonClickListener()); - } else { - item.setOnClick(new CommandExecutorClickListener(message)); - } - if (state) { - if (depend == null) { - addItem(GuiConfig.getState(path + subpath), OrcItem.coming_soon.clone()); - } else { - addItem(GuiConfig.getState(path + subpath), OrcItem.disabled.clone().setDepend(depend)); - } - } - addItem(GuiConfig.getSlot(path + subpath), item); - } - } + public void loadItem(String subpath, String message, boolean state) { + loadItem(subpath, message, state, null); + } - public void loadItem(String subpath, String message, boolean state) { - loadItem(subpath, message, state, null); - } + public void loadItem(String subpath, boolean state) { + loadItem(subpath, null, state); + } - public void loadItem(String subpath, boolean state) { - loadItem(subpath, null, state); - } + @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, 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 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()); - } - - public boolean canOpen(Player p) { - return new WorldPlayer(p).isOwnerofWorld(); - } + public boolean canOpen(Player p) { + return new WorldPlayer(p).isOwnerofWorld(); + } } diff --git a/src/main/java/de/butzlabben/world/gui/WorldSystemGUI.java b/src/main/java/de/butzlabben/world/gui/WorldSystemGUI.java index 99637d6..b2341dc 100644 --- a/src/main/java/de/butzlabben/world/gui/WorldSystemGUI.java +++ b/src/main/java/de/butzlabben/world/gui/WorldSystemGUI.java @@ -11,49 +11,49 @@ import org.bukkit.inventory.Inventory; public class WorldSystemGUI extends OrcInventory { - private final static String path = "worldsystem."; + private final static String path = "worldsystem."; - public WorldSystemGUI() { + public WorldSystemGUI() { - super(GuiConfig.getTitle(GuiConfig.getConfig(), "worldsystem"), GuiConfig.getRows("worldsystem"), GuiConfig.isFill("worldsystem")); + super(GuiConfig.getTitle(GuiConfig.getConfig(), "worldsystem"), GuiConfig.getRows("worldsystem"), GuiConfig.isFill("worldsystem")); - loadItem("playeroptions", (p, inv, item) -> { - p.closeInventory(); - PlayersPageGUI.openGUI(p); - }); + loadItem("playeroptions", (p, inv, item) -> { + p.closeInventory(); + PlayersPageGUI.openGUI(p); + }); - loadItem("worldoptions", new InventoryOpenClickListener(new WorldOptionsGUI())); + 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); - } - } + 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); - } + @Override + public Inventory getInventory(Player player) { + PlayersPageGUI.preloadPlayers(WorldConfig.getWorldConfig(player.getWorld().getName())); + return super.getInventory(player); + } - public void loadItem(String subpath, OrcClickListener listener) { - if (!GuiConfig.isEnabled(path + subpath)) - return; - OrcItem item = GuiConfig.getItem(path + subpath); - if (item != null) { - item.setOnClick(listener); - addItem(GuiConfig.getSlot(path + subpath), item); - } - } + public void loadItem(String subpath, OrcClickListener listener) { + if (!GuiConfig.isEnabled(path + subpath)) + 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 void loadItem(String subpath) { + loadItem(subpath, null); + } - public boolean canOpen(Player p) { - return true; - } + public boolean canOpen(Player p) { + return true; + } } \ No newline at end of file diff --git a/src/main/java/de/butzlabben/world/gui/clicklistener/ComingSoonClickListener.java b/src/main/java/de/butzlabben/world/gui/clicklistener/ComingSoonClickListener.java index 841402c..ef59b4f 100644 --- a/src/main/java/de/butzlabben/world/gui/clicklistener/ComingSoonClickListener.java +++ b/src/main/java/de/butzlabben/world/gui/clicklistener/ComingSoonClickListener.java @@ -7,10 +7,10 @@ import org.bukkit.entity.Player; public class ComingSoonClickListener implements OrcClickListener { - @Override - public void onClick(Player p, OrcInventory inv, OrcItem item) { - p.closeInventory(); - p.sendMessage("§cComing soon..."); - } + @Override + public void onClick(Player p, OrcInventory inv, OrcItem item) { + p.closeInventory(); + p.sendMessage("§cComing soon..."); + } } diff --git a/src/main/java/de/butzlabben/world/gui/clicklistener/CommandExecutorClickListener.java b/src/main/java/de/butzlabben/world/gui/clicklistener/CommandExecutorClickListener.java index 7e56d25..2bfe1f4 100644 --- a/src/main/java/de/butzlabben/world/gui/clicklistener/CommandExecutorClickListener.java +++ b/src/main/java/de/butzlabben/world/gui/clicklistener/CommandExecutorClickListener.java @@ -6,18 +6,18 @@ import de.butzlabben.inventory.OrcItem; import org.bukkit.entity.Player; public class CommandExecutorClickListener implements OrcClickListener { - - private final String message; - - public CommandExecutorClickListener(String message) { - this.message = message; - } - @Override - public void onClick(Player p, OrcInventory inv, OrcItem item) { - p.closeInventory(); + private final String message; + + public CommandExecutorClickListener(String message) { + this.message = message; + } + + @Override + public void onClick(Player p, OrcInventory inv, OrcItem item) { + p.closeInventory(); p.chat(message); - // Fix for #9 - inv.redraw(p); - } + // Fix for #9 + inv.redraw(p); + } } diff --git a/src/main/java/de/butzlabben/world/gui/clicklistener/InventoryOpenClickListener.java b/src/main/java/de/butzlabben/world/gui/clicklistener/InventoryOpenClickListener.java index d6ac2cb..e9a5604 100644 --- a/src/main/java/de/butzlabben/world/gui/clicklistener/InventoryOpenClickListener.java +++ b/src/main/java/de/butzlabben/world/gui/clicklistener/InventoryOpenClickListener.java @@ -9,25 +9,25 @@ import org.bukkit.inventory.Inventory; public class InventoryOpenClickListener implements OrcClickListener { - private final OrcInventory open; + private final OrcInventory open; - public InventoryOpenClickListener(OrcInventory inv) { - open = inv; - } + public InventoryOpenClickListener(OrcInventory inv) { + open = inv; + } - @Override - public void onClick(Player p, OrcInventory inv, OrcItem item) { - p.closeInventory(); - if (open == null) { - return; - } - Inventory to = open.getInventory(p); - if (to != null) { - p.openInventory(to); - } else { - p.closeInventory(); - p.sendMessage(MessageConfig.getNoPermission()); - } - } + @Override + public void onClick(Player p, OrcInventory inv, OrcItem item) { + p.closeInventory(); + if (open == null) { + return; + } + Inventory to = open.getInventory(p); + if (to != null) { + p.openInventory(to); + } else { + p.closeInventory(); + p.sendMessage(MessageConfig.getNoPermission()); + } + } } diff --git a/src/main/java/de/butzlabben/world/gui/playeroption/BuildStatus.java b/src/main/java/de/butzlabben/world/gui/playeroption/BuildStatus.java index 1c0e955..72230ed 100644 --- a/src/main/java/de/butzlabben/world/gui/playeroption/BuildStatus.java +++ b/src/main/java/de/butzlabben/world/gui/playeroption/BuildStatus.java @@ -7,15 +7,15 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; public class BuildStatus implements DependListener { - - private final WorldPlayer wp; - public BuildStatus(WorldPlayer wp) { - this.wp = wp; - } + private final WorldPlayer wp; - @Override - public ItemStack getItemStack(Player p, WorldPlayer player) { - return wp.canBuild() ? OrcItem.enabled.getItemStack(p, wp) : OrcItem.disabled.getItemStack(p, wp); - } + public BuildStatus(WorldPlayer wp) { + this.wp = wp; + } + + @Override + public ItemStack getItemStack(Player p, WorldPlayer player) { + return wp.canBuild() ? OrcItem.enabled.getItemStack(p, wp) : OrcItem.disabled.getItemStack(p, wp); + } } diff --git a/src/main/java/de/butzlabben/world/gui/playeroption/GamemodeStatus.java b/src/main/java/de/butzlabben/world/gui/playeroption/GamemodeStatus.java index 1f0edf0..5e2006f 100644 --- a/src/main/java/de/butzlabben/world/gui/playeroption/GamemodeStatus.java +++ b/src/main/java/de/butzlabben/world/gui/playeroption/GamemodeStatus.java @@ -7,15 +7,15 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; public class GamemodeStatus implements DependListener { - - private final WorldPlayer wp; - public GamemodeStatus(WorldPlayer wp) { - this.wp = wp; - } + private final WorldPlayer wp; - @Override - public ItemStack getItemStack(Player p, WorldPlayer player) { - return wp.canChangeGamemode() ? OrcItem.enabled.getItemStack(p, wp) : OrcItem.disabled.getItemStack(p, wp); - } + public GamemodeStatus(WorldPlayer wp) { + this.wp = wp; + } + + @Override + 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/src/main/java/de/butzlabben/world/gui/playeroption/TeleportStatus.java b/src/main/java/de/butzlabben/world/gui/playeroption/TeleportStatus.java index 140a541..6041b6b 100644 --- a/src/main/java/de/butzlabben/world/gui/playeroption/TeleportStatus.java +++ b/src/main/java/de/butzlabben/world/gui/playeroption/TeleportStatus.java @@ -8,14 +8,14 @@ import org.bukkit.inventory.ItemStack; public class TeleportStatus implements DependListener { - private final WorldPlayer wp; + private final WorldPlayer wp; - public TeleportStatus(WorldPlayer wp) { - this.wp = wp; - } + public TeleportStatus(WorldPlayer wp) { + this.wp = wp; + } - @Override - public ItemStack getItemStack(Player p, WorldPlayer player) { - return wp.canTeleport() ? OrcItem.enabled.getItemStack(p, wp) : OrcItem.disabled.getItemStack(p, wp); - } + @Override + 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/src/main/java/de/butzlabben/world/gui/worldoption/FireStatus.java b/src/main/java/de/butzlabben/world/gui/worldoption/FireStatus.java index 36c645b..de3927c 100644 --- a/src/main/java/de/butzlabben/world/gui/worldoption/FireStatus.java +++ b/src/main/java/de/butzlabben/world/gui/worldoption/FireStatus.java @@ -13,22 +13,22 @@ import java.io.File; public class FireStatus implements DependListener { - @Override - public ItemStack getItemStack(Player p, WorldPlayer wp) { - String worldname = new DependenceConfig(p).getWorldname(); - File file = new File(worldname + "/worldconfig.yml"); - if (!file.exists()) - file = new File(PluginConfig.getWorlddir() + "/worldconfig.yml"); - if (!file.exists()) - return null; - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); - boolean b = cfg.getBoolean("Settings.Fire"); - if (b) - return OrcItem.enabled.getItemStack(p); + @Override + public ItemStack getItemStack(Player p, WorldPlayer wp) { + String worldname = new DependenceConfig(p).getWorldname(); + File file = new File(worldname + "/worldconfig.yml"); + if (!file.exists()) + file = new File(PluginConfig.getWorlddir() + "/worldconfig.yml"); + if (!file.exists()) + return null; + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); + boolean b = cfg.getBoolean("Settings.Fire"); + if (b) + return OrcItem.enabled.getItemStack(p); - return null; - // TODO wenn enabled, dann return OrcItem.enabled.getItemStack(p, wp); - // sonst return null - } + return null; + // TODO wenn enabled, dann return OrcItem.enabled.getItemStack(p, wp); + // sonst return null + } } diff --git a/src/main/java/de/butzlabben/world/gui/worldoption/TntStatus.java b/src/main/java/de/butzlabben/world/gui/worldoption/TntStatus.java index 38867b8..77480af 100644 --- a/src/main/java/de/butzlabben/world/gui/worldoption/TntStatus.java +++ b/src/main/java/de/butzlabben/world/gui/worldoption/TntStatus.java @@ -13,22 +13,22 @@ import java.io.File; public class TntStatus implements DependListener { - @Override - public ItemStack getItemStack(Player p, WorldPlayer wp) { - String worldname = new DependenceConfig(p).getWorldname(); - File file = new File(worldname + "/worldconfig.yml"); - if (!file.exists()) - file = new File(PluginConfig.getWorlddir() + "/worldconfig.yml"); - if (!file.exists()) - return null; - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); - boolean b = cfg.getBoolean("Settings.TNTDamage"); - if (b) - return OrcItem.enabled.getItemStack(p); + @Override + public ItemStack getItemStack(Player p, WorldPlayer wp) { + String worldname = new DependenceConfig(p).getWorldname(); + File file = new File(worldname + "/worldconfig.yml"); + if (!file.exists()) + file = new File(PluginConfig.getWorlddir() + "/worldconfig.yml"); + if (!file.exists()) + return null; + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); + boolean b = cfg.getBoolean("Settings.TNTDamage"); + if (b) + return OrcItem.enabled.getItemStack(p); - return null; - // TODO wenn enabled, dann return OrcItem.enabled.getItemStack(p, wp); - // sonst return null - } + return null; + // TODO wenn enabled, dann return OrcItem.enabled.getItemStack(p, wp); + // sonst return null + } } diff --git a/src/main/java/de/butzlabben/world/listener/BlockListener.java b/src/main/java/de/butzlabben/world/listener/BlockListener.java index 7520d09..ada2fd1 100644 --- a/src/main/java/de/butzlabben/world/listener/BlockListener.java +++ b/src/main/java/de/butzlabben/world/listener/BlockListener.java @@ -15,62 +15,63 @@ import java.io.File; import java.util.Objects; public class BlockListener implements Listener { - - @EventHandler - public void onExplode(EntityExplodeEvent e) { - File file = WorldConfig.getWorldFile(Objects.requireNonNull(e.getLocation().getWorld()).getName()); - if(!file.exists()) - return; - WorldConfig wc = WorldConfig.getWorldConfig(e.getLocation().getWorld().getName()); - e.setCancelled(!wc.isTnt()); - } - @EventHandler - public void onPlace(BlockPlaceEvent e) { - Player p = e.getPlayer(); - if (p.hasPermission("ws.build")) - return; - String worldname = p.getWorld().getName(); - WorldPlayer wp = new WorldPlayer(p, worldname); - if (!wp.isOnSystemWorld()) - return; - if(!wp.isMember()) - e.setCancelled(true); - if (!wp.isOwnerofWorld()) { - e.setCancelled(!wp.canBuild()); - } - } + @EventHandler + public void onExplode(EntityExplodeEvent e) { + File file = WorldConfig.getWorldFile(Objects.requireNonNull(e.getLocation().getWorld()).getName()); + if (!file.exists()) + return; + WorldConfig wc = WorldConfig.getWorldConfig(e.getLocation().getWorld().getName()); + e.setCancelled(!wc.isTnt()); + } - @EventHandler - public void onBreak(BlockBreakEvent e) { - Player p = e.getPlayer(); - if (p.hasPermission("ws.build")) - return; - String worldname = p.getWorld().getName(); - WorldPlayer wp = new WorldPlayer(p, worldname); - if (!wp.isOnSystemWorld()) - return; - if(!wp.isMember()) - e.setCancelled(true); - if (!wp.isOwnerofWorld()) { - e.setCancelled(!wp.canBuild()); - } - } - @EventHandler - public void onFire(BlockIgniteEvent e) { - File file = WorldConfig.getWorldFile(e.getBlock().getWorld().getName()); - if(!file.exists()) - return; - WorldConfig wc = WorldConfig.getWorldConfig(e.getBlock().getWorld().getName()); - e.setCancelled(!wc.isFire()); - } + @EventHandler + public void onPlace(BlockPlaceEvent e) { + Player p = e.getPlayer(); + if (p.hasPermission("ws.build")) + return; + String worldname = p.getWorld().getName(); + WorldPlayer wp = new WorldPlayer(p, worldname); + if (!wp.isOnSystemWorld()) + return; + if (!wp.isMember()) + e.setCancelled(true); + if (!wp.isOwnerofWorld()) { + e.setCancelled(!wp.canBuild()); + } + } - @EventHandler - public void onFire(BlockBurnEvent e) { - File file = WorldConfig.getWorldFile(e.getBlock().getWorld().getName()); - if(!file.exists()) - return; - WorldConfig wc = WorldConfig.getWorldConfig(e.getBlock().getWorld().getName()); - e.setCancelled(!wc.isFire()); - } + @EventHandler + public void onBreak(BlockBreakEvent e) { + Player p = e.getPlayer(); + if (p.hasPermission("ws.build")) + return; + String worldname = p.getWorld().getName(); + WorldPlayer wp = new WorldPlayer(p, worldname); + if (!wp.isOnSystemWorld()) + return; + if (!wp.isMember()) + e.setCancelled(true); + if (!wp.isOwnerofWorld()) { + e.setCancelled(!wp.canBuild()); + } + } + + @EventHandler + public void onFire(BlockIgniteEvent e) { + File file = WorldConfig.getWorldFile(e.getBlock().getWorld().getName()); + if (!file.exists()) + return; + WorldConfig wc = WorldConfig.getWorldConfig(e.getBlock().getWorld().getName()); + e.setCancelled(!wc.isFire()); + } + + @EventHandler + public void onFire(BlockBurnEvent e) { + File file = WorldConfig.getWorldFile(e.getBlock().getWorld().getName()); + if (!file.exists()) + return; + WorldConfig wc = WorldConfig.getWorldConfig(e.getBlock().getWorld().getName()); + e.setCancelled(!wc.isFire()); + } } diff --git a/src/main/java/de/butzlabben/world/listener/PlayerDeathListener.java b/src/main/java/de/butzlabben/world/listener/PlayerDeathListener.java index 8ee0b71..ac546ab 100644 --- a/src/main/java/de/butzlabben/world/listener/PlayerDeathListener.java +++ b/src/main/java/de/butzlabben/world/listener/PlayerDeathListener.java @@ -15,36 +15,36 @@ import java.util.UUID; public class PlayerDeathListener implements Listener { - private final HashMap deathLocations = new HashMap<>(); + private final HashMap deathLocations = new HashMap<>(); - @EventHandler - public void onDie(PlayerDeathEvent e) { - Player p = e.getEntity(); - WorldPlayer wp = new WorldPlayer(p, p.getWorld().getName()); - if (wp.isOnSystemWorld()) { - deathLocations.put(p.getUniqueId(), p.getLocation().getWorld()); - } else { - p.setGameMode(PluginConfig.getSpawnGamemode()); - } - } + @EventHandler + public void onDie(PlayerDeathEvent e) { + Player p = e.getEntity(); + WorldPlayer wp = new WorldPlayer(p, p.getWorld().getName()); + if (wp.isOnSystemWorld()) { + deathLocations.put(p.getUniqueId(), p.getLocation().getWorld()); + } else { + p.setGameMode(PluginConfig.getSpawnGamemode()); + } + } - @EventHandler - public void onRespawn(PlayerRespawnEvent e) { - Player p = e.getPlayer(); - if (deathLocations.containsKey(p.getUniqueId())) { - World world = deathLocations.remove(p.getUniqueId()); + @EventHandler + public void onRespawn(PlayerRespawnEvent e) { + Player p = e.getPlayer(); + if (deathLocations.containsKey(p.getUniqueId())) { + World world = deathLocations.remove(p.getUniqueId()); - WorldConfig config = WorldConfig.getWorldConfig(world.getName()); - - if (config.getHome() != null) { - e.setRespawnLocation(config.getHome()); - } else { - if (PluginConfig.useWorldSpawn()) { - e.setRespawnLocation(PluginConfig.getWorldSpawn(world)); - } else { - e.setRespawnLocation(world.getSpawnLocation()); - } - } - } - } + WorldConfig config = WorldConfig.getWorldConfig(world.getName()); + + if (config.getHome() != null) { + e.setRespawnLocation(config.getHome()); + } else { + if (PluginConfig.useWorldSpawn()) { + e.setRespawnLocation(PluginConfig.getWorldSpawn(world)); + } else { + e.setRespawnLocation(world.getSpawnLocation()); + } + } + } + } } diff --git a/src/main/java/de/butzlabben/world/listener/PlayerListener.java b/src/main/java/de/butzlabben/world/listener/PlayerListener.java index 9a9b397..f54706f 100644 --- a/src/main/java/de/butzlabben/world/listener/PlayerListener.java +++ b/src/main/java/de/butzlabben/world/listener/PlayerListener.java @@ -16,31 +16,31 @@ import org.bukkit.event.player.PlayerQuitEvent; public class PlayerListener implements Listener { - //#17 - @EventHandler(priority = EventPriority.HIGHEST) - public void onJoin(PlayerJoinEvent e) { - if (PluginConfig.spawnTeleportation()) { - Player p = e.getPlayer(); - DependenceConfig dc = new DependenceConfig(p); - if (dc.hasWorld()) { - SystemWorld sw = SystemWorld.getSystemWorld(dc.getWorldname()); - if (sw != null && !sw.isLoaded()) { - e.getPlayer().teleport(PluginConfig.getSpawn(e.getPlayer())); - } - } - } - } + //#17 + @EventHandler(priority = EventPriority.HIGHEST) + public void onJoin(PlayerJoinEvent e) { + if (PluginConfig.spawnTeleportation()) { + Player p = e.getPlayer(); + DependenceConfig dc = new DependenceConfig(p); + if (dc.hasWorld()) { + SystemWorld sw = SystemWorld.getSystemWorld(dc.getWorldname()); + if (sw != null && !sw.isLoaded()) { + e.getPlayer().teleport(PluginConfig.getSpawn(e.getPlayer())); + } + } + } + } - @EventHandler - public void onLeave(PlayerQuitEvent e) { - Player p = e.getPlayer(); - World w = p.getWorld(); - WorldPlayer player = new WorldPlayer(p); - // Save last location for #23 - if (player.isOnSystemWorld()) { - WorldConfig config = WorldConfig.getWorldConfig(player.getWorldname()); - PlayerPositions.getInstance().saveWorldsPlayerLocation(p, config); - } - SystemWorld.tryUnloadLater(w); - } + @EventHandler + public void onLeave(PlayerQuitEvent e) { + Player p = e.getPlayer(); + World w = p.getWorld(); + WorldPlayer player = new WorldPlayer(p); + // Save last location for #23 + if (player.isOnSystemWorld()) { + WorldConfig config = WorldConfig.getWorldConfig(player.getWorldname()); + PlayerPositions.getInstance().saveWorldsPlayerLocation(p, config); + } + SystemWorld.tryUnloadLater(w); + } } \ No newline at end of file diff --git a/src/main/java/de/butzlabben/world/listener/WorldEditListener.java b/src/main/java/de/butzlabben/world/listener/WorldEditListener.java index 949696b..1b1c08f 100644 --- a/src/main/java/de/butzlabben/world/listener/WorldEditListener.java +++ b/src/main/java/de/butzlabben/world/listener/WorldEditListener.java @@ -1,13 +1,11 @@ package de.butzlabben.world.listener; import com.sk89q.worldedit.bukkit.WorldEditPlugin; -import com.sk89q.worldedit.extension.platform.CommandManager; import de.butzlabben.world.config.MessageConfig; import de.butzlabben.world.config.WorldConfig; import de.butzlabben.world.config.WorldPerm; import de.butzlabben.world.wrapper.WorldPlayer; import org.bukkit.Bukkit; -import org.bukkit.command.Command; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -37,7 +35,7 @@ public class WorldEditListener implements Listener { private boolean isWorldEditCommand(String command) { WorldEditPlugin plugin = (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"); // WorldEdit plugin not foung - if(plugin == null) + if (plugin == null) return false; if (command.startsWith("/")) { command = command.replaceFirst("/", ""); diff --git a/src/main/java/de/butzlabben/world/util/MoneyUtil.java b/src/main/java/de/butzlabben/world/util/MoneyUtil.java index 1a2adc8..0f23dfc 100644 --- a/src/main/java/de/butzlabben/world/util/MoneyUtil.java +++ b/src/main/java/de/butzlabben/world/util/MoneyUtil.java @@ -32,6 +32,9 @@ public class MoneyUtil { Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "Couldn't find a Vault Economy extension"); } + private MoneyUtil() { + } + public static void removeMoney(UUID uuid, int money) { Preconditions.checkNotNull(uuid); Preconditions.checkNotNull(economy); @@ -53,7 +56,4 @@ public class MoneyUtil { Economy economy = (Economy) MoneyUtil.economy; return economy.getBalance(op) >= money; } - - private MoneyUtil() { - } } diff --git a/src/main/java/de/butzlabben/world/util/PlayerPositions.java b/src/main/java/de/butzlabben/world/util/PlayerPositions.java index 452da3b..bd209ba 100644 --- a/src/main/java/de/butzlabben/world/util/PlayerPositions.java +++ b/src/main/java/de/butzlabben/world/util/PlayerPositions.java @@ -27,6 +27,10 @@ public class PlayerPositions { private final DatabaseUtil util = DatabaseRepository.getInstance().getUtil(); + private PlayerPositions() { + checkTables(); + } + public Location injectWorldsLocation(Player player, WorldConfig config, Location location) { if (!PluginConfig.useWorldSpawnLastLocation()) return location; @@ -65,7 +69,7 @@ public class PlayerPositions { public Location injectPlayersLocation(Player player, Location location) { if (!PluginConfig.useSpawnLastLocation()) return location; - if(player == null) + if (player == null) return location; Preconditions.checkNotNull(location); UUID uuid = player.getUniqueId(); @@ -198,8 +202,4 @@ public class PlayerPositions { e.printStackTrace(); } } - - private PlayerPositions() { - checkTables(); - } } diff --git a/src/main/java/de/butzlabben/world/util/TeleportUtil.java b/src/main/java/de/butzlabben/world/util/TeleportUtil.java index 814c33a..14c22d7 100644 --- a/src/main/java/de/butzlabben/world/util/TeleportUtil.java +++ b/src/main/java/de/butzlabben/world/util/TeleportUtil.java @@ -11,19 +11,19 @@ import java.util.UUID; * @since 13.09.2018 */ public class TeleportUtil { - - private static final HashMap oldLocs = new HashMap<>(); - - public static void teleportPlayer(Player p, Location loc) { - // Save old player location. - // If he does another teleport he will be taken back then to the first location - if(!oldLocs.containsKey(p.getUniqueId())) { - Location oldLoc = p.getLocation(); - oldLocs.put(p.getUniqueId(), oldLoc); - } - - } - private TeleportUtil() { - } + private static final HashMap oldLocs = new HashMap<>(); + + private TeleportUtil() { + } + + public static void teleportPlayer(Player p, Location loc) { + // Save old player location. + // If he does another teleport he will be taken back then to the first location + if (!oldLocs.containsKey(p.getUniqueId())) { + Location oldLoc = p.getLocation(); + oldLocs.put(p.getUniqueId(), oldLoc); + } + + } } diff --git a/src/main/java/de/butzlabben/world/util/VersionUtil.java b/src/main/java/de/butzlabben/world/util/VersionUtil.java index 7b3205a..3a814a8 100644 --- a/src/main/java/de/butzlabben/world/util/VersionUtil.java +++ b/src/main/java/de/butzlabben/world/util/VersionUtil.java @@ -10,6 +10,9 @@ public class VersionUtil { private static int version; + private VersionUtil() { + } + public static int getVersion() { if (version == 0) { // Detect version @@ -46,7 +49,4 @@ public class VersionUtil { } return version; } - - private VersionUtil() { - } } diff --git a/src/main/java/de/butzlabben/world/util/database/DatabaseConnection.java b/src/main/java/de/butzlabben/world/util/database/DatabaseConnection.java index 448c154..affe1c9 100644 --- a/src/main/java/de/butzlabben/world/util/database/DatabaseConnection.java +++ b/src/main/java/de/butzlabben/world/util/database/DatabaseConnection.java @@ -3,8 +3,8 @@ package de.butzlabben.world.util.database; import java.sql.*; public abstract class DatabaseConnection implements DatabaseUtil { - Connection connection; final Object lock = new Object(); + Connection connection; public void close() { synchronized (lock) { diff --git a/src/main/java/de/butzlabben/world/util/database/DatabaseUtil.java b/src/main/java/de/butzlabben/world/util/database/DatabaseUtil.java index 4f64d02..b0fdf9e 100644 --- a/src/main/java/de/butzlabben/world/util/database/DatabaseUtil.java +++ b/src/main/java/de/butzlabben/world/util/database/DatabaseUtil.java @@ -7,8 +7,12 @@ import java.sql.SQLException; public interface DatabaseUtil { ResultSet executeQuery(PreparedStatement preparedStatement) throws SQLException; + int executeUpdate(PreparedStatement preparedStatement) throws SQLException; + PreparedStatement prepareStatement(String sql) throws SQLException; + void close(); + void connect(); } diff --git a/src/main/java/de/butzlabben/world/wrapper/AsyncCreatorAdapter.java b/src/main/java/de/butzlabben/world/wrapper/AsyncCreatorAdapter.java index 07e1059..25300c9 100644 --- a/src/main/java/de/butzlabben/world/wrapper/AsyncCreatorAdapter.java +++ b/src/main/java/de/butzlabben/world/wrapper/AsyncCreatorAdapter.java @@ -15,28 +15,28 @@ import java.util.Objects; */ public class AsyncCreatorAdapter implements CreatorAdapter { - // Create worlds async to close #16 - @Override - public void create(WorldCreator creator, SystemWorld sw, Runnable r) { - TaskManager.IMP.async(() -> { - AsyncWorld world; - if (Bukkit.getWorld(creator.name()) == null) - world = AsyncWorld.create(creator); - else - world = AsyncWorld.wrap(Objects.requireNonNull(Bukkit.getWorld(creator.name()))); + // Create worlds async to close #16 + @Override + public void create(WorldCreator creator, SystemWorld sw, Runnable r) { + TaskManager.IMP.async(() -> { + AsyncWorld world; + if (Bukkit.getWorld(creator.name()) == null) + world = AsyncWorld.create(creator); + else + world = AsyncWorld.wrap(Objects.requireNonNull(Bukkit.getWorld(creator.name()))); - Block block = world.getBlockAt(0, 0, 0); - block.setType(Material.BEDROCK); + Block block = world.getBlockAt(0, 0, 0); + block.setType(Material.BEDROCK); - // When you are done - world.commit(); - Bukkit.getWorlds().add(world); - if (sw != null) - sw.setCreating(false); + // When you are done + world.commit(); + Bukkit.getWorlds().add(world); + if (sw != null) + sw.setCreating(false); - // Send the message - r.run(); - }); + // Send the message + r.run(); + }); } } diff --git a/src/main/java/de/butzlabben/world/wrapper/CreatorAdapter.java b/src/main/java/de/butzlabben/world/wrapper/CreatorAdapter.java index fb40d8b..35c84bb 100644 --- a/src/main/java/de/butzlabben/world/wrapper/CreatorAdapter.java +++ b/src/main/java/de/butzlabben/world/wrapper/CreatorAdapter.java @@ -8,5 +8,5 @@ import org.bukkit.WorldCreator; */ public interface CreatorAdapter { - void create(WorldCreator creator, SystemWorld world, Runnable sendPlayerMessageCallback); + void create(WorldCreator creator, SystemWorld world, Runnable sendPlayerMessageCallback); } diff --git a/src/main/java/de/butzlabben/world/wrapper/SystemWorld.java b/src/main/java/de/butzlabben/world/wrapper/SystemWorld.java index da1c0c9..27d7c6a 100644 --- a/src/main/java/de/butzlabben/world/wrapper/SystemWorld.java +++ b/src/main/java/de/butzlabben/world/wrapper/SystemWorld.java @@ -24,12 +24,16 @@ import java.util.HashMap; */ public class SystemWorld { + private static final HashMap cached = new HashMap<>(); private World w; private String worldname; private boolean unloading = false; private boolean creating = false; - private static final HashMap cached = new HashMap<>(); + private SystemWorld(String worldname) { + this.worldname = worldname; + w = Bukkit.getWorld(worldname); + } /** * This method is the online way to get a system world instance @@ -66,9 +70,99 @@ public class SystemWorld { }, 20); } - private SystemWorld(String worldname) { - this.worldname = worldname; - w = Bukkit.getWorld(worldname); + /** + * Trys to create a new systemworld with all entries etc. finally loads the + * world + * + * @param p Player to create the world for + * @return whether it succesfull or not + */ + public static boolean create(Player p, WorldTemplate template) { + + DependenceConfig dc = new DependenceConfig(p); + + String uuid = p.getUniqueId().toString(); + int id = DependenceConfig.getHighestID() + 1; + String worldname = "ID" + id + "-" + uuid; + + WorldCreator creator = template.getGeneratorSettings().asWorldCreator(worldname); + + WorldCreateEvent event = new WorldCreateEvent(p, creator); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) + return false; + + dc.createNewEntry(); + + String worlddir = PluginConfig.getWorlddir(); + 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); + + 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, template); + + // 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(); + } + } + 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() { + WorldSystem.getInstance().getAdapter().create(event.getWorldCreator(), sw, () -> { + // Fix for #16 + new BukkitRunnable() { + @Override + public void run() { + 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)); + } + } + }.runTask(WorldSystem.getInstance()); + }); + } + }.runTaskLater(WorldSystem.getInstance(), 1); + + return true; } /** @@ -250,101 +344,6 @@ public class SystemWorld { dc.setLastLoaded(); } - /** - * Trys to create a new systemworld with all entries etc. finally loads the - * world - * - * @param p Player to create the world for - * @return whether it succesfull or not - */ - public static boolean create(Player p, WorldTemplate template) { - - DependenceConfig dc = new DependenceConfig(p); - - String uuid = p.getUniqueId().toString(); - int id = DependenceConfig.getHighestID() + 1; - String worldname = "ID" + id + "-" + uuid; - - WorldCreator creator = template.getGeneratorSettings().asWorldCreator(worldname); - - WorldCreateEvent event = new WorldCreateEvent(p, creator); - Bukkit.getPluginManager().callEvent(event); - if (event.isCancelled()) - return false; - - dc.createNewEntry(); - - String worlddir = PluginConfig.getWorlddir(); - 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); - - 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, template); - - // 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(); - } - } - 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() { - WorldSystem.getInstance().getAdapter().create(event.getWorldCreator(), sw, () -> { - // Fix for #16 - new BukkitRunnable() { - @Override - public void run() { - 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)); - } - } - }.runTask(WorldSystem.getInstance()); - }); - } - }.runTaskLater(WorldSystem.getInstance(), 1); - - return true; - } - /** * @return if the world is loaded */ @@ -413,14 +412,14 @@ public class SystemWorld { return w; } - public void setCreating(boolean creating) { - this.creating = creating; - } - public boolean isCreating() { return creating; } + public void setCreating(boolean creating) { + this.creating = creating; + } + /** * @return the worldname */ diff --git a/src/main/java/de/butzlabben/world/wrapper/WorldPlayer.java b/src/main/java/de/butzlabben/world/wrapper/WorldPlayer.java index 148f0ee..129f7e1 100644 --- a/src/main/java/de/butzlabben/world/wrapper/WorldPlayer.java +++ b/src/main/java/de/butzlabben/world/wrapper/WorldPlayer.java @@ -24,6 +24,15 @@ public class WorldPlayer { private final OfflinePlayer p; private final String worldname; + public WorldPlayer(OfflinePlayer p, String worldname) { + this.p = p; + this.worldname = worldname; + } + + public WorldPlayer(Player p) { + this(p, p.getWorld().getName()); + } + /** * @return the worldname, where the worldplayer object was created for */ @@ -87,7 +96,6 @@ public class WorldPlayer { return wc.canWorldEdit(this.p.getUniqueId()); } - /** * toggles teleporting for this player * @@ -162,15 +170,6 @@ public class WorldPlayer { return wc.isMember(p.getUniqueId()); } - public WorldPlayer(OfflinePlayer p, String worldname) { - this.p = p; - this.worldname = worldname; - } - - public WorldPlayer(Player p) { - this(p, p.getWorld().getName()); - } - /** * @return if he is on a systemworld or not */ diff --git a/src/main/java/de/butzlabben/world/wrapper/WorldTemplateProvider.java b/src/main/java/de/butzlabben/world/wrapper/WorldTemplateProvider.java index 20fda4e..04080e0 100644 --- a/src/main/java/de/butzlabben/world/wrapper/WorldTemplateProvider.java +++ b/src/main/java/de/butzlabben/world/wrapper/WorldTemplateProvider.java @@ -15,11 +15,6 @@ import java.util.HashMap; public class WorldTemplateProvider { private static final WorldTemplateProvider instance = new WorldTemplateProvider(); - - public static WorldTemplateProvider getInstance() { - return instance; - } - private final HashMap templates = new HashMap<>(); private WorldTemplateProvider() { @@ -49,6 +44,10 @@ public class WorldTemplateProvider { } } + public static WorldTemplateProvider getInstance() { + return instance; + } + public WorldTemplate getTemplate(String key) { return templates.get(key); } @@ -62,7 +61,8 @@ public class WorldTemplateProvider { return null; try { return World.Environment.valueOf(env); - } catch (Exception ignored) {} + } catch (Exception ignored) { + } return null; } @@ -71,7 +71,8 @@ public class WorldTemplateProvider { return null; try { return WorldType.valueOf(type); - } catch (Exception ignored) {} + } catch (Exception ignored) { + } return null; } } diff --git a/src/main/java/org/bstats/bukkit/Metrics.java b/src/main/java/org/bstats/bukkit/Metrics.java index c3e258c..369b15f 100644 --- a/src/main/java/org/bstats/bukkit/Metrics.java +++ b/src/main/java/org/bstats/bukkit/Metrics.java @@ -25,11 +25,20 @@ import java.util.zip.GZIPOutputStream; /** * bStats collects some data for plugin authors. - * + *

* Check out https://bStats.org/ to learn more about bStats! */ public class Metrics { + // The version of this bStats class + public static final int B_STATS_VERSION = 1; + // The url to which the data is sent + private static final String URL = "https://bStats.org/submitData/bukkit"; + // Should failed requests be logged? + private static boolean logFailedRequests; + // The uuid of the server + private static String serverUUID; + static { // You can use the property to disable the check in your test environment if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) { @@ -43,18 +52,6 @@ public class Metrics { } } - // The version of this bStats class - public static final int B_STATS_VERSION = 1; - - // The url to which the data is sent - private static final String URL = "https://bStats.org/submitData/bukkit"; - - // Should failed requests be logged? - private static boolean logFailedRequests; - - // The uuid of the server - private static String serverUUID; - // The plugin private final JavaPlugin plugin; @@ -96,7 +93,8 @@ public class Metrics { ).copyDefaults(true); try { config.save(configFile); - } catch (IOException ignored) { } + } catch (IOException ignored) { + } } // Load the data @@ -110,7 +108,8 @@ public class Metrics { service.getField("B_STATS_VERSION"); // Our identifier :) found = true; // We aren't the first break; - } catch (NoSuchFieldException ignored) { } + } catch (NoSuchFieldException ignored) { + } } // Register our service Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal); @@ -121,161 +120,6 @@ public class Metrics { } } - /** - * Adds a custom chart. - * - * @param chart The chart to add. - */ - public void addCustomChart(CustomChart chart) { - if (chart == null) { - throw new IllegalArgumentException("Chart cannot be null!"); - } - charts.add(chart); - } - - /** - * Starts the Scheduler which submits our data every 30 minutes. - */ - private void startSubmitting() { - final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags - timer.scheduleAtFixedRate(new TimerTask() { - @Override - public void run() { - if (!plugin.isEnabled()) { // Plugin was disabled - timer.cancel(); - return; - } - // Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler - // Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;) - Bukkit.getScheduler().runTask(plugin, new Runnable() { - @Override - public void run() { - submitData(); - } - }); - } - }, 1000*60*5, 1000*60*30); - // Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start - // WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted! - // WARNING: Just don't do it! - } - - /** - * Gets the plugin specific data. - * This method is called using Reflection. - * - * @return The plugin specific data. - */ - @SuppressWarnings("unchecked") - public JSONObject getPluginData() { - JSONObject data = new JSONObject(); - - String pluginName = plugin.getDescription().getName(); - String pluginVersion = plugin.getDescription().getVersion(); - - data.put("pluginName", pluginName); // Append the name of the plugin - data.put("pluginVersion", pluginVersion); // Append the version of the plugin - JSONArray customCharts = new JSONArray(); - for (CustomChart customChart : charts) { - // Add the data of the custom charts - JSONObject chart = customChart.getRequestJsonObject(); - if (chart == null) { // If the chart is null, we skip it - continue; - } - customCharts.add(chart); - } - data.put("customCharts", customCharts); - - return data; - } - - /** - * Gets the server specific data. - * - * @return The server specific data. - */ - @SuppressWarnings("unchecked") - private JSONObject getServerData() { - // Minecraft specific data - int playerAmount; - try { - // Around MC 1.8 the return type was changed to a collection from an array, - // This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection; - Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers"); - playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class) - ? ((Collection) onlinePlayersMethod.invoke(Bukkit.getServer())).size() - : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length; - } catch (Exception e) { - playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed - } - int onlineMode = Bukkit.getOnlineMode() ? 1 : 0; - String bukkitVersion = org.bukkit.Bukkit.getVersion(); - bukkitVersion = bukkitVersion.substring(bukkitVersion.indexOf("MC: ") + 4, bukkitVersion.length() - 1); - - // OS/Java specific data - String javaVersion = System.getProperty("java.version"); - String osName = System.getProperty("os.name"); - String osArch = System.getProperty("os.arch"); - String osVersion = System.getProperty("os.version"); - int coreCount = Runtime.getRuntime().availableProcessors(); - - JSONObject data = new JSONObject(); - - data.put("serverUUID", serverUUID); - - data.put("playerAmount", playerAmount); - data.put("onlineMode", onlineMode); - data.put("bukkitVersion", bukkitVersion); - - data.put("javaVersion", javaVersion); - data.put("osName", osName); - data.put("osArch", osArch); - data.put("osVersion", osVersion); - data.put("coreCount", coreCount); - - return data; - } - - /** - * Collects the data and sends it afterwards. - */ - @SuppressWarnings("unchecked") - private void submitData() { - final JSONObject data = getServerData(); - - JSONArray pluginData = new JSONArray(); - // Search for all other bStats Metrics classes to get their plugin data - for (Class service : Bukkit.getServicesManager().getKnownServices()) { - try { - service.getField("B_STATS_VERSION"); // Our identifier :) - - for (RegisteredServiceProvider provider : Bukkit.getServicesManager().getRegistrations(service)) { - try { - pluginData.add(provider.getService().getMethod("getPluginData").invoke(provider.getProvider())); - } catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { } - } - } catch (NoSuchFieldException ignored) { } - } - - data.put("plugins", pluginData); - - // Create a new thread for the connection to the bStats server - new Thread(new Runnable() { - @Override - public void run() { - try { - // Send the data - sendData(data); - } catch (Exception e) { - // Something went wrong! :( - if (logFailedRequests) { - plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e); - } - } - } - }).start(); - } - /** * Sends the data to the bStats server. * @@ -331,6 +175,163 @@ public class Metrics { return outputStream.toByteArray(); } + /** + * Adds a custom chart. + * + * @param chart The chart to add. + */ + public void addCustomChart(CustomChart chart) { + if (chart == null) { + throw new IllegalArgumentException("Chart cannot be null!"); + } + charts.add(chart); + } + + /** + * Starts the Scheduler which submits our data every 30 minutes. + */ + private void startSubmitting() { + final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags + timer.scheduleAtFixedRate(new TimerTask() { + @Override + public void run() { + if (!plugin.isEnabled()) { // Plugin was disabled + timer.cancel(); + return; + } + // Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler + // Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;) + Bukkit.getScheduler().runTask(plugin, new Runnable() { + @Override + public void run() { + submitData(); + } + }); + } + }, 1000 * 60 * 5, 1000 * 60 * 30); + // Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start + // WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted! + // WARNING: Just don't do it! + } + + /** + * Gets the plugin specific data. + * This method is called using Reflection. + * + * @return The plugin specific data. + */ + @SuppressWarnings("unchecked") + public JSONObject getPluginData() { + JSONObject data = new JSONObject(); + + String pluginName = plugin.getDescription().getName(); + String pluginVersion = plugin.getDescription().getVersion(); + + data.put("pluginName", pluginName); // Append the name of the plugin + data.put("pluginVersion", pluginVersion); // Append the version of the plugin + JSONArray customCharts = new JSONArray(); + for (CustomChart customChart : charts) { + // Add the data of the custom charts + JSONObject chart = customChart.getRequestJsonObject(); + if (chart == null) { // If the chart is null, we skip it + continue; + } + customCharts.add(chart); + } + data.put("customCharts", customCharts); + + return data; + } + + /** + * Gets the server specific data. + * + * @return The server specific data. + */ + @SuppressWarnings("unchecked") + private JSONObject getServerData() { + // Minecraft specific data + int playerAmount; + try { + // Around MC 1.8 the return type was changed to a collection from an array, + // This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection; + Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers"); + playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class) + ? ((Collection) onlinePlayersMethod.invoke(Bukkit.getServer())).size() + : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length; + } catch (Exception e) { + playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed + } + int onlineMode = Bukkit.getOnlineMode() ? 1 : 0; + String bukkitVersion = org.bukkit.Bukkit.getVersion(); + bukkitVersion = bukkitVersion.substring(bukkitVersion.indexOf("MC: ") + 4, bukkitVersion.length() - 1); + + // OS/Java specific data + String javaVersion = System.getProperty("java.version"); + String osName = System.getProperty("os.name"); + String osArch = System.getProperty("os.arch"); + String osVersion = System.getProperty("os.version"); + int coreCount = Runtime.getRuntime().availableProcessors(); + + JSONObject data = new JSONObject(); + + data.put("serverUUID", serverUUID); + + data.put("playerAmount", playerAmount); + data.put("onlineMode", onlineMode); + data.put("bukkitVersion", bukkitVersion); + + data.put("javaVersion", javaVersion); + data.put("osName", osName); + data.put("osArch", osArch); + data.put("osVersion", osVersion); + data.put("coreCount", coreCount); + + return data; + } + + /** + * Collects the data and sends it afterwards. + */ + @SuppressWarnings("unchecked") + private void submitData() { + final JSONObject data = getServerData(); + + JSONArray pluginData = new JSONArray(); + // Search for all other bStats Metrics classes to get their plugin data + for (Class service : Bukkit.getServicesManager().getKnownServices()) { + try { + service.getField("B_STATS_VERSION"); // Our identifier :) + + for (RegisteredServiceProvider provider : Bukkit.getServicesManager().getRegistrations(service)) { + try { + pluginData.add(provider.getService().getMethod("getPluginData").invoke(provider.getProvider())); + } catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { + } + } + } catch (NoSuchFieldException ignored) { + } + } + + data.put("plugins", pluginData); + + // Create a new thread for the connection to the bStats server + new Thread(new Runnable() { + @Override + public void run() { + try { + // Send the data + sendData(data); + } catch (Exception e) { + // Something went wrong! :( + if (logFailedRequests) { + plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e); + } + } + } + }).start(); + } + /** * Represents a custom chart. */ @@ -352,7 +353,7 @@ public class Metrics { } @SuppressWarnings("unchecked") - private JSONObject getRequestJsonObject() { + private JSONObject getRequestJsonObject() { JSONObject chart = new JSONObject(); chart.put("chartId", chartId); try { @@ -385,7 +386,7 @@ public class Metrics { /** * Class constructor. * - * @param chartId The id of the chart. + * @param chartId The id of the chart. * @param callable The callable which is used to request the chart data. */ public SimplePie(String chartId, Callable callable) { @@ -394,7 +395,7 @@ public class Metrics { } @SuppressWarnings("unchecked") - @Override + @Override protected JSONObject getChartData() throws Exception { JSONObject data = new JSONObject(); String value = callable.call(); @@ -417,7 +418,7 @@ public class Metrics { /** * Class constructor. * - * @param chartId The id of the chart. + * @param chartId The id of the chart. * @param callable The callable which is used to request the chart data. */ public AdvancedPie(String chartId, Callable> callable) { @@ -426,7 +427,7 @@ public class Metrics { } @SuppressWarnings("unchecked") - @Override + @Override protected JSONObject getChartData() throws Exception { JSONObject data = new JSONObject(); JSONObject values = new JSONObject(); @@ -462,7 +463,7 @@ public class Metrics { /** * Class constructor. * - * @param chartId The id of the chart. + * @param chartId The id of the chart. * @param callable The callable which is used to request the chart data. */ public DrilldownPie(String chartId, Callable>> callable) { @@ -471,7 +472,7 @@ public class Metrics { } @SuppressWarnings("unchecked") - @Override + @Override public JSONObject getChartData() throws Exception { JSONObject data = new JSONObject(); JSONObject values = new JSONObject(); @@ -512,7 +513,7 @@ public class Metrics { /** * Class constructor. * - * @param chartId The id of the chart. + * @param chartId The id of the chart. * @param callable The callable which is used to request the chart data. */ public SingleLineChart(String chartId, Callable callable) { @@ -521,7 +522,7 @@ public class Metrics { } @SuppressWarnings("unchecked") - @Override + @Override protected JSONObject getChartData() throws Exception { JSONObject data = new JSONObject(); int value = callable.call(); @@ -545,7 +546,7 @@ public class Metrics { /** * Class constructor. * - * @param chartId The id of the chart. + * @param chartId The id of the chart. * @param callable The callable which is used to request the chart data. */ public MultiLineChart(String chartId, Callable> callable) { @@ -554,7 +555,7 @@ public class Metrics { } @SuppressWarnings("unchecked") - @Override + @Override protected JSONObject getChartData() throws Exception { JSONObject data = new JSONObject(); JSONObject values = new JSONObject(); @@ -591,7 +592,7 @@ public class Metrics { /** * Class constructor. * - * @param chartId The id of the chart. + * @param chartId The id of the chart. * @param callable The callable which is used to request the chart data. */ public SimpleBarChart(String chartId, Callable> callable) { @@ -600,7 +601,7 @@ public class Metrics { } @SuppressWarnings("unchecked") - @Override + @Override protected JSONObject getChartData() throws Exception { JSONObject data = new JSONObject(); JSONObject values = new JSONObject(); @@ -630,7 +631,7 @@ public class Metrics { /** * Class constructor. * - * @param chartId The id of the chart. + * @param chartId The id of the chart. * @param callable The callable which is used to request the chart data. */ public AdvancedBarChart(String chartId, Callable> callable) { @@ -639,7 +640,7 @@ public class Metrics { } @SuppressWarnings("unchecked") - @Override + @Override protected JSONObject getChartData() throws Exception { JSONObject data = new JSONObject(); JSONObject values = new JSONObject(); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 7023b9a..5506267 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -19,7 +19,7 @@ worldtemplates: default: 'template_default' templates: # The "1" can be any key - 1: + 1: # Name of directory in plugins/WorldSystem/worldsources # e.g. this would be plugins/WorldSystem/worldsources/template_default name: 'template_default' @@ -68,7 +68,7 @@ database: # How the table with the saved player positions on the playerworlds should be named worlds_table_name: worlds_positions # How the table with the saved player positions on the normal worlds should be named - players_table_name : player_positions + players_table_name: player_positions # Configure here your mysql connection mysql_settings: host: 127.0.0.1 diff --git a/src/main/resources/custom.yml b/src/main/resources/custom.yml index a687649..c06d5fe 100644 --- a/src/main/resources/custom.yml +++ b/src/main/resources/custom.yml @@ -13,7 +13,7 @@ world: delete: own: "" other: "%player" - does_not_exists: + does_not_exists: own: "" other: "" setting_up: "" @@ -65,7 +65,7 @@ info: fire: "%data" enabled: "" disabled: "" - + command_help: list: - "" diff --git a/src/main/resources/fi.yml b/src/main/resources/fi.yml index 2e87cc4..7ea79a8 100644 --- a/src/main/resources/fi.yml +++ b/src/main/resources/fi.yml @@ -64,7 +64,7 @@ info: fire: "Tuli: %data" enabled: "&aOn" disabled: "&cOff" - + command_help: list: - "/ws get &8- &7Luo sinulle maailman" diff --git a/src/main/resources/hu.yml b/src/main/resources/hu.yml index 07992fa..043a923 100644 --- a/src/main/resources/hu.yml +++ b/src/main/resources/hu.yml @@ -13,7 +13,7 @@ world: delete: own: "&cA vilgot trlve!" other: "Trlte a vilgot &c%player&6 jtkostl!" - does_not_exists: + does_not_exists: own: "&cNincs vilgod!" other: "&cEz a jtkos nem rendelkezik vilggal!" setting_up: "&aA vilg megteremtse..." @@ -65,7 +65,7 @@ info: fire: "Tz: %data" enabled: "&aBe" disabled: "&cKi" - + command_help: list: - "/ws get &8- &7Will give you a world" diff --git a/src/main/resources/nl.yml b/src/main/resources/nl.yml index 855a7d0..fd25ddd 100644 --- a/src/main/resources/nl.yml +++ b/src/main/resources/nl.yml @@ -13,7 +13,7 @@ world: delete: own: "&cJouw wereld is verwijderd!" other: "Jij hebt de wereld verwijderd van: &c%player&6!" - does_not_exists: + does_not_exists: own: "&cJij hebt nog geen wereld!" other: "&cDeze speler heeft nog geen wereld!" setting_up: "&aWereld word aangemaakt" @@ -64,7 +64,7 @@ info: fire: "Vuur: %data" enabled: "&Aan" disabled: "&cUit" - + command_help: list: - "/ws get &8- &7Will give you a world" diff --git a/src/main/resources/pl.yml b/src/main/resources/pl.yml index 0e1bba5..263b4a1 100644 --- a/src/main/resources/pl.yml +++ b/src/main/resources/pl.yml @@ -13,7 +13,7 @@ world: delete: own: "&cTwój świat został skasowany!" other: "Usunąłeś świat gracza: &c%player&6!" - does_not_exists: + does_not_exists: own: "&cNie masz swojego świata!" other: "&cTen gracz nie ma swojego świata!" setting_up: "&aUstawianie świata..." @@ -64,7 +64,7 @@ info: fire: "Ogień: %data" enabled: "&aWłączone" disabled: "&cWyłączone" - + command_help: list: - "/ws get &8- &7Tworzy Twój świat" diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 90a31e7..46f0ae3 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -60,7 +60,7 @@ permissions: default: op description: You can see lag messages ws.big: - default: op + default: op description: Gives you a bigger world (if set) ws.large: default: op @@ -70,5 +70,5 @@ permissions: ws.confirm: default: op description: You can confirm (if needed) an auto-update - + default-permission: admin \ No newline at end of file diff --git a/src/main/resources/ru.yml b/src/main/resources/ru.yml index 1c39559..923922f 100644 --- a/src/main/resources/ru.yml +++ b/src/main/resources/ru.yml @@ -13,7 +13,7 @@ world: delete: own: "&cТвой мир был удален!" other: "Мир от &c%player&6 был удален!" - does_not_exists: + does_not_exists: own: "&cУ тебя нету мира!" other: "&cУ этого игрока нету мира!" setting_up: "&aПриготовлеваю мир..." @@ -64,7 +64,7 @@ info: fire: "Огонь: %data" enabled: "&aВключен" disabled: "&cОтключен" - + command_help: list: - "/ws get &8- &7Даст тебе мир" diff --git a/src/main/resources/settings.yml b/src/main/resources/settings.yml index e05ad80..f97c842 100644 --- a/src/main/resources/settings.yml +++ b/src/main/resources/settings.yml @@ -1,5 +1,5 @@ # Center will be at the spawn or the worldspawn -worldborder: +worldborder: # If WorldSystem should change the worldborder should_change: true # Default size @@ -10,7 +10,7 @@ worldborder: # For example, with the permission ws.big you will get a worldborder with the size 1000 ws.big: 1000 ws.bigger: 1500 - + # Set a specialized center which is not the spawn center: as_spawn: true diff --git a/src/main/resources/zh.yml b/src/main/resources/zh.yml index 50f76be..30f852e 100644 --- a/src/main/resources/zh.yml +++ b/src/main/resources/zh.yml @@ -13,7 +13,7 @@ world: delete: own: "&c你的世界已删除!" other: "你删除了 &c%player &6的世界" - does_not_exists: + does_not_exists: own: "&c你没有世界!" other: "&c这个玩家没有世界!" setting_up: "&a正在建立世界..." @@ -63,7 +63,7 @@ info: fire: "火: %data" enabled: "&a开启" disabled: "&c关闭" - + command_help: list: - "/ws get &8- &7创建一个世界" diff --git a/target/classes/custom.yml b/target/classes/custom.yml new file mode 100644 index 0000000..c06d5fe --- /dev/null +++ b/target/classes/custom.yml @@ -0,0 +1,84 @@ +nopermission: "" +unknown_error: "" +lagdetection: "%world" +wrong_usage: "" +not_registered: "" + +world: + reseted: "" + still_loaded: "" + not_on: "" + created: "" + already_exists: "" + delete: + own: "" + other: "%player" + does_not_exists: + own: "" + other: "" + setting_up: "" + playerlist: "%players" + still_creating: "" + set_home: "" + not_enough_money: "" + + +member: + removed: "%player" + added: "%player" + already_added: " + not_added: + own: "" + other: "" + no_one_added + +request: + expired: "" + confirm: "%command" + until_expire: "%time" + already_sent: "" + not_sent: "" + invalid_input: "%input" + +toggle: + gamemode: + enabled: "" + disabled: "" + teleport: + enabled: "" + disabled: "" + build: + enabled: "" + disabled: "" + fire: + enabled: "" + disabled: "" + tnt: + enabled: "" + disabled: "" + +info: + owner: "%data" + id: "%data" + member: "%data" + tnt: "%data" + fire: "%data" + enabled: "" + disabled: "" + +command_help: + list: + - "" + - "" + - "" + - "" + - "" + - "" + - "" + - "" + - "" + - "" + - "" + - "" + - "" + delete_command: "" \ No newline at end of file diff --git a/target/classes/fi.yml b/target/classes/fi.yml new file mode 100644 index 0000000..7ea79a8 --- /dev/null +++ b/target/classes/fi.yml @@ -0,0 +1,85 @@ +nopermission: "&cSinulla ei ole lupaa tuohon komentoon!" +unknown_error: "&cJotain meni pieleen..." +lagdetection: "Lagia havaittu maailmassa: &c%world" +wrong_usage: "&c%usage" +not_registered: "&cTämä pelaaja ei ole liittynyt vielä!" + +world: + reseted: "Maailmasi nollautui!" + still_loaded: "&cMailmasi on vieläkin ladattu!" + not_on: "&cEt ole maailmassa!" + created: "Maailmasi on nyt valmis. Pääset sinne komennolla &a/ws home" + already_exists: "&cSinulla on jo maailma!" + delete: + own: "&cMaailmasi poistettiin!" + other: "Poistit pelaajan &c%player&6 maailman&6!" + does_not_exists: + own: "&cSinulla ei ole maailmaa!" + other: "&cKyseisellä pelaajalla ei ole maailmaa!" + setting_up: "&aAlustetaan maailmaa..." + playerlist: "Pelaajat tässä maailmassa: %players" + still_creating: "&cWorld is still creating" + set_home: "You set the home" + not_enough_money: "You do not have enough money" + +member: + removed: "Poistit pelaajan &c%player&6 maailmastasi!" + added: "Lisäsit pelaajan &c%player&6 maailmaasi!" + already_added: "&cKyseinen pelaaja on jo jäsen!" + not_added: + own: "&cKyseinen pelaaja ei ole jäsen!" + other: "&cSinua ei ole lisätty tähän maailmaan" + no_one_added: "&cThere are no members added" + +request: + expired: "&cPyyntösi on vanhentunut!" + confirm: "&cVahvista maailmasi nollaaminen: %command" + until_expire: "&cPyyntösi vanhentuu %time seconds sekunnin kuluttua!" + already_sent: "&cLähetit jo pyynnön!" + not_sent: "&cEt lähettänyt pyyntöä!" + invalid_input: "&cSyöte ei ole kelvollinen!" + +toggle: + gamemode: + enabled: "&a%player&6 voi nyt vaihtaa pelimuotonsa!" + disabled: "&c%player&6 ei voi enää vaihtaa pelimuotoansa!" + teleport: + enabled: "&a%player&6 voi nyt teleportata!" + disabled: "&c%player&6 ei voi enään teleportata!" + build: + enabled: "&a%player&6 voi nyt rakentaa!" + disabled: "&c%player&6 ei voi enään rakentaa!" + fire: + enabled: "&aSinä aktivoit tulen!" + disabled: "&cSinä deaktivoit tulen!" + tnt: + enabled: "&aSinä aktivoit TNT-Damagen!" + disabled: "&cSinä deaktivoit TNT-Damagen!" + +info: + owner: "Omistaja: %data" + id: "ID: %data" + member: "Jäsen: %data" + tnt: "TNT: %data" + fire: "Tuli: %data" + enabled: "&aOn" + disabled: "&cOff" + +command_help: + list: + - "/ws get &8- &7Luo sinulle maailman" + - "/ws home &8- &7Teleporttaa sinut maailmaasi" + - "/ws sethome &8- &7Sets a specific home" + - "/ws gui &8- &7Avaa sinulle valikon jos omistat tämän maailman" + - "/ws tp &8- &7Teleporttaa sinut tiettyyn maailmaan" + - "/ws addmember &8- &7Lisää pelaajan sinun maailmaasi" + - "/ws delmember &8- &7Poistaa pelaajan sinun maailmastasi" + - "/ws leave &8- &7Lähtee maailmasta" + - "/ws tnt &8- &7Sallii/Kieltää TNT sinun maailmastasi" + - "/ws fire &8- &7Sallii/Kieltää Tulen sinun maailmastasi" + - "/ws togglegm &8- &7Sallii/Kieltää pelaajan vaihtamasta pelimuotoansa" + - "/ws togglebuild &8- &7Sallii/Kieltää pelaajan rakentamasta" + - "/ws toggletp &8- &7Sallii/Kieltää pelaajan treleporttaamasta" + - "/ws info &8- &7Näyttää tietoa aktiivisesta maailmasta" + - "/ws reset &8- &7Nollaa sinun maailmasi" + delete_command: "/ws delete &8- &7Poistaa maailman" \ No newline at end of file diff --git a/target/classes/nl.yml b/target/classes/nl.yml new file mode 100644 index 0000000..fd25ddd --- /dev/null +++ b/target/classes/nl.yml @@ -0,0 +1,85 @@ +nopermission: "&cJij hebt geen rechten om dit te doen!" +unknown_error: "&cEr is iets verkeerd gegaan.." +lagdetection: "Lag gededecteerd in wereld: &c%world" +wrong_usage: "&c%gebruik" +not_registered: "&cDeze speler heeft nog nooit gejoined!" + +world: + reseted: "Jouw wereld is gereset!" + still_loaded: "&cJouw wereld is nog steeds geladen!" + not_on: "&cJij bent niet in een wereld!" + created: "Jouw wereld is gemaakt gebruik: &a/ws home" + already_exists: "&cJij hebt al een wereld!" + delete: + own: "&cJouw wereld is verwijderd!" + other: "Jij hebt de wereld verwijderd van: &c%player&6!" + does_not_exists: + own: "&cJij hebt nog geen wereld!" + other: "&cDeze speler heeft nog geen wereld!" + setting_up: "&aWereld word aangemaakt" + playerlist: "speler is in wereld: %players" + still_creating: "&cWorld is still creating" + set_home: "You set the home" + not_enough_money: "You do not have enough money" + +member: + removed: "Jij hebt &c%player&6 verwijderd van jouw wereld!" + added: "Jij hebt &c%player&6 toegevoegd aan jouw wereld!" + already_added: "&cDeze speler is al toegevoegd!" + not_added: + own: "&cDeze speler is nog niet toegevoegd!" + other: "&cJij bent niet aan deze wereld toegevoegd" + no_one_added: "&cThere are no members added" + +request: + expired: "&cJouw uitnodiging is verlopen!" + confirm: "&cBevestig het verwijderen van jouw wereld: %command" + until_expire: "&cJouw uitnodiging verloopt over %time seconden!" + already_sent: "&cJij hebt al een uitnodiging verstuurd!" + not_sent: "&cJij hebt geen uitnodiging gestuurd!" + invalid_input: "&c%input is niet een command!" + +toggle: + gamemode: + enabled: "&a%player&6 kan nu zijn spelermodus veranderen!" + disabled: "&c%player&6 kan niet meer zijn spelermodus veranderen!" + teleport: + enabled: "&a%player&6 kan nu teleporteren!" + disabled: "&c%player&6 kan nu niet meer teleporteren!" + build: + enabled: "&a%player&6 kan nu bouwen!" + disabled: "&c%player&6 kan nu niet meer bouwen!" + fire: + enabled: "&aJij hebt vuur geactiveert!" + disabled: "&cJij hebt vuur gedeactiveerd!" + tnt: + enabled: "&aJij hebt TNT-schade geactiveerd!" + disabled: "&cJij hebt TNT-schade gedeactiveerd!" + +info: + owner: "Owner: %data" + id: "ID: %data" + member: "Toegevoegd: %data" + tnt: "TNT: %data" + fire: "Vuur: %data" + enabled: "&Aan" + disabled: "&cUit" + +command_help: + list: + - "/ws get &8- &7Will give you a world" + - "/ws home &8- &7Teleports you on your world" + - "/ws sethome &8- &7Sets a specific home" + - "/ws gui &8- &7Opens the GUI menu if you are the worldowner" + - "/ws tp &8- &7Teleports you on a specific world" + - "/ws addmember &8- &7Adds a player to your world" + - "/ws delmember &8- &7Removes a player from your world" + - "/ws leave &8- &7Leave a world" + - "/ws tnt &8- &7Allows/Denys TNT on your world" + - "/ws fire &8- &7Allows/Denys Fire on your world" + - "/ws togglegm &8- &7Allows/Denys a player changing gamemode" + - "/ws togglebuild &8- &7Allows/Denys a player building" + - "/ws toggletp &8- &7Allows/Denys a player teleporting" + - "/ws info &8- &7Shows information about the world" + - "/ws reset &8- &7Will reset your world" + delete_command: "/ws delete &8- &7Will delete a world" \ No newline at end of file diff --git a/target/classes/pl.yml b/target/classes/pl.yml new file mode 100644 index 0000000..263b4a1 --- /dev/null +++ b/target/classes/pl.yml @@ -0,0 +1,85 @@ +nopermission: "&cNie posiadasz uprawnień do tego!" +unknown_error: "&cCoś poszło nie tak..." +lagdetection: "Wykryto laga na świecie: &c%world" +wrong_usage: "&c%usage" +not_registered: "&cTen gracz nie dołączył jeszcze na serwer!" + +world: + reseted: "Twój świat został zresetowany!" + still_loaded: "&cTwój serwer wciąż się ładuje!" + not_on: "&cNie jesteś na swoim świecie!" + created: "Twój świat jest gotowy. Dostań się na niego za pomocą &a/ws home" + already_exists: "&cJuż posiadasz swój świat!" + delete: + own: "&cTwój świat został skasowany!" + other: "Usunąłeś świat gracza: &c%player&6!" + does_not_exists: + own: "&cNie masz swojego świata!" + other: "&cTen gracz nie ma swojego świata!" + setting_up: "&aUstawianie świata..." + playerlist: "Gracze na tym świecie: %players" + still_creating: "&cWorld is still creating" + set_home: "You set the home" + not_enough_money: "You do not have enough money" + +member: + removed: "Usunąłeś &c%player&6 ze swojego świata!" + added: "Dodałeś &c%player&6 na swój świat!" + already_added: "&cTen gracz jest już dodany na Twoim świecie!" + not_added: + own: "&cTen gracz nie jest dodany do Twojego świata!" + other: "&cNie jesteś dodany na ten świat!" + no_one_added: "&cThere are no members added" + +request: + expired: "&cTwoja prośba wygasła!" + confirm: "&cPotwierdź zresetowanie swojego świata komendą: %command" + until_expire: "&cTwója prośba wygaśnie za %time sek.!" + already_sent: "&cJuż wysłałeś prośbę!" + not_sent: "&cNie wysłałeś prośby!" + invalid_input: "&c%input nie jest poprawnym argumentem komendy!" + +toggle: + gamemode: + enabled: "&a%player&6 może teraz zmienić swój gamemode!" + disabled: "&c%player&6 nie może już zmienić swojego gamemode!" + teleport: + enabled: "&a%player&6 może teleportować się!" + disabled: "&c%player&6 nie może teleportować się!" + build: + enabled: "&a%player&6 może budować!" + disabled: "&c%player&6 nie może już budować!" + fire: + enabled: "&aWłączyłeś ogień!" + disabled: "&cWyłączyłeś ogień!" + tnt: + enabled: "&aWłączyłeś obrażenia od TNT!" + disabled: "&cWyłączyłeś obrażenia od TNT!" + +info: + owner: "Właściciel: %data" + id: "ID: %data" + member: "Członek: %data" + tnt: "TNT: %data" + fire: "Ogień: %data" + enabled: "&aWłączone" + disabled: "&cWyłączone" + +command_help: + list: + - "/ws get &8- &7Tworzy Twój świat" + - "/ws home &8- &7Teleportuje Cie na Twój świat" + - "/ws sethome &8- &7Sets a specific home" + - "/ws gui &8- &7Otwiera GUI świata jeżeli jesteś jego właścicielem" + - "/ws tp &8- &7Teleportuje Cie na określony świat" + - "/ws addmember &8- &7Dodaj gracza na swój świat" + - "/ws delmember &8- &7Usuń gracza ze swojego świata" + - "/ws leave &8- &7Opuść świat" + - "/ws tnt &8- &7Zezwól/Odmów TNT na swoim świecie" + - "/ws fire &8- &7Zezwól/Odmów Ogień na swoim świecie" + - "/ws togglegm &8- &7Zezwól/Odmów graczowi zmieniać swój gamemode" + - "/ws togglebuild &8- &7Zezwól/Odmów graczowi budowanie" + - "/ws toggletp &8- &7Zezwól/Odmów graczowi teleportowanie się" + - "/ws info &8- &7Pokazuje informacje o świecie" + - "/ws reset &8- &7Zresetuje Twój świat" + delete_command: "/ws delete &8- &7Usunie Twój świat" \ No newline at end of file diff --git a/target/classes/ru.yml b/target/classes/ru.yml new file mode 100644 index 0000000..923922f --- /dev/null +++ b/target/classes/ru.yml @@ -0,0 +1,84 @@ +nopermission: "&cУ тебя нет прав!" +unknown_error: "&cЧего-то не удалось..." +lagdetection: "Лагов в мире: &c%world" +wrong_usage: "&c%usage" +not_registered: "&cЭтот игрок играет первый раз га этом сервере" + +world: + reseted: "Твой мир был возвращен!" + still_loaded: "&cТвой мир ещё загружен!" + not_on: "&cТебя нету в не каком мире!" + created: "Твой мир готов. Используй &a/ws home" + already_exists: "&cТакой мир уже существует!" + delete: + own: "&cТвой мир был удален!" + other: "Мир от &c%player&6 был удален!" + does_not_exists: + own: "&cУ тебя нету мира!" + other: "&cУ этого игрока нету мира!" + setting_up: "&aПриготовлеваю мир..." + playerlist: "Игроков в мире: %players" + still_creating: "&cWorld is still creating" + set_home: "You set the home" + not_enough_money: "You do not have enough money" + +member: + removed: "Ты удалил &c%player&6 из твоего мира!" + added: "Ты добавил &c%player&6 к твоему миру!" + already_added: "&cЭтот игрок уже член твоего мира!" + not_added: + own: "&cЭтот игрок не член твоего мира!" + other: "&cТебя не добавили к этому миру" + no_one_added: "&cThere are no members added" + +request: + expired: "&cТвой запрос вытек!" + confirm: "&Подтверди сброс: %command" + until_expire: "&cТвой запрос вытечет через %time секунды!" + already_sent: "&cТы уже послал запрос!" + not_sent: "&cТы не послал запрос!" + invalid_input: "&c%input не действительный запрос!" + +toggle: + gamemode: + enabled: "&a%player&6 теперь может изменить свой режим игры!" + disabled: "&c%player&6 не может больше изменить свой режим игры!" + teleport: + enabled: "&a%player&6 теперь может телепортироваться!" + disabled: "&c%player&6 не может больше телепортироваться!" + build: + enabled: "&a%player&6 может теперь строить!" + disabled: "&c%player&6 не может больше строить!" + fire: + enabled: "&aОгонь включен!" + disabled: "&cОгонь отключен" + tnt: + enabled: "&aПовреждение через ТНТ включено!" + disabled: "&cПовреждение через ТНТ отключено!" + +info: + owner: "Владелец: %data" + id: "ID: %data" + member: "Члены: %data" + tnt: "ТНТ: %data" + fire: "Огонь: %data" + enabled: "&aВключен" + disabled: "&cОтключен" + +command_help: + list: + - "/ws get &8- &7Даст тебе мир" + - "/ws home &8- &7Телепортирует тебя в твой мир" + - "/ws sethome &8- &7Sets a specific home" + - "/ws gui &8- &7Открывает ГИП если ты владелец этого мира" + - "/ws tp &8- &7Телепортирует тебя в определенный мир" + - "/ws addmember &8- &7Добавляет кого-то к твоему миру" + - "/ws delmember&8 - &7Удаляет кого-то из твоего мира" + - "/ws tnt &8- &7Разрешает/Запрещает TНT на твоем мире" + - "/ws fire &8- &7Разрешает/Запрещает огонь в твоем мире" + - "/ws togglegm &8- &7Разрешает/Запрещает игроку менять режим игры" + - "/ws togglebuild &8- &7Разрешает/Запрещает игроку строить" + - "/ws toggletp &8- &7Разрешает/Запрещает игроку телепортироваться" + - "/ws info &8- &7Показывает информацию про мир" + - "/ws reset &8- &7Сбрасывает твой мир" + delete_command: "/ws delete &8- &7Удалает твой мир" \ No newline at end of file diff --git a/target/classes/settings.yml b/target/classes/settings.yml new file mode 100644 index 0000000..f97c842 --- /dev/null +++ b/target/classes/settings.yml @@ -0,0 +1,62 @@ +# Center will be at the spawn or the worldspawn +worldborder: + # If WorldSystem should change the worldborder + should_change: true + # Default size + normal: 500 + # Here you can define your own ranks, as many as you want + # The permission node will be the key and the value the size + ranks: + # For example, with the permission ws.big you will get a worldborder with the size 1000 + ws.big: 1000 + ws.bigger: 1500 + + # Set a specialized center which is not the spawn + center: + as_spawn: true + # Should the worldborder move with the home set by the owner + as_home: false + x: 0 + y: 20 + z: 0 + +difficulty: EASY + + +# Commands that should be executed on /ws get when it is ready +# Placeholders: %player: Name of player, %world: Name of world, %uuid: UUID of player +commands_on_get: +#- tell %player You have got a world +#- tell %player You are now on %world + + +# All Gamerules in 1.12 +# Not supported gamerules will be ignored +# +# If you need help, look at +# https://minecraft.gamepedia.com/Commands/gamerule + +announceAdvancements: true +commandBlockOutput: false +disableElytraMovementCheck: false +doDaylightCycle: true +doEntityDrops: true +doFireTick: true +doLimitedCrafting: false +doMobLoot: true +doMobSpawning: true +doTileDrops: true +doWeatherCycle: false +gameLoopFunction: false +keepInventory: true +logAdminCommands: true +maxCommandChainLength: 65536 +maxEntityCramming: 24 +mobGriefing: true +naturalRegeneration: true +randomTickSpeed: 3 +reducedDebugInfo: false +sendCommandFeedback: true +showDeathMessages: true +spawnRadius: 10 +spectatorsGenerateChunks: true \ No newline at end of file diff --git a/target/classes/zh.yml b/target/classes/zh.yml new file mode 100644 index 0000000..30f852e --- /dev/null +++ b/target/classes/zh.yml @@ -0,0 +1,84 @@ +nopermission: "&c你没有权限!" +unknown_error: "&c出错..." +lagdetection: "滞后: &c%world" +wrong_usage: "&c%usage" +not_registered: "&c该玩家未在线!" + +world: + reseted: "你的世界已重置!" + still_loaded: "&c你的世界正在加载!" + not_on: "&c你未在世界里!" + created: "你的世界已准备就绪,输入 &a/ws home &6前往" + already_exists: "&c你已拥有一个世界!" + delete: + own: "&c你的世界已删除!" + other: "你删除了 &c%player &6的世界" + does_not_exists: + own: "&c你没有世界!" + other: "&c这个玩家没有世界!" + setting_up: "&a正在建立世界..." + playerlist: "玩家: %players 在这个世界上" + still_creating: "&cWorld is still creating" + set_home: "You set the home" + not_enough_money: "You do not have enough money" + +member: + removed: "玩家 &c%player&6 从你的世界移除!" + added: "你添加 &c%player&6 到你的世界!" + already_added: "&c这个玩家已经在你的世界里了!" + not_added: + own: "&c该玩家未在你的世界里!" + other: "&c你未加入这个世界" + +request: + expired: "&c确认超时!" + confirm: "&c请确认,重置你的世界: %command" + until_expire: "&c请在 %time 秒,内确认!" + already_sent: "&c你已发送请求!" + not_sent: "&c你未发送请求!" + invalid_input: "&c%input 错误!" + +toggle: + gamemode: + enabled: "&a%player&6 可以改变游戏模式!" + disabled: "&c%player&6 不能游戏模式!" + teleport: + enabled: "&a%player&6 可以传送!" + disabled: "&c%player&6 不能传送!" + build: + enabled: "&a%player&6 可以建筑!" + disabled: "&c%player&6 不能建筑!" + fire: + enabled: "&a你开启了 火!" + disabled: "&c你禁用了 火!" + tnt: + enabled: "&a你开启了 TNT-爆炸!" + disabled: "&c你禁用了 TNT-爆炸!" + +info: + owner: "管理者: %data" + id: "ID: %data" + member: "成员: %data" + tnt: "TNT: %data" + fire: "火: %data" + enabled: "&a开启" + disabled: "&c关闭" + +command_help: + list: + - "/ws get &8- &7创建一个世界" + - "/ws home &8- &7返回你的世界" + - "/ws sethome &8- &7Sets a specific home" + - "/ws gui &8- &7如果你是世界管理者,使用该指令打开菜单" + - "/ws tp &8- &7传送到指定世界" + - "/ws addmember &8- &7添加一个玩家到你的世界" + - "/ws delmember &8- &7将一个玩家从你的世界删除" + - "/ws leave &8- &7离开一个世界" + - "/ws tnt &8- &7开启/禁用 TNT爆炸" + - "/ws fire &8- &7开启/禁用,火" + - "/ws togglegm &8- &7开启/禁用,玩家切换模式" + - "/ws togglebuild &8- &7开启/禁用,玩家建筑" + - "/ws toggletp &8- &7开启/禁用,玩家传送" + - "/ws info &8- &7查看世界信息" + - "/ws reset &8- &7重置你的世界" + delete_command: "/ws delete &8- &7删除一个世界" \ No newline at end of file diff --git a/target/surefire-reports/TEST-de.butzlabben.world.wrapper.GeneratorSettingsTest.xml b/target/surefire-reports/TEST-de.butzlabben.world.wrapper.GeneratorSettingsTest.xml new file mode 100644 index 0000000..e5101e3 --- /dev/null +++ b/target/surefire-reports/TEST-de.butzlabben.world.wrapper.GeneratorSettingsTest.xml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file