Skip to content

Commit

Permalink
trying to resolve some issues around bamboo and the fertilize event
Browse files Browse the repository at this point in the history
  • Loading branch information
msudol committed Mar 7, 2021
1 parent 37f004d commit 3bbcf45
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 19 deletions.
28 changes: 25 additions & 3 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
154 changes: 154 additions & 0 deletions src/com/pwn9/PwnPlantGrowth/BlockFertilizeListener.java
Original file line number Diff line number Diff line change
@@ -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<List<String>> specialBlocks, String thisBlock, String curBiome, Boolean isDark)
{
return new Calculate(specialBlocks, thisBlock, curBiome, isDark);
}

// retrieve list of special blocks
public List<List<String>> specialBlockList(BlockFertilizeEvent e)
{
List<String> fBlocksFound = new ArrayList<String>();
List<String> wkBlocksFound = new ArrayList<String>();
List<String> uvBlocksFound = new ArrayList<String>();;

List<List<String>> result = new ArrayList<List<String>>();

// 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;
}

}
6 changes: 4 additions & 2 deletions src/com/pwn9/PwnPlantGrowth/BlockGrowListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{

Expand All @@ -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")
{

Expand Down Expand Up @@ -259,6 +259,8 @@ else if (downBlock == "GRASS" || downBlock == "GRASS_BLOCK" || downBlock == "TAL
{
PwnPlantGrowth.logToFile(toLog, "BlockGrow");
}

return;
}

}
14 changes: 7 additions & 7 deletions src/com/pwn9/PwnPlantGrowth/BlockSpreadListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -86,7 +87,7 @@ public List<List<String>> 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)
{

Expand All @@ -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;
Expand All @@ -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)))
{
Expand Down Expand Up @@ -156,7 +154,9 @@ public void blockSpread(BlockSpreadEvent e)
if ((PwnPlantGrowth.logEnabled) && (PwnPlantGrowth.logPlantEnabled))
{
PwnPlantGrowth.logToFile(toLog, "BlockSpread");
}
}

return;
}

}
1 change: 1 addition & 0 deletions src/com/pwn9/PwnPlantGrowth/Calculate.java
Original file line number Diff line number Diff line change
Expand Up @@ -468,5 +468,6 @@ else if (thisBlock == "KELP") {
}

doLog = toLog + ". ";
return;
}
}
1 change: 1 addition & 0 deletions src/com/pwn9/PwnPlantGrowth/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
7 changes: 2 additions & 5 deletions src/com/pwn9/PwnPlantGrowth/PlayerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {


Expand Down Expand Up @@ -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);
}

}
}
}
}

}
}
Loading

0 comments on commit 3bbcf45

Please sign in to comment.