Skip to content

Commit

Permalink
issue #7 - extend to the other listeners and make a few tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
msudol committed Mar 23, 2020
1 parent 2097950 commit 48d7bb2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 710 deletions.
263 changes: 0 additions & 263 deletions src/com/pwn9/PwnPlantGrowth/BlockGrowListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,268 +26,6 @@ static Calculate getCalcs(List<List<String>> specialBlocks, String thisBlock, St
return new Calculate(specialBlocks, thisBlock, curBiome, isDark);
}

// called to run the calculations and determine what happens to the plant on the event
public String runCalcs(BlockGrowEvent e, String thisBlock, String curBiome, Boolean isDark)
{
String toLog = "";
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
boolean noBiome = true;

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

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

// check the biome group settings
if (plugin.getConfig().isSet(thisBlock+".BiomeGroup"))
{

// create list from the config setting
List<?> groupList = plugin.getConfig().getList(thisBlock+".BiomeGroup");

groupLog += "BiomeGroup: " + groupList.toString() + ", ";

// iterate through list and see if any of that list matches curBiome
boolean matches = false;
for (int i = 0; i < groupList.size(); i++)
{

// check the biomegroup for this named group
if ((plugin.getConfig().getList("BiomeGroup."+groupList.get(i)) != null) && (plugin.getConfig().getList("BiomeGroup."+groupList.get(i)).contains(curBiome)))
{
matches = true;
noBiome = false;
groupLog += "Matches: " + groupList.get(i) + ", ";

// reference the configs now to see if the config settings are set!
if (plugin.getConfig().isSet(thisBlock+"."+groupList.get(i)+".Growth"))
{
curGrowth = plugin.getConfig().getInt(thisBlock+"."+groupList.get(i)+".Growth");
groupLog += "New Growth: " + curGrowth + ", ";
}

if (plugin.getConfig().isSet(thisBlock+"."+groupList.get(i)+".Death"))
{
curDeath = plugin.getConfig().getInt(thisBlock+"."+groupList.get(i)+".Death");
groupLog += "New Death: " + curDeath + ", ";
}
}
}
if (!matches) {
groupLog += "Matches: NULL, ";
}
}
else {
groupLog += "BiomeGroup: NULL, ";
}

groupLog += "Specific Settings: {";

if (plugin.getConfig().getList(thisBlock+".Biome").contains(curBiome)) {
noBiome = false;
// override with individual settings
if (plugin.getConfig().isSet(thisBlock+"."+curBiome+".Growth"))
{
curGrowth = plugin.getConfig().getInt(thisBlock+"."+curBiome+".Growth");
groupLog += "Growth for " + curBiome + ": " + curGrowth + ", ";
}

if (plugin.getConfig().isSet(thisBlock+"."+curBiome+".Death"))
{
curDeath = plugin.getConfig().getInt(thisBlock+"."+curBiome+".Death");
groupLog += "Death for " + curBiome + ": " + curDeath + ", ";
}
}

// 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))
{
groupLog += PwnPlantGrowth.fertFound;
// set the current growth to the fertilizer rate
curGrowth = PwnPlantGrowth.frate;
}
groupLog += "}}, ";

// See if there are special settings for dark growth
if (isDark)
{
// If uv is enabled and found, isDark remains false.
if (uvBlocksFound.contains(PwnPlantGrowth.uv))
{
darkLog += PwnPlantGrowth.uvFound;
}
else
{
// default isDark config rates (if exist)
if (plugin.getConfig().isSet(thisBlock+".GrowthDark"))
{
curGrowth = plugin.getConfig().getInt(thisBlock+".GrowthDark");
darkLog += "Growth: " + curGrowth + ", ";
}

if (plugin.getConfig().isSet(thisBlock+".DeathDark"))
{
curDeath = plugin.getConfig().getInt(thisBlock+".DeathDark");
darkLog += "Death: " + curDeath + ", ";
}

// override default values with biome group values
if (plugin.getConfig().isSet(thisBlock+".BiomeGroup"))
{

// create list from the config setting
List<?> groupList = plugin.getConfig().getList(thisBlock+".BiomeGroup");

darkLog += "BiomeGroup: " + groupList.toString() + ", ";

// iterate through list and see if any of that list matches curBiome
boolean matches = false;
for (int i = 0; i < groupList.size(); i++) {

// check the biomegroup for this named group
if ((plugin.getConfig().getList("BiomeGroup."+groupList.get(i)) != null) && (plugin.getConfig().getList("BiomeGroup."+groupList.get(i)).contains(curBiome)))
{

matches = true;
noBiome = false;
darkLog += "Matching: " + groupList.get(i) + ", ";

// reference the configs now to see if the config settings are set!
if (plugin.getConfig().isSet(thisBlock+"."+groupList.get(i)+".GrowthDark"))
{
curGrowth = plugin.getConfig().getInt(thisBlock+"."+groupList.get(i)+".GrowthDark");
darkLog += "New Growth: " + curGrowth + ", ";
}

if (plugin.getConfig().isSet(thisBlock+"."+groupList.get(i)+".DeathDark"))
{
curDeath = plugin.getConfig().getInt(thisBlock+"."+groupList.get(i)+".DeathDark");
darkLog += "New Death: " + curDeath + ", ";
}
}
}
if (!matches) {
darkLog += "Matches: NULL, ";
}
}
else {
darkLog += "BiomeGroup: NULL, ";
}

darkLog += "Specific Settings: {";

// per biome isDark rates (if exist)
if (plugin.getConfig().getList(thisBlock+".Biome").contains(curBiome)) {
noBiome = false;
if (plugin.getConfig().isSet(thisBlock+"."+curBiome+".GrowthDark"))
{
curGrowth = plugin.getConfig().getInt(thisBlock+"."+curBiome+".GrowthDark");
darkLog += "Growth for " + curBiome + ": " + curGrowth + ", ";
}

if (plugin.getConfig().isSet(thisBlock+"."+curBiome+".DeathDark"))
{
curDeath = plugin.getConfig().getInt(thisBlock+"."+curBiome+".DeathDark");
darkLog += "Death for " + curBiome + ": " + curDeath + ", ";
}
}

darkLog += "}}, ";
}
}

// cancel bad biomes here
if (noBiome)
{
e.setCancelled(true);
toLog += "RESULT: {Failed Growth: Bad Biome}";
// chance of death
if (PwnPlantGrowth.random(curDeath))
{
// TODO: make these configurable
if (thisBlock == "COCOA") {
e.getBlock().setType(Material.VINE);
}
else {
e.getBlock().setType(Material.DEAD_BUSH);
}
toLog += " {Plant Died, Rate: " + curDeath + "}";
}
}
// Run the chance for growth here...
else if (!(PwnPlantGrowth.random(curGrowth)))
{
e.setCancelled(true);
toLog += "RESULT: {Failed Growth, Rate: " + curGrowth + "} ";

if (wkBlocksFound.contains(PwnPlantGrowth.weedKiller))
{
toLog += PwnPlantGrowth.wkFound;
}
else
{
// chance of death
if (PwnPlantGrowth.random(curDeath))
{
// TODO: make these configurable
if (thisBlock == "COCOA") {
e.getBlock().setType(Material.VINE);
}
else {
e.getBlock().setType(Material.DEAD_BUSH);
}
toLog += " {Plant Died, Rate: " + curDeath + "}";
}
}
}
else
{
toLog += "RESULT: {Plant Grew, Rate: " + curGrowth + "}";

}
}
else
{
e.setCancelled(true);
toLog += "RESULT: {Failed Growth: Bad Biome}";
// chance of death
if (PwnPlantGrowth.random(curDeath))
{
// TODO: make these configurable
if (thisBlock == "COCOA") {
Material replace = Material.VINE;
e.getBlock().setType(replace);
}
else {
e.getBlock().setType(Material.DEAD_BUSH);
}
toLog += " {Plant Died, Rate: " + curDeath + "}";
}
}

String midLog = "";
if (isDark) {
midLog += darkLog;
}
else {
midLog += groupLog;
}

return frontLog + midLog + ", "+ toLog;
}

// retrieve list of special blocks
public List<List<String>> specialBlockList(BlockGrowEvent e)
{
Expand Down Expand Up @@ -417,7 +155,6 @@ public void plantGrow(BlockGrowEvent e)
if (curBlock != "AIR")
{
// run calcs
//toLog += runCalcs(e, curBlock, curBiome, isDark);
Calculate cal = getCalcs(specialBlockList(e), curBlock, curBiome, isDark);
toLog += cal.doLog;
e.setCancelled(cal.isCancelled);
Expand Down
Loading

0 comments on commit 48d7bb2

Please sign in to comment.