From 3bbcf45717f0ccba22b13ea3f18e7c459607f680 Mon Sep 17 00:00:00 2001 From: msudol Date: Sat, 6 Mar 2021 22:16:26 -0500 Subject: [PATCH] trying to resolve some issues around bamboo and the fertilize event --- config.yml | 28 +++- plugin.yml | 2 +- .../BlockFertilizeListener.java | 154 ++++++++++++++++++ .../PwnPlantGrowth/BlockGrowListener.java | 6 +- .../PwnPlantGrowth/BlockSpreadListener.java | 14 +- src/com/pwn9/PwnPlantGrowth/Calculate.java | 1 + src/com/pwn9/PwnPlantGrowth/Config.java | 1 + .../pwn9/PwnPlantGrowth/PlayerListener.java | 7 +- .../pwn9/PwnPlantGrowth/PwnPlantGrowth.java | 25 ++- .../PwnPlantGrowth/StructureGrowListener.java | 2 + 10 files changed, 221 insertions(+), 19 deletions(-) create mode 100644 src/com/pwn9/PwnPlantGrowth/BlockFertilizeListener.java diff --git a/config.yml b/config.yml index 01dafd9..ae6cb24 100644 --- a/config.yml +++ b/config.yml @@ -52,7 +52,7 @@ uv: GLOWSTONE # Radius that UV affects uv_radius: 5 -# Allow plugin to capture bonemeal (only works for trees right now) +# Allow plugin to capture bonemeal limit_bonemeal: false # Show players possible growth rates for an item if they click it on a block in a biome @@ -70,6 +70,9 @@ tree_log: false # Will additionally log Plant Growing Events. plant_log: false +# Will additionally log Bonemeal Growing Events. +bonemeal_log: false + # Set true if you want also to log the coordinates on the world of the event - gets really spammy log_coords: false @@ -169,6 +172,19 @@ BAMBOO: Biome: - NONE +# Bamboo Sapling is a freshly planted bamboo, it is a block item not a tree item even though it is labeled "sapling" +BAMBOO_SAPLING: + Growth: 50 + Death: 5 + BiomeGroup: + - Jungle + Jungle: + Growth: 50 + GrowthDark: 25 + Death: 0 + DeathDark: 5 + Biome: + - NONE # In this example beetroot only grows in GoodGrowing and GreatGrowing biomes, setting biome NONE should block all others BEETROOTS: @@ -266,6 +282,12 @@ GRASS: Death: 0 Biome: [] +# Similar to GRASS above, specifically for when bonemeal is used on a grass block +GRASS_BLOCK: + Growth: 50 + Death: 0 + Biome: [] + # In this example kelp will grow anywhere - Biome: [] - but only at 50% KELP: Growth: 50 @@ -476,7 +498,7 @@ WARPED_FUNGUS: Biome: - WARPED_FOREST -# Plugin will check for the following list of plants as of ver. 2.6.0 for Minecraft 1.16.x +# Plugin will check for the following list of plants as of ver. 2.6.1 for Minecraft 1.16.x -# Ageable / BlockGrowEvent: "BAMBO", "BEETROOTS", "CACTUS", "CARROTS", "COCOA", "CHORUS_FLOWER", "GRASS", "KELP", "MELON", "MELON_STEM", "NETHER_WART", "POTATOS", "PUMPKIN", "PUMPKIN_STEM", "SUGAR_CANE", "TWISTING_VINES", "WEEPING_VINES", "WHEAT", "SWEET_BERRY_BUSH" +# Ageable / BlockGrowEvent: "BAMBOO", "BAMBOO_SAPLING", "BEETROOTS", "CACTUS", "CARROTS", "COCOA", "CHORUS_FLOWER", "GRASS", "GRASS_BLOCK", "KELP", "MELON", "MELON_STEM", "NETHER_WART", "POTATOS", "PUMPKIN", "PUMPKIN_STEM", "SUGAR_CANE", "TWISTING_VINES", "WEEPING_VINES", "WHEAT", "SWEET_BERRY_BUSH" # Structures / StructureGrowEvent: "ACACIA_SAPLING", "BIRCH_SAPLING", "DARK_OAK_SAPLING", "JUNGLE_SAPLING", "OAK_SAPLING", "SPRUCE_SAPLING", "RED_MUSHROOM", "BROWN_MUSHROOM", "CRIMSON_FUNGUS", "WARPED_FUNGUS" diff --git a/plugin.yml b/plugin.yml index 3749093..8efd7f5 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ main: com.pwn9.PwnPlantGrowth.PwnPlantGrowth name: PwnPlantGrowth -version: 2.6.0 +version: 2.6.1 author: tremor77 description: Take control over all plant growth website: http://pwn9.com diff --git a/src/com/pwn9/PwnPlantGrowth/BlockFertilizeListener.java b/src/com/pwn9/PwnPlantGrowth/BlockFertilizeListener.java new file mode 100644 index 0000000..97fcffc --- /dev/null +++ b/src/com/pwn9/PwnPlantGrowth/BlockFertilizeListener.java @@ -0,0 +1,154 @@ +package com.pwn9.PwnPlantGrowth; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.World; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockFertilizeEvent; + +public class BlockFertilizeListener implements Listener +{ + + private final PwnPlantGrowth plugin; + + public BlockFertilizeListener(PwnPlantGrowth plugin) + { + plugin.getServer().getPluginManager().registerEvents(this, plugin); + this.plugin = plugin; + } + + static Calculate getCalcs(List> specialBlocks, String thisBlock, String curBiome, Boolean isDark) + { + return new Calculate(specialBlocks, thisBlock, curBiome, isDark); + } + + // retrieve list of special blocks + public List> specialBlockList(BlockFertilizeEvent e) + { + List fBlocksFound = new ArrayList(); + List wkBlocksFound = new ArrayList(); + List uvBlocksFound = new ArrayList();; + + List> result = new ArrayList>(); + + // Check for fertilizer blocks + if (PwnPlantGrowth.fenabled) + { + for (int fx = -(PwnPlantGrowth.fradius); fx <= PwnPlantGrowth.fradius; fx++) + { + for (int fy = -(PwnPlantGrowth.fradius); fy <= PwnPlantGrowth.fradius; fy++) + { + for (int fz = -(PwnPlantGrowth.fradius); fz <= PwnPlantGrowth.fradius; fz++) + { + fBlocksFound.add(String.valueOf(e.getBlock().getRelative(fx, fy, fz).getType())); + } + } + } + } + + // Check for weed killer blocks + if (PwnPlantGrowth.wkenabled) + { + for (int wx = -(PwnPlantGrowth.wkradius); wx <= PwnPlantGrowth.wkradius; wx++) + { + for (int wy = -(PwnPlantGrowth.wkradius); wy <= PwnPlantGrowth.wkradius; wy++) + { + for (int wz = -(PwnPlantGrowth.wkradius); wz <= PwnPlantGrowth.wkradius; wz++) + { + wkBlocksFound.add(String.valueOf(e.getBlock().getRelative(wx, wy, wz).getType())); + } + } + } + } + + // Check for uv blocks + if (PwnPlantGrowth.uvenabled) + { + for (int ux = -(PwnPlantGrowth.uvradius); ux <= PwnPlantGrowth.uvradius; ux++) + { + for (int uy = -(PwnPlantGrowth.uvradius); uy <= PwnPlantGrowth.uvradius; uy++) + { + for (int uz = -(PwnPlantGrowth.uvradius); uz <= PwnPlantGrowth.uvradius; uz++) + { + uvBlocksFound.add(String.valueOf(e.getBlock().getRelative(ux, uy, uz).getType())); + } + } + } + } + + result.add(fBlocksFound); + result.add(wkBlocksFound); + result.add(uvBlocksFound); + + return result; + } + + // Listen for plant growth from block fertilize, and then do stuff + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false) + public void blockFertilize(BlockFertilizeEvent e) + { + + // Enabled in world? + World world = e.getBlock().getWorld(); + if (!PwnPlantGrowth.isEnabledIn(world.getName())) return; + + // Get source block type and make a string for comparison later + String sourceBlock = String.valueOf(e.getBlock().getType()); + + // Get current biome and make a string for comparison later + String curBiome = PwnPlantGrowth.getBiome(e); + + if ((PwnPlantGrowth.logEnabled) && (PwnPlantGrowth.logPlantEnabled) && (PwnPlantGrowth.logVerbose)) + { + PwnPlantGrowth.logToFile("Block Event for: " + sourceBlock + " - In biome: " + curBiome, "BlockFertilize"); + } + + // Is anything set for this block in the config? If not, abort. + if (!(plugin.getConfig().isSet(sourceBlock))) { + PwnPlantGrowth.logToFile("No plant configuration set in config for: " + sourceBlock); + return; + } + + // Get coords of the event for logging + String coords = String.valueOf(e.getBlock().getLocation()); + + // Setup boolean to see if event is in defined natural light or not + Boolean isDark = false; + + // Get the current natural light level + int lightLevel = e.getBlock().getLightFromSky(); + + // If the light level is lower than configured threshold and the plant is NOT exempt from dark grow, set this transaction to isDark = true + if ((PwnPlantGrowth.naturalLight > lightLevel) && (!PwnPlantGrowth.canDarkGrow(sourceBlock))) + { + isDark = true; + } + + String toLog = ""; + + // Start log string with world name and coordinates + if (PwnPlantGrowth.logCoords) + { + toLog += coords + ": "; + } + + toLog += "Fertilizing: " + sourceBlock; + + Calculate cal = getCalcs(specialBlockList(e), sourceBlock, curBiome, isDark); + toLog += cal.doLog; + e.setCancelled(cal.isCancelled); + // don't do replacement if death and replace for a fertilze event + + // Log it + if ((PwnPlantGrowth.logEnabled) && (PwnPlantGrowth.logBonemealEnabled)) + { + PwnPlantGrowth.logToFile(toLog, "Fertilize"); + } + + return; + } + +} \ No newline at end of file diff --git a/src/com/pwn9/PwnPlantGrowth/BlockGrowListener.java b/src/com/pwn9/PwnPlantGrowth/BlockGrowListener.java index 2b873d7..521fbef 100644 --- a/src/com/pwn9/PwnPlantGrowth/BlockGrowListener.java +++ b/src/com/pwn9/PwnPlantGrowth/BlockGrowListener.java @@ -190,7 +190,7 @@ else if ((e.getBlock().getRelative(BlockFace.EAST).getType() == Material.PUMPKIN faceBlock = "AIR"; } - // Handle Cactus, Sugar Cane; the plants that grow vertically only. + // Handle Cactus, Sugar Cane, Bamboo; the plants that grow vertically only. if (downBlock == "CACTUS" || downBlock == "SUGAR_CANE") { @@ -204,7 +204,7 @@ else if ((e.getBlock().getRelative(BlockFace.EAST).getType() == Material.PUMPKIN e.getBlock().setType(cal.replacement); } } - // Handle Cactus, Sugar Cane; the plants that grow vertically only. + // not a vertical growing plant so fallback to a melon else if (faceBlock == "MELON" || faceBlock == "PUMPKIN") { @@ -259,6 +259,8 @@ else if (downBlock == "GRASS" || downBlock == "GRASS_BLOCK" || downBlock == "TAL { PwnPlantGrowth.logToFile(toLog, "BlockGrow"); } + + return; } } \ No newline at end of file diff --git a/src/com/pwn9/PwnPlantGrowth/BlockSpreadListener.java b/src/com/pwn9/PwnPlantGrowth/BlockSpreadListener.java index 1b6e79c..847b880 100644 --- a/src/com/pwn9/PwnPlantGrowth/BlockSpreadListener.java +++ b/src/com/pwn9/PwnPlantGrowth/BlockSpreadListener.java @@ -5,6 +5,7 @@ import org.bukkit.World; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockSpreadEvent; @@ -86,7 +87,7 @@ public List> specialBlockList(BlockSpreadEvent e) } // Listen for plant growth from block spread, this is like chorus plant, and then do stuff - @EventHandler(ignoreCancelled = false) + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false) public void blockSpread(BlockSpreadEvent e) { @@ -111,7 +112,7 @@ public void blockSpread(BlockSpreadEvent e) PwnPlantGrowth.logToFile("Block Event for: " + sourceBlock + " - In biome: " + curBiome, "BlockSpread"); } - // Is anything set for this block in the config, or is it AIR? If not, abort. + // Is anything set for this block in the config? If not, abort. if (!(plugin.getConfig().isSet(sourceBlock))) { PwnPlantGrowth.logToFile("No plant configuration set in config for: " + sourceBlock); return; @@ -125,10 +126,7 @@ public void blockSpread(BlockSpreadEvent e) // Get the current natural light level int lightLevel = e.getBlock().getLightFromSky(); - - // Do we want to check on actual lighting? Maybe in a future release - //int actualLight = e.getBlock().getLightFromBlocks(); - + // If the light level is lower than configured threshold and the plant is NOT exempt from dark grow, set this transaction to isDark = true if ((PwnPlantGrowth.naturalLight > lightLevel) && (!PwnPlantGrowth.canDarkGrow(sourceBlock))) { @@ -156,7 +154,9 @@ public void blockSpread(BlockSpreadEvent e) if ((PwnPlantGrowth.logEnabled) && (PwnPlantGrowth.logPlantEnabled)) { PwnPlantGrowth.logToFile(toLog, "BlockSpread"); - } + } + + return; } } \ No newline at end of file diff --git a/src/com/pwn9/PwnPlantGrowth/Calculate.java b/src/com/pwn9/PwnPlantGrowth/Calculate.java index 1d2c056..8757e46 100644 --- a/src/com/pwn9/PwnPlantGrowth/Calculate.java +++ b/src/com/pwn9/PwnPlantGrowth/Calculate.java @@ -468,5 +468,6 @@ else if (thisBlock == "KELP") { } doLog = toLog + ". "; + return; } } diff --git a/src/com/pwn9/PwnPlantGrowth/Config.java b/src/com/pwn9/PwnPlantGrowth/Config.java index a391f51..6fd98e8 100644 --- a/src/com/pwn9/PwnPlantGrowth/Config.java +++ b/src/com/pwn9/PwnPlantGrowth/Config.java @@ -11,6 +11,7 @@ public static void LoadConfig() PwnPlantGrowth.logEnabled = PwnPlantGrowth.instance.getConfig().getBoolean("debug_log", false); PwnPlantGrowth.logTreeEnabled = PwnPlantGrowth.instance.getConfig().getBoolean("tree_log", false); PwnPlantGrowth.logPlantEnabled = PwnPlantGrowth.instance.getConfig().getBoolean("plant_log", false); + PwnPlantGrowth.logBonemealEnabled = PwnPlantGrowth.instance.getConfig().getBoolean("bonemeal_log", false); PwnPlantGrowth.logCoords = PwnPlantGrowth.instance.getConfig().getBoolean("log_coords", false); PwnPlantGrowth.logVerbose = PwnPlantGrowth.instance.getConfig().getBoolean("log_verbose", false); diff --git a/src/com/pwn9/PwnPlantGrowth/PlayerListener.java b/src/com/pwn9/PwnPlantGrowth/PlayerListener.java index 6d35592..399375b 100644 --- a/src/com/pwn9/PwnPlantGrowth/PlayerListener.java +++ b/src/com/pwn9/PwnPlantGrowth/PlayerListener.java @@ -128,7 +128,6 @@ public void checkBlockClick(PlayerInteractEvent e) // Get the current natural light level int lightLevel = e.getPlayer().getLocation().getBlock().getLightFromSky(); - if(PwnPlantGrowth.plantTypes.contains(m.toString())) { @@ -193,14 +192,12 @@ else if (m == Material.WHEAT_SEEDS) { String msg = ChatColor.translateAlternateColorCodes('&', PwnPlantGrowth.msgFormat + a); p.sendMessage(msg); - // annoying unable to test in create without breaking block so cancel even in creative only + // annoying unable to test in creative without breaking block so cancel event in creative only if (p.getGameMode() == GameMode.CREATIVE) { e.setCancelled(true); } - } } } - } - + } } \ No newline at end of file diff --git a/src/com/pwn9/PwnPlantGrowth/PwnPlantGrowth.java b/src/com/pwn9/PwnPlantGrowth/PwnPlantGrowth.java index 993f4fc..2f49cdd 100644 --- a/src/com/pwn9/PwnPlantGrowth/PwnPlantGrowth.java +++ b/src/com/pwn9/PwnPlantGrowth/PwnPlantGrowth.java @@ -12,6 +12,7 @@ import java.util.Random; import java.util.ArrayList; +import org.bukkit.event.block.BlockFertilizeEvent; import org.bukkit.event.block.BlockGrowEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.world.StructureGrowEvent; @@ -33,6 +34,7 @@ public class PwnPlantGrowth extends JavaPlugin public static Boolean logEnabled; public static Boolean logTreeEnabled; public static Boolean logPlantEnabled; + public static Boolean logBonemealEnabled; public static Boolean logCoords; public static Boolean logVerbose; public static Boolean blockWaterBucket; @@ -92,6 +94,7 @@ public void onEnable() new StructureGrowListener(this); new PlayerListener(this); new BlockSpreadListener(this); + new BlockFertilizeListener(this); // Get data folder PwnPlantGrowth.dataFolder = getDataFolder(); @@ -105,7 +108,7 @@ public void onEnable() PwnPlantGrowth.uvFound = " UV found, allowing false light growth."; // Load all possible plant types - String sArray[] = new String[] { "BAMBOO", "BEETROOTS", "CACTUS", "CARROTS", "CHORUS_FLOWER", "COCOA", "GRASS", "KELP", "MELON", "MELON_STEM", "NETHER_WART", "POTATOES", "PUMPKIN", "PUMPKIN_STEM", "SUGAR_CANE", "SWEET_BERRY_BUSH", "TWISTING_VINES", "WEEPING_VINES", "WHEAT", "ACACIA_SAPLING", "BIRCH_SAPLING", "DARK_OAK_SAPLING", "JUNGLE_SAPLING", "OAK_SAPLING", "SPRUCE_SAPLING", "RED_MUSHROOM", "BROWN_MUSHROOM", "CRIMSON_FUNGUS", "WARPED_FUNGUS"}; + String sArray[] = new String[] { "BAMBOO", "BAMBOO_SAPLING", "BEETROOTS", "CACTUS", "CARROTS", "CHORUS_FLOWER", "COCOA", "GRASS", "KELP", "MELON", "MELON_STEM", "NETHER_WART", "POTATOES", "PUMPKIN", "PUMPKIN_STEM", "SUGAR_CANE", "SWEET_BERRY_BUSH", "TWISTING_VINES", "WEEPING_VINES", "WHEAT", "ACACIA_SAPLING", "BIRCH_SAPLING", "DARK_OAK_SAPLING", "JUNGLE_SAPLING", "OAK_SAPLING", "SPRUCE_SAPLING", "RED_MUSHROOM", "BROWN_MUSHROOM", "CRIMSON_FUNGUS", "WARPED_FUNGUS"}; PwnPlantGrowth.plantTypes = Arrays.asList(sArray); // Load all possible seed types not in plant types, the items that plant a plant @@ -281,6 +284,26 @@ public static String getBiome(StructureGrowEvent e) } } + public static String getBiome(BlockFertilizeEvent e) + { + if (tc != null) + { + String tControl = TerrainControl.getBiomeName(e.getBlock().getWorld().getName(), e.getBlock().getLocation().getBlockX(), e.getBlock().getLocation().getBlockZ()); + if (tControl != null) + { + return tControl; + } + else + { + return String.valueOf(e.getBlock().getBiome()); + } + } + else + { + return String.valueOf(e.getBlock().getBiome()); + } + } + // need to get the biome of the clicked block, not the player, in case the block is in a different biome public static String getBiome(PlayerInteractEvent e) { if (tc != null) diff --git a/src/com/pwn9/PwnPlantGrowth/StructureGrowListener.java b/src/com/pwn9/PwnPlantGrowth/StructureGrowListener.java index efa1758..e69750e 100644 --- a/src/com/pwn9/PwnPlantGrowth/StructureGrowListener.java +++ b/src/com/pwn9/PwnPlantGrowth/StructureGrowListener.java @@ -165,6 +165,8 @@ public void structureGrow(StructureGrowEvent e) { PwnPlantGrowth.logToFile(toLog, "StructureGrow"); } + + return; } } \ No newline at end of file