diff --git a/pom.xml b/pom.xml index b262b00..68e167c 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.songoda EpicFarming - 3.2.1 + 3.2.2 clean install @@ -54,7 +54,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.3.0-SNAPSHOT + 3.3.0 @@ -124,7 +124,7 @@ com.songoda SongodaCore - 2.6.12 + 2.6.13 compile diff --git a/src/main/java/com/songoda/epicfarming/EpicFarming.java b/src/main/java/com/songoda/epicfarming/EpicFarming.java index 9411867..e156162 100644 --- a/src/main/java/com/songoda/epicfarming/EpicFarming.java +++ b/src/main/java/com/songoda/epicfarming/EpicFarming.java @@ -4,6 +4,7 @@ import com.songoda.core.SongodaCore; import com.songoda.core.SongodaPlugin; import com.songoda.core.commands.CommandManager; import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.core.compatibility.ServerVersion; import com.songoda.core.configuration.Config; import com.songoda.core.database.DataMigrationManager; import com.songoda.core.database.DatabaseConnector; @@ -31,11 +32,7 @@ import com.songoda.epicfarming.farming.levels.modules.Module; import com.songoda.epicfarming.farming.levels.modules.ModuleAutoBreeding; import com.songoda.epicfarming.farming.levels.modules.ModuleAutoButcher; import com.songoda.epicfarming.farming.levels.modules.ModuleAutoCollect; -import com.songoda.epicfarming.listeners.BlockListeners; -import com.songoda.epicfarming.listeners.EntityListeners; -import com.songoda.epicfarming.listeners.InteractListeners; -import com.songoda.epicfarming.listeners.InventoryListeners; -import com.songoda.epicfarming.listeners.UnloadListeners; +import com.songoda.epicfarming.listeners.*; import com.songoda.epicfarming.settings.Settings; import com.songoda.epicfarming.storage.Storage; import com.songoda.epicfarming.storage.StorageRow; @@ -160,6 +157,9 @@ public class EpicFarming extends SongodaPlugin { pluginManager.registerEvents(new InteractListeners(this), this); pluginManager.registerEvents(new UnloadListeners(this), this); pluginManager.registerEvents(new InventoryListeners(), this); + if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_14)) { + pluginManager.registerEvents(new MoistureListeners(this), this); + } if (pluginManager.isPluginEnabled("FabledSkyBlock")) { try { diff --git a/src/main/java/com/songoda/epicfarming/farming/Farm.java b/src/main/java/com/songoda/epicfarming/farming/Farm.java index bc1a6fb..3dd81a0 100644 --- a/src/main/java/com/songoda/epicfarming/farming/Farm.java +++ b/src/main/java/com/songoda/epicfarming/farming/Farm.java @@ -18,13 +18,7 @@ import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.UUID; +import java.util.*; public class Farm { @@ -155,15 +149,7 @@ public class Farm { Block b2 = block.getWorld().getBlockAt(bx + fx, by + fy, bz + fz); // ToDo: enum for all flowers. - if (b2.getType() == CompatibleMaterial.TALL_GRASS.getMaterial() - || b2.getType() == CompatibleMaterial.GRASS.getMaterial() - || b2.getType().name().contains("TULIP") - || b2.getType().name().contains("ORCHID") - || b2.getType() == CompatibleMaterial.AZURE_BLUET.getMaterial() - || b2.getType() == CompatibleMaterial.ALLIUM.getMaterial() - || b2.getType() == CompatibleMaterial.POPPY.getMaterial() - || b2.getType() == CompatibleMaterial.DANDELION.getMaterial() - || b2.getType() == CompatibleMaterial.SNOW.getMaterial()) { + if (Settings.BREAKABLE_BLOCKS.getStringList().contains(CompatibleMaterial.getMaterial(b2.getType()).name())) { Bukkit.getScheduler().runTaskLater(EpicFarming.getInstance(), () -> { b2.getRelative(BlockFace.DOWN).setType(CompatibleMaterial.FARMLAND.getMaterial()); b2.breakNaturally(); diff --git a/src/main/java/com/songoda/epicfarming/listeners/MoistureListeners.java b/src/main/java/com/songoda/epicfarming/listeners/MoistureListeners.java new file mode 100644 index 0000000..185665f --- /dev/null +++ b/src/main/java/com/songoda/epicfarming/listeners/MoistureListeners.java @@ -0,0 +1,28 @@ +package com.songoda.epicfarming.listeners; + +import com.songoda.epicfarming.EpicFarming; +import com.songoda.epicfarming.farming.Farm; +import org.bukkit.block.data.type.Farmland; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.MoistureChangeEvent; + +public class MoistureListeners implements Listener { + + private final EpicFarming plugin; + public MoistureListeners(EpicFarming plugin) { + this.plugin = plugin; + } + + @EventHandler + public void onMoistureChange(MoistureChangeEvent event) { + if (event.getNewState().getBlockData() instanceof Farmland) { + return; + } + + Farm farm = plugin.getFarmManager().checkForFarm(event.getBlock().getLocation()); + if (farm != null) { + event.setCancelled(true); + } + } +} diff --git a/src/main/java/com/songoda/epicfarming/settings/Settings.java b/src/main/java/com/songoda/epicfarming/settings/Settings.java index c396098..74c20d0 100644 --- a/src/main/java/com/songoda/epicfarming/settings/Settings.java +++ b/src/main/java/com/songoda/epicfarming/settings/Settings.java @@ -7,6 +7,7 @@ import com.songoda.core.configuration.ConfigSetting; import com.songoda.core.hooks.EconomyManager; import com.songoda.epicfarming.EpicFarming; +import java.util.Arrays; import java.util.stream.Collectors; public class Settings { @@ -43,6 +44,15 @@ public class Settings { public static final ConfigSetting USE_PROTECTION_PLUGINS = new ConfigSetting(config, "Main.Use Protection Plugins", true, "Should we use protection plugins?"); + public static final ConfigSetting BREAKABLE_BLOCKS = new ConfigSetting(config, "Main.Breakable Blocks", Arrays.asList( + "TALL_GRASS", "GRASS", "BLUE_ORCHID", "AZURE_BLUET", + "ALLIUM", "POPPY", "DANDELION", "SNOW", + "CORNFLOWER", "FERN", "LARGE_FERN", "SUNFLOWER", + "ROSE_BUSH", "OXEYE_DAISY", "LILY_OF_THE_VALLEY", "PEONY", + "LILAC", "WITHER_ROSE", "PINK_TULIP", "RED_TULIP", + "WHITE_TULIP", "ORANGE_TULIP", "NETHER_SPROUTS", "GLOW_LICHEN"), + "Which blocks should farms be allowed to break when they til the land?"); + public static final ConfigSetting ECONOMY_PLUGIN = new ConfigSetting(config, "Main.Economy", EconomyManager.getEconomy() == null ? "Vault" : EconomyManager.getEconomy().getName(), "Which economy plugin should be used?", "Supported plugins you have installed: \"" + EconomyManager.getManager().getRegisteredPlugins().stream().collect(Collectors.joining("\", \"")) + "\".");