From 7a97c45fa1d5929f7c0f455396b7851ce490e28b Mon Sep 17 00:00:00 2001 From: Brianna O'Keefe Date: Thu, 30 Aug 2018 14:47:46 -0400 Subject: [PATCH] Implemented real API system. Added in the HookHandler v3 --- EpicFarming-API/EpicFarming-API.iml | 24 +++ .../songoda/epicfarming/api/EpicFarming.java | 20 +++ .../epicfarming/api/EpicFarmingAPI.java | 46 ++++++ .../songoda/epicfarming/api/farming/Farm.java | 14 ++ .../epicfarming/api/farming/FarmManager.java | 18 +++ .../epicfarming/api/farming/Level.java | 21 +++ .../epicfarming/api/farming/LevelManager.java | 20 +++ .../epicfarming/api/farming}/UpgradeType.java | 2 +- .../utils/ClaimableProtectionPluginHook.java | 39 +++++ .../api/utils/ProtectionPluginHook.java | 48 ++++++ EpicFarming-Plugin/EpicFarming-Plugin.iml | 26 ++++ .../epicfarming/EpicFarmingPlugin.java | 143 ++++++++++++++---- .../java/com/songoda/epicfarming/Locale.java | 0 .../com/songoda/epicfarming/References.java | 2 +- .../epicfarming/events/BlockListeners.java | 28 ++-- .../epicfarming/events/EntityListeners.java | 0 .../epicfarming/events/InteractListeners.java | 11 +- .../events/InventoryListeners.java | 12 +- .../com/songoda/epicfarming/farming/Crop.java | 1 + .../songoda/epicfarming/farming/EFarm.java | 32 ++-- .../epicfarming/farming/EFarmManager.java | 10 +- .../songoda/epicfarming/farming/ELevel.java | 17 ++- .../epicfarming/farming/ELevelManager.java | 22 ++- .../epicfarming/handlers/CommandHandler.java | 12 +- .../epicfarming/handlers/FarmingHandler.java | 13 +- .../epicfarming/handlers/GrowthHandler.java | 8 +- .../epicfarming/hooks/HookASkyBlock.java | 60 ++++++++ .../epicfarming/hooks/HookFactions.java | 45 ++++++ .../hooks/HookGriefPrevention.java | 30 ++++ .../epicfarming/hooks/HookKingdoms.java | 38 +++++ .../epicfarming/hooks/HookPlotSquared.java | 29 ++++ .../epicfarming/hooks/HookRedProtect.java | 32 ++++ .../songoda/epicfarming/hooks/HookTowny.java | 59 ++++++++ .../epicfarming/hooks/HookUSkyBlock.java | 38 +++++ .../epicfarming/hooks/HookWorldGuard.java | 27 ++++ .../player/PlayerActionManager.java | 0 .../epicfarming/player/PlayerData.java | 8 +- .../songoda/epicfarming/utils/CropType.java | 4 - .../songoda/epicfarming/utils/Debugger.java | 4 +- .../songoda/epicfarming/utils/Methods.java | 30 +--- .../epicfarming/utils/SettingsManager.java | 7 +- .../main/resources/SettingDefinitions.yml | 0 .../src}/main/resources/en_US.lang | 0 .../src}/main/resources/plugin.yml | 0 .../epicfarming/handlers/HookHandler.java | 114 -------------- .../epicfarming/hooks/ASkyBlockHook.java | 64 -------- .../epicfarming/hooks/FactionsHook.java | 56 ------- .../hooks/GriefPreventionHook.java | 38 ----- .../com/songoda/epicfarming/hooks/Hook.java | 40 ----- .../epicfarming/hooks/KingdomsHook.java | 43 ------ .../epicfarming/hooks/PlotSquaredHook.java | 38 ----- .../epicfarming/hooks/RedProtectHook.java | 34 ----- .../songoda/epicfarming/hooks/TownyHook.java | 56 ------- .../epicfarming/hooks/USkyBlockHook.java | 49 ------ .../epicfarming/hooks/WorldGuardHook.java | 31 ---- 55 files changed, 866 insertions(+), 697 deletions(-) create mode 100644 EpicFarming-API/EpicFarming-API.iml create mode 100644 EpicFarming-API/src/main/java/com/songoda/epicfarming/api/EpicFarming.java create mode 100644 EpicFarming-API/src/main/java/com/songoda/epicfarming/api/EpicFarmingAPI.java create mode 100644 EpicFarming-API/src/main/java/com/songoda/epicfarming/api/farming/Farm.java create mode 100644 EpicFarming-API/src/main/java/com/songoda/epicfarming/api/farming/FarmManager.java create mode 100644 EpicFarming-API/src/main/java/com/songoda/epicfarming/api/farming/Level.java create mode 100644 EpicFarming-API/src/main/java/com/songoda/epicfarming/api/farming/LevelManager.java rename {src/main/java/com/songoda/epicfarming/api => EpicFarming-API/src/main/java/com/songoda/epicfarming/api/farming}/UpgradeType.java (53%) create mode 100644 EpicFarming-API/src/main/java/com/songoda/epicfarming/api/utils/ClaimableProtectionPluginHook.java create mode 100644 EpicFarming-API/src/main/java/com/songoda/epicfarming/api/utils/ProtectionPluginHook.java create mode 100644 EpicFarming-Plugin/EpicFarming-Plugin.iml rename src/main/java/com/songoda/epicfarming/EpicFarming.java => EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/EpicFarmingPlugin.java (64%) rename {src => EpicFarming-Plugin/src}/main/java/com/songoda/epicfarming/Locale.java (100%) rename {src => EpicFarming-Plugin/src}/main/java/com/songoda/epicfarming/References.java (64%) rename {src => EpicFarming-Plugin/src}/main/java/com/songoda/epicfarming/events/BlockListeners.java (82%) rename {src => EpicFarming-Plugin/src}/main/java/com/songoda/epicfarming/events/EntityListeners.java (100%) rename {src => EpicFarming-Plugin/src}/main/java/com/songoda/epicfarming/events/InteractListeners.java (75%) rename {src => EpicFarming-Plugin/src}/main/java/com/songoda/epicfarming/events/InventoryListeners.java (88%) rename {src => EpicFarming-Plugin/src}/main/java/com/songoda/epicfarming/farming/Crop.java (92%) rename src/main/java/com/songoda/epicfarming/farming/Farm.java => EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/farming/EFarm.java (90%) rename src/main/java/com/songoda/epicfarming/farming/FarmManager.java => EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/farming/EFarmManager.java (82%) rename src/main/java/com/songoda/epicfarming/farming/Level.java => EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/farming/ELevel.java (77%) rename src/main/java/com/songoda/epicfarming/farming/LevelManager.java => EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/farming/ELevelManager.java (56%) rename {src => EpicFarming-Plugin/src}/main/java/com/songoda/epicfarming/handlers/CommandHandler.java (93%) rename {src => EpicFarming-Plugin/src}/main/java/com/songoda/epicfarming/handlers/FarmingHandler.java (93%) rename {src => EpicFarming-Plugin/src}/main/java/com/songoda/epicfarming/handlers/GrowthHandler.java (89%) create mode 100644 EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookASkyBlock.java create mode 100644 EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookFactions.java create mode 100644 EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookGriefPrevention.java create mode 100644 EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookKingdoms.java create mode 100644 EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookPlotSquared.java create mode 100644 EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookRedProtect.java create mode 100644 EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookTowny.java create mode 100644 EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookUSkyBlock.java create mode 100644 EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookWorldGuard.java rename {src => EpicFarming-Plugin/src}/main/java/com/songoda/epicfarming/player/PlayerActionManager.java (100%) rename {src => EpicFarming-Plugin/src}/main/java/com/songoda/epicfarming/player/PlayerData.java (74%) rename {src => EpicFarming-Plugin/src}/main/java/com/songoda/epicfarming/utils/CropType.java (96%) rename {src => EpicFarming-Plugin/src}/main/java/com/songoda/epicfarming/utils/Debugger.java (88%) rename {src => EpicFarming-Plugin/src}/main/java/com/songoda/epicfarming/utils/Methods.java (55%) rename {src => EpicFarming-Plugin/src}/main/java/com/songoda/epicfarming/utils/SettingsManager.java (97%) rename {src => EpicFarming-Plugin/src}/main/resources/SettingDefinitions.yml (100%) rename {src => EpicFarming-Plugin/src}/main/resources/en_US.lang (100%) rename {src => EpicFarming-Plugin/src}/main/resources/plugin.yml (100%) delete mode 100644 src/main/java/com/songoda/epicfarming/handlers/HookHandler.java delete mode 100644 src/main/java/com/songoda/epicfarming/hooks/ASkyBlockHook.java delete mode 100644 src/main/java/com/songoda/epicfarming/hooks/FactionsHook.java delete mode 100644 src/main/java/com/songoda/epicfarming/hooks/GriefPreventionHook.java delete mode 100644 src/main/java/com/songoda/epicfarming/hooks/Hook.java delete mode 100644 src/main/java/com/songoda/epicfarming/hooks/KingdomsHook.java delete mode 100644 src/main/java/com/songoda/epicfarming/hooks/PlotSquaredHook.java delete mode 100644 src/main/java/com/songoda/epicfarming/hooks/RedProtectHook.java delete mode 100644 src/main/java/com/songoda/epicfarming/hooks/TownyHook.java delete mode 100644 src/main/java/com/songoda/epicfarming/hooks/USkyBlockHook.java delete mode 100644 src/main/java/com/songoda/epicfarming/hooks/WorldGuardHook.java diff --git a/EpicFarming-API/EpicFarming-API.iml b/EpicFarming-API/EpicFarming-API.iml new file mode 100644 index 0000000..59e16af --- /dev/null +++ b/EpicFarming-API/EpicFarming-API.iml @@ -0,0 +1,24 @@ + + + + + + + SPIGOT + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/EpicFarming-API/src/main/java/com/songoda/epicfarming/api/EpicFarming.java b/EpicFarming-API/src/main/java/com/songoda/epicfarming/api/EpicFarming.java new file mode 100644 index 0000000..45ac845 --- /dev/null +++ b/EpicFarming-API/src/main/java/com/songoda/epicfarming/api/EpicFarming.java @@ -0,0 +1,20 @@ +package com.songoda.epicfarming.api; + +import com.songoda.epicfarming.api.farming.FarmManager; +import com.songoda.epicfarming.api.farming.Level; +import com.songoda.epicfarming.api.farming.LevelManager; +import com.songoda.epicfarming.api.utils.ProtectionPluginHook; +import org.bukkit.inventory.ItemStack; + +public interface EpicFarming { + + void registerProtectionHook(ProtectionPluginHook hook); + + int getLevelFromItem(ItemStack item); + + ItemStack makeFarmItem(Level level); + + FarmManager getFarmManager(); + + LevelManager getLevelManager(); +} diff --git a/EpicFarming-API/src/main/java/com/songoda/epicfarming/api/EpicFarmingAPI.java b/EpicFarming-API/src/main/java/com/songoda/epicfarming/api/EpicFarmingAPI.java new file mode 100644 index 0000000..b587dd2 --- /dev/null +++ b/EpicFarming-API/src/main/java/com/songoda/epicfarming/api/EpicFarmingAPI.java @@ -0,0 +1,46 @@ +package com.songoda.epicfarming.api; +/** + * The access point of the EpicFarmingAPI, 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 + * EpicFarming 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 EpicFarming} may + * be passed if absolutely necessary. + * + * @see EpicFarming + * @since 3.0.0 + */ +public class EpicFarmingAPI { + + private static EpicFarming implementation; + + /** + * Set the EpicFarming 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 EpicFarming plugin + * + * @param implementation the implementation to set + */ + public static void setImplementation(EpicFarming implementation) { + if (EpicFarmingAPI.implementation != null) { + throw new IllegalArgumentException("Cannot set API implementation twice"); + } + + EpicFarmingAPI.implementation = implementation; + } + + /** + * Get the EpicFarming implementation. This method may be redundant in most + * situations as all methods present in {@link EpicFarming} will be mirrored + * with static modifiers in the {@link EpicFarmingAPI} class + * + * @return the EpicFarming implementation + */ + public static EpicFarming getImplementation() { + return implementation; + } + } + + diff --git a/EpicFarming-API/src/main/java/com/songoda/epicfarming/api/farming/Farm.java b/EpicFarming-API/src/main/java/com/songoda/epicfarming/api/farming/Farm.java new file mode 100644 index 0000000..b6b4029 --- /dev/null +++ b/EpicFarming-API/src/main/java/com/songoda/epicfarming/api/farming/Farm.java @@ -0,0 +1,14 @@ +package com.songoda.epicfarming.api.farming; + +import org.bukkit.Location; +import org.bukkit.inventory.Inventory; + +public interface Farm { + Inventory getInventory(); + + Location getLocation(); + + void setLocation(Location location); + + Level getLevel(); +} diff --git a/EpicFarming-API/src/main/java/com/songoda/epicfarming/api/farming/FarmManager.java b/EpicFarming-API/src/main/java/com/songoda/epicfarming/api/farming/FarmManager.java new file mode 100644 index 0000000..db8d677 --- /dev/null +++ b/EpicFarming-API/src/main/java/com/songoda/epicfarming/api/farming/FarmManager.java @@ -0,0 +1,18 @@ +package com.songoda.epicfarming.api.farming; + +import org.bukkit.Location; +import org.bukkit.block.Block; + +import java.util.Map; + +public interface FarmManager { + void addFarm(Location location, Farm farm); + + Farm removeFarm(Location location); + + Farm getFarm(Location location); + + Farm getFarm(Block block); + + Map getFarms(); +} diff --git a/EpicFarming-API/src/main/java/com/songoda/epicfarming/api/farming/Level.java b/EpicFarming-API/src/main/java/com/songoda/epicfarming/api/farming/Level.java new file mode 100644 index 0000000..eebb2e4 --- /dev/null +++ b/EpicFarming-API/src/main/java/com/songoda/epicfarming/api/farming/Level.java @@ -0,0 +1,21 @@ +package com.songoda.epicfarming.api.farming; + +import java.util.List; + +public interface Level { + List getDescription(); + + int getLevel(); + + int getRadius(); + + boolean isAutoHarvest(); + + boolean isAutoReplant(); + + double getSpeedMultiplier(); + + int getCostExperiance(); + + int getCostEconomy(); +} diff --git a/EpicFarming-API/src/main/java/com/songoda/epicfarming/api/farming/LevelManager.java b/EpicFarming-API/src/main/java/com/songoda/epicfarming/api/farming/LevelManager.java new file mode 100644 index 0000000..16f09cb --- /dev/null +++ b/EpicFarming-API/src/main/java/com/songoda/epicfarming/api/farming/LevelManager.java @@ -0,0 +1,20 @@ +package com.songoda.epicfarming.api.farming; + +import java.util.Map; + +public interface LevelManager { + + void addLevel(int level, int costExperiance, int costEconomy, double speedMultiplier, int radius, boolean autoHarvest, boolean autoReplant); + + Level getLevel(int level); + + Level getLowestLevel(); + + Level getHighestLevel(); + + boolean isLevel(int level); + + Map getLevels(); + + void clear(); +} diff --git a/src/main/java/com/songoda/epicfarming/api/UpgradeType.java b/EpicFarming-API/src/main/java/com/songoda/epicfarming/api/farming/UpgradeType.java similarity index 53% rename from src/main/java/com/songoda/epicfarming/api/UpgradeType.java rename to EpicFarming-API/src/main/java/com/songoda/epicfarming/api/farming/UpgradeType.java index 6284c7c..f78a130 100644 --- a/src/main/java/com/songoda/epicfarming/api/UpgradeType.java +++ b/EpicFarming-API/src/main/java/com/songoda/epicfarming/api/farming/UpgradeType.java @@ -1,4 +1,4 @@ -package com.songoda.epicfarming.api; +package com.songoda.epicfarming.api.farming; public enum UpgradeType { EXPERIENCE, ECONOMY diff --git a/EpicFarming-API/src/main/java/com/songoda/epicfarming/api/utils/ClaimableProtectionPluginHook.java b/EpicFarming-API/src/main/java/com/songoda/epicfarming/api/utils/ClaimableProtectionPluginHook.java new file mode 100644 index 0000000..dd85ffb --- /dev/null +++ b/EpicFarming-API/src/main/java/com/songoda/epicfarming/api/utils/ClaimableProtectionPluginHook.java @@ -0,0 +1,39 @@ +package com.songoda.epicfarming.api.utils; + +import org.bukkit.Location; + +/** + * A more specific implementation of {@link ProtectionPluginHook} used internally by + * EpicSpawners to retain more information about default hooks. Often times this + * interface is not recommended over the ProtectionPluginHook interface as its methods + * will not often be used by implementation, though they are available if more information + * is desired. It is, however, recommended to use the former + * + * @author Parker Hawke - 2008Choco + */ +public interface ClaimableProtectionPluginHook extends ProtectionPluginHook { + + /** + * Check whether the provided location is in the claim with the given String ID + * + * @param location the location to check + * @param id the ID of the claim to check + * + * @return true if the location is within the claim, false otherwise or if the + * claim ID does not exist + */ + public boolean isInClaim(Location location, String id); + + /** + * Get the ID of the claim with the given name. Often times this is unnecessary + * as unique IDs are not provided by a claim implementation, though for plugins + * such as factions, the passed parameter is the name of the faction and the + * returned String is its unique ID + * + * @param name the name of the claim to check + * + * @return the unique String ID. null if no claim exists + */ + public String getClaimID(String name); + +} \ No newline at end of file diff --git a/EpicFarming-API/src/main/java/com/songoda/epicfarming/api/utils/ProtectionPluginHook.java b/EpicFarming-API/src/main/java/com/songoda/epicfarming/api/utils/ProtectionPluginHook.java new file mode 100644 index 0000000..6cc36bf --- /dev/null +++ b/EpicFarming-API/src/main/java/com/songoda/epicfarming/api/utils/ProtectionPluginHook.java @@ -0,0 +1,48 @@ +package com.songoda.epicfarming.api.utils; + +import com.songoda.epicfarming.api.EpicFarming; +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +/** + * Represents a hook for a protection plugin. This is used by EpicSpawners to determine + * whether a block break should be successful or not according to the current state of + * another plugin. For plugins providing claims with unique String IDs, see the + * {@link ClaimableProtectionPluginHook} for a more detailed implementation. To register + * a protection hook implementation, see + * {@link EpicFarming#registerProtectionHook(ProtectionPluginHook)} + */ +public interface ProtectionPluginHook { + + /** + * The plugin to which this plugin hook belongs. Must not be null + * + * @return the hooking plugin + */ + public JavaPlugin getPlugin(); + + /** + * Check whether the provided player may build at the specified location + * + * @param player the player to check + * @param location the location to check + * + * @return true if player is permitted to build, false otherwise + */ + public boolean canBuild(Player player, Location location); + + /** + * Check whether the provided player may build at the specified block + * + * @param player the player to check + * @param block the block to check + * + * @return true if player is permitted to build, false otherwise + */ + public default boolean canBuild(Player player, Block block) { + return block != null && canBuild(player, block.getLocation()); + } + +} \ No newline at end of file diff --git a/EpicFarming-Plugin/EpicFarming-Plugin.iml b/EpicFarming-Plugin/EpicFarming-Plugin.iml new file mode 100644 index 0000000..8b4c6a4 --- /dev/null +++ b/EpicFarming-Plugin/EpicFarming-Plugin.iml @@ -0,0 +1,26 @@ + + + + + + + SPIGOT + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/songoda/epicfarming/EpicFarming.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/EpicFarmingPlugin.java similarity index 64% rename from src/main/java/com/songoda/epicfarming/EpicFarming.java rename to EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/EpicFarmingPlugin.java index 10a2f4d..4fbd599 100644 --- a/src/main/java/com/songoda/epicfarming/EpicFarming.java +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/EpicFarmingPlugin.java @@ -1,54 +1,72 @@ package com.songoda.epicfarming; +import com.google.common.base.Preconditions; import com.songoda.arconix.api.mcupdate.MCUpdate; import com.songoda.arconix.api.utils.ConfigWrapper; import com.songoda.arconix.plugin.Arconix; +import com.songoda.epicfarming.api.farming.Farm; +import com.songoda.epicfarming.api.farming.Level; +import com.songoda.epicfarming.api.utils.ClaimableProtectionPluginHook; +import com.songoda.epicfarming.api.utils.ProtectionPluginHook; import com.songoda.epicfarming.events.BlockListeners; import com.songoda.epicfarming.events.EntityListeners; import com.songoda.epicfarming.events.InteractListeners; import com.songoda.epicfarming.events.InventoryListeners; -import com.songoda.epicfarming.farming.Farm; -import com.songoda.epicfarming.farming.FarmManager; -import com.songoda.epicfarming.farming.LevelManager; +import com.songoda.epicfarming.farming.EFarm; +import com.songoda.epicfarming.farming.EFarmManager; +import com.songoda.epicfarming.farming.ELevel; +import com.songoda.epicfarming.farming.ELevelManager; import com.songoda.epicfarming.handlers.CommandHandler; import com.songoda.epicfarming.handlers.FarmingHandler; import com.songoda.epicfarming.handlers.GrowthHandler; -import com.songoda.epicfarming.handlers.HookHandler; +import com.songoda.epicfarming.hooks.*; import com.songoda.epicfarming.player.PlayerActionManager; import com.songoda.epicfarming.player.PlayerData; +import com.songoda.epicfarming.utils.Debugger; +import com.songoda.epicfarming.utils.Methods; import com.songoda.epicfarming.utils.SettingsManager; +import com.songoda.epicfarming.api.EpicFarming; +import org.apache.commons.lang.math.NumberUtils; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.command.CommandSender; -import org.bukkit.event.Listener; +import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; +import java.util.ArrayList; import java.util.List; +import java.util.function.Supplier; /** * Created by songoda on 1/23/2018. */ -public class EpicFarming extends JavaPlugin implements Listener { +public class EpicFarmingPlugin extends JavaPlugin implements EpicFarming { - private static EpicFarming INSTANCE; + private static EpicFarmingPlugin INSTANCE; + + private List protectionHooks = new ArrayList<>(); + private ClaimableProtectionPluginHook factionsHook, townyHook, aSkyblockHook, uSkyblockHook; public SettingsManager settingsManager; public References references; - public HookHandler hooks; public ConfigWrapper dataFile = new ConfigWrapper(this, "", "data.yml"); + private ConfigWrapper hooksFile = new ConfigWrapper(this, "", "hooks.yml"); + public ConfigWrapper dataFile = new ConfigWrapper(this, "", "data.yml"); private Locale locale; private FarmingHandler farmingHandler; private GrowthHandler growthHandler; - private FarmManager farmManager; - private LevelManager levelManager; + private EFarmManager farmManager; + private ELevelManager levelManager; private PlayerActionManager playerActionManager; - public static EpicFarming pl() { + public static EpicFarmingPlugin pl() { return INSTANCE; } - public static EpicFarming getInstance() { + public static EpicFarmingPlugin getInstance() { return INSTANCE; } @@ -74,7 +92,7 @@ public class EpicFarming extends JavaPlugin implements Listener { loadLevelManager(); - farmManager = new FarmManager(); + farmManager = new EFarmManager(); /* * Register Farms into FarmManger from configuration @@ -87,7 +105,7 @@ public class EpicFarming extends JavaPlugin implements Listener { List items = (List) dataFile.getConfig().getList("Farms." + locationStr + ".Contents"); - Farm farm = new Farm(location, levelManager.getLevel(level)); + EFarm farm = new EFarm(location, levelManager.getLevel(level)); farm.loadInventory(items); farmManager.addFarm(location, farm); @@ -95,8 +113,6 @@ public class EpicFarming extends JavaPlugin implements Listener { } playerActionManager = new PlayerActionManager(); - hooks = new HookHandler(); - hooks.hook(); farmingHandler = new FarmingHandler(this); growthHandler = new GrowthHandler(this); @@ -104,13 +120,26 @@ public class EpicFarming extends JavaPlugin implements Listener { this.getCommand("EpicFarming").setExecutor(new CommandHandler(this)); - getServer().getPluginManager().registerEvents(new BlockListeners(this), this); - getServer().getPluginManager().registerEvents(new InteractListeners(this), this); - getServer().getPluginManager().registerEvents(new InventoryListeners(this), this); - getServer().getPluginManager().registerEvents(new EntityListeners(), this); + PluginManager pluginManager = Bukkit.getPluginManager(); - this.getServer().getPluginManager().registerEvents(this, this); + // Register Listeners + pluginManager.registerEvents(new BlockListeners(this), this); + pluginManager.registerEvents(new InteractListeners(this), this); + pluginManager.registerEvents(new InventoryListeners(this), this); + pluginManager.registerEvents(new EntityListeners(), this); + + // Register default hooks + if (pluginManager.isPluginEnabled("ASkyBlock")) this.register(HookASkyBlock::new); + if (pluginManager.isPluginEnabled("Factions")) 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("WorldGuard")) this.register(HookWorldGuard::new); + Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this::saveToFile, 6000, 6000); new MCUpdate(this, true); @@ -134,7 +163,7 @@ public class EpicFarming extends JavaPlugin implements Listener { private void loadLevelManager() { // Load an instance of LevelManager - levelManager = new LevelManager(); + levelManager = new ELevelManager(); /* * Register Levels into LevelManager from configuration. @@ -168,7 +197,7 @@ public class EpicFarming extends JavaPlugin implements Listener { || farm.getLocation().getWorld() == null) continue; String locationStr = Arconix.pl().getApi().serialize().serializeLocation(farm.getLocation()); dataFile.getConfig().set("Farms." + locationStr + ".level", farm.getLevel().getLevel()); - dataFile.getConfig().set("Farms." + locationStr + ".Contents", farm.dumpInventory()); + dataFile.getConfig().set("Farms." + locationStr + ".Contents", ((EFarm)farm).dumpInventory()); } //Save to file @@ -177,9 +206,6 @@ public class EpicFarming extends JavaPlugin implements Listener { } public void reload() { - hooks.hooksFile.createNewFile("Loading hooks File", "EpicFarming hooks File"); - hooks = new HookHandler(); - hooks.hook(); locale.reloadMessages(); references = new References(); reloadConfig(); @@ -243,11 +269,72 @@ public class EpicFarming extends JavaPlugin implements Listener { return locale; } - public FarmManager getFarmManager() { + + private void register(Supplier hookSupplier) { + this.registerProtectionHook(hookSupplier.get()); + } + + + @Override + public void registerProtectionHook(ProtectionPluginHook hook) { + Preconditions.checkNotNull(hook, "Cannot register null hook"); + Preconditions.checkNotNull(hook.getPlugin(), "Protection plugin hook returns null plugin instance (#getPlugin())"); + + JavaPlugin hookPlugin = hook.getPlugin(); + for (ProtectionPluginHook existingHook : protectionHooks) { + 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; + this.hooksFile.getConfig().options().copyDefaults(true); + this.hooksFile.saveConfig(); + + this.protectionHooks.add(hook); + this.getLogger().info("Registered protection hook for plugin: " + hook.getPlugin().getName()); + } + + public boolean canBuild(Player player, Location location) { + if (player.hasPermission(getDescription().getName() + ".bypass")) { + return true; + } + + for (ProtectionPluginHook hook : protectionHooks) + if (!hook.canBuild(player, location)) return false; + return true; + } + + @Override + public int getLevelFromItem(ItemStack item) { + try { + if (!item.hasItemMeta() || !item.getItemMeta().hasDisplayName()) return 0; + if (item.getItemMeta().getDisplayName().contains(":")) { + return NumberUtils.toInt(item.getItemMeta().getDisplayName().replace("\u00A7", "").split(":")[0], 0); + } + } catch (Exception ex) { + Debugger.runReport(ex); + } + return 0; + } + + @Override + public ItemStack makeFarmItem(Level level) { + ItemStack item = new ItemStack(Material.valueOf(EpicFarmingPlugin.getInstance().getConfig().getString("Main.Farm Block Material")), 1); + ItemMeta meta = item.getItemMeta(); + meta.setDisplayName(Arconix.pl().getApi().format().formatText(Methods.formatName(level.getLevel(), true))); + item.setItemMeta(meta); + return item; + } + + @Override + public EFarmManager getFarmManager() { return farmManager; } - public LevelManager getLevelManager() { + @Override + public ELevelManager getLevelManager() { return levelManager; } diff --git a/src/main/java/com/songoda/epicfarming/Locale.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/Locale.java similarity index 100% rename from src/main/java/com/songoda/epicfarming/Locale.java rename to EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/Locale.java diff --git a/src/main/java/com/songoda/epicfarming/References.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/References.java similarity index 64% rename from src/main/java/com/songoda/epicfarming/References.java rename to EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/References.java index 1f09498..277a548 100644 --- a/src/main/java/com/songoda/epicfarming/References.java +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/References.java @@ -5,7 +5,7 @@ public class References { private String prefix; public References() { - prefix = EpicFarming.getInstance().getLocale().getMessage("general.nametag.prefix") + " "; + prefix = EpicFarmingPlugin.getInstance().getLocale().getMessage("general.nametag.prefix") + " "; } public String getPrefix() { diff --git a/src/main/java/com/songoda/epicfarming/events/BlockListeners.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/events/BlockListeners.java similarity index 82% rename from src/main/java/com/songoda/epicfarming/events/BlockListeners.java rename to EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/events/BlockListeners.java index 5169faa..6da08d6 100644 --- a/src/main/java/com/songoda/epicfarming/events/BlockListeners.java +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/events/BlockListeners.java @@ -1,9 +1,11 @@ package com.songoda.epicfarming.events; -import com.songoda.epicfarming.EpicFarming; -import com.songoda.epicfarming.farming.Farm; -import com.songoda.epicfarming.farming.FarmManager; -import com.songoda.epicfarming.farming.Level; +import com.songoda.epicfarming.EpicFarmingPlugin; +import com.songoda.epicfarming.api.farming.Farm; +import com.songoda.epicfarming.api.farming.Level; +import com.songoda.epicfarming.farming.EFarm; +import com.songoda.epicfarming.farming.EFarmManager; +import com.songoda.epicfarming.farming.ELevel; import com.songoda.epicfarming.utils.Debugger; import com.songoda.epicfarming.utils.Methods; import org.bukkit.Bukkit; @@ -24,9 +26,9 @@ import org.bukkit.inventory.ItemStack; */ public class BlockListeners implements Listener { - private EpicFarming instance; + private EpicFarmingPlugin instance; - public BlockListeners(EpicFarming instance) { + public BlockListeners(EpicFarmingPlugin instance) { this.instance = instance; } @@ -63,7 +65,7 @@ public class BlockListeners implements Listener { boolean allowNonCommandIssued = instance.getConfig().getBoolean("Main.Allow Non Command Issued Farm Items"); if (e.getPlayer().getItemInHand().getType() != farmBlock - || Methods.getLevelFromItem(e.getItemInHand()) == 0 && !allowNonCommandIssued) return; + || instance.getLevelFromItem(e.getItemInHand()) == 0 && !allowNonCommandIssued) return; if (e.getBlockAgainst().getType() == farmBlock) e.setCancelled(true); @@ -71,13 +73,13 @@ public class BlockListeners implements Listener { Bukkit.getScheduler().runTaskLater(instance, () -> { int level = 1; - if (Methods.getLevelFromItem(e.getItemInHand()) != 0) { - level = Methods.getLevelFromItem(e.getItemInHand()); + if (instance.getLevelFromItem(e.getItemInHand()) != 0) { + level = instance.getLevelFromItem(e.getItemInHand()); } if (location.getBlock().getType() != farmBlock) return; - Farm farm = new Farm(location, instance.getLevelManager().getLevel(level)); + EFarm farm = new EFarm(location, instance.getLevelManager().getLevel(level)); instance.getFarmManager().addFarm(location, farm); farm.tillLand(e.getBlock().getLocation()); @@ -90,7 +92,7 @@ public class BlockListeners implements Listener { private boolean checkForFarm(Location location) { - FarmManager farmManager = instance.getFarmManager(); + EFarmManager farmManager = instance.getFarmManager(); Block block = location.getBlock(); for(Level level : instance.getLevelManager().getLevels().values()) { @@ -129,14 +131,14 @@ public class BlockListeners implements Listener { event.setCancelled(true); - ItemStack item = Methods.makeFarmItem(farm.getLevel()); + ItemStack item = instance.makeFarmItem(farm.getLevel()); Block block = event.getBlock(); block.setType(Material.AIR); block.getLocation().getWorld().dropItemNaturally(block.getLocation().add(.5,.5,.5), item); - for (ItemStack itemStack : farm.dumpInventory()) { + for (ItemStack itemStack : ((EFarm)farm).dumpInventory()) { if (itemStack == null) continue; farm.getLocation().getWorld().dropItemNaturally(farm.getLocation().add(.5,.5,.5), itemStack); } diff --git a/src/main/java/com/songoda/epicfarming/events/EntityListeners.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/events/EntityListeners.java similarity index 100% rename from src/main/java/com/songoda/epicfarming/events/EntityListeners.java rename to EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/events/EntityListeners.java diff --git a/src/main/java/com/songoda/epicfarming/events/InteractListeners.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/events/InteractListeners.java similarity index 75% rename from src/main/java/com/songoda/epicfarming/events/InteractListeners.java rename to EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/events/InteractListeners.java index 9f1e2f5..b554224 100644 --- a/src/main/java/com/songoda/epicfarming/events/InteractListeners.java +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/events/InteractListeners.java @@ -1,6 +1,7 @@ package com.songoda.epicfarming.events; -import com.songoda.epicfarming.EpicFarming; +import com.songoda.epicfarming.EpicFarmingPlugin; +import com.songoda.epicfarming.farming.EFarm; import com.songoda.epicfarming.utils.Debugger; import org.bukkit.Location; import org.bukkit.Material; @@ -14,9 +15,9 @@ import org.bukkit.event.player.PlayerInteractEvent; */ public class InteractListeners implements Listener { - private EpicFarming instance; + private EpicFarmingPlugin instance; - public InteractListeners(EpicFarming instance) { + public InteractListeners(EpicFarmingPlugin instance) { this.instance = instance; } @@ -26,7 +27,7 @@ public class InteractListeners implements Listener { if (e.getClickedBlock() == null || e.getClickedBlock().getType() != Material.valueOf(instance.getConfig().getString("Main.Farm Block Material"))) return; - if (!instance.hooks.canBuild(e.getPlayer(), e.getClickedBlock().getLocation())) { + if (!instance.canBuild(e.getPlayer(), e.getClickedBlock().getLocation())) { e.setCancelled(true); return; } @@ -37,7 +38,7 @@ public class InteractListeners implements Listener { if (instance.getFarmManager().getFarms().containsKey(location)) { e.setCancelled(true); - instance.getFarmManager().getFarm(location).view(e.getPlayer()); + ((EFarm)instance.getFarmManager().getFarm(location)).view(e.getPlayer()); } } catch (Exception ex) { Debugger.runReport(ex); diff --git a/src/main/java/com/songoda/epicfarming/events/InventoryListeners.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/events/InventoryListeners.java similarity index 88% rename from src/main/java/com/songoda/epicfarming/events/InventoryListeners.java rename to EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/events/InventoryListeners.java index e280f68..673079a 100644 --- a/src/main/java/com/songoda/epicfarming/events/InventoryListeners.java +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/events/InventoryListeners.java @@ -1,8 +1,8 @@ package com.songoda.epicfarming.events; -import com.songoda.epicfarming.EpicFarming; -import com.songoda.epicfarming.api.UpgradeType; -import com.songoda.epicfarming.farming.Farm; +import com.songoda.epicfarming.EpicFarmingPlugin; +import com.songoda.epicfarming.api.farming.UpgradeType; +import com.songoda.epicfarming.farming.EFarm; import com.songoda.epicfarming.player.PlayerData; import com.songoda.epicfarming.utils.Debugger; import org.bukkit.entity.Player; @@ -16,9 +16,9 @@ import org.bukkit.event.inventory.InventoryType; */ public class InventoryListeners implements Listener { - private EpicFarming instance; + private EpicFarmingPlugin instance; - public InventoryListeners(EpicFarming instance) { + public InventoryListeners(EpicFarmingPlugin instance) { this.instance = instance; } @@ -31,7 +31,7 @@ public class InventoryListeners implements Listener { if (event.getInventory().getType() != InventoryType.CHEST) return; PlayerData playerData = instance.getPlayerActionManager().getPlayerAction((Player)event.getWhoClicked()); - Farm farm = playerData.getFarm(); + EFarm farm = playerData.getFarm(); if (event.getSlot() <= 26) { event.setCancelled(true); } diff --git a/src/main/java/com/songoda/epicfarming/farming/Crop.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/farming/Crop.java similarity index 92% rename from src/main/java/com/songoda/epicfarming/farming/Crop.java rename to EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/farming/Crop.java index 73218f2..f52365c 100644 --- a/src/main/java/com/songoda/epicfarming/farming/Crop.java +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/farming/Crop.java @@ -1,5 +1,6 @@ package com.songoda.epicfarming.farming; +import com.songoda.epicfarming.api.farming.Farm; import org.bukkit.Location; public class Crop { diff --git a/src/main/java/com/songoda/epicfarming/farming/Farm.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/farming/EFarm.java similarity index 90% rename from src/main/java/com/songoda/epicfarming/farming/Farm.java rename to EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/farming/EFarm.java index 8f7ede2..67f2897 100644 --- a/src/main/java/com/songoda/epicfarming/farming/Farm.java +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/farming/EFarm.java @@ -1,11 +1,13 @@ package com.songoda.epicfarming.farming; import com.songoda.arconix.plugin.Arconix; -import com.songoda.epicfarming.EpicFarming; -import com.songoda.epicfarming.api.UpgradeType; +import com.songoda.epicfarming.EpicFarmingPlugin; +import com.songoda.epicfarming.api.farming.Level; +import com.songoda.epicfarming.api.farming.UpgradeType; import com.songoda.epicfarming.player.PlayerData; import com.songoda.epicfarming.utils.Debugger; import com.songoda.epicfarming.utils.Methods; +import com.songoda.epicfarming.api.farming.Farm; import net.milkbowl.vault.economy.Economy; import org.bukkit.*; import org.bukkit.block.Block; @@ -20,13 +22,13 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; -public class Farm { +public class EFarm implements Farm { private Location location; private Level level; private Inventory inventory; - public Farm(Location location, Level level) { + public EFarm(Location location, Level level) { this.location = location; this.level = level; this.inventory = Bukkit.createInventory(null, 54, Methods.formatName(level.getLevel(),false)); @@ -40,7 +42,7 @@ public class Farm { setupOverview(player); player.openInventory(inventory); - PlayerData playerData = EpicFarming.getInstance().getPlayerActionManager().getPlayerAction(player); + PlayerData playerData = EpicFarmingPlugin.getInstance().getPlayerActionManager().getPlayerAction(player); playerData.setFarm(this); @@ -56,9 +58,9 @@ public class Farm { inventory.setContents(this.inventory.getContents()); this.inventory = inventory; - EpicFarming instance = EpicFarming.getInstance(); + EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance(); - Level nextLevel = instance.getLevelManager().getHighestLevel().getLevel() > level.getLevel() ? instance.getLevelManager().getLevel(level.getLevel()+1) : null; + ELevel nextLevel = instance.getLevelManager().getHighestLevel().getLevel() > level.getLevel() ? instance.getLevelManager().getLevel(level.getLevel()+1) : null; int level = this.level.getLevel(); @@ -131,6 +133,7 @@ public class Farm { inventory.setItem(26, Methods.getBackgroundGlass(true)); } + @Override public Inventory getInventory() { return inventory; } @@ -155,10 +158,10 @@ public class Farm { public void upgrade(UpgradeType type, Player player) { try { - EpicFarming instance = EpicFarming.getInstance(); + EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance(); if (instance.getLevelManager().getLevels().containsKey(this.level.getLevel()+1)) { - Level level = instance.getLevelManager().getLevel(this.level.getLevel()+1); + com.songoda.epicfarming.api.farming.Level level = instance.getLevelManager().getLevel(this.level.getLevel()+1); int cost; if (type == UpgradeType.EXPERIENCE) { cost = level.getCostExperiance(); @@ -198,7 +201,7 @@ public class Farm { private void upgradeFinal(Level level, Player player) { try { - EpicFarming instance = EpicFarming.getInstance(); + EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance(); this.level = level; if (instance.getLevelManager().getHighestLevel() != level) { player.sendMessage(instance.getLocale().getMessage("event.upgrade.success", level.getLevel())); @@ -225,7 +228,7 @@ public class Farm { private static final Random random = new Random(); public boolean tillLand(Location location) { - EpicFarming instance = EpicFarming.getInstance(); + EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance(); Block block = location.getBlock(); int radius = level.getRadius(); int bx = block.getX(); @@ -239,7 +242,7 @@ public class Farm { // ToDo: enum for all flowers. if (b2.getType() == Material.TALL_GRASS || b2.getType() == Material.GRASS || b2.getType().name().contains("TULIP") || b2.getType() == Material.AZURE_BLUET || b2.getType() == Material.BLUE_ORCHID || b2.getType() == Material.ALLIUM || b2.getType() == Material.POPPY || b2.getType() == Material.DANDELION) { - Bukkit.getScheduler().runTaskLater(EpicFarming.getInstance(), () -> { + Bukkit.getScheduler().runTaskLater(EpicFarmingPlugin.getInstance(), () -> { b2.getRelative(BlockFace.DOWN).setType(Material.LEGACY_SOIL); b2.breakNaturally(); if (instance.getConfig().getBoolean("Main.Sounds Enabled")) { @@ -248,7 +251,7 @@ public class Farm { }, random.nextInt(30) + 1); } if ((b2.getType() == Material.GRASS_BLOCK || b2.getType() == Material.DIRT) && b2.getRelative(BlockFace.UP).getType() == Material.AIR) { - Bukkit.getScheduler().runTaskLater(EpicFarming.getInstance(), () -> { + Bukkit.getScheduler().runTaskLater(EpicFarmingPlugin.getInstance(), () -> { b2.setType(Material.LEGACY_SOIL); if (instance.getConfig().getBoolean("Main.Sounds Enabled")) { b2.getWorld().playSound(b2.getLocation(), org.bukkit.Sound.BLOCK_GRASS_BREAK, 10, 15); @@ -262,14 +265,17 @@ public class Farm { return false; } + @Override public Location getLocation() { return location.clone(); } + @Override public void setLocation(Location location) { this.location = location; } + @Override public Level getLevel() { return level; } diff --git a/src/main/java/com/songoda/epicfarming/farming/FarmManager.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/farming/EFarmManager.java similarity index 82% rename from src/main/java/com/songoda/epicfarming/farming/FarmManager.java rename to EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/farming/EFarmManager.java index f51d01c..231a96a 100644 --- a/src/main/java/com/songoda/epicfarming/farming/FarmManager.java +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/farming/EFarmManager.java @@ -1,6 +1,7 @@ package com.songoda.epicfarming.farming; -import org.bukkit.Bukkit; +import com.songoda.epicfarming.api.farming.Farm; +import com.songoda.epicfarming.api.farming.FarmManager; import org.bukkit.Location; import org.bukkit.block.Block; @@ -8,26 +9,31 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; -public class FarmManager { +public class EFarmManager implements FarmManager { private final Map registeredFarms = new HashMap<>(); + @Override public void addFarm(Location location, Farm farm) { registeredFarms.put(roundLocation(location), farm); } + @Override public Farm removeFarm(Location location) { return registeredFarms.remove(roundLocation(location)); } + @Override public Farm getFarm(Location location) { return registeredFarms.get(roundLocation(location)); } + @Override public Farm getFarm(Block block) { return getFarm(block.getLocation()); } + @Override public Map getFarms() { return Collections.unmodifiableMap(registeredFarms); } diff --git a/src/main/java/com/songoda/epicfarming/farming/Level.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/farming/ELevel.java similarity index 77% rename from src/main/java/com/songoda/epicfarming/farming/Level.java rename to EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/farming/ELevel.java index af2705f..908670c 100644 --- a/src/main/java/com/songoda/epicfarming/farming/Level.java +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/farming/ELevel.java @@ -1,11 +1,12 @@ package com.songoda.epicfarming.farming; -import com.songoda.epicfarming.EpicFarming; +import com.songoda.epicfarming.EpicFarmingPlugin; +import com.songoda.epicfarming.api.farming.Level; import java.util.ArrayList; import java.util.List; -public class Level { +public class ELevel implements Level { private int level, costExperiance, costEconomy, radius; @@ -15,7 +16,7 @@ public class Level { private List description = new ArrayList<>(); - public Level(int level, int costExperiance, int costEconomy, double speedMultiplier, int radius, boolean autoHarvest, boolean autoReplant) { + public ELevel(int level, int costExperiance, int costEconomy, double speedMultiplier, int radius, boolean autoHarvest, boolean autoReplant) { this.level = level; this.costExperiance = costExperiance; this.costEconomy = costEconomy; @@ -24,7 +25,7 @@ public class Level { this.autoHarvest = autoHarvest; this.autoReplant = autoReplant; - EpicFarming instance = EpicFarming.getInstance(); + EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance(); description.add(instance.getLocale().getMessage("interface.button.radius", radius)); description.add(instance.getLocale().getMessage("interface.button.speed", speedMultiplier)); @@ -37,34 +38,42 @@ public class Level { } + @Override public List getDescription() { return new ArrayList<>(description); } + @Override public int getLevel() { return level; } + @Override public int getRadius() { return radius; } + @Override public boolean isAutoHarvest() { return autoHarvest; } + @Override public boolean isAutoReplant() { return autoReplant; } + @Override public double getSpeedMultiplier() { return speedMultiplier; } + @Override public int getCostExperiance() { return costExperiance; } + @Override public int getCostEconomy() { return costEconomy; } diff --git a/src/main/java/com/songoda/epicfarming/farming/LevelManager.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/farming/ELevelManager.java similarity index 56% rename from src/main/java/com/songoda/epicfarming/farming/LevelManager.java rename to EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/farming/ELevelManager.java index 6b165d8..5a51fc0 100644 --- a/src/main/java/com/songoda/epicfarming/farming/LevelManager.java +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/farming/ELevelManager.java @@ -1,38 +1,48 @@ package com.songoda.epicfarming.farming; +import com.songoda.epicfarming.api.farming.Level; +import com.songoda.epicfarming.api.farming.LevelManager; + import java.util.Collections; import java.util.Map; import java.util.NavigableMap; import java.util.TreeMap; -public class LevelManager { +public class ELevelManager implements LevelManager { - private final NavigableMap registeredLevels = new TreeMap<>(); + private final NavigableMap registeredLevels = new TreeMap<>(); + @Override public void addLevel(int level, int costExperiance, int costEconomy, double speedMultiplier, int radius, boolean autoHarvest, boolean autoReplant) { - registeredLevels.put(level, new Level(level, costExperiance, costEconomy, speedMultiplier, radius, autoHarvest, autoReplant)); + registeredLevels.put(level, new ELevel(level, costExperiance, costEconomy, speedMultiplier, radius, autoHarvest, autoReplant)); } - public Level getLevel(int level) { + @Override + public ELevel getLevel(int level) { return registeredLevels.get(level); } - public Level getLowestLevel() { + @Override + public ELevel getLowestLevel() { return registeredLevels.firstEntry().getValue(); } - public Level getHighestLevel() { + @Override + public ELevel getHighestLevel() { return registeredLevels.lastEntry().getValue(); } + @Override public boolean isLevel(int level) { return registeredLevels.containsKey(level); } + @Override public Map getLevels() { return Collections.unmodifiableMap(registeredLevels); } + @Override public void clear() { registeredLevels.clear(); } diff --git a/src/main/java/com/songoda/epicfarming/handlers/CommandHandler.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/handlers/CommandHandler.java similarity index 93% rename from src/main/java/com/songoda/epicfarming/handlers/CommandHandler.java rename to EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/handlers/CommandHandler.java index 7c85f6e..557348d 100644 --- a/src/main/java/com/songoda/epicfarming/handlers/CommandHandler.java +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/handlers/CommandHandler.java @@ -1,8 +1,8 @@ package com.songoda.epicfarming.handlers; import com.songoda.arconix.plugin.Arconix; -import com.songoda.epicfarming.EpicFarming; -import com.songoda.epicfarming.farming.Level; +import com.songoda.epicfarming.EpicFarmingPlugin; +import com.songoda.epicfarming.farming.ELevel; import com.songoda.epicfarming.utils.Debugger; import com.songoda.epicfarming.utils.Methods; import org.bukkit.Bukkit; @@ -17,9 +17,9 @@ import org.bukkit.entity.Player; public class CommandHandler implements CommandExecutor { - private EpicFarming instance; + private EpicFarmingPlugin instance; - public CommandHandler(EpicFarming instance) { + public CommandHandler(EpicFarmingPlugin instance) { this.instance = instance; } @@ -48,7 +48,7 @@ public class CommandHandler implements CommandExecutor { } if (args.length >= 1) { - Level level = instance.getLevelManager().getLowestLevel(); + ELevel level = instance.getLevelManager().getLowestLevel(); Player player; if (args.length != 1 && Bukkit.getPlayer(args[1]) == null) { sender.sendMessage(instance.references.getPrefix() + Arconix.pl().getApi().format().formatText("&cThat player does not exist or is currently offline.")); @@ -70,7 +70,7 @@ public class CommandHandler implements CommandExecutor { } else if (args.length != 1){ level = instance.getLevelManager().getLevel(Integer.parseInt(args[2])); } - player.getInventory().addItem(Methods.makeFarmItem(level)); + player.getInventory().addItem(instance.makeFarmItem(level)); player.sendMessage(instance.references.getPrefix() + instance.getLocale().getMessage("command.give.success", level.getLevel())); } else if (Bukkit.getPlayerExact(args[1]) == null) { diff --git a/src/main/java/com/songoda/epicfarming/handlers/FarmingHandler.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/handlers/FarmingHandler.java similarity index 93% rename from src/main/java/com/songoda/epicfarming/handlers/FarmingHandler.java rename to EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/handlers/FarmingHandler.java index 623f6d1..def2c48 100644 --- a/src/main/java/com/songoda/epicfarming/handlers/FarmingHandler.java +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/handlers/FarmingHandler.java @@ -1,8 +1,9 @@ package com.songoda.epicfarming.handlers; -import com.songoda.epicfarming.EpicFarming; +import com.songoda.epicfarming.EpicFarmingPlugin; +import com.songoda.epicfarming.api.farming.Farm; import com.songoda.epicfarming.farming.Crop; -import com.songoda.epicfarming.farming.Farm; +import com.songoda.epicfarming.farming.EFarm; import com.songoda.epicfarming.utils.CropType; import com.songoda.epicfarming.utils.Debugger; import org.bukkit.Bukkit; @@ -22,12 +23,12 @@ import java.util.Random; public class FarmingHandler { - private EpicFarming instance; + private EpicFarmingPlugin instance; - public FarmingHandler(EpicFarming instance) { + public FarmingHandler(EpicFarmingPlugin instance) { this.instance = instance; - Bukkit.getScheduler().scheduleSyncRepeatingTask(EpicFarming.getInstance(), this::farmRunner, 0, instance.getConfig().getInt("Main.Farm Tick Speed")); - Bukkit.getScheduler().scheduleSyncRepeatingTask(EpicFarming.getInstance(), this::hopRunner, 0, 8); + Bukkit.getScheduler().scheduleSyncRepeatingTask(EpicFarmingPlugin.getInstance(), this::farmRunner, 0, instance.getConfig().getInt("Main.Farm Tick Speed")); + Bukkit.getScheduler().scheduleSyncRepeatingTask(EpicFarmingPlugin.getInstance(), this::hopRunner, 0, 8); } diff --git a/src/main/java/com/songoda/epicfarming/handlers/GrowthHandler.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/handlers/GrowthHandler.java similarity index 89% rename from src/main/java/com/songoda/epicfarming/handlers/GrowthHandler.java rename to EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/handlers/GrowthHandler.java index 59fe17d..2663f88 100644 --- a/src/main/java/com/songoda/epicfarming/handlers/GrowthHandler.java +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/handlers/GrowthHandler.java @@ -1,6 +1,6 @@ package com.songoda.epicfarming.handlers; -import com.songoda.epicfarming.EpicFarming; +import com.songoda.epicfarming.EpicFarmingPlugin; import com.songoda.epicfarming.farming.Crop; import org.bukkit.Bukkit; import org.bukkit.CropState; @@ -15,9 +15,9 @@ import java.util.Random; public class GrowthHandler { - public GrowthHandler(EpicFarming instance) { - Bukkit.getScheduler().scheduleSyncRepeatingTask(EpicFarming.getInstance(), this::growthRunner, 0, instance.getConfig().getInt("Main.Growth Tick Speed")); - Bukkit.getScheduler().scheduleSyncRepeatingTask(EpicFarming.getInstance(), this::clear, 0, instance.getConfig().getInt("Main.Clear Tick Speed")); + public GrowthHandler(EpicFarmingPlugin instance) { + Bukkit.getScheduler().scheduleSyncRepeatingTask(EpicFarmingPlugin.getInstance(), this::growthRunner, 0, instance.getConfig().getInt("Main.Growth Tick Speed")); + Bukkit.getScheduler().scheduleSyncRepeatingTask(EpicFarmingPlugin.getInstance(), this::clear, 0, instance.getConfig().getInt("Main.Clear Tick Speed")); } Map liveCrops = new HashMap<>(); diff --git a/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookASkyBlock.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookASkyBlock.java new file mode 100644 index 0000000..0b1acf9 --- /dev/null +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookASkyBlock.java @@ -0,0 +1,60 @@ +package com.songoda.epicfarming.hooks; + +import com.songoda.epicfarming.api.utils.ClaimableProtectionPluginHook; +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 ClaimableProtectionPluginHook { + + private final ASkyBlockAPI skyblock; + + public HookASkyBlock() { + this.skyblock = ASkyBlockAPI.getInstance(); + } + + @Override + public JavaPlugin getPlugin() { + return ASkyBlock.getPlugin(); + } + + @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, 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/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookFactions.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookFactions.java new file mode 100644 index 0000000..0a3114c --- /dev/null +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookFactions.java @@ -0,0 +1,45 @@ +package com.songoda.epicfarming.hooks; + +import com.songoda.epicfarming.api.utils.ClaimableProtectionPluginHook; +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 ClaimableProtectionPluginHook { + + private final FactionsFramework factions; + + public HookFactions() { + this.factions = FactionsFramework.get(); + } + + @Override + public JavaPlugin getPlugin() { + return factions; + } + + @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, 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/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookGriefPrevention.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookGriefPrevention.java new file mode 100644 index 0000000..423d3cb --- /dev/null +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookGriefPrevention.java @@ -0,0 +1,30 @@ +package com.songoda.epicfarming.hooks; + +import com.songoda.epicfarming.api.utils.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 boolean canBuild(Player player, Location location) { + Claim claim = griefPrevention.dataStore.getClaimAt(location, false, null); + return claim != null && claim.allowBuild(player, Material.STONE) == null; + } + +} \ No newline at end of file diff --git a/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookKingdoms.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookKingdoms.java new file mode 100644 index 0000000..fdb5437 --- /dev/null +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookKingdoms.java @@ -0,0 +1,38 @@ +package com.songoda.epicfarming.hooks; + +import com.songoda.epicfarming.api.utils.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 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); + } + +} \ No newline at end of file diff --git a/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookPlotSquared.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookPlotSquared.java new file mode 100644 index 0000000..930c695 --- /dev/null +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookPlotSquared.java @@ -0,0 +1,29 @@ +package com.songoda.epicfarming.hooks; + +import com.intellectualcrafters.plot.api.PlotAPI; +import com.plotsquared.bukkit.BukkitMain; +import com.songoda.epicfarming.api.utils.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 boolean canBuild(Player player, Location location) { + return plotSquared.getPlot(location) != null && plotSquared.isInPlot(player) + && plotSquared.getPlot(location) == plotSquared.getPlot(player); + } + +} \ No newline at end of file diff --git a/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookRedProtect.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookRedProtect.java new file mode 100644 index 0000000..ddf7f47 --- /dev/null +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookRedProtect.java @@ -0,0 +1,32 @@ +package com.songoda.epicfarming.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.epicfarming.api.utils.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 boolean canBuild(Player player, Location location) { + RedProtectAPI api = redProtect.getAPI(); + Region region = api.getRegion(location); + + return region != null && region.canBuild(player); + } + +} \ No newline at end of file diff --git a/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookTowny.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookTowny.java new file mode 100644 index 0000000..7bc86a4 --- /dev/null +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookTowny.java @@ -0,0 +1,59 @@ +package com.songoda.epicfarming.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.epicfarming.api.utils.ClaimableProtectionPluginHook; +import com.songoda.epicfarming.utils.Debugger; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +public class HookTowny implements ClaimableProtectionPluginHook { + + private final Towny towny; + + public HookTowny() { + this.towny = Towny.getPlugin(); + } + + @Override + public JavaPlugin getPlugin() { + return towny; + } + + @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, 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/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookUSkyBlock.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookUSkyBlock.java new file mode 100644 index 0000000..a8931a3 --- /dev/null +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookUSkyBlock.java @@ -0,0 +1,38 @@ +package com.songoda.epicfarming.hooks; + +import com.songoda.epicfarming.api.utils.ClaimableProtectionPluginHook; +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 ClaimableProtectionPluginHook { + + 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 boolean canBuild(Player player, Location location) { + return uSkyblock.getIslandInfo(location).getOnlineMembers().contains(player) || uSkyblock.getIslandInfo(location).isLeader(player); + } + + @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/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookWorldGuard.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookWorldGuard.java new file mode 100644 index 0000000..a64ef1b --- /dev/null +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/hooks/HookWorldGuard.java @@ -0,0 +1,27 @@ +package com.songoda.epicfarming.hooks; + +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.songoda.epicfarming.api.utils.ProtectionPluginHook; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +public class HookWorldGuard implements ProtectionPluginHook { + + private final WorldGuardPlugin worldGuard; + + public HookWorldGuard() { + this.worldGuard = WorldGuardPlugin.inst(); + } + + @Override + public JavaPlugin getPlugin() { + return worldGuard; + } + + @Override + public boolean canBuild(Player player, Location location) { + return worldGuard.canBuild(player, location); + } + +} \ No newline at end of file diff --git a/src/main/java/com/songoda/epicfarming/player/PlayerActionManager.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/player/PlayerActionManager.java similarity index 100% rename from src/main/java/com/songoda/epicfarming/player/PlayerActionManager.java rename to EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/player/PlayerActionManager.java diff --git a/src/main/java/com/songoda/epicfarming/player/PlayerData.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/player/PlayerData.java similarity index 74% rename from src/main/java/com/songoda/epicfarming/player/PlayerData.java rename to EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/player/PlayerData.java index cfd827c..5d0ef0f 100644 --- a/src/main/java/com/songoda/epicfarming/player/PlayerData.java +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/player/PlayerData.java @@ -1,6 +1,6 @@ package com.songoda.epicfarming.player; -import com.songoda.epicfarming.farming.Farm; +import com.songoda.epicfarming.farming.EFarm; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -9,17 +9,17 @@ import java.util.UUID; public class PlayerData { private final UUID playerUUID; - private Farm farm = null; + private EFarm farm = null; public PlayerData(UUID playerUUID) { this.playerUUID = playerUUID; } - public Farm getFarm() { + public EFarm getFarm() { return farm; } - public void setFarm(Farm farm) { + public void setFarm(EFarm farm) { this.farm = farm; } diff --git a/src/main/java/com/songoda/epicfarming/utils/CropType.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/CropType.java similarity index 96% rename from src/main/java/com/songoda/epicfarming/utils/CropType.java rename to EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/CropType.java index a4a22b6..6cf4379 100644 --- a/src/main/java/com/songoda/epicfarming/utils/CropType.java +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/CropType.java @@ -1,11 +1,7 @@ package com.songoda.epicfarming.utils; -import com.songoda.epicfarming.EpicFarming; import org.bukkit.Material; -import java.util.ArrayList; -import java.util.List; - public enum CropType { WHEAT("Wheat", Material.WHEAT, Material.WHEAT, Material.WHEAT_SEEDS), diff --git a/src/main/java/com/songoda/epicfarming/utils/Debugger.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/Debugger.java similarity index 88% rename from src/main/java/com/songoda/epicfarming/utils/Debugger.java rename to EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/Debugger.java index f7bc70c..6611cd7 100644 --- a/src/main/java/com/songoda/epicfarming/utils/Debugger.java +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/Debugger.java @@ -1,6 +1,6 @@ package com.songoda.epicfarming.utils; -import com.songoda.epicfarming.EpicFarming; +import com.songoda.epicfarming.EpicFarmingPlugin; /** * Created by songoda on 3/21/2017. @@ -24,7 +24,7 @@ public class Debugger { } public static boolean isDebug() { - EpicFarming plugin = EpicFarming.pl(); + EpicFarmingPlugin plugin = EpicFarmingPlugin.pl(); return plugin.getConfig().getBoolean("System.Debugger Enabled"); } diff --git a/src/main/java/com/songoda/epicfarming/utils/Methods.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/Methods.java similarity index 55% rename from src/main/java/com/songoda/epicfarming/utils/Methods.java rename to EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/Methods.java index d47d891..3cf8d7c 100644 --- a/src/main/java/com/songoda/epicfarming/utils/Methods.java +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/Methods.java @@ -1,8 +1,8 @@ package com.songoda.epicfarming.utils; import com.songoda.arconix.plugin.Arconix; -import com.songoda.epicfarming.EpicFarming; -import com.songoda.epicfarming.farming.Level; +import com.songoda.epicfarming.EpicFarmingPlugin; +import com.songoda.epicfarming.farming.ELevel; import org.apache.commons.lang.math.NumberUtils; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -12,7 +12,7 @@ public class Methods { public static ItemStack getGlass() { try { - EpicFarming plugin = EpicFarming.pl(); + EpicFarmingPlugin plugin = EpicFarmingPlugin.pl(); return Arconix.pl().getApi().getGUI().getGlass(plugin.getConfig().getBoolean("settings.Rainbow-Glass"), plugin.getConfig().getInt("Interfaces.Glass Type 1")); } catch (Exception ex) { Debugger.runReport(ex); @@ -22,7 +22,7 @@ public class Methods { public static ItemStack getBackgroundGlass(boolean type) { try { - EpicFarming plugin = EpicFarming.pl(); + EpicFarmingPlugin plugin = EpicFarmingPlugin.pl(); if (type) return Arconix.pl().getApi().getGUI().getGlass(false, plugin.getConfig().getInt("Interfaces.Glass Type 2")); else @@ -33,21 +33,9 @@ public class Methods { return null; } - public static int getLevelFromItem(ItemStack item) { - try { - if (!item.hasItemMeta() || !item.getItemMeta().hasDisplayName()) return 0; - if (item.getItemMeta().getDisplayName().contains(":")) { - return NumberUtils.toInt(item.getItemMeta().getDisplayName().replace("\u00A7", "").split(":")[0], 0); - } - } catch (Exception ex) { - Debugger.runReport(ex); - } - return 0; - } - public static String formatName(int level, boolean full) { try { - String name = EpicFarming.getInstance().getLocale().getMessage("general.nametag.farm", level); + String name = EpicFarmingPlugin.getInstance().getLocale().getMessage("general.nametag.farm", level); String info = ""; if (full) { @@ -60,12 +48,4 @@ public class Methods { } return null; } - - public static ItemStack makeFarmItem(Level level) { - ItemStack item = new ItemStack(Material.valueOf(EpicFarming.getInstance().getConfig().getString("Main.Farm Block Material")), 1); - ItemMeta meta = item.getItemMeta(); - meta.setDisplayName(Arconix.pl().getApi().format().formatText(Methods.formatName(level.getLevel(), true))); - item.setItemMeta(meta); - return item; - } } \ No newline at end of file diff --git a/src/main/java/com/songoda/epicfarming/utils/SettingsManager.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/SettingsManager.java similarity index 97% rename from src/main/java/com/songoda/epicfarming/utils/SettingsManager.java rename to EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/SettingsManager.java index 030859d..4e87eb9 100644 --- a/src/main/java/com/songoda/epicfarming/utils/SettingsManager.java +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/SettingsManager.java @@ -2,8 +2,7 @@ package com.songoda.epicfarming.utils; import com.songoda.arconix.api.methods.formatting.TextComponent; import com.songoda.arconix.api.utils.ConfigWrapper; -import com.songoda.arconix.plugin.Arconix; -import com.songoda.epicfarming.EpicFarming; +import com.songoda.epicfarming.EpicFarmingPlugin; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -34,9 +33,9 @@ public class SettingsManager implements Listener { private Map cat = new HashMap<>(); - private final EpicFarming instance; + private final EpicFarmingPlugin instance; - public SettingsManager(EpicFarming plugin) { + public SettingsManager(EpicFarmingPlugin plugin) { this.instance = plugin; plugin.saveResource("SettingDefinitions.yml", true); diff --git a/src/main/resources/SettingDefinitions.yml b/EpicFarming-Plugin/src/main/resources/SettingDefinitions.yml similarity index 100% rename from src/main/resources/SettingDefinitions.yml rename to EpicFarming-Plugin/src/main/resources/SettingDefinitions.yml diff --git a/src/main/resources/en_US.lang b/EpicFarming-Plugin/src/main/resources/en_US.lang similarity index 100% rename from src/main/resources/en_US.lang rename to EpicFarming-Plugin/src/main/resources/en_US.lang diff --git a/src/main/resources/plugin.yml b/EpicFarming-Plugin/src/main/resources/plugin.yml similarity index 100% rename from src/main/resources/plugin.yml rename to EpicFarming-Plugin/src/main/resources/plugin.yml diff --git a/src/main/java/com/songoda/epicfarming/handlers/HookHandler.java b/src/main/java/com/songoda/epicfarming/handlers/HookHandler.java deleted file mode 100644 index e229fd7..0000000 --- a/src/main/java/com/songoda/epicfarming/handlers/HookHandler.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.songoda.epicfarming.handlers; - -import com.songoda.arconix.api.utils.ConfigWrapper; -import com.songoda.epicfarming.EpicFarming; -import com.songoda.epicfarming.hooks.*; -import com.songoda.epicfarming.utils.Debugger; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.entity.Player; - -/** - * Created by songoda on 3/17/2017. - */ -public class HookHandler { - - public Hook FactionsHook = null, RedProtectHook = null, ASkyBlockHook = null, USkyBlockHook = null, - WorldGuardHook = null, GriefPreventionHook = null, PlotSquaredHook = null, KingdomsHook = null, - TownyHook = null; - - public ConfigWrapper hooksFile = new ConfigWrapper(EpicFarming.getInstance(), "", "hooks.yml"); - - public HookHandler() { - } - - public void hook() { - try { - hooksFile.createNewFile("Loading hooks File", EpicFarming.getInstance().getDescription().getName() + " hooks File"); - - new FactionsHook(); - new RedProtectHook(); - new GriefPreventionHook(); - new ASkyBlockHook(); - new USkyBlockHook(); - new WorldGuardHook(); - new PlotSquaredHook(); - new KingdomsHook(); - new TownyHook(); - - hooksFile.getConfig().options().copyDefaults(true); - hooksFile.saveConfig(); - } catch (Exception e) { - Debugger.runReport(e); - } - - } - - public boolean isInFaction(String name, Location l) { - if (FactionsHook != null) { - return FactionsHook.isInClaim(name, l); - } - return false; - } - - public String getFactionId(String name) { - if (FactionsHook != null) { - return FactionsHook.getClaimId(name); - } - return null; - } - - public boolean isInTown(String name, Location l) { - if (TownyHook != null) { - return TownyHook.isInClaim(name, l); - } - return false; - } - - public String getTownId(String name) { - if (TownyHook != null) { - return TownyHook.getClaimId(name); - } - return null; - } - - public boolean isInIsland(String name, Location l) { - if (USkyBlockHook != null) - return USkyBlockHook.isInClaim(name, l); - else if (ASkyBlockHook != null) - return ASkyBlockHook.isInClaim(name, l); - else - return false; - } - - public String getIslandId(String name) { - try { - return Bukkit.getOfflinePlayer(name).getUniqueId().toString(); - } catch (Exception ignore) { - } - return null; - } - - public boolean canBuild(Player p, Location l) { - boolean result = true; - if (WorldGuardHook != null) - result = WorldGuardHook.canBuild(p, l); - if (RedProtectHook != null && result) - result = RedProtectHook.canBuild(p, l); - if (FactionsHook != null && result) - result = FactionsHook.canBuild(p, l); - if (ASkyBlockHook != null && result) - result = ASkyBlockHook.canBuild(p, l); - if (USkyBlockHook != null && result) - result = USkyBlockHook.canBuild(p, l); - if (GriefPreventionHook != null && result) - result = GriefPreventionHook.canBuild(p, l); - if (PlotSquaredHook != null && result) - result = PlotSquaredHook.canBuild(p, l); - if (KingdomsHook != null && result) - result = KingdomsHook.canBuild(p, l); - if (TownyHook != null && result) - result = TownyHook.canBuild(p, l); - return result; - } -} diff --git a/src/main/java/com/songoda/epicfarming/hooks/ASkyBlockHook.java b/src/main/java/com/songoda/epicfarming/hooks/ASkyBlockHook.java deleted file mode 100644 index d7738b9..0000000 --- a/src/main/java/com/songoda/epicfarming/hooks/ASkyBlockHook.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.songoda.epicfarming.hooks; - -import com.songoda.epicfarming.EpicFarming; -import com.songoda.epicfarming.utils.Debugger; -import com.wasteofplastic.askyblock.ASkyBlockAPI; -import org.bukkit.Location; -import org.bukkit.entity.Player; - -import java.util.List; -import java.util.Set; -import java.util.UUID; - -/** - * Created by songoda on 3/17/2017. - */ -public class ASkyBlockHook extends Hook { - - private ASkyBlockAPI as; - - public ASkyBlockHook() { - super("ASkyblock"); - if (isEnabled()) { - as = ASkyBlockAPI.getInstance(); - EpicFarming plugin = EpicFarming.pl(); - plugin.hooks.ASkyBlockHook = this; - } - } - - @Override - public boolean canBuild(Player p, Location location) { - try { - if (hasBypass(p) || as.getIslandAt(location) == null) return true; - - UUID owner = as.getOwner(location); - List list = as.getTeamMembers(owner); - Set list2 = as.getCoopIslands(p); - - if (owner == null) return true; - - for (UUID uuid : list) { - if (uuid.equals(p.getUniqueId())) { - return true; - } - } - - for (Location loc: list2) { - if (as.getIslandAt(location).getOwner().equals(as.getIslandAt(loc).getOwner())) { - return true; - } - } - - return owner.equals(p.getUniqueId()); - } catch (Exception e) { - Debugger.runReport(e); - } - return true; - } - - @Override - public boolean isInClaim(String uuid, Location location) { - return as.getOwner(location).toString().equals(uuid); - } - -} diff --git a/src/main/java/com/songoda/epicfarming/hooks/FactionsHook.java b/src/main/java/com/songoda/epicfarming/hooks/FactionsHook.java deleted file mode 100644 index 70cb89c..0000000 --- a/src/main/java/com/songoda/epicfarming/hooks/FactionsHook.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.songoda.epicfarming.hooks; - -import com.songoda.epicfarming.EpicFarming; -import com.songoda.epicfarming.utils.Debugger; -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; - -/** - * Created by songoda on 3/17/2017. - */ -public class FactionsHook extends Hook { - - public FactionsHook() { - super("Factions"); - EpicFarming plugin = EpicFarming.pl(); - if (isEnabled()) - plugin.hooks.GriefPreventionHook = this; - } - - @Override - public boolean canBuild(Player p, Location location) { - try { - FPlayer fp = FPlayers.getBySender(p); - - Faction faction = Factions.getFactionAt(location); - - return (fp.getFaction().equals(faction) || faction.isNone()); - } catch (Exception e) { - Debugger.runReport(e); - } - return false; - } - - @Override - public boolean isInClaim(String id, Location location) { - Faction faction = Factions.getFactionAt(location); - - return faction.getId().equals(id); - } - - @Override - public String getClaimId(String name) { - try { - Faction faction = Factions.getByName(name, ""); - - return faction.getId(); - } catch (Exception e) { - } - return null; - } - -} diff --git a/src/main/java/com/songoda/epicfarming/hooks/GriefPreventionHook.java b/src/main/java/com/songoda/epicfarming/hooks/GriefPreventionHook.java deleted file mode 100644 index c863696..0000000 --- a/src/main/java/com/songoda/epicfarming/hooks/GriefPreventionHook.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.songoda.epicfarming.hooks; - -import com.songoda.epicfarming.EpicFarming; -import com.songoda.epicfarming.utils.Debugger; -import me.ryanhamshire.GriefPrevention.Claim; -import me.ryanhamshire.GriefPrevention.GriefPrevention; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.entity.Player; - -/** - * Created by songoda on 3/17/2017. - */ -public class GriefPreventionHook extends Hook { - - private EpicFarming plugin = EpicFarming.pl(); - - public GriefPreventionHook() { - super("GriefPrevention"); - if (isEnabled()) - plugin.hooks.GriefPreventionHook = this; - } - - @Override - public boolean canBuild(Player p, Location location) { - try { - if (hasBypass(p)) - return true; - - Claim claim = GriefPrevention.instance.dataStore.getClaimAt(location, false, null); - return claim != null && claim.allowBuild(p, Material.STONE) == null; - - } catch (Exception e) { - Debugger.runReport(e); - } - return false; - } -} diff --git a/src/main/java/com/songoda/epicfarming/hooks/Hook.java b/src/main/java/com/songoda/epicfarming/hooks/Hook.java deleted file mode 100644 index db95f14..0000000 --- a/src/main/java/com/songoda/epicfarming/hooks/Hook.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.songoda.epicfarming.hooks; - -import com.songoda.epicfarming.EpicFarming; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.entity.Player; - -public abstract class Hook { - - protected final String pluginName; - - protected Hook(String pluginName) { - this.pluginName = pluginName; - if (isEnabled()) - EpicFarming.getInstance().hooks.hooksFile.getConfig().addDefault("hooks." + pluginName, true); - } - - protected boolean isEnabled() { - return (Bukkit.getPluginManager().isPluginEnabled(pluginName) - && EpicFarming.getInstance().hooks.hooksFile.getConfig().getBoolean("hooks." + pluginName,true)); - } - - protected boolean hasBypass(Player p) { - return p.hasPermission(EpicFarming.getInstance().getDescription().getName() + ".bypass"); - } - - public abstract boolean canBuild(Player p, Location location); - - public boolean isInClaim(String id, Location location) { - return false; - } - - public String getClaimId(String name) { - return null; - } - - - - -} diff --git a/src/main/java/com/songoda/epicfarming/hooks/KingdomsHook.java b/src/main/java/com/songoda/epicfarming/hooks/KingdomsHook.java deleted file mode 100644 index f531293..0000000 --- a/src/main/java/com/songoda/epicfarming/hooks/KingdomsHook.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.songoda.epicfarming.hooks; - -import com.songoda.epicfarming.EpicFarming; -import com.songoda.epicfarming.utils.Debugger; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.kingdoms.constants.land.Land; -import org.kingdoms.constants.land.SimpleChunkLocation; -import org.kingdoms.constants.player.OfflineKingdomPlayer; -import org.kingdoms.manager.game.GameManagement; - -/** - * Created by songoda on 3/17/2017. - */ -public class KingdomsHook extends Hook { - - public KingdomsHook() { - super("Kingdoms"); - EpicFarming plugin = EpicFarming.pl(); - if (isEnabled()) - plugin.hooks.KingdomsHook = this; - } - - @Override - public boolean canBuild(Player p, Location location) { - try { - if (hasBypass(p)) return true; - - OfflineKingdomPlayer pl = GameManagement.getPlayerManager().getOfflineKingdomPlayer(p); - if (pl.getKingdomPlayer().getKingdom() == null) return true; - - SimpleChunkLocation chunkLocation = new SimpleChunkLocation(location.getWorld().getName(), location.getChunk().getX(), location.getChunk().getZ()); - Land land = GameManagement.getLandManager().getOrLoadLand(chunkLocation); - String owner = land.getOwner(); - - return pl.getKingdomPlayer().getKingdom().getKingdomName().equals(owner) || owner == null; - } catch (Exception e) { - Debugger.runReport(e); - } - return true; - } - -} diff --git a/src/main/java/com/songoda/epicfarming/hooks/PlotSquaredHook.java b/src/main/java/com/songoda/epicfarming/hooks/PlotSquaredHook.java deleted file mode 100644 index 9b1a8dc..0000000 --- a/src/main/java/com/songoda/epicfarming/hooks/PlotSquaredHook.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.songoda.epicfarming.hooks; - -import com.intellectualcrafters.plot.api.PlotAPI; -import com.songoda.epicfarming.EpicFarming; -import com.songoda.epicfarming.utils.Debugger; -import org.bukkit.Location; -import org.bukkit.entity.Player; - -/** - * Created by songoda on 3/17/2017. - */ -public class PlotSquaredHook extends Hook { - - private PlotAPI plotAPI; - - public PlotSquaredHook() { - super("PlotSquared"); - if (isEnabled()) { - EpicFarming plugin = EpicFarming.pl(); - plugin.hooks.PlotSquaredHook = this; - this.plotAPI = new PlotAPI(); - } - } - - @Override - public boolean canBuild(Player p, Location location) { - try { - return hasBypass(p) - || (plotAPI.getPlot(location) != null - && plotAPI.isInPlot(p) - && plotAPI.getPlot(p) == plotAPI.getPlot(location)); - } catch (Exception e) { - Debugger.runReport(e); - } - return true; - } - -} diff --git a/src/main/java/com/songoda/epicfarming/hooks/RedProtectHook.java b/src/main/java/com/songoda/epicfarming/hooks/RedProtectHook.java deleted file mode 100644 index 3eccffb..0000000 --- a/src/main/java/com/songoda/epicfarming/hooks/RedProtectHook.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.songoda.epicfarming.hooks; - -import br.net.fabiozumbi12.RedProtect.Bukkit.API.RedProtectAPI; -import br.net.fabiozumbi12.RedProtect.Bukkit.RedProtect; -import com.songoda.epicfarming.EpicFarming; -import com.songoda.epicfarming.utils.Debugger; -import org.bukkit.Location; -import org.bukkit.entity.Player; - -/** - * Created by songoda on 3/17/2017. - */ -public class RedProtectHook extends Hook { - - private EpicFarming plugin = EpicFarming.pl(); - - public RedProtectHook() { - super("RedProtect"); - if (isEnabled()) - plugin.hooks.RedProtectHook = this; - } - - @Override - public boolean canBuild(Player p, Location location) { - try { - RedProtectAPI rpAPI = RedProtect.get().getAPI(); - return hasBypass(p) || (rpAPI.getRegion(location) != null && rpAPI.getRegion(location).canBuild(p)); - } catch (Exception e) { - Debugger.runReport(e); - } - return true; - } - -} diff --git a/src/main/java/com/songoda/epicfarming/hooks/TownyHook.java b/src/main/java/com/songoda/epicfarming/hooks/TownyHook.java deleted file mode 100644 index bd0b584..0000000 --- a/src/main/java/com/songoda/epicfarming/hooks/TownyHook.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.songoda.epicfarming.hooks; - -import com.palmergames.bukkit.towny.object.Resident; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.songoda.epicfarming.EpicFarming; -import com.songoda.epicfarming.utils.Debugger; -import org.bukkit.Location; -import org.bukkit.entity.Player; - -/** - * Created by songoda on 3/17/2017. - */ -public class TownyHook extends Hook { - - public TownyHook() { - super("Towny"); - EpicFarming plugin = EpicFarming.pl(); - if (isEnabled()) - plugin.hooks.TownyHook = this; - } - - @Override - public boolean canBuild(Player p, Location location) { - try { - if (hasBypass(p) || TownyUniverse.isWilderness(location.getBlock())) return true; - if (!TownyUniverse.getTownBlock(location).hasTown()) return true; - - Resident r = TownyUniverse.getDataSource().getResident(p.getName()); - return r.hasTown() && TownyUniverse.getTownName(location).equals(r.getTown().getName()); - } catch (Exception e) { - Debugger.runReport(e); - } - return true; - } - - @Override - public boolean isInClaim(String id, Location location) { - try { - return !TownyUniverse.isWilderness(location.getBlock()) - && TownyUniverse.getTownBlock(location).getTown().getUID() == Integer.parseInt(id); - } catch (Exception e) { - Debugger.runReport(e); - } - return false; - } - - @Override - public String getClaimId(String name) { - try { - return TownyUniverse.getDataSource().getTown(name).getUID().toString(); - } catch (Exception e) { - Debugger.runReport(e); - } - return null; - } -} diff --git a/src/main/java/com/songoda/epicfarming/hooks/USkyBlockHook.java b/src/main/java/com/songoda/epicfarming/hooks/USkyBlockHook.java deleted file mode 100644 index 09c34ef..0000000 --- a/src/main/java/com/songoda/epicfarming/hooks/USkyBlockHook.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.songoda.epicfarming.hooks; - -import com.songoda.epicfarming.EpicFarming; -import com.songoda.epicfarming.utils.Debugger; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import us.talabrek.ultimateskyblock.api.uSkyBlockAPI; - -/** - * Created by songoda on 3/17/2017. - */ -public class USkyBlockHook extends Hook { - - private uSkyBlockAPI usb; - private EpicFarming plugin = EpicFarming.pl(); - - public USkyBlockHook() { - super("USkyBlock"); - if (isEnabled()) { - plugin.hooks.USkyBlockHook = this; - this.usb = (uSkyBlockAPI) Bukkit.getPluginManager().getPlugin(pluginName); - } - } - - @Override - public boolean canBuild(Player p, Location location) { - try { - if (hasBypass(p)) return true; - - for (Player pl : usb.getIslandInfo(location).getOnlineMembers()) { - if (pl.equals(p)) { - return true; - } - } - - return usb.getIslandInfo(location).isLeader(p); - } catch (Exception e) { - Debugger.runReport(e); - } - return false; - } - - @Override - public boolean isInClaim(String uuid, Location location) { - return usb.getIslandInfo(location).getLeader().equals(uuid); - } - -} diff --git a/src/main/java/com/songoda/epicfarming/hooks/WorldGuardHook.java b/src/main/java/com/songoda/epicfarming/hooks/WorldGuardHook.java deleted file mode 100644 index 814cf64..0000000 --- a/src/main/java/com/songoda/epicfarming/hooks/WorldGuardHook.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.songoda.epicfarming.hooks; - -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.songoda.epicfarming.EpicFarming; -import com.songoda.epicfarming.utils.Debugger; -import org.bukkit.Location; -import org.bukkit.entity.Player; - -/** - * Created by songoda on 3/17/2017. - */ -public class WorldGuardHook extends Hook { - - private EpicFarming plugin = EpicFarming.pl(); - - public WorldGuardHook() { - super("WorldGuard"); - if (isEnabled()) - plugin.hooks.WorldGuardHook = this; - } - - @Override - public boolean canBuild(Player p, Location location) { - try { - return p.hasPermission(plugin.getDescription().getName() + ".bypass") || WorldGuardPlugin.inst().canBuild(p, location); - } catch (Exception e) { - Debugger.runReport(e); - } - return false; - } -}