Skip to content

Commit

Permalink
Update to Spigot 1.16.1.
Browse files Browse the repository at this point in the history
Implement 3d Biome updating.
Minimize 4x4x4 biome cube issue.
Improve default biome config file.
Add biome environment option.
  • Loading branch information
BONNe committed Jun 25, 2020
1 parent 6d22235 commit a8cf13c
Show file tree
Hide file tree
Showing 16 changed files with 536 additions and 120 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<java.version>1.8</java.version>
<powermock.version>2.0.2</powermock.version>
<!-- More visible way how to change dependency versions -->
<spigot.version>1.15.2-R0.1-SNAPSHOT</spigot.version>
<spigot.version>1.16.1-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.14.0-SNAPSHOT</bentobox.version>
<level.version>1.9.3</level.version>
<vault.version>1.7</vault.version>
Expand Down
69 changes: 39 additions & 30 deletions src/main/java/world/bentobox/biomes/BiomesAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,36 +135,45 @@ public void onEnable()

this.registerRequestHandler(new ChangeBiomeRequestHandler(this));

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

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

BiomeChunkUpdateObject updater = iterator.next();

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

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);

// force-load chunk asynchronously
Util.getChunkAtAsync(world, updater.getChunkX(), updater.getChunkZ());
}
}, 5L, 5L);
if (this.settings.getUpdateTickCounter() > 0)
{
// This task will force-load chunk every update tick if its biome is not updated.
Bukkit.getScheduler().runTaskTimer(this.getPlugin(),
() -> {
Iterator<BiomeChunkUpdateObject> iterator =
this.addonManager.getBiomeUpdaterCollection().iterator();

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

BiomeChunkUpdateObject updater = iterator.next();

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

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);

// force-load chunk asynchronously
Util.getChunkAtAsync(world,
updater.getChunkX(),
updater.getChunkZ());
}
},
this.settings.getUpdateTickCounter(),
this.settings.getUpdateTickCounter());
}
}
else
{
Expand Down
28 changes: 26 additions & 2 deletions src/main/java/world/bentobox/biomes/BiomesAddonManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ public boolean loadBiomes(BiomesObject biome, boolean overwrite, User user, bool
return false;
}

// Compatibility fix from older versions.
if (biome.getEnvironment() == null)
{
// If not specified, use over world.
biome.setEnvironment(World.Environment.NORMAL);
}

// Contains in array list is not fast.. but list is not so large, so it is ok there.

if (this.biomesCacheData.containsKey(biome.getUniqueId()))
Expand Down Expand Up @@ -282,13 +289,30 @@ private void readBiomes(YamlConfiguration config, User user, World world, boolea
newBiomeObject.setFriendlyName(details.getString("friendlyName", biome));

newBiomeObject.setDescription(
GuiUtils.stringSplit(details.getString("description", ""),
this.addon.getSettings().getLoreLineLength()));
GuiUtils.stringSplit(details.getString("description", ""),
this.addon.getSettings().getLoreLineLength()));
newBiomeObject.setIcon(ItemParser.parse(details.getString("icon") + ":1"));

newBiomeObject.setRequiredLevel(details.getInt("islandLevel", 0));
newBiomeObject.setRequiredCost(details.getInt("cost", 0));

String environmentValue = details.getString("environment", "normal").toUpperCase();

switch (environmentValue)
{
case "NETHER":
newBiomeObject.setEnvironment(World.Environment.NETHER);
break;
case "THE_END":
newBiomeObject.setEnvironment(World.Environment.THE_END);
break;
default:
newBiomeObject.setEnvironment(World.Environment.NORMAL);
break;
}

newBiomeObject.setOrder(details.getInt("order", 0));

List<String> permissions = details.getStringList("permission");

if (permissions.isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public boolean execute(User user, String label, List<String> args)
user,
targetUser,
biome,
getWorld(),
this.getWorld(),
updateMode,
size,
false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public boolean execute(User user, String label, List<String> args)
user,
user,
biome,
user.getWorld(),
this.getWorld(),
updateMode,
size,
true);
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/world/bentobox/biomes/config/Settings.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package world.bentobox.biomes.config;


import com.google.gson.annotations.Since;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -133,6 +134,16 @@ public boolean isUseProtectionRange()
}


