Skip to content

Commit

Permalink
fix all the things
Browse files Browse the repository at this point in the history
  • Loading branch information
msudol committed May 21, 2020
1 parent e6f2bad commit a82ba29
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 22 deletions.
2 changes: 1 addition & 1 deletion config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ COCOA:
- JUNGLE_HILLS
- JUNGLE_EDGE

# In this example grass, tallgrass, bonemeal used on grass - will grow anywhere - Biome: [] - but only at 50%
# In this example grass, tallgrass, bonemeal used on grass - will grow anywhere - Biome: [] - but only at 50% (also handles GRASS_BLOCK?)
GRASS:
Growth: 50
Death: 0
Expand Down
6 changes: 3 additions & 3 deletions src/com/pwn9/PwnPlantGrowth/BlockGrowListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ else if ((e.getBlock().getRelative(BlockFace.EAST).getType() == Material.PUMPKIN
}
}
// Handle Cactus, Sugar Cane; the plants that grow vertically only.
else if (faceBlock == "MELON" || faceBlock == "PUMPKING")
else if (faceBlock == "MELON" || faceBlock == "PUMPKIN")
{

toLog += faceBlock;
Expand Down Expand Up @@ -235,11 +235,11 @@ else if (downBlock == "GRASS" || downBlock == "GRASS_BLOCK" || downBlock == "TAL
}
}

