From 4d6a51bebb3af48c0a4ddf101c745186ac986240 Mon Sep 17 00:00:00 2001 From: Brianna Date: Sun, 26 May 2019 19:33:05 -0400 Subject: [PATCH] Removed API layer. Merged Legacy into Master. Redid HopTask system. Fixed issue preventing redstone from working with hoppers. Hoppers will now transfer items once per tick. HopTask is now at least 30% faster. The hopper filter void will now function at the same time as blacklist and whitelist. Fixed rare dupe glitch with suction. SettingManager overhaul. Support for PlayerPoints added. --- .gitlab-ci.yml | 4 +- EpicHoppers-API/pom.xml | 16 - .../songoda/epichoppers/api/EpicHoppers.java | 35 -- .../epichoppers/api/EpicHoppersAPI.java | 48 --- .../epichoppers/api/hopper/Filter.java | 25 -- .../epichoppers/api/hopper/Hopper.java | 125 ------ .../epichoppers/api/hopper/HopperManager.java | 24 -- .../epichoppers/api/hopper/levels/Level.java | 79 ---- .../api/hopper/levels/LevelManager.java | 63 --- .../api/hopper/levels/modules/Module.java | 25 -- EpicHoppers-Plugin/pom.xml | 211 --------- .../songoda/epichoppers/hook/HookManager.java | 98 ----- .../songoda/epichoppers/hook/HookType.java | 6 - .../hook/ProtectionPluginHook.java | 25 -- .../epichoppers/hook/hooks/HookASkyBlock.java | 71 --- .../epichoppers/hook/hooks/HookFactions.java | 56 --- .../hook/hooks/HookGriefPrevention.java | 51 --- .../epichoppers/hook/hooks/HookKingdoms.java | 62 --- .../hook/hooks/HookPlotSquared.java | 63 --- .../hook/hooks/HookRedProtect.java | 55 --- .../hook/hooks/HookSkyBlockEarth.java | 70 --- .../epichoppers/hook/hooks/HookTowny.java | 71 --- .../epichoppers/hook/hooks/HookUSkyBlock.java | 49 --- .../hook/hooks/HookWorldGuard.java | 55 --- .../songoda/epichoppers/tasks/HopTask.java | 403 ------------------ .../songoda/epichoppers/utils/Debugger.java | 31 -- .../epichoppers/utils/SettingsManager.java | 232 ---------- pom.xml | 100 ++++- .../com/songoda/epichoppers/EpicHoppers.java | 144 +++---- .../java/com/songoda/epichoppers/Locale.java | 2 +- .../com/songoda/epichoppers/References.java | 2 +- .../songoda/epichoppers/boost/BoostData.java | 0 .../epichoppers/boost/BoostManager.java | 0 .../epichoppers/command/AbstractCommand.java | 0 .../epichoppers/command/CommandManager.java | 0 .../epichoppers/command/TabManager.java | 0 .../command/commands/CommandBook.java | 0 .../command/commands/CommandBoost.java | 0 .../command/commands/CommandEpicHoppers.java | 0 .../command/commands/CommandGive.java | 0 .../command/commands/CommandReload.java | 0 .../command/commands/CommandSettings.java | 0 .../songoda/epichoppers/economy/Economy.java | 10 + .../economy/PlayerPointsEconomy.java | 36 ++ .../epichoppers/economy/VaultEconomy.java | 28 ++ .../epichoppers/enchantment/Enchantment.java | 0 .../songoda/epichoppers/gui/GUICrafting.java | 0 .../songoda/epichoppers/gui/GUIFilter.java | 0 .../songoda/epichoppers/gui/GUIOverview.java | 0 .../epichoppers/handlers/TeleportHandler.java | 0 .../songoda/epichoppers/hopper/Filter.java | 0 .../songoda/epichoppers/hopper/Hopper.java | 0 .../epichoppers/hopper/HopperManager.java | 0 .../epichoppers/hopper/levels/Level.java | 0 .../hopper/levels/LevelManager.java | 0 .../hopper/levels/modules/Module.java | 4 + .../levels/modules/ModuleAutoCrafting.java | 0 .../hopper/levels/modules/ModuleAutoSell.java | 0 .../levels/modules/ModuleBlockBreak.java | 0 .../hopper/levels/modules/ModuleSuction.java | 0 .../epichoppers/listeners/BlockListeners.java | 0 .../listeners/EntityListeners.java | 0 .../listeners/HopperListeners.java | 0 .../listeners/InteractListeners.java | 0 .../listeners/InventoryListeners.java | 0 .../epichoppers/player/PlayerData.java | 0 .../epichoppers/player/PlayerDataManager.java | 0 .../songoda/epichoppers/player/SyncType.java | 0 .../songoda/epichoppers/storage/Storage.java | 16 +- .../epichoppers/storage/StorageItem.java | 0 .../epichoppers/storage/StorageRow.java | 0 .../storage/types/StorageMysql.java | 7 +- .../storage/types/StorageYaml.java | 4 +- .../songoda/epichoppers/tasks/HopTask.java | 359 ++++++++++++++++ .../epichoppers/utils/ConfigWrapper.java | 0 .../songoda/epichoppers/utils}/CostType.java | 2 +- .../epichoppers/utils/HopperDirection.java | 60 +++ .../songoda/epichoppers/utils/Methods.java | 123 ++++-- .../songoda/epichoppers/utils/Metrics.java | 4 +- .../epichoppers/utils/MySQLDatabase.java | 6 +- .../epichoppers/utils/Serializers.java | 0 .../epichoppers/utils/ServerVersion.java | 27 ++ .../epichoppers/utils}/TeleportTrigger.java | 2 +- .../epichoppers/utils/gui/AbstractGUI.java | 0 .../epichoppers/utils/gui/Clickable.java | 0 .../epichoppers/utils/gui/OnClose.java | 0 .../songoda/epichoppers/utils/gui/Range.java | 0 .../epichoppers/utils/settings/Category.java | 29 ++ .../epichoppers/utils/settings/Setting.java | 300 +++++++++++++ .../utils/settings/SettingsManager.java | 309 ++++++++++++++ .../src => src}/main/resources/en_US.lang | 2 +- .../src => src}/main/resources/levels.yml | 0 .../src => src}/main/resources/plugin.yml | 2 +- 93 files changed, 1416 insertions(+), 2215 deletions(-) delete mode 100644 EpicHoppers-API/pom.xml delete mode 100644 EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/EpicHoppers.java delete mode 100644 EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/EpicHoppersAPI.java delete mode 100644 EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/Filter.java delete mode 100644 EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/Hopper.java delete mode 100644 EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/HopperManager.java delete mode 100644 EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/levels/Level.java delete mode 100644 EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/levels/LevelManager.java delete mode 100644 EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/levels/modules/Module.java delete mode 100644 EpicHoppers-Plugin/pom.xml delete mode 100644 EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/HookManager.java delete mode 100644 EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/HookType.java delete mode 100644 EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/ProtectionPluginHook.java delete mode 100644 EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookASkyBlock.java delete mode 100644 EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookFactions.java delete mode 100644 EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookGriefPrevention.java delete mode 100644 EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookKingdoms.java delete mode 100644 EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookPlotSquared.java delete mode 100644 EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookRedProtect.java delete mode 100644 EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookSkyBlockEarth.java delete mode 100644 EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookTowny.java delete mode 100644 EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookUSkyBlock.java delete mode 100644 EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookWorldGuard.java delete mode 100644 EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/tasks/HopTask.java delete mode 100644 EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/Debugger.java delete mode 100644 EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/SettingsManager.java rename EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/EpicHoppersPlugin.java => src/main/java/com/songoda/epichoppers/EpicHoppers.java (76%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/Locale.java (99%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/References.java (64%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/boost/BoostData.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/boost/BoostManager.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/command/AbstractCommand.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/command/CommandManager.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/command/TabManager.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/command/commands/CommandBook.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/command/commands/CommandBoost.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/command/commands/CommandEpicHoppers.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/command/commands/CommandGive.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/command/commands/CommandReload.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/command/commands/CommandSettings.java (100%) create mode 100644 src/main/java/com/songoda/epichoppers/economy/Economy.java create mode 100644 src/main/java/com/songoda/epichoppers/economy/PlayerPointsEconomy.java create mode 100644 src/main/java/com/songoda/epichoppers/economy/VaultEconomy.java rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/enchantment/Enchantment.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/gui/GUICrafting.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/gui/GUIFilter.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/gui/GUIOverview.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/handlers/TeleportHandler.java (100%) rename EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/EFilter.java => src/main/java/com/songoda/epichoppers/hopper/Filter.java (100%) rename EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/EHopper.java => src/main/java/com/songoda/epichoppers/hopper/Hopper.java (100%) rename EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/EHopperManager.java => src/main/java/com/songoda/epichoppers/hopper/HopperManager.java (100%) rename EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/levels/ELevel.java => src/main/java/com/songoda/epichoppers/hopper/levels/Level.java (100%) rename EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/levels/ELevelManager.java => src/main/java/com/songoda/epichoppers/hopper/levels/LevelManager.java (100%) create mode 100644 src/main/java/com/songoda/epichoppers/hopper/levels/modules/Module.java rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoCrafting.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoSell.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleBlockBreak.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleSuction.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/listeners/BlockListeners.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/listeners/EntityListeners.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/listeners/HopperListeners.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/listeners/InteractListeners.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/listeners/InventoryListeners.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/player/PlayerData.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/player/PlayerDataManager.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/player/SyncType.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/storage/Storage.java (81%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/storage/StorageItem.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/storage/StorageRow.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/storage/types/StorageMysql.java (96%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/storage/types/StorageYaml.java (97%) create mode 100644 src/main/java/com/songoda/epichoppers/tasks/HopTask.java rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/utils/ConfigWrapper.java (100%) rename {EpicHoppers-API/src/main/java/com/songoda/epichoppers/api => src/main/java/com/songoda/epichoppers/utils}/CostType.java (88%) create mode 100644 src/main/java/com/songoda/epichoppers/utils/HopperDirection.java rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/utils/Methods.java (69%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/utils/Metrics.java (99%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/utils/MySQLDatabase.java (93%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/utils/Serializers.java (100%) create mode 100644 src/main/java/com/songoda/epichoppers/utils/ServerVersion.java rename {EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper => src/main/java/com/songoda/epichoppers/utils}/TeleportTrigger.java (61%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/utils/gui/AbstractGUI.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/utils/gui/Clickable.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/utils/gui/OnClose.java (100%) rename {EpicHoppers-Plugin/src => src}/main/java/com/songoda/epichoppers/utils/gui/Range.java (100%) create mode 100644 src/main/java/com/songoda/epichoppers/utils/settings/Category.java create mode 100644 src/main/java/com/songoda/epichoppers/utils/settings/Setting.java create mode 100644 src/main/java/com/songoda/epichoppers/utils/settings/SettingsManager.java rename {EpicHoppers-Plugin/src => src}/main/resources/en_US.lang (97%) rename {EpicHoppers-Plugin/src => src}/main/resources/levels.yml (100%) rename {EpicHoppers-Plugin/src => src}/main/resources/plugin.yml (88%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8ca3695..4509caf 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ stages: variables: name: "EpicHoppers" path: "/builds/$CI_PROJECT_PATH" - version: "3.6.3" + version: "4-pre-release-1" build: stage: build @@ -14,7 +14,7 @@ build: - find $path/ -type f -name "*.yml" -print0 | xargs -0 sed -i -e s/maven-version-number/$version/g - mvn clean package - find $path/ -depth -path '*original*' -delete - - mv $path/$name-Plugin/target/*.jar $path/ + - mv $path/target/*.jar $path/ artifacts: name: $name-$version paths: diff --git a/EpicHoppers-API/pom.xml b/EpicHoppers-API/pom.xml deleted file mode 100644 index 143f7cd..0000000 --- a/EpicHoppers-API/pom.xml +++ /dev/null @@ -1,16 +0,0 @@ - - 4.0.0 - - - com.songoda - EpicHoppers-Parent - maven-version-number - - com.songoda - EpicHoppers-API - - clean install - EpicHoppers-API - - diff --git a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/EpicHoppers.java b/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/EpicHoppers.java deleted file mode 100644 index 4bd9b51..0000000 --- a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/EpicHoppers.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.songoda.epichoppers.api; - -import com.songoda.epichoppers.api.hopper.HopperManager; -import com.songoda.epichoppers.api.hopper.levels.Level; -import com.songoda.epichoppers.api.hopper.levels.LevelManager; -import org.bukkit.inventory.ItemStack; - -import java.util.function.Supplier; - -/** - * The main API class for the EpicHoppers plugin. This class will provide various - * methods to access important features of the plugin's API. For static method - * wrappers to all methods in this interface, see the {@link EpicHoppersAPI} class - */ -public interface EpicHoppers { - - Level getLevelFromItem(ItemStack item); - - ItemStack newHopperItem(Level level); - - /** - * Get an instance of the {@link LevelManager} - * - * @return the level manager - */ - LevelManager getLevelManager(); - - - /** - * Get an instance of the {@link HopperManager} - * - * @return the hopper manager - */ - HopperManager getHopperManager(); -} diff --git a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/EpicHoppersAPI.java b/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/EpicHoppersAPI.java deleted file mode 100644 index eefbdea..0000000 --- a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/EpicHoppersAPI.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.songoda.epichoppers.api; - - -import org.bukkit.ChatColor; - -/** - * The access point of the EpicHoppersAPI, a class acting as a bridge between API - * and plugin implementation. It is from here where developers should access the - * important and core methods in the API. All static methods in this class will - * call directly upon the implementation at hand (in most cases this will be the - * EpicHoppers plugin itself), therefore a call to {@link #getImplementation()} is - * not required and redundant in most situations. Method calls from this class are - * preferred the majority of time, though an instance of {@link EpicHoppers} may - * be passed if absolutely necessary. - * - * @see EpicHoppers - * @since 3.0.0 - */ -public class EpicHoppersAPI { - - private static EpicHoppers implementation; - - /** - * Set the EpicHoppers implementation. Once called for the first time, this - * method will throw an exception on any subsequent invocations. The implementation - * may only be set a single time, presumably by the EpicHoppers plugin - * - * @param implementation the implementation to set - */ - public static void setImplementation(EpicHoppers implementation) { - if (EpicHoppersAPI.implementation != null) { - throw new IllegalArgumentException("Cannot set API implementation twice"); - } - - EpicHoppersAPI.implementation = implementation; - } - - /** - * Get the EpicHoppers implementation. This method may be redundant in most - * situations as all methods present in {@link EpicHoppers} will be mirrored - * with static modifiers in the {@link EpicHoppersAPI} class - * - * @return the EpicHoppers implementation - */ - public static EpicHoppers getImplementation() { - return implementation; - } -} diff --git a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/Filter.java b/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/Filter.java deleted file mode 100644 index 2f04a69..0000000 --- a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/Filter.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.songoda.epichoppers.api.hopper; - -import org.bukkit.Location; -import org.bukkit.block.Block; -import org.bukkit.inventory.ItemStack; - -import java.util.List; - -public interface Filter { - List getWhiteList(); - - void setWhiteList(List whiteList); - - List getBlackList(); - - void setBlackList(List blackList); - - List getVoidList(); - - void setVoidList(List voidList); - - Location getEndPoint(); - - void setEndPoint(Location endPoint); -} diff --git a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/Hopper.java b/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/Hopper.java deleted file mode 100644 index 5d4f384..0000000 --- a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/Hopper.java +++ /dev/null @@ -1,125 +0,0 @@ -package com.songoda.epichoppers.api.hopper; - -import com.songoda.epichoppers.api.hopper.levels.Level; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; - -import java.util.List; -import java.util.UUID; - -public interface Hopper { - - /** - * This will link this hopper with another hopper. - * - * @param toSync the block containing the hopper - * that this hopper will be synchronized - * with - * @param filtered whether or not this action is for the - * filtered link or not - * @param player the player initializing the synchronization - */ - void link(Block toSync, boolean filtered, Player player); - - /** - * Get location of the hopper. - * - * @return location of spawner - */ - Location getLocation(); - - World getWorld(); - - /** - * Get the X coordinate for the hopper. - * - * @return X coordinate. - */ - int getX(); - - /** - * Get the Y coordinate for the shopper. - * - * @return Y coordinate. - */ - int getY(); - - /** - * Get the Z coordinate for the hopper. - * - * @return Z coordinate. - */ - int getZ(); - - /** - * Get the {@link Level} associated with this hopper. - * - * @return the hoppers level - */ - Level getLevel(); - - /** - * Get the player that placed this hopper. - * - * @return the player the placed this hopper. - */ - UUID getPlacedBy(); - - /** - * Get the player that last used this hopper. - * - * @return the last player - */ - UUID getLastPlayer(); - - /** - * Set the last player to use this hopper. - * - * @param uuid the last player - */ - void setLastPlayer(UUID uuid); - - /** - * Get the item being automatically crafted. - * - * @return item being crafted - */ - Material getAutoCrafting(); - - /** - * Set the Item being automatically crafted. - * - * @param autoCrafting item to craft - */ - void setAutoCrafting(Material autoCrafting); - - /** - * Get the teleport trigger is currently enabled. - * - * @return TeleportTrigger - */ - TeleportTrigger getTeleportTrigger(); - - /** - * Set which teleport trigger is currently enabled. - * - * @param teleportTrigger TeleportTrigger - */ - void setTeleportTrigger(TeleportTrigger teleportTrigger); - - List getLinkedBlocks(); - - void addLinkedBlock(Location block); - - void clearLinkedBlocks(); - - /** - * Get the filter associated with this hopper - * - * @return filter associated with this hopper - */ - Filter getFilter(); -} diff --git a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/HopperManager.java b/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/HopperManager.java deleted file mode 100644 index 7c4e3e0..0000000 --- a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/HopperManager.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.songoda.epichoppers.api.hopper; - -import org.bukkit.Location; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; - -import java.util.Map; - -public interface HopperManager { - - void addHopper(Location location, Hopper hopper); - - Hopper removeHopper(Location location); - - Hopper getHopper(Location location); - - Hopper getHopper(Block block); - - boolean isHopper(Location location); - - Map getHoppers(); - - Hopper getHopperFromPlayer(Player player); -} diff --git a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/levels/Level.java b/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/levels/Level.java deleted file mode 100644 index 4b4d1e1..0000000 --- a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/levels/Level.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.songoda.epichoppers.api.hopper.levels; - -import com.songoda.epichoppers.api.hopper.levels.modules.Module; - -import java.util.ArrayList; -import java.util.List; - -public interface Level { - - /** - * Get the current level in numerical format. - * - * @return level - */ - int getLevel(); - - /** - * Get the range that this Level will allow - * the applied hopper to remotely connect with - * another hopper. - * - * @return range - */ - int getRange(); - - /** - * Get the amount of items that will transfer - * between this hopper and the remotely connected - * hopper at a single time. - * - * @return amount - */ - int getAmount(); - - /** - * Whether or not the filter is enabled with this - * level. - * - * @return true if the filter is enabled, false - * otherwise - */ - boolean isFilter(); - - /** - * Whether or not teleporting through hoppers is - * enabled with this level. - * - * @return true if teleporting is enabled false - * otherwise - */ - boolean isTeleport(); - - - int getAutoSell(); - - int getLinkAmount(); - - /** - * Get the cost in experience in order to upgrade - * to this level. - * - * @return experience upgrade cost - */ - int getCostExperience(); - - /** - * Get the cost in economy in order to upgrade - * to this level. - * - * @return economy upgrade cost - */ - int getCostEconomy(); - - List getDescription(); - - ArrayList getRegisteredModules(); - - void addModule(Module module); -} diff --git a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/levels/LevelManager.java b/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/levels/LevelManager.java deleted file mode 100644 index d668a36..0000000 --- a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/levels/LevelManager.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.songoda.epichoppers.api.hopper.levels; - -import com.songoda.epichoppers.api.hopper.levels.modules.Module; - -import java.util.ArrayList; -import java.util.Map; - -public interface LevelManager { - - /** - * This will add a level to the level manager. These levels can be - * used when upgrading hoppers or giving hoppers with the built in - * "give" command. - * - * @param level The level of the hopper - * @param costExperience The cost in experience to upgrade the hopper - * @param costEconomy The cost in economy to upgrade the hopper - * @param range The range in which this hopper will need to be in order to link with another hopper - * @param amount The amount of items this hopper will transfer at a single time - * @param filter Whether or not access to the filter is allowed. - * @param teleport Whether or not teleporting through hoppers is allowed. - */ - void addLevel(int level, int costExperience, int costEconomy, int range, int amount, boolean filter, boolean teleport, int linkAmount, int autoSell, ArrayList modules); - - /** - * Get {@link Level} by corresponding integer value. - * - * @param level the integer level - * @return level object - */ - Level getLevel(int level); - - /** - * Get the lowest {@link Level} in the LevelManager. - * - * @return lowest level - */ - Level getLowestLevel(); - - - /** - * Get the highest {@link Level} in the LevelManager. - * - * @return high level - */ - Level getHighestLevel(); - - /** - * Whether or not this level exists. - * - * @param level the integer level - * @return true if a level, false otherwise - */ - boolean isLevel(int level); - - /** - * Get a unmodifiable map of the current level registered - * in the manager. - * - * @return map of levels. - */ - Map getLevels(); -} diff --git a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/levels/modules/Module.java b/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/levels/modules/Module.java deleted file mode 100644 index bde09a7..0000000 --- a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/levels/modules/Module.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.songoda.epichoppers.api.hopper.levels.modules; - -import com.songoda.epichoppers.api.hopper.Hopper; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; - -import java.util.List; - -public interface Module { - - String getName(); - - void run(Hopper hopper, Inventory hopperInventory); - - ItemStack getGUIButton(Hopper hopper); - - void runButtonPress(Player player, Hopper hopper); - - List getBlockedItems(Hopper hopper); - - String getDescription(); - -} diff --git a/EpicHoppers-Plugin/pom.xml b/EpicHoppers-Plugin/pom.xml deleted file mode 100644 index 7f304ac..0000000 --- a/EpicHoppers-Plugin/pom.xml +++ /dev/null @@ -1,211 +0,0 @@ - - 4.0.0 - - - com.songoda - EpicHoppers-Parent - maven-version-number - - - EpicHoppers-Plugin - - - - private - http://repo.songoda.com/artifactory/private - - - - - com.songoda - EpicHoppers-API - ${project.version} - compile - - - net.arcaniax - liquidtanks - 2.1.0 - provided - - - org - kingdoms - 13.0.9 - provided - - - net.milkbowl - vault - 1.7.1 - provided - - - me.ryanhamshire - GriefPrevention - 16.6 - provided - - - com.sk89q - worldedit - 7.0.0 - provided - - - com.sk89q - worldguard - 7.0.0 - provided - - - com - plotsquared - BREAKING - provided - - - com.songoda - fabledskyblock - 72 - provided - - - com.palmergames.bukkit - towny - 0.93.0.0 - provided - - - com.wasteofplastic - askyblock - 3.0.6.8 - provided - - - us.talabrek - ultimateskyblock - 2.7.2 - provided - - - me.markeh - factionsframework - 1.2.0 - provided - - - br.net.fabiozumbi12 - RedProtect - 7.3.0 - provided - - - com.gmail.nossr50 - mcmmo - 1.5.09 - provided - - - com.gamingmesh - jobs - 4.6.0 - provided - - - me.botsko - prism - 2.0.6 - provided - - - de.diddiz - logblock - 1.10.0 - provided - - - net - coreprotect - 2.14.2 - provided - - - uk.antiperson - stackmob - 2.2.6 - provided - - - net.sothatsit - blockstore - 1.5.0 - provided - - - org.black_ixx - playerpoints - 2.1.4 - provided - - - xyz.wildseries - wildstacker - b13 - provided - - - me.clip - placeholderapi - 2.5.1 - provided - - - - - clean install - EpicHoppers-${project.version} - - - com.google.code.maven-replacer-plugin - replacer - 1.5.3 - - - prepare-package - - replace - - - - - ${project.build.directory}/classes/plugin.yml - ${project.basedir}/../.gitlab-ci.yml - - - maven-version-number - ${project.version} - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.0 - - - package - - shade - - - false - - - - - - - diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/HookManager.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/HookManager.java deleted file mode 100644 index deb953a..0000000 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/HookManager.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.songoda.epichoppers.hook; - -import com.songoda.epichoppers.EpicHoppersPlugin; -import com.songoda.epichoppers.hook.hooks.*; -import com.songoda.epichoppers.utils.ConfigWrapper; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.java.JavaPlugin; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.Supplier; -import java.util.stream.Collectors; - -public class HookManager { - - private final EpicHoppersPlugin plugin; - - private ConfigWrapper hooksFile; - private List registeredHooks = new ArrayList<>(); - - public HookManager(EpicHoppersPlugin plugin) { - this.plugin = plugin; - this.hooksFile = new ConfigWrapper(plugin, "", "hooks.yml"); - this.hooksFile.createNewFile("Loading Hooks File", plugin.getDescription().getName() + " Hooks File"); - - PluginManager pluginManager = Bukkit.getPluginManager(); - - // Register default hooks - if (pluginManager.isPluginEnabled("ASkyBlock")) this.register(HookASkyBlock::new); - if (pluginManager.isPluginEnabled("FactionsFramework")) this.register(HookFactions::new); - if (pluginManager.isPluginEnabled("GriefPrevention")) this.register(HookGriefPrevention::new); - if (pluginManager.isPluginEnabled("Kingdoms")) this.register(HookKingdoms::new); - if (pluginManager.isPluginEnabled("PlotSquared")) this.register(HookPlotSquared::new); - if (pluginManager.isPluginEnabled("RedProtect")) this.register(HookRedProtect::new); - if (pluginManager.isPluginEnabled("Towny")) this.register(HookTowny::new); - if (pluginManager.isPluginEnabled("USkyBlock")) this.register(HookUSkyBlock::new); - if (pluginManager.isPluginEnabled("SkyBlock")) this.register(HookSkyBlockEarth::new); - if (pluginManager.isPluginEnabled("WorldGuard")) this.register(HookWorldGuard::new); - } - - public boolean canBuild(Player player, Location location) { - if (player.hasPermission(EpicHoppersPlugin.getInstance().getDescription().getName() + ".bypass")) return true; - - for (ProtectionPluginHook hook : registeredHooks) { - if (!hook.isInClaim(location)) continue; - - if (!hook.canBuild(player, location)) return false; - } - - return true; - } - - public boolean isInClaim(HookType hookType, String name, Location l) { - List hooks = registeredHooks.stream().filter(hook -> hook.getHookType() == hookType).collect(Collectors.toList()); - for (ProtectionPluginHook hook : hooks) { - if (hook.isInClaim(l, name)) { - return true; - } - } - return false; - } - - public String getClaimId(HookType hookType, String name) { - List hooks = registeredHooks.stream().filter(hook -> hook.getHookType() == hookType).collect(Collectors.toList()); - for (ProtectionPluginHook hook : hooks) { - return hook.getClaimID(name); - } - return null; - } - - - private ProtectionPluginHook register(Supplier hookSupplier) { - return this.registerProtectionHook(hookSupplier.get()); - } - - public ProtectionPluginHook registerProtectionHook(ProtectionPluginHook hook) { - if (hook != null && hook.getPlugin() != null) return null; - - JavaPlugin hookPlugin = hook.getPlugin(); - for (ProtectionPluginHook existingHook : registeredHooks) { - if (existingHook.getPlugin().equals(hookPlugin)) { - throw new IllegalArgumentException("Hook already registered"); - } - } - - this.hooksFile.getConfig().addDefault("hooks." + hookPlugin.getName(), true); - if (!hooksFile.getConfig().getBoolean("hooks." + hookPlugin.getName(), true)) return null; - this.hooksFile.getConfig().options().copyDefaults(true); - this.hooksFile.saveConfig(); - - this.registeredHooks.add(hook); - plugin.getLogger().info("Registered protection hook for plugin: " + hook.getPlugin().getName()); - return hook; - } -} diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/HookType.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/HookType.java deleted file mode 100644 index f51b98f..0000000 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/HookType.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.songoda.epichoppers.hook; - -public enum HookType { - - FACTION, TOWN, ISLAND, REGULAR -} diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/ProtectionPluginHook.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/ProtectionPluginHook.java deleted file mode 100644 index 7c25647..0000000 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/ProtectionPluginHook.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.songoda.epichoppers.hook; - -import org.bukkit.Location; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -public interface ProtectionPluginHook { - - JavaPlugin getPlugin(); - - HookType getHookType(); - - boolean canBuild(Player player, Location location); - - default boolean canBuild(Player player, Block block) { - return block != null && canBuild(player, block.getLocation()); - } - - boolean isInClaim(Location location); - - boolean isInClaim(Location location, String id); - - String getClaimID(String name); -} \ No newline at end of file diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookASkyBlock.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookASkyBlock.java deleted file mode 100644 index f99ae2a..0000000 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookASkyBlock.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.songoda.epichoppers.hook.hooks; - -import com.songoda.epichoppers.hook.HookType; -import com.songoda.epichoppers.hook.ProtectionPluginHook; -import com.wasteofplastic.askyblock.ASkyBlock; -import com.wasteofplastic.askyblock.ASkyBlockAPI; -import com.wasteofplastic.askyblock.Island; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -import java.util.List; -import java.util.Set; -import java.util.UUID; - -public class HookASkyBlock implements ProtectionPluginHook { - - private final ASkyBlockAPI skyblock; - - public HookASkyBlock() { - this.skyblock = ASkyBlockAPI.getInstance(); - } - - @Override - public JavaPlugin getPlugin() { - return ASkyBlock.getPlugin(); - } - - @Override - public HookType getHookType() { - return HookType.ISLAND; - } - - @Override - public boolean canBuild(Player player, Location location) { - Island island = skyblock.getIslandAt(location); - if (island == null) return true; - - UUID owner = island.getOwner(); - UUID playerUUID = player.getUniqueId(); - if (owner == null || owner.equals(playerUUID)) return true; - - List teamMembers = skyblock.getTeamMembers(owner); - if (teamMembers.contains(playerUUID)) return true; - - Set coopIslands = skyblock.getCoopIslands(player); - for (Location islandLocation : coopIslands) { - if (skyblock.getIslandAt(islandLocation).getOwner().equals(playerUUID)) { - return true; - } - } - - return false; - } - - @Override - public boolean isInClaim(Location location) { - return skyblock.getIslandAt(location) != null; - } - - @Override - public boolean isInClaim(Location location, String id) { - return skyblock.getOwner(location).toString().equals(id); - } - - @Override - public String getClaimID(String name) { - return null; - } - -} \ No newline at end of file diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookFactions.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookFactions.java deleted file mode 100644 index aac5762..0000000 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookFactions.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.songoda.epichoppers.hook.hooks; - -import com.songoda.epichoppers.hook.HookType; -import com.songoda.epichoppers.hook.ProtectionPluginHook; -import me.markeh.factionsframework.FactionsFramework; -import me.markeh.factionsframework.entities.FPlayer; -import me.markeh.factionsframework.entities.FPlayers; -import me.markeh.factionsframework.entities.Faction; -import me.markeh.factionsframework.entities.Factions; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -public class HookFactions implements ProtectionPluginHook { - - private final FactionsFramework factions; - - public HookFactions() { - this.factions = FactionsFramework.get(); - } - - @Override - public JavaPlugin getPlugin() { - return factions; - } - - @Override - public HookType getHookType() { - return HookType.FACTION; - } - - @Override - public boolean canBuild(Player player, Location location) { - FPlayer fPlayer = FPlayers.getBySender(player); - Faction faction = Factions.getFactionAt(location); - - return faction.isNone() || fPlayer.getFaction().equals(faction); - } - - @Override - public boolean isInClaim(Location location) { - return !Factions.getFactionAt(location).isNone(); - } - - @Override - public boolean isInClaim(Location location, String id) { - return Factions.getFactionAt(location).getId().equals(id); - } - - @Override - public String getClaimID(String name) { - Faction faction = Factions.getByName(name, ""); - return (faction != null) ? faction.getId() : null; - } - -} \ No newline at end of file diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookGriefPrevention.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookGriefPrevention.java deleted file mode 100644 index d8e808f..0000000 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookGriefPrevention.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.songoda.epichoppers.hook.hooks; - -import com.songoda.epichoppers.hook.HookType; -import com.songoda.epichoppers.hook.ProtectionPluginHook; -import me.ryanhamshire.GriefPrevention.Claim; -import me.ryanhamshire.GriefPrevention.GriefPrevention; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -public class HookGriefPrevention implements ProtectionPluginHook { - - private final GriefPrevention griefPrevention; - - public HookGriefPrevention() { - this.griefPrevention = GriefPrevention.instance; - } - - @Override - public JavaPlugin getPlugin() { - return griefPrevention; - } - - @Override - public HookType getHookType() { - return HookType.REGULAR; - } - - @Override - public boolean canBuild(Player player, Location location) { - Claim claim = griefPrevention.dataStore.getClaimAt(location, false, null); - return claim != null && claim.allowBuild(player, Material.HOPPER) == null; - } - - @Override - public boolean isInClaim(Location location) { - return griefPrevention.dataStore.getClaimAt(location, false, null) != null; - } - - @Override - public boolean isInClaim(Location location, String id) { - return false; - } - - @Override - public String getClaimID(String name) { - return null; - } - -} \ No newline at end of file diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookKingdoms.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookKingdoms.java deleted file mode 100644 index b9801d8..0000000 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookKingdoms.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.songoda.epichoppers.hook.hooks; - -import com.songoda.epichoppers.hook.HookType; -import com.songoda.epichoppers.hook.ProtectionPluginHook; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; -import org.kingdoms.constants.land.Land; -import org.kingdoms.constants.land.SimpleChunkLocation; -import org.kingdoms.constants.player.KingdomPlayer; -import org.kingdoms.main.Kingdoms; -import org.kingdoms.manager.game.GameManagement; - -public class HookKingdoms implements ProtectionPluginHook { - - private final Kingdoms kingdoms; - - public HookKingdoms() { - this.kingdoms = Kingdoms.getInstance(); - } - - @Override - public JavaPlugin getPlugin() { - return kingdoms; - } - - @Override - public HookType getHookType() { - return HookType.REGULAR; - } - - @Override - public boolean canBuild(Player player, Location location) { - KingdomPlayer kPlayer = GameManagement.getPlayerManager().getOfflineKingdomPlayer(player).getKingdomPlayer(); - if (kPlayer.getKingdom() == null) return true; - - SimpleChunkLocation chunkLocation = new SimpleChunkLocation(location.getChunk()); - Land land = GameManagement.getLandManager().getOrLoadLand(chunkLocation); - String owner = land.getOwner(); - - return owner == null || kPlayer.getKingdom().getKingdomName().equals(owner); - } - - @Override - public boolean isInClaim(Location location) { - SimpleChunkLocation chunkLocation = new SimpleChunkLocation(location.getChunk()); - Land land = GameManagement.getLandManager().getOrLoadLand(chunkLocation); - String owner = land.getOwner(); - return owner != null; - } - - @Override - public boolean isInClaim(Location location, String id) { - return false; - } - - @Override - public String getClaimID(String name) { - return null; - } - -} \ No newline at end of file diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookPlotSquared.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookPlotSquared.java deleted file mode 100644 index bc3a2e6..0000000 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookPlotSquared.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.songoda.epichoppers.hook.hooks; - -import com.github.intellectualsites.plotsquared.api.PlotAPI; -import com.github.intellectualsites.plotsquared.bukkit.BukkitMain; -import com.github.intellectualsites.plotsquared.plot.object.Plot; -import com.songoda.epichoppers.hook.HookType; -import com.songoda.epichoppers.hook.ProtectionPluginHook; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -public class HookPlotSquared implements ProtectionPluginHook { - - private final PlotAPI plotSquared; - - public HookPlotSquared() { - this.plotSquared = new PlotAPI(); - } - - @Override - public JavaPlugin getPlugin() { // BukkitMain? Really? - return JavaPlugin.getPlugin(BukkitMain.class); - } - - @Override - public HookType getHookType() { - return HookType.REGULAR; - } - - @Override - public boolean canBuild(Player player, Location location) { - com.github.intellectualsites.plotsquared.plot.object.Location plotLocation = - new com.github.intellectualsites.plotsquared.plot.object.Location(location.getWorld().getName(), - location.getBlockX(), location.getBlockY(), location.getBlockZ()); - - Plot plot = plotLocation.getPlot(); - - return plot != null - && plot.getOwners().contains(player.getUniqueId()) - && plot.getMembers().contains(player.getUniqueId()); - } - - @Override - public boolean isInClaim(Location location) { - com.github.intellectualsites.plotsquared.plot.object.Location plotLocation = - new com.github.intellectualsites.plotsquared.plot.object.Location(location.getWorld().getName(), - location.getBlockX(), location.getBlockY(), location.getBlockZ()); - - Plot plot = plotLocation.getPlot(); - return plot != null; - } - - @Override - public boolean isInClaim(Location location, String id) { - return false; - } - - @Override - public String getClaimID(String name) { - return null; - } - -} \ No newline at end of file diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookRedProtect.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookRedProtect.java deleted file mode 100644 index e4399de..0000000 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookRedProtect.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.songoda.epichoppers.hook.hooks; - -import br.net.fabiozumbi12.RedProtect.Bukkit.API.RedProtectAPI; -import br.net.fabiozumbi12.RedProtect.Bukkit.RedProtect; -import br.net.fabiozumbi12.RedProtect.Bukkit.Region; -import com.songoda.epichoppers.hook.HookType; -import com.songoda.epichoppers.hook.ProtectionPluginHook; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -public class HookRedProtect implements ProtectionPluginHook { - - private final RedProtect redProtect; - - public HookRedProtect() { - this.redProtect = RedProtect.get(); - } - - @Override - public JavaPlugin getPlugin() { - return redProtect; - } - - @Override - public HookType getHookType() { - return HookType.REGULAR; - } - - @Override - public boolean canBuild(Player player, Location location) { - RedProtectAPI api = redProtect.getAPI(); - Region region = api.getRegion(location); - - return region != null && region.canBuild(player); - } - - @Override - public boolean isInClaim(Location location) { - RedProtectAPI api = redProtect.getAPI(); - Region region = api.getRegion(location); - return region != null; - } - - @Override - public boolean isInClaim(Location location, String id) { - return false; - } - - @Override - public String getClaimID(String name) { - return null; - } - -} \ No newline at end of file diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookSkyBlockEarth.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookSkyBlockEarth.java deleted file mode 100644 index 8ad5fdf..0000000 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookSkyBlockEarth.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.songoda.epichoppers.hook.hooks; - -import com.songoda.epichoppers.hook.HookType; -import com.songoda.epichoppers.hook.ProtectionPluginHook; -import me.goodandevil.skyblock.SkyBlock; -import me.goodandevil.skyblock.island.Island; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -import java.util.List; -import java.util.Set; -import java.util.UUID; - -public class HookSkyBlockEarth implements ProtectionPluginHook { - - private final SkyBlock skyblock; - - public HookSkyBlockEarth() { - this.skyblock = SkyBlock.getInstance(); - } - - @Override - public JavaPlugin getPlugin() { - return SkyBlock.getInstance(); - } - - @Override - public HookType getHookType() { - return HookType.ISLAND; - } - - @Override - public boolean canBuild(Player player, Location location) { - Island island = skyblock.getIslandManager().getIslandAtLocation(location); - if (island == null) return true; - - UUID owner = island.getOwnerUUID(); - UUID playerUUID = player.getUniqueId(); - if (owner == null || owner.equals(playerUUID)) return true; - - Set teamMembers = island.getCoopPlayers(); - if (teamMembers.contains(playerUUID)) return true; - - List coopIslands = skyblock.getIslandManager().getCoopIslands(player); - for (Island is : coopIslands) { - if (is.getOwnerUUID().equals(playerUUID)) { - return true; - } - } - - return false; - } - - @Override - public boolean isInClaim(Location location) { - return skyblock.getIslandManager().getIslandAtLocation(location) != null; - } - - @Override - public boolean isInClaim(Location location, String id) { - return skyblock.getIslandManager().getIslandAtLocation(location).getOwnerUUID().toString().equals(id); - } - - @Override - public String getClaimID(String name) { - return null; - } - -} \ No newline at end of file diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookTowny.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookTowny.java deleted file mode 100644 index 4cd7232..0000000 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookTowny.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.songoda.epichoppers.hook.hooks; - -import com.palmergames.bukkit.towny.Towny; -import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; -import com.palmergames.bukkit.towny.object.Resident; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.songoda.epichoppers.hook.HookType; -import com.songoda.epichoppers.hook.ProtectionPluginHook; -import com.songoda.epichoppers.utils.Debugger; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -public class HookTowny implements ProtectionPluginHook { - - private final Towny towny; - - public HookTowny() { - this.towny = Towny.getPlugin(); - } - - @Override - public JavaPlugin getPlugin() { - return towny; - } - - @Override - public HookType getHookType() { - return HookType.TOWN; - } - - @Override - public boolean canBuild(Player player, Location location) { - if (TownyUniverse.isWilderness(location.getBlock()) || !TownyUniverse.getTownBlock(location).hasTown()) - return true; - - try { - Resident resident = TownyUniverse.getDataSource().getResident(player.getName()); - return resident.hasTown() && TownyUniverse.getTownName(location).equals(resident.getTown().getName()); - } catch (NotRegisteredException e) { - Debugger.runReport(e); - return false; - } - } - - @Override - public boolean isInClaim(Location location) { - return !TownyUniverse.isWilderness(location.getBlock()); - } - - @Override - public boolean isInClaim(Location location, String id) { - try { - return (!TownyUniverse.isWilderness(location.getBlock())) && TownyUniverse.getTownBlock(location).getTown().getUID().toString().equals(id); - } catch (NotRegisteredException e) { - Debugger.runReport(e); - return false; - } - } - - @Override - public String getClaimID(String name) { - try { - return TownyUniverse.getDataSource().getTown(name).getUID().toString(); - } catch (NotRegisteredException e) { - Debugger.runReport(e); - return null; - } - } - -} \ No newline at end of file diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookUSkyBlock.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookUSkyBlock.java deleted file mode 100644 index 32f8fab..0000000 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookUSkyBlock.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.songoda.epichoppers.hook.hooks; - -import com.songoda.epichoppers.hook.HookType; -import com.songoda.epichoppers.hook.ProtectionPluginHook; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; -import us.talabrek.ultimateskyblock.api.uSkyBlockAPI; - -public class HookUSkyBlock implements ProtectionPluginHook { - - private final uSkyBlockAPI uSkyblock; - - public HookUSkyBlock() { - this.uSkyblock = (uSkyBlockAPI) Bukkit.getPluginManager().getPlugin("USkyBlock"); - } - - @Override - public JavaPlugin getPlugin() { // uSkyBlockAPI is also an instance of JavaPlugin - return (JavaPlugin) uSkyblock; - } - - @Override - public HookType getHookType() { - return HookType.ISLAND; - } - - @Override - public boolean canBuild(Player player, Location location) { - return uSkyblock.getIslandInfo(location).getOnlineMembers().contains(player) || uSkyblock.getIslandInfo(location).isLeader(player); - } - - @Override - public boolean isInClaim(Location location) { - return uSkyblock.getIslandInfo(location) != null; - } - - @Override - public boolean isInClaim(Location location, String id) { - return uSkyblock.getIslandInfo(location).getLeader().equals(id); - } - - @Override - public String getClaimID(String name) { - return null; - } - -} \ No newline at end of file diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookWorldGuard.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookWorldGuard.java deleted file mode 100644 index b808072..0000000 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hook/hooks/HookWorldGuard.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.songoda.epichoppers.hook.hooks; - -import com.sk89q.worldedit.bukkit.BukkitAdapter; -import com.sk89q.worldguard.WorldGuard; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.protection.ApplicableRegionSet; -import com.sk89q.worldguard.protection.flags.Flags; -import com.sk89q.worldguard.protection.regions.RegionQuery; -import com.songoda.epichoppers.hook.HookType; -import com.songoda.epichoppers.hook.ProtectionPluginHook; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -public class HookWorldGuard implements ProtectionPluginHook { - - private final WorldGuard worldGuard; - - public HookWorldGuard() { - this.worldGuard = WorldGuard.getInstance(); - } - - @Override - public JavaPlugin getPlugin() { - return WorldGuardPlugin.inst(); - } - - @Override - public HookType getHookType() { - return HookType.REGULAR; - } - - @Override - public boolean canBuild(Player player, Location location) { - RegionQuery q = worldGuard.getPlatform().getRegionContainer().createQuery(); - ApplicableRegionSet ars = q.getApplicableRegions(BukkitAdapter.adapt(player.getLocation())); - return ars.testState(WorldGuardPlugin.inst().wrapPlayer(player), Flags.BUILD); - } - - @Override - public boolean isInClaim(Location location) { - return true; - } - - @Override - public boolean isInClaim(Location location, String id) { - return false; - } - - @Override - public String getClaimID(String name) { - return null; - } - -} \ No newline at end of file diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/tasks/HopTask.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/tasks/HopTask.java deleted file mode 100644 index d6dc3f2..0000000 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/tasks/HopTask.java +++ /dev/null @@ -1,403 +0,0 @@ -package com.songoda.epichoppers.tasks; - -import com.songoda.epichoppers.EpicHoppersPlugin; -import com.songoda.epichoppers.api.hopper.levels.modules.Module; -import com.songoda.epichoppers.boost.BoostData; -import com.songoda.epichoppers.utils.SettingsManager; -import me.goodandevil.skyblock.SkyBlock; -import me.goodandevil.skyblock.stackable.Stackable; -import me.goodandevil.skyblock.stackable.StackableManager; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.OfflinePlayer; -import org.bukkit.block.Block; -import org.bukkit.block.BlockState; -import org.bukkit.block.Hopper; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.minecart.HopperMinecart; -import org.bukkit.entity.minecart.StorageMinecart; -import org.bukkit.inventory.*; -import org.bukkit.scheduler.BukkitRunnable; - -import java.util.*; - -/** - * Created by songoda on 3/14/2017. - */ -public class HopTask extends BukkitRunnable { - - // Hop to the bop to the be bop top. - - private static EpicHoppersPlugin plugin; - - public HopTask(EpicHoppersPlugin plug) { - plugin = plug; - runTaskTimer(plugin, 0, SettingsManager.Setting.HOP_TICKS.getInt()); - } - - @Override - public void run() { - main: - for (com.songoda.epichoppers.api.hopper.Hopper hopper : new HashMap<>(plugin.getHopperManager().getHoppers()).values()) { - Location location = hopper.getLocation(); - - if (location.getWorld() == null || !location.getWorld().isChunkLoaded(location.getBlockX() >> 4, location.getBlockZ() >> 4)) - continue; - - Block block = location.getBlock(); - - if (block.getType() != Material.HOPPER) { - plugin.getHopperManager().removeHopper(location); - continue; - } - - if (block.isBlockPowered() || block.isBlockIndirectlyPowered()) continue; - - Hopper hopperState = (Hopper) block.getState(); - Inventory hopperInventory = hopperState.getInventory(); - - List blockedMaterials = new ArrayList<>(); - - for (Module module : hopper.getLevel().getRegisteredModules()) { - // Run Module - module.run(hopper, hopperInventory); - - // Add banned materials to list. - List materials = module.getBlockedItems(hopper); - if (materials == null || materials.isEmpty()) continue; - blockedMaterials.addAll(materials); - } - - // Fetch all hopper contents. - ItemStack[] hopperContents = hopperInventory.getContents(); - - // Get hopper orientation. - HopperDirection hopperDirection = HopperDirection.getDirection(hopperState.getRawData()); - Location check = hopperDirection.getLocation(location); - - Inventory override = null; - List linked = hopper.getLinkedBlocks(); - - if (hopper.getLinkedBlocks() == null || hopper.getLinkedBlocks().isEmpty()) { - - linked.add(check); - - Collection nearbyEntities = hopper.getLocation().getWorld().getNearbyEntities(check, .5, .5, .5); - - for (Entity entity : nearbyEntities) { - if (entity.getType() == EntityType.MINECART_HOPPER) - override = ((HopperMinecart) entity).getInventory(); - else if (entity.getType() == EntityType.MINECART_CHEST) - override = ((StorageMinecart) entity).getInventory(); - } - - if (linked.isEmpty()) continue; - } - - - // Support for FabledSkyBlock stackables. - if (Bukkit.getPluginManager().isPluginEnabled("FabledSkyBlock")) { - StackableManager stackableManager = SkyBlock.getInstance().getStackableManager(); - if (stackableManager != null && stackableManager.isStacked(check)) { - Stackable stackable = stackableManager.getStack(check, check.getBlock().getType()); - - for (int i = 0; i < 5; i++) { - if (hopperContents[i] == null) continue; - ItemStack item = hopperContents[i].clone(); - - if (item.getType() == stackable.getMaterial()) { - stackable.addOne(); - if (item.getAmount() == 1) { - hopperInventory.setItem(i, null); - } else { - item.setAmount(item.getAmount() - 1); - hopperInventory.setItem(i, item); - } - return; - } - } - } - } - - for (Location destinationLocation : linked) { - Block destinationBlock = destinationLocation.getBlock(); - Inventory destinationInventory = override; - if (override == null) { - - if (!destinationLocation.getWorld().isChunkLoaded(destinationLocation.getBlockX() >> 4, - destinationLocation.getBlockZ() >> 4)) - continue; - - destinationBlock = destinationLocation.getBlock(); - BlockState state = destinationBlock.getState(); - if (!(state instanceof InventoryHolder)) { - hopper.clearLinkedBlocks(); - continue; - } - destinationInventory = ((InventoryHolder) state).getInventory(); - } - - BoostData boostData = plugin.getBoostManager().getBoost(hopper.getPlacedBy()); - - int amount = hopper.getLevel().getAmount() * (boostData == null ? 1 : boostData.getMultiplier()); - - List whiteList = hopper.getFilter().getWhiteList(); - List blackList = hopper.getFilter().getBlackList(); - - for (int i = 0; i < 5; i++) { - if (hopperContents[i] == null) continue; - - ItemStack item = hopperContents[i].clone(); - item.setAmount(1); - - if (hopper.getLocation().getBlock().isBlockPowered() - || hopperContents[i] != null && blockedMaterials.contains(hopperContents[i].getType())) { - continue; - } - - int finalIncrement = i; - - if (!whiteList.isEmpty() - && whiteList.stream().noneMatch(itemStack -> itemStack.isSimilar(hopperContents[finalIncrement]))) { - doBlacklist(hopperInventory, hopper, hopperContents[i].clone(), amount, i); - continue main; - } - - if (blackList.stream().noneMatch(itemStack -> itemStack.isSimilar(hopperContents[finalIncrement]))) { - if (addItem(hopperInventory, hopper, destinationInventory, destinationBlock, hopperContents[i], amount, i)) { - continue main; - } - } else { - doBlacklist(hopperInventory, hopper, hopperContents[i].clone(), amount, i); - continue main; - } - } - } - } - } - - - private void doBlacklist(Inventory hopperInventory, com.songoda.epichoppers.api.hopper.Hopper hopper, ItemStack item, int amt, int place) { - Location dest = hopper.getFilter().getEndPoint(); - if (hopper.getFilter().getEndPoint() == null) return; - if (!dest.getWorld().isChunkLoaded(dest.getBlockX() >> 4, dest.getBlockZ() >> 4)) - return; - - Block destinationBlock = dest.getBlock(); - BlockState state = destinationBlock.getState(); - if (!(state instanceof InventoryHolder)) { - hopper.getFilter().setEndPoint(null); - return; - } - Inventory destinationInventory = ((InventoryHolder) state).getInventory(); - - addItem(hopperInventory, hopper, destinationInventory, destinationBlock, item, amt, place); - } - - private boolean addItem(Inventory hopperInventory, com.songoda.epichoppers.api.hopper.Hopper hopper, Inventory destinationInventory, Block destinationBlock, ItemStack is, int amt, int place) { - ItemStack it = null; - if (is != null) { - it = is.clone(); - it.setAmount(1); - } - - List ovoid = new ArrayList<>(hopper.getFilter().getVoidList()); - - if (is.getType() == Material.AIR) { - return true; - } - ItemStack item = is; - ItemStack newItem = is.clone(); - - if ((item.getAmount() - amt) <= 0) { - amt = item.getAmount(); - } - if ((item.getAmount() - amt) >= 1) { - newItem.setAmount(newItem.getAmount() - amt); - is = newItem.clone(); - } else { - is = null; - } - - newItem.setAmount(amt); - - if (destinationBlock.getType().equals(Material.ENDER_CHEST)) { - OfflinePlayer op = Bukkit.getOfflinePlayer(hopper.getPlacedBy()); - - if (op.isOnline() && canMove(op.getPlayer().getEnderChest(), newItem)) { - ItemStack finalIt = it; - if (ovoid.stream().noneMatch(itemStack -> itemStack.isSimilar(finalIt))) { - op.getPlayer().getEnderChest().addItem(newItem); - } - hopperInventory.setItem(place, is); - } - return true; - } - - switch (destinationBlock.getType()) { - case BLACK_SHULKER_BOX: - case BLUE_SHULKER_BOX: - case BROWN_SHULKER_BOX: - case CYAN_SHULKER_BOX: - case GRAY_SHULKER_BOX: - case GREEN_SHULKER_BOX: - case LIGHT_BLUE_SHULKER_BOX: - case LIGHT_GRAY_SHULKER_BOX: - case LIME_SHULKER_BOX: - case MAGENTA_SHULKER_BOX: - case ORANGE_SHULKER_BOX: - case PINK_SHULKER_BOX: - case PURPLE_SHULKER_BOX: - case RED_SHULKER_BOX: - case SHULKER_BOX: - case WHITE_SHULKER_BOX: - case YELLOW_SHULKER_BOX: - return false; - case BREWING_STAND: { - BrewerInventory brewerInventory = (BrewerInventory) destinationInventory; - - int maxSize = newItem.getMaxStackSize(); - - String typeStr = item.getType().name().toUpperCase(); - boolean isBottle = typeStr.contains("POTION") || typeStr.contains("BOTTLE") || item.getType() == Material.DRAGON_BREATH; - boolean isLeft = item.getType() == Material.BLAZE_POWDER; - - Map output = new HashMap<>(); - if (isBottle) { - output.put(0, brewerInventory.getItem(0)); - output.put(1, brewerInventory.getItem(1)); - output.put(2, brewerInventory.getItem(2)); - } else if (isLeft) { - output.put(4, brewerInventory.getItem(4)); - } else { - output.put(3, brewerInventory.getItem(3)); - } - - ItemStack finalIt = it; - for (Map.Entry entry : output.entrySet()) { - if (ovoid.stream().noneMatch(itemStack -> itemStack.isSimilar(finalIt))) { - ItemStack currentOutput = entry.getValue(); - int currentOutputAmount = currentOutput == null ? 0 : currentOutput.getAmount(); - if (currentOutput != null && (!currentOutput.isSimilar(newItem)) - || currentOutputAmount + newItem.getAmount() > maxSize) continue; - - if (currentOutput != null) { - currentOutput.setAmount(currentOutputAmount + newItem.getAmount()); - } else { - currentOutput = newItem.clone(); - } - - brewerInventory.setItem(entry.getKey(), currentOutput); - } - hopperInventory.setItem(place, is); - return true; - } - break; - } - case FURNACE: { - FurnaceInventory furnaceInventory = (FurnaceInventory) destinationInventory; - - boolean isFuel = item.getType().isFuel() && !item.getType().name().contains("LOG"); - ItemStack output = isFuel ? furnaceInventory.getFuel() : furnaceInventory.getSmelting(); - if (output != null && !output.isSimilar(newItem)) return false; - int maxSize = newItem.getMaxStackSize(); - int currentOutputAmount = output == null ? 0 : output.getAmount(); - - if (currentOutputAmount + newItem.getAmount() <= maxSize) { - ItemStack finalIt = it; - if (ovoid.stream().noneMatch(itemStack -> itemStack.isSimilar(finalIt))) { - if (output != null) { - output.setAmount(currentOutputAmount + newItem.getAmount()); - } else { - output = newItem.clone(); - } - if (isFuel) { - furnaceInventory.setFuel(output); - } else { - furnaceInventory.setSmelting(output); - } - hopperInventory.setItem(place, is); - } - } - return true; - } - } - - if (!canMove(destinationInventory, newItem)) return false; - ItemStack finalIt = it; - if (ovoid.stream().noneMatch(itemStack -> itemStack.isSimilar(finalIt))) { - destinationInventory.addItem(newItem); - } - hopperInventory.setItem(place, is); - return true; - } - - private boolean canMove(Inventory inventory, ItemStack item) { - if (inventory.firstEmpty() != -1) return true; - for (ItemStack stack : inventory.getContents()) { - if (stack.isSimilar(item) && (stack.getAmount() + item.getAmount()) - 1 < stack.getMaxStackSize()) { - return true; - } - } - return false; - } - - public enum HopperDirection { - - DOWN(0, 8, 0, -1, 0), - NORTH(2, 10, 0, 0, -1), - SOUTH(3, 11, 0, 0, 1), - WEST(4, 12, -1, 0, 0), - EAST(5, 13, 1, 0, 0); - - private int unpowered; - private int powered; - - private int x; - private int y; - private int z; - - HopperDirection(int unpowered, int powered, int x, int y, int z) { - this.unpowered = unpowered; - this.powered = powered; - - this.x = x; - this.y = y; - this.z = z; - } - - public static HopperDirection getDirection(int value) { - for (HopperDirection hopperDirection : HopperDirection.values()) { - if (hopperDirection.getPowered() == value - || hopperDirection.getUnpowered() == value) return hopperDirection; - } - return null; - } - - public Location getLocation(Location location) { - return location.add(getX(), getY(), getZ()); - } - - public int getX() { - return x; - } - - public int getY() { - return y; - } - - public int getZ() { - return z; - } - - public int getUnpowered() { - return unpowered; - } - - public int getPowered() { - return powered; - } - } -} \ No newline at end of file diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/Debugger.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/Debugger.java deleted file mode 100644 index a5a11ca..0000000 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/Debugger.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.songoda.epichoppers.utils; - -import com.songoda.epichoppers.EpicHoppersPlugin; - -/** - * Created by songoda on 3/21/2017. - */ -public class Debugger { - - - public static void runReport(Exception e) { - if (isDebug()) { - System.out.println("=============================================================="); - System.out.println("The following is an error encountered in EpicHoppers."); - System.out.println("--------------------------------------------------------------"); - e.printStackTrace(); - System.out.println("=============================================================="); - } - sendReport(e); - } - - public static void sendReport(Exception e) { - - } - - public static boolean isDebug() { - EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance(); - return instance.getConfig().getBoolean("System.Debugger Enabled"); - } - -} diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/SettingsManager.java b/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/SettingsManager.java deleted file mode 100644 index 588fc1b..0000000 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/SettingsManager.java +++ /dev/null @@ -1,232 +0,0 @@ -package com.songoda.epichoppers.utils; - -import com.songoda.epichoppers.EpicHoppersPlugin; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.configuration.file.FileConfiguration; -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.player.AsyncPlayerChatEvent; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -import java.util.*; -import java.util.regex.Pattern; - -/** - * Created by songo on 6/4/2017. - */ -public class SettingsManager implements Listener { - - private static final Pattern SETTINGS_PATTERN = Pattern.compile("(.{1,28}(?:\\s|$))|(.{0,28})", Pattern.DOTALL); - private final EpicHoppersPlugin instance; - private String pluginName = "EpicHoppers"; - private Map cat = new HashMap<>(); - private Map current = new HashMap<>(); - - public SettingsManager(EpicHoppersPlugin plugin) { - this.instance = plugin; - Bukkit.getPluginManager().registerEvents(this, plugin); - } - - @EventHandler - public void onInventoryClick(InventoryClickEvent event) { - ItemStack clickedItem = event.getCurrentItem(); - - if (event.getInventory() != event.getWhoClicked().getOpenInventory().getTopInventory() - || clickedItem == null || !clickedItem.hasItemMeta() - || !clickedItem.getItemMeta().hasDisplayName()) { - return; - } - - if (event.getView().getTitle().equals(pluginName + " Settings Manager")) { - event.setCancelled(true); - if (clickedItem.getType().name().contains("STAINED_GLASS")) return; - - String type = ChatColor.stripColor(clickedItem.getItemMeta().getDisplayName()); - this.cat.put((Player) event.getWhoClicked(), type); - this.openEditor((Player) event.getWhoClicked()); - } else if (event.getView().getTitle().equals(pluginName + " Settings Editor")) { - event.setCancelled(true); - if (clickedItem.getType().name().contains("STAINED_GLASS")) return; - - Player player = (Player) event.getWhoClicked(); - - String key = cat.get(player) + "." + ChatColor.stripColor(clickedItem.getItemMeta().getDisplayName()); - - if (instance.getConfig().get(key).getClass().getName().equals("java.lang.Boolean")) { - this.instance.getConfig().set(key, !instance.getConfig().getBoolean(key)); - this.finishEditing(player); - } else { - this.editObject(player, key); - } - } - } - - @EventHandler - public void onChat(AsyncPlayerChatEvent event) { - Player player = event.getPlayer(); - if (!current.containsKey(player)) return; - - String value = current.get(player); - FileConfiguration config = instance.getConfig(); - if (config.isInt(value)) { - config.set(value, Integer.parseInt(event.getMessage())); - } else if (config.isDouble(value)) { - config.set(value, Double.parseDouble(event.getMessage())); - } else if (config.isString(value)) { - config.set(value, event.getMessage()); - } - - Bukkit.getScheduler().scheduleSyncDelayedTask(EpicHoppersPlugin.getInstance(), () -> - this.finishEditing(player), 0L); - - event.setCancelled(true); - } - - private void finishEditing(Player player) { - this.current.remove(player); - this.instance.saveConfig(); - this.openEditor(player); - } - - private void editObject(Player player, String current) { - this.current.put(player, ChatColor.stripColor(current)); - - player.closeInventory(); - player.sendMessage(""); - player.sendMessage(Methods.formatText("&7Please enter a value for &6" + current + "&7.")); - if (instance.getConfig().isInt(current) || instance.getConfig().isDouble(current)) { - player.sendMessage(Methods.formatText("&cUse only numbers.")); - } - player.sendMessage(""); - } - - public void openSettingsManager(Player player) { - Inventory inventory = Bukkit.createInventory(null, 27, pluginName + " Settings Manager"); - ItemStack glass = Methods.getGlass(); - for (int i = 0; i < inventory.getSize(); i++) { - inventory.setItem(i, glass); - } - - int slot = 10; - for (String key : instance.getConfig().getDefaultSection().getKeys(false)) { - ItemStack item = new ItemStack(Material.WHITE_WOOL, 1, (byte) (slot - 9)); //ToDo: Make this function as it was meant to. - ItemMeta meta = item.getItemMeta(); - meta.setLore(Collections.singletonList(Methods.formatText("&6Click To Edit This Category."))); - meta.setDisplayName(Methods.formatText("&f&l" + key)); - item.setItemMeta(meta); - inventory.setItem(slot, item); - slot++; - } - - player.openInventory(inventory); - } - - private void openEditor(Player player) { - Inventory inventory = Bukkit.createInventory(null, 54, pluginName + " Settings Editor"); - FileConfiguration config = instance.getConfig(); - - int slot = 0; - for (String key : config.getConfigurationSection(cat.get(player)).getKeys(true)) { - String fKey = cat.get(player) + "." + key; - ItemStack item = new ItemStack(Material.DIAMOND_HELMET); - ItemMeta meta = item.getItemMeta(); - meta.setDisplayName(Methods.formatText("&6" + key)); - - List lore = new ArrayList<>(); - if (config.isBoolean(fKey)) { - item.setType(Material.LEVER); - lore.add(Methods.formatText(config.getBoolean(fKey) ? "&atrue" : "&cfalse")); - } else if (config.isString(fKey)) { - item.setType(Material.PAPER); - lore.add(Methods.formatText("&9" + config.getString(fKey))); - } else if (config.isInt(fKey)) { - item.setType(Material.CLOCK); - lore.add(Methods.formatText("&5" + config.getInt(fKey))); - } - - meta.setLore(lore); - item.setItemMeta(meta); - - inventory.setItem(slot, item); - slot++; - } - - player.openInventory(inventory); - } - - public void updateSettings() { - FileConfiguration config = instance.getConfig(); - - for (Setting setting : Setting.values()) { - config.addDefault(setting.setting, setting.option); - } - } - - public enum Setting { - HOPPER_UPGRADING("Main.Allow hopper Upgrading", true), - UPGRADE_WITH_ECONOMY("Main.Upgrade With Economy", true), - UPGRADE_WITH_XP("Main.Upgrade With XP", true), - TELEPORT("Main.Allow Players To Teleport Through Hoppers", true), - ENDERCHESTS("Main.Support Enderchests", true), - PARTICLE_TYPE("Main.Upgrade Particle Type", "SPELL_WITCH"), - HOP_TICKS("Main.Amount of Ticks Between Hops", 8L), - AUTOSAVE("Main.Auto Save Interval In Seconds", 15), - TELEPORT_TICKS("Main.Amount of Ticks Between Teleport", 10L), - SYNC_TIMEOUT("Main.Timeout When Syncing Hoppers", 300L), - MAX_CHUNK("Main.Max Hoppers Per Chunk", -1), - TIPS("Main.Display Helpful Tips For Operators", true), - SOUNDS("Main.Sounds Enabled", true), - BLOCKBREAK_PARTICLE("Main.BlockBreak Particle Type", "LAVA"), - BLACKLIST("Main.BlockBreak Blacklisted Blocks", Arrays.asList("BEDROCK")), - AUTOSELL_PRICES("Main.AutoSell Prices", Arrays.asList("STONE,0.50", "COBBLESTONE,0.20", "IRON_ORE,0.35", "COAL_ORE,0.20")), - - RAINBOW("Interfaces.Replace Glass Type 1 With Rainbow Glass", false), - ECO_ICON("Interfaces.Economy Icon", "SUNFLOWER"), - XP_ICON("Interfaces.XP Icon", "EXPERIENCE_BOTTLE"), - GLASS_TYPE_1("Interfaces.Glass Type 1", 7), - GLASS_TYPE_2("Interfaces.Glass Type 2", 11), - GLASS_TYPE_3("Interfaces.Glass Type 3", 3), - - DATABASE_SUPPORT("Database.Activate Mysql Support", false), - DATABASE_IP("Database.IP", "127.0.0.1"), - DATABASE_PORT("Database.Port", 3306), - DATABASE_NAME("Database.Database Name", "EpicHoppers"), - DATABASE_PREFIX("Database.Prefix", "EH-"), - DATABASE_USERNAME("Database.Username", "PUT_USERNAME_HERE"), - DATABASE_PASSWORD("Database.Password", "PUT_PASSWORD_HERE"), - - DOWNLOAD_FILES("System.Download Needed Data Files", true), - LANGUGE_MODE("System.Language Mode", "en_US"), - DEBUGGER("System.Debugger Enabled", false); - - private String setting; - private Object option; - - Setting(String setting, Object option) { - this.setting = setting; - this.option = option; - } - - public List getStringList() { - return EpicHoppersPlugin.getInstance().getConfig().getStringList(setting); - } - - public boolean getBoolean() { - return EpicHoppersPlugin.getInstance().getConfig().getBoolean(setting); - } - - public int getInt() { - return EpicHoppersPlugin.getInstance().getConfig().getInt(setting); - } - - public String getString() { - return EpicHoppersPlugin.getInstance().getConfig().getString(setting); - } - } -} \ No newline at end of file diff --git a/pom.xml b/pom.xml index ca6a3ca..3cc849e 100644 --- a/pom.xml +++ b/pom.xml @@ -1,28 +1,11 @@ - - 4.0.0 - + com.songoda - EpicHoppers-Parent - pom + EpicHoppers + 4.0.0 maven-version-number - - - EpicHoppers-API - EpicHoppers-Plugin - - - - - org.spigotmc - spigot - 1.14-pre5 - provided - - - clean install + EpicHoppers-${project.version} org.apache.maven.plugins @@ -33,6 +16,39 @@ 1.8 + + org.apache.maven.plugins + maven-shade-plugin + 3.1.0 + + + shaded + package + + shade + + + false + false + + + com.songoda:songodaupdater + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + @@ -41,4 +57,46 @@ http://repo.songoda.com/artifactory/private/ + + + org.spigotmc + spigot + 1.14.1 + + + com.songoda + songodaupdater + 1 + + + net.arcaniax + liquidtanks + 2.1.0 + provided + + + xyz.wildseries + wildstacker + b13 + provided + + + net.milkbowl + vault + 1.7.1 + provided + + + org.black_ixx + playerpoints + 2.1.4 + + + com.songoda + fabledskyblock + 72 + provided + + + diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/EpicHoppersPlugin.java b/src/main/java/com/songoda/epichoppers/EpicHoppers.java similarity index 76% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/EpicHoppersPlugin.java rename to src/main/java/com/songoda/epichoppers/EpicHoppers.java index bc09c09..050942a 100644 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/EpicHoppersPlugin.java +++ b/src/main/java/com/songoda/epichoppers/EpicHoppers.java @@ -1,39 +1,31 @@ package com.songoda.epichoppers; -import com.songoda.epichoppers.api.EpicHoppers; -import com.songoda.epichoppers.api.EpicHoppersAPI; -import com.songoda.epichoppers.api.hopper.HopperManager; -import com.songoda.epichoppers.api.hopper.TeleportTrigger; -import com.songoda.epichoppers.api.hopper.levels.Level; -import com.songoda.epichoppers.api.hopper.levels.LevelManager; -import com.songoda.epichoppers.api.hopper.levels.modules.Module; import com.songoda.epichoppers.boost.BoostData; import com.songoda.epichoppers.boost.BoostManager; import com.songoda.epichoppers.command.CommandManager; +import com.songoda.epichoppers.economy.Economy; +import com.songoda.epichoppers.economy.PlayerPointsEconomy; +import com.songoda.epichoppers.economy.VaultEconomy; import com.songoda.epichoppers.enchantment.Enchantment; -import com.songoda.epichoppers.tasks.HopTask; import com.songoda.epichoppers.handlers.TeleportHandler; -import com.songoda.epichoppers.hook.HookManager; -import com.songoda.epichoppers.hopper.EFilter; -import com.songoda.epichoppers.hopper.EHopper; -import com.songoda.epichoppers.hopper.EHopperManager; -import com.songoda.epichoppers.hopper.levels.ELevelManager; -import com.songoda.epichoppers.hopper.levels.modules.ModuleAutoCrafting; -import com.songoda.epichoppers.hopper.levels.modules.ModuleAutoSell; -import com.songoda.epichoppers.hopper.levels.modules.ModuleBlockBreak; -import com.songoda.epichoppers.hopper.levels.modules.ModuleSuction; +import com.songoda.epichoppers.hopper.Filter; +import com.songoda.epichoppers.hopper.Hopper; +import com.songoda.epichoppers.hopper.HopperManager; +import com.songoda.epichoppers.hopper.levels.Level; +import com.songoda.epichoppers.hopper.levels.LevelManager; +import com.songoda.epichoppers.hopper.levels.modules.*; import com.songoda.epichoppers.listeners.*; import com.songoda.epichoppers.player.PlayerDataManager; import com.songoda.epichoppers.storage.Storage; import com.songoda.epichoppers.storage.StorageRow; import com.songoda.epichoppers.storage.types.StorageMysql; import com.songoda.epichoppers.storage.types.StorageYaml; -import com.songoda.epichoppers.utils.ConfigWrapper; -import com.songoda.epichoppers.utils.Methods; -import com.songoda.epichoppers.utils.Metrics; -import com.songoda.epichoppers.utils.SettingsManager; +import com.songoda.epichoppers.tasks.HopTask; +import com.songoda.epichoppers.utils.*; +import com.songoda.epichoppers.utils.settings.Setting; +import com.songoda.epichoppers.utils.settings.SettingsManager; +import org.apache.commons.lang.ArrayUtils; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.command.CommandSender; @@ -46,7 +38,6 @@ import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; -import java.io.File; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; @@ -57,10 +48,13 @@ import java.util.List; import java.util.UUID; -public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers { +public class EpicHoppers extends JavaPlugin { private static CommandSender console = Bukkit.getConsoleSender(); - private static EpicHoppersPlugin INSTANCE; + private static EpicHoppers INSTANCE; + + private ServerVersion serverVersion = ServerVersion.fromPackageName(Bukkit.getServer().getClass().getPackage().getName()); + public References references = null; public Enchantment enchantmentHandler; private SettingsManager settingsManager; @@ -72,7 +66,8 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers { private LevelManager levelManager; private BoostManager boostManager; private PlayerDataManager playerDataManager; - private HookManager hookManager; + + private Economy economy; private TeleportHandler teleportHandler; @@ -80,40 +75,20 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers { private boolean liquidtanks = false; - public static EpicHoppersPlugin getInstance() { + public static EpicHoppers getInstance() { return INSTANCE; } - private boolean checkVersion() { - int workingVersion = 13; - int currentVersion = Integer.parseInt(Bukkit.getServer().getClass() - .getPackage().getName().split("\\.")[3].split("_")[1]); - - if (currentVersion < workingVersion) { - Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> { - Bukkit.getConsoleSender().sendMessage(""); - Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "You installed the 1." + workingVersion + "+ only version of " + this.getDescription().getName() + " on a 1." + currentVersion + " server. Since you are on the wrong version we disabled the plugin for you. Please install correct version to continue using " + this.getDescription().getName() + "."); - Bukkit.getConsoleSender().sendMessage(""); - }, 20L); - return false; - } - return true; - } - @Override public void onEnable() { INSTANCE = this; - EpicHoppersAPI.setImplementation(this); - - // Check to make sure the Bukkit version is compatible. - if (!checkVersion()) return; console.sendMessage(Methods.formatText("&a=============================")); console.sendMessage(Methods.formatText("&7EpicHoppers " + this.getDescription().getVersion() + " by &5Songoda <3&7!")); console.sendMessage(Methods.formatText("&7Action: &aEnabling&7...")); this.settingsManager = new SettingsManager(this); - this.setupConfig(); + this.settingsManager.setupConfig(); // Setup language String langMode = getConfig().getString("System.Language Mode"); @@ -125,12 +100,19 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers { this.update(); this.enchantmentHandler = new Enchantment(); - this.hopperManager = new EHopperManager(); + this.hopperManager = new HopperManager(); this.playerDataManager = new PlayerDataManager(); this.boostManager = new BoostManager(); this.references = new References(); this.commandManager = new CommandManager(this); - this.hookManager = new HookManager(this); + + // Setup Economy + if (Setting.VAULT_ECONOMY.getBoolean() + && getServer().getPluginManager().getPlugin("Vault") != null) + this.economy = new VaultEconomy(this); + else if (Setting.PLAYER_POINTS_ECONOMY.getBoolean() + && getServer().getPluginManager().getPlugin("PlayerPoints") != null) + this.economy = new PlayerPointsEconomy(this); this.loadLevelManager(); this.checkStorage(); @@ -154,7 +136,7 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers { if (pluginManager.isPluginEnabled("LiquidTanks")) liquidtanks = true; // Start auto save - int saveInterval = getConfig().getInt("Main.Auto Save Interval In Seconds") * 60 * 20; + int saveInterval = Setting.AUTOSAVE.getInt() * 60 * 20; Bukkit.getScheduler().runTaskTimerAsynchronously(this, this::saveToFile, saveInterval, saveInterval); // Start Metrics @@ -208,6 +190,22 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers { } + public ServerVersion getServerVersion() { + return serverVersion; + } + + public boolean isServerVersion(ServerVersion version) { + return serverVersion == version; + } + + public boolean isServerVersion(ServerVersion... versions) { + return ArrayUtils.contains(versions, serverVersion); + } + + public boolean isServerVersionAtLeast(ServerVersion version) { + return serverVersion.ordinal() >= version.ordinal(); + } + private void checkStorage() { if (getConfig().getBoolean("Database.Activate Mysql Support")) { this.storage = new StorageMysql(this); @@ -256,21 +254,25 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers { List blackList = row.get("blacklist").asItemStackList(); List voidList = row.get("void").asItemStackList(); - Material autoCrafting = Material.valueOf(row.get("autocrafting").asString() == null ? "AIR" : row.get("autocrafting").asString()); + String autoCraftingStr = row.get("autocrafting").asString() == null ? "AIR" : row.get("autocrafting").asString(); + + String[] autoCraftingParts = autoCraftingStr.split(":"); + + ItemStack autoCrafting = new ItemStack(Material.valueOf(autoCraftingParts[0]), 1, Short.parseShort(autoCraftingParts.length == 2 ? autoCraftingParts[1] : "0")); String blackLoc = row.get("black").asString(); Location black = blackLoc == null ? null : Methods.unserializeLocation(blackLoc); boolean autoBreak = row.get("autobreak").asBoolean(); - EFilter filter = new EFilter(); + Filter filter = new Filter(); filter.setWhiteList(whiteList); filter.setBlackList(blackList); filter.setVoidList(voidList); filter.setEndPoint(black); - EHopper hopper = new EHopper(location, levelManager.getLevel(level), lastPlayer, placedBy, blocks, filter, teleportTrigger, autoCrafting); + Hopper hopper = new Hopper(location, levelManager.getLevel(level), lastPlayer, placedBy, blocks, filter, teleportTrigger, autoCrafting); if (autoBreak) hopper.toggleAutoBreaking(); @@ -302,11 +304,11 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers { saveResource("levels.yml", false); // Load an instance of LevelManager - levelManager = new ELevelManager(); + levelManager = new LevelManager(); /* * Register Levels into LevelManager from configuration. */ - ((ELevelManager) levelManager).clear(); + levelManager.clear(); for (String levelName : levelsFile.getConfig().getKeys(false)) { int level = Integer.valueOf(levelName.split("-")[1]); @@ -339,33 +341,15 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers { } } - private void setupConfig() { - settingsManager.updateSettings(); - this.getConfig().options().copyDefaults(true); - this.saveConfig(); - } - public void reload() { String langMode = getConfig().getString("System.Language Mode"); this.locale = Locale.getLocale(getConfig().getString("System.Language Mode", langMode)); this.locale.reloadMessages(); - this.hookManager = new HookManager(this); references = new References(); - this.setupConfig(); + this.settingsManager.reloadConfig(); loadLevelManager(); } - @Override - public Level getLevelFromItem(ItemStack item) { - if (item.getItemMeta().getDisplayName().contains(":")) { - String arr[] = item.getItemMeta().getDisplayName().replace(String.valueOf(ChatColor.COLOR_CHAR), "").split(":"); - return getLevelManager().getLevel(Integer.parseInt(arr[0])); - } else { - return getLevelManager().getLowestLevel(); - } - } - - @Override public ItemStack newHopperItem(Level level) { ItemStack item = new ItemStack(Material.HOPPER, 1); ItemMeta itemmeta = item.getItemMeta(); @@ -394,16 +378,10 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers { return commandManager; } - public HookManager getHookManager() { - return hookManager; - } - - @Override public LevelManager getLevelManager() { return levelManager; } - @Override public HopperManager getHopperManager() { return hopperManager; } @@ -412,6 +390,10 @@ public class EpicHoppersPlugin extends JavaPlugin implements EpicHoppers { return settingsManager; } + public Economy getEconomy() { + return economy; + } + public PlayerDataManager getPlayerDataManager() { return playerDataManager; } diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/Locale.java b/src/main/java/com/songoda/epichoppers/Locale.java similarity index 99% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/Locale.java rename to src/main/java/com/songoda/epichoppers/Locale.java index b71822b..f73ebe6 100644 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/Locale.java +++ b/src/main/java/com/songoda/epichoppers/Locale.java @@ -53,7 +53,7 @@ public class Locale { /** * Initialize the locale class to generate information and search for localizations. * This must be called before any other methods in the Locale class can be invoked. - * Note that this will also call {@link #searchForLocales()}, so there is no need to + * Note that this will also call {@link #searchForLocales()}, so there is blacklist need to * invoke it for yourself after the initialization * * @param plugin the plugin instance diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/References.java b/src/main/java/com/songoda/epichoppers/References.java similarity index 64% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/References.java rename to src/main/java/com/songoda/epichoppers/References.java index 21d1b94..ccefa9a 100644 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/References.java +++ b/src/main/java/com/songoda/epichoppers/References.java @@ -5,7 +5,7 @@ public class References { private String prefix; public References() { - prefix = EpicHoppersPlugin.getInstance().getLocale().getMessage("general.nametag.prefix") + " "; + prefix = EpicHoppers.getInstance().getLocale().getMessage("general.nametag.prefix") + " "; } public String getPrefix() { diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/boost/BoostData.java b/src/main/java/com/songoda/epichoppers/boost/BoostData.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/boost/BoostData.java rename to src/main/java/com/songoda/epichoppers/boost/BoostData.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/boost/BoostManager.java b/src/main/java/com/songoda/epichoppers/boost/BoostManager.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/boost/BoostManager.java rename to src/main/java/com/songoda/epichoppers/boost/BoostManager.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/command/AbstractCommand.java b/src/main/java/com/songoda/epichoppers/command/AbstractCommand.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/command/AbstractCommand.java rename to src/main/java/com/songoda/epichoppers/command/AbstractCommand.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/command/CommandManager.java b/src/main/java/com/songoda/epichoppers/command/CommandManager.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/command/CommandManager.java rename to src/main/java/com/songoda/epichoppers/command/CommandManager.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/command/TabManager.java b/src/main/java/com/songoda/epichoppers/command/TabManager.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/command/TabManager.java rename to src/main/java/com/songoda/epichoppers/command/TabManager.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/command/commands/CommandBook.java b/src/main/java/com/songoda/epichoppers/command/commands/CommandBook.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/command/commands/CommandBook.java rename to src/main/java/com/songoda/epichoppers/command/commands/CommandBook.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/command/commands/CommandBoost.java b/src/main/java/com/songoda/epichoppers/command/commands/CommandBoost.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/command/commands/CommandBoost.java rename to src/main/java/com/songoda/epichoppers/command/commands/CommandBoost.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/command/commands/CommandEpicHoppers.java b/src/main/java/com/songoda/epichoppers/command/commands/CommandEpicHoppers.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/command/commands/CommandEpicHoppers.java rename to src/main/java/com/songoda/epichoppers/command/commands/CommandEpicHoppers.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/command/commands/CommandGive.java b/src/main/java/com/songoda/epichoppers/command/commands/CommandGive.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/command/commands/CommandGive.java rename to src/main/java/com/songoda/epichoppers/command/commands/CommandGive.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/command/commands/CommandReload.java b/src/main/java/com/songoda/epichoppers/command/commands/CommandReload.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/command/commands/CommandReload.java rename to src/main/java/com/songoda/epichoppers/command/commands/CommandReload.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/command/commands/CommandSettings.java b/src/main/java/com/songoda/epichoppers/command/commands/CommandSettings.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/command/commands/CommandSettings.java rename to src/main/java/com/songoda/epichoppers/command/commands/CommandSettings.java diff --git a/src/main/java/com/songoda/epichoppers/economy/Economy.java b/src/main/java/com/songoda/epichoppers/economy/Economy.java new file mode 100644 index 0000000..013f732 --- /dev/null +++ b/src/main/java/com/songoda/epichoppers/economy/Economy.java @@ -0,0 +1,10 @@ +package com.songoda.epicspawners.economy; + +import org.bukkit.entity.Player; + +public interface Economy { + + boolean hasBalance(Player player, double cost); + + boolean withdrawBalance(Player player, double cost); +} diff --git a/src/main/java/com/songoda/epichoppers/economy/PlayerPointsEconomy.java b/src/main/java/com/songoda/epichoppers/economy/PlayerPointsEconomy.java new file mode 100644 index 0000000..ecfd400 --- /dev/null +++ b/src/main/java/com/songoda/epichoppers/economy/PlayerPointsEconomy.java @@ -0,0 +1,36 @@ +package com.songoda.epicspawners.economy; + +import com.songoda.epicspawners.EpicSpawners; +import org.black_ixx.playerpoints.PlayerPoints; +import org.bukkit.entity.Player; + +public class PlayerPointsEconomy implements Economy { + + private final EpicSpawners plugin; + + private final PlayerPoints playerPoints; + + public PlayerPointsEconomy(EpicSpawners plugin) { + this.plugin = plugin; + + this.playerPoints = (PlayerPoints) plugin.getServer().getPluginManager().getPlugin("PlayerPoints"); + } + + private int convertAmount(double amount) { + return (int) Math.ceil(amount); + } + + @Override + public boolean hasBalance(Player player, double cost) { + int amount = convertAmount(cost); + return playerPoints.getAPI().look(player.getUniqueId()) >= amount; + + } + + @Override + public boolean withdrawBalance(Player player, double cost) { + int amount = convertAmount(cost); + return playerPoints.getAPI().take(player.getUniqueId(), amount); + + } +} diff --git a/src/main/java/com/songoda/epichoppers/economy/VaultEconomy.java b/src/main/java/com/songoda/epichoppers/economy/VaultEconomy.java new file mode 100644 index 0000000..4484fc0 --- /dev/null +++ b/src/main/java/com/songoda/epichoppers/economy/VaultEconomy.java @@ -0,0 +1,28 @@ +package com.songoda.epicspawners.economy; + +import com.songoda.epicspawners.EpicSpawners; +import org.bukkit.entity.Player; + +public class VaultEconomy implements Economy { + + private final EpicSpawners plugin; + + private final net.milkbowl.vault.economy.Economy vault; + + public VaultEconomy(EpicSpawners plugin) { + this.plugin = plugin; + + this.vault = plugin.getServer().getServicesManager(). + getRegistration(net.milkbowl.vault.economy.Economy.class).getProvider(); + } + + @Override + public boolean hasBalance(Player player, double cost) { + return vault.has(player, cost); + } + + @Override + public boolean withdrawBalance(Player player, double cost) { + return vault.withdrawPlayer(player, cost).transactionSuccess(); + } +} diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/enchantment/Enchantment.java b/src/main/java/com/songoda/epichoppers/enchantment/Enchantment.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/enchantment/Enchantment.java rename to src/main/java/com/songoda/epichoppers/enchantment/Enchantment.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/gui/GUICrafting.java b/src/main/java/com/songoda/epichoppers/gui/GUICrafting.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/gui/GUICrafting.java rename to src/main/java/com/songoda/epichoppers/gui/GUICrafting.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/gui/GUIFilter.java b/src/main/java/com/songoda/epichoppers/gui/GUIFilter.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/gui/GUIFilter.java rename to src/main/java/com/songoda/epichoppers/gui/GUIFilter.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/gui/GUIOverview.java b/src/main/java/com/songoda/epichoppers/gui/GUIOverview.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/gui/GUIOverview.java rename to src/main/java/com/songoda/epichoppers/gui/GUIOverview.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/handlers/TeleportHandler.java b/src/main/java/com/songoda/epichoppers/handlers/TeleportHandler.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/handlers/TeleportHandler.java rename to src/main/java/com/songoda/epichoppers/handlers/TeleportHandler.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/EFilter.java b/src/main/java/com/songoda/epichoppers/hopper/Filter.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/EFilter.java rename to src/main/java/com/songoda/epichoppers/hopper/Filter.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/EHopper.java b/src/main/java/com/songoda/epichoppers/hopper/Hopper.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/EHopper.java rename to src/main/java/com/songoda/epichoppers/hopper/Hopper.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/EHopperManager.java b/src/main/java/com/songoda/epichoppers/hopper/HopperManager.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/EHopperManager.java rename to src/main/java/com/songoda/epichoppers/hopper/HopperManager.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/levels/ELevel.java b/src/main/java/com/songoda/epichoppers/hopper/levels/Level.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/levels/ELevel.java rename to src/main/java/com/songoda/epichoppers/hopper/levels/Level.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/levels/ELevelManager.java b/src/main/java/com/songoda/epichoppers/hopper/levels/LevelManager.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/levels/ELevelManager.java rename to src/main/java/com/songoda/epichoppers/hopper/levels/LevelManager.java diff --git a/src/main/java/com/songoda/epichoppers/hopper/levels/modules/Module.java b/src/main/java/com/songoda/epichoppers/hopper/levels/modules/Module.java new file mode 100644 index 0000000..54a7896 --- /dev/null +++ b/src/main/java/com/songoda/epichoppers/hopper/levels/modules/Module.java @@ -0,0 +1,4 @@ +package com.songoda.epichoppers.hopper.levels.modules; + +public class Module { +} diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoCrafting.java b/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoCrafting.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoCrafting.java rename to src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoCrafting.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoSell.java b/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoSell.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoSell.java rename to src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleAutoSell.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleBlockBreak.java b/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleBlockBreak.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleBlockBreak.java rename to src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleBlockBreak.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleSuction.java b/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleSuction.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleSuction.java rename to src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleSuction.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/listeners/BlockListeners.java b/src/main/java/com/songoda/epichoppers/listeners/BlockListeners.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/listeners/BlockListeners.java rename to src/main/java/com/songoda/epichoppers/listeners/BlockListeners.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/listeners/EntityListeners.java b/src/main/java/com/songoda/epichoppers/listeners/EntityListeners.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/listeners/EntityListeners.java rename to src/main/java/com/songoda/epichoppers/listeners/EntityListeners.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/listeners/HopperListeners.java b/src/main/java/com/songoda/epichoppers/listeners/HopperListeners.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/listeners/HopperListeners.java rename to src/main/java/com/songoda/epichoppers/listeners/HopperListeners.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/listeners/InteractListeners.java b/src/main/java/com/songoda/epichoppers/listeners/InteractListeners.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/listeners/InteractListeners.java rename to src/main/java/com/songoda/epichoppers/listeners/InteractListeners.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/listeners/InventoryListeners.java b/src/main/java/com/songoda/epichoppers/listeners/InventoryListeners.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/listeners/InventoryListeners.java rename to src/main/java/com/songoda/epichoppers/listeners/InventoryListeners.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/player/PlayerData.java b/src/main/java/com/songoda/epichoppers/player/PlayerData.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/player/PlayerData.java rename to src/main/java/com/songoda/epichoppers/player/PlayerData.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/player/PlayerDataManager.java b/src/main/java/com/songoda/epichoppers/player/PlayerDataManager.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/player/PlayerDataManager.java rename to src/main/java/com/songoda/epichoppers/player/PlayerDataManager.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/player/SyncType.java b/src/main/java/com/songoda/epichoppers/player/SyncType.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/player/SyncType.java rename to src/main/java/com/songoda/epichoppers/player/SyncType.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/storage/Storage.java b/src/main/java/com/songoda/epichoppers/storage/Storage.java similarity index 81% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/storage/Storage.java rename to src/main/java/com/songoda/epichoppers/storage/Storage.java index e58f931..faca842 100644 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/storage/Storage.java +++ b/src/main/java/com/songoda/epichoppers/storage/Storage.java @@ -1,9 +1,8 @@ package com.songoda.epichoppers.storage; -import com.songoda.epichoppers.EpicHoppersPlugin; -import com.songoda.epichoppers.api.hopper.Hopper; +import com.songoda.epichoppers.EpicHoppers; import com.songoda.epichoppers.boost.BoostData; -import com.songoda.epichoppers.hopper.EHopper; +import com.songoda.epichoppers.hopper.Hopper; import com.songoda.epichoppers.utils.ConfigWrapper; import com.songoda.epichoppers.utils.Methods; import org.bukkit.Material; @@ -13,10 +12,10 @@ import java.util.List; public abstract class Storage { - protected final EpicHoppersPlugin instance; + protected final EpicHoppers instance; protected final ConfigWrapper dataFile; - public Storage(EpicHoppersPlugin instance) { + public Storage(EpicHoppers instance) { this.instance = instance; this.dataFile = new ConfigWrapper(instance, "", "data.yml"); this.dataFile.createNewFile(null, "EpicHoppers Data File"); @@ -30,7 +29,7 @@ public abstract class Storage { public abstract void prepareSaveItem(String group, StorageItem... items); - public void updateData(EpicHoppersPlugin instance) { + public void updateData(EpicHoppers instance) { /* * Dump HopperManager to file. */ @@ -47,11 +46,10 @@ public abstract class Storage { new StorageItem("player", hopper.getLastPlayer() == null ? null : hopper.getLastPlayer().toString()), new StorageItem("teleporttrigger", hopper.getTeleportTrigger().toString()), - new StorageItem("autocrafting", hopper.getAutoCrafting() == null || hopper.getAutoCrafting() == Material.AIR ? null : hopper.getAutoCrafting().name()), - new StorageItem("whitelist", hopper.getFilter().getWhiteList()), + new StorageItem("autocrafting", hopper.getAutoCrafting() == null || hopper.getAutoCrafting().getType() == Material.AIR ? null : hopper.getAutoCrafting().getType().name() + (hopper.getAutoCrafting().getDurability() == 0 ? "" : ":" + hopper.getAutoCrafting().getDurability())), new StorageItem("whitelist", hopper.getFilter().getWhiteList()), new StorageItem("blacklist", hopper.getFilter().getBlackList()), new StorageItem("void", hopper.getFilter().getVoidList()), - new StorageItem("autobreak", ((EHopper)hopper).isAutoBreaking()), + new StorageItem("autobreak", hopper.isAutoBreaking()), new StorageItem("black", hopper.getFilter().getEndPoint() == null ? null : Methods.serializeLocation(hopper.getFilter().getEndPoint()))); } diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/storage/StorageItem.java b/src/main/java/com/songoda/epichoppers/storage/StorageItem.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/storage/StorageItem.java rename to src/main/java/com/songoda/epichoppers/storage/StorageItem.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/storage/StorageRow.java b/src/main/java/com/songoda/epichoppers/storage/StorageRow.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/storage/StorageRow.java rename to src/main/java/com/songoda/epichoppers/storage/StorageRow.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/storage/types/StorageMysql.java b/src/main/java/com/songoda/epichoppers/storage/types/StorageMysql.java similarity index 96% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/storage/types/StorageMysql.java rename to src/main/java/com/songoda/epichoppers/storage/types/StorageMysql.java index 93ca11b..495fc7c 100644 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/storage/types/StorageMysql.java +++ b/src/main/java/com/songoda/epichoppers/storage/types/StorageMysql.java @@ -1,13 +1,10 @@ package com.songoda.epichoppers.storage.types; -import com.songoda.epichoppers.EpicHoppersPlugin; -import com.songoda.epichoppers.storage.Storage; -import com.songoda.epichoppers.storage.StorageItem; +import com.songoda.epichoppers.EpicHoppers; import com.songoda.epichoppers.utils.MySQLDatabase; import com.songoda.epichoppers.storage.Storage; import com.songoda.epichoppers.storage.StorageItem; import com.songoda.epichoppers.storage.StorageRow; -import com.songoda.epichoppers.utils.MySQLDatabase; import java.sql.DatabaseMetaData; import java.sql.ResultSet; @@ -24,7 +21,7 @@ public class StorageMysql extends Storage { private static Map lastSave = null; private MySQLDatabase database; - public StorageMysql(EpicHoppersPlugin instance) { + public StorageMysql(EpicHoppers instance) { super(instance); this.database = new MySQLDatabase(instance); } diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/storage/types/StorageYaml.java b/src/main/java/com/songoda/epichoppers/storage/types/StorageYaml.java similarity index 97% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/storage/types/StorageYaml.java rename to src/main/java/com/songoda/epichoppers/storage/types/StorageYaml.java index 0aeae28..382573f 100644 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/storage/types/StorageYaml.java +++ b/src/main/java/com/songoda/epichoppers/storage/types/StorageYaml.java @@ -1,6 +1,6 @@ package com.songoda.epichoppers.storage.types; -import com.songoda.epichoppers.EpicHoppersPlugin; +import com.songoda.epichoppers.EpicHoppers; import com.songoda.epichoppers.storage.Storage; import com.songoda.epichoppers.storage.StorageItem; import com.songoda.epichoppers.storage.StorageRow; @@ -15,7 +15,7 @@ public class StorageYaml extends Storage { private static final Map toSave = new HashMap<>(); private static Map lastSave = null; - public StorageYaml(EpicHoppersPlugin instance) { + public StorageYaml(EpicHoppers instance) { super(instance); } diff --git a/src/main/java/com/songoda/epichoppers/tasks/HopTask.java b/src/main/java/com/songoda/epichoppers/tasks/HopTask.java new file mode 100644 index 0000000..d370ab9 --- /dev/null +++ b/src/main/java/com/songoda/epichoppers/tasks/HopTask.java @@ -0,0 +1,359 @@ +package com.songoda.epichoppers.tasks; + +import com.songoda.epichoppers.EpicHoppers; +import com.songoda.epichoppers.boost.BoostData; +import com.songoda.epichoppers.hopper.levels.modules.Module; +import com.songoda.epichoppers.utils.HopperDirection; +import com.songoda.epichoppers.utils.Methods; +import com.songoda.epichoppers.utils.ServerVersion; +import com.songoda.epichoppers.utils.settings.Setting; +import org.bukkit.*; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.block.Hopper; +import org.bukkit.inventory.*; +import org.bukkit.scheduler.BukkitRunnable; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Created by songoda on 3/14/2017. + */ +public class HopTask extends BukkitRunnable { + + // Hop to the bop to the be bop top. + + private static EpicHoppers plugin; + + private final List blacklist = new ArrayList<>(); + + public HopTask(EpicHoppers plug) { + plugin = plug; + runTaskTimer(plugin, 0, Setting.HOP_TICKS.getInt()); + } + + @Override + public void run() { + main: + for (com.songoda.epichoppers.hopper.Hopper hopper : new HashMap<>(plugin.getHopperManager().getHoppers()).values()) { + // Get this hoppers location. + Location location = hopper.getLocation(); + + // Skip is chunk not loaded. + if (location.getWorld() == null + || !location.getWorld().isChunkLoaded(location.getBlockX() >> 4, location.getBlockZ() >> 4)) + continue; + + // Get Hopper Block. + Block block = location.getBlock(); + + // If block is not a hopper remove and continue. + if (block.getType() != Material.HOPPER) { + plugin.getHopperManager().removeHopper(location); + continue; + } + + // If hopper block is powered continue. + if (block.isBlockPowered() || block.isBlockIndirectlyPowered()) continue; + + // Get hopper state. + Hopper hopperState = (Hopper) block.getState(); + + // Create list to hold blocked materials. + List blockedMaterials = new ArrayList<>(); + + // Cycle through modules. + for (Module module : hopper.getLevel().getRegisteredModules()) { + // Run Module + module.run(hopper, hopperState.getInventory()); + + // Add banned materials to list. + List materials = module.getBlockedItems(hopper); + if (materials == null || materials.isEmpty()) continue; + blockedMaterials.addAll(materials); + } + + // Get remote linked containers. + List linkedContainers = hopper.getLinkedBlocks(); + + // Add linked container that the hopper is attached to physically. + HopperDirection hopperDirection = HopperDirection.getDirection(hopperState.getRawData()); + linkedContainers.add(hopperDirection.getLocation(location)); + + // Amount to be moved. + BoostData boostData = plugin.getBoostManager().getBoost(hopper.getPlacedBy()); + int amount = hopper.getLevel().getAmount() * (boostData == null ? 1 : boostData.getMultiplier()); + + // Fetch all hopper contents. + ItemStack[] hopperContents = hopperState.getInventory().getContents(); + + // Get filter endpoint + InventoryHolder filterEndpoint = getFilterEndpoint(hopper); + + // Loop through our container list. + for (Location destinationLocation : linkedContainers) { + + // Make sure the destination chunk is loaded. + if (!destinationLocation.getWorld().isChunkLoaded(destinationLocation.getBlockX() >> 4, + destinationLocation.getBlockZ() >> 4)) + continue; + + // Get the destination block. + Block destinationBlock = destinationLocation.getBlock(); + + // Get the destination state. + BlockState blockState = destinationBlock.getState(); + + // Remove if destination is not a inventoryholder. + if (!(blockState instanceof InventoryHolder)) { + //ToDO: Have this remove the link all together. + continue; + } + + // Cast blockState to container + InventoryHolder destinationContainer = ((InventoryHolder) blockState); + + // Loop through all of our hoppers item slots. + for (int i = 0; i < 5; i++) { + + // Skip if slot empty. + if (hopperContents[i] == null) continue; + + // Get potential item to move. + ItemStack item = hopperContents[i]; + + // Skip if item blacklisted. + if (blacklist.contains(item) || blockedMaterials.contains(item)) + continue; + + // Get amount to move. + int amountToMove = item.getAmount() < amount ? item.getAmount() : amount; + + // Create item that will be moved. + ItemStack itemToMove = item.clone(); + itemToMove.setAmount(amountToMove); + + // Process void. + if (hopper.getFilter().getVoidList().stream().anyMatch(itemStack -> itemStack.isSimilar(item))) { + item.setAmount(item.getAmount() - amountToMove); + break main; + } + + // Set current destination. + InventoryHolder currentDestination = destinationContainer; + + // Process whitelist and blacklist. + boolean blocked = (!hopper.getFilter().getWhiteList().isEmpty() && hopper.getFilter().getWhiteList().stream().noneMatch(itemStack -> itemStack.isSimilar(item)) + || hopper.getFilter().getBlackList().stream().anyMatch(itemStack -> itemStack.isSimilar(item))); + + // If blocked check to see if a movement can be made if blacklist skip to the next slot + // otherwise set the current destination to the endpoint. + if (blocked) { + if (filterEndpoint == null || !canMove(filterEndpoint.getInventory(), itemToMove)) + break; + currentDestination = filterEndpoint; + } + + // Add item to container and continue on success. + if (addItem(hopper, currentDestination, destinationBlock.getType(), item, itemToMove, amountToMove)) + continue main; + } + } + } + // Empty blacklist in preparation for next cycle. + this.blacklist.clear(); + } + + private boolean addItem(com.songoda.epichoppers.hopper.Hopper hopper, InventoryHolder currentDestination, + Material destinationType, ItemStack item, ItemStack itemToMove, int amountToMove) { + + Inventory destinationInventory = currentDestination.getInventory(); + + switch (destinationType) { + case ENDER_CHEST: + OfflinePlayer op = Bukkit.getOfflinePlayer(hopper.getPlacedBy()); + + if (op.isOnline()) + destinationInventory = op.getPlayer().getEnderChest(); + break; + case BLACK_SHULKER_BOX: + case BLUE_SHULKER_BOX: + case BROWN_SHULKER_BOX: + case CYAN_SHULKER_BOX: + case GRAY_SHULKER_BOX: + case GREEN_SHULKER_BOX: + case LIGHT_BLUE_SHULKER_BOX: + case LIGHT_GRAY_SHULKER_BOX: + case LIME_SHULKER_BOX: + case MAGENTA_SHULKER_BOX: + case ORANGE_SHULKER_BOX: + case PINK_SHULKER_BOX: + case PURPLE_SHULKER_BOX: + case RED_SHULKER_BOX: + case SHULKER_BOX: + case WHITE_SHULKER_BOX: + case YELLOW_SHULKER_BOX: + return false; + case BREWING_STAND: { + BrewerInventory brewerInventory = (BrewerInventory) destinationInventory; + + int maxSize = itemToMove.getMaxStackSize(); + + String typeStr = item.getType().name().toUpperCase(); + boolean isBottle = typeStr.contains("POTION") || typeStr.contains("BOTTLE"); + boolean isLeft = item.getType() == Material.BLAZE_POWDER; + + Map output = new HashMap<>(); + if (isBottle) { + output.put(0, brewerInventory.getItem(0)); + output.put(1, brewerInventory.getItem(1)); + output.put(2, brewerInventory.getItem(2)); + } else if (isLeft) { + output.put(4, brewerInventory.getItem(4)); + } else { + output.put(3, brewerInventory.getItem(3)); + } + + for (Map.Entry entry : output.entrySet()) { + ItemStack currentOutput = entry.getValue(); + int currentOutputAmount = currentOutput == null ? 0 : currentOutput.getAmount(); + if (currentOutput != null && (!currentOutput.isSimilar(itemToMove)) + || currentOutputAmount + amountToMove > maxSize) continue; + + if (currentOutput != null) { + currentOutput.setAmount(currentOutputAmount + amountToMove); + } else { + currentOutput = itemToMove; + } + + brewerInventory.setItem(entry.getKey(), currentOutput); + } + item.setAmount(item.getAmount() - amountToMove); + return true; + } + case FURNACE: { + FurnaceInventory furnaceInventory = (FurnaceInventory) destinationInventory; + + boolean isFuel = (plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? item.getType().isFuel() : Methods.isLegacyFuel(item.getType())) && !item.getType().name().contains("LOG"); + ItemStack output = isFuel ? furnaceInventory.getFuel() : furnaceInventory.getSmelting(); + if (output != null && !output.isSimilar(itemToMove)) return false; + int maxSize = itemToMove.getMaxStackSize(); + int currentOutputAmount = output == null ? 0 : output.getAmount(); + + if (currentOutputAmount + amountToMove <= maxSize) { + if (output != null) { + output.setAmount(currentOutputAmount + amountToMove); + } else { + output = itemToMove; + } + if (isFuel) { + furnaceInventory.setFuel(output); + } else { + furnaceInventory.setSmelting(output); + } + item.setAmount(item.getAmount() - amountToMove); + } + return true; + } + } + + // Continue if move would fail. + if (!canMove(destinationInventory, itemToMove)) + return false; + + // Move item to destination. + destinationInventory.addItem(itemToMove); + + // Debt hopper + item.setAmount(item.getAmount() - amountToMove); + + // Update comparators for destination hopper. + updateAdjacentComparators(((BlockState) currentDestination).getLocation()); + + // Update comparators for current hopper. + updateAdjacentComparators(hopper.getLocation()); + + // Prevent item from being moved again during this cycle. + this.blacklist.add(itemToMove); + + // Continue to next hopper. + return true; + } + + private InventoryHolder getFilterEndpoint(com.songoda.epichoppers.hopper.Hopper hopper) { + // Get endpoint location. + Location endPoint = hopper.getFilter().getEndPoint(); + + // Check for null. + if (hopper.getFilter().getEndPoint() == null) return null; + + // Make sure chunk is loaded. + if (!endPoint.getWorld().isChunkLoaded(endPoint.getBlockX() >> 4, endPoint.getBlockZ() >> 4)) + return null; + + // Cast to state. + BlockState state = endPoint.getBlock().getState(); + + //Remove if not a container. + if (!(state instanceof InventoryHolder)) { + hopper.getFilter().setEndPoint(null); + return null; + } + + // Cast and return as InventoryHolder. + return (InventoryHolder) state; + } + + private Class clazzCraftWorld, clazzCraftBlock, clazzBlockPosition; + private Method getHandle, updateAdjacentComparators, getNMS, getBlock; + + private void updateAdjacentComparators(Location location) { + try { + // Cache reflection. + if (clazzCraftWorld == null) { + String ver = Bukkit.getServer().getClass().getPackage().getName().substring(23); + clazzCraftWorld = Class.forName("org.bukkit.craftbukkit." + ver + ".CraftWorld"); + clazzCraftBlock = Class.forName("org.bukkit.craftbukkit." + ver + ".block.CraftBlock"); + clazzBlockPosition = Class.forName("net.minecraft.server." + ver + ".BlockPosition"); + Class clazzWorld = Class.forName("net.minecraft.server." + ver + ".World"); + Class clazzIBlockData = Class.forName("net.minecraft.server." + ver + ".IBlockData"); + Class clazzBlock = Class.forName("net.minecraft.server." + ver + ".Block"); + + getHandle = clazzCraftWorld.getMethod("getHandle"); + updateAdjacentComparators = clazzWorld.getMethod("updateAdjacentComparators", clazzBlockPosition, clazzBlock); + getNMS = clazzCraftBlock.getMethod("getNMS"); + getBlock = clazzIBlockData.getMethod("getBlock"); + } + + // invoke and cast objects. + Object craftWorld = clazzCraftWorld.cast(location.getWorld()); + Object world = getHandle.invoke(craftWorld); + Object craftBlock = clazzCraftBlock.cast(location.getBlock()); + Object iBlockData = getNMS.invoke(craftBlock); + + // Invoke final method. + updateAdjacentComparators + .invoke(world, clazzBlockPosition.getConstructor(double.class, double.class, double.class) + .newInstance(location.getX(), location.getY(), location.getZ()), + getBlock.invoke(iBlockData)); + + } catch (ReflectiveOperationException e) { + e.printStackTrace(); + } + } + + private boolean canMove(Inventory inventory, ItemStack item) { + if (inventory.firstEmpty() != -1) return true; + for (ItemStack stack : inventory.getContents()) { + if (stack.isSimilar(item) && (stack.getAmount() + item.getAmount()) - 1 < stack.getMaxStackSize()) { + return true; + } + } + return false; + } + +} \ No newline at end of file diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/ConfigWrapper.java b/src/main/java/com/songoda/epichoppers/utils/ConfigWrapper.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/ConfigWrapper.java rename to src/main/java/com/songoda/epichoppers/utils/ConfigWrapper.java diff --git a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/CostType.java b/src/main/java/com/songoda/epichoppers/utils/CostType.java similarity index 88% rename from EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/CostType.java rename to src/main/java/com/songoda/epichoppers/utils/CostType.java index 55e885f..a615d55 100644 --- a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/CostType.java +++ b/src/main/java/com/songoda/epichoppers/utils/CostType.java @@ -1,4 +1,4 @@ -package com.songoda.epichoppers.api; +package com.songoda.epichoppers.utils; /** * Represents a cost type when making a purchase from EpicSpawners diff --git a/src/main/java/com/songoda/epichoppers/utils/HopperDirection.java b/src/main/java/com/songoda/epichoppers/utils/HopperDirection.java new file mode 100644 index 0000000..374015c --- /dev/null +++ b/src/main/java/com/songoda/epichoppers/utils/HopperDirection.java @@ -0,0 +1,60 @@ +package com.songoda.epichoppers.utils; + +import org.bukkit.Location; + +public enum HopperDirection { + + DOWN(0, 8, 0, -1, 0), + NORTH(2, 10, 0, 0, -1), + SOUTH(3, 11, 0, 0, 1), + WEST(4, 12, -1, 0, 0), + EAST(5, 13, 1, 0, 0); + + private int unpowered; + private int powered; + + private int x; + private int y; + private int z; + + HopperDirection(int unpowered, int powered, int x, int y, int z) { + this.unpowered = unpowered; + this.powered = powered; + + this.x = x; + this.y = y; + this.z = z; + } + + public static HopperDirection getDirection(int value) { + for (HopperDirection hopperDirection : HopperDirection.values()) { + if (hopperDirection.getPowered() == value + || hopperDirection.getUnpowered() == value) return hopperDirection; + } + return null; + } + + public Location getLocation(Location location) { + return location.add(getX(), getY(), getZ()); + } + + public int getX() { + return x; + } + + public int getY() { + return y; + } + + public int getZ() { + return z; + } + + public int getUnpowered() { + return unpowered; + } + + public int getPowered() { + return powered; + } +} \ No newline at end of file diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/Methods.java b/src/main/java/com/songoda/epichoppers/utils/Methods.java similarity index 69% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/Methods.java rename to src/main/java/com/songoda/epichoppers/utils/Methods.java index 6354d5a..5d855dd 100644 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/Methods.java +++ b/src/main/java/com/songoda/epichoppers/utils/Methods.java @@ -1,6 +1,6 @@ package com.songoda.epichoppers.utils; -import com.songoda.epichoppers.EpicHoppersPlugin; +import com.songoda.epichoppers.EpicHoppers; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.entity.Entity; @@ -22,8 +22,81 @@ public class Methods { private static Map serializeCache = new HashMap<>(); + public static boolean isLegacyFuel(Material material) { + if (material == null) return false; + switch(material.ordinal() + 1) { + case 6: + case 7: + case 18: + case 26: + case 36: + case 48: + case 54: + case 55: + case 59: + case 66: + case 73: + case 85: + case 86: + case 97: + case 100: + case 101: + case 108: + case 127: + case 135: + case 136: + case 137: + case 144: + case 147: + case 152: + case 163: + case 164: + case 165: + case 172: + case 174: + case 184: + case 185: + case 186: + case 187: + case 188: + case 189: + case 190: + case 191: + case 192: + case 193: + case 260: + case 262: + case 267: + case 268: + case 269: + case 270: + case 279: + case 280: + case 289: + case 322: + case 323: + case 326: + case 332: + case 345: + case 368: + case 424: + case 426: + case 427: + case 428: + case 429: + case 430: + case 443: + case 444: + case 445: + case 446: + case 447: + return true; + default: + return false; + } + } + public static boolean isSync(Player p) { - try { if (p.getItemInHand().hasItemMeta() && p.getItemInHand().getType() != Material.AIR && p.getItemInHand().getType() != Material.ENCHANTED_BOOK @@ -34,42 +107,31 @@ public class Methods { } } } - } catch (Exception e) { - Debugger.runReport(e); - } return false; } public static ItemStack getGlass() { - try { - EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance(); - return Methods.getGlass(instance.getConfig().getBoolean("Interfaces.Replace Glass Type 1 With Rainbow Glass"), instance.getConfig().getInt("Interfaces.Glass Type 1")); - } catch (Exception e) { - Debugger.runReport(e); - } - return null; + EpicHoppers instance = EpicHoppers.getInstance(); + return Methods.getGlass(instance.getConfig().getBoolean("Interfaces.Replace Glass Type 1 With Rainbow Glass"), instance.getConfig().getInt("Interfaces.Glass Type 1")); } public static ItemStack getBackgroundGlass(boolean type) { - try { - EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance(); - if (type) - return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 2")); - else - return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 3")); - } catch (Exception e) { - Debugger.runReport(e); - } - return null; + EpicHoppers instance = EpicHoppers.getInstance(); + if (type) + return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 2")); + else + return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 3")); } private static ItemStack getGlass(Boolean rainbow, int type) { int randomNum = 1 + (int) (Math.random() * 6); ItemStack glass; if (rainbow) { - glass = new ItemStack(Material.LEGACY_STAINED_GLASS_PANE, 1, (short) randomNum); + glass = new ItemStack(EpicHoppers.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? + Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) randomNum); } else { - glass = new ItemStack(Material.LEGACY_STAINED_GLASS_PANE, 1, (short) type); + glass = new ItemStack(EpicHoppers.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? + Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) type); } ItemMeta glassmeta = glass.getItemMeta(); glassmeta.setDisplayName("§l"); @@ -78,8 +140,7 @@ public class Methods { } public static String formatName(int level, boolean full) { - try { - EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance(); + EpicHoppers instance = EpicHoppers.getInstance(); String name = instance.getLocale().getMessage("general.nametag.nameformat", level); String info = ""; @@ -88,22 +149,14 @@ public class Methods { } return info + Methods.formatText(name); - } catch (Exception e) { - Debugger.runReport(e); - } - return null; } public static void doParticles(Entity entity, Location location) { - try { - EpicHoppersPlugin instance = EpicHoppersPlugin.getInstance(); + EpicHoppers instance = EpicHoppers.getInstance(); location.setX(location.getX() + .5); location.setY(location.getY() + .5); location.setZ(location.getZ() + .5); entity.getWorld().spawnParticle(org.bukkit.Particle.valueOf(instance.getConfig().getString("Main.Upgrade Particle Type")), location, 200, .5, .5, .5); - } catch (Exception e) { - Debugger.runReport(e); - } } /** diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/Metrics.java b/src/main/java/com/songoda/epichoppers/utils/Metrics.java similarity index 99% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/Metrics.java rename to src/main/java/com/songoda/epichoppers/utils/Metrics.java index 1923ea3..792f0cd 100644 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/Metrics.java +++ b/src/main/java/com/songoda/epichoppers/utils/Metrics.java @@ -103,7 +103,7 @@ public class Metrics { config.options().header( "bStats collects some data for plugin authors like how many servers are using their plugins.\n" + "To honor their work, you should not disable it.\n" + - "This has nearly no effect on the server performance!\n" + + "This has nearly blacklist effect on the server performance!\n" + "Check out https://bStats.org/ to learn more :)" ).copyDefaults(true); try { @@ -176,7 +176,7 @@ public class Metrics { } }, 1000 * 60 * 5, 1000 * 60 * 30); // Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start - // WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted! + // WARNING: Changing the frequency has blacklist effect but your plugin WILL be blocked/deleted! // WARNING: Just don't do it! } diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/MySQLDatabase.java b/src/main/java/com/songoda/epichoppers/utils/MySQLDatabase.java similarity index 93% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/MySQLDatabase.java rename to src/main/java/com/songoda/epichoppers/utils/MySQLDatabase.java index c8253f6..fa70851 100644 --- a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/MySQLDatabase.java +++ b/src/main/java/com/songoda/epichoppers/utils/MySQLDatabase.java @@ -1,6 +1,6 @@ package com.songoda.epichoppers.utils; -import com.songoda.epichoppers.EpicHoppersPlugin; +import com.songoda.epichoppers.EpicHoppers; import java.sql.Connection; import java.sql.DriverManager; @@ -8,11 +8,11 @@ import java.sql.SQLException; public class MySQLDatabase { - private final EpicHoppersPlugin instance; + private final EpicHoppers instance; private Connection connection; - public MySQLDatabase(EpicHoppersPlugin instance) { + public MySQLDatabase(EpicHoppers instance) { this.instance = instance; try { Class.forName("com.mysql.jdbc.Driver"); diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/Serializers.java b/src/main/java/com/songoda/epichoppers/utils/Serializers.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/Serializers.java rename to src/main/java/com/songoda/epichoppers/utils/Serializers.java diff --git a/src/main/java/com/songoda/epichoppers/utils/ServerVersion.java b/src/main/java/com/songoda/epichoppers/utils/ServerVersion.java new file mode 100644 index 0000000..34f6ca5 --- /dev/null +++ b/src/main/java/com/songoda/epichoppers/utils/ServerVersion.java @@ -0,0 +1,27 @@ +package com.songoda.epichoppers.utils; + +public enum ServerVersion { + + UNKNOWN("unknown_server_version"), + V1_7("org.bukkit.craftbukkit.v1_7"), + V1_8("org.bukkit.craftbukkit.v1_8"), + V1_9("org.bukkit.craftbukkit.v1_9"), + V1_10("org.bukkit.craftbukkit.v1_10"), + V1_11("org.bukkit.craftbukkit.v1_11"), + V1_12("org.bukkit.craftbukkit.v1_12"), + V1_13("org.bukkit.craftbukkit.v1_13"), + V1_14("org.bukkit.craftbukkit.v1_14"); + + + private final String packagePrefix; + + ServerVersion(String packagePrefix) { + this.packagePrefix = packagePrefix; + } + + public static ServerVersion fromPackageName(String packageName) { + for (ServerVersion version : values()) + if (packageName.startsWith(version.packagePrefix)) return version; + return ServerVersion.UNKNOWN; + } +} \ No newline at end of file diff --git a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/TeleportTrigger.java b/src/main/java/com/songoda/epichoppers/utils/TeleportTrigger.java similarity index 61% rename from EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/TeleportTrigger.java rename to src/main/java/com/songoda/epichoppers/utils/TeleportTrigger.java index 60b48cf..f70b0d7 100644 --- a/EpicHoppers-API/src/main/java/com/songoda/epichoppers/api/hopper/TeleportTrigger.java +++ b/src/main/java/com/songoda/epichoppers/utils/TeleportTrigger.java @@ -1,4 +1,4 @@ -package com.songoda.epichoppers.api.hopper; +package com.songoda.epichoppers.utils; public enum TeleportTrigger { DISABLED, diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/gui/AbstractGUI.java b/src/main/java/com/songoda/epichoppers/utils/gui/AbstractGUI.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/gui/AbstractGUI.java rename to src/main/java/com/songoda/epichoppers/utils/gui/AbstractGUI.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/gui/Clickable.java b/src/main/java/com/songoda/epichoppers/utils/gui/Clickable.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/gui/Clickable.java rename to src/main/java/com/songoda/epichoppers/utils/gui/Clickable.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/gui/OnClose.java b/src/main/java/com/songoda/epichoppers/utils/gui/OnClose.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/gui/OnClose.java rename to src/main/java/com/songoda/epichoppers/utils/gui/OnClose.java diff --git a/EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/gui/Range.java b/src/main/java/com/songoda/epichoppers/utils/gui/Range.java similarity index 100% rename from EpicHoppers-Plugin/src/main/java/com/songoda/epichoppers/utils/gui/Range.java rename to src/main/java/com/songoda/epichoppers/utils/gui/Range.java diff --git a/src/main/java/com/songoda/epichoppers/utils/settings/Category.java b/src/main/java/com/songoda/epichoppers/utils/settings/Category.java new file mode 100644 index 0000000..4fbec92 --- /dev/null +++ b/src/main/java/com/songoda/epichoppers/utils/settings/Category.java @@ -0,0 +1,29 @@ +package com.songoda.epicspawners.utils.settings; + +public enum Category { + + ECONOMY("Settings regarding economy.", + "Only one economy option can be used at a time. If you enable more than", + "one of these the first one will be used."), + SPAWNER_BOOSTING("These are settings regarding the boosting of spawners."), + SPAWNER_DROPS("These are settings regarding spawner drops."), + ENTITY("These are settings regarding entities."), + MAIN("General settings and options."), + MAIN_EQUATIONS("These are settings relating to equations."), + INTERFACES("These settings allow you to alter the way interfaces look.", + "They are used in GUI's to make patterns, change them up then open up a", + "GUI to see how it works."), + DATABASE("Settings regarding the Database."), + SYSTEM("System related settings."); + + private String[] comments; + + + Category(String... comments) { + this.comments = comments; + } + + public String[] getComments() { + return comments; + } +} \ No newline at end of file diff --git a/src/main/java/com/songoda/epichoppers/utils/settings/Setting.java b/src/main/java/com/songoda/epichoppers/utils/settings/Setting.java new file mode 100644 index 0000000..f6d5d32 --- /dev/null +++ b/src/main/java/com/songoda/epichoppers/utils/settings/Setting.java @@ -0,0 +1,300 @@ +package com.songoda.epicspawners.utils.settings; + +import com.songoda.epicspawners.EpicSpawners; +import com.songoda.epicspawners.utils.ServerVersion; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public enum Setting { + + SPAWNERS_MAX("Main.Spawner Max Upgrade", 5, + "The maximum level a spawner can be upgraded to."), + + NAME_FORMAT("Main.Spawner Name Format", "&e{TYPE} &fSpawner [&c{AMT}x]", + "The text displayed in the hologram positioned above every spawner."), + + FORCE_COMBINE_RADIUS("Main.Force Combine Radius", 0, + "Spawners placed next to each other within this radius will automatically", + "combine with each other."), + + FORCE_COMBINE_DENY("Main.Deny Place On Force Combine", false, + "Prevent spawners from being placed next to each other within the specified radius."), + + SEARCH_RADIUS("Main.Radius To Search Around Spawners", "8x4x8", + "The radius checked around a spawner before spawning entities.", + "By default this is used to make sure there are no more than 7 entities", + "around any single spawner."), + + ALERT_PLACE_BREAK("Main.Alerts On Place And Break", true, + "Toggle an alerting chat message after triggered by placing or breaking a spawner."), + + SNEAK_FOR_STACK("Main.Sneak To Receive A Stacked Spawner", true, + "Toggle ability to receive a stacked spawner when breaking a spawner while sneaking."), + + SPAWNER_HOLOGRAMS("Main.Spawners Have Holograms", true, + "Toggle holograms showing above spawners."), + + ONLY_DROP_PLACED("Main.Only Drop Placed Spawner", false, + "Should natural mob spawners drop upon being broken?"), + + ONLY_CHARGE_NATURAL("Main.Only Charge Natural Spawners", false, + "Should map generated spawners charge a price in order to be broken?", + "You can configure the cost for each spawner type in the Spawners.yml."), + + CUSTOM_SPAWNER_TICK_RATE("Main.Custom Spawner Tick Rate", 10, + "The tick rate in which spawners will attempt to spawn.", + "Making this smaller or larger will not effect a spawners spawn rate as", + "this value only effects the frequency in which a spawn attempt is triggered."), + + RANDOM_LOW_HIGH("Main.Random Amount Added To Each Spawn", "1:4", + "Spawners will always spawn a single entity for every level it contains multiplied", + "by a random number generated between (by default) 1 and 4.", + "For example if the random number 3 is generated then by default", + "a level 5 spawner will spawn (5 * 3) entities which would be 15."), + + SOUNDS_ENABLED("Main.Sounds Enabled", true, + "Toggles various sound effects used throughout the plugin."), + + DISPLAY_LEVEL_ONE("Main.Display Level In Spawner Title If Level 1", false, + "Should a spawners hologram display its level if it's level one?"), + + OMNI_SPAWNERS("Main.OmniSpawners Enabled", true, + "Should spawners of different mob types be stackable into a single spawner?"), + + EGGS_CONVERT_SPAWNERS("Main.Convert Spawners With Eggs", true, + "Ability to change mob spawner type with spawn eggs."), + + HELPFUL_TIPS_ENABLED("Main.Display Helpful Tips For Operators", true, + "Show tips to server operators."), + + UPGRADE_WITH_ECO_ENABLED("Main.Upgrade With Economy", true, + "Can spawners be upgraded with money?"), + + UPGRADE_WITH_XP_ENABLED("Main.Upgrade With XP", true, + "Can spawners be upgraded with XP levels?"), + + UPGRADE_COST_ECONOMY("Main.Cost To Upgrade With Economy", 10000, + "Cost to upgrade a spawners level."), + + UPGRADE_COST_EXPERIANCE("Main.Cost To Upgrade With XP", 50, + "Experience cost to upgrade a spawners level."), + + USE_CUSTOM_UPGRADE_EQUATION("Main.Use Custom Equations for Upgrade Costs", false, + "Should custom equations be used to generate upgrade costs?"), + + LIQUID_REPEL_RADIUS("Main.Spawner Repel Liquid Radius", 1, + "Prevent water from flowing next to or on top of a spawner within the here declared radius.", + "Set to 0 to disable."), + + REDSTONE_ACTIVATE("Main.Redstone Power Deactivates Spawners", true, + "Does redstone power disable a spawner?"), + + DISPLAY_HELP_BUTTON("Main.Display Help Button In Spawner Overview", true, + "should the button be visible in each spawners overview GUI."), + + SPAWNERS_DONT_EXPLODE("Main.Prevent Spawners From Exploding", false, + "Should spawners break when blown up?"), + + SPAWNERS_TO_INVENTORY("Main.Add Spawners To Inventory On Drop", false, + "Should broken spawners be added directly to the players inventory?", + "Alternatively they will drop to the ground?"), + + UPGRADE_PARTICLE_TYPE("Main.Upgrade Particle Type", "SPELL_WITCH", + "The name of the particle shown when upgrading a spawner."), + + EXTRA_SPAWN_TICKS("Main.Extra Ticks Added To Each Spawn", 0, + "After every spawner successfully spawns, a new delay is added to it.", + "That delay is different for every spawner type and can be configured in the Spawners.yml", + "The number configured here is then added to that delay."), + + MAX_SPAWNERS("Main.Max Spawners Per Player", -1, + "The maximum amount of spawners a player can place. Set to -1 to allow unlimited", + "spawner placement."), + + AUTOSAVE("Main.Auto Save Interval In Seconds", 15, + "The amount of time in between saving to file.", + "This is purely a safety function to prevent against unplanned crashes or", + "restarts. With that said it is advised to keep this enabled.", + "If however you enjoy living on the edge, feel free to turn it off."), + + NO_AI("Main.Nerf Spawner Mobs", false, + "If enabled mobs spawned by spawners will not move or attack."), + + COST_EQUATION_EXPERIANCE("Main.Equations.Calculate XP Upgrade Cost", "{XPCost} * {Level}", + "The equation used to calculate the experience upgrade cost."), + + COST_EQUATION_ECONOMY("Main.Equations.Calculate Economy Upgrade Cost", "{ECOCost} * {Level}", + "The equation used to calculate the economy upgrade cost."), + + SPAWNER_EQUATION_SPAWNS("Main.Equations.Mobs Spawned Per Spawn", "{MULTI} * {RAND}", + "The equation that defines the amount of mobs a spawner will spawn each time it is triggered."), + + NAMED_SPAWNER_TIERS("Main.Named Spawners Tiers", false, + "Whether or not spawners will have names rather than numbers."), + + TIER_NAMES("Main.Tier Names", Arrays.asList("&7Common", "&6Uncommon", "&4Rare", "&5Mythic"), + "The names of each spawner tier.", + "Where one spawner is common, two is uncommon, three is rate, and four and mythic."), + + MAX_PLAYER_BOOST("Spawner Boosting.Max Multiplier For A Spawner Boost", 5, + "The highest multiplier a spawner can be boosted to."), + + BOOST_COST("Spawner Boosting.Item Charged For A Boost", "DIAMOND:2", + "The cost required when a player boosts their own spawner.", + "If you would rather charge experience or economy then enter respectively", + "ECO or XP in place of the default DIAMOND."), + + HOSTILE_MOBS_ATTACK_SECOND("entity.Hostile Mobs Attack Second", false, + "Should hostile mobs attack only if attacked first?"), + + ONLY_DROP_STACKED("Spawner Drops.Only Drop Stacked Spawners", false, + "Should stacked spawners always drop their whole stack when broken?"), + + MOB_KILLING_COUNT("Spawner Drops.Allow Killing Mobs To Drop Spawners", true, + "Should spawners drop when enough mobs of that spawners type are killed?"), + + COUNT_UNNATURAL_KILLS("Spawner Drops.Count Unnatural Kills Towards Spawner Drop", false, + "Can mobs from spawners count towards the spawner drop count?"), + + KILL_GOAL("Spawner Drops.Kills Needed for Drop", 100, + "Amount of mob kills required to drop a spawner."), + + ALERT_INTERVAL("Spawner Drops.Alert Every X Before Drop", 10, + "Alert players every x amount of kills before dropping spawner."), + + DROP_ON_CREEPER_EXPLOSION("Spawner Drops.Drop On Creeper Explosion", true, + "Should a spawner destroyed by a creeper drop?"), + + DROP_ON_TNT_EXPLOSION("Spawner Drops.Drop On TNT Explosion", true, + "Should a spawner destroyed by TNT drop?"), + + EXPLOSION_DROP_CHANCE_TNT("Spawner Drops.Chance On TNT Explosion", "100%", + "Chance of a TNT explosion dropping a spawner."), + + EXPLOSION_DROP_CHANCE_CREEPER("Spawner Drops.Chance On Creeper Explosion", "100%", + "Chance of a creeper explosion dropping a spawner."), + + SILKTOUCH_SPAWNERS("Spawner Drops.Drop On SilkTouch", true, + "Do spawners drop when broken with a pick enchanted with silk touch?"), + + SILKTOUCH_MIN_LEVEL("Spawner Drops.Minimum Required Silktouch Level", 1, + "What level of silk touch is required to drop a spawner?"), + + SILKTOUCH_NATURAL_SPAWNER_DROP_CHANCE("Spawner Drops.Chance On Natural Silktouch", "100%", + "Chance of a natural spawner dropping with silk touch."), + + SILKTOUCH_PLACED_SPAWNER_DROP_CHANCE("Spawner Drops.Chance On Placed Silktouch", "100%", + "Chance of a placed spawner dropping with silk touch."), + + VAULT_ECONOMY("Economy.Use Vault Economy", true, + "Should Vault be used?"), + + PLAYER_POINTS_ECONOMY("Economy.Use Player Points Economy", false, + "Should PlayerPoints be used?"), + + EXIT_ICON("Interfaces.Exit Icon", EpicSpawners.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? "OAK_DOOR" : "WOOD_DOOR", + "Item to be displayed as the icon for exiting the interface."), + + BUY_ICON("Interfaces.Buy Icon", "EMERALD", + "Item to be displayed as the icon for buying a spawner."), + + ECO_ICON("Interfaces.Economy Icon", EpicSpawners.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? "SUNFLOWER" : "DOUBLE_PLANT", + "Item to be displayed as the icon for economy upgrades."), + + XP_ICON("Interfaces.XP Icon", EpicSpawners.getInstance().isServerVersionAtLeast(ServerVersion.V1_13) ? "EXPERIENCE_BOTTLE" : "EXP_BOTTLE", + "Item to be displayed as the icon for XP upgrades."), + + GLASS_TYPE_1("Interfaces.Glass Type 1", 7), + GLASS_TYPE_2("Interfaces.Glass Type 2", 11), + GLASS_TYPE_3("Interfaces.Glass Type 3", 3), + RAINBOW_GLASS("Interfaces.Replace Glass Type 1 With Rainbow Glass", false), + + DATABASE_SUPPORT("Database.Activate Mysql Support", false, + "Should MySQL be used for data storage?"), + + DATABASE_IP("Database.IP", "127.0.0.1", + "MySQL IP"), + + DATABASE_PORT("Database.Port", 3306, + "MySQL Port"), + + DATABASE_NAME("Database.Database Name", "EpicSpawners", + "The database you are inserting data into."), + + DATABASE_PREFIX("Database.Prefix", "ES-", + "The prefix for tables inserted into the database."), + + DATABASE_USERNAME("Database.Username", "PUT_USERNAME_HERE", + "MySQL Username"), + + DATABASE_PASSWORD("Database.Password", "PUT_PASSWORD_HERE", + "MySQL Password"), + + LANGUGE_MODE("System.Language Mode", "en_US", + "The enabled language file.", + "More language files (if available) can be found in the plugins data folder."); + + private String setting; + private Object option; + private String[] comments; + + Setting(String setting, Object option, String... comments) { + this.setting = setting; + this.option = option; + this.comments = comments; + } + + Setting(String setting, Object option) { + this.setting = setting; + this.option = option; + this.comments = null; + } + + public static Setting getSetting(String setting) { + List settings = Arrays.stream(values()).filter(setting1 -> setting1.setting.equals(setting)).collect(Collectors.toList()); + if (settings.isEmpty()) return null; + return settings.get(0); + } + + public String getSetting() { + return setting; + } + + public Object getOption() { + return option; + } + + public String[] getComments() { + return comments; + } + + public List getStringList() { + return EpicSpawners.getInstance().getConfig().getStringList(setting); + } + + public boolean getBoolean() { + return EpicSpawners.getInstance().getConfig().getBoolean(setting); + } + + public int getInt() { + return EpicSpawners.getInstance().getConfig().getInt(setting); + } + + public long getLong() { + return EpicSpawners.getInstance().getConfig().getLong(setting); + } + + public String getString() { + return EpicSpawners.getInstance().getConfig().getString(setting); + } + + public char getChar() { + return EpicSpawners.getInstance().getConfig().getString(setting).charAt(0); + } + + public double getDouble() { + return EpicSpawners.getInstance().getConfig().getDouble(setting); + } +} \ No newline at end of file diff --git a/src/main/java/com/songoda/epichoppers/utils/settings/SettingsManager.java b/src/main/java/com/songoda/epichoppers/utils/settings/SettingsManager.java new file mode 100644 index 0000000..a08c29f --- /dev/null +++ b/src/main/java/com/songoda/epichoppers/utils/settings/SettingsManager.java @@ -0,0 +1,309 @@ +package com.songoda.epicspawners.utils.settings; + +import com.songoda.epicspawners.EpicSpawners; +import com.songoda.epicspawners.utils.Methods; +import com.songoda.epicspawners.utils.ServerVersion; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.configuration.file.FileConfiguration; +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.player.AsyncPlayerChatEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.io.*; +import java.util.*; + +/** + * Created by songoda on 6/4/2017. + */ +public class SettingsManager implements Listener { + + private final EpicSpawners plugin; + private Map cat = new HashMap<>(); + private Map current = new HashMap<>(); + + public SettingsManager(EpicSpawners plugin) { + this.plugin = plugin; + Bukkit.getPluginManager().registerEvents(this, plugin); + } + + @EventHandler + public void onInventoryClick(InventoryClickEvent event) { + ItemStack clickedItem = event.getCurrentItem(); + + if (event.getInventory() != event.getWhoClicked().getOpenInventory().getTopInventory() + || clickedItem == null || !clickedItem.hasItemMeta() + || !clickedItem.getItemMeta().hasDisplayName()) { + return; + } + + if (event.getView().getTitle().equals(plugin.getName() + " Settings Manager")) { + event.setCancelled(true); + if (clickedItem.getType().name().contains("STAINED_GLASS")) return; + + String type = ChatColor.stripColor(clickedItem.getItemMeta().getDisplayName()); + this.cat.put((Player) event.getWhoClicked(), type); + this.openEditor((Player) event.getWhoClicked()); + } else if (event.getView().getTitle().equals(plugin.getName() + " Settings Editor")) { + event.setCancelled(true); + if (clickedItem.getType().name().contains("STAINED_GLASS")) return; + + Player player = (Player) event.getWhoClicked(); + + String key = cat.get(player) + "." + ChatColor.stripColor(clickedItem.getItemMeta().getDisplayName()); + + if (plugin.getConfig().get(key).getClass().getName().equals("java.lang.Boolean")) { + this.plugin.getConfig().set(key, !plugin.getConfig().getBoolean(key)); + this.finishEditing(player); + } else { + this.editObject(player, key); + } + } + } + + @EventHandler + public void onChat(AsyncPlayerChatEvent event) { + Player player = event.getPlayer(); + if (!current.containsKey(player)) return; + + String value = current.get(player); + FileConfiguration config = plugin.getConfig(); + if (config.isLong(value)) { + config.set(value, Long.parseLong(event.getMessage())); + } else if (config.isInt(value)) { + config.set(value, Integer.parseInt(event.getMessage())); + } else if (config.isDouble(value)) { + config.set(value, Double.parseDouble(event.getMessage())); + } else if (config.isString(value)) { + config.set(value, event.getMessage()); + } + + Bukkit.getScheduler().scheduleSyncDelayedTask(EpicSpawners.getInstance(), () -> + this.finishEditing(player), 0L); + + event.setCancelled(true); + } + + private void finishEditing(Player player) { + this.current.remove(player); + this.saveConfig(); + this.openEditor(player); + } + + private void editObject(Player player, String current) { + this.current.put(player, ChatColor.stripColor(current)); + + player.closeInventory(); + player.sendMessage(""); + player.sendMessage(Methods.formatText("&7Please enter a value for &6" + current + "&7.")); + if (plugin.getConfig().isInt(current) || plugin.getConfig().isDouble(current)) { + player.sendMessage(Methods.formatText("&cUse only numbers.")); + } + player.sendMessage(""); + } + + public void openSettingsManager(Player player) { + Inventory inventory = Bukkit.createInventory(null, 27, plugin.getName() + " Settings Manager"); + ItemStack glass = Methods.getGlass(); + for (int i = 0; i < inventory.getSize(); i++) { + inventory.setItem(i, glass); + } + + int slot = 10; + for (String key : plugin.getConfig().getDefaultSection().getKeys(false)) { + ItemStack item = new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.LEGACY_WOOL : Material.valueOf("WOOL"), 1, (byte) (slot - 9)); + ItemMeta meta = item.getItemMeta(); + meta.setLore(Collections.singletonList(Methods.formatText("&6Click To Edit This Category."))); + meta.setDisplayName(Methods.formatText("&f&l" + key)); + item.setItemMeta(meta); + inventory.setItem(slot, item); + slot++; + } + + player.openInventory(inventory); + } + + private void openEditor(Player player) { + Inventory inventory = Bukkit.createInventory(null, 54, plugin.getName() + " Settings Editor"); + FileConfiguration config = plugin.getConfig(); + + int slot = 0; + for (String key : config.getConfigurationSection(cat.get(player)).getKeys(true)) { + String fKey = cat.get(player) + "." + key; + ItemStack item = new ItemStack(Material.DIAMOND_HELMET); + ItemMeta meta = item.getItemMeta(); + meta.setDisplayName(Methods.formatText("&6" + key)); + + List lore = new ArrayList<>(); + if (config.isBoolean(fKey)) { + item.setType(Material.LEVER); + lore.add(Methods.formatText(config.getBoolean(fKey) ? "&atrue" : "&cfalse")); + } else if (config.isString(fKey)) { + item.setType(Material.PAPER); + lore.add(Methods.formatText("&7" + config.getString(fKey))); + } else if (config.isInt(fKey)) { + item.setType(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH")); + lore.add(Methods.formatText("&7" + config.getInt(fKey))); + } else if (config.isLong(fKey)) { + item.setType(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH")); + lore.add(Methods.formatText("&7" + config.getLong(fKey))); + } else if (config.isDouble(fKey)) { + item.setType(plugin.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.CLOCK : Material.valueOf("WATCH")); + lore.add(Methods.formatText("&7" + config.getDouble(fKey))); + } + + Setting setting = Setting.getSetting(fKey); + + if (setting != null && setting.getComments() != null) { + lore.add(""); + + String comment = String.join(" ", setting.getComments()); + + int lastIndex = 0; + for (int n = 0; n < comment.length(); n++) { + if (n - lastIndex < 30) + continue; + + if (comment.charAt(n) == ' ') { + lore.add(Methods.formatText("&8" + comment.substring(lastIndex, n).trim())); + lastIndex = n; + } + } + + if (lastIndex - comment.length() < 30) + lore.add(Methods.formatText("&8" + comment.substring(lastIndex).trim())); + + } + + meta.setLore(lore); + item.setItemMeta(meta); + + inventory.setItem(slot, item); + slot++; + } + + player.openInventory(inventory); + } + + public void reloadConfig() { + plugin.reloadConfig(); + this.setupConfig(); + } + + public void setupConfig() { + FileConfiguration config = plugin.getConfig(); + + for (Setting setting : Setting.values()) { + config.addDefault(setting.getSetting(), setting.getOption()); + } + plugin.getConfig().options().copyDefaults(true); + saveConfig(); + } + + private void saveConfig() { + String dump = plugin.getConfig().saveToString(); + + StringBuilder config = new StringBuilder(); + + BufferedReader bufReader = new BufferedReader(new StringReader(dump)); + + try { + boolean first = true; + + String line; + int currentTab = 0; + String category = ""; + + while ((line = bufReader.readLine()) != null) { + if (line.trim().startsWith("#")) continue; + + int tabChange = line.length() - line.trim().length(); + if (currentTab != tabChange) { + category = category.contains(".") && tabChange != 0 ? category.substring(0, category.indexOf(".")) : ""; + currentTab = tabChange; + } + + if (line.endsWith(":")) { + bufReader.mark(1000); + String found = bufReader.readLine(); + bufReader.reset(); + + if (!found.trim().startsWith("-")) { + + String newCategory = line.substring(0, line.length() - 1).trim(); + + if (category.equals("")) + category = newCategory; + else + category += "." + newCategory; + + currentTab = tabChange + 2; + + if (!first) { + config.append("\n\n"); + } else { + first = false; + } + + if (!category.contains(".")) + config.append("#").append("\n"); + try { + Category categoryObj = Category.valueOf(category.toUpperCase() + .replace(" ", "_") + .replace(".", "_")); + + config.append(new String(new char[tabChange]).replace('\0', ' ')); + for (String l : categoryObj.getComments()) + config.append("# ").append(l).append("\n"); + } catch (IllegalArgumentException e) { + config.append("# ").append(category).append("\n"); + } + if (!category.contains(".")) + config.append("#").append("\n"); + + config.append(line).append("\n"); + + continue; + } + } + + if (line.trim().startsWith("-")) { + config.append(line).append("\n"); + continue; + } + + String key = category + "." + (line.split(":")[0].trim()); + for (Setting setting : Setting.values()) { + if (!setting.getSetting().equals(key) || setting.getComments() == null) continue; + config.append(" ").append("\n"); + for (String l : setting.getComments()) { + config.append(new String(new char[currentTab]).replace('\0', ' ')); + config.append("# ").append(l).append("\n"); + } + } + config.append(line).append("\n"); + } + } catch (IOException e) { + e.printStackTrace(); + } + + try { + if (!plugin.getDataFolder().exists()) + plugin.getDataFolder().mkdir(); + BufferedWriter writer = + new BufferedWriter(new FileWriter(new File(plugin.getDataFolder() + File.separator + "config.yml"))); + writer.write(config.toString()); + writer.flush(); + writer.close(); + + } catch (IOException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/EpicHoppers-Plugin/src/main/resources/en_US.lang b/src/main/resources/en_US.lang similarity index 97% rename from EpicHoppers-Plugin/src/main/resources/en_US.lang rename to src/main/resources/en_US.lang index 2eb997f..7fca323 100644 --- a/EpicHoppers-Plugin/src/main/resources/en_US.lang +++ b/src/main/resources/en_US.lang @@ -41,7 +41,7 @@ interface.hopper.blocklore = "|&7BlockBreak is set to &6%enabled%&7." interface.hopper.synchopper = "&6Click to Link This hopper" interface.hopper.rejectsync = "&6Click to Link Rejected Items" interface.filter.infotitle = "&aFilter Guide" -interface.filter.infolore = "&7Items placed in the leftmost column|&7space will be whitelisted.||&7Items placed in the rightmost column|&7will be void.||&7Items placed in the middle column|&7will be blacklisted.||&cUsing the whitelist will disable|&cboth the blacklist and the void." +interface.filter.infolore = "&7Items placed in the leftmost column|&7space will be whitelisted.||&7Items placed in the rightmost column|&7will be void.||&7Items placed in the middle column|&7will be blacklisted." interface.filter.whitelist = "&f&lWhite List" interface.filter.blacklist = "&8&lBlack List" interface.filter.void = "&c&lVoid" diff --git a/EpicHoppers-Plugin/src/main/resources/levels.yml b/src/main/resources/levels.yml similarity index 100% rename from EpicHoppers-Plugin/src/main/resources/levels.yml rename to src/main/resources/levels.yml diff --git a/EpicHoppers-Plugin/src/main/resources/plugin.yml b/src/main/resources/plugin.yml similarity index 88% rename from EpicHoppers-Plugin/src/main/resources/plugin.yml rename to src/main/resources/plugin.yml index 1771883..848d6ff 100644 --- a/EpicHoppers-Plugin/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: EpicHoppers description: EpicHoppers -main: com.songoda.epichoppers.EpicHoppersPlugin +main: com.songoda.epichoppers.EpicHoppers softdepend: [LiquidTanks, WildStacker, Towny, RedProtect, Kingdoms, PlotsSquared, GriefPrevention, USkyBlock, ASkyBlock, WorldGuard, Factions, Vault] version: maven-version-number author: Songoda