/**
* This method returns the updateTickCounter value.
* @return the value of updateTickCounter.
*/
public int getUpdateTickCounter()
{
return updateTickCounter;
}


// ---------------------------------------------------------------------
// Section: Setters
// ---------------------------------------------------------------------
Expand Down Expand Up @@ -239,6 +250,17 @@ public void setUseProtectionRange(boolean useProtectionRange)
}


/**
* This method sets the updateTickCounter value.
* @param updateTickCounter the updateTickCounter new value.
*
*/
public void setUpdateTickCounter(int updateTickCounter)
{
this.updateTickCounter = updateTickCounter;
}


// ---------------------------------------------------------------------
// Section: Enums used for Settings.
// ---------------------------------------------------------------------
Expand Down Expand Up @@ -432,6 +454,13 @@ public static Lore getLore(String parameter)
@ConfigEntry(path = "cooldown")
private int coolDown = 60;

@ConfigComment("")
@ConfigComment("This indicates tick counter between each background update task.")
@ConfigComment("This process load chunks that require biome update and change biome in it.")
@ConfigComment("Setting 0 will stop background task and biome will be updated only when loaded.")
@ConfigEntry(path = "update-tick-counter", needsRestart = true, since = "1.13.0")
private int updateTickCounter = 5;

@ConfigComment("")
@ConfigComment("This variable allows to choose which biomes users can see in Biomes GUI.")
@ConfigComment("Valid values are:")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,48 @@ public void setMaxZ(int maxZ)
}


/**
* This method returns the minY value.
* @return the value of minY.
*/
public int getMinY()
{
return minY;
}


/**
* This method sets the minY value.
* @param minY the minY new value.
*
*/
public void setMinY(int minY)
{
this.minY = minY;
}


/**
* This method returns the maxY value.
* @return the value of maxY.
*/
public int getMaxY()
{
return maxY;
}


/**
* This method sets the maxY value.
* @param maxY the maxY new value.
*
*/
public void setMaxY(int maxY)
{
this.maxY = maxY;
}


/**
* This method returns the chunkX value.
* @return the value of chunkX.
Expand Down Expand Up @@ -280,6 +322,18 @@ public void setForceLoaded(boolean forceLoaded)
@Expose
private int maxZ;

/**
* Minimal Y coordinate of biome update.
*/
@Expose
private int minY;

/**
* Maximal Y coordinate of biome update.
*/
@Expose
private int maxY;

/**
* Chunk X coordinate.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package world.bentobox.biomes.database.objects;


import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;

import org.bukkit.Material;
import org.bukkit.World;
Expand Down Expand Up @@ -260,6 +257,27 @@ public void setRequiredPermissions(Set<String> requiredPermissions)
}


/**
* This method returns the environment value.
* @return the value of environment.
*/
public World.Environment getEnvironment()
{
return this.environment;
}


/**
* This method sets the environment value.
* @param environment the environment new value.
*
*/
public void setEnvironment(World.Environment environment)
{
this.environment = environment;
}


// ---------------------------------------------------------------------
// Section: Other methods
// ---------------------------------------------------------------------
Expand Down Expand Up @@ -317,10 +335,16 @@ else if (this.uniqueId == null || other.getUniqueId() == null)
@Override
public int compareTo(BiomesObject object)
{
int rc = Integer.compare(this.order, object.getOrder());

return this.biome != null && object.getBiome() != null && rc == 0 ?
this.biome.compareTo(object.getBiome()) : rc;
// Compare by order
return Comparator.comparingInt(BiomesObject::getOrder).
// Compare by environment
thenComparing(BiomesObject::getEnvironment).
// compare by biome
thenComparing(BiomesObject::getBiome).
// compare by friendly name
thenComparing(BiomesObject::getFriendlyName).
// Provide objects
compare(this, object);
}


Expand Down Expand Up @@ -369,6 +393,10 @@ public int compareTo(BiomesObject object)
@Expose
private String world;

@ConfigComment("Allows to specify environment for biome. This allows to split overworld, nether and the end biomes.")
@Expose
private World.Environment environment;

@ConfigComment("Unique StringName of the biome")
@Expose
private String uniqueId;
Expand Down

0 comments on commit a8cf13c

Please sign in to comment.