// An unknown block growth event from AIR has occurred
// An unknown block growth event from AIR has occurred - log to main log for debugging
else
{
// were not sure what has happened so log it and let it grow, maybe a new plant we haven't caught yet.
toLog += downBlock + " as UNKNOWN EVENT";
toLog += "on " + downBlock + " as UNKNOWN EVENT at location: " + coords;
// Log it
if (PwnPlantGrowth.logEnabled)
{
Expand Down
4 changes: 2 additions & 2 deletions src/com/pwn9/PwnPlantGrowth/BlockSpreadListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public List<List<String>> specialBlockList(BlockSpreadEvent e)
return result;
}

// Listen for plant growth and then do stuff
// Listen for plant growth from block spread, this is like chorus plant, and then do stuff
@EventHandler(ignoreCancelled = false)
public void blockSpread(BlockSpreadEvent e)
{
Expand All @@ -97,7 +97,7 @@ public void blockSpread(BlockSpreadEvent e)
// Get source block type and make a string for comparison later
String sourceBlock = String.valueOf(e.getSource().getType());

// we only care about these 2 for now
// we only care about these for now
if (sourceBlock != "CHORUS_FLOWER" && sourceBlock != "KELP" && sourceBlock != "BAMBOO" && sourceBlock != "BAMBOO_SAPLING")
{
return;
Expand Down
44 changes: 35 additions & 9 deletions src/com/pwn9/PwnPlantGrowth/Calculate.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,27 @@ public class Calculate {
String frontLog = ", Biome: " + curBiome + ", Dark: " + isDark.toString() + ", ";
String darkLog = "Dark Settings: {";
String groupLog = "Settings: {";

// bool to catch if the biome is never declared in any config, therefor a bad biome and should not grow
// not true - i'm an idiot, the null biome is ok to have actually and means default growth
boolean noBiome = true;

int curGrowth = PwnPlantGrowth.instance.getConfig().getInt(thisBlock+".Growth");
frontLog += "Default Growth: " + curGrowth + ", ";
int curDeath = PwnPlantGrowth.instance.getConfig().getInt(thisBlock+".Death");
frontLog += "Default Death: " + curDeath + ", ";


if ((PwnPlantGrowth.instance.getConfig().isSet(thisBlock+".BiomeGroup")) || (PwnPlantGrowth.instance.getConfig().getList(thisBlock+".Biome").isEmpty()) || (PwnPlantGrowth.instance.getConfig().getList(thisBlock+".Biome").contains(curBiome)))
{
// check the area to find if any of the special blocks are found
List<String> fBlocksFound = specialBlocks.get(0);
List<String> wkBlocksFound = specialBlocks.get(1);
List<String> uvBlocksFound = specialBlocks.get(2);

// check the biome group settings


// check the biome group settings if they are set.
if (PwnPlantGrowth.instance.getConfig().isSet(thisBlock+".BiomeGroup"))
{

Expand Down Expand Up @@ -76,6 +81,9 @@ public class Calculate {

groupLog += "Specific Settings: {";



// BIOME SETTINGS - if per biome is set, it overrides a biome group
if (PwnPlantGrowth.instance.getConfig().getList(thisBlock+".Biome").contains(curBiome)) {
noBiome = false;
// override with individual settings
Expand All @@ -92,6 +100,9 @@ public class Calculate {
}
}




// if there is fertilizer, grow this plant at the fertilizer rate - default 100%
// TODO: should fertilizer override dark settings or not - i think not for now
if (fBlocksFound.contains(PwnPlantGrowth.fertilizer))
Expand All @@ -102,6 +113,9 @@ public class Calculate {
}
groupLog += "}}, ";




// See if there are special settings for dark growth
if (isDark)
{
Expand All @@ -112,7 +126,7 @@ public class Calculate {
}
else
{
// default isDark config rates (if exist)
// ISDARK: default isDark config rates (if exist)
if (PwnPlantGrowth.instance.getConfig().isSet(thisBlock+".GrowthDark"))
{
curGrowth = PwnPlantGrowth.instance.getConfig().getInt(thisBlock+".GrowthDark");
Expand All @@ -125,7 +139,9 @@ public class Calculate {
darkLog += "Death: " + curDeath + ", ";
}

// override default values with biome group values


// ISDARK: override default values with biome group values
if (PwnPlantGrowth.instance.getConfig().isSet(thisBlock+".BiomeGroup"))
{

Expand Down Expand Up @@ -170,7 +186,7 @@ public class Calculate {

darkLog += "Specific Settings: {";

// per biome isDark rates (if exist)
// ISDARK: per biome isDark rates (if exist) override biomegroup rates
if (PwnPlantGrowth.instance.getConfig().getList(thisBlock+".Biome").contains(curBiome)) {
noBiome = false;
if (PwnPlantGrowth.instance.getConfig().isSet(thisBlock+"."+curBiome+".GrowthDark"))
Expand All @@ -190,7 +206,13 @@ public class Calculate {
}
}

// cancel bad biomes here
// if BIOME was left empty, BIOME: [] it was intentional.. and this means use default growth rate.
if ((PwnPlantGrowth.instance.getConfig().getList(thisBlock+".Biome").isEmpty())) {
noBiome = false;
}


// check config again - nobiome means the plant had no config available anywhere not even empty/default
if (noBiome)
{
isCancelled = true;
Expand Down Expand Up @@ -278,7 +300,7 @@ else if (thisBlock == "KELP") {
doLog = frontLog + midLog + toLog;
}

// just report the rate for listerner feature
// just report the rate for player listener feature for growth rates
Calculate(Boolean report, List<List<String>> specialBlocks, String thisBlock, String curBiome, Boolean isDark)
{
isCancelled = false;
Expand Down Expand Up @@ -402,7 +424,6 @@ else if (thisBlock == "KELP") {
}
}
}


// per biome isDark rates (if exist)
if (PwnPlantGrowth.instance.getConfig().getList(thisBlock+".Biome").contains(curBiome)) {
Expand All @@ -420,14 +441,19 @@ else if (thisBlock == "KELP") {
}
}
}

// if BIOME was left empty, BIOME: [] it was intentional.. and this means use default growth rate.
if ((PwnPlantGrowth.instance.getConfig().getList(thisBlock+".Biome").isEmpty())) {
noBiome = false;
}

if (noBiome)
{
toLog += thisBlock + " will not grow in biome: " + curBiome;
}
else
{
toLog += thisBlock + " grows at " + curGrowth + "% at this location in biome " + curBiome;
toLog += thisBlock + " grows at " + curGrowth + "% in biome " + curBiome;
if (isDark)
{
toLog += " in the dark";
Expand All @@ -442,6 +468,6 @@ else if (thisBlock == "KELP") {
}
}

doLog = toLog;
doLog = toLog + ". ";
}
}
19 changes: 16 additions & 3 deletions src/com/pwn9/PwnPlantGrowth/PlayerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.ArrayList;
import java.util.List;

import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
Expand Down Expand Up @@ -113,7 +115,6 @@ public void checkBlockClick(PlayerInteractEvent e)

Block block = e.getClickedBlock();


if (block.getType() == Material.FARMLAND || block.getType() == Material.DIRT || block.getType() == Material.GRASS_BLOCK || block.getType() == Material.JUNGLE_LOG || block.getType() == Material.SAND || block.getType() == Material.SOUL_SAND)
{

Expand Down Expand Up @@ -141,7 +142,13 @@ public void checkBlockClick(PlayerInteractEvent e)
Calculate cal = getCalcs(true, specialBlockList(e), m.toString(), curBiome, isDark);
a += cal.doLog;

p.sendMessage(PwnPlantGrowth.msgFormat + a);
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
if (p.getGameMode() == GameMode.CREATIVE) {
e.setCancelled(true);
}

}
else if(PwnPlantGrowth.seedTypes.contains(m.toString())) {
Expand Down Expand Up @@ -183,7 +190,13 @@ else if (m == Material.WHEAT_SEEDS) {
a += cal.doLog;
}

p.sendMessage(PwnPlantGrowth.msgFormat + a);
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
if (p.getGameMode() == GameMode.CREATIVE) {
e.setCancelled(true);
}

}
}
Expand Down
9 changes: 5 additions & 4 deletions src/com/pwn9/PwnPlantGrowth/PwnPlantGrowth.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,23 +281,24 @@ public static String getBiome(StructureGrowEvent e)
}
}


// 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)
{
String tControl = TerrainControl.getBiomeName(e.getPlayer().getWorld().getName(), e.getPlayer().getLocation().getBlockX(), e.getPlayer().getLocation().getBlockZ());
//String tControl = TerrainControl.getBiomeName(e.getPlayer().getWorld().getName(), e.getPlayer().getLocation().getBlockX(), e.getPlayer().getLocation().getBlockZ());
String tControl = TerrainControl.getBiomeName(e.getPlayer().getWorld().getName(), e.getClickedBlock().getLocation().getBlockX(), e.getClickedBlock().getLocation().getBlockZ());
if (tControl != null)
{
return tControl;
}
else
{
return String.valueOf(e.getPlayer().getLocation().getBlock().getBiome());
return String.valueOf(e.getClickedBlock().getBiome());
}
}
else
{
return String.valueOf(e.getPlayer().getLocation().getBlock().getBiome());
return String.valueOf(e.getClickedBlock().getBiome());
}
}

Expand Down

0 comments on commit a82ba29

Please sign in to comment.