diff --git a/.DS_Store b/.DS_Store index 00e5db2..ff793b9 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/TestFiles/TestConfig.yml b/TestFiles/TestConfig.yml index e69de29..d7608d7 100644 --- a/TestFiles/TestConfig.yml +++ b/TestFiles/TestConfig.yml @@ -0,0 +1,123 @@ +########################################################################## +### __ __ __ _______ __ ### +### \ \ / / / / / / ___/ / / ### +### \ \ __ / /___ ___/ /___/ / /____ ______/ /______________ ### +### \ \ / \ / / __ \/ _/ / __ /__ / / / / __/ __/ ___/ _ _ / ### +### \ \/ /\ \/ / /_/ / // / /_/ /__/ / /_/ /_ / /_/ ___/ // // / ### +### \__/ \__/\____/_//_/\__,_/____/\__, /___/\__/\___/_//_//_/ ### +### ___/ / ### +### \___/ ### +########################################################################## + + +#################### +# General Settings # +#################### + +# The Language to plugin should run in +language: "en" +#The Path that the Worlds of players will be stored when not in use. +playerWorldsDir: 'plugins/WorldSystem/Worlds' + +#The time that a world should take till it unloads from no use +unloadTime: 20 + +#Prefix on Messages sent by the plugin +prefix: '&8[&3WorldSystem&8] &6' + +#Delete the world after set amount of days +#-1 to disable +deleteAfterDays: -1 + +#World Difficulty + #Options: PEACEFUL, EASY, NORMAL, HARD +worldDifficulty: 'EASY' + +########################## +# World Creation Setting # +########################## + +#Allow Players to Choose the Template they want +multiChoose: false +#The Default Generation File +#Warning: "do not add the .json" +defaultGenerator: 'Vanilla' +#World Generation Folder +worldGenTemplates: 'plugins/WorldSystem/Generators' + +#World Borders + #The Default World Border Size for everyone +worldBorderDefaultSize: 500 +#!Note: Dynamic World Borders Will Added back in a Future Update + +#World Border Center +worldBorderCenter: + x: 0 + z: 0 + +########################## +# World Entering/Exiting # +########################## + +#This is the Settings you need to adjust to your server +serverSpawn: + #The Gamemode the Main server uses + #Options: Survival, Creative, Adventure + #Warning: Spectator is not a Valid Input + #Warning: Spelling Matters, Capitalization Does not + serverGamemode: 'Survival' + #The point the player should be placed when leaving a WS World + serverSpawnPoint: + worldName: 'world' + x: 0 + y: 60 + z: 0 + +#This is the Settings you need to adjust to your server +wsWorldSpawn: + #The Gamemode the Main server uses + #World Gamemode + #Options: Survival, Creative, Adventure + #Warning: Spectator is not a Valid Input + #Warning: Spelling Matters, Capitalization Does not + worldGameMode: 'Survival' + # places the player at their last known location in the world + useLastLocation: false + #The point the player should be placed when entering a WS World + #for the first Time + defaultWorldSpawnPoint: + worldName: 'world' + x: 0 + y: 60 + z: 0 + +################### +# World Gamerules # +################### + +#!DevTODO create a class to handle this to make it cleaner +#Also Document this part of the config +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/src/main/java/de/butzlabben/WorldSystem.java b/src/main/java/de/butzlabben/WorldSystem.java deleted file mode 100644 index 3b0458a..0000000 --- a/src/main/java/de/butzlabben/WorldSystem.java +++ /dev/null @@ -1,219 +0,0 @@ -package de.butzlabben; - -import de.butzlabben.world.GCRunnable; -import de.butzlabben.world.WorldCheckerRunnable; -import de.butzlabben.world.command.CommandRegistry; -import de.butzlabben.world.config.*; -import de.butzlabben.world.listener.*; -import de.butzlabben.world.util.PapiExtension; -import de.butzlabben.world.util.PlayerPositions; -import de.butzlabben.world.util.VersionUtil; -import de.butzlabben.world.util.database.DatabaseProvider; -import de.butzlabben.world.wrapper.CreatorAdapter; -import de.butzlabben.world.wrapper.SystemWorld; -import org.bstats.bukkit.Metrics; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.java.JavaPlugin; - -import java.io.File; -import java.io.IOException; - -/** - * @author Butzlabben - * @author Jubeki - * @version 2.2.0.1 - * @since 10.07.2017 - */ -public class WorldSystem extends JavaPlugin { - private static boolean is1_13Plus = false; - final private String version = this.getDescription().getVersion(); - private static File configFile; - private CreatorAdapter creator; - - public static void createConfigs() { - File folder = getInstance().getDataFolder(); - File dir = new File(folder + "/worldsources"); - configFile = new File(folder, "config.yml"); - File dconfig = new File(folder, "dependence.yml"); - File languages = new File(folder + "/languages"); - File gui = new File(folder, "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")); - MessageConfig.checkConfig(new File(languages, "ja.yml")); - // Here we are for #5 - MessageConfig.checkConfig(new File(languages, "zh.yml")); - MessageConfig.checkConfig(new File(languages, "fr.yml")); - - // If has custom language - 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); - } - - @Override - public void onEnable() { - ////// - getCommand("ws").setExecutor(new CommandRegistry()); - - // Set right version - if (VersionUtil.getVersion() >= 13) - is1_13Plus = true; - - createConfigs(); - - // Establish database connection - DatabaseProvider.instance.util.connect(); - - // Fix for #34 - // Check if tables exist and create them if necessary. - PlayerPositions.instance.checkTables(); - - PluginManager pm = Bukkit.getPluginManager(); - pm.registerEvents(new PlayerListener(), this); - pm.registerEvents(new BlockListener(), this); - pm.registerEvents(new CommandListener(), this); - pm.registerEvents(new WorldInitSkipSpawn(), this); - if (pm.getPlugin("WorldEdit") != null) - pm.registerEvents(new WorldEditListener(), this); - - - Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new WorldCheckerRunnable(), 20 * 5, - 20 * PluginConfig.getLagCheckPeriod()); - - if (PluginConfig.useGC()) { - Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new GCRunnable(), 20 * 5, - 20 * PluginConfig.getGCPeriod()); - } - - - /* TODO better check this only on worldInitEvent - Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> { - for (World w : Bukkit.getWorlds()) { - SystemWorld sw = SystemWorld.getSystemWorld(w.getName()); - if (sw != null && sw.isLoaded()) - SettingsConfig.editWorld(w); - - } - }, 20, 20 * 10);*/ - - Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> { - for (World w : Bukkit.getWorlds()) { - SystemWorld.tryUnloadLater(w); - } - }, 20 * 60 * 2, 20 * 60 * 2); - - //COMMANDS - System.out.println("Registered"); - - //this.getCommand("ws").setExecutor(new WSCommandMain()); - //this.getCommand("ws").setExecutor(new CommandMain()); - //this.getCommand("ws get").setExecutor(new WSGet()); - //this.getCommand("ws reset").setExecutor(new WorldReset()); - //this.getCommand("ws home").setExecutor(new WorldHome()); - //this.getCommand("ws tnt").setExecutor(new WorldTnt()); - //this.getCommand("ws fire").setExecutor(new WorldFire()); - - - System.setProperty("bstats.relocatecheck", "false"); - Metrics m = new Metrics(this); - m.addCustomChart(new Metrics.SingleLineChart("worlds", DependenceConfig::getHighestID)); - - //AutoUpdater.startAsync(); - - // Choose right creatoradapter for #16 - /*if (Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null - && Bukkit.getPluginManager().getPlugin("WorldEdit") != null - && PluginConfig.loadWorldsASync() - && !is1_13Plus) { - - creator = new AsyncCreatorAdapter(); - Bukkit.getConsoleSender() - .sendMessage(PluginConfig.getPrefix() + "Found FAWE! Worlds now will be created asynchronously"); - } else {*/ - creator = (c, sw, r) -> { - Bukkit.getWorlds().add(c.createWorld()); - if (sw != null) - sw.setCreating(false); - r.run(); - }; - //} - - // Starting for #28 - if (PluginConfig.shouldDelete()) { - Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() - + "Searching for old worlds to delete if not loaded for " + PluginConfig.deleteAfter() + " days"); - DependenceConfig.checkWorlds(); - } - - if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) - new PapiExtension().register(); - - Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "Successfully enabled WorldSystem v" + version); - } - - @Override - public void onDisable() { - for (World w : Bukkit.getWorlds()) { - SystemWorld sw = SystemWorld.getSystemWorld(w.getName()); - if (sw != null && sw.isLoaded()) { - sw.directUnload(w); - } - } - - // Close database connection - DatabaseProvider.instance.util.close(); - - Bukkit.getConsoleSender() - .sendMessage(PluginConfig.getPrefix() + "Successfully disabled WorldSystem v" + version); - } - - public CreatorAdapter getAdapter() { - return creator; - } - - public static File getConfigFile() { return configFile; } - -} diff --git a/src/main/java/de/butzlabben/inventory/CostumInv.java b/src/main/java/de/butzlabben/inventory/CostumInv.java deleted file mode 100644 index a5472f8..0000000 --- a/src/main/java/de/butzlabben/inventory/CostumInv.java +++ /dev/null @@ -1,16 +0,0 @@ -package de.butzlabben.inventory; - -/** - * @author Butzlabben - * @since 28.06.2018 - */ -public class CostumInv extends OrcInventory { - - public CostumInv(String title, int rows) { - super(title, rows); - } - - public CostumInv(String title, int rows, boolean fill) { - super(title, rows, fill); - } -} diff --git a/src/main/java/de/butzlabben/inventory/DependListener.java b/src/main/java/de/butzlabben/inventory/DependListener.java deleted file mode 100644 index e8946db..0000000 --- a/src/main/java/de/butzlabben/inventory/DependListener.java +++ /dev/null @@ -1,11 +0,0 @@ -package de.butzlabben.inventory; - -import de.butzlabben.world.wrapper.WorldPlayer; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -public interface DependListener { - - 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 deleted file mode 100644 index 1da2d87..0000000 --- a/src/main/java/de/butzlabben/inventory/OrcClickListener.java +++ /dev/null @@ -1,9 +0,0 @@ -package de.butzlabben.inventory; - -import org.bukkit.entity.Player; - -public interface OrcClickListener { - - 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 deleted file mode 100644 index f551fe7..0000000 --- a/src/main/java/de/butzlabben/inventory/OrcInventory.java +++ /dev/null @@ -1,110 +0,0 @@ -package de.butzlabben.inventory; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryType; -import org.bukkit.inventory.Inventory; - -import java.util.HashMap; -import java.util.Map.Entry; -import java.util.Objects; - -public abstract class OrcInventory { - - 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, 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, InventoryType type) { - this(title); - if (type == null || type == InventoryType.CHEST) { - this.type = null; - rows = 3; - } else { - this.type = type; - } - } - - public void addItem(int slot, OrcItem item) { - if (item == null) { - removeItem(slot); - } else { - items.put(slot, item); - } - } - - public void addItem(int row, int col, OrcItem item) { - addItem(row * 9 + col, item); - } - - public void removeItem(int slot) { - items.remove(slot); - } - - public void removeItem(int row, int col) { - removeItem(row * 9 + col); - } - - public Inventory getInventory(Player p) { - return getInventory(p, title); - } - - public void redraw(Player p) { - p.closeInventory(); - p.openInventory(getInventory(p)); - } - - public Inventory getInventory(Player p, String title) { - 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(); - } - - 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!"); - } - } - - 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 deleted file mode 100644 index 6459d7a..0000000 --- a/src/main/java/de/butzlabben/inventory/OrcItem.java +++ /dev/null @@ -1,142 +0,0 @@ -package de.butzlabben.inventory; - -import de.butzlabben.world.wrapper.WorldPlayer; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; - -public class OrcItem { - - 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; - - public OrcItem(Material mat, String display, String... lore) { - setItemStack(mat, display, lore); - } - - public OrcItem(ItemStack is) { - setItemStack(is); - } - - public OrcItem(Material mat, String display, List lore) { - setItemStack(mat, (byte) 0, display, lore); - } - - public OrcItem(Material mat) { - this(new ItemStack(mat)); - } - - public OrcItem(Material material, byte data, String display, ArrayList lore) { - setItemStack(material, data, display, lore); - } - - public void setCallback(Runnable r) { - callback = r; - } - - @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, 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 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 setOnClick(OrcClickListener listener) { - this.listener = listener; - 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 setDisplay(String display) { - ItemMeta meta = is.getItemMeta(); - meta.setDisplayName(display); - 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 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 setDepend(DependListener listener) { - depend = listener; - return this; - } - - 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 deleted file mode 100644 index d21a3ef..0000000 --- a/src/main/java/de/butzlabben/inventory/OrcListener.java +++ /dev/null @@ -1,54 +0,0 @@ -package de.butzlabben.inventory; - -import de.butzlabben.WorldSystem; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.InventoryCloseEvent; - -import java.util.HashMap; -import java.util.UUID; - -/** - * @author Butzlabben - * @since 10.06.2018 - */ -public class OrcListener implements Listener { - - private static OrcListener instance; - - private final HashMap invs = new HashMap<>(); - - 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 deleted file mode 100644 index 26fcdf8..0000000 --- a/src/main/java/de/butzlabben/inventory/pages/InventoryPage.java +++ /dev/null @@ -1,59 +0,0 @@ -package de.butzlabben.inventory.pages; - -import de.butzlabben.inventory.OrcInventory; -import de.butzlabben.inventory.OrcItem; -import de.butzlabben.world.config.GuiConfig; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; - -/** - * @author Butzlabben - * @since 20.05.2018 - */ -public class InventoryPage extends OrcInventory { - - InventoryPage next, before = null; - private int i = 0; - - public InventoryPage(String title, int page, int pages) { - super(title, 6); - - YamlConfiguration cfg = GuiConfig.getConfig(); - String path = "options.players.currentpage"; - - OrcItem oi = new OrcItem(GuiConfig.getMaterial(cfg, path), GuiConfig.getData(cfg, path), - GuiConfig.getDisplay(cfg, path).replaceAll("%page", "" + page), GuiConfig.getLore(cfg, path)); - addItem(GuiConfig.getSlot(path), oi); - - path = "options.players.pagebefore"; - oi = GuiConfig.getItem(path); - oi.setOnClick((p, inv, item) -> { - p.closeInventory(); - p.openInventory(this.before.getInventory(p)); - }); - addItem(GuiConfig.getSlot(path), oi); - - path = "options.players.nextpage"; - oi = GuiConfig.getItem(path); - oi.setOnClick((p, inv, item) -> { - p.closeInventory(); - p.openInventory(this.next.getInventory(p)); - }); - addItem(GuiConfig.getSlot(path), oi); - } - - @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++; - } -} diff --git a/src/main/java/de/butzlabben/inventory/pages/ItemConverter.java b/src/main/java/de/butzlabben/inventory/pages/ItemConverter.java deleted file mode 100644 index b5c3875..0000000 --- a/src/main/java/de/butzlabben/inventory/pages/ItemConverter.java +++ /dev/null @@ -1,13 +0,0 @@ -package de.butzlabben.inventory.pages; - -import de.butzlabben.inventory.OrcItem; - -/** - * @author Butzlabben - * @since 21.05.2018 - */ -public interface ItemConverter { - - 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 deleted file mode 100644 index 22a1cb8..0000000 --- a/src/main/java/de/butzlabben/inventory/pages/PageGUICreator.java +++ /dev/null @@ -1,64 +0,0 @@ -package de.butzlabben.inventory.pages; - -import de.butzlabben.inventory.OrcItem; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; - -/** - * @author Butzlabben - * @since 21.05.2018 - */ -public class PageGUICreator { - - private final int elementsPerPage; - private List invpages; - - public PageGUICreator() { - this(4 * 9); - } - - public PageGUICreator(int elementsPerPage) { - this.elementsPerPage = elementsPerPage; - } - - public void create(String title, Collection elements, ItemConverter converter) { - List items = elements.stream().map(r -> converter.convert(r)).collect(Collectors.toList()); - if (items == null || items.size() == 0) - return; - - int pages = (int) (Math.ceil((items.size() / (double) elementsPerPage) < 1 ? 1 : Math.ceil((double) items.size() / (double) elementsPerPage))); - - invpages = new ArrayList<>(pages); - - for (int i = 1; i < pages + 1; i++) { - int start = i == 1 ? 0 : elementsPerPage * (i - 1); - int end = items.size() < elementsPerPage * i ? items.size() : elementsPerPage * i; - List page = items.subList(start, end); - - InventoryPage invpage = new InventoryPage(title, i, pages); - page.forEach(invpage::addItem); - invpages.add(invpage); - } - - for (int i = 0; i < invpages.size(); i++) { - - int beforeIndex = i == 0 ? invpages.size() - 1 : i - 1; - int nextIndex = i == invpages.size() - 1 ? 0 : i + 1; - - invpages.get(i).before = invpages.get(beforeIndex); - invpages.get(i).next = invpages.get(nextIndex); - } - } - - public void show(Player p) { - p.openInventory(invpages.get(0).getInventory(p)); - } - - public List getInvPages() { - return invpages; - } -} diff --git a/src/main/java/de/butzlabben/world/GCRunnable.java b/src/main/java/de/butzlabben/world/GCRunnable.java deleted file mode 100644 index 68d5697..0000000 --- a/src/main/java/de/butzlabben/world/GCRunnable.java +++ /dev/null @@ -1,9 +0,0 @@ -package de.butzlabben.world; - -public class GCRunnable implements Runnable { - - @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 deleted file mode 100644 index c1a9bcd..0000000 --- a/src/main/java/de/butzlabben/world/GameProfileBuilder.java +++ /dev/null @@ -1,133 +0,0 @@ -package de.butzlabben.world; - -import com.google.gson.*; -import com.mojang.authlib.GameProfile; -import com.mojang.authlib.properties.Property; -import com.mojang.authlib.properties.PropertyMap; -import com.mojang.util.UUIDTypeAdapter; -import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.lang.reflect.Type; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.*; - -/** - * @author Butzlabben - * @since 26.02.2018 - */ -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 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, 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(); - - 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 skin) { - return getProfile(uuid, name, skin, null); - } - - public static GameProfile getProfile(UUID uuid, String name, String skinUrl, String capeUrl) { - GameProfile profile = new GameProfile(uuid, name); - boolean cape = (capeUrl != null) && (!capeUrl.isEmpty()); - - 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 void setCacheTime(long time) { - cacheTime = time; - } - - private static class GameProfileSerializer implements JsonSerializer, JsonDeserializer { - - 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; - } - - 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; - } - } - - private static class CachedProfile { - private final GameProfile profile; - - 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 deleted file mode 100644 index 78a1054..0000000 --- a/src/main/java/de/butzlabben/world/WorldCheckerRunnable.java +++ /dev/null @@ -1,48 +0,0 @@ -package de.butzlabben.world; - -import de.butzlabben.world.config.MessageConfig; -import de.butzlabben.world.config.PluginConfig; -import de.butzlabben.world.wrapper.SystemWorld; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.World; -import org.bukkit.entity.Entity; -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())); - - } - } - } - } -} diff --git a/src/main/java/de/butzlabben/world/WorldSystem.java b/src/main/java/de/butzlabben/world/WorldSystem.java new file mode 100644 index 0000000..a2e0075 --- /dev/null +++ b/src/main/java/de/butzlabben/world/WorldSystem.java @@ -0,0 +1,5 @@ +package de.butzlabben.world; + +public class WorldSystem +{ +} diff --git a/src/main/java/de/butzlabben/world/command/CommandRegistry.java b/src/main/java/de/butzlabben/world/command/CommandRegistry.java deleted file mode 100644 index 22ea74f..0000000 --- a/src/main/java/de/butzlabben/world/command/CommandRegistry.java +++ /dev/null @@ -1,98 +0,0 @@ -package de.butzlabben.world.command; - -import de.butzlabben.world.command.commands.WSCommands; -import de.butzlabben.world.command.commands.WorldAdministrateCommand; -import de.butzlabben.world.command.commands.WorldSettingsCommands; -import de.butzlabben.world.util.Worldutils; -import de.butzlabben.world.wrapper.WorldTemplateProvider; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; - - -public class CommandRegistry implements CommandExecutor { - - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - - if (args.length == 0) { - WSCommands ws = new WSCommands(); - return ws.mainCommand(sender, command, label, args); - } else { - WSCommands ws = new WSCommands(); - WorldAdministrateCommand admin = new WorldAdministrateCommand(); - WorldSettingsCommands settings = new WorldSettingsCommands(); - switch (args[0]) { - //WSCommands - case "get": - return ws.getCommand(sender, command, label, args); - case "gui": - return ws.guiCommand(sender, command, label, args); - case "home": - return ws.homeCommand(sender, command, label, args); - case "info": - return ws.infoComannd(sender, command, label, args); - case "leave": - return ws.leaveCommand(sender, command, label, args); - case "tp": - return ws.tpCommand(sender, command, label, args); - //Admin Command - case "day": - return admin.setTime(sender,0); - case "night": - return admin.setTime(sender,14000); - case "time": - return admin.setTime(sender, args[1]); - case "rain": - case "storm": - return admin.setStorm(sender,true); - case "sun": - return admin.setStorm(sender, false); - case "delmember": - return admin.delMemberCommand(sender, command, label, args); - case "delete": - if (sender.hasPermission("ws.delete")) { - return admin.deleteCommand(sender, command, label, args); - } else { - return false; - } - case "addmember": - return admin.addMemberCommand(sender, command, label, args); - case "toggletp": - return admin.toggleTeleportCommand(sender, command, label, args); - case "togglegm": - return admin.toggleGamemodeCommand(sender, command, label, args); - case "togglewe": - return admin.toggleWorldeditCommand(sender, command, label, args); - case "togglebuild": - return admin.toggleBuildCommand(sender, command, label, args); - //World Settings Command - case "reset": - return settings.resetCommand(sender, command, label, args); - case "sethome": - sender.sendMessage("Disabled For Major Error and Rework"); - return false; - /* - if (sender.hasPermission("ws.sethome")) { - return settings.setHomeCommand(sender, command, label, args); - } else { - return false; - }*/ - case "tnt": - return settings.tntCommand(sender, command, label, args); - case "fire": - return settings.fireCommand(sender, command, label, args); - case "reload": - if(!sender.isOp()){ - sender.sendMessage("Reloading Settings!"); - WorldTemplateProvider.getInstance().reload(); - Worldutils.reloadWorldSettings(); - return true; - } - default: - //default command is better than the other one - return ws.mainCommand(sender, command, label, args); - } - } - } -} diff --git a/src/main/java/de/butzlabben/world/command/commands/WSCommands.java b/src/main/java/de/butzlabben/world/command/commands/WSCommands.java deleted file mode 100644 index ef5f39f..0000000 --- a/src/main/java/de/butzlabben/world/command/commands/WSCommands.java +++ /dev/null @@ -1,277 +0,0 @@ -package de.butzlabben.world.command.commands; - -import de.butzlabben.WorldSystem; -import de.butzlabben.world.config.DependenceConfig; -import de.butzlabben.world.config.MessageConfig; -import de.butzlabben.world.config.PluginConfig; -import de.butzlabben.world.config.WorldConfig; -import de.butzlabben.world.gui.WorldChooseGUI; -import de.butzlabben.world.gui.WorldSystemGUI; -import de.butzlabben.world.util.MoneyUtil; -import de.butzlabben.world.wrapper.SystemWorld; -import de.butzlabben.world.wrapper.WorldPlayer; -import de.butzlabben.world.wrapper.WorldTemplate; -import de.butzlabben.world.wrapper.WorldTemplateProvider; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import java.util.Iterator; -import java.util.List; - -public class WSCommands { - public boolean mainCommand(CommandSender sender, Command command, String label, String[] args) { - CommandSender cs = sender; - - String prefix = PluginConfig.getPrefix(); - cs.sendMessage( - prefix + "WorldSystem by Butzlabben v" + WorldSystem.getInstance().getDescription().getVersion()); - cs.sendMessage(prefix + "Contributors: Jubeki, montlikadani, jstoeckm2"); - List cmdHelp = MessageConfig.getCommandHelp(); - cmdHelp.forEach(s -> cs.sendMessage(prefix + s)); - if (cs.hasPermission("ws.delete")) { - cs.sendMessage(MessageConfig.getDeleteCommandHelp()); - } - return true; - } - - public boolean guiCommand(CommandSender sender, Command command, String label, String[] args) { - if (sender instanceof Player) { - Player p = (Player) sender; - WorldPlayer wp = new WorldPlayer(p); - if (!wp.isOnSystemWorld()) { - p.sendMessage(MessageConfig.getNotOnWorld()); - return false; - } - if (!wp.isOwnerofWorld()) { - p.sendMessage(MessageConfig.getNoPermission()); - return false; - } - p.openInventory(new WorldSystemGUI().getInventory(p)); - return true; - } else { - sender.sendMessage("No Console"); //TODO Get Config - return false; - } - } - - - public boolean getCommand(CommandSender sender, Command command, String label, String[] args) { - if (sender instanceof Player) { - Player p = (Player)sender; - - // Check if use can create a world - if (!p.hasPermission("ws.get")) { - p.sendMessage(MessageConfig.getNoPermission()); - return false; - } - - // create New Entry - DependenceConfig dc = new DependenceConfig(p); - if (dc.hasWorld()) { - p.sendMessage(MessageConfig.getWorldAlreadyExists()); - return false; - } - - - if (PluginConfig.isMultiChoose()) { - if (args.length > 1) { - String key = args[1]; - WorldTemplate template = WorldTemplateProvider.getInstance().getTemplate(key); - if (template != null) { - // Permission for this specific template - if (template.getPermission() != null && !p.hasPermission(template.getPermission())) { - p.sendMessage(MessageConfig.getNoPermission()); - return false; - } - - // Implementation check for #15 - if (template.getCost() > 0) { - if (!MoneyUtil.hasMoney(p.getUniqueId(), template.getCost())) { - p.sendMessage(MessageConfig.getNotEnoughMoney()); - return false; - } - MoneyUtil.removeMoney(p.getUniqueId(), template.getCost()); - } - - this.create(p, template); - return false; - } - } - WorldChooseGUI.letChoose(p); - } else { - WorldTemplate template = WorldTemplateProvider.getInstance() - .getTemplate(PluginConfig.getDefaultWorldTemplate()); - if (template != null) - this.create(p, template); - else { - p.sendMessage(PluginConfig.getPrefix() + "§cError in config at \"worldtemplates.default\""); - p.sendMessage(PluginConfig.getPrefix() + "§cPlease contact an administrator"); - } - } - return true; - } else { - sender.sendMessage("No Console"); //TODO Add Config - return false; - } - - } - public boolean homeCommand(CommandSender sender, Command command, String label, String[] args) { - - if (sender instanceof Player) { - Player p = (Player) sender; - - String worldname = p.getWorld().getName(); - DependenceConfig dc = new DependenceConfig(p); - if (!dc.hasWorld()) { - p.sendMessage(MessageConfig.getNoWorldOwn()); - return false; - } - WorldPlayer wp = new WorldPlayer(p, worldname); - if (wp.isOnSystemWorld()) { - SystemWorld.tryUnloadLater(Bukkit.getWorld(worldname)); - } - SystemWorld sw = SystemWorld.getSystemWorld(dc.getWorldname()); - if (sw == null) { - p.sendMessage(MessageConfig.getNoWorldOwn()); - return false; - } - if (sw.isLoaded()) { - sw.teleportToWorldSpawn(p); - } else { - sw.load(p); - } - return true; - } else { - sender.sendMessage("No Console"); //TODO Add Config - return false; - } - } - - public boolean infoComannd(CommandSender sender, Command command, String label, String[] args) { - if (sender instanceof Player) { - Player p = (Player) sender; - WorldPlayer wp = new WorldPlayer(p, p.getWorld().getName()); - if (!wp.isOnSystemWorld()) { - p.sendMessage(MessageConfig.getNotOnWorld()); - return false; - } - - WorldConfig wc = WorldConfig.getWorldConfig(p.getWorld().getName()); - int id = wc.getId(); - String owner = wc.getOwnerName(); - boolean fire = wc.isFire(); - boolean tnt = wc.isTnt(); - - p.sendMessage(MessageConfig.getInfoOwner().replaceAll("%data", owner)); - p.sendMessage(MessageConfig.getInfoId().replaceAll("%data", "" + id)); - p.sendMessage(MessageConfig.getInfoTnt().replaceAll("%data", - tnt ? MessageConfig.getInfoEnabled() : MessageConfig.getInfoDisabled())); - p.sendMessage(MessageConfig.getInfoFire().replaceAll("%data", - fire ? MessageConfig.getInfoEnabled() : MessageConfig.getInfoDisabled())); - StringBuilder sb = new StringBuilder(); - Iterator it = wc.getMembersWithNames().values().iterator(); - while (it.hasNext()) { - sb.append(it.next()); - if (it.hasNext()) - sb.append(" "); - } - p.sendMessage(MessageConfig.getInfoMember().replaceAll("%data", sb.toString().trim())); - return true; - } else { - sender.sendMessage("No Console"); //TODO Get Config - return false; - } - } - - public boolean leaveCommand(CommandSender sender, Command command, String label, String[] args) { - if (sender instanceof Player) { - Player p = (Player) sender; - String worldname = p.getWorld().getName(); - WorldPlayer wp = new WorldPlayer(p, worldname); - - if (wp.isOnSystemWorld()) { - // Extra safety for #2 - if (PluginConfig.getSpawn(null).getWorld() == null) { - Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "§cThe spawn is not properly set"); - p.sendMessage(PluginConfig.getPrefix() + "§cThe spawn is not properly set"); - return false; - } - - p.teleport(PluginConfig.getSpawn(p)); - p.setGameMode(PluginConfig.getSpawnGamemode()); - World w = Bukkit.getWorld(p.getWorld().getName()); - SystemWorld.tryUnloadLater(w); - } else { - p.sendMessage(MessageConfig.getNotOnWorld()); - } - return true; - } else { - sender.sendMessage("No Console"); //TODO Get Config - return false; - } - } - - - public boolean tpCommand(CommandSender sender, Command command, String label, String[] args) { - - if (sender instanceof Player) { - Player p = (Player) sender; - if (args.length < 2) { - p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", "/ws tp ")); - return false; - } - - if (args[1].equalsIgnoreCase(p.getName()) || args[1].equalsIgnoreCase(p.getUniqueId().toString())) { - p.chat("/ws home"); - return false; - } - - - DependenceConfig dc = new DependenceConfig(args[1]); - String worldname = dc.getWorldNameByOfflinePlayer(); - if (!dc.hasWorld()) { - p.sendMessage(MessageConfig.getNoWorldOther()); - return false; - } - SystemWorld sw = SystemWorld.getSystemWorld(worldname); - WorldPlayer wp1 = new WorldPlayer(p, p.getWorld().getName()); - WorldPlayer wp = new WorldPlayer(p, worldname); - if (p.getWorld().getName().equals(worldname)) { - sw.teleportToWorldSpawn(p); - return false; - } - if (!p.hasPermission("ws.tp.world")) { - if (!wp.isMemberofWorld(worldname) && !wp.isOwnerofWorld()) { - p.sendMessage(MessageConfig.getNoMemberOther()); - return false; - } - } - if (wp1.isOnSystemWorld()) { - World w = p.getWorld(); - SystemWorld.tryUnloadLater(w); - } - if (sw != null) { - if (!sw.isLoaded()) { - sw.load(p); - } else { - sw.teleportToWorldSpawn(p); - } - } - return true; - } else { - sender.sendMessage("No Console"); //TODO Get Config - return false; - } - } - - - private void create(Player p, WorldTemplate template) { - Bukkit.getScheduler().runTask(WorldSystem.getInstance(), () -> { - if (SystemWorld.create(p, template)) - p.sendMessage(MessageConfig.getSettingUpWorld()); - }); - } -} diff --git a/src/main/java/de/butzlabben/world/command/commands/WorldAdministrateCommand.java b/src/main/java/de/butzlabben/world/command/commands/WorldAdministrateCommand.java deleted file mode 100644 index 1caf3d4..0000000 --- a/src/main/java/de/butzlabben/world/command/commands/WorldAdministrateCommand.java +++ /dev/null @@ -1,397 +0,0 @@ -package de.butzlabben.world.command.commands; - -import de.butzlabben.WorldSystem; -import de.butzlabben.world.config.DependenceConfig; -import de.butzlabben.world.config.MessageConfig; -import de.butzlabben.world.config.PluginConfig; -import de.butzlabben.world.config.WorldConfig; -import de.butzlabben.world.event.WorldAddmemberEvent; -import de.butzlabben.world.event.WorldDeleteEvent; -import de.butzlabben.world.event.WorldRemovememberEvent; -import de.butzlabben.world.util.PlayerPositions; -import de.butzlabben.world.util.PlayerWrapper; -import de.butzlabben.world.wrapper.SystemWorld; -import de.butzlabben.world.wrapper.WorldPlayer; -import org.apache.commons.io.FileUtils; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; - -import java.io.File; -import java.io.IOException; - -public class WorldAdministrateCommand { - - public boolean setTime(CommandSender sender, String ticks) { - switch (ticks) { - case "day": - return setTime(sender, 0); - case "night": - return setTime(sender, 14000); - case "dawn": - return setTime(sender, 23000); - default: - try { - return setTime(sender, Long.parseLong(ticks)); - } catch (NumberFormatException e) { - sender.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", "/ws time [day/night/dawn/0-24000]")); - return false; - } - - } - } - - public boolean setStorm(CommandSender sender, boolean storm) { - if (!(sender instanceof Player)) { - sender.sendMessage("Command has to be executed as a player!"); - return false; - } - - Player p = (Player) sender; - DependenceConfig dc = new DependenceConfig(p); - if (!dc.hasWorld()) { - p.sendMessage(MessageConfig.getNotOnWorld()); - return false; - } - - if (dc.getWorldname().equals(p.getWorld().getName())) { - p.getWorld().setStorm(storm); - return true; - } - - - p.sendMessage(MessageConfig.getNotOnWorld()); - return false; - } - - public boolean setTime(CommandSender sender, long ticks) { - if (!(sender instanceof Player)) { - sender.sendMessage("Command has to be executed as a player!"); - return false; - } - - Player p = (Player) sender; - DependenceConfig dc = new DependenceConfig(p); - if (!dc.hasWorld()) { - p.sendMessage(MessageConfig.getNotOnWorld()); - return false; - } - - if (dc.getWorldname().equals(p.getWorld().getName())) { - p.getWorld().setTime(ticks); - return true; - } - - - p.sendMessage(MessageConfig.getNotOnWorld()); - return false; - } - - public boolean delMemberCommand(CommandSender sender, Command command, String label, String[] args) { - if (sender instanceof Player) { - Player p = (Player) sender; - if (args.length < 2) { - p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", "/ws delmember ")); - return false; - } - - DependenceConfig dc = new DependenceConfig(p); - if (!dc.hasWorld()) { - p.sendMessage(MessageConfig.getNoWorldOwn()); - return false; - } - - @SuppressWarnings("deprecation") - OfflinePlayer a = PlayerWrapper.getOfflinePlayer(args[1]); - WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname()); - if (a == null) { - p.sendMessage(MessageConfig.getNotRegistered().replaceAll("%player", args[1])); - return false; - } else if (!wc.isMember(a.getUniqueId())) { - p.sendMessage(MessageConfig.getNoMemberOwn()); - return false; - } - WorldRemovememberEvent event = new WorldRemovememberEvent(a.getUniqueId(), dc.getWorldname(), p); - Bukkit.getPluginManager().callEvent(event); - if (event.isCancelled()) - return false; - - if (a.isOnline()) { - Player t = (Player) a; - if (t.getWorld().getName().equals(new DependenceConfig(p).getWorldname())) { - t.teleport(PluginConfig.getSpawn(t)); - t.setGameMode(PluginConfig.getSpawnGamemode()); - } - } - - wc.removeMember(a.getUniqueId()); - try { - wc.save(); - } catch (IOException e) { - p.sendMessage(MessageConfig.getUnknownError()); - e.printStackTrace(); - } - p.sendMessage(MessageConfig.getMemberRemoved().replaceAll("%player", a.getName())); - return true; - } else { - sender.sendMessage("No Console"); //TODO Get Config - return false; - } - } - - public boolean deleteCommand(CommandSender sender, Command command, String label, String[] args) { - CommandSender cs = sender; - - if (args.length < 2) { - cs.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", "/ws delete ")); - return false; - } - - DependenceConfig dc = new DependenceConfig(args[1]); - if (!dc.hasWorld()) { - cs.sendMessage(MessageConfig.getNoWorldOther()); - return false; - } - - String worldname = dc.getWorldname(); - SystemWorld sw = SystemWorld.getSystemWorld(worldname); - WorldDeleteEvent event = new WorldDeleteEvent(cs, sw); - Bukkit.getPluginManager().callEvent(event); - if (event.isCancelled()) - return false; - - if (sw != null && sw.isLoaded()) - sw.directUnload(Bukkit.getWorld(worldname)); - - WorldConfig config = WorldConfig.getWorldConfig(worldname); - // Delete unnecessary positions - PlayerPositions.instance.deletePositions(config); - - Bukkit.getScheduler().runTaskLater(WorldSystem.getInstance(), () -> { - OfflinePlayer op = dc.getOwner(); - - String uuid = op.getUniqueId().toString(); - File dir = new File(PluginConfig.getWorlddir() + "/" + worldname); - if (!dir.exists()) - dir = new File(Bukkit.getWorldContainer(), worldname); - if (dir.exists()) - try { - FileUtils.deleteDirectory(dir); - } catch (Exception e) { - cs.sendMessage(MessageConfig.getUnknownError()); - e.printStackTrace(); - } - File dconfig = new File("plugins//WorldSystem//dependence.yml"); - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(dconfig); - cfg.set("Dependences." + uuid + ".ID", null); - cfg.set("Dependences." + uuid + ".ActualName", null); - cfg.set("Dependences." + uuid, null); - try { - cfg.save(dconfig); - } catch (Exception e) { - cs.sendMessage(MessageConfig.getUnknownError()); - e.printStackTrace(); - } - cs.sendMessage(MessageConfig.getDeleteWorldOther().replaceAll("%player", op.getName())); - if (op.isOnline()) { - Player p1 = Bukkit.getPlayer(op.getUniqueId()); - p1.sendMessage(MessageConfig.getDeleteWorldOwn()); - } - }, 10); - return true; - } - - public boolean addMemberCommand(CommandSender sender, Command command, String label, String[] args) { - if (!(sender instanceof Player)) { - sender.sendMessage("No Console"); //TODO Get Config - return false; - } - Player p = (Player) sender; - if (args.length < 2) { - p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", "/ws addmember ")); - return false; - } - - DependenceConfig dc = new DependenceConfig(p); - if (!dc.hasWorld()) { - p.sendMessage(MessageConfig.getNoWorldOwn()); - return false; - } - @SuppressWarnings("deprecation") - OfflinePlayer a = PlayerWrapper.getOfflinePlayer(args[1]); - WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname()); - if (a == null) { - p.sendMessage(MessageConfig.getNotRegistered().replaceAll("%player", args[1])); - return false; - } else if (wc.isMember(a.getUniqueId())) { - p.sendMessage(MessageConfig.getAlreadyMember()); - return false; - } - - WorldAddmemberEvent event = new WorldAddmemberEvent(a.getUniqueId(), dc.getWorldname(), p); - Bukkit.getPluginManager().callEvent(event); - if (event.isCancelled()) - return false; - - wc.addMember(a.getUniqueId()); - try { - wc.save(); - } catch (IOException e) { - p.sendMessage(MessageConfig.getUnknownError()); - e.printStackTrace(); - } - p.sendMessage(MessageConfig.getMemberAdded().replaceAll("%player", a.getName())); - return true; - - } - - public boolean toggleTeleportCommand(CommandSender sender, Command command, String label, String[] args) { - if (sender instanceof Player) { - Player p = (Player) sender; - if (args.length < 2) { - p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", "/ws toggletp ")); - return false; - } - - DependenceConfig dc = new DependenceConfig(p); - if (!dc.hasWorld()) { - p.sendMessage(MessageConfig.getNoWorldOwn()); - return false; - } - OfflinePlayer a = PlayerWrapper.getOfflinePlayer(args[1]); - WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname()); - if (!wc.isMember(a.getUniqueId())) { - p.sendMessage(MessageConfig.getNoMemberOwn()); - return false; - } - WorldPlayer wp = new WorldPlayer(a, dc.getWorldname()); - if (wp.isOwnerofWorld()) { - p.sendMessage(PluginConfig.getPrefix() + "§cYou are the owner"); - return false; - } - if (wp.toggleTeleport()) { - p.sendMessage(MessageConfig.getToggleTeleportEnabled().replaceAll("%player", a.getName())); - } else { - p.sendMessage(MessageConfig.getToggleTeleportDisabled().replaceAll("%player", a.getName())); - } - return true; - } else { - sender.sendMessage("No Console"); //TODO Get Config - return false; - } - } - - public boolean toggleGamemodeCommand(CommandSender sender, Command command, String label, String[] args) { - if (sender instanceof Player) { - Player p = (Player) sender; - if (args.length < 2) { - p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", "/ws togglegm ")); - return false; - } - - DependenceConfig dc = new DependenceConfig(p); - if (!dc.hasWorld()) { - p.sendMessage(MessageConfig.getNoWorldOwn()); - return false; - } - @SuppressWarnings("deprecation") - OfflinePlayer a = PlayerWrapper.getOfflinePlayer(args[1]); - WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname()); - if (!wc.isMember(a.getUniqueId())) { - p.sendMessage(MessageConfig.getNoMemberOwn()); - return false; - } - WorldPlayer wp = new WorldPlayer(a, dc.getWorldname()); - if (wp.isOwnerofWorld()) { - p.sendMessage(PluginConfig.getPrefix() + "§cYou are the owner"); - return false; - } - if (wp.toggleGamemode()) { - p.sendMessage(MessageConfig.getToggleGameModeEnabled().replaceAll("%player", a.getName())); - } else { - p.sendMessage(MessageConfig.getToggleGameModeDisabled().replaceAll("%player", a.getName())); - } - return true; - } else { - sender.sendMessage("No Console"); //TODO Get Config - return false; - } - } - - public boolean toggleWorldeditCommand(CommandSender sender, Command command, String label, String[] args) { - if (sender instanceof Player) { - Player p = (Player) sender; - if (args.length < 2) { - p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", "/ws togglewe ")); - return false; - } - - DependenceConfig dc = new DependenceConfig(p); - if (!dc.hasWorld()) { - p.sendMessage(MessageConfig.getNoWorldOwn()); - return false; - } - @SuppressWarnings("deprecation") - OfflinePlayer a = PlayerWrapper.getOfflinePlayer(args[1]); - WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname()); - if (!wc.isMember(a.getUniqueId())) { - p.sendMessage(MessageConfig.getNoMemberOwn()); - return false; - } - WorldPlayer wp = new WorldPlayer(a, dc.getWorldname()); - if (wp.isOwnerofWorld()) { - p.sendMessage(PluginConfig.getPrefix() + "§cYou are the owner"); - return false; - } - if (wp.toggleWorldEdit()) { - p.sendMessage(MessageConfig.getToggleWorldeditEnabled().replaceAll("%player", a.getName())); - } else { - p.sendMessage(MessageConfig.getToggleWorldeditDisabled().replaceAll("%player", a.getName())); - } - return true; - } else { - sender.sendMessage("No Console"); //TODO Get Config - return false; - } - } - - public boolean toggleBuildCommand(CommandSender sender, Command command, String label, String[] args) { - if (sender instanceof Player) { - Player p = (Player) sender; - if (args.length < 2) { - p.sendMessage(MessageConfig.getWrongUsage().replaceAll("%usage", "/ws togglebuild ")); - return false; - } - - DependenceConfig dc = new DependenceConfig(p); - if (!dc.hasWorld()) { - p.sendMessage(MessageConfig.getNoWorldOwn()); - return false; - } - @SuppressWarnings("deprecation") - OfflinePlayer a = PlayerWrapper.getOfflinePlayer(args[1]); - WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname()); - if (!wc.isMember(a.getUniqueId())) { - p.sendMessage(MessageConfig.getNoMemberOwn()); - return false; - } - WorldPlayer wp = new WorldPlayer(a, dc.getWorldname()); - if (wp.isOwnerofWorld()) { - p.sendMessage(PluginConfig.getPrefix() + "§cYou are the owner"); - return false; - } - if (wp.toggleBuild()) { - p.sendMessage(MessageConfig.getToggleBuildEnabled().replaceAll("%player", a.getName())); - } else { - p.sendMessage(MessageConfig.getToggleBuildDisabled().replaceAll("%player", a.getName())); - } - return true; - } else { - sender.sendMessage("No Console"); //TODO Get Config - return false; - } - } -} diff --git a/src/main/java/de/butzlabben/world/command/commands/WorldSettingsCommands.java b/src/main/java/de/butzlabben/world/command/commands/WorldSettingsCommands.java deleted file mode 100644 index 533bd81..0000000 --- a/src/main/java/de/butzlabben/world/command/commands/WorldSettingsCommands.java +++ /dev/null @@ -1,276 +0,0 @@ -package de.butzlabben.world.command.commands; - -import de.butzlabben.WorldSystem; -import de.butzlabben.world.config.DependenceConfig; -import de.butzlabben.world.config.MessageConfig; -import de.butzlabben.world.config.PluginConfig; -import de.butzlabben.world.config.WorldConfig; -import de.butzlabben.world.event.WorldResetEvent; -import de.butzlabben.world.event.WorldToggleFireEvent; -import de.butzlabben.world.event.WorldToggleTntEvent; -import de.butzlabben.world.gui.WorldChooseGUI; -import de.butzlabben.world.util.PlayerPositions; -import de.butzlabben.world.wrapper.SystemWorld; -import de.butzlabben.world.wrapper.WorldPlayer; -import de.butzlabben.world.wrapper.WorldTemplate; -import de.butzlabben.world.wrapper.WorldTemplateProvider; -import org.apache.commons.io.FileUtils; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.WorldCreator; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; - -public class WorldSettingsCommands { - private static final ArrayList toConfirm = new ArrayList<>(); - - - public boolean resetCommand(CommandSender sender, Command command, String label, String[] args) { - if (sender instanceof Player) { - Player p = (Player) sender; - - DependenceConfig dc = new DependenceConfig(p); - String worldname = dc.getWorldname(); - SystemWorld sw = SystemWorld.getSystemWorld(worldname); - if (!dc.hasWorld()) { - p.sendMessage(MessageConfig.getNoWorldOwn()); - return false; - } - if (args.length > 1) { - if (args[1].equalsIgnoreCase("confirm")) { - if (sw.isLoaded()) - sw.directUnload(Bukkit.getWorld(worldname)); - - if (!toConfirm.contains(p)) { - p.sendMessage(MessageConfig.getNoRequestSend()); - return false; - } - WorldResetEvent event = new WorldResetEvent(p, sw); - Bukkit.getPluginManager().callEvent(event); - if (event.isCancelled()) - return false; - - if (sw.isLoaded()) { - p.sendMessage(MessageConfig.getWorldStillLoaded()); - return false; - } - - WorldConfig config = WorldConfig.getWorldConfig(worldname); - // Delete positions to prevent suffocating and such stuff - PlayerPositions.instance.deletePositions(config); - - File f = new File(PluginConfig.getWorlddir() + "/" + worldname); - - if (!PluginConfig.isMultiChoose()) { - WorldTemplate template = WorldTemplateProvider.getInstance() - .getTemplate(PluginConfig.getDefaultWorldTemplate()); - if (template != null) - createWorld(p, worldname, f, template, sw); - else { - p.sendMessage(PluginConfig.getPrefix() + "§cError in config at \"worldtemplates.default\""); - p.sendMessage(PluginConfig.getPrefix() + "§cPlease contact an administrator"); - } - } else { - WorldChooseGUI.letChoose(p, (template) -> { - if (template != null) - createWorld(p, worldname, f, template, sw); - else { - p.sendMessage(PluginConfig.getPrefix() + "§cError in config at \"worldtemplates.default\""); - p.sendMessage(PluginConfig.getPrefix() + "§cPlease contact an administrator"); - } - }); - } - - } else { - p.sendMessage(MessageConfig.getInvalidInput().replaceAll("input", args[1])); - } - } else { - if (sw.isLoaded()) - sw.directUnload(Bukkit.getWorld(worldname)); - - if (toConfirm.contains(p)) { - p.sendMessage(MessageConfig.getRequestAlreadySent()); - return false; - } - - int time = PluginConfig.getRequestExpire(); - p.sendMessage(MessageConfig.getConfirmRequest().replaceAll("%command", "/ws reset confirm")); - p.sendMessage(MessageConfig.getTimeUntilExpires().replaceAll("%time", String.valueOf(time))); - toConfirm.add(p); - Bukkit.getScheduler().runTaskLater(WorldSystem.getInstance(), () -> { - if (toConfirm.contains(p)) { - p.sendMessage(MessageConfig.getRequestExpired()); - toConfirm.remove(p); - } - }, time * 20L); - } - return true; - } else { - sender.sendMessage("No Console"); //TODO Get Config - return false; - } - } - - public boolean setHomeCommand(CommandSender sender, Command command, String label, String[] args) { - if (sender instanceof Player) { - Player p = (Player) sender; - WorldPlayer wp = new WorldPlayer(p); - if (!wp.isOnSystemWorld()) { - p.sendMessage(MessageConfig.getNotOnWorld()); - return false; - } - if (!wp.isOwnerofWorld()) { - p.sendMessage(MessageConfig.getNoPermission()); - return false; - } - - if (!p.hasPermission("ws.sethome")) { - p.sendMessage(MessageConfig.getNoPermission()); - return false; - } - - WorldConfig config = WorldConfig.getWorldConfig(p.getWorld().getName()); - Location playerLocation = p.getLocation(); - config.home = playerLocation; - System.out.println("installed"); - try { - if (config.home == playerLocation) { - System.out.println("registered"); - } else { - System.out.println("registered incorrectly"); - } - config.save(); - p.sendMessage(MessageConfig.getHomeSet()); - } catch (IOException e) { - p.sendMessage(MessageConfig.getUnknownError() + ": " + e.getMessage()); - e.printStackTrace(); - } - return true; - } else { - sender.sendMessage("No Console"); //TODO Get Config - return false; - } - } - - public boolean tntCommand(CommandSender sender, Command command, String label, String[] args) { - if (sender instanceof Player) { - Player p = (Player) sender; - DependenceConfig dc = new DependenceConfig(p); - WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname()); - boolean tnt = wc.isTnt(); - WorldToggleTntEvent event = new WorldToggleTntEvent(p, SystemWorld.getSystemWorld(dc.getWorldname()), tnt); - Bukkit.getPluginManager().callEvent(event); - if (event.isCancelled()) - return false; - - wc.setTnt(p.getUniqueId(), !tnt); - try { - wc.save(); - } catch (IOException e) { - p.sendMessage(PluginConfig.getPrefix() + "§cSomething went wrong"); - e.printStackTrace(); - } - tnt = wc.isTnt(); - if (tnt) { - p.sendMessage(MessageConfig.getToggleTntEnabled()); - } else { - p.sendMessage(MessageConfig.getToggleTntDisabled()); - } - return true; - } else { - sender.sendMessage("No Console"); //TODO Get Config - return false; - } - } - - public boolean fireCommand(CommandSender sender, Command command, String label, String[] args) { - if (sender instanceof Player) { - Player p = (Player) sender; - DependenceConfig dc = new DependenceConfig(p); - WorldConfig wc = WorldConfig.getWorldConfig(dc.getWorldname()); - boolean fire = wc.isFire(); - WorldToggleFireEvent event = new WorldToggleFireEvent(p, SystemWorld.getSystemWorld(dc.getWorldname()), fire); - Bukkit.getPluginManager().callEvent(event); - if (event.isCancelled()) - return false; - - wc.setFire(p.getUniqueId(), !fire); - try { - wc.save(); - } catch (IOException e) { - p.sendMessage(PluginConfig.getPrefix() + "§cSomething went wrong"); - e.printStackTrace(); - } - fire = wc.isFire(); - if (fire) { - p.sendMessage(MessageConfig.getToggleFireEnabled()); - } else { - p.sendMessage(MessageConfig.getToggleFireDisabled()); - } - return true; - } else { - sender.sendMessage("No Console"); //TODO Get Config - return false; - } - } - - - - - - - - - - - - private void createWorld(Player p, String worldname, File f, WorldTemplate template, SystemWorld sw) { - - 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 { - File templateDirectory = new File(template.getPath()); - if (templateDirectory.isDirectory()) - FileUtils.copyDirectory(templateDirectory, f); - toConfirm.remove(p); - - FileUtils.moveDirectoryToDirectory(f, Bukkit.getWorldContainer(), false); - - WorldConfig config = WorldConfig.getWorldConfig(worldname); - config.home = null; - config.setTemplateKey(template.getName()); - config.save(); - - p.sendMessage(MessageConfig.getWorldReseted()); - - // For fast worldcreating after reset - WorldCreator creator = template.generatorSettings.asWorldCreator(worldname); - - sw.setCreating(true); - // For #16 - WorldSystem.getInstance().getAdapter().create(creator, sw, () -> { - if (p != null && p.isOnline()) - p.sendMessage(MessageConfig.getWorldCreated()); - }); - - } catch (IOException e) { - e.printStackTrace(); - p.sendMessage(MessageConfig.getUnknownError()); - System.err.println("Couldn't reset world of " + p.getName()); - } - } -} diff --git a/src/main/java/de/butzlabben/world/commands/WorldSystemCommand.java b/src/main/java/de/butzlabben/world/commands/WorldSystemCommand.java new file mode 100644 index 0000000..08ba3e5 --- /dev/null +++ b/src/main/java/de/butzlabben/world/commands/WorldSystemCommand.java @@ -0,0 +1,6 @@ +package de.butzlabben.world.commands; + +public interface WorldSystemCommand +{ + public boolean run(); +} diff --git a/src/main/java/de/butzlabben/world/commands/WorldSystemCommandExecuter.java b/src/main/java/de/butzlabben/world/commands/WorldSystemCommandExecuter.java new file mode 100644 index 0000000..a122eaf --- /dev/null +++ b/src/main/java/de/butzlabben/world/commands/WorldSystemCommandExecuter.java @@ -0,0 +1,24 @@ +package de.butzlabben.world.commands; + +import java.util.HashMap; +import java.util.Map; + +public class WorldSystemCommandExecuter +{ + private static Map commands = new HashMap(); + + public static void addCommand(String commandName, WorldSystemCommand cmd) + { + if (commands.containsValue(commandName)) { + //Log Command Excists + return; + } + commands.put(commandName, cmd); + } + + public static boolean execute(String cmd) { + return commands.get(cmd).run(); + } + + +} diff --git a/src/main/java/de/butzlabben/world/commands/commands/testCommand.java b/src/main/java/de/butzlabben/world/commands/commands/testCommand.java new file mode 100644 index 0000000..f47592e --- /dev/null +++ b/src/main/java/de/butzlabben/world/commands/commands/testCommand.java @@ -0,0 +1,12 @@ +package de.butzlabben.world.commands.commands; + +import de.butzlabben.world.commands.WorldSystemCommand; + +public class testCommand implements WorldSystemCommand +{ + @Override + public boolean run() + { + return false; + } +} diff --git a/src/main/java/de/butzlabben/world/config/DependenceConfig.java b/src/main/java/de/butzlabben/world/config/DependenceConfig.java deleted file mode 100644 index 3244e6e..0000000 --- a/src/main/java/de/butzlabben/world/config/DependenceConfig.java +++ /dev/null @@ -1,163 +0,0 @@ -package de.butzlabben.world.config; - -import de.butzlabben.world.util.PlayerWrapper; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; - -import java.io.File; -import java.io.IOException; -import java.util.UUID; - -public class DependenceConfig { - - private UUID uuid; - - public DependenceConfig() { - setConfig(); - } - - public DependenceConfig(String s) { - OfflinePlayer op = null; - try { - op = PlayerWrapper.getOfflinePlayer(UUID.fromString(s)); - } catch (Exception ignored) { - } - if (op == null) { - op = PlayerWrapper.getOfflinePlayer(s); - } - uuid = op.getUniqueId(); - } - - public DependenceConfig(Player p) { - uuid = p.getUniqueId(); - refreshName(); - } - - public DependenceConfig(OfflinePlayer p) { - uuid = p.getUniqueId(); - refreshName(); - } - - public DependenceConfig(UUID uuid) { - this.uuid = uuid; - } - - public static int getHighestID() { - File dconfig = new File("plugins//WorldSystem//dependence.yml"); - YamlConfiguration dcfg = YamlConfiguration.loadConfiguration(dconfig); - return dcfg.getInt("HighestID"); - } - - 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); - } - } - } - - 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.uuid.toString(); - cfg.set("Dependences." + uuid + ".ActualName", PlayerWrapper.getOfflinePlayer(this.uuid).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.uuid.toString(); - int id = cfg.getInt("HighestID"); - id++; - cfg.set("HighestID", id); - cfg.set("Dependences." + uuid + ".ID", id); - cfg.set("Dependences." + uuid + ".ActualName", PlayerWrapper.getOfflinePlayer(this.uuid).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 = this.uuid.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 = this.uuid.toString(); - int id = dcfg.getInt("Dependences." + uuid + ".ID"); - return "ID" + id + "-" + uuid; - } - - public String getWorldNameByOfflinePlayer() { - String name; - String uuid = this.uuid.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 = this.uuid.toString(); - cfg.set("Dependences." + uuid + ".last_loaded", System.currentTimeMillis()); - try { - cfg.save(dconfig); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public int getID() { - File dconfig = new File("plugins//WorldSystem//dependence.yml"); - YamlConfiguration dcfg = YamlConfiguration.loadConfiguration(dconfig); - return dcfg.getInt("Dependences." + this.uuid.toString() + ".ID"); - } - - public OfflinePlayer getOwner() { - return PlayerWrapper.getOfflinePlayer(uuid); - } -} diff --git a/src/main/java/de/butzlabben/world/config/Entry.java b/src/main/java/de/butzlabben/world/config/Entry.java deleted file mode 100644 index 516717e..0000000 --- a/src/main/java/de/butzlabben/world/config/Entry.java +++ /dev/null @@ -1,53 +0,0 @@ -package de.butzlabben.world.config; - -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.configuration.file.YamlConfiguration; - -import java.io.File; - -public class Entry { - - private final OfflinePlayer op; - private final String worldname; - private int id; - - 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); - } -} diff --git a/src/main/java/de/butzlabben/world/config/GuiConfig.java b/src/main/java/de/butzlabben/world/config/GuiConfig.java deleted file mode 100644 index 29d3efc..0000000 --- a/src/main/java/de/butzlabben/world/config/GuiConfig.java +++ /dev/null @@ -1,150 +0,0 @@ -package de.butzlabben.world.config; - -import de.butzlabben.inventory.OrcItem; -import de.butzlabben.WorldSystem; -import de.butzlabben.world.util.VersionUtil; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.plugin.java.JavaPlugin; - -import java.io.*; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.util.ArrayList; -import java.util.List; - -public class GuiConfig { - - private static File file; - - private GuiConfig() { - } - - public static void checkConfig(File f) { - file = f; - if (!file.exists()) { - try { - String guiFileResource; - if (VersionUtil.getVersion() >= 14) { - guiFileResource = "1_14_gui.yml"; - } else if (VersionUtil.getVersion() == 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), StandardCharsets.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 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 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 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 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 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 getEnabled() { - return getItem("options.enabled"); - } - - public static OrcItem getDisabled() { - return getItem("options.disabled"); - } - - 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 deleted file mode 100644 index c55829d..0000000 --- a/src/main/java/de/butzlabben/world/config/MessageConfig.java +++ /dev/null @@ -1,285 +0,0 @@ -package de.butzlabben.world.config; - -import de.butzlabben.WorldSystem; -import net.md_5.bungee.api.ChatColor; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.plugin.java.JavaPlugin; - -import java.io.*; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -public class MessageConfig { - - private static final List defaultCmdHelp = new ArrayList<>(20); - private static File file; - - static { - defaultCmdHelp.add("/ws get §8- §7Will give you a World"); - defaultCmdHelp.add("/ws home §8- §7Teleports you on your World"); - defaultCmdHelp.add("/ws sethome §8- §7Sets a specific home"); - defaultCmdHelp.add("/ws tp §8- §7Teleports you on a specific World"); - defaultCmdHelp.add("/ws addmember §8- §7Adds a player to your World"); - defaultCmdHelp.add("/ws delmember§8 - §7Removes a player from your World"); - defaultCmdHelp.add("/ws tnt §8- §7Allows/Denys TNT on your World"); - defaultCmdHelp.add("/ws fire §8- §7Allows/Denys Fire on your World"); - defaultCmdHelp.add("/ws togglechgm §8- §7Allows/Denys a player changing gamemode"); - defaultCmdHelp.add("/ws togglebuild §8- §7Allows/Denys a player building"); - defaultCmdHelp.add("/ws toggletp §8- §7Allows/Denys a player teleporting"); - defaultCmdHelp.add("/ws info §8- §7Shows information about the World"); - defaultCmdHelp.add("/ws reset §8- §7Will reset your World"); - } - - private MessageConfig() { - } - - public static void checkConfig(File f) { - file = f; - if (!file.exists()) { - try { - InputStream in = JavaPlugin.getPlugin(WorldSystem.class).getResource("languages/" + f.getName()); - - if (in == null) { - in = JavaPlugin.getPlugin(WorldSystem.class).getResource("custom.yml"); - } - Files.copy(in, file.toPath()); - } catch (IOException e) { - System.err.println("Wasn't able to create Message file"); - e.printStackTrace(); - } - } - } - - private static YamlConfiguration getConfig() { - try { - return YamlConfiguration.loadConfiguration(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - return null; - } - - private static String getRawMessage(String path, String alt) { - return ChatColor.translateAlternateColorCodes('&', getConfig().getString(path, alt)); - } - - private static String getMessage(String path, String alt) { - return PluginConfig.getPrefix() + getRawMessage(path, alt); - } - - public static String getNoPermission() { - return getMessage("nopermission", "§cYou don't have permissions!"); - } - - public static String getSettingUpWorld() { - return getMessage("world.setting_up", "§aSetting up world..."); - } - - public static String getPlayerList() { - return getMessage("world.playerlist", "Player in this world: %player"); - } - - public static String getLagDetection() { - return getMessage("lagdetection", "Lagdetection in world from: §c%world"); - } - - public static String getWrongUsage() { - return getMessage("wrong_usage", "§c%usage"); - } - - public static String getNoWorldOwn() { - return getMessage("world.does_not_exists.own", "§cYou don't have a world!"); - } - - public static String getNoWorldOther() { - return getMessage("world.does_not_exists.other", "§cThis player doesn't has a world!"); - } - - public static String getNotRegistered() { - return getMessage("not_registered", "§cThis player hasn't joined yet!"); - } - - public static String getAlreadyMember() { - return getMessage("member.already_added", "§cThis player is already a member!"); - } - - public static String getMemberAdded() { - return getMessage("member.added", "You have added &c%player&6 to your World!"); - } - - public static String getUnknownError() { - return getMessage("unknown_error", "§cSomething went wrong..."); - } - - public static String getDeleteWorldOwn() { - return getMessage("world.delete.own", "§cYour world was deleted!"); - } - - public static String getDeleteWorldOther() { - return getMessage("world.delete.other", "You deleted the world of §c%player§6!"); - } - - public static String getNoMemberOwn() { - return getMessage("member.not_added.own", "§cThis player isn't a member!"); - } - - public static String getMemberRemoved() { - return getMessage("member.removed", "You removed §c%player§6 from your world!"); - } - - public static String getNoMemberAdded() { - return getMessage("member.no_one_added", "§cThere are no members added"); - } - - public static String getWorldAlreadyExists() { - return getMessage("world.already_exists", "§cYou already have a world!"); - } - - public static String getWorldCreated() { - return getMessage("world.created", "Your world is now ready. Get there with §a/ws home"); - } - - public static String getWorldStillCreating() { - return getMessage("world.still_creating", "§cWorld is still creating"); - } - - public static String getNotOnWorld() { - return getMessage("world.not_on", "§cYou are not on a world!"); - } - - public static String getWorldStillLoaded() { - return getMessage("world.still_loaded", "§cYour world is still loaded!"); - } - - public static String getNoRequestSend() { - return getMessage("request.not_sent", "§cYou didn't send a request!"); - } - - public static String getWorldReseted() { - return getMessage("world.reseted", "Your world was reseted!"); - } - - public static String getInvalidInput() { - return getMessage("request.invalid_input", "§c%input is not a valid input!"); - } - - public static String getRequestAlreadySent() { - return getMessage("request.already_sent", "§cYou already sent a request!"); - } - - public static String getRequestExpired() { - return getMessage("request.expired", "§cYou request is expired!"); - } - - public static String getTimeUntilExpires() { - return getMessage("request.until_expire", "§cYour request expires in %time seconds!"); - } - - public static String getConfirmRequest() { - return getMessage("request.confirm", "§cPlease confirm reset of your world: %command"); - } - - public static String getNoMemberOther() { - return getMessage("member.not_added.other", "§cYou are not added to this world!"); - } - - public static String getInfoOwner() { - return getMessage("info.owner", "Owner: %data"); - } - - public static String getInfoId() { - return getMessage("info.id", "ID: %data"); - } - - public static String getInfoMember() { - return getMessage("info.member", "Member: %data"); - } - - public static String getInfoTnt() { - return getMessage("info.tnt", "TNT: %data"); - } - - public static String getInfoFire() { - return getMessage("info.fire", "Fire: %data"); - } - - public static String getInfoEnabled() { - return getRawMessage("info.enabled", "§aOn"); - } - - public static String getInfoDisabled() { - return getRawMessage("info.disabled", "§cOff"); - } - - public static String getToggleGameModeEnabled() { - return getMessage("toggle.gamemode.enabled", "§a%player§6 can now change his gamemode!"); - } - - public static String getToggleGameModeDisabled() { - return getMessage("toggle.gamemode.disabled", "§c%player§6 can no longer change his gamemode!"); - } - - public static String getToggleTeleportEnabled() { - return getMessage("toggle.teleport.enabled", "§a%player§6 can now teleport!"); - } - - public static String getToggleTeleportDisabled() { - return getMessage("toggle.teleport.disabled", "§c%player§6 can no longer teleport!"); - } - - public static String getToggleBuildEnabled() { - return getMessage("toggle.build.enabled", "§a%player§6 can now build!"); - } - - public static String getToggleBuildDisabled() { - return getMessage("toggle.build.disabled", "§c%player§6 can no longer build!"); - } - - public static String getToggleWorldeditEnabled() { - return getMessage("toggle.worldedit.enabled", "§a%player§6 can now use WorldEdit!"); - } - - public static String getToggleWorldeditDisabled() { - return getMessage("toggle.worldedit.disabled", "§c%player§6 can no longer use WorldEdit!"); - } - - - public static String getToggleFireEnabled() { - return getMessage("toggle.fire.enabled", "§aYou activated fire!"); - } - - public static String getToggleFireDisabled() { - return getMessage("toggle.fire.disabled", "§cYou deactivated fire!"); - } - - public static String getToggleTntEnabled() { - return getMessage("toggle.tnt.enabled", "§aYou activated TNT-Damage!"); - } - - public static String getToggleTntDisabled() { - return getMessage("toggle.tnt.disabled", "§cYou deactivated TNT-Damage!"); - } - - public static String getDeleteCommandHelp() { - return getMessage("command_help.delete_command", "/ws delete §8- §7Will delete a World"); - } - - public static List getCommandHelp() { - List list = getConfig().getStringList("command_help.list"); - if (list == null) - list = defaultCmdHelp; - list = list.stream().map(s -> ChatColor.translateAlternateColorCodes('&', s)).collect(Collectors.toList()); - return list; - } - - public static String getHomeSet() { - return getMessage("world.set_home", "You set the home"); - } - - public static String getNotEnoughMoney() { - return getMessage("not_enough_money", "You do not have enough money"); - } -} diff --git a/src/main/java/de/butzlabben/world/config/PluginConfig.java b/src/main/java/de/butzlabben/world/config/PluginConfig.java index 8785171..0db0cd2 100644 --- a/src/main/java/de/butzlabben/world/config/PluginConfig.java +++ b/src/main/java/de/butzlabben/world/config/PluginConfig.java @@ -1,16 +1,10 @@ package de.butzlabben.world.config; -import de.butzlabben.WorldSystem; import de.butzlabben.world.exceptions.InvalidConfigFormatException; -import de.butzlabben.world.util.PlayerPositions; -import net.md_5.bungee.api.ChatColor; -import org.bukkit.Bukkit; +import de.butzlabben.world.utils.PlanerCords; +import org.bukkit.Difficulty; import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.World; import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; import java.io.*; import java.nio.charset.StandardCharsets; @@ -18,9 +12,11 @@ import java.nio.file.Files; import java.nio.file.StandardCopyOption; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Dictionary; public class PluginConfig { + //New Config private YamlConfiguration config; private File configFile; @@ -46,6 +42,8 @@ public class PluginConfig { StandardCopyOption.REPLACE_EXISTING); Files.delete(configFile.toPath()); System.err.println("[WorldSystem] Config is broken, creating a new one!"); + + //TODO Create new Config } catch (IOException ex) { //Somthing Really Bad Happened @@ -62,232 +60,160 @@ public class PluginConfig { } - private void verifyConfigFormating() throws InvalidConfigFormatException { + private void verifyConfigFormating() throws InvalidConfigFormatException + { //Verify General if (!(config.isString("playerWorldsDir") && - config.isInt("unloadTime") && - config.isString("prefix") && - config.isInt("deleteAfterDays") && - config.isString("worldDifficulty"))) { + config.isInt("unloadTime") && + config.isString("prefix") && + config.isInt("deleteAfterDays") && + config.isString("worldDifficulty"))) + { throw new InvalidConfigFormatException("Invaild Config Format in General Settings"); } //Verify World Creation Settings if (!(config.isBoolean("multiChoose") && - config.isString("defaultGenerator") && - config.isString("worldGenTemplates") && - config.isInt("worldBorderDefaultSize") && - config.isInt("worldBorderCenter.x") && - config.isInt("worldBorderCenter.z") - )) { + config.isString("defaultGenerator") && + config.isString("worldGenTemplates") && + config.isInt("worldBorderDefaultSize") && + config.isInt("worldBorderCenter.x") && + config.isInt("worldBorderCenter.z") + )) + { throw new InvalidConfigFormatException("Invaild Config Format in World Creation Settings"); } if (!(config.isString("serverSpawn.serverGamemode") && - config.isString("serverSpawn.serverSpawnPoint.worldName") && - config.isInt("serverSpawn.serverSpawnPoint.x") && - config.isInt("serverSpawn.serverSpawnPoint.y") && - config.isInt("serverSpawn.serverSpawnPoint.z") && - config.isString("wsWorldSpawn.worldGameMode") && - config.isBoolean("wsWorldSpawn.useLastLocation") && - config.isString("wsWorldSpawn.defaultWorldSpawnPoint.worldName") && - config.isInt("wsWorldSpawn.defaultWorldSpawnPoint.x") && - config.isInt("wsWorldSpawn.defaultWorldSpawnPoint.y") && - config.isInt("wsWorldSpawn.defaultWorldSpawnPoint.z"))) { + config.isString("serverSpawn.serverSpawnPoint.worldName") && + config.isInt("serverSpawn.serverSpawnPoint.x") && + config.isInt("serverSpawn.serverSpawnPoint.y") && + config.isInt("serverSpawn.serverSpawnPoint.z") && + config.isString("wsWorldSpawn.worldGameMode") && + config.isBoolean("wsWorldSpawn.useLastLocation") && + config.isString("wsWorldSpawn.defaultWorldSpawnPoint.worldName") && + config.isInt("wsWorldSpawn.defaultWorldSpawnPoint.x") && + config.isInt("wsWorldSpawn.defaultWorldSpawnPoint.y") && + config.isInt("wsWorldSpawn.defaultWorldSpawnPoint.z"))) + { throw new InvalidConfigFormatException("Invaild Config Format in World Entering/Exiting"); } if (!(config.isBoolean("announceAdvancements") && - config.isBoolean("commandBlockOutput") && - config.isBoolean("disableElytraMovementCheck") && - config.isBoolean("doDaylightCycle") && - config.isBoolean("doEntityDrops") && - config.isBoolean("doFireTick") && - config.isBoolean("doLimitedCrafting") && - config.isBoolean("doMobLoot") && - config.isBoolean("doMobSpawning") && - config.isBoolean("doTileDrops") && - config.isBoolean("doWeatherCycle") && - config.isBoolean("gameLoopFunction") && - config.isBoolean("keepInventory") && - config.isBoolean("logAdminCommands") && - config.isInt("maxCommandChainLength") && - config.isInt("maxEntityCramming") && - config.isBoolean("mobGriefing") && - config.isBoolean("naturalRegeneration") && - config.isInt("randomTickSpeed") && - config.isBoolean("reducedDebugInfo") && - config.isBoolean("sendCommandFeedback") && - config.isBoolean("showDeathMessages") && - config.isInt("spawnRadius") && - config.isBoolean("spectatorsGenerateChunks"))) { + config.isBoolean("commandBlockOutput") && + config.isBoolean("disableElytraMovementCheck") && + config.isBoolean("doDaylightCycle") && + config.isBoolean("doEntityDrops") && + config.isBoolean("doFireTick") && + config.isBoolean("doLimitedCrafting") && + config.isBoolean("doMobLoot") && + config.isBoolean("doMobSpawning") && + config.isBoolean("doTileDrops") && + config.isBoolean("doWeatherCycle") && + config.isBoolean("gameLoopFunction") && + config.isBoolean("keepInventory") && + config.isBoolean("logAdminCommands") && + config.isInt("maxCommandChainLength") && + config.isInt("maxEntityCramming") && + config.isBoolean("mobGriefing") && + config.isBoolean("naturalRegeneration") && + config.isInt("randomTickSpeed") && + config.isBoolean("reducedDebugInfo") && + config.isBoolean("sendCommandFeedback") && + config.isBoolean("showDeathMessages") && + config.isInt("spawnRadius") && + config.isBoolean("spectatorsGenerateChunks"))) + { throw new InvalidConfigFormatException("Invaild Config Format in Gamerules "); } } - public String getWorldDir() { - return config.getString("playerWorldsDir", "plugins/WorldSystem/Worlds") + "/"; + + //General Setting Getters + + + public String getLanguage() + { + return config.getString("language"); } - public boolean useWorldSpawn() { - return config.getBoolean("wsWorldSpawn.useLastLocation", true); + public String getWorldDir() + { + return config.getString("playerWorldsDir"); } - public GameMode getWorldSystemGamemode() { - return stringToGamemode(config.getString("wsWorldSpawn.worldGameMode", "Survival")); + public int getUnloadTime() + { + return config.getInt("unloadTime"); } - public GameMode getServerGamemode() { - return stringToGamemode(config.getString("serverSpawn.serverGamemode", "Survival")); + public String getPrefix() + { + return config.getString("prefix"); } - public int getUnloadingTime() { - return config.getInt("unloadTime", 20); + public int getDeleteAfter() { + return config.getInt("deleteAfterDays"); } - public boolean isMultiChoose() { - return config.getBoolean("multiChoose", false); + public Difficulty getWorldDifficulty() { + return stringToDifficulty(config.getString("worldDifficulty")); + } + + //World Creation Setting Getters + + public boolean allowsMultiChoice() { + return config.getBoolean("multiChoose"); } public String getDefaultWorldGenerator() { - return config.getString("defaultGenerator", "Vanilla"); + return config.getString("defaultGenerator"); } - public String getLanguage() { - return config.getString("language", "en"); + public String getGeneratorTemplatesDir() { + return config.getString("worldGenTemplates"); } - public String getPrefix() { - return ChatColor.translateAlternateColorCodes('&', config.getString("prefix", "§8[§3WorldSystem§8] §6")); + public int getDefaultWorldBorderSize() { + return config.getInt("worldBorderDefaultSize"); } - public Location getWorldSpawn(World w) { - return getLocation(config, "wsWorldSpawn.defaultWorldSpawnPoint", w); + public PlanerCords getWorldBorderCords() { + return new PlanerCords(config.getInt("worldBorderCenter.x"), config.getInt("worldBorderCenter.y")); } - public Location getSpawn(Player player) { - Location location = getLocation(config, "wsWorldSpawn.defaultWorldSpawnPoint", Bukkit.getWorld(config.getString("wsWorldSpawn.defaultWorldSpawnPoint.worldName", "world"))); + //World Entering/Exiting Getters - //TODO Player Positions with PlayerWorldData; - return PlayerPositions.instance.injectPlayersLocation(player, location); + public GameMode getServerGamemode() { + + return stringToGamemode(config.getString("serverSpawn.serverGamemode")); } - private GameMode stringToGamemode(String gamemode) { - switch (gamemode.toLowerCase()) { - case "Creative": + + + + + private GameMode stringToGamemode(String gm) { + switch (gm.toLowerCase()) { + case "creative": return GameMode.CREATIVE; - case "Adventure": + case "adventure": return GameMode.ADVENTURE; default: return GameMode.SURVIVAL; } } - private static Location getLocation(YamlConfiguration cfg, String path, World world) { - return new Location(world, cfg.getDouble(path + ".x", 0), cfg.getDouble(path + ".y", 20), - cfg.getDouble(path + ".z", 0)); + private Difficulty stringToDifficulty(String diff) { + switch (diff.toUpperCase()) { + case "EASY": + return Difficulty.EASY; + case "NORMAL": + return Difficulty.NORMAL; + case "HARD": + return Difficulty.HARD; + default: + return Difficulty.PEACEFUL; + } } - /* - - public static int getGCPeriod() { - return getConfig().getInt("lagsystem.garbagecollector.period_in_minutes", 5); - } - - public static boolean useGC() { - return getConfig().getBoolean("lagsystem.garbagecollector.use", false); - } - - public static int getEntitysPerWorld() { - return getConfig().getInt("lagsystem.entities_per_world", 350); - } - - public static int getLagCheckPeriod() { - return getConfig().getInt("lagsystem.period_in_seconds", 10); - } - -///////////////////////////////////// - - public static Location getSpawn(Player player) { - YamlConfiguration cfg = getConfig(); - Location location = getLocation(cfg, "spawn.spawnpoint", Bukkit.getWorld(cfg.getString("spawn.spawnpoint.world", "world"))); - return PlayerPositions.instance.injectPlayersLocation(player, location); - } - - public static int getRequestExpire() { - return getConfig().getInt("request_expires", 20); - } - - public static boolean confirmNeed() { - return getConfig().getBoolean("need_confirm", true); - } - - public static boolean contactAuth() { - return getConfig().getBoolean("contact_authserver", true); - } - - public static boolean spawnTeleportation() { - return getConfig().getBoolean("spawn_teleportation", true); - } - - public static boolean shouldDelete() { - return getConfig().getInt("delete_after") != -1; - } - - public static long deleteAfter() { - return getConfig().getLong("delete_after"); - } - - public static boolean useWorldSpawnLastLocation() { - return getConfig().getBoolean("worldspawn.use_last_location"); - } - - public static boolean useSpawnLastLocation() { - return getConfig().getBoolean("spawn.spawnpoint.use_last_location"); - } - - public static String getWorldsTableName() { - return getConfig().getString("database.worlds_table_name"); - } - - public static String getPlayersTableName() { - return getConfig().getString("database.players_table_name"); - } - - public static String getUUIDTableName() { - return getConfig().getString("database.players_uuids"); - } - - - - public static String getDatabaseType() { - return getConfig().getString("database.type"); - } - - public static String getSqliteFile() { - return getConfig().getString("database.sqlite_settings.file"); - } - - public static String getMysqlHost() { - return getConfig().getString("database.mysql_settings.host"); - } - - public static int getMysqlPort() { - return getConfig().getInt("database.mysql_settings.port"); - } - - public static String getMysqlUser() { - return getConfig().getString("database.mysql_settings.username"); - } - - public static String getMysqlPassword() { - return getConfig().getString("database.mysql_settings.password"); - } - - public static String getMysqlDatabaseName() { - return getConfig().getString("database.mysql_settings.database"); - } - - public static boolean loadWorldsASync() { - return getConfig().getBoolean("load_worlds_async"); - }*/ } diff --git a/src/main/java/de/butzlabben/world/config/SettingsConfig.java b/src/main/java/de/butzlabben/world/config/SettingsConfig.java deleted file mode 100644 index 7a5c68d..0000000 --- a/src/main/java/de/butzlabben/world/config/SettingsConfig.java +++ /dev/null @@ -1,196 +0,0 @@ -package de.butzlabben.world.config; - -import de.butzlabben.WorldSystem; -import de.butzlabben.world.wrapper.SystemWorld; -import org.bukkit.Bukkit; -import org.bukkit.Difficulty; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -import java.io.*; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.util.HashMap; -import java.util.List; -import java.util.UUID; - -//maybe just merge this config with the WorldConfig -public class SettingsConfig { - - private static final HashMap borderSizes = new HashMap<>(); - - private static File file; - - private SettingsConfig() { - } - - @SuppressWarnings("deprecation") - // TODO rebuild this, as it's inperformant and not very beautiful code.. - // only load once, and then reload the things from the disk on command - public static void editWorld(World w) { - YamlConfiguration cfg = getConfig(); - - SystemWorld sw = SystemWorld.getSystemWorld(w.getName()); - - 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); - - // Only edit worldborder size if owner is online - if (p != null && p.isOnline()) { - - // Check permissions - for (String string : borderSizes.keySet()) { - if (p.hasPermission(string) && size < borderSizes.get(string)) { - size = borderSizes.get(string); - } - } - - w.getWorldBorder().setSize(size); - } - - 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()); - } - } - } - - // 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("announceAdvancements")) - w.setGameRuleValue("announceAdvancements", cfg.getString("announceAdvancements")); - - if (w.isGameRule("commandBlockOutput")) - w.setGameRuleValue("commandBlockOutput", cfg.getString("commandBlockOutput")); - - if (w.isGameRule("disableElytraMovementCheck")) - w.setGameRuleValue("disableElytraMovementCheck", cfg.getString("disableElytraMovementCheck")); - - if (w.isGameRule("doDaylightCycle")) - w.setGameRuleValue("doDaylightCycle", cfg.getString("doDaylightCycle")); - - if (w.isGameRule("doEntityDrops")) - w.setGameRuleValue("doEntityDrops", cfg.getString("doEntityDrops")); - - if (w.isGameRule("doFireTick")) - w.setGameRuleValue("doFireTick", cfg.getString("doFireTick")); - - if (w.isGameRule("doLimitedCrafting")) - w.setGameRuleValue("doLimitedCrafting", cfg.getString("doLimitedCrafting")); - - if (w.isGameRule("doMobLoot")) - w.setGameRuleValue("doMobLoot", cfg.getString("doMobLoot")); - - if (w.isGameRule("doMobSpawning")) - w.setGameRuleValue("doMobSpawning", cfg.getString("doMobSpawning")); - - if (w.isGameRule("doTileDrops")) - w.setGameRuleValue("doTileDrops", cfg.getString("doTileDrops")); - - if (w.isGameRule("doWeatherCycle")) - w.setGameRuleValue("doWeatherCycle", cfg.getString("doWeatherCycle")); - - if (w.isGameRule("gameLoopFunction")) - w.setGameRuleValue("gameLoopFunction", cfg.getString("gameLoopFunction")); - - if (w.isGameRule("keepInventory")) - w.setGameRuleValue("keepInventory", cfg.getString("keepInventory")); - - if (w.isGameRule("logAdminCommands")) - w.setGameRuleValue("logAdminCommands", cfg.getString("logAdminCommands")); - - if (w.isGameRule("maxCommandChainLength")) - w.setGameRuleValue("maxCommandChainLength", cfg.getString("maxCommandChainLength")); - - if (w.isGameRule("maxEntityCramming")) - w.setGameRuleValue("maxEntityCramming", cfg.getString("maxEntityCramming")); - - if (w.isGameRule("mobGriefing")) - w.setGameRuleValue("mobGriefing", cfg.getString("mobGriefing")); - - if (w.isGameRule("naturalRegeneration")) - w.setGameRuleValue("naturalRegeneration", cfg.getString("naturalRegeneration")); - - if (w.isGameRule("randomTickSpeed")) - w.setGameRuleValue("randomTickSpeed", cfg.getString("randomTickSpeed")); - - if (w.isGameRule("reducedDebugInfo")) - w.setGameRuleValue("reducedDebugInfo", cfg.getString("reducedDebugInfo")); - - if (w.isGameRule("sendCommandFeedback")) - w.setGameRuleValue("sendCommandFeedback", cfg.getString("sendCommandFeedback")); - - if (w.isGameRule("showDeathMessages")) - w.setGameRuleValue("showDeathMessages", cfg.getString("showDeathMessages")); - - if (w.isGameRule("spawnRadius")) - w.setGameRuleValue("spawnRadius", cfg.getString("spawnRadius")); - - if (w.isGameRule("spectatorsGenerateChunks")) - w.setGameRuleValue("spectatorsGenerateChunks", cfg.getString("spectatorsGenerateChunks")); - } - - private static YamlConfiguration getConfig() { - try { - return YamlConfiguration - .loadConfiguration(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - return null; - } - - 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)); - } - } - - /** - * @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 deleted file mode 100644 index 42eec9b..0000000 --- a/src/main/java/de/butzlabben/world/config/WorldConfig.java +++ /dev/null @@ -1,593 +0,0 @@ -package de.butzlabben.world.config; - -import com.google.common.collect.Sets; -import com.mojang.authlib.GameProfile; -import de.butzlabben.world.GameProfileBuilder; -import de.butzlabben.world.util.PlayerWrapper; -import de.butzlabben.world.wrapper.WorldTemplate; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; -import java.util.UUID; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.OfflinePlayer; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.YamlConfiguration; - -/** - * This class represents a worldconfig.yml file Here you can edit and read all - * things Get an instance via WorldConfig.getWorldConfig() - * - * @since 01.05.2018 - */ -@SuppressWarnings("ResultOfMethodCallIgnored") -public class WorldConfig { - - private static final HashMap instances = new HashMap<>(); - - private final UUID owner; - private final int id; - - private final HashMap> permissions = new HashMap<>(); - - private String ownerName; - private String templateKey; - private boolean fire, tnt; - - public 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()) { - worldconfig = new File(PluginConfig.getWorlddir() + "/" + worldname + "/worldconfig.yml"); - } - if (!worldconfig.exists()) { - worldconfig = new File(worldname + "/worldconfig.yml"); - } - return worldconfig; - } - - /** - * Returns whether a worldconfig exists for this worldname - * - * @param worldname name of the world - * @return Whether this world has a worldconfig - */ - public static boolean exists(String worldname) { - return getWorldFile(worldname).exists(); - } - - /** - * Gets the worldconfig for a specific worldname or creates a new one of no - * exists - * - * @param worldname of the world - * @return WorldConfig of the world - */ - public static WorldConfig getWorldConfig(String worldname) { - if (!instances.containsKey(worldname)) - instances.put(worldname, new WorldConfig(worldname)); - return instances.get(worldname).load(); - } - - public static void create(UUID uuid, WorldTemplate template) { - DependenceConfig dc = new DependenceConfig(uuid); - String worldname = dc.getWorldname(); - File file = new File(PluginConfig.getWorlddir() + worldname + "/worldconfig.yml"); - try { - file.createNewFile(); - } catch (IOException e1) { - e1.printStackTrace(); - System.err.println("Error while creating worldconfig for " + uuid.toString()); - } - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); - cfg.set("Informations.ID", dc.getID()); - cfg.set("Informations.Owner.PlayerUUID", uuid.toString()); - cfg.set("Informations.Owner.Actualname", Objects.requireNonNull(PlayerWrapper.getOfflinePlayer(uuid)).getName()); - cfg.set("Informations.template_key", template.getName()); - cfg.set("Settings.TNTDamage", false); - cfg.set("Settings.Fire", false); - cfg.set("Members", null); - try { - cfg.save(file); - } catch (IOException e) { - e.printStackTrace(); - System.err.println("Error while saving worldconfig for " + uuid.toString()); - } - } - - /** - * Add a permission to a player of this world - * - * @param player who is edited - * @param perm which permission will be added - * @return true if the permission was added, false if he already has the - * permission - */ - public boolean addPermission(UUID player, WorldPerm perm) { - if (owner.equals(player)) - throw new IllegalArgumentException("Permissions of the owner cannot change"); - HashSet perms = permissions.computeIfAbsent(player, k -> new HashSet<>()); - return perms.add(perm); - } - - /** - * Remove a permission from a player of this world - * - * @param player who is edited - * @param perm which permission will be removed - * @return true if the permission was removed, false if he doesn't have the - * permission - */ - public boolean removePermission(UUID player, WorldPerm perm) { - if (owner.equals(player)) - throw new IllegalArgumentException("Permissions of the owner cannot change"); - HashSet perms = permissions.get(player); - if (perms == null) { - return false; - } - return perms.remove(perm); - } - - /** - * Remove all permissions from a player of this world - * - * @param player who is edited - * @return true if a permission was removed false otherwise - */ - public boolean removeAllPermissions(UUID player) { - if (owner.equals(player)) - throw new IllegalArgumentException("Permissions of the owner cannot change"); - HashSet perms = permissions.remove(player); - return perms != null && perms.size() != 0; - } - - /** - * Add all permissions to a player of this world - * - * @param player who is edited - * @return true if the permissions of the player changed, false otherwiste - */ - public boolean addAllPermissions(UUID player) { - if (owner.equals(player)) - throw new IllegalArgumentException("Permissions of the owner cannot change"); - HashSet perms = permissions.computeIfAbsent(player, k -> new HashSet<>()); - return perms.addAll(Sets.newHashSet(WorldPerm.values())); - } - - /** - * Checks the permission of a player - * - * @param player who gets their permission checked - * @param perm to check - * @return true if the player has the permission, false otherwise - */ - public boolean hasPermission(UUID player, WorldPerm perm) { - if (owner.equals(player)) - return true; - HashSet perms = permissions.get(player); - return perms != null && perms.contains(perm); - } - - /** - * Get all permissions of a player - * - * @param player from who to get the permissions - * @return all permissions for this player - */ - public HashSet getPermissions(UUID player) { - if (owner == player) { - return Sets.newHashSet(WorldPerm.values()); - } - HashSet perms = permissions.get(player); - if (perms == null) { - return Sets.newHashSet(); - } - return Sets.newHashSet(perms); - } - - /** - * Adds a player to the world - * - * @param player who gets added - * @return true if the player was no member - */ - public boolean addMember(UUID player) { - return addPermission(player, WorldPerm.MEMBER); - } - - /** - * Try to add a player to the world - * - * @param player who's permission gets checked - * @param target to add to the world - * @return true if the player was successfully added - */ - public boolean addMember(UUID player, UUID target) { - if (hasPermission(player, WorldPerm.EDITMEMBERS)) { - return addMember(target); - } - return false; - } - - /** - * @return the owner of this world - */ - public UUID getOwner() { - return owner; - } - - /** - * Is the player a member of this world - * - * @param player to check - * @return if the player is a member of this world - */ - public boolean isMember(UUID player) { - return hasPermission(player, WorldPerm.MEMBER); - } - - /** - * Removes a Member from this world - * - * @param player to remove - * @return if the player was a member of this world - */ - public boolean removeMember(UUID player) { - return removeAllPermissions(player); - } - - /** - * Try to remove a Member from this world - * - * @param player who gets his permissions checked - * @param target to remove - * @return if the player was a member of this world - */ - public boolean removeMember(UUID player, UUID target) { - if (hasPermission(player, WorldPerm.EDITMEMBERS) && !hasPermission(player, WorldPerm.EDITMEMBERS)) { - return removeMember(target); - } - return false; - } - - /** - * Checks wheater a player can build or not - * - * @param player to check - * @return if the can build or not - */ - public boolean canBuild(UUID player) { - return hasPermission(player, WorldPerm.BUILD); - } - - /** - * Allow or disallow a player to build on this world - * - * @param player to edit - * @param allowed if he is allowed to build - */ - public void setBuild(UUID player, boolean allowed) { - if (allowed) { - addPermission(player, WorldPerm.BUILD); - } else { - removePermission(player, WorldPerm.BUILD); - } - } - - /** - * Allow or disallow a player to build with the permissions of a spefic - * player - * - * @param player who gets his permission checked - * @param target to allow or disallow - * @param allowed if he is allowed to build - * @return if the player has the permissions - */ - public boolean setBuild(UUID player, UUID target, boolean allowed) { - if (!isAllowedToAdministrateMember(player, target)) - return false; - setBuild(target, allowed); - return true; - } - - private boolean isAllowedToAdministrateMember(UUID player, UUID target) { - return target != owner && player != target && hasPermission(player, WorldPerm.ADMINISTRATEMEMBERS) - && hasPermission(player, WorldPerm.ADMINISTRATEMEMBERS); - } - - /** - * Checks wheater a player can build on this world or not - * - * @param player to check - * @return if the player can build - */ - public boolean canGamemode(UUID player) { - return hasPermission(player, WorldPerm.GAMEMODE); - } - - /** - * Allow or disallow a player to change his gamemode - * - * @param player to allow or disallow - * @param allowed if he is allowed to change his gamemode or not - */ - public void setGamemode(UUID player, boolean allowed) { - if (allowed) { - addPermission(player, WorldPerm.GAMEMODE); - } else { - removePermission(player, WorldPerm.GAMEMODE); - } - } - - public boolean setGamemode(UUID player, UUID target, boolean allowed) { - if (!isAllowedToAdministrateMember(player, target)) - return false; - setGamemode(target, allowed); - return true; - } - - public boolean canTeleport(UUID player) { - return hasPermission(player, WorldPerm.TELEPORT); - } - - /** - * Allow or disallow a player to teleport - * - * @param player to allow or disallow - * @param allowed if he is allowed to teleport or not - */ - public void setTeleport(UUID player, boolean allowed) { - if (allowed) { - addPermission(player, WorldPerm.TELEPORT); - } else { - removePermission(player, WorldPerm.TELEPORT); - } - } - - public boolean setTeleport(UUID player, UUID target, boolean allowed) { - if (!isAllowedToAdministrateMember(player, target)) - return false; - setTeleport(target, allowed); - return true; - } - - public HashSet getMembers() { - return Sets.newHashSet(permissions.keySet()); - } - - public HashMap getMembersWithNames() { - HashMap map = new HashMap<>(); - for (UUID uuid : permissions.keySet()) { - OfflinePlayer op = PlayerWrapper.getOfflinePlayer(uuid); - if (op == null || op.getName() == null) { - if (PluginConfig.contactAuth()) { - try { - GameProfile prof = GameProfileBuilder.fetch(uuid); - map.put(uuid, prof.getName()); - } catch (IOException e) { - e.printStackTrace(); - } - } - } else - map.put(uuid, op.getName()); - } - return map; - } - - public WorldConfig save() throws IOException { - File file = getWorldFile(getWorldName()); - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); - - cfg.set("Informations.ID", id); - cfg.set("Informations.Owner.Actualname", ownerName); - cfg.set("Informations.Owner.PlayerUUID", owner.toString()); - cfg.set("Informations.template_key", templateKey); - cfg.set("Settings.TNTDamage", tnt); - cfg.set("Settings.Fire", fire); - - if (home != null) { - cfg.set("Settings.home.x", home.getX()); - cfg.set("Settings.home.y", home.getY()); - cfg.set("Settings.home.z", home.getZ()); - cfg.set("Settings.home.yaw", home.getYaw()); - cfg.set("Settings.home.pitch", home.getPitch()); - } else { - cfg.set("Settings.home", null); - } - - cfg.set("Members", null); - - for (java.util.Map.Entry> entry : permissions.entrySet()) { - ArrayList array = new ArrayList<>(entry.getValue().size()); - for (WorldPerm perm : entry.getValue()) { - array.add(perm.name()); - } - cfg.set("Members." + entry.getKey(), array); - } - - cfg.save(file); - return this; - } - - private String getWorldName() { - return "ID" + id + "-" + owner; - } - - public WorldConfig load() { - File file = getWorldFile(getWorldName()); - permissions.clear(); - - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); - ownerName = cfg.getString("Informations.Owner.Actualname", "Unknown Playername"); - templateKey = cfg.getString("Informations.template_key"); - tnt = cfg.getBoolean("Settings.TNTDamage", true); - fire = cfg.getBoolean("Settings.Fire", true); - - if (cfg.isSet("Settings.home")) { - home = new Location(null, cfg.getDouble("Settings.home.x"), cfg.getDouble("Settings.home.y"), - cfg.getDouble("Settings.home.z"), (float) cfg.getDouble("Settings.home.yaw"), - (float) cfg.getDouble("Settings.home.pitch")); - } - - if (membersOldFormatted(cfg)) { - for (String s : cfg.getConfigurationSection("Members").getKeys(false)) { - HashSet perms = new HashSet<>(); - perms.add(WorldPerm.MEMBER); - if (cfg.getBoolean("Members." + s + ".Permissions.CanBuild")) - perms.add(WorldPerm.BUILD); - if (cfg.getBoolean("Members." + s + ".Permissions.CanTP")) - perms.add(WorldPerm.TELEPORT); - if (cfg.getBoolean("Members." + s + ".Permissions.CanBuild")) - perms.add(WorldPerm.GAMEMODE); - permissions.put(UUID.fromString(s), perms); - } - try { - save(); - } catch (IOException e) { - e.printStackTrace(); - } - } else { - ConfigurationSection section = cfg.getConfigurationSection("Members"); - if (section != null) { - for (String suuid : section.getKeys(false)) { - UUID uuid = UUID.fromString(suuid); - List list = section.getStringList(suuid); - HashSet perms = new HashSet<>(list.size()); - for (String perm : list) { - perms.add(WorldPerm.valueOf(perm)); - } - permissions.put(uuid, perms); - } - } - } - return this; - } - - private boolean membersOldFormatted(YamlConfiguration cfg) { - if (cfg.getConfigurationSection("Members") == null) - return false; - String name = cfg.getString( - "Members." + cfg.getConfigurationSection("Members").getKeys(false).iterator().next() + ".Actualname"); - return name != null; - } - - /** - * @return the home of the world. If not set returns null - */ - public Location getHome() { - if (home == null) - return null; - return new Location(Bukkit.getWorld(getWorldName()), home.getX(), home.getY(), home.getZ(), home.getYaw(), - home.getPitch()); - } - - /** - * @param loc the new home of the world - */ - /*public void setHome(Location loc) { - home = loc; - }*/ - - public String getOwnerName() { - return ownerName; - } - - public void setOwnerName(String ownerName) { - this.ownerName = ownerName; - } - - public boolean isFire() { - return fire; - } - - public void setFire(boolean fire) { - this.fire = fire; - } - - /** - * Allow or Disallow Fire Damage on this world - * - * @param player the player which toggles fire - * @param fire if fire is enabled - * @return if the player has the permissions to change the value - */ - public boolean setFire(UUID player, boolean fire) { - if (!hasPermission(player, WorldPerm.ADMINISTRATEWORLD)) - return false; - setFire(fire); - return true; - } - - public boolean isTnt() { - return tnt; - } - - public void setTnt(boolean tnt) { - this.tnt = tnt; - } - - /** - * Allow or Disallow TNT Damage on this world - * - * @param player which toggles tnt - * @param tnt if tnt is enabled - * @return if the player has the permissions to change the value - */ - public boolean setTnt(UUID player, boolean tnt) { - if (!hasPermission(player, WorldPerm.ADMINISTRATEWORLD)) - return false; - setTnt(tnt); - return true; - } - - /** - * Get the id of this world. The id is written in the filename at the xx - * position: 'IDxx-uuid.yml' - * - * @return id of this world - */ - public int getId() { - return id; - } - - public void setWorldEdit(UUID player, boolean allowed) { - if (allowed) { - addPermission(player, WorldPerm.WORLDEDIT); - } else { - removePermission(player, WorldPerm.WORLDEDIT); - } - } - - public boolean setWorldEdit(UUID player, UUID target, boolean allowed) { - if (!isAllowedToAdministrateMember(player, target)) { - return false; - } - setWorldEdit(target, allowed); - return true; - } - - public boolean canWorldEdit(UUID player) { - return hasPermission(player, WorldPerm.WORLDEDIT); - } - - public String getTemplateKey() { - return templateKey; - } - - public void setTemplateKey(String templateKey) { - this.templateKey = templateKey; - } -} diff --git a/src/main/java/de/butzlabben/world/config/WorldPerm.java b/src/main/java/de/butzlabben/world/config/WorldPerm.java deleted file mode 100644 index f14b3a8..0000000 --- a/src/main/java/de/butzlabben/world/config/WorldPerm.java +++ /dev/null @@ -1,23 +0,0 @@ -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; - } - -} diff --git a/src/main/java/de/butzlabben/world/data/objects/WorldSystemData.java b/src/main/java/de/butzlabben/world/data/objects/WorldSystemData.java index 9af4cef..79732a3 100644 --- a/src/main/java/de/butzlabben/world/data/objects/WorldSystemData.java +++ b/src/main/java/de/butzlabben/world/data/objects/WorldSystemData.java @@ -1,13 +1,13 @@ package de.butzlabben.world.data.objects; -import de.butzlabben.WorldSystem; -import de.butzlabben.world.data.WorldDatabase; +//import de.butzlabben.WorldSystem; +//import de.butzlabben.world.data.WorldDatabase; -import java.io.File; -import java.util.ArrayList; +//import java.io.File; +//import java.util.ArrayList; import java.util.HashMap; -import java.util.List; +//import java.util.List; import java.util.Map; public class WorldSystemData { diff --git a/src/main/java/de/butzlabben/world/event/WorldAddmemberEvent.java b/src/main/java/de/butzlabben/world/event/WorldAddmemberEvent.java deleted file mode 100644 index fc59de9..0000000 --- a/src/main/java/de/butzlabben/world/event/WorldAddmemberEvent.java +++ /dev/null @@ -1,52 +0,0 @@ -package de.butzlabben.world.event; - -import org.bukkit.entity.Player; -import org.bukkit.event.HandlerList; - -import java.util.UUID; - -/** - * Event for adding somebody to a world - * - * @author Butzlabben - * @since 09.05.2018 - */ -public class WorldAddmemberEvent extends WorldEvent { - - public final static HandlerList handlers = new HandlerList(); - 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; - } -} diff --git a/src/main/java/de/butzlabben/world/event/WorldCreateEvent.java b/src/main/java/de/butzlabben/world/event/WorldCreateEvent.java deleted file mode 100644 index adefb7a..0000000 --- a/src/main/java/de/butzlabben/world/event/WorldCreateEvent.java +++ /dev/null @@ -1,53 +0,0 @@ -package de.butzlabben.world.event; - -import org.bukkit.WorldCreator; -import org.bukkit.event.HandlerList; - -import java.util.UUID; - -/** - * 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 { - - public final static HandlerList handlers = new HandlerList(); - private final UUID owner; - private WorldCreator worldCreator; - - public WorldCreateEvent(UUID owner, WorldCreator creator) { - this.owner = owner; - this.setWorldCreator(creator); - } - - public final static HandlerList getHandlerList() { - return handlers; - } - - /** - * @return owner of world that gets created - */ - public UUID getOwner() { - return owner; - } - - @Override - public final HandlerList getHandlers() { - return handlers; - } - - /** - * @return the worldcreator which will be used - */ - public WorldCreator getWorldCreator() { - return 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 deleted file mode 100644 index c6c0563..0000000 --- a/src/main/java/de/butzlabben/world/event/WorldDeleteEvent.java +++ /dev/null @@ -1,47 +0,0 @@ -package de.butzlabben.world.event; - -import de.butzlabben.world.wrapper.SystemWorld; -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -/** - * Event if a systemworld gets deleted - * - * @author Butzlabben - * @since 09.05.2018 - */ -public class WorldDeleteEvent extends WorldEvent { - - 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 deleted file mode 100644 index a424cd0..0000000 --- a/src/main/java/de/butzlabben/world/event/WorldEvent.java +++ /dev/null @@ -1,27 +0,0 @@ -package de.butzlabben.world.event; - -import org.bukkit.event.Cancellable; -import org.bukkit.event.Event; - -public abstract class WorldEvent extends Event implements Cancellable { - - private boolean cancelled; - - public WorldEvent() { - } - - public WorldEvent(boolean cancel) { - setCancelled(cancel); - } - - @Override - public boolean isCancelled() { - return cancelled; - } - - @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 deleted file mode 100644 index 890c24f..0000000 --- a/src/main/java/de/butzlabben/world/event/WorldLoadEvent.java +++ /dev/null @@ -1,47 +0,0 @@ -package de.butzlabben.world.event; - -import de.butzlabben.world.wrapper.SystemWorld; -import org.bukkit.entity.Player; -import org.bukkit.event.HandlerList; - -/** - * Event for loading a world - * - * @author Butzlabben - * @since 09.05.2018 - */ -public class WorldLoadEvent extends WorldEvent { - - 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 static HandlerList getHandlerList() { - return handlers; - } - - /** - * @return get the world which will be loaded - */ - public SystemWorld getWorld() { - return world; - } - - /** - * @return get person which intiziated the loading - */ - public Player getOwner() { - return owner; - } - - @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 deleted file mode 100644 index 498739b..0000000 --- a/src/main/java/de/butzlabben/world/event/WorldRemovememberEvent.java +++ /dev/null @@ -1,50 +0,0 @@ -package de.butzlabben.world.event; - -import org.bukkit.entity.Player; -import org.bukkit.event.HandlerList; - -import java.util.UUID; - -/** - * @author Butzlabben - * @since 09.05.2018 - */ -public class WorldRemovememberEvent extends WorldEvent { - - 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; - } - - /** - * @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 deleted file mode 100644 index b7462b1..0000000 --- a/src/main/java/de/butzlabben/world/event/WorldResetEvent.java +++ /dev/null @@ -1,46 +0,0 @@ -package de.butzlabben.world.event; - -import de.butzlabben.world.wrapper.SystemWorld; -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -/** - * Event when a world gets reset - * - * @author Butzlabben - * @since 09.05.2018 - */ -public class WorldResetEvent extends WorldEvent { - - 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 deleted file mode 100644 index 8d581a0..0000000 --- a/src/main/java/de/butzlabben/world/event/WorldToggleFireEvent.java +++ /dev/null @@ -1,60 +0,0 @@ -package de.butzlabben.world.event; - -import de.butzlabben.world.wrapper.SystemWorld; -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -/** - * @author Butzlabben - * @since 09.05.2018 - */ -public class WorldToggleFireEvent extends WorldEvent { - - 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 deleted file mode 100644 index 1e51906..0000000 --- a/src/main/java/de/butzlabben/world/event/WorldToggleTntEvent.java +++ /dev/null @@ -1,61 +0,0 @@ -package de.butzlabben.world.event; - -import de.butzlabben.world.wrapper.SystemWorld; -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -/** - * @author Butzlabben - * @since 09.05.2018 - */ -public class WorldToggleTntEvent extends WorldEvent { - - 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 deleted file mode 100644 index 6455274..0000000 --- a/src/main/java/de/butzlabben/world/event/WorldUnloadEvent.java +++ /dev/null @@ -1,35 +0,0 @@ -package de.butzlabben.world.event; - -import de.butzlabben.world.wrapper.SystemWorld; -import org.bukkit.event.HandlerList; - -/** - * @author Butzlabben - * @since 09.05.2018 - */ -public class WorldUnloadEvent extends WorldEvent { - - 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 deleted file mode 100644 index 7db2dfe..0000000 --- a/src/main/java/de/butzlabben/world/gui/GuiCommand.java +++ /dev/null @@ -1,31 +0,0 @@ -package de.butzlabben.world.gui; - -import de.butzlabben.world.config.MessageConfig; -import de.butzlabben.world.wrapper.WorldPlayer; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -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; - } - -} diff --git a/src/main/java/de/butzlabben/world/gui/PlayerOptionsGUI.java b/src/main/java/de/butzlabben/world/gui/PlayerOptionsGUI.java deleted file mode 100644 index f5b9e55..0000000 --- a/src/main/java/de/butzlabben/world/gui/PlayerOptionsGUI.java +++ /dev/null @@ -1,73 +0,0 @@ -package de.butzlabben.world.gui; - -import de.butzlabben.inventory.DependListener; -import de.butzlabben.inventory.OrcInventory; -import de.butzlabben.inventory.OrcItem; -import de.butzlabben.world.config.GuiConfig; -import de.butzlabben.world.gui.clicklistener.ComingSoonClickListener; -import de.butzlabben.world.gui.clicklistener.CommandExecutorClickListener; -import de.butzlabben.world.gui.playeroption.BuildStatus; -import de.butzlabben.world.gui.playeroption.GamemodeStatus; -import de.butzlabben.world.gui.playeroption.TeleportStatus; -import de.butzlabben.world.gui.playeroption.WorldEditStatus; -import de.butzlabben.world.util.PlayerWrapper; -import de.butzlabben.world.wrapper.WorldPlayer; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -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(PlayerWrapper.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); - } - } - - 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 deleted file mode 100644 index 4039916..0000000 --- a/src/main/java/de/butzlabben/world/gui/PlayersPageGUI.java +++ /dev/null @@ -1,93 +0,0 @@ -package de.butzlabben.world.gui; - -import de.butzlabben.inventory.OrcItem; -import de.butzlabben.inventory.pages.PageGUICreator; -import de.butzlabben.world.config.GuiConfig; -import de.butzlabben.world.config.MessageConfig; -import de.butzlabben.world.config.WorldConfig; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.SkullMeta; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map.Entry; -import java.util.UUID; - -/** - * @author Butzlabben - * @since 20.04.2018 - */ -public class PlayersPageGUI { - - @SuppressWarnings("deprecation") - public static void openGUI(Player p) { - WorldConfig config = WorldConfig.getWorldConfig(p.getWorld().getName()); - - HashMap members = config.getMembersWithNames(); - - if (members.size() == 0) { - p.sendMessage(MessageConfig.getNoMemberAdded()); - return; - } - - PageGUICreator> creator = new PageGUICreator<>(GuiConfig.getRows("options.players")); - - creator.create(GuiConfig.getTitle(GuiConfig.getConfig(), "options.players"), members.entrySet(), (entry) -> { - String name = entry.getValue(); - OrcItem oi = new OrcItem(GuiConfig.getSkullItem(), GuiConfig - .getDisplay(GuiConfig.getConfig(), "options.players.playerhead").replaceAll("%player", name)); - SkullMeta sm = (SkullMeta) oi.getItemStack().getItemMeta(); - sm.setOwner(name); - oi.getItemStack().setItemMeta(sm); - oi.setOnClick((player, inv, item) -> { - player.closeInventory(); - PlayerOptionsGUI gui = new PlayerOptionsGUI(player, name, entry.getKey()); - player.openInventory(gui.getInventory(p)); - }); - return oi; - }); - - if (GuiConfig.isEnabled("options.players.back")) { - OrcItem back = OrcItem.back.clone(); - back.setOnClick((player, inv, i) -> { - player.closeInventory(); - player.openInventory(new WorldSystemGUI().getInventory(p)); - }); - creator.getInvPages().forEach((oi) -> { - oi.addItem(GuiConfig.getSlot("options.players.back"), back); - }); - } - - creator.show(p); - } - - @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()); - - 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/WorldChooseGUI.java b/src/main/java/de/butzlabben/world/gui/WorldChooseGUI.java deleted file mode 100644 index b521d6b..0000000 --- a/src/main/java/de/butzlabben/world/gui/WorldChooseGUI.java +++ /dev/null @@ -1,82 +0,0 @@ -package de.butzlabben.world.gui; - -import de.butzlabben.inventory.OrcClickListener; -import de.butzlabben.inventory.OrcInventory; -import de.butzlabben.inventory.OrcItem; -import de.butzlabben.world.config.GuiConfig; -import de.butzlabben.world.wrapper.WorldTemplate; -import de.butzlabben.world.wrapper.WorldTemplateProvider; -import org.bukkit.entity.Player; - -import java.util.function.Consumer; - -/** - * @author Butzlabben - * @since 15.12.2018 - */ -public class WorldChooseGUI extends OrcInventory { - - private final static String path = "worldchoose."; - - public WorldChooseGUI() { - this(null, null); - } - - public WorldChooseGUI(Player player) { - this(null, player); - } - - public WorldChooseGUI(Consumer onClick, Player player) { - super(GuiConfig.getTitle(GuiConfig.getConfig(), "worldchoose"), GuiConfig.getRows("worldchoose"), - GuiConfig.isFill("worldchoose")); - - for (WorldTemplate template : WorldTemplateProvider.getInstance().getTemplates()) { - // Check if player has permission to see template - if (template.getPermission() != null && !player.hasPermission(template.getPermission())) - continue; - - OrcItem icon = template.getIcon(); - if (onClick != null) - icon.setOnClick((p, inv, item) -> { - p.closeInventory(); - onClick.accept(template); - }); - int slot = template.getSlot(); - addItem(slot, icon); - } - - if (GuiConfig.isEnabled(path + "back")) { - OrcItem back = OrcItem.back.clone(); - back.setOnClick((p, inv, item) -> { - p.closeInventory(); - }); - addItem(GuiConfig.getSlot(path + "back"), back); - } - } - - public static void letChoose(Player player, Consumer template) { - player.openInventory(new WorldChooseGUI(template, player).getInventory(player)); - } - - public static void letChoose(Player player) { - player.openInventory(new WorldChooseGUI(player).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) { - loadItem(subpath, null); - } - - public boolean canOpen(Player p) { - return true; - } -} \ No newline at end of file diff --git a/src/main/java/de/butzlabben/world/gui/WorldOptionsGUI.java b/src/main/java/de/butzlabben/world/gui/WorldOptionsGUI.java deleted file mode 100644 index c1354a0..0000000 --- a/src/main/java/de/butzlabben/world/gui/WorldOptionsGUI.java +++ /dev/null @@ -1,98 +0,0 @@ -package de.butzlabben.world.gui; - -import de.butzlabben.inventory.DependListener; -import de.butzlabben.inventory.OrcInventory; -import de.butzlabben.inventory.OrcItem; -import de.butzlabben.world.config.GuiConfig; -import de.butzlabben.world.gui.clicklistener.ComingSoonClickListener; -import de.butzlabben.world.gui.clicklistener.CommandExecutorClickListener; -import de.butzlabben.world.gui.worldoption.FireStatus; -import de.butzlabben.world.gui.worldoption.TntStatus; -import de.butzlabben.world.wrapper.WorldPlayer; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; - -import java.util.HashMap; -import java.util.UUID; - -public class WorldOptionsGUI extends OrcInventory { - - public final static HashMap data = new HashMap<>(); - private final static String path = "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()); - - 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); - } - - 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) { - loadItem(subpath, message, state, null); - } - - 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) { - 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(); - } - -} diff --git a/src/main/java/de/butzlabben/world/gui/WorldSystemGUI.java b/src/main/java/de/butzlabben/world/gui/WorldSystemGUI.java deleted file mode 100644 index b2341dc..0000000 --- a/src/main/java/de/butzlabben/world/gui/WorldSystemGUI.java +++ /dev/null @@ -1,59 +0,0 @@ -package de.butzlabben.world.gui; - -import de.butzlabben.inventory.OrcClickListener; -import de.butzlabben.inventory.OrcInventory; -import de.butzlabben.inventory.OrcItem; -import de.butzlabben.world.config.GuiConfig; -import de.butzlabben.world.config.WorldConfig; -import de.butzlabben.world.gui.clicklistener.InventoryOpenClickListener; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; - -public class WorldSystemGUI extends OrcInventory { - - private final static String path = "worldsystem."; - - public WorldSystemGUI() { - - super(GuiConfig.getTitle(GuiConfig.getConfig(), "worldsystem"), GuiConfig.getRows("worldsystem"), GuiConfig.isFill("worldsystem")); - - loadItem("playeroptions", (p, inv, item) -> { - p.closeInventory(); - PlayersPageGUI.openGUI(p); - }); - - loadItem("worldoptions", new InventoryOpenClickListener(new WorldOptionsGUI())); - - if (GuiConfig.isEnabled(path + "back")) { - OrcItem back = OrcItem.back.clone(); - back.setOnClick((p, inv, item) -> { - p.closeInventory(); - }); - addItem(GuiConfig.getSlot(path + "back"), back); - } - } - - @Override - public Inventory getInventory(Player player) { - PlayersPageGUI.preloadPlayers(WorldConfig.getWorldConfig(player.getWorld().getName())); - return super.getInventory(player); - } - - public void loadItem(String subpath, OrcClickListener listener) { - 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 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 deleted file mode 100644 index ef59b4f..0000000 --- a/src/main/java/de/butzlabben/world/gui/clicklistener/ComingSoonClickListener.java +++ /dev/null @@ -1,16 +0,0 @@ -package de.butzlabben.world.gui.clicklistener; - -import de.butzlabben.inventory.OrcClickListener; -import de.butzlabben.inventory.OrcInventory; -import de.butzlabben.inventory.OrcItem; -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..."); - } - -} diff --git a/src/main/java/de/butzlabben/world/gui/clicklistener/CommandExecutorClickListener.java b/src/main/java/de/butzlabben/world/gui/clicklistener/CommandExecutorClickListener.java deleted file mode 100644 index 2bfe1f4..0000000 --- a/src/main/java/de/butzlabben/world/gui/clicklistener/CommandExecutorClickListener.java +++ /dev/null @@ -1,23 +0,0 @@ -package de.butzlabben.world.gui.clicklistener; - -import de.butzlabben.inventory.OrcClickListener; -import de.butzlabben.inventory.OrcInventory; -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(); - p.chat(message); - // 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 deleted file mode 100644 index e9a5604..0000000 --- a/src/main/java/de/butzlabben/world/gui/clicklistener/InventoryOpenClickListener.java +++ /dev/null @@ -1,33 +0,0 @@ -package de.butzlabben.world.gui.clicklistener; - -import de.butzlabben.inventory.OrcClickListener; -import de.butzlabben.inventory.OrcInventory; -import de.butzlabben.inventory.OrcItem; -import de.butzlabben.world.config.MessageConfig; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; - -public class InventoryOpenClickListener implements OrcClickListener { - - private final OrcInventory open; - - 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()); - } - } - -} diff --git a/src/main/java/de/butzlabben/world/gui/playeroption/BuildStatus.java b/src/main/java/de/butzlabben/world/gui/playeroption/BuildStatus.java deleted file mode 100644 index 72230ed..0000000 --- a/src/main/java/de/butzlabben/world/gui/playeroption/BuildStatus.java +++ /dev/null @@ -1,21 +0,0 @@ -package de.butzlabben.world.gui.playeroption; - -import de.butzlabben.inventory.DependListener; -import de.butzlabben.inventory.OrcItem; -import de.butzlabben.world.wrapper.WorldPlayer; -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; - } - - @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 deleted file mode 100644 index 5e2006f..0000000 --- a/src/main/java/de/butzlabben/world/gui/playeroption/GamemodeStatus.java +++ /dev/null @@ -1,21 +0,0 @@ -package de.butzlabben.world.gui.playeroption; - -import de.butzlabben.inventory.DependListener; -import de.butzlabben.inventory.OrcItem; -import de.butzlabben.world.wrapper.WorldPlayer; -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; - } - - @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 deleted file mode 100644 index 6041b6b..0000000 --- a/src/main/java/de/butzlabben/world/gui/playeroption/TeleportStatus.java +++ /dev/null @@ -1,21 +0,0 @@ -package de.butzlabben.world.gui.playeroption; - -import de.butzlabben.inventory.DependListener; -import de.butzlabben.inventory.OrcItem; -import de.butzlabben.world.wrapper.WorldPlayer; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -public class TeleportStatus implements DependListener { - - private final WorldPlayer 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); - } -} \ No newline at end of file diff --git a/src/main/java/de/butzlabben/world/gui/playeroption/WorldEditStatus.java b/src/main/java/de/butzlabben/world/gui/playeroption/WorldEditStatus.java deleted file mode 100644 index a6e42ed..0000000 --- a/src/main/java/de/butzlabben/world/gui/playeroption/WorldEditStatus.java +++ /dev/null @@ -1,20 +0,0 @@ -package de.butzlabben.world.gui.playeroption; - -import de.butzlabben.inventory.DependListener; -import de.butzlabben.inventory.OrcItem; -import de.butzlabben.world.wrapper.WorldPlayer; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -public class WorldEditStatus - implements DependListener { - private final WorldPlayer wp; - - public WorldEditStatus(WorldPlayer wp) { - this.wp = wp; - } - - public ItemStack getItemStack(Player p, WorldPlayer player) { - return this.wp.canWorldedit() ? OrcItem.enabled.getItemStack(p, this.wp) : OrcItem.disabled.getItemStack(p, this.wp); - } -} diff --git a/src/main/java/de/butzlabben/world/gui/worldoption/FireStatus.java b/src/main/java/de/butzlabben/world/gui/worldoption/FireStatus.java deleted file mode 100644 index 3afe164..0000000 --- a/src/main/java/de/butzlabben/world/gui/worldoption/FireStatus.java +++ /dev/null @@ -1,32 +0,0 @@ -package de.butzlabben.world.gui.worldoption; - -import de.butzlabben.inventory.DependListener; -import de.butzlabben.inventory.OrcItem; -import de.butzlabben.world.config.DependenceConfig; -import de.butzlabben.world.config.PluginConfig; -import de.butzlabben.world.wrapper.WorldPlayer; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -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); - - 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 deleted file mode 100644 index 15b3a23..0000000 --- a/src/main/java/de/butzlabben/world/gui/worldoption/TntStatus.java +++ /dev/null @@ -1,32 +0,0 @@ -package de.butzlabben.world.gui.worldoption; - -import de.butzlabben.inventory.DependListener; -import de.butzlabben.inventory.OrcItem; -import de.butzlabben.world.config.DependenceConfig; -import de.butzlabben.world.config.PluginConfig; -import de.butzlabben.world.wrapper.WorldPlayer; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -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); - - return null; - } - -} diff --git a/src/main/java/de/butzlabben/world/listener/BlockListener.java b/src/main/java/de/butzlabben/world/listener/BlockListener.java deleted file mode 100644 index 654ee4c..0000000 --- a/src/main/java/de/butzlabben/world/listener/BlockListener.java +++ /dev/null @@ -1,94 +0,0 @@ -package de.butzlabben.world.listener; - -import de.butzlabben.world.config.WorldConfig; -import de.butzlabben.world.wrapper.WorldPlayer; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockBurnEvent; -import org.bukkit.event.block.BlockIgniteEvent; -import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.entity.EntityExplodeEvent; -import org.bukkit.event.player.PlayerBucketEmptyEvent; - -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 onPlaceLiquid(PlayerBucketEmptyEvent 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 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/CommandListener.java b/src/main/java/de/butzlabben/world/listener/CommandListener.java deleted file mode 100644 index 8b5dafb..0000000 --- a/src/main/java/de/butzlabben/world/listener/CommandListener.java +++ /dev/null @@ -1,158 +0,0 @@ -package de.butzlabben.world.listener; - -import de.butzlabben.world.config.MessageConfig; -import de.butzlabben.world.config.PluginConfig; -import de.butzlabben.world.config.WorldConfig; -import de.butzlabben.world.util.PlayerPositions; -import de.butzlabben.world.wrapper.SystemWorld; -import de.butzlabben.world.wrapper.WorldPlayer; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.player.PlayerTeleportEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; - -public class CommandListener implements Listener { - - @EventHandler(priority = EventPriority.HIGH) - public void onTeleport(PlayerTeleportEvent e) { - Player p = e.getPlayer(); - World from = e.getFrom().getWorld(); - World to = e.getTo().getWorld(); - boolean fromIsSystemWorld = WorldConfig.exists(from.getName()); - boolean toIsSystemWorld = WorldConfig.exists(to.getName()); - WorldPlayer wp = new WorldPlayer(p); - - if (from != to) - SystemWorld.tryUnloadLater(from); - - if (e.getCause() == TeleportCause.SPECTATE) { - if (from != to && toIsSystemWorld) { - if (!p.hasPermission("ws.tp.toother")) { - e.setCancelled(true); - p.sendMessage(MessageConfig.getNoPermission()); - return; - } - } - - if (!wp.isOnSystemWorld() || wp.isOwnerofWorld() || wp.canTeleport() || p.hasPermission("ws.tp.toother")) - return; - - e.setCancelled(true); - p.sendMessage(MessageConfig.getNoPermission()); - } else if (e.getCause() == TeleportCause.COMMAND) { - if (from != to && toIsSystemWorld) { - if (!p.hasPermission("ws.tp.toother")) { - e.setCancelled(true); - p.sendMessage(MessageConfig.getNoPermission()); - return; - } - } - - if (!wp.isOnSystemWorld() || wp.isOwnerofWorld() || wp.canTeleport() || p.hasPermission("ws.tp.toother")) - return; - - e.setCancelled(true); - p.sendMessage(MessageConfig.getNoPermission()); - } - - // Fix for #18 - if (from != to || fromIsSystemWorld) { - // Save location for #23 - if (fromIsSystemWorld) { - WorldConfig config = WorldConfig.getWorldConfig(from.getName()); - PlayerPositions.instance.saveWorldsPlayerLocation(p, config); - } else { - if (toIsSystemWorld) - PlayerPositions.instance.savePlayerLocation(p); - } - GameMode gameMode = PluginConfig.getSpawnGamemode(); - if (toIsSystemWorld) { - if (PluginConfig.isSurvival()) { - gameMode = GameMode.SURVIVAL; - } else { - gameMode = GameMode.CREATIVE; - } - } - - p.setGameMode(gameMode); - } - } - - @EventHandler(priority = EventPriority.HIGH) - public void onCmd(PlayerCommandPreprocessEvent e) { - String cmd = e.getMessage().toLowerCase(); - Player p = e.getPlayer(); - WorldPlayer wp = new WorldPlayer(p); - - if (!wp.isOnSystemWorld()) - return; - - if (cmd.startsWith("/gamemode") || cmd.startsWith("/gm")) { - if (!wp.isOnSystemWorld()) - return; - if (p.hasPermission("ws.gamemode")) - return; - if (PluginConfig.isSurvival()) { - e.setCancelled(true); - p.sendMessage(MessageConfig.getNoPermission()); - return; - } - - if (!wp.canChangeGamemode() && !wp.isOwnerofWorld()) { - p.sendMessage(MessageConfig.getNoPermission()); - e.setCancelled(true); - } - } else if (cmd.startsWith("/tp") || cmd.startsWith("/teleport")) { - String[] args = e.getMessage().split(" "); - if (args.length == 2) { - if (p.hasPermission("ws.tp.toother")) - return; - if (PluginConfig.isSurvival()) { - e.setCancelled(true); - p.sendMessage(MessageConfig.getNoPermission()); - return; - } - Player a = Bukkit.getPlayer(args[1]); - if (a == null) - return; - if (p.getWorld() != a.getWorld()) { - e.setCancelled(true); - p.sendMessage(MessageConfig.getNoPermission()); - return; - } - if (wp.isOwnerofWorld()) - return; - if (!wp.canTeleport()) { - p.sendMessage(MessageConfig.getNoPermission()); - e.setCancelled(true); - } - } else if (args.length == 3) { - if (!p.hasPermission("ws.tp.other")) { - p.sendMessage(MessageConfig.getNoPermission()); - e.setCancelled(true); - } - - } else if (args.length == 4) { - if (p.hasPermission("ws.tp.toother")) - return; - if (PluginConfig.isSurvival()) { - e.setCancelled(true); - p.sendMessage(MessageConfig.getNoPermission()); - return; - } - if (wp.isOwnerofWorld()) - return; - if (!wp.canTeleport()) { - p.sendMessage(MessageConfig.getNoPermission()); - e.setCancelled(true); - } - } - } - } -} diff --git a/src/main/java/de/butzlabben/world/listener/PlayerListener.java b/src/main/java/de/butzlabben/world/listener/PlayerListener.java deleted file mode 100644 index b72ca99..0000000 --- a/src/main/java/de/butzlabben/world/listener/PlayerListener.java +++ /dev/null @@ -1,86 +0,0 @@ -package de.butzlabben.world.listener; - -import de.butzlabben.world.config.DependenceConfig; -import de.butzlabben.world.config.PluginConfig; -import de.butzlabben.world.config.WorldConfig; -import de.butzlabben.world.util.PlayerPositions; -import de.butzlabben.world.util.PlayerWrapper; -import de.butzlabben.world.wrapper.SystemWorld; -import de.butzlabben.world.wrapper.WorldPlayer; -import java.util.HashMap; -import java.util.UUID; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.player.PlayerRespawnEvent; - -public class PlayerListener implements Listener { - - private final HashMap deathLocations = new HashMap<>(); - - //#17 - @EventHandler(priority = EventPriority.HIGHEST) - public void onJoin(PlayerJoinEvent e) { - PlayerWrapper.updateDatabase(e.getPlayer()); - 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 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()); - - 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()); - } - } - } - } - -} \ 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 deleted file mode 100644 index 10900ee..0000000 --- a/src/main/java/de/butzlabben/world/listener/WorldEditListener.java +++ /dev/null @@ -1,71 +0,0 @@ -package de.butzlabben.world.listener; - -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.command.SimpleCommandMap; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -public class WorldEditListener implements Listener { - - private final List worldEditCommands= new ArrayList<>(); - - public WorldEditListener() { - try { - String packageName = Bukkit.getServer().getClass().getPackage().getName(); - String version = packageName.substring(packageName.lastIndexOf(".") + 1); - Class serverClass = Class.forName("org.bukkit.craftbukkit." + version + ".CraftServer"); - - Field f1 = serverClass.getDeclaredField("commandMap"); - f1.setAccessible(true); - SimpleCommandMap commandMap = (SimpleCommandMap) f1.get(Bukkit.getServer()); - - Field f2 = SimpleCommandMap.class.getDeclaredField("knownCommands"); - f2.setAccessible(true); - @SuppressWarnings({"unchecked", "rawtypes"}) - Map knownCommands = (Map) f2.get(commandMap); - worldEditCommands.addAll(knownCommands.entrySet().stream().filter(entry -> entry.getKey().contains("worldedit")) - .map(entry -> entry.getValue().getName()).collect(Collectors.toList())); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @EventHandler - public void playerCommandHandler(PlayerCommandPreprocessEvent event) { - String command = event.getMessage().split(" ")[0]; - if (!isWorldEditCommand(command)) { - return; - } - Player p = event.getPlayer(); - String worldname = p.getWorld().getName(); - WorldPlayer wp = new WorldPlayer(p, worldname); - if (wp.isOnSystemWorld() && - !wp.isOwnerofWorld() && !p.hasPermission(WorldPerm.WORLDEDIT.getOpPerm())) { - WorldConfig wc = WorldConfig.getWorldConfig(p.getWorld().getName()); - if (!wc.hasPermission(p.getUniqueId(), WorldPerm.WORLDEDIT)) { - p.sendMessage(MessageConfig.getNoPermission()); - event.setCancelled(true); - } - } - } - - private boolean isWorldEditCommand(String command) { - System.out.println(command); - return worldEditCommands.contains(command) - || worldEditCommands.contains(command.replaceFirst("/", "")) - || worldEditCommands.contains(command.replaceFirst("/worldedit:", "")); - } -} diff --git a/src/main/java/de/butzlabben/world/listener/WorldInitSkipSpawn.java b/src/main/java/de/butzlabben/world/listener/WorldInitSkipSpawn.java deleted file mode 100644 index 427fccb..0000000 --- a/src/main/java/de/butzlabben/world/listener/WorldInitSkipSpawn.java +++ /dev/null @@ -1,23 +0,0 @@ -package de.butzlabben.world.listener; - -import de.butzlabben.world.config.SettingsConfig; -import de.butzlabben.world.wrapper.SystemWorld; -import org.bukkit.World; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.world.WorldInitEvent; - -public class WorldInitSkipSpawn implements Listener { - - @EventHandler - public void worldInit(WorldInitEvent e) { - World world = e.getWorld(); - SystemWorld sw = SystemWorld.getSystemWorld(world.getName()); - if(sw == null) - return; - - SettingsConfig.editWorld(world); - e.getWorld().setKeepSpawnInMemory(false); - } - -} diff --git a/src/main/java/de/butzlabben/world/util/MoneyUtil.java b/src/main/java/de/butzlabben/world/util/MoneyUtil.java deleted file mode 100644 index 973c7f9..0000000 --- a/src/main/java/de/butzlabben/world/util/MoneyUtil.java +++ /dev/null @@ -1,59 +0,0 @@ -package de.butzlabben.world.util; - -import com.google.common.base.Preconditions; -import de.butzlabben.world.config.PluginConfig; -import net.milkbowl.vault.economy.Economy; -import net.milkbowl.vault.economy.EconomyResponse; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.plugin.RegisteredServiceProvider; - -import java.util.UUID; - -/** - * Little util class for dealing with money with vault - * Used for #15 - */ -public class MoneyUtil { - private static Object economy = null; - - static { - if (Bukkit.getPluginManager().getPlugin("Vault") != null) { - try { - RegisteredServiceProvider service = Bukkit.getServicesManager().getRegistration(Economy.class); - if (service != null) - economy = service.getProvider(); - } catch (Exception ignored) { - } - - } - - if (economy == null) - 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); - Preconditions.checkArgument(money > 0, "Money must not be negative"); - OfflinePlayer op = PlayerWrapper.getOfflinePlayer(uuid); - Economy economy = (Economy) MoneyUtil.economy; - EconomyResponse response = economy.withdrawPlayer(op, money); - if (!response.transactionSuccess()) { - Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "§cTransaction failure for removing " + money + " from " + op.getName()); - Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "§cError message: " + response.errorMessage); - } - } - - public static boolean hasMoney(UUID uuid, int money) { - Preconditions.checkNotNull(uuid); - Preconditions.checkNotNull(economy); - Preconditions.checkArgument(money > 0, "Money must not be negative"); - OfflinePlayer op = PlayerWrapper.getOfflinePlayer(uuid); - Economy economy = (Economy) MoneyUtil.economy; - return economy.getBalance(op) >= money; - } -} diff --git a/src/main/java/de/butzlabben/world/util/PapiExtension.java b/src/main/java/de/butzlabben/world/util/PapiExtension.java deleted file mode 100644 index c18ce88..0000000 --- a/src/main/java/de/butzlabben/world/util/PapiExtension.java +++ /dev/null @@ -1,74 +0,0 @@ -package de.butzlabben.world.util; - -import de.butzlabben.WorldSystem; -import de.butzlabben.world.config.DependenceConfig; -import de.butzlabben.world.config.WorldConfig; -import de.butzlabben.world.wrapper.SystemWorld; -import de.butzlabben.world.wrapper.WorldPlayer; -import me.clip.placeholderapi.expansion.PlaceholderExpansion; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.World; -import org.bukkit.entity.Player; - -import java.util.Objects; - -public class PapiExtension extends PlaceholderExpansion { - - private final WorldSystem worldSystem = WorldSystem.getInstance(); - - @Override - public String getIdentifier() { - return "worldsystem"; - } - - @Override - public String getAuthor() { - return "Butzlabben"; - } - - @Override - public String getVersion() { - return worldSystem.getDescription().getVersion(); - } - - @Override - public String onRequest(OfflinePlayer p, String params) { - DependenceConfig config = new DependenceConfig(p); - switch (params) { - case "has_world": - return new DependenceConfig(p).hasWorld() + ""; - case "is_creator": - WorldPlayer player = new WorldPlayer(Objects.requireNonNull(Bukkit.getPlayer(p.getUniqueId()))); - if (!player.isOnSystemWorld()) - return "false"; - return player.isOwnerofWorld() + ""; - case "world_name_of_player": - if (!config.hasWorld()) - return "none"; - else - return config.getWorldname(); - case "world_of_player_loaded": - if (!config.hasWorld()) - return "none"; - return SystemWorld.getSystemWorld(config.getWorldname()).isLoaded() + ""; - case "pretty_world_name": - if (!p.isOnline()) { - if (!config.hasWorld()) { - Player p1 = p.getPlayer(); - if (p1 != null && p1.isOnline()) - return p1.getLocation().getWorld().getName(); - return "none"; - } - return config.getOwner().getName(); - } else { - World world = ((Player) p).getWorld(); - if (WorldConfig.exists(world.getName())) - return WorldConfig.getWorldConfig(world.getName()).getOwnerName(); - return world.getName(); - } - default: - throw new IllegalArgumentException("No placeholder named\"" + getIdentifier() + "_" + params + "\" is known"); - } - } -} diff --git a/src/main/java/de/butzlabben/world/util/PlayerPositions.java b/src/main/java/de/butzlabben/world/util/PlayerPositions.java deleted file mode 100644 index 1e0699c..0000000 --- a/src/main/java/de/butzlabben/world/util/PlayerPositions.java +++ /dev/null @@ -1,218 +0,0 @@ -package de.butzlabben.world.util; - -import com.google.common.base.Preconditions; -import de.butzlabben.world.config.PluginConfig; -import de.butzlabben.world.config.WorldConfig; -import de.butzlabben.world.util.database.DatabaseProvider; -import de.butzlabben.world.util.database.DatabaseUtil; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.UUID; -import lombok.Getter; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.entity.Player; - -/* -Class for implementing #23 - */ -public class PlayerPositions { - - @Getter - public static PlayerPositions instance = new PlayerPositions(); - - private final DatabaseUtil util = DatabaseProvider.instance.util; - - - private PlayerPositions() { - checkTables(); - } - - public Location injectWorldsLocation(Player player, WorldConfig config, Location location) { - if (!PluginConfig.useWorldSpawnLastLocation()) - return location; - if (!util.isConnectionAvailable()) - return location; - - Preconditions.checkNotNull(player); - Preconditions.checkNotNull(config); - Preconditions.checkNotNull(location); - UUID uuid = player.getUniqueId(); - int id = config.getId(); - UUID owner = config.getOwner(); - String tableName = PluginConfig.getWorldsTableName(); - - try { - PreparedStatement ps = util.prepareStatement("SELECT * FROM " + tableName + " WHERE player=? AND id=? AND owner=?"); - - ps.setString(1, uuid.toString()); - ps.setInt(2, id); - ps.setString(3, owner.toString()); - ResultSet rs = util.executeQuery(ps); - if (!rs.next()) - return location; - - double x = rs.getDouble("x"); - double y = rs.getDouble("y"); - double z = rs.getDouble("z"); - - location.setX(x); - location.setY(y); - location.setZ(z); - } catch (SQLException e) { - e.printStackTrace(); - } - return location; - } - - public Location injectPlayersLocation(Player player, Location location) { - if (!PluginConfig.useSpawnLastLocation()) - return location; - if (!util.isConnectionAvailable()) - return location; - if (player == null) - return location; - Preconditions.checkNotNull(location); - UUID uuid = player.getUniqueId(); - - String tableName = PluginConfig.getPlayersTableName(); - - try { - PreparedStatement ps = util.prepareStatement("SELECT * FROM " + tableName + " WHERE player=?"); - - ps.setString(1, uuid.toString()); - ResultSet rs = util.executeQuery(ps); - if (!rs.next()) - return location; - - double x = rs.getDouble("x"); - double y = rs.getDouble("y"); - double z = rs.getDouble("z"); - - location.setX(x); - location.setY(y); - location.setZ(z); - - World locationWorld = location.getWorld(); - if (locationWorld == null || !locationWorld.getName().equals(rs.getString("world"))) { - World world = Bukkit.getWorld(rs.getString("world")); - if (world != null) { - location.setWorld(world); - } - } - } catch (SQLException e) { - e.printStackTrace(); - } - return location; - } - - public void savePlayerLocation(Player player) { - if (!PluginConfig.useSpawnLastLocation()) - return; - if (!util.isConnectionAvailable()) - return; - - Preconditions.checkNotNull(player); - - String playersTableName = PluginConfig.getPlayersTableName(); - - UUID uuid = player.getUniqueId(); - Location location = player.getLocation(); - try { - PreparedStatement ps = util.prepareStatement("REPLACE INTO " + playersTableName + - " (player, world, x, y, z) VALUES (?, ?, ?, ?, ?)"); - - ps.setString(1, uuid.toString()); - ps.setString(2, location.getWorld().getName()); - - ps.setDouble(3, location.getX()); - ps.setDouble(4, location.getY()); - ps.setDouble(5, location.getZ()); - - util.executeUpdate(ps); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - public void saveWorldsPlayerLocation(Player player, WorldConfig config) { - if (!PluginConfig.useWorldSpawnLastLocation()) - return; - if (!util.isConnectionAvailable()) - return; - - Preconditions.checkNotNull(player); - Preconditions.checkNotNull(config); - UUID uuid = player.getUniqueId(); - int id = config.getId(); - UUID owner = config.getOwner(); - Location location = player.getLocation(); - String tableName = PluginConfig.getWorldsTableName(); - try { - PreparedStatement ps = util.prepareStatement("REPLACE INTO " + tableName + - " (player, id, owner, x, y, z) VALUES (?, ?, ?, ?, ?, ?)"); - - ps.setString(1, uuid.toString()); - ps.setInt(2, id); - ps.setString(3, owner.toString()); - ps.setDouble(4, location.getX()); - ps.setDouble(5, location.getY()); - ps.setDouble(6, location.getZ()); - - util.executeUpdate(ps); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - public void deletePositions(WorldConfig config) { - Preconditions.checkNotNull(config); - if (!util.isConnectionAvailable()) - return; - - String tableName = PluginConfig.getWorldsTableName(); - - int id = config.getId(); - UUID owner = config.getOwner(); - try { - PreparedStatement ps = util.prepareStatement("DELETE FROM " + tableName + - " WHERE id=? AND owner=?"); - - ps.setInt(1, id); - ps.setString(2, owner.toString()); - - util.executeUpdate(ps); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - public void checkTables() { - if (!util.isConnectionAvailable()) - return; - - String worldsTableName = PluginConfig.getWorldsTableName(); - try { - PreparedStatement ps = util.prepareStatement("CREATE TABLE IF NOT EXISTS " + worldsTableName + - " ( `player` VARCHAR(36) NOT NULL , `id` INT NOT NULL , `owner` VARCHAR(36) NOT NULL , " + - "`x` DOUBLE NOT NULL , `y` DOUBLE NOT NULL , `z` DOUBLE NOT NULL , PRIMARY KEY (`player`, `id`, `owner`))"); - - util.executeUpdate(ps); - } catch (SQLException e) { - e.printStackTrace(); - } - - String playersTableName = PluginConfig.getPlayersTableName(); - try { - PreparedStatement ps = util.prepareStatement("CREATE TABLE IF NOT EXISTS " + playersTableName + - "( `player` VARCHAR(36) NOT NULL , `world` TEXT NOT NULL , " + - "`x` DOUBLE NOT NULL , `y` DOUBLE NOT NULL , `z` DOUBLE NOT NULL , PRIMARY KEY (`player`))"); - - util.executeUpdate(ps); - } catch (SQLException e) { - e.printStackTrace(); - } - } -} diff --git a/src/main/java/de/butzlabben/world/util/PlayerWrapper.java b/src/main/java/de/butzlabben/world/util/PlayerWrapper.java deleted file mode 100644 index 10f1fec..0000000 --- a/src/main/java/de/butzlabben/world/util/PlayerWrapper.java +++ /dev/null @@ -1,98 +0,0 @@ -package de.butzlabben.world.util; - -import com.google.common.base.Preconditions; -import com.sk89q.worldedit.bukkit.BukkitPlayer; -import de.butzlabben.world.config.PluginConfig; -import de.butzlabben.world.util.database.DatabaseProvider; -import de.butzlabben.world.util.database.DatabaseUtil; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; - -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.UUID; - -public class PlayerWrapper { - - - private static final DatabaseUtil util = DatabaseProvider.instance.util; - - static { - checkTables(); - } - - public static void checkTables() { - if (!util.isConnectionAvailable()) - return; - - String uuidTableName = PluginConfig.getUUIDTableName(); - try { - PreparedStatement ps = util.prepareStatement("CREATE TABLE IF NOT EXISTS " + uuidTableName + - " ( `uuid` VARCHAR(36) NOT NULL , `name` VARCHAR(36) NOT NULL , " + - " PRIMARY KEY (`name`))"); - - util.executeUpdate(ps); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - public static void updateDatabase(Player player) { - if (!util.isConnectionAvailable()) - return; - - Preconditions.checkNotNull(player); - String uuidTableName = PluginConfig.getUUIDTableName(); - - try { - PreparedStatement ps = util.prepareStatement("REPLACE INTO " + uuidTableName + - " (uuid, name) VALUES (?, ?)"); - ps.setString(1, player.getUniqueId().toString()); - ps.setString(2, player.getName()); - - util.executeUpdate(ps); - } catch (SQLException e) { - e.printStackTrace(); - } - - } - - private static UUID getUUID(String name) { - String uuidTableName = PluginConfig.getUUIDTableName(); - - try { - PreparedStatement ps = util.prepareStatement("SELECT * FROM " + uuidTableName + " WHERE name=?"); - - ps.setString(1, name); - ResultSet rs = util.executeQuery(ps); - if (!rs.next()) - return null; - - return UUID.fromString(rs.getString("uuid")); - - } catch (SQLException e) { - e.printStackTrace(); - } - return null; - } - - public static OfflinePlayer getOfflinePlayer(String name) { - Player player = Bukkit.getPlayer(name); - if(player != null) - return Bukkit.getOfflinePlayer(player.getUniqueId()); - - UUID uuid = PlayerWrapper.getUUID(name); - if(uuid != null) - return Bukkit.getOfflinePlayer(uuid); - - return Bukkit.getOfflinePlayer(name); - } - - public static OfflinePlayer getOfflinePlayer(UUID uuid) { - return Bukkit.getOfflinePlayer(uuid); - } - - -} diff --git a/src/main/java/de/butzlabben/world/util/TeleportUtil.java b/src/main/java/de/butzlabben/world/util/TeleportUtil.java deleted file mode 100644 index 14c22d7..0000000 --- a/src/main/java/de/butzlabben/world/util/TeleportUtil.java +++ /dev/null @@ -1,29 +0,0 @@ -package de.butzlabben.world.util; - -import org.bukkit.Location; -import org.bukkit.entity.Player; - -import java.util.HashMap; -import java.util.UUID; - -/** - * @author Butzlabben - * @since 13.09.2018 - */ -public class 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 deleted file mode 100644 index ca45b78..0000000 --- a/src/main/java/de/butzlabben/world/util/VersionUtil.java +++ /dev/null @@ -1,69 +0,0 @@ -package de.butzlabben.world.util; - -import org.bukkit.Bukkit; -import org.bukkit.scheduler.BukkitTask; - -/** - * @author Butzlabben - * @since 14.08.2018 - */ -public class VersionUtil { - - private static int version; - - private VersionUtil() { - } - - public static int getVersion() { - if (version == 0) { - // Detect version - String v = Bukkit.getVersion(); - if (v.contains("1.19")) - version = 19; - else if (v.contains("1.18")) - version = 18; - else if (v.contains("1.17")) - version = 17; - else if (v.contains("1.16")) - version = 16; - else if (v.contains("1.15")) - version = 15; - else if (v.contains("1.14")) - version = 14; - else if (v.contains("1.13")) - version = 13; - else if (v.contains("1.12")) - version = 12; - else if (v.contains("1.11")) - version = 11; - else if (v.contains("1.10")) - version = 10; - else if (v.contains("1.9")) - version = 9; - else if (v.contains("1.8")) - version = 8; - else if (v.contains("1.7")) - version = 7; - else if (v.contains("1.6")) - version = 6; - else if (v.contains("1.5")) - version = 5; - else if (v.contains("1.4")) - version = 4; - else if (v.contains("1.3")) - version = 3; - } - if (version == 0) { - System.err.println("[WorldSystem] Unknown version: " + Bukkit.getVersion()); - System.err.println("[WorldSystem] Choosing version 1.12.2"); - version = 12; - } - return version; - } - - public static boolean isCancelled(BukkitTask task) { - if (getVersion() <= 12) - return false; - return task.isCancelled(); - } -} diff --git a/src/main/java/de/butzlabben/world/util/Worldutils.java b/src/main/java/de/butzlabben/world/util/Worldutils.java deleted file mode 100644 index 75ceefc..0000000 --- a/src/main/java/de/butzlabben/world/util/Worldutils.java +++ /dev/null @@ -1,18 +0,0 @@ -package de.butzlabben.world.util; - -import de.butzlabben.world.config.SettingsConfig; -import de.butzlabben.world.wrapper.SystemWorld; -import org.bukkit.Bukkit; -import org.bukkit.World; - -public class Worldutils { - - public static void reloadWorldSettings(){ - for (World w : Bukkit.getWorlds()) { - SystemWorld sw = SystemWorld.getSystemWorld(w.getName()); - if (sw != null && sw.isLoaded()) - SettingsConfig.editWorld(w); - - } - } -} diff --git a/src/main/java/de/butzlabben/world/util/database/DatabaseConnection.java b/src/main/java/de/butzlabben/world/util/database/DatabaseConnection.java deleted file mode 100644 index 11c6bba..0000000 --- a/src/main/java/de/butzlabben/world/util/database/DatabaseConnection.java +++ /dev/null @@ -1,56 +0,0 @@ -package de.butzlabben.world.util.database; - -import lombok.Getter; - -import java.sql.*; - -public abstract class DatabaseConnection implements DatabaseUtil { - - final Object lock = new Object(); - @Getter - Connection connection; - - public void close() { - synchronized (lock) { - try { - if (connection == null || connection.isClosed()) { - System.err.println("[WorldSystem | DB] Connection does not exist or was already closed"); - return; - } - connection.close(); - } catch (SQLException e) { - System.out.println("[WorldSystem | DB] Connection could not be closed"); - e.printStackTrace(); - } - } - } - - public PreparedStatement prepareStatement(String sql) throws SQLException { - synchronized (lock) { - if (connection == null || connection.isClosed()) - connect(); - return connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); - } - } - - public ResultSet executeQuery(PreparedStatement ps) throws SQLException { - synchronized (lock) { - if (connection == null || connection.isClosed()) - connect(); - return ps.executeQuery(); - } - } - - public int executeUpdate(PreparedStatement ps) throws SQLException { - synchronized (lock) { - if (connection == null || connection.isClosed()) - connect(); - return ps.executeUpdate(); - } - } - - @Override - public boolean isConnectionAvailable() { - return connection != null; - } -} diff --git a/src/main/java/de/butzlabben/world/util/database/DatabaseProvider.java b/src/main/java/de/butzlabben/world/util/database/DatabaseProvider.java deleted file mode 100644 index 9c9a8b3..0000000 --- a/src/main/java/de/butzlabben/world/util/database/DatabaseProvider.java +++ /dev/null @@ -1,23 +0,0 @@ -package de.butzlabben.world.util.database; - -import de.butzlabben.world.config.PluginConfig; -import lombok.Getter; - -public class DatabaseProvider { - @Getter - public static DatabaseProvider instance = new DatabaseProvider(); - - @Getter - public final DatabaseUtil util; - - private DatabaseProvider() { - String dbType = PluginConfig.getDatabaseType(); - if (dbType.equalsIgnoreCase("sqlite")) - util = new SqliteConnection(); - else if (dbType.equalsIgnoreCase("mysql")) - util = new MysqlConnection(); - else { - throw new IllegalArgumentException("Unknown database type: " + dbType); - } - } -} \ No newline at end of file diff --git a/src/main/java/de/butzlabben/world/util/database/DatabaseUtil.java b/src/main/java/de/butzlabben/world/util/database/DatabaseUtil.java deleted file mode 100644 index d2ea9fc..0000000 --- a/src/main/java/de/butzlabben/world/util/database/DatabaseUtil.java +++ /dev/null @@ -1,20 +0,0 @@ -package de.butzlabben.world.util.database; - -import java.sql.PreparedStatement; -import java.sql.ResultSet; -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(); - - boolean isConnectionAvailable(); -} diff --git a/src/main/java/de/butzlabben/world/util/database/MysqlConnection.java b/src/main/java/de/butzlabben/world/util/database/MysqlConnection.java deleted file mode 100644 index 93819c1..0000000 --- a/src/main/java/de/butzlabben/world/util/database/MysqlConnection.java +++ /dev/null @@ -1,35 +0,0 @@ -package de.butzlabben.world.util.database; - -import de.butzlabben.world.config.PluginConfig; -import org.bukkit.Bukkit; - -import java.sql.DriverManager; -import java.sql.SQLException; -import java.util.logging.Level; - -public class MysqlConnection extends DatabaseConnection { - - private void connect(String host, String database, String port, String user, String password) { - synchronized (lock) { - try { - Class.forName("com.mysql.jdbc.Driver"); - } catch (ClassNotFoundException e) { - Bukkit.getLogger().log(Level.SEVERE, "[WorldSystem | MySQL] Drivers are not working properly"); - return; - } - try { - connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?user=" - + user + "&password=" + password); - Bukkit.getLogger().log(Level.INFO, "[WorldSystem | MySQL] Connected to remote MySQL database"); - } catch (SQLException e) { - Bukkit.getLogger().log(Level.SEVERE, "[WorldSystem | MySQL] Failed to connect with given server:"); - e.printStackTrace(); - } - } - } - - public void connect() { - connect(PluginConfig.getMysqlHost(), PluginConfig.getMysqlDatabaseName(), PluginConfig.getMysqlPort() + "", - PluginConfig.getMysqlUser(), PluginConfig.getMysqlPassword()); - } -} diff --git a/src/main/java/de/butzlabben/world/util/database/SqliteConnection.java b/src/main/java/de/butzlabben/world/util/database/SqliteConnection.java deleted file mode 100644 index c481f9a..0000000 --- a/src/main/java/de/butzlabben/world/util/database/SqliteConnection.java +++ /dev/null @@ -1,43 +0,0 @@ -package de.butzlabben.world.util.database; - -import de.butzlabben.world.config.PluginConfig; -import de.butzlabben.world.util.VersionUtil; -import org.bukkit.Bukkit; - -import java.sql.DriverManager; -import java.sql.SQLException; -import java.util.logging.Level; - -public class SqliteConnection extends DatabaseConnection { - - private void connect(String file) { - if (VersionUtil.getVersion() <= 8) { - Bukkit.getLogger().log(Level.SEVERE, "[WorldSystem | SQLite] ========================================================"); - Bukkit.getLogger().log(Level.SEVERE, "[WorldSystem | SQLite] SQLite is not available in 1.8."); - Bukkit.getLogger().log(Level.SEVERE, "[WorldSystem | SQLite] Please consider using MySQL or disable the use_last_location option"); - Bukkit.getLogger().log(Level.SEVERE, "[WorldSystem | SQLite] ========================================================"); - return; - } - - synchronized (lock) { - try { - Class.forName("com.mysql.jdbc.Driver"); - Class.forName("org.sqlite.JDBC"); - } catch (ClassNotFoundException e) { - Bukkit.getLogger().log(Level.SEVERE, "[WorldSystem | SQLite] Drivers are not working properly"); - return; - } - try { - connection = DriverManager.getConnection("jdbc:sqlite:" + file); - Bukkit.getLogger().log(Level.INFO, "[WorldSystem | SQLite] Connected to local file database"); - } catch (SQLException e) { - Bukkit.getLogger().log(Level.SEVERE, "[WorldSystem | SQLite] Failed to connect with given server:"); - e.printStackTrace(); - } - } - } - - public void connect() { - connect(PluginConfig.getSqliteFile()); - } -} diff --git a/src/main/java/de/butzlabben/world/utils/CubicCords.java b/src/main/java/de/butzlabben/world/utils/CubicCords.java new file mode 100644 index 0000000..4ac1761 --- /dev/null +++ b/src/main/java/de/butzlabben/world/utils/CubicCords.java @@ -0,0 +1,16 @@ +package de.butzlabben.world.utils; + +public class CubicCords extends PlanerCords { + + private int z; + + public CubicCords(int x, int y, int z) + { + super(x, y); + this.z = z; + } + + public int getZ() { + return this.z; + } +} diff --git a/src/main/java/de/butzlabben/world/utils/PlanerCords.java b/src/main/java/de/butzlabben/world/utils/PlanerCords.java new file mode 100644 index 0000000..cf17fa2 --- /dev/null +++ b/src/main/java/de/butzlabben/world/utils/PlanerCords.java @@ -0,0 +1,20 @@ +package de.butzlabben.world.utils; + +public class PlanerCords +{ + private int x; + private int y; + + public PlanerCords(int x, int y) { + this.x = x; + this.y = y; + } + + public int getX() { + return this.x; + } + + public int getY() { + return this.y; + } +} diff --git a/src/main/java/de/butzlabben/world/wrapper/AsyncCreatorAdapter.java b/src/main/java/de/butzlabben/world/wrapper/AsyncCreatorAdapter.java deleted file mode 100644 index 3d8276a..0000000 --- a/src/main/java/de/butzlabben/world/wrapper/AsyncCreatorAdapter.java +++ /dev/null @@ -1,45 +0,0 @@ -package de.butzlabben.world.wrapper; - -//import com.boydti.fawe.bukkit.wrapper.AsyncWorld; -//import com.boydti.fawe.util.TaskManager; -import com.fastasyncworldedit.core.util.TaskManager; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.WorldCreator; -import org.bukkit.block.Block; - -import java.util.Objects; - -/** - * @author Butzlabben - * @since 08.06.2018 - */ -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()))); - - 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); - - // 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 deleted file mode 100644 index 35c84bb..0000000 --- a/src/main/java/de/butzlabben/world/wrapper/CreatorAdapter.java +++ /dev/null @@ -1,12 +0,0 @@ -package de.butzlabben.world.wrapper; - -import org.bukkit.WorldCreator; - -/** - * @author Butzlabben - * @since 07.06.2018 - */ -public interface CreatorAdapter { - - void create(WorldCreator creator, SystemWorld world, Runnable sendPlayerMessageCallback); -} diff --git a/src/main/java/de/butzlabben/world/wrapper/GeneratorSettings.java b/src/main/java/de/butzlabben/world/wrapper/GeneratorSettings.java deleted file mode 100644 index ccc0f56..0000000 --- a/src/main/java/de/butzlabben/world/wrapper/GeneratorSettings.java +++ /dev/null @@ -1,37 +0,0 @@ -package de.butzlabben.world.wrapper; - -import lombok.AllArgsConstructor; -import org.bukkit.World; -import org.bukkit.WorldCreator; -import org.bukkit.WorldType; - -@AllArgsConstructor -public class GeneratorSettings { - final private long seed; - final private World.Environment environment; - final private WorldType type; - final private String generator; - - // Default generatorsettings - public GeneratorSettings() { - type = null; - environment = null; - seed = 0; - generator = null; - } - - public WorldCreator asWorldCreator(String name) { - WorldCreator creator = new WorldCreator(name); - - if (type != null) - creator.type(type); - if (environment != null) - creator.environment(environment); - if (seed != 0) - creator.seed(seed); - if (generator != null && !generator.trim().isEmpty()) - creator.generator(generator); - - return creator; - } -} diff --git a/src/main/java/de/butzlabben/world/wrapper/SystemWorld.java b/src/main/java/de/butzlabben/world/wrapper/SystemWorld.java deleted file mode 100644 index d61e3dd..0000000 --- a/src/main/java/de/butzlabben/world/wrapper/SystemWorld.java +++ /dev/null @@ -1,461 +0,0 @@ - - package de.butzlabben.world.wrapper; - - import com.google.common.base.Preconditions; - import de.butzlabben.WorldSystem; - import de.butzlabben.world.config.*; - import de.butzlabben.world.event.WorldCreateEvent; - import de.butzlabben.world.event.WorldLoadEvent; - import de.butzlabben.world.event.WorldUnloadEvent; - import de.butzlabben.world.util.PlayerPositions; - import de.butzlabben.world.util.PlayerWrapper; - import de.butzlabben.world.util.VersionUtil; - import org.apache.commons.io.FileUtils; - import org.bukkit.*; - import org.bukkit.entity.Player; - import org.bukkit.scheduler.BukkitRunnable; - import org.bukkit.scheduler.BukkitTask; - - import java.io.File; - import java.io.IOException; - import java.util.HashMap; - import java.util.UUID; - -/** - * This class represents a systemworld, loaded or not - * - * @author Butzlabben - * @since 14.02.2018 - */ -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 BukkitTask unloadLaterTask; - - private SystemWorld(String worldname) { - this.worldname = worldname; - w = Bukkit.getWorld(worldname); - } - - /** - * This method is the online way to get a system world instance - * - * @param worldname as in minecraft - * @return a systemworld instance if it is a systemworld or null if is not a - * systemworld - * @throws NullPointerException worldname == null - */ - public static SystemWorld getSystemWorld(String worldname) { - Preconditions.checkNotNull(worldname, "worldname must not be null"); - if (cached.containsKey(worldname)) - return cached.get(worldname); - SystemWorld sw = new SystemWorld(worldname); - if (sw != null && sw.exists()) { - cached.put(worldname, sw); - return sw; - } - return null; - } - - /** - * @param w a world in bukkit, no matter if systemworld or not Trys to unload a - * systemworld later, with the given delay in the config - */ - public static void tryUnloadLater(World w) { - if (w != null) - Bukkit.getScheduler().runTaskLater(WorldSystem.getInstance(), () -> { - if (w.getPlayers().size() == 0) { - SystemWorld sw = SystemWorld.getSystemWorld(w.getName()); - if (sw != null && sw.isLoaded()) - sw.unloadLater(w); - } - }, 20); - } - - public static boolean create(Player p, WorldTemplate template) { - return create(p.getUniqueId(), template); - } - - - /** - * Trys to create a new systemworld with all entries etc. finally loads the - * world - * - * @param uniqueID UUID of the player to create the world for - * @return whether it succesfull or not - */ - public static boolean create(UUID uniqueID, WorldTemplate template) { - - DependenceConfig dc = new DependenceConfig(uniqueID); - - String uuid = uniqueID.toString(); - int id = DependenceConfig.getHighestID() + 1; - String worldname = "ID" + id + "-" + uuid; - Player p = Bukkit.getPlayer(uniqueID); - - WorldCreator creator = template.generatorSettings.asWorldCreator(worldname); - - WorldCreateEvent event = new WorldCreateEvent(uniqueID, 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 " + uuid); - e.printStackTrace(); - } - else - newworld.mkdirs(); - - WorldConfig.create(uniqueID, 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) { - if (p != null && p.isOnline()) - p.sendMessage(PluginConfig.getPrefix() + "§cError: " + e.getMessage()); - System.err.println("Couldn't load world of " + uuid); - 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; - } - - /** - * Trys to force-unload this world - * - * @param w associated world - * @throws NullPointerException w == null - */ - public void directUnload(World w) { - if (!Bukkit.isPrimaryThread()) { - Bukkit.getScheduler().runTask(WorldSystem.getInstance(), () -> directUnload(w)); - return; - } - Preconditions.checkNotNull(w, "world must not be null"); - setUnloading(true); - w.save(); - Chunk[] arrayOfChunk; - int j = (arrayOfChunk = w.getLoadedChunks()).length; - for (int i = 0; i < j; i++) { - Chunk c = arrayOfChunk[i]; - c.unload(); - } - - WorldConfig config = WorldConfig.getWorldConfig(worldname); - for (Player a : w.getPlayers()) { - PlayerPositions.instance.saveWorldsPlayerLocation(a, config); - a.teleport(PluginConfig.getSpawn(a)); - a.setGameMode(PluginConfig.getSpawnGamemode()); - } - if (unloading) { - if (Bukkit.unloadWorld(w, true)) { - File worldinserver = new File(Bukkit.getWorldContainer(), worldname); - File worlddir = new File(PluginConfig.getWorlddir()); - try { - FileUtils.moveDirectoryToDirectory(worldinserver, worlddir, false); - Bukkit.getWorlds().remove(w); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - } - - /** - * Trys to unload this world later, with the given delay in the config - * - * @param w the associated world - * @throws NullPointerException w == null - */ - private void unloadLater(World w) { - if (!Bukkit.isPrimaryThread()) { - Bukkit.getScheduler().runTask(WorldSystem.getInstance(), () -> unloadLater(w)); - return; - } - - // Do not start another unload task - if (unloading) { - return; - } - - Preconditions.checkNotNull(w, "world must not be null"); - WorldUnloadEvent event = new WorldUnloadEvent(this); - Bukkit.getPluginManager().callEvent(event); - if (event.isCancelled()) - return; - // Set unloading to true - setUnloading(true); - w.save(); - Chunk[] arrayOfChunk; - int j = (arrayOfChunk = w.getLoadedChunks()).length; - for (int i = 0; i < j; i++) { - Chunk c = arrayOfChunk[i]; - c.unload(); - } - for (Player a : w.getPlayers()) { - a.teleport(PluginConfig.getSpawn(a)); - a.setGameMode(PluginConfig.getSpawnGamemode()); - } - - unloadLaterTask = Bukkit.getScheduler().runTaskLater(WorldSystem.getInstance(), () -> { - // Still in world unloading process? - if (unloading && w.getPlayers().size() == 0) { - if (Bukkit.unloadWorld(w, true)) { - File worldinserver = new File(Bukkit.getWorldContainer(), worldname); - File worlddir = new File(PluginConfig.getWorlddir()); - try { - FileUtils.moveDirectoryToDirectory(worldinserver, worlddir, false); - Bukkit.getWorlds().remove(w); - setUnloading(false); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - }, 20 * PluginConfig.getUnloadingTime()); - } - - /** - * Trys to load this world, and messages the player about the process - * - * @param p the player to teleport on the world - * @throws NullPointerException if p is null - * @throws IllegalArgumentException if player is not online - */ - public void load(Player p) { - if (!Bukkit.isPrimaryThread()) { - Bukkit.getScheduler().runTask(WorldSystem.getInstance(), () -> load(p)); - return; - } - Preconditions.checkNotNull(p, "player must not be null"); - Preconditions.checkArgument(p.isOnline(), "player must be online"); - - if (creating) { - p.sendMessage(MessageConfig.getWorldStillCreating()); - return; - } - - WorldLoadEvent event = new WorldLoadEvent(p, this); - Bukkit.getPluginManager().callEvent(event); - if (event.isCancelled()) - return; - - setUnloading(false); - - p.sendMessage(MessageConfig.getSettingUpWorld()); - - // Move World into Server dir - String worlddir = PluginConfig.getWorlddir(); - File world = new File(worlddir + "/" + worldname); - - if (world.exists()) { - // Check for duplicated worlds - File propablyExistingWorld = new File(Bukkit.getWorldContainer(), worldname); - if (propablyExistingWorld.exists()) { - System.err.println("World " + worldname + " existed twice!"); - try { - FileUtils.deleteDirectory(propablyExistingWorld); - } catch (IOException e) { - p.sendMessage(MessageConfig.getUnknownError()); - e.printStackTrace(); - } - } - - //Move world if exists - try { - FileUtils.moveDirectoryToDirectory(world, Bukkit.getWorldContainer(), false); - } catch (IOException e) { - System.err.println("Couldn't load world of " + p.getName()); - p.sendMessage(PluginConfig.getPrefix() + "§cError: " + e.getMessage()); - e.printStackTrace(); - } - } - - // Check for old named worlds - if (worldname.charAt(worldname.length() - 37) == ' ') { - StringBuilder myName = new StringBuilder(worldname); - myName.setCharAt(worldname.length() - 37, '-'); - world.renameTo(new File(Bukkit.getWorldContainer(), myName.toString())); - worldname = myName.toString(); - } - - - WorldCreator creator = new WorldCreator(worldname); - - String templateKey = WorldConfig.getWorldConfig(worldname).getTemplateKey(); - WorldTemplate template = WorldTemplateProvider.getInstance().getTemplate(templateKey); - if (template == null) - template = WorldTemplateProvider.getInstance().getTemplate(PluginConfig.getDefaultWorldTemplate()); - - if (template != null) - creator = template.generatorSettings.asWorldCreator(worldname); - - - World w = Bukkit.getWorld(worldname); - if (w == null) - w = Bukkit.createWorld(creator); - - this.w = w; - - Bukkit.getScheduler().scheduleSyncDelayedTask(WorldSystem.getInstance(), new Runnable() { - public void run() { - teleportToWorldSpawn(p); - } - }, 10L); - - OfflinePlayer owner = PlayerWrapper.getOfflinePlayer(WorldConfig.getWorldConfig(worldname).getOwner()); - DependenceConfig dc = new DependenceConfig(owner); - dc.setLastLoaded(); - } - - /** - * @return if the world is loaded - */ - public boolean isLoaded() { - File worldAsDir = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); - World w = Bukkit.getWorld(worldname); - return worldAsDir.exists() && w != null; - } - - private boolean exists() { - File worldAsDir = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); - if (worldAsDir.exists()) { - return true; - } - worldAsDir = new File(PluginConfig.getWorlddir() + "/" + worldname + "/worldconfig.yml"); - return worldAsDir.exists(); - } - - /** - * Teleports the player to the world with the given settings in the config - * - * @param p player to teleport - * @throws NullPointerException if player is null - * @throws IllegalArgumentException if player is not online - */ - public void teleportToWorldSpawn(Player p) { - Preconditions.checkNotNull(p, "player must not be null"); - Preconditions.checkArgument(p.isOnline(), "player must be online"); - PlayerPositions positions = PlayerPositions.instance; - - if (creating) { - p.sendMessage(MessageConfig.getWorldStillCreating()); - return; - } - - setUnloading(false); - w = Bukkit.getWorld(worldname); - if (w == null) - return; - - WorldConfig config = WorldConfig.getWorldConfig(worldname); - if (config.getHome() != null) { - p.teleport(positions.injectWorldsLocation(p, config, config.getHome())); - } else { - if (PluginConfig.useWorldSpawn()) { - p.teleport(positions.injectWorldsLocation(p, config, PluginConfig.getWorldSpawn(w))); - } else { - p.teleport(positions.injectWorldsLocation(p, config, w.getSpawnLocation())); - } - } - if (PluginConfig.isSurvival()) { - p.setGameMode(GameMode.SURVIVAL); - } else { - p.setGameMode(GameMode.CREATIVE); - } - - OfflinePlayer owner = PlayerWrapper.getOfflinePlayer(WorldConfig.getWorldConfig(worldname).getOwner()); - DependenceConfig dc = new DependenceConfig(owner); - dc.setLastLoaded(); - } - - /** - * @return the world - */ - public World getWorld() { - return w; - } - - public boolean isCreating() { - return creating; - } - - public void setCreating(boolean creating) { - this.creating = creating; - } - - public void setUnloading(boolean unloading) { - this.unloading = unloading; - - // Cancel unload task if unloading is set to false - if (!unloading && unloadLaterTask != null && !VersionUtil.isCancelled(unloadLaterTask)) { - unloadLaterTask.cancel(); - } - } - - /** - * @return the worldname - */ - public String getName() { - return worldname; - } -} \ No newline at end of file diff --git a/src/main/java/de/butzlabben/world/wrapper/WorldPlayer.java b/src/main/java/de/butzlabben/world/wrapper/WorldPlayer.java deleted file mode 100644 index 497aa91..0000000 --- a/src/main/java/de/butzlabben/world/wrapper/WorldPlayer.java +++ /dev/null @@ -1,220 +0,0 @@ -package de.butzlabben.world.wrapper; - -import com.google.common.base.Preconditions; -import de.butzlabben.WorldSystem; -import de.butzlabben.world.config.PluginConfig; -import de.butzlabben.world.config.WorldConfig; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; - -/** - * This class represents a player, on a systemworld or not but be carefull when - * accesing some methods when the player is not on a systemworld like - * toggleBuild() - * - * @author Butzlabben - * @since 15.03.2018 - */ -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 - */ - public String getWorldname() { - return worldname; - } - - /** - * toggles building for this player - * - * @return whether can build or not - */ - public boolean toggleBuild() { - Preconditions.checkArgument(isOnSystemWorld(), "player must be for this on a systemworld"); - - WorldConfig wc = WorldConfig.getWorldConfig(worldname); - if (!wc.isMember(p.getUniqueId())) - return false; - - boolean build = wc.canBuild(p.getUniqueId()); - build = !build; - wc.setBuild(p.getUniqueId(), build); - try { - wc.save(); - } catch (IOException e) { - e.printStackTrace(); - } - return build; - } - - /** - * @return whether can build or not - */ - public boolean canBuild() { - Preconditions.checkArgument(isOnSystemWorld(), "player must be for this on a systemworld"); - WorldConfig wc = WorldConfig.getWorldConfig(worldname); - return wc.canBuild(p.getUniqueId()); - } - - public boolean toggleWorldEdit() { - Preconditions.checkArgument(isOnSystemWorld(), "player must be for this on a systemworld"); - - WorldConfig wc = WorldConfig.getWorldConfig(this.worldname); - if (!wc.isMember(this.p.getUniqueId())) { - return false; - } - boolean build = wc.canWorldEdit(this.p.getUniqueId()); - build = !build; - wc.setWorldEdit(this.p.getUniqueId(), build); - try { - wc.save(); - } catch (IOException e) { - e.printStackTrace(); - } - return build; - } - - public boolean canWorldedit() { - Preconditions.checkArgument(isOnSystemWorld(), "player must be for this on a systemworld"); - WorldConfig wc = WorldConfig.getWorldConfig(this.worldname); - return wc.canWorldEdit(this.p.getUniqueId()); - } - - /** - * toggles teleporting for this player - * - * @return whether can teleport or not - */ - public boolean toggleTeleport() { - Preconditions.checkArgument(isOnSystemWorld(), "player must be for this on a systemworld"); - - WorldConfig wc = WorldConfig.getWorldConfig(worldname); - if (!wc.isMember(p.getUniqueId())) - return false; - - boolean teleport = wc.canTeleport(p.getUniqueId()); - teleport = !teleport; - wc.setTeleport(p.getUniqueId(), teleport); - try { - wc.save(); - } catch (IOException e) { - e.printStackTrace(); - } - return teleport; - } - - /** - * @return whether can teleport or not - */ - public boolean canTeleport() { - Preconditions.checkArgument(isOnSystemWorld(), "player must be for this on a systemworld"); - WorldConfig wc = WorldConfig.getWorldConfig(worldname); - return wc.canTeleport(p.getUniqueId()); - } - - /** - * toggles gamemode changing for this player - * - * @return whether can change his gamemode or not - */ - public boolean toggleGamemode() { - Preconditions.checkArgument(isOnSystemWorld(), "player must be for this on a systemworld"); - - WorldConfig wc = WorldConfig.getWorldConfig(worldname); - if (!wc.isMember(p.getUniqueId())) - return false; - - boolean changeGamemode = wc.canGamemode(p.getUniqueId()); - changeGamemode = !changeGamemode; - wc.setGamemode(p.getUniqueId(), changeGamemode); - try { - wc.save(); - } catch (IOException e) { - e.printStackTrace(); - } - return changeGamemode; - } - - /** - * @return whether can change his gamemode or not - */ - public boolean canChangeGamemode() { - Preconditions.checkArgument(isOnSystemWorld(), "player must be for this on a systemworld"); - WorldConfig wc = WorldConfig.getWorldConfig(worldname); - return wc.canGamemode(p.getUniqueId()); - } - - /** - * @return if he is a member - */ - public boolean isMember() { - Preconditions.checkArgument(isOnSystemWorld(), "player must be for this on a systemworld"); - - WorldConfig wc = WorldConfig.getWorldConfig(worldname); - return wc.isMember(p.getUniqueId()); - } - - /** - * @return if he is on a systemworld or not - */ - public boolean isOnSystemWorld() { - File worldconfig = new File(Bukkit.getWorldContainer(), worldname + "/worldconfig.yml"); - if (!worldconfig.exists()) { - try { - worldconfig = new File(new PluginConfig(WorldSystem.getConfigFile()).getWorlddir() + worldname + "/worldconfig.yml"); - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } - } - if (worldconfig.exists()) { - YamlConfiguration cfg = YamlConfiguration.loadConfiguration(worldconfig); - return cfg.getString("Informations.Owner.PlayerUUID") != null; - } - return false; - } - - /** - * @return the given player - */ - public OfflinePlayer getPlayer() { - return p; - } - - /** - * @return if he ist the owner - */ - public boolean isOwnerofWorld() { - if (!isOnSystemWorld()) - return false; - WorldConfig wc = WorldConfig.getWorldConfig(worldname); - return wc.getOwner().equals(p.getUniqueId()); - } - - /** - * @param worldname of the world to be tested - * @return worldname if he is the owner of the specified world - */ - public boolean isMemberofWorld(String worldname) { - WorldConfig wc = WorldConfig.getWorldConfig(worldname); - return wc.isMember(p.getUniqueId()); - } - -} diff --git a/src/main/java/de/butzlabben/world/wrapper/WorldTemplate.java b/src/main/java/de/butzlabben/world/wrapper/WorldTemplate.java deleted file mode 100644 index a75e9d9..0000000 --- a/src/main/java/de/butzlabben/world/wrapper/WorldTemplate.java +++ /dev/null @@ -1,59 +0,0 @@ -package de.butzlabben.world.wrapper; - -import de.butzlabben.inventory.OrcItem; -import de.butzlabben.world.config.GuiConfig; -import lombok.Getter; - -/** - * @author Butzlabben - * @since 15.12.2018 - */ -@Getter -public class WorldTemplate { - - public final String name; - public final String permission; - public final OrcItem icon; - public final int slot; - public final int cost; - public final GeneratorSettings generatorSettings; - - public WorldTemplate(String name, String permission, int cost, GeneratorSettings generatorSettings) { - this.name = name; - this.permission = permission; - this.cost = cost; - this.generatorSettings = generatorSettings; - - this.icon = GuiConfig.getItem("worldchoose." + name); - this.slot = GuiConfig.getSlot("worldchoose." + name); - - icon.setOnClick((p, inv, item) -> { - p.closeInventory(); - p.chat("/ws get " + name); - }); - } - - public int getSlot() { - return slot; - } - - public int getCost() { - return cost; - } - - public OrcItem getIcon() { - return icon; - } - - public String getName() { - return name; - } - - public String getPath() { - return "plugins/WorldSystem/worldsources/" + name; - } - - public String getPermission() { - return permission; - } -} diff --git a/src/main/java/de/butzlabben/world/wrapper/WorldTemplateProvider.java b/src/main/java/de/butzlabben/world/wrapper/WorldTemplateProvider.java deleted file mode 100644 index 7911281..0000000 --- a/src/main/java/de/butzlabben/world/wrapper/WorldTemplateProvider.java +++ /dev/null @@ -1,85 +0,0 @@ -package de.butzlabben.world.wrapper; - -import de.butzlabben.world.config.PluginConfig; -import org.bukkit.World; -import org.bukkit.WorldType; -import org.bukkit.configuration.ConfigurationSection; - -import java.util.Collection; -import java.util.HashMap; - -/** - * @author Butzlabben - * @since 16.12.2018 - */ -public class WorldTemplateProvider { - - private static final WorldTemplateProvider instance = new WorldTemplateProvider(); - private final HashMap templates = new HashMap<>(); - - - private WorldTemplateProvider() { - reload(); - } - - public void reload(){ - templates.clear(); - - ConfigurationSection section = PluginConfig.getConfig().getConfigurationSection("worldtemplates.templates"); - for (String key : section.getKeys(false)) { - String name = section.getString(key + ".name"); - String permission = null; - if (section.isString(key + ".permission")) - permission = section.getString(key + ".permission"); - - int cost = -1; - // Get money for #15 if needed - if (section.isInt(key + ".cost")) - cost = section.getInt(key + ".cost"); - - GeneratorSettings settings = new GeneratorSettings(); - if (section.contains(key + ".generator")) { - ConfigurationSection gSection = section.getConfigurationSection(key + ".generator"); - long seed = gSection.getLong("seed", 0); - String env = gSection.getString("environment"); - String type = gSection.getString("type"); - String generator = gSection.getString("generator"); - settings = new GeneratorSettings(seed, getEnvironment(env), getWorldType(type), generator); - } - - templates.put(name, new WorldTemplate(name, permission, cost, settings)); - } - } - - public static WorldTemplateProvider getInstance() { - return instance; - } - - public WorldTemplate getTemplate(String key) { - return templates.get(key); - } - - public Collection getTemplates() { - return templates.values(); - } - - private World.Environment getEnvironment(String env) { - if (env == null) - return null; - try { - return World.Environment.valueOf(env); - } catch (Exception ignored) { - } - return null; - } - - private WorldType getWorldType(String type) { - if (type == null) - return null; - try { - return WorldType.valueOf(type); - } catch (Exception ignored) { - } - return null; - } -} diff --git a/src/test/java/de/butzlabben/world/config/TestPluginConfig.java b/src/test/java/de/butzlabben/world/config/TestPluginConfig.java index 51a8b00..5590436 100644 --- a/src/test/java/de/butzlabben/world/config/TestPluginConfig.java +++ b/src/test/java/de/butzlabben/world/config/TestPluginConfig.java @@ -1,14 +1,127 @@ package de.butzlabben.world.config; +import de.butzlabben.world.utils.PlanerCords; +import org.bukkit.Difficulty; +import org.bukkit.GameMode; import org.junit.jupiter.api.Test; import java.io.File; import java.io.FileNotFoundException; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class TestPluginConfig { @Test public void testPluginConfigInit() throws FileNotFoundException { - File cfgFile = new File("TestFiles/workingDir/TestConfig.yml"); + File cfgFile = new File("TestFiles/TestConfig.yml"); PluginConfig cfg = new PluginConfig(cfgFile); } + + + //TODO ADD Invalid Config Test + + + + //TESTS For General Settings + + @Test + public void testGetLanguage() throws FileNotFoundException + { + File cfgFile = new File("TestFiles/TestConfig.yml"); + PluginConfig cfg = new PluginConfig(cfgFile); + assertEquals("en", cfg.getLanguage()); + } + + @Test + public void testGetWorldDir() throws FileNotFoundException + { + File cfgFile = new File("TestFiles/TestConfig.yml"); + PluginConfig cfg = new PluginConfig(cfgFile); + assertEquals("plugins/WorldSystem/Worlds", cfg.getWorldDir()); + } + + @Test + public void testGetUnloadTime() throws FileNotFoundException + { + File cfgFile = new File("TestFiles/TestConfig.yml"); + PluginConfig cfg = new PluginConfig(cfgFile); + assertEquals(20, cfg.getUnloadTime()); + } + + @Test + public void testGetPrefix() throws FileNotFoundException + { + File cfgFile = new File("TestFiles/TestConfig.yml"); + PluginConfig cfg = new PluginConfig(cfgFile); + assertEquals("&8[&3WorldSystem&8] &6", cfg.getPrefix()); + } + + @Test + public void testGetDeleteAfter() throws FileNotFoundException + { + File cfgFile = new File("TestFiles/TestConfig.yml"); + PluginConfig cfg = new PluginConfig(cfgFile); + assertEquals(-1, cfg.getDeleteAfter()); + } + + @Test + public void testGameDifficulty() throws FileNotFoundException + { + File cfgFile = new File("TestFiles/TestConfig.yml"); + PluginConfig cfg = new PluginConfig(cfgFile); + assertEquals(Difficulty.EASY, cfg.getWorldDifficulty()); + } + + //TESTS For General Settings World Creation Setting + + @Test + public void testMultiChoice() throws FileNotFoundException + { + File cfgFile = new File("TestFiles/TestConfig.yml"); + PluginConfig cfg = new PluginConfig(cfgFile); + assertEquals(false, cfg.allowsMultiChoice()); + } + @Test + public void testgetDefaultGenerator() throws FileNotFoundException + { + File cfgFile = new File("TestFiles/TestConfig.yml"); + PluginConfig cfg = new PluginConfig(cfgFile); + assertEquals("Vanilla", cfg.getDefaultWorldGenerator()); + } + @Test + public void worldGenTemplates() throws FileNotFoundException + { + File cfgFile = new File("TestFiles/TestConfig.yml"); + PluginConfig cfg = new PluginConfig(cfgFile); + assertEquals("plugins/WorldSystem/Generators", cfg.getGeneratorTemplatesDir()); + } + @Test + public void testWorldBorderDefaultSize() throws FileNotFoundException + { + File cfgFile = new File("TestFiles/TestConfig.yml"); + PluginConfig cfg = new PluginConfig(cfgFile); + assertEquals(500, cfg.getDefaultWorldBorderSize()); + } + + @Test + public void testWorldBorderCords() throws FileNotFoundException + { + File cfgFile = new File("TestFiles/TestConfig.yml"); + PluginConfig cfg = new PluginConfig(cfgFile); + + assertEquals(0, cfg.getWorldBorderCords().getX()); + assertEquals(0, cfg.getWorldBorderCords().getY()); + } + + + //TESTS for World Entering/Exiting + + + @Test + public void testServerGamemode() throws FileNotFoundException + { + File cfgFile = new File("TestFiles/TestConfig.yml"); + PluginConfig cfg = new PluginConfig(cfgFile); + assertEquals(GameMode.SURVIVAL, cfg.getServerGamemode()); + } } diff --git a/src/test/java/de/butzlabben/world/data/TestWorldDatabase.java b/src/test/java/de/butzlabben/world/data/TestWorldDatabase.java index 4a099ec..4f5f632 100644 --- a/src/test/java/de/butzlabben/world/data/TestWorldDatabase.java +++ b/src/test/java/de/butzlabben/world/data/TestWorldDatabase.java @@ -7,7 +7,6 @@ import org.junit.jupiter.api.Test; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; -import java.nio.file.Path; import java.util.Scanner; import static org.junit.jupiter.api.Assertions.*; diff --git "a/src\\TestFiles\\ExistingPopulatedFileInit.json" "b/src\\TestFiles\\ExistingPopulatedFileInit.json" new file mode 100644 index 0000000..ae5bd6a --- /dev/null +++ "b/src\\TestFiles\\ExistingPopulatedFileInit.json" @@ -0,0 +1 @@ +{"players":{"BlankUUID":{"playerWorlds":[]}}} \ No newline at end of file diff --git a/target/classes/config.yml b/target/classes/config.yml index 22fc74b..f1e22e2 100644 --- a/target/classes/config.yml +++ b/target/classes/config.yml @@ -14,6 +14,8 @@ # General Settings # #################### +# The Language to plugin should run in +language: "en" #The Path that the Worlds of players will be stored when not in use. playerWorldsDir: 'plugins/WorldSystem/Worlds' @@ -80,7 +82,7 @@ wsWorldSpawn: #Warning: Spelling Matters, Capitalization Does not worldGameMode: 'Survival' # places the player at their last known location in the world - useLastLocation: true; + useLastLocation: false; #The point the player should be placed when entering a WS World #for the first Time defaultWorldSpawnPoint: diff --git a/target/classes/de/butzlabben/inventory/CostumInv.class b/target/classes/de/butzlabben/inventory/CostumInv.class deleted file mode 100644 index 303a951..0000000 Binary files a/target/classes/de/butzlabben/inventory/CostumInv.class and /dev/null differ diff --git a/target/classes/de/butzlabben/inventory/DependListener 2.class b/target/classes/de/butzlabben/inventory/DependListener 2.class deleted file mode 100644 index 81f5dd3..0000000 Binary files a/target/classes/de/butzlabben/inventory/DependListener 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/inventory/DependListener.class b/target/classes/de/butzlabben/inventory/DependListener.class deleted file mode 100644 index 81f5dd3..0000000 Binary files a/target/classes/de/butzlabben/inventory/DependListener.class and /dev/null differ diff --git a/target/classes/de/butzlabben/inventory/OrcClickListener.class b/target/classes/de/butzlabben/inventory/OrcClickListener.class deleted file mode 100644 index b89dce0..0000000 Binary files a/target/classes/de/butzlabben/inventory/OrcClickListener.class and /dev/null differ diff --git a/target/classes/de/butzlabben/inventory/OrcInventory 2.class b/target/classes/de/butzlabben/inventory/OrcInventory 2.class deleted file mode 100644 index 95ce4d3..0000000 Binary files a/target/classes/de/butzlabben/inventory/OrcInventory 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/inventory/OrcInventory.class b/target/classes/de/butzlabben/inventory/OrcInventory.class deleted file mode 100644 index 95ce4d3..0000000 Binary files a/target/classes/de/butzlabben/inventory/OrcInventory.class and /dev/null differ diff --git a/target/classes/de/butzlabben/inventory/OrcItem.class b/target/classes/de/butzlabben/inventory/OrcItem.class deleted file mode 100644 index ec836f5..0000000 Binary files a/target/classes/de/butzlabben/inventory/OrcItem.class and /dev/null differ diff --git a/target/classes/de/butzlabben/inventory/OrcListener.class b/target/classes/de/butzlabben/inventory/OrcListener.class deleted file mode 100644 index c69c91e..0000000 Binary files a/target/classes/de/butzlabben/inventory/OrcListener.class and /dev/null differ diff --git a/target/classes/de/butzlabben/inventory/pages/InventoryPage.class b/target/classes/de/butzlabben/inventory/pages/InventoryPage.class deleted file mode 100644 index 0d1ba91..0000000 Binary files a/target/classes/de/butzlabben/inventory/pages/InventoryPage.class and /dev/null differ diff --git a/target/classes/de/butzlabben/inventory/pages/ItemConverter.class b/target/classes/de/butzlabben/inventory/pages/ItemConverter.class deleted file mode 100644 index f6a0188..0000000 Binary files a/target/classes/de/butzlabben/inventory/pages/ItemConverter.class and /dev/null differ diff --git a/target/classes/de/butzlabben/inventory/pages/PageGUICreator.class b/target/classes/de/butzlabben/inventory/pages/PageGUICreator.class deleted file mode 100644 index 2c79ac7..0000000 Binary files a/target/classes/de/butzlabben/inventory/pages/PageGUICreator.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/GameProfileBuilder 2.class b/target/classes/de/butzlabben/world/GameProfileBuilder 2.class deleted file mode 100644 index 7e1c7b4..0000000 Binary files a/target/classes/de/butzlabben/world/GameProfileBuilder 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/GameProfileBuilder$CachedProfile 2.class b/target/classes/de/butzlabben/world/GameProfileBuilder$CachedProfile 2.class deleted file mode 100644 index f382492..0000000 Binary files a/target/classes/de/butzlabben/world/GameProfileBuilder$CachedProfile 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/GameProfileBuilder$GameProfileSerializer 2.class b/target/classes/de/butzlabben/world/GameProfileBuilder$GameProfileSerializer 2.class deleted file mode 100644 index fb61f14..0000000 Binary files a/target/classes/de/butzlabben/world/GameProfileBuilder$GameProfileSerializer 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/WorldCheckerRunnable 2.class b/target/classes/de/butzlabben/world/WorldCheckerRunnable 2.class deleted file mode 100644 index 06662cf..0000000 Binary files a/target/classes/de/butzlabben/world/WorldCheckerRunnable 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/WorldSystem.class b/target/classes/de/butzlabben/world/WorldSystem.class new file mode 100644 index 0000000..05f6e9e Binary files /dev/null and b/target/classes/de/butzlabben/world/WorldSystem.class differ diff --git a/target/classes/de/butzlabben/world/command/CommandRegistry.class b/target/classes/de/butzlabben/world/command/CommandRegistry.class deleted file mode 100644 index 46bf77c..0000000 Binary files a/target/classes/de/butzlabben/world/command/CommandRegistry.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/command/commands/WSCommands 2.class b/target/classes/de/butzlabben/world/command/commands/WSCommands 2.class deleted file mode 100644 index 0a0f331..0000000 Binary files a/target/classes/de/butzlabben/world/command/commands/WSCommands 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/command/commands/WorldSettingsCommands 2.class b/target/classes/de/butzlabben/world/command/commands/WorldSettingsCommands 2.class deleted file mode 100644 index 1bf730f..0000000 Binary files a/target/classes/de/butzlabben/world/command/commands/WorldSettingsCommands 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/commands/WorldSystemCommand.class b/target/classes/de/butzlabben/world/commands/WorldSystemCommand.class new file mode 100644 index 0000000..b84fa90 Binary files /dev/null and b/target/classes/de/butzlabben/world/commands/WorldSystemCommand.class differ diff --git a/target/classes/de/butzlabben/world/commands/WorldSystemCommandExecuter.class b/target/classes/de/butzlabben/world/commands/WorldSystemCommandExecuter.class new file mode 100644 index 0000000..d77c66d Binary files /dev/null and b/target/classes/de/butzlabben/world/commands/WorldSystemCommandExecuter.class differ diff --git a/target/classes/de/butzlabben/world/commands/commands/testCommand.class b/target/classes/de/butzlabben/world/commands/commands/testCommand.class new file mode 100644 index 0000000..99f79a7 Binary files /dev/null and b/target/classes/de/butzlabben/world/commands/commands/testCommand.class differ diff --git a/target/classes/de/butzlabben/world/config/DependenceConfig 2.class b/target/classes/de/butzlabben/world/config/DependenceConfig 2.class deleted file mode 100644 index d691a61..0000000 Binary files a/target/classes/de/butzlabben/world/config/DependenceConfig 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/config/Entry 2.class b/target/classes/de/butzlabben/world/config/Entry 2.class deleted file mode 100644 index 211a60e..0000000 Binary files a/target/classes/de/butzlabben/world/config/Entry 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/config/GuiConfig 2.class b/target/classes/de/butzlabben/world/config/GuiConfig 2.class deleted file mode 100644 index bab66d4..0000000 Binary files a/target/classes/de/butzlabben/world/config/GuiConfig 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/config/MessageConfig 2.class b/target/classes/de/butzlabben/world/config/MessageConfig 2.class deleted file mode 100644 index bc7f35d..0000000 Binary files a/target/classes/de/butzlabben/world/config/MessageConfig 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/config/PluginConfig 2.class b/target/classes/de/butzlabben/world/config/PluginConfig 2.class deleted file mode 100644 index 176ce18..0000000 Binary files a/target/classes/de/butzlabben/world/config/PluginConfig 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/config/PluginConfig.class b/target/classes/de/butzlabben/world/config/PluginConfig.class new file mode 100644 index 0000000..0f93606 Binary files /dev/null and b/target/classes/de/butzlabben/world/config/PluginConfig.class differ diff --git a/target/classes/de/butzlabben/world/config/SettingsConfig 2.class b/target/classes/de/butzlabben/world/config/SettingsConfig 2.class deleted file mode 100644 index fafbfbf..0000000 Binary files a/target/classes/de/butzlabben/world/config/SettingsConfig 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/config/WorldPerm 2.class b/target/classes/de/butzlabben/world/config/WorldPerm 2.class deleted file mode 100644 index ffccf43..0000000 Binary files a/target/classes/de/butzlabben/world/config/WorldPerm 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/data/WorldDatabase 2.class b/target/classes/de/butzlabben/world/data/WorldDatabase.class similarity index 53% rename from target/classes/de/butzlabben/world/data/WorldDatabase 2.class rename to target/classes/de/butzlabben/world/data/WorldDatabase.class index c1e22da..5f7509b 100644 Binary files a/target/classes/de/butzlabben/world/data/WorldDatabase 2.class and b/target/classes/de/butzlabben/world/data/WorldDatabase.class differ diff --git a/target/classes/de/butzlabben/world/data/objects/PlayerData 2.class b/target/classes/de/butzlabben/world/data/objects/PlayerData.class similarity index 74% rename from target/classes/de/butzlabben/world/data/objects/PlayerData 2.class rename to target/classes/de/butzlabben/world/data/objects/PlayerData.class index c5aa565..4c6d7fc 100644 Binary files a/target/classes/de/butzlabben/world/data/objects/PlayerData 2.class and b/target/classes/de/butzlabben/world/data/objects/PlayerData.class differ diff --git a/target/classes/de/butzlabben/world/data/objects/PlayerWorld 2.class b/target/classes/de/butzlabben/world/data/objects/PlayerWorld 2.class deleted file mode 100644 index 68c2d10..0000000 Binary files a/target/classes/de/butzlabben/world/data/objects/PlayerWorld 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/data/objects/PlayerWorld.class b/target/classes/de/butzlabben/world/data/objects/PlayerWorld.class new file mode 100644 index 0000000..3a283a3 Binary files /dev/null and b/target/classes/de/butzlabben/world/data/objects/PlayerWorld.class differ diff --git a/target/classes/de/butzlabben/world/data/objects/WorldSystemData.class b/target/classes/de/butzlabben/world/data/objects/WorldSystemData.class new file mode 100644 index 0000000..110cddd Binary files /dev/null and b/target/classes/de/butzlabben/world/data/objects/WorldSystemData.class differ diff --git a/target/classes/de/butzlabben/world/exceptions/InvalidConfigFormatException.class b/target/classes/de/butzlabben/world/exceptions/InvalidConfigFormatException.class new file mode 100644 index 0000000..32720d0 Binary files /dev/null and b/target/classes/de/butzlabben/world/exceptions/InvalidConfigFormatException.class differ diff --git a/target/classes/de/butzlabben/world/gui/GuiCommand 2.class b/target/classes/de/butzlabben/world/gui/GuiCommand 2.class deleted file mode 100644 index d436289..0000000 Binary files a/target/classes/de/butzlabben/world/gui/GuiCommand 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/gui/PlayerOptionsGUI 2.class b/target/classes/de/butzlabben/world/gui/PlayerOptionsGUI 2.class deleted file mode 100644 index 4c9495a..0000000 Binary files a/target/classes/de/butzlabben/world/gui/PlayerOptionsGUI 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/gui/PlayersPageGUI 2.class b/target/classes/de/butzlabben/world/gui/PlayersPageGUI 2.class deleted file mode 100644 index e7fbb4d..0000000 Binary files a/target/classes/de/butzlabben/world/gui/PlayersPageGUI 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/gui/WorldChooseGUI 2.class b/target/classes/de/butzlabben/world/gui/WorldChooseGUI 2.class deleted file mode 100644 index 733841c..0000000 Binary files a/target/classes/de/butzlabben/world/gui/WorldChooseGUI 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/gui/WorldOptionsGUI 2.class b/target/classes/de/butzlabben/world/gui/WorldOptionsGUI 2.class deleted file mode 100644 index 361e520..0000000 Binary files a/target/classes/de/butzlabben/world/gui/WorldOptionsGUI 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/gui/WorldSystemGUI 2.class b/target/classes/de/butzlabben/world/gui/WorldSystemGUI 2.class deleted file mode 100644 index 20baaa4..0000000 Binary files a/target/classes/de/butzlabben/world/gui/WorldSystemGUI 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/gui/clicklistener/CommandExecutorClickListener 2.class b/target/classes/de/butzlabben/world/gui/clicklistener/CommandExecutorClickListener 2.class deleted file mode 100644 index bc5429b..0000000 Binary files a/target/classes/de/butzlabben/world/gui/clicklistener/CommandExecutorClickListener 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/gui/clicklistener/InventoryOpenClickListener 2.class b/target/classes/de/butzlabben/world/gui/clicklistener/InventoryOpenClickListener 2.class deleted file mode 100644 index 64a0d36..0000000 Binary files a/target/classes/de/butzlabben/world/gui/clicklistener/InventoryOpenClickListener 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/gui/playeroption/GamemodeStatus 2.class b/target/classes/de/butzlabben/world/gui/playeroption/GamemodeStatus 2.class deleted file mode 100644 index 17dc5f4..0000000 Binary files a/target/classes/de/butzlabben/world/gui/playeroption/GamemodeStatus 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/gui/playeroption/TeleportStatus 2.class b/target/classes/de/butzlabben/world/gui/playeroption/TeleportStatus 2.class deleted file mode 100644 index db4cb06..0000000 Binary files a/target/classes/de/butzlabben/world/gui/playeroption/TeleportStatus 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/gui/playeroption/WorldEditStatus 2.class b/target/classes/de/butzlabben/world/gui/playeroption/WorldEditStatus 2.class deleted file mode 100644 index 121e632..0000000 Binary files a/target/classes/de/butzlabben/world/gui/playeroption/WorldEditStatus 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/gui/worldoption/FireStatus 2.class b/target/classes/de/butzlabben/world/gui/worldoption/FireStatus 2.class deleted file mode 100644 index 36c5409..0000000 Binary files a/target/classes/de/butzlabben/world/gui/worldoption/FireStatus 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/utils/CubicCords.class b/target/classes/de/butzlabben/world/utils/CubicCords.class new file mode 100644 index 0000000..7fc3a74 Binary files /dev/null and b/target/classes/de/butzlabben/world/utils/CubicCords.class differ diff --git a/target/classes/de/butzlabben/world/utils/PlanerCords.class b/target/classes/de/butzlabben/world/utils/PlanerCords.class new file mode 100644 index 0000000..474d556 Binary files /dev/null and b/target/classes/de/butzlabben/world/utils/PlanerCords.class differ diff --git a/target/classes/de/butzlabben/world/wrapper/AsyncCreatorAdapter 2.class b/target/classes/de/butzlabben/world/wrapper/AsyncCreatorAdapter 2.class deleted file mode 100644 index 33d9526..0000000 Binary files a/target/classes/de/butzlabben/world/wrapper/AsyncCreatorAdapter 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/wrapper/GeneratorSettings 2.class b/target/classes/de/butzlabben/world/wrapper/GeneratorSettings 2.class deleted file mode 100644 index b9749e6..0000000 Binary files a/target/classes/de/butzlabben/world/wrapper/GeneratorSettings 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/wrapper/SystemWorld 2.class b/target/classes/de/butzlabben/world/wrapper/SystemWorld 2.class deleted file mode 100644 index 8aa01aa..0000000 Binary files a/target/classes/de/butzlabben/world/wrapper/SystemWorld 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/wrapper/WorldPlayer.class b/target/classes/de/butzlabben/world/wrapper/WorldPlayer.class deleted file mode 100644 index 6d5ffc4..0000000 Binary files a/target/classes/de/butzlabben/world/wrapper/WorldPlayer.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/wrapper/WorldTemplate 2.class b/target/classes/de/butzlabben/world/wrapper/WorldTemplate 2.class deleted file mode 100644 index 21efd7f..0000000 Binary files a/target/classes/de/butzlabben/world/wrapper/WorldTemplate 2.class and /dev/null differ diff --git a/target/classes/de/butzlabben/world/wrapper/WorldTemplateProvider 2.class b/target/classes/de/butzlabben/world/wrapper/WorldTemplateProvider 2.class deleted file mode 100644 index 3167ece..0000000 Binary files a/target/classes/de/butzlabben/world/wrapper/WorldTemplateProvider 2.class and /dev/null differ diff --git a/target/classes/org/bstats/bukkit/Metrics$1$1.class b/target/classes/org/bstats/bukkit/Metrics$1$1.class new file mode 100644 index 0000000..6f9d6ed Binary files /dev/null and b/target/classes/org/bstats/bukkit/Metrics$1$1.class differ diff --git a/target/classes/org/bstats/bukkit/Metrics$1.class b/target/classes/org/bstats/bukkit/Metrics$1.class new file mode 100644 index 0000000..af3eec8 Binary files /dev/null and b/target/classes/org/bstats/bukkit/Metrics$1.class differ diff --git a/target/classes/org/bstats/bukkit/Metrics$2.class b/target/classes/org/bstats/bukkit/Metrics$2.class new file mode 100644 index 0000000..d9b538b Binary files /dev/null and b/target/classes/org/bstats/bukkit/Metrics$2.class differ diff --git a/target/classes/org/bstats/bukkit/Metrics$AdvancedBarChart.class b/target/classes/org/bstats/bukkit/Metrics$AdvancedBarChart.class new file mode 100644 index 0000000..2f32b8d Binary files /dev/null and b/target/classes/org/bstats/bukkit/Metrics$AdvancedBarChart.class differ diff --git a/target/classes/org/bstats/bukkit/Metrics$AdvancedPie.class b/target/classes/org/bstats/bukkit/Metrics$AdvancedPie.class new file mode 100644 index 0000000..6860fbe Binary files /dev/null and b/target/classes/org/bstats/bukkit/Metrics$AdvancedPie.class differ diff --git a/target/classes/org/bstats/bukkit/Metrics$CustomChart.class b/target/classes/org/bstats/bukkit/Metrics$CustomChart.class new file mode 100644 index 0000000..6cea34c Binary files /dev/null and b/target/classes/org/bstats/bukkit/Metrics$CustomChart.class differ diff --git a/target/classes/org/bstats/bukkit/Metrics$DrilldownPie.class b/target/classes/org/bstats/bukkit/Metrics$DrilldownPie.class new file mode 100644 index 0000000..bc0534b Binary files /dev/null and b/target/classes/org/bstats/bukkit/Metrics$DrilldownPie.class differ diff --git a/target/classes/org/bstats/bukkit/Metrics$MultiLineChart.class b/target/classes/org/bstats/bukkit/Metrics$MultiLineChart.class new file mode 100644 index 0000000..62e079a Binary files /dev/null and b/target/classes/org/bstats/bukkit/Metrics$MultiLineChart.class differ diff --git a/target/classes/org/bstats/bukkit/Metrics$SimpleBarChart.class b/target/classes/org/bstats/bukkit/Metrics$SimpleBarChart.class new file mode 100644 index 0000000..02ef57c Binary files /dev/null and b/target/classes/org/bstats/bukkit/Metrics$SimpleBarChart.class differ diff --git a/target/classes/org/bstats/bukkit/Metrics$SimplePie.class b/target/classes/org/bstats/bukkit/Metrics$SimplePie.class new file mode 100644 index 0000000..c6c8993 Binary files /dev/null and b/target/classes/org/bstats/bukkit/Metrics$SimplePie.class differ diff --git a/target/classes/org/bstats/bukkit/Metrics$SingleLineChart.class b/target/classes/org/bstats/bukkit/Metrics$SingleLineChart.class new file mode 100644 index 0000000..43b29ab Binary files /dev/null and b/target/classes/org/bstats/bukkit/Metrics$SingleLineChart.class differ diff --git a/target/classes/org/bstats/bukkit/Metrics.class b/target/classes/org/bstats/bukkit/Metrics.class new file mode 100644 index 0000000..c33ca89 Binary files /dev/null and b/target/classes/org/bstats/bukkit/Metrics.class differ diff --git a/target/test-classes/de/butzlabben/world/config/TestPluginConfig.class b/target/test-classes/de/butzlabben/world/config/TestPluginConfig.class new file mode 100644 index 0000000..8e0cb7a Binary files /dev/null and b/target/test-classes/de/butzlabben/world/config/TestPluginConfig.class differ diff --git a/target/test-classes/de/butzlabben/world/data/TestWorldDatabase.class b/target/test-classes/de/butzlabben/world/data/TestWorldDatabase.class index 4ad9943..b34441d 100644 Binary files a/target/test-classes/de/butzlabben/world/data/TestWorldDatabase.class and b/target/test-classes/de/butzlabben/world/data/TestWorldDatabase.class differ