From a260dbcad975eed249017a1265e8bfc9fe512651 Mon Sep 17 00:00:00 2001 From: avesanidennis <71428288+avesanidennis@users.noreply.github.com> Date: Mon, 18 Oct 2021 13:38:30 +0200 Subject: [PATCH 1/2] Created a new setting option to collect with hopper --- src/main/java/com/songoda/epicfarming/settings/Settings.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/songoda/epicfarming/settings/Settings.java b/src/main/java/com/songoda/epicfarming/settings/Settings.java index c396098..f62529f 100644 --- a/src/main/java/com/songoda/epicfarming/settings/Settings.java +++ b/src/main/java/com/songoda/epicfarming/settings/Settings.java @@ -58,6 +58,9 @@ public class Settings { "The enabled language file.", "More language files (if available) can be found in the plugins data folder."); + public static final ConfigSetting COLLECT_WITH_HOPPER = new ConfigSetting(config, "Main.Collect With Hopper", true, + "Should you be able to collect items with an hopper under the farming item?"); + /** * In order to set dynamic economy comment correctly, this needs to be * called after EconomyManager load @@ -84,4 +87,4 @@ public static void setupConfig() { config.saveChanges(); } -} \ No newline at end of file +} From 14ff2445db3a95e102551e86f4008fc06544a375 Mon Sep 17 00:00:00 2001 From: avesanidennis <71428288+avesanidennis@users.noreply.github.com> Date: Mon, 18 Oct 2021 13:39:45 +0200 Subject: [PATCH 2/2] Update HopperTask with the check of the HOPPER_WITH_ITEM in config.yml --- .../songoda/epicfarming/tasks/HopperTask.java | 49 ++++++++++--------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/songoda/epicfarming/tasks/HopperTask.java b/src/main/java/com/songoda/epicfarming/tasks/HopperTask.java index 40143e4..fb2a45a 100644 --- a/src/main/java/com/songoda/epicfarming/tasks/HopperTask.java +++ b/src/main/java/com/songoda/epicfarming/tasks/HopperTask.java @@ -4,6 +4,7 @@ import com.songoda.epicfarming.EpicFarming; import com.songoda.epicfarming.farming.Farm; import com.songoda.epicfarming.farming.FarmManager; +import com.songoda.epicfarming.settings.Settings; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -34,38 +35,40 @@ public static HopperTask startTask(EpicFarming plugin) { @Override public void run() { - for (Farm farm : manager.getFarms().values()) { - Location farmLocation = farm.getLocation(); - if (farmLocation == null || farmLocation.getWorld() == null) { - manager.removeFarm(farm.getLocation()); - continue; - } + if(Settings.COLLECT_WITH_HOPPER.getBoolean()) { + for (Farm farm : manager.getFarms().values()) { + Location farmLocation = farm.getLocation(); + if (farmLocation == null || farmLocation.getWorld() == null) { + manager.removeFarm(farm.getLocation()); + continue; + } - int x = farmLocation.getBlockX() >> 4; - int z = farmLocation.getBlockZ() >> 4; + int x = farmLocation.getBlockX() >> 4; + int z = farmLocation.getBlockZ() >> 4; - if (!farmLocation.getWorld().isChunkLoaded(x, z)) { - continue; - } + if (!farmLocation.getWorld().isChunkLoaded(x, z)) { + continue; + } - Block block = farmLocation.getBlock().getRelative(BlockFace.DOWN); + Block block = farmLocation.getBlock().getRelative(BlockFace.DOWN); - if (block.getType() != Material.HOPPER) - continue; + if (block.getType() != Material.HOPPER) + continue; - Inventory hopperInventory = ((Hopper) block.getState()).getInventory(); + Inventory hopperInventory = ((Hopper) block.getState()).getInventory(); - for (ItemStack item : farm.getItems().toArray(new ItemStack[0])) { - if (item.getType() == CompatibleMaterial.BONE_MEAL.getMaterial()) continue; + for (ItemStack item : farm.getItems().toArray(new ItemStack[0])) { + if (item.getType() == CompatibleMaterial.BONE_MEAL.getMaterial()) continue; - ItemStack toMove = item.clone(); - toMove.setAmount(1); + ItemStack toMove = item.clone(); + toMove.setAmount(1); - if (canHop(hopperInventory, toMove)) { - farm.removeMaterial(toMove.getType(), 1); - hopperInventory.addItem(toMove); + if (canHop(hopperInventory, toMove)) { + farm.removeMaterial(toMove.getType(), 1); + hopperInventory.addItem(toMove); + } + break; } - break; } } }