diff --git a/.gitignore b/.gitignore
index 5ec6929..ac5d64e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,5 @@ out/
\.idea/
EpicFarming\.iml
+/src/main/resources/META-INF/MANIFEST.MF
+/target/
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..fae2abf
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,185 @@
+
+ 4.0.0
+ com.songoda
+ EpicFarming
+ 1.1
+
+ jar
+
+ EpicFarming
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ 1.8
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ 1.4
+
+
+ package
+
+ shade
+
+
+
+
+
+
+
+
+ jcenter
+ http://jcenter.bintray.com
+
+
+
+ bukkit-repo
+ https://hub.spigotmc.org/nexus/content/groups/public/
+
+
+
+ songoda-public
+ http://jenkins.songoda.com:8081/repository/songoda-public/
+
+
+ songoda-private
+ http://jenkins.songoda.com:8081/repository/songoda-private/
+
+
+
+ sk89q-repo
+ http://maven.sk89q.com/repo/
+
+
+
+ vault-repo
+ http://nexus.hc.to/content/repositories/pub_releases
+
+
+
+ uSkyBlock-mvn-repo
+ https://raw.github.com/rlf/uSkyBlock/mvn-repo/
+
+ true
+ always
+
+
+
+
+ bintray-tastybento-maven-repo
+ bintray
+ http://dl.bintray.com/tastybento/maven-repo
+
+
+ jitpack.io
+ https://jitpack.io
+
+
+
+
+
+
+ org.bukkit
+ bukkit
+ 1.12.2-R0.1-SNAPSHOT
+ jar
+ provided
+
+
+
+ com.songoda.arconix
+ api
+ 2.0.0
+ provided
+
+
+ com.songoda.arconix
+ plugin
+ 2.0.0
+ provided
+
+
+
+ com.sk89q
+ worldguard
+ 6.1.1-SNAPSHOT
+ provided
+
+
+
+ net.milkbowl.vault
+ VaultAPI
+ 1.6
+ provided
+
+
+
+ com.palmergames
+ Towny
+ 0.92.0.0
+ provided
+
+
+
+ com.github.rlf
+ uSkyBlock-API
+ 2.6.4
+ provided
+
+
+
+ br.net.fabiozumbi12
+ RedProtect
+ 7.3.0
+ provided
+
+
+
+ com.intellectualcrafters
+ PlotSquared
+ 18.05.01
+ provided
+
+
+
+ org.kingdoms
+ Kingdoms
+ 13.3.40
+ provided
+
+
+
+ com.github.TechFortress
+ GriefPrevention
+ 16.7.1
+ provided
+
+
+
+ me.markeh
+ factionsframework
+ 1.2.0
+ provided
+
+
+
+ com.wasteofplastic
+ askyblock
+ 3.0.8.2
+ provided
+
+
+
+ commons-lang
+ commons-lang
+ 2.6
+ compile
+
+
+
\ No newline at end of file
diff --git a/src/com/songoda/epicfarming/EpicFarming.java b/src/com/songoda/epicfarming/EpicFarming.java
deleted file mode 100644
index 8c5d80d..0000000
Binary files a/src/com/songoda/epicfarming/EpicFarming.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/Lang.java b/src/com/songoda/epicfarming/Lang.java
deleted file mode 100644
index 8d4e9a1..0000000
Binary files a/src/com/songoda/epicfarming/Lang.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/References.java b/src/com/songoda/epicfarming/References.java
deleted file mode 100644
index 3ebef3e..0000000
Binary files a/src/com/songoda/epicfarming/References.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/api/MCUpdate.java b/src/com/songoda/epicfarming/api/MCUpdate.java
deleted file mode 100644
index 7597cb0..0000000
Binary files a/src/com/songoda/epicfarming/api/MCUpdate.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/events/BlockListeners.java b/src/com/songoda/epicfarming/events/BlockListeners.java
deleted file mode 100644
index ef9cb3f..0000000
Binary files a/src/com/songoda/epicfarming/events/BlockListeners.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/events/EntityListeners.java b/src/com/songoda/epicfarming/events/EntityListeners.java
deleted file mode 100644
index d8b2eb5..0000000
Binary files a/src/com/songoda/epicfarming/events/EntityListeners.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/events/InteractListeners.java b/src/com/songoda/epicfarming/events/InteractListeners.java
deleted file mode 100644
index bb3b89b..0000000
Binary files a/src/com/songoda/epicfarming/events/InteractListeners.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/events/InventoryListeners.java b/src/com/songoda/epicfarming/events/InventoryListeners.java
deleted file mode 100644
index ca46243..0000000
Binary files a/src/com/songoda/epicfarming/events/InventoryListeners.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/farming/Crop.java b/src/com/songoda/epicfarming/farming/Crop.java
deleted file mode 100644
index 22466fc..0000000
Binary files a/src/com/songoda/epicfarming/farming/Crop.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/farming/Farm.java b/src/com/songoda/epicfarming/farming/Farm.java
deleted file mode 100644
index b64a807..0000000
Binary files a/src/com/songoda/epicfarming/farming/Farm.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/farming/FarmManager.java b/src/com/songoda/epicfarming/farming/FarmManager.java
deleted file mode 100644
index 49d22b6..0000000
Binary files a/src/com/songoda/epicfarming/farming/FarmManager.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/farming/Level.java b/src/com/songoda/epicfarming/farming/Level.java
deleted file mode 100644
index ff74197..0000000
Binary files a/src/com/songoda/epicfarming/farming/Level.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/farming/LevelManager.java b/src/com/songoda/epicfarming/farming/LevelManager.java
deleted file mode 100644
index 68afa68..0000000
Binary files a/src/com/songoda/epicfarming/farming/LevelManager.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/handlers/CommandHandler.java b/src/com/songoda/epicfarming/handlers/CommandHandler.java
deleted file mode 100644
index 23a746f..0000000
Binary files a/src/com/songoda/epicfarming/handlers/CommandHandler.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/handlers/FarmingHandler.java b/src/com/songoda/epicfarming/handlers/FarmingHandler.java
deleted file mode 100644
index 8985116..0000000
Binary files a/src/com/songoda/epicfarming/handlers/FarmingHandler.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/handlers/GrowthHandler.java b/src/com/songoda/epicfarming/handlers/GrowthHandler.java
deleted file mode 100644
index 90088cc..0000000
Binary files a/src/com/songoda/epicfarming/handlers/GrowthHandler.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/handlers/HookHandler.java b/src/com/songoda/epicfarming/handlers/HookHandler.java
deleted file mode 100644
index 6c68f58..0000000
Binary files a/src/com/songoda/epicfarming/handlers/HookHandler.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/hooks/ASkyBlockHook.java b/src/com/songoda/epicfarming/hooks/ASkyBlockHook.java
deleted file mode 100644
index 24da432..0000000
Binary files a/src/com/songoda/epicfarming/hooks/ASkyBlockHook.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/hooks/FactionsHook.java b/src/com/songoda/epicfarming/hooks/FactionsHook.java
deleted file mode 100644
index d2d3ec0..0000000
Binary files a/src/com/songoda/epicfarming/hooks/FactionsHook.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/hooks/GriefPreventionHook.java b/src/com/songoda/epicfarming/hooks/GriefPreventionHook.java
deleted file mode 100644
index 848830c..0000000
Binary files a/src/com/songoda/epicfarming/hooks/GriefPreventionHook.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/hooks/Hook.java b/src/com/songoda/epicfarming/hooks/Hook.java
deleted file mode 100644
index 6a3ec21..0000000
Binary files a/src/com/songoda/epicfarming/hooks/Hook.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/hooks/KingdomsHook.java b/src/com/songoda/epicfarming/hooks/KingdomsHook.java
deleted file mode 100644
index e45d4e2..0000000
Binary files a/src/com/songoda/epicfarming/hooks/KingdomsHook.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/hooks/PlotSquaredHook.java b/src/com/songoda/epicfarming/hooks/PlotSquaredHook.java
deleted file mode 100644
index 130424a..0000000
Binary files a/src/com/songoda/epicfarming/hooks/PlotSquaredHook.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/hooks/RedProtectHook.java b/src/com/songoda/epicfarming/hooks/RedProtectHook.java
deleted file mode 100644
index 3ca9567..0000000
Binary files a/src/com/songoda/epicfarming/hooks/RedProtectHook.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/hooks/TownyHook.java b/src/com/songoda/epicfarming/hooks/TownyHook.java
deleted file mode 100644
index 0c0af2e..0000000
Binary files a/src/com/songoda/epicfarming/hooks/TownyHook.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/hooks/USkyBlockHook.java b/src/com/songoda/epicfarming/hooks/USkyBlockHook.java
deleted file mode 100644
index 5aa64c4..0000000
Binary files a/src/com/songoda/epicfarming/hooks/USkyBlockHook.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/hooks/WorldGuardHook.java b/src/com/songoda/epicfarming/hooks/WorldGuardHook.java
deleted file mode 100644
index 0918b78..0000000
Binary files a/src/com/songoda/epicfarming/hooks/WorldGuardHook.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/player/PlayerActionManager.java b/src/com/songoda/epicfarming/player/PlayerActionManager.java
deleted file mode 100644
index 508e3df..0000000
Binary files a/src/com/songoda/epicfarming/player/PlayerActionManager.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/player/PlayerData.java b/src/com/songoda/epicfarming/player/PlayerData.java
deleted file mode 100644
index 69ca742..0000000
Binary files a/src/com/songoda/epicfarming/player/PlayerData.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/utils/ConfigWrapper.java b/src/com/songoda/epicfarming/utils/ConfigWrapper.java
deleted file mode 100644
index 75b1145..0000000
Binary files a/src/com/songoda/epicfarming/utils/ConfigWrapper.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/utils/CropType.java b/src/com/songoda/epicfarming/utils/CropType.java
deleted file mode 100644
index a7180cf..0000000
Binary files a/src/com/songoda/epicfarming/utils/CropType.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/utils/Debugger.java b/src/com/songoda/epicfarming/utils/Debugger.java
deleted file mode 100644
index d57ed77..0000000
Binary files a/src/com/songoda/epicfarming/utils/Debugger.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/utils/Methods.java b/src/com/songoda/epicfarming/utils/Methods.java
deleted file mode 100644
index 189875e..0000000
Binary files a/src/com/songoda/epicfarming/utils/Methods.java and /dev/null differ
diff --git a/src/com/songoda/epicfarming/utils/SettingsManager.java b/src/com/songoda/epicfarming/utils/SettingsManager.java
deleted file mode 100644
index d1078c6..0000000
Binary files a/src/com/songoda/epicfarming/utils/SettingsManager.java and /dev/null differ
diff --git a/src/main/java/com/songoda/epicfarming/EpicFarming.java b/src/main/java/com/songoda/epicfarming/EpicFarming.java
new file mode 100644
index 0000000..3cc0463
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/EpicFarming.java
@@ -0,0 +1,269 @@
+package com.songoda.epicfarming;
+
+import com.songoda.arconix.api.mcupdate.MCUpdate;
+import com.songoda.arconix.api.utils.ConfigWrapper;
+import com.songoda.arconix.plugin.Arconix;
+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.handlers.CommandHandler;
+import com.songoda.epicfarming.handlers.FarmingHandler;
+import com.songoda.epicfarming.handlers.GrowthHandler;
+import com.songoda.epicfarming.handlers.HookHandler;
+import com.songoda.epicfarming.player.PlayerActionManager;
+import com.songoda.epicfarming.player.PlayerData;
+import com.songoda.epicfarming.utils.SettingsManager;
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.command.CommandSender;
+import org.bukkit.event.Listener;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.plugin.java.JavaPlugin;
+
+import java.util.List;
+
+/**
+ * Created by songoda on 1/23/2018.
+ */
+public class EpicFarming extends JavaPlugin implements Listener {
+
+ private static EpicFarming INSTANCE;
+
+ public SettingsManager settingsManager;
+ public References references;
+ public HookHandler hooks;
+
+ private ConfigWrapper langFile = new ConfigWrapper(this, "", "lang.yml");
+
+ public boolean v1_10 = Bukkit.getServer().getClass().getPackage().getName().contains("1_10");
+ public boolean v1_9 = Bukkit.getServer().getClass().getPackage().getName().contains("1_9");
+ public boolean v1_7 = Bukkit.getServer().getClass().getPackage().getName().contains("1_7");
+ public boolean v1_8 = Bukkit.getServer().getClass().getPackage().getName().contains("1_8");
+
+
+ private FarmingHandler farmingHandler;
+ private GrowthHandler growthHandler;
+
+ private FarmManager farmManager;
+ private LevelManager levelManager;
+ private PlayerActionManager playerActionManager;
+
+ public ConfigWrapper dataFile = new ConfigWrapper(this, "", "data.yml");
+
+ public void onEnable() {
+ INSTANCE = this;
+ Arconix.pl().hook(this);
+
+ CommandSender console = Bukkit.getConsoleSender();
+ console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
+ console.sendMessage(Arconix.pl().getApi().format().formatText("&7EpicFarming " + this.getDescription().getVersion() + " by &5Brianna <3&7!"));
+ console.sendMessage(Arconix.pl().getApi().format().formatText("&7Action: &aEnabling&7..."));
+
+ langFile.createNewFile("Loading Language File", "EpicFarming Language File");
+ loadLanguageFile();
+
+ settingsManager = new SettingsManager(this);
+ setupConfig();
+ levelManager = new LevelManager();
+
+ dataFile.createNewFile("Loading Data File", "EpicFarming Data File");
+ loadDataFile();
+
+ /*
+ * Register Levels into LevelManager from configuration.
+ */
+ for (String levelName : getConfig().getConfigurationSection("settings.levels").getKeys(false)) {
+ int level = Integer.valueOf(levelName.split("-")[1]);
+ int radius = getConfig().getInt("settings.levels." + levelName + ".Radius");
+ int costExperiance = getConfig().getInt("settings.levels." + levelName + ".Cost-xp");
+ int costEconomy = getConfig().getInt("settings.levels." + levelName + ".Cost-eco");
+ double speedMultiplier = getConfig().getDouble("settings.levels." + levelName + ".Speed-Multiplier");
+ boolean autoHarvest = getConfig().getBoolean("settings.levels." + levelName + ".Auto-Harvest");
+ boolean autoReplant = getConfig().getBoolean("settings.levels." + levelName + ".Auto-Replant");
+ levelManager.addLevel(level, costExperiance, costEconomy, speedMultiplier, radius, autoHarvest, autoReplant);
+ }
+
+ farmManager = new FarmManager();
+
+ /*
+ * Register Farms into FarmManger from configuration
+ */
+ if (dataFile.getConfig().contains("Farms")) {
+ for (String locationStr : dataFile.getConfig().getConfigurationSection("Farms").getKeys(false)) {
+ Location location = Arconix.pl().getApi().serialize().unserializeLocation(locationStr);
+ int level = dataFile.getConfig().getInt("Farms." + locationStr + ".level");
+
+ List items = (List)dataFile.getConfig().getList("Farms." + locationStr + ".Contents");
+
+ Farm farm = new Farm(location, levelManager.getLevel(level));
+ farm.loadInventory(items);
+
+ farmManager.addFarm(location, farm);
+ }
+ }
+ playerActionManager = new PlayerActionManager();
+
+ hooks = new HookHandler();
+ hooks.hook();
+
+ farmingHandler = new FarmingHandler(this);
+ growthHandler = new GrowthHandler(this);
+ references = new References();
+
+ 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);
+
+ this.getServer().getPluginManager().registerEvents(this, this);
+
+ new MCUpdate(this, true);
+
+ console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
+ }
+
+ public void onDisable() {
+ saveToFile();
+ for (PlayerData playerData : playerActionManager.getRegisteredPlayers()) {
+ if (playerData.getPlayer() != null)
+ playerData.getPlayer().closeInventory();
+ }
+ CommandSender console = Bukkit.getConsoleSender();
+ dataFile.saveConfig();
+ console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
+ console.sendMessage(Arconix.pl().getApi().format().formatText("&7EpicFarming " + this.getDescription().getVersion() + " by &5Brianna <3!"));
+ console.sendMessage(Arconix.pl().getApi().format().formatText("&7Action: &cDisabling&7..."));
+ console.sendMessage(Arconix.pl().getApi().format().formatText("&a============================="));
+ }
+
+ /*
+ * Saves registered farms to file.
+ */
+ private void saveToFile() {
+
+ // Wipe old kit information
+ dataFile.getConfig().set("Farms", null);
+
+ /*
+ * Dump FarmManager to file.
+ */
+ for (Farm farm : farmManager.getFarms().values()) {
+ 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());
+ }
+
+ //Save to file
+ dataFile.saveConfig();
+
+ }
+
+ public void reload() {
+ langFile.createNewFile("Loading Language File", "EpicFarming Language File");
+ hooks.hooksFile.createNewFile("Loading hooks File", "EpicFarming hooks File");
+ hooks = new HookHandler();
+ hooks.hook();
+ loadLanguageFile();
+ references = new References();
+ reloadConfig();
+ saveConfig();
+ }
+
+ private void setupConfig() {
+ settingsManager.updateSettings();
+
+ if (!getConfig().contains("settings.levels.Level-1")) {
+ getConfig().addDefault("settings.levels.Level-1.Radius", 1);
+ getConfig().addDefault("settings.levels.Level-1.Speed-Multiplier", 1);
+ getConfig().addDefault("settings.levels.Level-1.Cost-xp", 20);
+ getConfig().addDefault("settings.levels.Level-1.Cost-eco", 5000);
+
+ getConfig().addDefault("settings.levels.Level-2.Radius", 2);
+ getConfig().addDefault("settings.levels.Level-2.Speed-Multiplier", 1.5);
+ getConfig().addDefault("settings.levels.Level-2.Auto-Harvest", true);
+ getConfig().addDefault("settings.levels.Level-2.Cost-xp", 20);
+ getConfig().addDefault("settings.levels.Level-2.Cost-eco", 5000);
+
+ getConfig().addDefault("settings.levels.Level-3.Radius", 3);
+ getConfig().addDefault("settings.levels.Level-3.Speed-Multiplier", 1.5);
+ getConfig().addDefault("settings.levels.Level-3.Auto-Harvest", true);
+ getConfig().addDefault("settings.levels.Level-3.Auto-Replant", true);
+ getConfig().addDefault("settings.levels.Level-3.Cost-xp", 25);
+ getConfig().addDefault("settings.levels.Level-3.Cost-eco", 7500);
+
+ getConfig().addDefault("settings.levels.Level-4.Radius", 3);
+ getConfig().addDefault("settings.levels.Level-4.Speed-Multiplier", 2);
+ getConfig().addDefault("settings.levels.Level-4.Auto-Harvest", true);
+ getConfig().addDefault("settings.levels.Level-4.Auto-Replant", true);
+ getConfig().addDefault("settings.levels.Level-4.Cost-xp", 30);
+ getConfig().addDefault("settings.levels.Level-4.Cost-eco", 10000);
+
+ getConfig().addDefault("settings.levels.Level-5.Radius", 3);
+ getConfig().addDefault("settings.levels.Level-5.Speed-Multiplier", 2.5);
+ getConfig().addDefault("settings.levels.Level-5.Auto-Harvest", true);
+ getConfig().addDefault("settings.levels.Level-5.Auto-Replant", true);
+ getConfig().addDefault("settings.levels.Level-5.Cost-xp", 35);
+ getConfig().addDefault("settings.levels.Level-5.Cost-eco", 12000);
+
+ getConfig().addDefault("settings.levels.Level-6.Radius", 4);
+ getConfig().addDefault("settings.levels.Level-6.Speed-Multiplier", 3);
+ getConfig().addDefault("settings.levels.Level-6.Auto-Harvest", true);
+ getConfig().addDefault("settings.levels.Level-6.Auto-Replant", true);
+ getConfig().addDefault("settings.levels.Level-6.Cost-xp", 40);
+ getConfig().addDefault("settings.levels.Level-6.Cost-eco", 25000);
+ }
+
+ getConfig().options().copyDefaults(true);
+ saveConfig();
+ }
+
+ private void loadLanguageFile() {
+ Lang.setFile(langFile.getConfig());
+
+ for (final Lang value : Lang.values()) {
+ langFile.getConfig().addDefault(value.getPath(), value.getDefault());
+ }
+
+ langFile.getConfig().options().copyDefaults(true);
+ langFile.saveConfig();
+ }
+
+ private void loadDataFile() {
+ dataFile.getConfig().options().copyDefaults(true);
+ dataFile.saveConfig();
+ }
+
+ public static EpicFarming pl() {
+ return INSTANCE;
+ }
+
+ public static EpicFarming getInstance() {
+ return INSTANCE;
+ }
+
+ public FarmManager getFarmManager() {
+ return farmManager;
+ }
+
+ public LevelManager getLevelManager() {
+ return levelManager;
+ }
+
+ public FarmingHandler getFarmingHandler() {
+ return farmingHandler;
+ }
+
+ public PlayerActionManager getPlayerActionManager() {
+ return playerActionManager;
+ }
+
+ public GrowthHandler getGrowthHandler() {
+ return growthHandler;
+ }
+}
diff --git a/src/main/java/com/songoda/epicfarming/Lang.java b/src/main/java/com/songoda/epicfarming/Lang.java
new file mode 100644
index 0000000..838769f
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/Lang.java
@@ -0,0 +1,111 @@
+package com.songoda.epicfarming;
+
+import org.bukkit.ChatColor;
+import org.bukkit.configuration.file.FileConfiguration;
+
+public enum Lang {
+
+ PREFIX("prefix", "&8[&6EpicFarming&8]"),
+ NEXT("Next", "&9Next"),
+ BACK("Back", "&9Back"),
+
+ XPTITLE("Xp-upgrade-title", "&aUpgrade with XP"),
+ XPLORE("Xp-upgrade-lore", "&7Cost: &a{COST} Levels"),
+
+ ECOTITLE("Eco-upgrade-title", "&aUpgrade with ECO"),
+ ECOLORE("Eco-upgrade-lore", "&7Cost: &a${COST}"),
+
+ LEVEL("Level", "&6Farm Level &7{LEVEL}"),
+ NEXT_LEVEL("Next-Level", "&6Next Level &7{LEVEL}"),
+
+ NEXT_RADIUS("Next-Radius", "&7Radius: &6{RADIUS}"),
+ NEXT_SPEED("Next-Speed", "&7Speed: &6{SPEED}x"),
+ NEXT_AUTO_HARVEST("Next-Auto-Harvest", "&7Auto Harvest: &6{AUTOHARVEST}"),
+ NEXT_AUTO_REPLANT("Next-Auto-Replant", "&7Auto Replant: &6{AUTOREPLANT}"),
+
+ CANT_AFFORD("Cant-afford", "&cYou cannot afford this upgrade."),
+
+ UPGRADE_MESSAGE("Upgrade-message", "&7You successfully upgraded this farm to &6level {LEVEL}&7!"),
+
+ MAXED("Maxed", "&6This farm is maxed out."),
+
+ YOU_MAXED("You-Maxed", "&7You maxed out this farm at &6{NEW}x&7."),
+
+ NAME_FORMAT("Name-format", "&eLevel {LEVEL} &fFarm"),
+
+ NO_PERMS("No-perms", "&cYou do not have permission to do that.");
+
+ private String path;
+ private String def;
+ private static FileConfiguration LANG;
+
+ Lang(String path, String start) {
+ this.path = path;
+ this.def = start;
+ }
+
+ public static void setFile(final FileConfiguration config) {
+ LANG = config;
+ }
+
+ public String getDefault() {
+ return this.def;
+ }
+
+ public String getPath() {
+ return this.path;
+ }
+
+ public String getConfigValue() {
+ return getConfigValue(null, null, null);
+ }
+
+ public String getConfigValue(String arg) {
+ return getConfigValue(arg, null, null);
+ }
+
+ public String getConfigValue(int arg) {
+ return getConfigValue(Integer.toString(arg));
+ }
+
+ public String getConfigValue(double arg) {
+ return getConfigValue(Double.toString(arg));
+ }
+
+ public String getConfigValue(boolean arg) {
+ return getConfigValue(Boolean.toString(arg));
+ }
+
+ public String getConfigValue(String arg, String arg2, String arg3) {
+ String value = ChatColor.translateAlternateColorCodes('&', LANG.getString(this.path, this.def));
+
+ if (arg != null) {
+ value = value.replace("{COST}", arg);
+ value = value.replace("{GOAL}", arg);
+ value = value.replace("{NEW}", arg);
+ value = value.replace("{MAX}", arg);
+ value = value.replace("{AMT}", arg);
+ value = value.replace("{LEVEL}", arg);
+ value = value.replace("{NEWM}", arg);
+
+ value = value.replace("{RADIUS}", arg);
+ value = value.replace("{SPEED}", arg);
+ value = value.replace("{AUTOHARVEST}", arg);
+ value = value.replace("{AUTOREPLANT}", arg);
+
+ if (arg2 != null) {
+ value = value.replace("{TYPE}", arg2);
+ }
+ value = value.replace("{TYPE}", arg);
+ if (arg3 != null)
+ value = value.replace("{TIME}", arg3);
+ }
+
+ if (arg2 != null) {
+ value = value.replace("{COST}", arg2).replace("{GOAL}", arg2).replace("{NEW}", arg2).replace("{MAX}", arg2).replace("{AMT}", arg2)
+ .replace("{LEVEL}", arg2).replace("{TYPE}", arg2).replace("{NEWM}", arg2);
+ }
+
+ return value;
+ }
+}
diff --git a/src/main/java/com/songoda/epicfarming/References.java b/src/main/java/com/songoda/epicfarming/References.java
new file mode 100644
index 0000000..73c6415
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/References.java
@@ -0,0 +1,14 @@
+package com.songoda.epicfarming;
+
+public class References {
+
+ private String prefix;
+
+ public References() {
+ prefix = Lang.PREFIX.getConfigValue() + " ";
+ }
+
+ public String getPrefix() {
+ return this.prefix;
+ }
+}
diff --git a/src/main/java/com/songoda/epicfarming/events/BlockListeners.java b/src/main/java/com/songoda/epicfarming/events/BlockListeners.java
new file mode 100644
index 0000000..41a3950
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/events/BlockListeners.java
@@ -0,0 +1,130 @@
+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.utils.Debugger;
+import com.songoda.epicfarming.utils.Methods;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.block.Block;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
+import org.bukkit.event.block.BlockBreakEvent;
+import org.bukkit.event.block.BlockFadeEvent;
+import org.bukkit.event.block.BlockGrowEvent;
+import org.bukkit.event.block.BlockPlaceEvent;
+import org.bukkit.inventory.ItemStack;
+
+/**
+ * Created by songoda on 3/14/2017.
+ */
+public class BlockListeners implements Listener {
+
+ private EpicFarming instance;
+
+ public BlockListeners(EpicFarming instance) {
+ this.instance = instance;
+ }
+
+ @EventHandler
+ public void onBlockFade(BlockFadeEvent e) {
+ try {
+ if (checkForFarm(e.getBlock().getLocation())) {
+ e.setCancelled(true);
+ }
+
+ } catch (Exception ex) {
+ Debugger.runReport(ex);
+ }
+ }
+
+ @EventHandler
+ public void onGrow(BlockGrowEvent e) {
+ try {
+ if (checkForFarm(e.getNewState().getLocation())) {
+ e.setCancelled(true);
+ }
+ } catch (Exception ex) {
+ Debugger.runReport(ex);
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onBlockPlace(BlockPlaceEvent e) {
+ try {
+ if (e.getPlayer().getItemInHand().getType() != Material.END_ROD
+ || Methods.getLevelFromItem(e.getItemInHand()) == 0) return;
+
+ if (e.getBlockAgainst().getType() == Material.END_ROD) e.setCancelled(true);
+
+ Location location = e.getBlock().getLocation();
+
+ Farm farm = new Farm(location, instance.getLevelManager().getLevel(Methods.getLevelFromItem(e.getItemInHand())));
+ instance.getFarmManager().addFarm(location, farm);
+
+ farm.tillLand(e.getBlock().getLocation());
+
+ } catch (Exception ex) {
+ Debugger.runReport(ex);
+ }
+ }
+
+ private boolean checkForFarm(Location location) {
+
+ FarmManager farmManager = instance.getFarmManager();
+
+ Block block = location.getBlock();
+ for(Level level : instance.getLevelManager().getLevels().values()) {
+ int radius = level.getRadius();
+ int bx = block.getX();
+ int by = block.getY();
+ int bz = block.getZ();
+ for (int fx = -radius; fx <= radius; fx++) {
+ for (int fy = -2; fy <= 1; fy++) {
+ for (int fz = -radius; fz <= radius; fz++) {
+ Block b2 = block.getWorld().getBlockAt(bx + fx, by + fy, bz + fz);
+ if (b2.getType() == Material.END_ROD) {
+ if (!farmManager.getFarms().containsKey(b2.getLocation())) continue;
+ if (level.getRadius() != farmManager.getFarm(b2.getLocation()).getLevel().getRadius()) continue;
+ return true;
+ }
+
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST)
+ public void onBlockBreak(BlockBreakEvent event) {
+ try {
+ if (event.getBlock().getType() != Material.END_ROD) return;
+
+ Farm farm = instance.getFarmManager().removeFarm(event.getBlock().getLocation());
+
+ instance.getFarmingHandler().getCrops(farm, false);
+
+ if (farm == null) return;
+
+ event.setCancelled(true);
+
+ ItemStack item = Methods.makeFarmItem(farm.getLevel().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()) {
+ if (itemStack == null) continue;
+ farm.getLocation().getWorld().dropItemNaturally(farm.getLocation().add(.5,.5,.5), itemStack);
+ }
+ } catch (Exception ex) {
+ Debugger.runReport(ex);
+ }
+ }
+}
diff --git a/src/main/java/com/songoda/epicfarming/events/EntityListeners.java b/src/main/java/com/songoda/epicfarming/events/EntityListeners.java
new file mode 100644
index 0000000..2d8fdbe
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/events/EntityListeners.java
@@ -0,0 +1,27 @@
+package com.songoda.epicfarming.events;
+
+import com.songoda.epicfarming.utils.Debugger;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.entity.EntityDeathEvent;
+import org.bukkit.event.inventory.InventoryMoveItemEvent;
+
+public class EntityListeners implements Listener {
+
+ @EventHandler
+ public void onHop(InventoryMoveItemEvent e) {
+ try {
+
+ } catch (Exception ex) {
+ Debugger.runReport(ex);
+ }
+ }
+
+ @EventHandler
+ public void ondrop(EntityDeathEvent e) {
+ try {
+ } catch (Exception ex) {
+ Debugger.runReport(ex);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/songoda/epicfarming/events/InteractListeners.java b/src/main/java/com/songoda/epicfarming/events/InteractListeners.java
new file mode 100644
index 0000000..de9c991
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/events/InteractListeners.java
@@ -0,0 +1,39 @@
+package com.songoda.epicfarming.events;
+
+import com.songoda.epicfarming.EpicFarming;
+import com.songoda.epicfarming.utils.Debugger;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.block.Action;
+import org.bukkit.event.player.PlayerInteractEvent;
+
+/**
+ * Created by songoda on 3/14/2017.
+ */
+public class InteractListeners implements Listener {
+
+ private EpicFarming instance;
+
+ public InteractListeners(EpicFarming instance) {
+ this.instance = instance;
+ }
+
+ @EventHandler
+ public void onBlockInteract(PlayerInteractEvent e) {
+ try {
+ if (e.getClickedBlock() != null && e.getClickedBlock().getType() != Material.END_ROD) return;
+
+ if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
+
+ Location location = e.getClickedBlock().getLocation();
+
+ if (instance.getFarmManager().getFarms().containsKey(location)) {
+ instance.getFarmManager().getFarm(location).view(e.getPlayer());
+ }
+ } catch (Exception ex) {
+ Debugger.runReport(ex);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/songoda/epicfarming/events/InventoryListeners.java b/src/main/java/com/songoda/epicfarming/events/InventoryListeners.java
new file mode 100644
index 0000000..3b8418e
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/events/InventoryListeners.java
@@ -0,0 +1,70 @@
+package com.songoda.epicfarming.events;
+
+import com.songoda.epicfarming.EpicFarming;
+import com.songoda.epicfarming.farming.Farm;
+import com.songoda.epicfarming.player.PlayerData;
+import com.songoda.epicfarming.utils.Debugger;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.inventory.InventoryClickEvent;
+import org.bukkit.event.inventory.InventoryCloseEvent;
+import org.bukkit.event.inventory.InventoryType;
+
+/**
+ * Created by songoda on 3/14/2017.
+ */
+public class InventoryListeners implements Listener {
+
+ private EpicFarming instance;
+
+ public InventoryListeners(EpicFarming instance) {
+ this.instance = instance;
+ }
+
+ @EventHandler
+ public void onInventoryClick(InventoryClickEvent event) {
+ try {
+ if (instance.getPlayerActionManager().getPlayerAction((Player)event.getWhoClicked()).getFarm() == null
+ || event.getInventory() == null) return;
+
+
+ if (event.getInventory().getType() != InventoryType.CHEST) return;
+
+ PlayerData playerData = instance.getPlayerActionManager().getPlayerAction((Player)event.getWhoClicked());
+ Farm farm = playerData.getFarm();
+ if (event.getSlot() <= 26) {
+ event.setCancelled(true);
+ }
+
+ Player player = (Player)event.getWhoClicked();
+
+ if (event.getSlot() == 11 && player.hasPermission("EpicFarming.Upgrade.XP")) {
+ if (!event.getCurrentItem().getItemMeta().getDisplayName().equals("§l")) {
+ farm.upgrade("XP", player);
+ player.closeInventory();
+ }
+ } else if (event.getSlot() == 15 && player.hasPermission("EpicFarming.Upgrade.ECO")) {
+ if (!event.getCurrentItem().getItemMeta().getDisplayName().equals("§l")) {
+ farm.upgrade("ECO", player);
+ player.closeInventory();
+ }
+ }
+
+ } catch (Exception ex) {
+ Debugger.runReport(ex);
+ }
+ }
+
+ @EventHandler
+ public void onClose(InventoryCloseEvent event) {
+ try {
+ if (instance.getPlayerActionManager().getRegisteredPlayers().size() == 0
+ || instance.getPlayerActionManager().getPlayerAction((Player)event.getPlayer()).getFarm() != null) return;
+
+ instance.getPlayerActionManager().getPlayerAction((Player)event.getPlayer()).setFarm(null);
+ } catch (Exception ex) {
+ Debugger.runReport(ex);
+ }
+ }
+}
diff --git a/src/main/java/com/songoda/epicfarming/farming/Crop.java b/src/main/java/com/songoda/epicfarming/farming/Crop.java
new file mode 100644
index 0000000..73218f2
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/farming/Crop.java
@@ -0,0 +1,32 @@
+package com.songoda.epicfarming.farming;
+
+import org.bukkit.Location;
+
+public class Crop {
+
+ private Location location;
+
+ private int ticksLived = 1;
+ private Farm farm;
+
+ public Crop(Location location, Farm farm) {
+ this.location = location;
+ this.farm = farm;
+ }
+
+ public int getTicksLived() {
+ return ticksLived;
+ }
+
+ public void setTicksLived(int ticksLived) {
+ this.ticksLived = ticksLived;
+ }
+
+ public Farm getFarm() {
+ return farm;
+ }
+
+ public Location getLocation() {
+ return location;
+ }
+}
diff --git a/src/main/java/com/songoda/epicfarming/farming/Farm.java b/src/main/java/com/songoda/epicfarming/farming/Farm.java
new file mode 100644
index 0000000..aa1e425
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/farming/Farm.java
@@ -0,0 +1,296 @@
+package com.songoda.epicfarming.farming;
+
+
+import com.songoda.arconix.plugin.Arconix;
+import com.songoda.epicfarming.EpicFarming;
+import com.songoda.epicfarming.Lang;
+import com.songoda.epicfarming.player.PlayerData;
+import com.songoda.epicfarming.utils.Debugger;
+import com.songoda.epicfarming.utils.Methods;
+import net.milkbowl.vault.economy.Economy;
+import org.bukkit.Bukkit;
+import org.bukkit.GameMode;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.block.Block;
+import org.bukkit.block.BlockFace;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.Inventory;
+import org.bukkit.inventory.InventoryHolder;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+import org.bukkit.plugin.RegisteredServiceProvider;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
+public class Farm implements InventoryHolder {
+
+ private Location location;
+ private Level level;
+ private Inventory inventory;
+
+ public Farm(Location location, Level level) {
+ this.location = location;
+ this.level = level;
+ this.inventory = Bukkit.createInventory(null, 54, Methods.formatName(level.getLevel(),false));
+ }
+
+ public void view(Player player) {
+ try {
+ if (!player.hasPermission("epicfarming.view"))
+ return;
+
+ setupOverview(player);
+
+ player.openInventory(inventory);
+ PlayerData playerData = EpicFarming.getInstance().getPlayerActionManager().getPlayerAction(player);
+
+ playerData.setFarm(this);
+
+ getInventory();
+
+ } catch (Exception ex) {
+ Debugger.runReport(ex);
+ }
+ }
+
+ public void setupOverview(Player player) {
+ Inventory inventory = Bukkit.createInventory(null, 54, Methods.formatName(level.getLevel(),false));
+ inventory.setContents(this.inventory.getContents());
+ this.inventory = inventory;
+
+ EpicFarming instance = EpicFarming.getInstance();
+
+ Level nextLevel = instance.getLevelManager().getHighestLevel().getLevel() > level.getLevel() ? instance.getLevelManager().getLevel(level.getLevel()+1) : null;
+
+ int level = this.level.getLevel();
+
+ ItemStack item = new ItemStack(Material.END_ROD, 1);
+ ItemMeta itemmeta = item.getItemMeta();
+ itemmeta.setDisplayName(Arconix.pl().getApi().format().formatText(Lang.LEVEL.getConfigValue(level)));
+ ArrayList lore = this.level.getDescription();
+ lore.add("");
+ if (nextLevel == null) lore.add(Lang.MAXED.getConfigValue());
+ else {
+ lore.add(Lang.NEXT_LEVEL.getConfigValue(nextLevel.getLevel()));
+ lore.addAll(nextLevel.getDescription());
+ }
+
+ itemmeta.setLore(lore);
+ item.setItemMeta(itemmeta);
+
+ ItemStack itemXP = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.XP Icon")), 1);
+ ItemMeta itemmetaXP = itemXP.getItemMeta();
+ itemmetaXP.setDisplayName(Lang.XPTITLE.getConfigValue());
+ ArrayList loreXP = new ArrayList<>();
+ if (nextLevel != null)
+ loreXP.add(Lang.XPLORE.getConfigValue(Integer.toString(nextLevel.getCostExperiance())));
+ else
+ loreXP.add(Lang.MAXED.getConfigValue());
+ itemmetaXP.setLore(loreXP);
+ itemXP.setItemMeta(itemmetaXP);
+
+ ItemStack itemECO = new ItemStack(Material.valueOf(instance.getConfig().getString("Interfaces.Economy Icon")), 1);
+ ItemMeta itemmetaECO = itemECO.getItemMeta();
+ itemmetaECO.setDisplayName(Lang.ECOTITLE.getConfigValue());
+ ArrayList loreECO = new ArrayList<>();
+ if (nextLevel != null)
+ loreECO.add(Lang.ECOLORE.getConfigValue(Arconix.pl().getApi().format().formatEconomy(nextLevel.getCostExperiance())));
+ else
+ loreECO.add(Lang.MAXED.getConfigValue());
+ itemmetaECO.setLore(loreECO);
+ itemECO.setItemMeta(itemmetaECO);
+
+ int nu = 0;
+ while (nu != 27) {
+ inventory.setItem(nu, Methods.getGlass());
+ nu++;
+ }
+ if (instance.getConfig().getBoolean("Main.Upgrade With XP") && player != null && player.hasPermission("EpicDispensers.Upgrade.XP")) {
+ inventory.setItem(11, itemXP);
+ }
+
+ inventory.setItem(13, item);
+
+ if (instance.getConfig().getBoolean("Main.Upgrade With Economy") && player != null && player.hasPermission("EpicDispensers.Upgrade.ECO")) {
+ inventory.setItem(15, itemECO);
+ }
+
+ inventory.setItem(0, Methods.getBackgroundGlass(true));
+ inventory.setItem(1, Methods.getBackgroundGlass(true));
+ inventory.setItem(2, Methods.getBackgroundGlass(false));
+ inventory.setItem(6, Methods.getBackgroundGlass(false));
+ inventory.setItem(7, Methods.getBackgroundGlass(true));
+ inventory.setItem(8, Methods.getBackgroundGlass(true));
+ inventory.setItem(9, Methods.getBackgroundGlass(true));
+ inventory.setItem(10, Methods.getBackgroundGlass(false));
+ inventory.setItem(16, Methods.getBackgroundGlass(false));
+ inventory.setItem(17, Methods.getBackgroundGlass(true));
+ inventory.setItem(18, Methods.getBackgroundGlass(true));
+ inventory.setItem(19, Methods.getBackgroundGlass(true));
+ inventory.setItem(20, Methods.getBackgroundGlass(false));
+ inventory.setItem(24, Methods.getBackgroundGlass(false));
+ inventory.setItem(25, Methods.getBackgroundGlass(true));
+ inventory.setItem(26, Methods.getBackgroundGlass(true));
+ }
+
+ @Override
+ public Inventory getInventory() {
+ return inventory;
+ }
+
+ public void loadInventory(List items) {
+ setupOverview(null);
+ int i = 27;
+ for (ItemStack item : items) {
+ inventory.setItem(i++, item);
+ }
+ }
+
+ public List dumpInventory() {
+ List items = new ArrayList<>();
+
+ for(int i=27; i < inventory.getSize(); i++) {
+ items.add(inventory.getItem(i));
+ }
+
+ return items;
+ }
+
+ public void upgrade(String type, Player player) {
+ try {
+ EpicFarming instance = EpicFarming.getInstance();
+ if (instance.getLevelManager().getLevels().containsKey(this.level.getLevel()+1)) {
+
+ Level level = instance.getLevelManager().getLevel(this.level.getLevel()+1);
+ int cost;
+ if (type == "XP") {
+ cost = level.getCostExperiance();
+ } else {
+ cost = level.getCostEconomy();
+ }
+
+ if (type == "ECO") {
+ if (instance.getServer().getPluginManager().getPlugin("Vault") != null) {
+ RegisteredServiceProvider rsp = instance.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
+ net.milkbowl.vault.economy.Economy econ = rsp.getProvider();
+ if (econ.has(player, cost)) {
+ econ.withdrawPlayer(player, cost);
+ upgradeFinal(level, player);
+ } else {
+ player.sendMessage(instance.references.getPrefix() + Lang.CANT_AFFORD.getConfigValue(null));
+ }
+ } else {
+ player.sendMessage("Vault is not installed.");
+ }
+ } else if (type == "XP") {
+ if (player.getLevel() >= cost || player.getGameMode() == GameMode.CREATIVE) {
+ if (player.getGameMode() != GameMode.CREATIVE) {
+ player.setLevel(player.getLevel() - cost);
+ }
+ upgradeFinal(level, player);
+ } else {
+ player.sendMessage(instance.references.getPrefix() + Lang.CANT_AFFORD.getConfigValue(null));
+ }
+ }
+ }
+ } catch (Exception ex) {
+ Debugger.runReport(ex);
+ }
+ }
+
+
+ public void upgradeFinal(Level level, Player player) {
+ try {
+ EpicFarming instance = EpicFarming.getInstance();
+ this.level = level;
+ if (instance.getLevelManager().getHighestLevel() != level) {
+ player.sendMessage(Lang.UPGRADE_MESSAGE.getConfigValue(level.getLevel()));
+ } else {
+ player.sendMessage(Lang.YOU_MAXED.getConfigValue(Integer.toString(level.getLevel())));
+ }
+ if (instance.getConfig().getBoolean("settings.On-upgrade-particles")) {
+ Location loc = location.clone().add(.5,.5,.5);
+ if (!instance.v1_8 && !instance.v1_7) {
+ player.getWorld().spawnParticle(org.bukkit.Particle.valueOf(instance.getConfig().getString("Main.Upgrade Particle Type")), loc, 200, .5, .5, .5);
+ } else {
+ player.getWorld().playEffect(loc, org.bukkit.Effect.valueOf(instance.getConfig().getString("Main.Upgrade Particle Type")), 1, 0);
+ //Can't get that to resolve.
+ //player.getWorld().spigot().playEffect(loc, org.bukkit.Effect.valueOf(instance.getConfig().getString("Main.Upgrade Particle Type")), 1, 0, (float) 1, (float) 1, (float) 1, 1, 200, 10);
+ }
+ }
+ if (instance.getConfig().getBoolean("Main.Sounds Enabled")) {
+ if (instance.getLevelManager().getHighestLevel() == level) {
+ if (!instance.v1_8 && !instance.v1_7) {
+ player.playSound(player.getLocation(), org.bukkit.Sound.ENTITY_PLAYER_LEVELUP, 0.6F, 15.0F);
+ } else {
+ player.playSound(player.getLocation(), org.bukkit.Sound.valueOf("LEVEL_UP"), 2F, 15.0F);
+ }
+ } else {
+ if (!instance.v1_10 && !instance.v1_9 && !instance.v1_8 && !instance.v1_7) {
+ player.playSound(player.getLocation(), org.bukkit.Sound.ENTITY_PLAYER_LEVELUP, 2F, 25.0F);
+ player.playSound(player.getLocation(), org.bukkit.Sound.BLOCK_NOTE_CHIME, 2F, 25.0F);
+ Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> player.playSound(player.getLocation(), org.bukkit.Sound.BLOCK_NOTE_CHIME, 1.2F, 35.0F), 5L);
+ Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> player.playSound(player.getLocation(), org.bukkit.Sound.BLOCK_NOTE_CHIME, 1.8F, 35.0F), 10L);
+ } else {
+ player.playSound(player.getLocation(), org.bukkit.Sound.valueOf("LEVEL_UP"), 2F, 25.0F);
+ }
+ }
+ }
+ tillLand(location);
+ } catch (Exception ex) {
+ Debugger.runReport(ex);
+ }
+ }
+
+ private static final Random random = new Random();
+
+ public boolean tillLand(Location location) {
+ EpicFarming instance = EpicFarming.getInstance();
+ Block block = location.getBlock();
+ int radius = level.getRadius();
+ int bx = block.getX();
+ int by = block.getY();
+ int bz = block.getZ();
+ for (int fx = -radius; fx <= radius; fx++) {
+ for (int fy = -2; fy <= 1; fy++) {
+ for (int fz = -radius; fz <= radius; fz++) {
+ Block b2 = block.getWorld().getBlockAt(bx + fx, by + fy, bz + fz);
+
+ // ToDo: enum for all flowers.
+ if (b2.getType() == Material.LONG_GRASS || b2.getType() == Material.RED_ROSE || b2.getType() == Material.YELLOW_FLOWER) {
+ Bukkit.getScheduler().runTaskLater(EpicFarming.getInstance(), () -> {
+ b2.getRelative(BlockFace.DOWN).setType(Material.SOIL);
+ b2.breakNaturally();
+ if (instance.getConfig().getBoolean("Main.Sounds Enabled"))
+ b2.getWorld().playSound(b2.getLocation(), org.bukkit.Sound.BLOCK_GRASS_BREAK, 10, 15);
+ }, random.nextInt(30) + 1);
+ }
+ if ((b2.getType() == Material.GRASS || b2.getType() == Material.DIRT) && b2.getRelative(BlockFace.UP).getType() == Material.AIR) {
+ Bukkit.getScheduler().runTaskLater(EpicFarming.getInstance(), () -> {
+ b2.setType(Material.SOIL);
+ if (instance.getConfig().getBoolean("Main.Sounds Enabled"))
+ b2.getWorld().playSound(b2.getLocation(), org.bukkit.Sound.BLOCK_GRASS_BREAK, 10, 15);
+ }, random.nextInt(30) + 1);
+ }
+
+ }
+ }
+ }
+ return false;
+ }
+
+ public Location getLocation() {
+ return location.clone();
+ }
+
+ public void setLocation(Location location) {
+ this.location = location;
+ }
+
+ public Level getLevel() {
+ return level;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/songoda/epicfarming/farming/FarmManager.java b/src/main/java/com/songoda/epicfarming/farming/FarmManager.java
new file mode 100644
index 0000000..b60817f
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/farming/FarmManager.java
@@ -0,0 +1,36 @@
+package com.songoda.epicfarming.farming;
+
+import org.bukkit.Location;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+public class FarmManager {
+
+ private final Map registeredFarms = new HashMap<>();
+
+ public void addFarm(Location location, Farm farm) {
+ registeredFarms.put(roundLocation(location), farm);
+ }
+
+ public Farm removeFarm(Location location) {
+ return registeredFarms.remove(roundLocation(location));
+ }
+
+ public Farm getFarm(Location location) {
+ return registeredFarms.get(roundLocation(location));
+ }
+
+ public Map getFarms() {
+ return Collections.unmodifiableMap(registeredFarms);
+ }
+
+ private Location roundLocation(Location location) {
+ location = location.clone();
+ location.setX(location.getBlockX());
+ location.setY(location.getBlockY());
+ location.setZ(location.getBlockZ());
+ return location;
+ }
+}
diff --git a/src/main/java/com/songoda/epicfarming/farming/Level.java b/src/main/java/com/songoda/epicfarming/farming/Level.java
new file mode 100644
index 0000000..9ca6a3a
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/farming/Level.java
@@ -0,0 +1,68 @@
+package com.songoda.epicfarming.farming;
+
+import com.songoda.epicfarming.Lang;
+
+import java.util.ArrayList;
+
+public class Level {
+
+ private int level, costExperiance, costEconomy, radius;
+
+ private double speedMultiplier;
+
+ private boolean autoHarvest, autoReplant;
+
+ private ArrayList description = new ArrayList<>();
+
+ public Level(int level, int costExperiance, int costEconomy, double speedMultiplier, int radius, boolean autoHarvest, boolean autoReplant) {
+ this.level = level;
+ this.costExperiance = costExperiance;
+ this.costEconomy = costEconomy;
+ this.speedMultiplier = speedMultiplier;
+ this.radius = radius;
+ this.autoHarvest = autoHarvest;
+ this.autoReplant = autoReplant;
+
+ description.add(Lang.NEXT_RADIUS.getConfigValue(radius));
+ description.add(Lang.NEXT_SPEED.getConfigValue(speedMultiplier));
+
+ if (autoHarvest)
+ description.add(Lang.NEXT_AUTO_HARVEST.getConfigValue(autoHarvest));
+
+ if (autoReplant)
+ description.add(Lang.NEXT_AUTO_REPLANT.getConfigValue(autoReplant));
+
+ }
+
+ public ArrayList getDescription() {
+ return (ArrayList)description.clone();
+ }
+
+ public int getLevel() {
+ return level;
+ }
+
+ public int getRadius() {
+ return radius;
+ }
+
+ public boolean isAutoHarvest() {
+ return autoHarvest;
+ }
+
+ public boolean isAutoReplant() {
+ return autoReplant;
+ }
+
+ public double getSpeedMultiplier() {
+ return speedMultiplier;
+ }
+
+ public int getCostExperiance() {
+ return costExperiance;
+ }
+
+ public int getCostEconomy() {
+ return costEconomy;
+ }
+}
diff --git a/src/main/java/com/songoda/epicfarming/farming/LevelManager.java b/src/main/java/com/songoda/epicfarming/farming/LevelManager.java
new file mode 100644
index 0000000..ad54b79
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/farming/LevelManager.java
@@ -0,0 +1,30 @@
+package com.songoda.epicfarming.farming;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.NavigableMap;
+import java.util.TreeMap;
+
+public class LevelManager {
+
+ private final NavigableMap registeredLevels = new TreeMap<>();
+
+ 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));
+ }
+
+ public Level getLevel(int level) {
+ return registeredLevels.get(level);
+ }
+
+ public Level getLowestLevel() {
+ return registeredLevels.firstEntry().getValue();
+ }
+
+ public Level getHighestLevel() {
+ return registeredLevels.lastEntry().getValue();
+ }
+ public Map getLevels() {
+ return Collections.unmodifiableMap(registeredLevels);
+ }
+}
diff --git a/src/main/java/com/songoda/epicfarming/handlers/CommandHandler.java b/src/main/java/com/songoda/epicfarming/handlers/CommandHandler.java
new file mode 100644
index 0000000..2f2cc12
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/handlers/CommandHandler.java
@@ -0,0 +1,74 @@
+package com.songoda.epicfarming.handlers;
+
+import com.songoda.arconix.plugin.Arconix;
+import com.songoda.epicfarming.EpicFarming;
+import com.songoda.epicfarming.Lang;
+import com.songoda.epicfarming.utils.Debugger;
+import com.songoda.epicfarming.utils.Methods;
+import org.bukkit.Bukkit;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+/**
+ * Created by songoda on 3/14/2017.
+ */
+
+public class CommandHandler implements CommandExecutor {
+
+ private EpicFarming instance;
+
+ public CommandHandler(EpicFarming instance) {
+ this.instance = instance;
+ }
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
+ try {
+ if (args.length == 0 || args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("?")) {
+ sender.sendMessage("");
+ sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&7" + instance.getDescription().getVersion() + " Created by &5&l&oBrianna"));
+ sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- &aEFA help &7Displays this page."));
+ sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- &aEFA settings &7Edit the EpicFarming Settings."));
+ sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- &aEFA reload &7Reloads Configuration and Language files."));
+ sender.sendMessage(Arconix.pl().getApi().format().formatText(" &8- &aEFA givefarmitem [player] &7Give a farm item to a player."));
+ sender.sendMessage("");
+ } else if (args[0].equalsIgnoreCase("reload")) {
+ if (!sender.hasPermission("epicfarming.admin")) {
+ sender.sendMessage(instance.references.getPrefix() + Lang.NO_PERMS.getConfigValue());
+ } else {
+ instance.reload();
+ sender.sendMessage(Arconix.pl().getApi().format().formatText(instance.references.getPrefix() + "&8Configuration and Language files reloaded."));
+ }
+ } else if (args[0].equalsIgnoreCase("givefarmitem")) {
+ if (!sender.hasPermission("epicfarming.admin")) {
+ sender.sendMessage(instance.references.getPrefix() + Lang.NO_PERMS.getConfigValue());
+ return true;
+ }
+ //ToDo: add the ability to specify level.
+ if (args.length == 1) {
+ if (sender instanceof Player)
+ ((Player) sender).getInventory().addItem(Methods.makeFarmItem(1));
+ } else if (Bukkit.getPlayerExact(args[1]) == null) {
+ sender.sendMessage(instance.references.getPrefix() + Arconix.pl().getApi().format().formatText("&cThat username does not exist, or the user is not online!"));
+ } else {
+ Bukkit.getPlayerExact(args[1]).getInventory().addItem(Methods.makeFarmItem(1));
+ }
+ } else if (sender instanceof Player) {
+ if (args[0].equalsIgnoreCase("settings")) {
+ if (!sender.hasPermission("epicfarming.admin")) {
+ sender.sendMessage(instance.references.getPrefix() + Lang.NO_PERMS.getConfigValue());
+ } else {
+ Player p = (Player) sender;
+ instance.settingsManager.openSettingsManager(p);
+ }
+ }
+ }
+
+ } catch (Exception ex) {
+ Debugger.runReport(ex);
+ }
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/songoda/epicfarming/handlers/FarmingHandler.java b/src/main/java/com/songoda/epicfarming/handlers/FarmingHandler.java
new file mode 100644
index 0000000..6f53b5a
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/handlers/FarmingHandler.java
@@ -0,0 +1,113 @@
+package com.songoda.epicfarming.handlers;
+
+import com.songoda.epicfarming.EpicFarming;
+import com.songoda.epicfarming.farming.Crop;
+import com.songoda.epicfarming.farming.Farm;
+import com.songoda.epicfarming.utils.CropType;
+import com.songoda.epicfarming.utils.Debugger;
+import org.bukkit.Bukkit;
+import org.bukkit.CropState;
+import org.bukkit.Material;
+import org.bukkit.block.Block;
+import org.bukkit.block.BlockState;
+import org.bukkit.inventory.Inventory;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.material.Crops;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
+public class FarmingHandler {
+
+ private EpicFarming instance;
+
+ public FarmingHandler(EpicFarming instance) {
+ this.instance = instance;
+ Bukkit.getScheduler().scheduleSyncRepeatingTask(EpicFarming.getInstance(), this::farmRunner, 0, instance.getConfig().getInt("Main.Farm Tick Speed"));
+ }
+
+
+ private void farmRunner() {
+ try {
+ for (Farm farm : instance.getFarmManager().getFarms().values()) {
+ for (Block block : getCrops(farm, true)) {
+ Crops crop = (Crops) block.getState().getData();
+
+ // Add to GrowthHandler
+ if (!instance.getGrowthHandler().liveCrops.containsKey(block.getLocation()))
+ instance.getGrowthHandler().liveCrops.put(block.getLocation(), new Crop(block.getLocation(), farm));
+
+ if (!farm.getLevel().isAutoHarvest()
+ || !crop.getState().equals(CropState.RIPE)
+ || !doDrop(farm, block.getType())) continue;
+
+ if (farm.getLevel().isAutoReplant()) {
+ BlockState cropState = block.getState();
+ Crops cropData = (Crops) cropState.getData();
+ cropData.setState(CropState.VERY_SMALL);
+ cropState.setData(cropData);
+ cropState.update();
+ continue;
+ }
+ block.setType(Material.AIR);
+ }
+ }
+ } catch (Exception ex) {
+ Debugger.runReport(ex);
+ }
+ }
+
+ private boolean doDrop(Farm farm, Material material) {
+ Random random = new Random();
+
+ ItemStack stack = new ItemStack(CropType.getCropType(material).getYieldMaterial());
+ ItemStack seedStack = new ItemStack(CropType.getCropType(material).getSeedMaterial(), random.nextInt(3));
+
+ if (!canMove(farm.getInventory(), stack)) return false;
+ farm.getInventory().addItem(stack);
+ farm.getInventory().addItem(seedStack);
+ return true;
+ }
+
+ public List getCrops(Farm farm, boolean add) {
+ List crops = new ArrayList<>();
+
+ Block block = farm.getLocation().getBlock();
+ int radius = farm.getLevel().getRadius();
+ int bx = block.getX();
+ int by = block.getY();
+ int bz = block.getZ();
+ for (int fx = -radius; fx <= radius; fx++) {
+ for (int fy = -2; fy <= 1; fy++) {
+ for (int fz = -radius; fz <= radius; fz++) {
+ Block b2 = block.getWorld().getBlockAt(bx + fx, by + fy, bz + fz);
+
+ if (!(b2.getState().getData() instanceof Crops)) continue;
+ if (add)
+ crops.add(b2);
+ else {
+ instance.getGrowthHandler().liveCrops.remove(b2.getLocation());
+ }
+
+ }
+ }
+ }
+ return crops;
+ }
+
+ private boolean canMove(Inventory inventory, ItemStack item) {
+ try {
+ if (inventory.firstEmpty() != -1) return true;
+
+ for (ItemStack stack : inventory.getContents()) {
+ if (stack.isSimilar(item) && stack.getAmount() <= stack.getMaxStackSize()) {
+ return true;
+ }
+ }
+ } catch (Exception e) {
+ Debugger.runReport(e);
+ }
+ return false;
+ }
+}
diff --git a/src/main/java/com/songoda/epicfarming/handlers/GrowthHandler.java b/src/main/java/com/songoda/epicfarming/handlers/GrowthHandler.java
new file mode 100644
index 0000000..0c45671
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/handlers/GrowthHandler.java
@@ -0,0 +1,80 @@
+package com.songoda.epicfarming.handlers;
+
+import com.songoda.epicfarming.EpicFarming;
+import com.songoda.epicfarming.farming.Crop;
+import org.bukkit.Bukkit;
+import org.bukkit.CropState;
+import org.bukkit.Location;
+import org.bukkit.block.BlockState;
+import org.bukkit.material.Crops;
+
+import java.util.HashMap;
+import java.util.Map;
+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"));
+ }
+
+ Map liveCrops = new HashMap<>();
+
+ private static final Random random = new Random();
+
+ private void growthRunner() {
+
+ for (Crop crop : liveCrops.values()) {
+
+ if (!(crop.getLocation().getBlock().getState().getData() instanceof Crops)) continue;
+
+ //ToDO: This should be in config.
+ int cap = (int)Math.ceil(60 / crop.getFarm().getLevel().getSpeedMultiplier()) - crop.getTicksLived();
+ if (cap > 2) {
+ int rand = random.nextInt(cap) + 1;
+
+ crop.setTicksLived(crop.getTicksLived() + 1);
+ if (rand != cap - 1 && crop.getTicksLived() != cap / 2) continue;
+
+ }
+
+ BlockState cropState = crop.getLocation().getBlock().getState();
+ Crops cropData = (Crops) cropState.getData();
+
+ switch(cropData.getState()) {
+ case SEEDED:
+ cropData.setState(CropState.GERMINATED);
+ break;
+ case GERMINATED:
+ cropData.setState(CropState.VERY_SMALL);
+ break;
+ case VERY_SMALL:
+ cropData.setState(CropState.SMALL);
+ break;
+ case SMALL:
+ cropData.setState(CropState.MEDIUM);
+ break;
+ case MEDIUM:
+ cropData.setState(CropState.TALL);
+ break;
+ case TALL:
+ cropData.setState(CropState.VERY_TALL);
+ break;
+ case VERY_TALL:
+ cropData.setState(CropState.RIPE);
+ break;
+ case RIPE:
+ break;
+ }
+ cropState.setData(cropData);
+ cropState.update();
+ crop.setTicksLived(1);
+
+ }
+ }
+
+ private void clear() {
+ liveCrops.clear();
+ }
+}
diff --git a/src/main/java/com/songoda/epicfarming/handlers/HookHandler.java b/src/main/java/com/songoda/epicfarming/handlers/HookHandler.java
new file mode 100644
index 0000000..e229fd7
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/handlers/HookHandler.java
@@ -0,0 +1,114 @@
+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
new file mode 100644
index 0000000..d7738b9
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/hooks/ASkyBlockHook.java
@@ -0,0 +1,64 @@
+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
new file mode 100644
index 0000000..70cb89c
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/hooks/FactionsHook.java
@@ -0,0 +1,56 @@
+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
new file mode 100644
index 0000000..c863696
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/hooks/GriefPreventionHook.java
@@ -0,0 +1,38 @@
+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
new file mode 100644
index 0000000..db95f14
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/hooks/Hook.java
@@ -0,0 +1,40 @@
+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
new file mode 100644
index 0000000..f531293
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/hooks/KingdomsHook.java
@@ -0,0 +1,43 @@
+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
new file mode 100644
index 0000000..9b1a8dc
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/hooks/PlotSquaredHook.java
@@ -0,0 +1,38 @@
+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
new file mode 100644
index 0000000..3eccffb
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/hooks/RedProtectHook.java
@@ -0,0 +1,34 @@
+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
new file mode 100644
index 0000000..bd0b584
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/hooks/TownyHook.java
@@ -0,0 +1,56 @@
+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
new file mode 100644
index 0000000..09c34ef
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/hooks/USkyBlockHook.java
@@ -0,0 +1,49 @@
+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
new file mode 100644
index 0000000..814cf64
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/hooks/WorldGuardHook.java
@@ -0,0 +1,31 @@
+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;
+ }
+}
diff --git a/src/main/java/com/songoda/epicfarming/player/PlayerActionManager.java b/src/main/java/com/songoda/epicfarming/player/PlayerActionManager.java
new file mode 100644
index 0000000..fb6138e
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/player/PlayerActionManager.java
@@ -0,0 +1,18 @@
+package com.songoda.epicfarming.player;
+
+import org.bukkit.entity.Player;
+
+import java.util.*;
+
+public class PlayerActionManager {
+
+ private final Map registeredPlayers = new HashMap<>();
+
+ public PlayerData getPlayerAction(Player player) {
+ return (player != null) ? registeredPlayers.computeIfAbsent(player.getUniqueId(), p -> new PlayerData(player.getUniqueId())) : null;
+ }
+
+ public Collection getRegisteredPlayers() {
+ return Collections.unmodifiableCollection(registeredPlayers.values());
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/songoda/epicfarming/player/PlayerData.java b/src/main/java/com/songoda/epicfarming/player/PlayerData.java
new file mode 100644
index 0000000..cfd827c
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/player/PlayerData.java
@@ -0,0 +1,29 @@
+package com.songoda.epicfarming.player;
+
+import com.songoda.epicfarming.farming.Farm;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+
+import java.util.UUID;
+
+public class PlayerData {
+
+ private final UUID playerUUID;
+ private Farm farm = null;
+
+ public PlayerData(UUID playerUUID) {
+ this.playerUUID = playerUUID;
+ }
+
+ public Farm getFarm() {
+ return farm;
+ }
+
+ public void setFarm(Farm farm) {
+ this.farm = farm;
+ }
+
+ public Player getPlayer() {
+ return Bukkit.getPlayer(playerUUID);
+ }
+}
diff --git a/src/main/java/com/songoda/epicfarming/utils/CropType.java b/src/main/java/com/songoda/epicfarming/utils/CropType.java
new file mode 100644
index 0000000..0ad890c
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/utils/CropType.java
@@ -0,0 +1,107 @@
+package com.songoda.epicfarming.utils;
+
+import org.bukkit.Material;
+
+/**
+ * A list of all crop types available in Minecraft that can be
+ * modified by CropsReborn
+ */
+public enum CropType {
+
+ WHEAT("Wheat", Material.CROPS, Material.WHEAT, Material.SEEDS),
+
+ CARROT("Carrot", Material.CARROT, Material.CARROT_ITEM, Material.CARROT_ITEM),
+
+ POTATO("Potato", Material.POTATO, Material.CARROT_ITEM, Material.POTATO_ITEM),
+
+ BEETROOT("Beetroot", Material.BEETROOT_BLOCK, Material.BEETROOT, Material.BEETROOT_SEEDS),
+
+ WATER_MELON_STEM("Watermelon", Material.MELON_STEM, Material.MELON, Material.MELON_SEEDS),
+
+ PUMPKIN_STEM("Pumpkin", Material.PUMPKIN_STEM, Material.PUMPKIN, Material.PUMPKIN_SEEDS),
+
+ NETHER_WARTS("Nether Wart", Material.NETHER_WART_BLOCK, Material.NETHER_WARTS, Material.NETHER_WARTS);
+
+ private final String name;
+ private final Material yieldMaterial, blockMaterial, seedMaterial;
+
+ CropType(String name, Material blockMaterial, Material yieldMaterial, Material seedMaterial) {
+ this.name = name;
+ this.blockMaterial = blockMaterial;
+ this.seedMaterial = seedMaterial;
+ this.yieldMaterial = yieldMaterial;
+ }
+
+ /**
+ * Get the friendly name of the crop
+ *
+ * @return the name of the crop
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Get the blockMaterial that represents this crop type
+ *
+ * @return the represented blockMaterial
+ */
+ public Material getBlockMaterial() {
+ return blockMaterial;
+ }
+
+ /**
+ * Get the yield Material that represents this crop type
+ *
+ * @return the represented yieldMaterial
+ */
+ public Material getYieldMaterial() {
+ return yieldMaterial;
+ }
+
+ /**
+ * Get the blockMaterial that represents the seed item for this crop type
+ *
+ * @return the represented seed blockMaterial
+ */
+ public Material getSeedMaterial() {
+ return seedMaterial;
+ }
+
+ /**
+ * Check whether a specific blockMaterial is an enumerated crop type or not
+ *
+ * @param material the blockMaterial to check
+ * @return true if it is a crop, false otherwise
+ */
+ public static boolean isCrop(Material material) {
+ for (CropType type : values())
+ if (type.getBlockMaterial() == material) return true;
+ return false;
+ }
+
+ /**
+ * Check whether a specific blockMaterial is an enumerated crop type seed or not
+ *
+ * @param material the blockMaterial to check
+ * @return true if it is a seed, false otherwise
+ */
+ public static boolean isCropSeed(Material material) {
+ for (CropType type : values())
+ if (type.getSeedMaterial() == material) return true;
+ return false;
+ }
+
+ /**
+ * Get the crop type based on the specified blockMaterial
+ *
+ * @param material the crop blockMaterial
+ * @return the respective CropType. null if none found
+ */
+ public static CropType getCropType(Material material) {
+ for (CropType type : values())
+ if (type.getBlockMaterial() == material) return type;
+ return null;
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/songoda/epicfarming/utils/Debugger.java b/src/main/java/com/songoda/epicfarming/utils/Debugger.java
new file mode 100644
index 0000000..f7bc70c
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/utils/Debugger.java
@@ -0,0 +1,31 @@
+package com.songoda.epicfarming.utils;
+
+import com.songoda.epicfarming.EpicFarming;
+
+/**
+ * Created by songoda on 3/21/2017.
+ */
+public class Debugger {
+
+
+ public static void runReport(Exception e) {
+ if (isDebug()) {
+ System.out.println("==============================================================");
+ System.out.println("The following is an error encountered in EpicFarming.");
+ System.out.println("--------------------------------------------------------------");
+ e.printStackTrace();
+ System.out.println("==============================================================");
+ }
+ sendReport(e);
+ }
+
+ public static void sendReport(Exception e) {
+
+ }
+
+ public static boolean isDebug() {
+ EpicFarming plugin = EpicFarming.pl();
+ return plugin.getConfig().getBoolean("System.Debugger Enabled");
+ }
+
+}
diff --git a/src/main/java/com/songoda/epicfarming/utils/Methods.java b/src/main/java/com/songoda/epicfarming/utils/Methods.java
new file mode 100644
index 0000000..4027b8e
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/utils/Methods.java
@@ -0,0 +1,74 @@
+package com.songoda.epicfarming.utils;
+
+import com.songoda.arconix.plugin.Arconix;
+import com.songoda.epicfarming.EpicFarming;
+import com.songoda.epicfarming.Lang;
+import org.apache.commons.lang.math.NumberUtils;
+import org.bukkit.Material;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+
+/**
+ * Created by songoda on 2/24/2017.
+ */
+public class Methods {
+
+ public static ItemStack getGlass() {
+ try {
+ EpicFarming plugin = EpicFarming.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);
+ }
+ return null;
+ }
+
+ public static ItemStack getBackgroundGlass(boolean type) {
+ try {
+ EpicFarming plugin = EpicFarming.pl();
+ if (type)
+ return Arconix.pl().getApi().getGUI().getGlass(false, plugin.getConfig().getInt("Interfaces.Glass Type 2"));
+ else
+ return Arconix.pl().getApi().getGUI().getGlass(false, plugin.getConfig().getInt("Interfaces.Glass Type 3"));
+ } catch (Exception ex) {
+ Debugger.runReport(ex);
+ }
+ 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 = Lang.NAME_FORMAT.getConfigValue(level);
+
+ String info = "";
+ if (full) {
+ info += Arconix.pl().getApi().format().convertToInvisibleString(level + ":");
+ }
+
+ return info + Arconix.pl().getApi().format().formatText(name);
+ } catch (Exception ex) {
+ Debugger.runReport(ex);
+ }
+ return null;
+ }
+
+ public static ItemStack makeFarmItem(int level) {
+ ItemStack item = new ItemStack(Material.END_ROD, 1);
+ ItemMeta meta = item.getItemMeta();
+ meta.setDisplayName(Arconix.pl().getApi().format().formatText(Methods.formatName(level, true)));
+ item.setItemMeta(meta);
+ return item;
+ }
+}
diff --git a/src/main/java/com/songoda/epicfarming/utils/SettingsManager.java b/src/main/java/com/songoda/epicfarming/utils/SettingsManager.java
new file mode 100644
index 0000000..f296bc6
--- /dev/null
+++ b/src/main/java/com/songoda/epicfarming/utils/SettingsManager.java
@@ -0,0 +1,246 @@
+package com.songoda.epicfarming.utils;
+
+import com.songoda.arconix.api.utils.ConfigWrapper;
+import com.songoda.arconix.plugin.Arconix;
+import com.songoda.epicfarming.EpicFarming;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.Material;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.inventory.InventoryClickEvent;
+import org.bukkit.event.player.AsyncPlayerChatEvent;
+import org.bukkit.inventory.Inventory;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Created by songo on 6/4/2017.
+ */
+public class SettingsManager implements Listener {
+
+ private String pluginName = "EpicFarming";
+ private final EpicFarming instance;
+
+ private static ConfigWrapper defs;
+
+ private Map cat = new HashMap<>();
+
+ public SettingsManager(EpicFarming instance) {
+ this.instance = instance;
+ instance.saveResource("SettingDefinitions.yml", true);
+ defs = new ConfigWrapper(instance, "", "SettingDefinitions.yml");
+ defs.createNewFile("Loading data file", "EpicFarming SettingDefinitions file");
+ instance.getServer().getPluginManager().registerEvents(this, instance);
+ }
+
+ public Map current = new HashMap<>();
+
+ @EventHandler
+ public void onInventoryClick(InventoryClickEvent e) {
+ if (e.getInventory() == null
+ || e.getCurrentItem() == null
+ || !e.getCurrentItem().hasItemMeta()
+ || !e.getCurrentItem().getItemMeta().hasDisplayName()
+ || e.getWhoClicked().getOpenInventory().getTopInventory() != e.getInventory()) {
+ return;
+ }
+ if (e.getInventory().getTitle().equals(pluginName + " Settings Manager")) {
+
+ if (e.getCurrentItem().getType().equals(Material.STAINED_GLASS_PANE)) {
+ e.setCancelled(true);
+ return;
+ }
+
+ String type = ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName());
+ cat.put((Player) e.getWhoClicked(), type);
+ openEditor((Player) e.getWhoClicked());
+ e.setCancelled(true);
+ } else if (e.getInventory().getTitle().equals(pluginName + " Settings Editor")) {
+
+ if (e.getCurrentItem().getType().equals(Material.STAINED_GLASS_PANE)) {
+ e.setCancelled(true);
+ return;
+ }
+
+ Player p = (Player) e.getWhoClicked();
+ e.setCancelled(true);
+
+ String key = cat.get(p) + "." + ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName());
+
+ if (instance.getConfig().get(key).getClass().getName().equals("java.lang.Boolean")) {
+ boolean bool = (Boolean) instance.getConfig().get(key);
+ if (!bool)
+ instance.getConfig().set(key, true);
+ else
+ instance.getConfig().set(key, false);
+ finishEditing(p);
+ } else {
+ editObject(p, key);
+ }
+ }
+ }
+
+ @EventHandler
+ public void onChat(AsyncPlayerChatEvent e) {
+ final Player p = e.getPlayer();
+ if (!current.containsKey(p)) {
+ return;
+ }
+ switch (instance.getConfig().get(current.get(p)).getClass().getName()) {
+ case "java.lang.Integer":
+ instance.getConfig().set(current.get(p), Integer.parseInt(e.getMessage()));
+ break;
+ case "java.lang.Double":
+ instance.getConfig().set(current.get(p), Double.parseDouble(e.getMessage()));
+ break;
+ case "java.lang.String":
+ instance.getConfig().set(current.get(p), e.getMessage());
+ break;
+ }
+ finishEditing(p);
+ e.setCancelled(true);
+
+ }
+
+ public void finishEditing(Player p) {
+ current.remove(p);
+ instance.saveConfig();
+ openEditor(p);
+ }
+
+
+ public void editObject(Player p, String current) {
+ this.current.put(p, ChatColor.stripColor(current));
+ p.closeInventory();
+ p.sendMessage("");
+ p.sendMessage(Arconix.pl().getApi().format().formatText("&7Please enter a value for &6" + current + "&7."));
+ if (instance.getConfig().get(current).getClass().getName().equals("java.lang.Integer")) {
+ p.sendMessage(Arconix.pl().getApi().format().formatText("&cUse only numbers."));
+ }
+ p.sendMessage("");
+ }
+
+ public void openSettingsManager(Player p) {
+ Inventory i = Bukkit.createInventory(null, 27, pluginName + " Settings Manager");
+ int nu = 0;
+ while (nu != 27) {
+ i.setItem(nu, Methods.getGlass());
+ nu++;
+ }
+
+ int spot = 10;
+ for (String key : instance.getConfig().getConfigurationSection("").getKeys(false)) {
+ ItemStack item = new ItemStack(Material.WOOL, 1, (byte) (spot - 9));
+ ItemMeta meta = item.getItemMeta();
+ meta.setLore(Collections.singletonList(Arconix.pl().getApi().format().formatText("&6Click To Edit This Category.")));
+ meta.setDisplayName(Arconix.pl().getApi().format().formatText("&f&l" + key));
+ item.setItemMeta(meta);
+ i.setItem(spot, item);
+ spot++;
+ }
+ p.openInventory(i);
+ }
+
+ public void openEditor(Player p) {
+ Inventory i = Bukkit.createInventory(null, 54, pluginName + " Settings Editor");
+
+ int num = 0;
+ for (String key : instance.getConfig().getConfigurationSection(cat.get(p)).getKeys(true)) {
+ String fKey = cat.get(p) + "." + key;
+ ItemStack item = new ItemStack(Material.DIAMOND_HELMET);
+ ItemMeta meta = item.getItemMeta();
+ meta.setDisplayName(Arconix.pl().getApi().format().formatText("&6" + key));
+ ArrayList lore = new ArrayList<>();
+ switch (instance.getConfig().get(fKey).getClass().getName()) {
+ case "java.lang.Boolean":
+
+ item.setType(Material.LEVER);
+ boolean bool = (Boolean) instance.getConfig().get(fKey);
+
+ if (!bool)
+ lore.add(Arconix.pl().getApi().format().formatText("&c" + false));
+ else
+ lore.add(Arconix.pl().getApi().format().formatText("&a" + true));
+
+ break;
+ case "java.lang.String":
+ item.setType(Material.PAPER);
+ String str = (String) instance.getConfig().get(fKey);
+ lore.add(Arconix.pl().getApi().format().formatText("&9" + str));
+ break;
+ case "java.lang.Integer":
+ item.setType(Material.WATCH);
+
+ int in = (Integer) instance.getConfig().get(fKey);
+ lore.add(Arconix.pl().getApi().format().formatText("&5" + in));
+ break;
+ default:
+ continue;
+ }
+ if (defs.getConfig().contains(fKey)) {
+ String text = defs.getConfig().getString(key);
+
+ Pattern regex = Pattern.compile("(.{1,28}(?:\\s|$))|(.{0,28})", Pattern.DOTALL);
+ Matcher m = regex.matcher(text);
+ while (m.find()) {
+ if (m.end() != text.length() || m.group().length() != 0)
+ lore.add(Arconix.pl().getApi().format().formatText("&7" + m.group()));
+ }
+ }
+ meta.setLore(lore);
+ item.setItemMeta(meta);
+
+ i.setItem(num, item);
+ num++;
+ }
+ p.openInventory(i);
+ }
+
+ public void updateSettings() {
+ for (settings s : settings.values()) {
+ if (s.setting.equals("Main.Upgrade Particle Type")) {
+ if (instance.v1_7 || instance.v1_8)
+ instance.getConfig().addDefault(s.setting, "WITCH_MAGIC");
+ else
+ instance.getConfig().addDefault(s.setting, s.option);
+ } else
+ instance.getConfig().addDefault(s.setting, s.option);
+ }
+ }
+
+ public enum settings {
+ o1("Main.Upgrade With Economy", true),
+ o2("Main.Upgrade With XP", true),
+ o3("Main.Upgrade Particle Type", "SPELL_WITCH"),
+ o4("Main.Sounds Enabled", true),
+ o5("Main.Farm Tick Speed", 70),
+ o6("Main.Growth Tick Speed", 20),
+ o7("Main.Clear Tick Speed", 1800),
+
+ o8("Interfaces.Economy Icon", "DOUBLE_PLANT"),
+ o9("Interfaces.XP Icon", "EXP_BOTTLE"),
+ o10("Interfaces.Glass Type 1", 7),
+ o11("Interfaces.Glass Type 2", 11),
+ o12("Interfaces.Glass Type 3", 3),
+
+ o13("System.Debugger Enabled", false);
+
+ private String setting;
+ private Object option;
+
+ settings(String setting, Object option) {
+ this.setting = setting;
+ this.option = option;
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/src/SettingDefinitions.yml b/src/main/resources/SettingDefinitions.yml
similarity index 100%
rename from src/SettingDefinitions.yml
rename to src/main/resources/SettingDefinitions.yml
diff --git a/src/plugin.yml b/src/main/resources/plugin.yml
similarity index 100%
rename from src/plugin.yml
rename to src/main/resources/plugin.yml