Skip to content

Commit

Permalink
Removes an ability to change biome in Greenhouses.
Browse files Browse the repository at this point in the history
It was considered as a bug and it is fixed now.
  • Loading branch information
BONNe committed Sep 22, 2020
1 parent a1a592d commit 0f91da6
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 50 deletions.
9 changes: 8 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@
<powermock.version>2.0.2</powermock.version>
<!-- More visible way how to change dependency versions -->
<spigot.version>1.16.1-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.14.0-SNAPSHOT</bentobox.version>
<bentobox.version>1.14.0</bentobox.version>
<level.version>2.4.0-SNAPSHOT</level.version>
<greenhouses.version>1.4.0-SNAPSHOT</greenhouses.version>
<vault.version>1.7</vault.version>
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
Expand Down Expand Up @@ -159,6 +160,12 @@
<version>${level.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>world.bentobox</groupId>
<artifactId>Greenhouses</artifactId>
<version>${greenhouses.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
Expand Down
151 changes: 106 additions & 45 deletions src/main/java/world/bentobox/biomes/BiomesAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import world.bentobox.biomes.handlers.ChangeBiomeRequestHandler;
import world.bentobox.biomes.listeners.ChangeOwnerListener;
import world.bentobox.biomes.listeners.ChunkLoadListener;
import world.bentobox.greenhouses.Greenhouses;
import world.bentobox.level.Level;


Expand Down Expand Up @@ -64,16 +65,15 @@ public void onEnable()
return;
}

hookInGameModes();
this.hookInGameModes();

if (this.hooked)
{
setupAddon();
this.setupAddon();
}
else
{
this.logError(
"Biomes could not hook into any GameMode so will not do anything!");
this.logError("Biomes could not hook into any GameMode so will not do anything!");
this.setState(State.DISABLED);
}
}
Expand All @@ -87,11 +87,13 @@ private void setupAddon() {
this.addonManager = new BiomesAddonManager(this);

// Try to find Level addon and if it does not exist, display a warning
findLevelAddon();
this.findLevelAddon();
// Try to find Greenhouses addon
this.findGreenhousesAddon();
// Try to find Economy Plugin
this.findVaultPlugin();

findVaultPlugin();

// Register the reset listener
// Register the reset listener
this.registerListener(new ChangeOwnerListener(this));
this.registerListener(new ChunkLoadListener(this));

Expand All @@ -108,79 +110,88 @@ private void setupAddon() {
if (this.settings.getUpdateTickCounter() > 0)
{
// This task will force-load chunk every update tick if its biome is not updated.
runChunkUpdatingScheduler();
this.runChunkUpdatingScheduler();
}

}


/**
* This task will force-load chunk every update tick if its biome is not updated.
*/
private void runChunkUpdatingScheduler() {
Bukkit.getScheduler().runTaskTimer(this.getPlugin(), () -> {
Iterator<BiomeChunkUpdateObject> iterator =
private void runChunkUpdatingScheduler()
{
Bukkit.getScheduler().runTaskTimer(this.getPlugin(), () -> {
Iterator<BiomeChunkUpdateObject> iterator =
this.addonManager.getBiomeUpdaterCollection().iterator();

// if there is nothing to load, then skip.
if (!iterator.hasNext())
{
return;
}
// if there is nothing to load, then skip.
if (!iterator.hasNext())
{
return;
}

BiomeChunkUpdateObject updater = iterator.next();
BiomeChunkUpdateObject updater = iterator.next();

// if chunk is already force-loaded, then skip.
while (iterator.hasNext() && updater.isForceLoaded())
{
updater = iterator.next();
}
// if chunk is already force-loaded, then skip.
while (iterator.hasNext() && updater.isForceLoaded())
{
updater = iterator.next();
}

World world = updater.getWorld();
World world = updater.getWorld();

// if chunk is loaded then skip.
if (!world.isChunkLoaded(updater.getChunkX(), updater.getChunkZ()))
{
// Set flag as force-loaded.
updater.setForceLoaded(true);
// if chunk is loaded then skip.
if (!world.isChunkLoaded(updater.getChunkX(), updater.getChunkZ()))
{
// Set flag as force-loaded.
updater.setForceLoaded(true);

// force-load chunk asynchronously
Util.getChunkAtAsync(world,
// force-load chunk asynchronously
Util.getChunkAtAsync(world,
updater.getChunkX(),
updater.getChunkZ());
}
},
this.settings.getUpdateTickCounter(),
this.settings.getUpdateTickCounter());
}
},

this.settings.getUpdateTickCounter(),
this.settings.getUpdateTickCounter());
}


private void findVaultPlugin() {
/**
* This is silly method that was introduced to reduce main method complexity, and just reports
* if economy is enabled or not.
*/
private void findVaultPlugin()
{
Optional<VaultHook> vault = this.getPlugin().getVault();

if (!vault.isPresent() || !vault.get().hook())
{
this.vaultHook = null;
this.logWarning(
"Economy plugin not found so money requirements will be ignored!");
"Economy plugin not found so money requirements will be ignored!");
}
else
{
this.economyProvided = true;
this.vaultHook = vault.get();
}

}


private void findLevelAddon() {
/**
* This is silly method that was introduced to reduce main method complexity, and just reports
* if level addon is enabled or not.
*/
private void findLevelAddon()
{
Optional<Addon> level = this.getAddonByName("Level");

if (!level.isPresent())
{
this.logWarning(
"Level add-on not found so level requirements will be ignored!");
"Level add-on not found so level requirements will be ignored!");
this.levelAddon = null;
this.levelProvided = false;
}
Expand All @@ -192,7 +203,27 @@ private void findLevelAddon() {
}


private void hookInGameModes() {
/**
* This is silly method that was introduced to reduce main method complexity, and just reports
* if greenhouses is enabled or not.
*/
private void findGreenhousesAddon()
{
Optional<Addon> greenhouses = this.getAddonByName("Greenhouses");

if (greenhouses.isPresent())
{
this.greenhousesProvided = true;
this.greenhouses = (Greenhouses) greenhouses.get();
}
}


/**
* This method hooks commands and flags into each GameModeAddon.
*/
private void hookInGameModes()
{
this.getPlugin().getAddonsManager().getGameModeAddons().forEach(gameModeAddon -> {
if (!this.settings.getDisabledGameModes().contains(gameModeAddon.getDescription().getName()))
{
Expand Down Expand Up @@ -338,9 +369,29 @@ public boolean isLevelProvided()
}


// ---------------------------------------------------------------------
// Section: Variables
// ---------------------------------------------------------------------
/**
* This method returns the Greenhouses value.
* @return the value of Greenhouses.
*/
public Greenhouses getGreenhouses()
{
return this.greenhouses;
}


/**
* This method returns the greenhousesProvided value.
* @return the value of greenhousesProvided.
*/
public boolean isGreenhousesProvided()
{
return this.greenhousesProvided;
}


// ---------------------------------------------------------------------
// Section: Variables
// ---------------------------------------------------------------------


/**
Expand Down Expand Up @@ -378,6 +429,16 @@ public boolean isLevelProvided()
*/
private boolean levelProvided;

/**
* Greenhouses addon.
*/
private Greenhouses greenhouses;

/**
* This indicate if greenhouses addon exists.
*/
private boolean greenhousesProvided;


// ---------------------------------------------------------------------
// Section: Flags
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/world/bentobox/biomes/BiomesAddonManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.TreeMap;
import java.util.stream.Collectors;

import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.configuration.ConfigurationSection;
Expand Down Expand Up @@ -618,6 +619,22 @@ public boolean hasAnyBiome(World world)
}


/**
* This method returns true if in given location exit a greenhouse.
* @param world World where greenhouse must be searched.
* @param x X location.
* @param y Y location.
* @param z Z location.
* @return {@code true} if in given location exist a greenhouse, {@code false} otherwise.
*/
public boolean hasGreenhouseInLocation(World world, int x, int y, int z)
{
return this.addon.isGreenhousesProvided() &&
this.addon.getGreenhouses().getManager().getMap().
inGreenhouse(new Location(world, x, y, z));
}


// ---------------------------------------------------------------------
// Section: Later Biome Updater
// ---------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ public void onChunkLoad(ChunkLoadEvent event)
{
for (int y = updateObject.getMinY(); y <= updateObject.getMaxY(); y += 4)
{
// Change Biome
updateObject.getWorld().setBiome(x, y, z, updateObject.getBiome());
// Biome should not be changed in Greenhouses.
if (!this.addon.getAddonManager().
hasGreenhouseInLocation(updateObject.getWorld(), x, y, z))
{
// Change Biome
updateObject.getWorld().setBiome(x, y, z, updateObject.getBiome());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,13 @@ public void run()
}
else
{
// Change Biome
updateObject.getWorld().setBiome(x, y, z, this.biome);
// Biome should not be changed in Greenhouses.
if (!this.addon.getAddonManager().
hasGreenhouseInLocation(updateObject.getWorld(), x, y, z))
{
// Change Biome
updateObject.getWorld().setBiome(x, y, z, this.biome);
}
}
}
}
Expand Down

0 comments on commit 0f91da6

Please sign in to comment.