Skip to content

Commit

Permalink
Merge pull request #56 from BentoBoxWorld/develop
Browse files Browse the repository at this point in the history
Release 2.3.0
  • Loading branch information
tastybento authored Jul 11, 2023
2 parents eb3777c + 5174297 commit 470f893
Show file tree
Hide file tree
Showing 27 changed files with 634 additions and 202 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 17
uses: actions/setup-java@v1
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: 17
- name: Cache SonarCloud packages
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ A game mode where you are boxed into a tiny space that only expands by completin

## BentoBox Requirements

* Requires BentoBox 1.16.0 or later (Snapshots can be downloaded here: [https://ci.bentobox.world](https://ci.bentobox.world))
* Requires BentoBox 1.23.0 or later (Snapshots can be downloaded here: [https://ci.bentobox.world](https://ci.bentobox.world))
* InvSwitcher - keeps advancements, inventory, etc. separate between worlds on a server.
* Border - shows the box

## Required Plugins

* Requires WorldGeneratorAPI plugin. [Download the correct one for your server here.](https://github.com/rutgerkok/WorldGeneratorApi/releases)
* Border requires WorldBorderAPI by default. [Download it here.](https://github.com/yannicklamprecht/WorldBorderAPI/releases)
### Warning!!
Boxed requires **a lot of RAM** and can take up to **10 minutes** to boot up for the first time as it pre-generates the worlds. After the initial start, it will start up much quicker. With 12GB of RAM running on a fast ARM-based system, it takes ~ 8 minutes for the first boot. If you do not have enough RAM then weird things will happen to you server including strange errors about chunks and things like that. To dedicate enough RAM to your JVM, use the correct flags during startup. Here is my `start.sh` for running on Paper 1.19.4:
```
#!/bin/sh
java -Xms12G -Xmx12G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:InitiatingHeapOccupancyPercent=15 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true -jar paper-1.19.4.jar nogui
```

## How to install

Expand Down
9 changes: 5 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@
<!-- Non-minecraft related dependencies -->
<powermock.version>2.0.9</powermock.version>
<!-- More visible way how to change dependency versions -->
<spigot.version>1.19.4-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.23.0</bentobox.version>
<spigot.version>1.20.1-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.24.0</bentobox.version>
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
<!-- This allows to change between versions. -->
<build.version>2.1.1</build.version>
<build.version>2.3.0</build.version>

<sonar.projectKey>BentoBoxWorld_Boxed</sonar.projectKey>
<sonar.organization>bentobox-world</sonar.organization>
Expand Down Expand Up @@ -254,6 +254,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<!--suppress MavenModelInspection -->
<configuration>
<argLine>
${argLine}
Expand Down Expand Up @@ -338,7 +339,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<version>0.8.10</version>
<configuration>
<append>true</append>
<excludes>
Expand Down
1 change: 1 addition & 0 deletions src/main/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.DS_Store
12 changes: 4 additions & 8 deletions src/main/java/world/bentobox/boxed/AdvancementsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import world.bentobox.bentobox.database.Database;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.util.Util;
import world.bentobox.boxed.objects.IslandAdvancements;

/**
Expand All @@ -34,7 +33,7 @@ public class AdvancementsManager {
// Database handler for level data
private final Database<IslandAdvancements> handler;
// A cache of island levels.
private final Map<String, IslandAdvancements> cache;
private final Map<String, IslandAdvancements> cache = new HashMap<>();
private final YamlConfiguration advConfig;
private int unknownAdvChange;
private int unknownRecipeChange;
Expand All @@ -48,8 +47,6 @@ public AdvancementsManager(Boxed addon) {
// Set up the database handler to store and retrieve data
// Note that these are saved by the BentoBox database
handler = new Database<>(addon, IslandAdvancements.class);
// Initialize the cache
cache = new HashMap<>();
// Advancement score sheet
addon.saveResource("advancements.yml", false);
advConfig = new YamlConfiguration();
Expand Down Expand Up @@ -185,7 +182,7 @@ public int checkIslandSize(Island island) {
* @return score for advancement. 0 if the advancement was not added.
*/
public int addAdvancement(Player p, Advancement advancement) {
if (!addon.getOverWorld().equals(Util.getWorld(p.getWorld()))) {
if (!addon.inWorld(p.getWorld())) {
// Wrong world
return 0;
}
Expand Down Expand Up @@ -240,7 +237,7 @@ public int getScore(String key) {
/**
* Get the score for this advancement
* @param a - advancement
* @return score of advancement, or 0 if cannot be worked out
* @return score of advancement, or 0 if it cannot be worked out
*/
public int getScore(Advancement a) {
String adv = "advancements." + a.getKey().getKey();
Expand All @@ -255,8 +252,7 @@ public int getScore(Advancement a) {
if (!a.getKey().getKey().contains("recipes") && a.getDisplay() != null) {
float x = a.getDisplay().getX();
float y = a.getDisplay().getY();
int score = (int) Math.round(Math.sqrt(x * x + y * y));
return score;
return (int) Math.round(Math.sqrt(x * x + y * y));
} else {
return 0;
}
Expand Down
86 changes: 58 additions & 28 deletions src/main/java/world/bentobox/boxed/Boxed.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package world.bentobox.boxed;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.bukkit.Bukkit;
import org.bukkit.Difficulty;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.WorldCreator;
import org.bukkit.entity.SpawnCategory;
import org.bukkit.generator.BiomeProvider;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;

import world.bentobox.bentobox.api.addons.GameModeAddon;
Expand All @@ -21,13 +25,14 @@
import world.bentobox.bentobox.api.flags.Flag;
import world.bentobox.bentobox.api.flags.Flag.Mode;
import world.bentobox.bentobox.api.flags.Flag.Type;
import world.bentobox.bentobox.api.hooks.Hook;
import world.bentobox.bentobox.hooks.WorldManagementHook;
import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.boxed.commands.AdminPlaceStructureCommand;
import world.bentobox.boxed.generators.biomes.BoxedBiomeGenerator;
import world.bentobox.boxed.generators.biomes.NetherSeedBiomeGenerator;
import world.bentobox.boxed.generators.biomes.SeedBiomeGenerator;
import world.bentobox.boxed.generators.chunks.AbstractBoxedChunkGenerator;
import world.bentobox.boxed.generators.chunks.BoxedBlockPopulator;
import world.bentobox.boxed.generators.chunks.BoxedChunkGenerator;
import world.bentobox.boxed.generators.chunks.BoxedSeedChunkGenerator;
import world.bentobox.boxed.listeners.AdvancementListener;
Expand Down Expand Up @@ -61,13 +66,10 @@ public class Boxed extends GameModeAddon {
private final Config<Settings> configObject = new Config<>(this, Settings.class);
private AdvancementsManager advManager;
private AbstractBoxedChunkGenerator netherChunkGenerator;
private World baseWorld;
private World baseWorldNether;
private World seedWorld;
private World seedWorldNether;
private final Map<World, ChunkGenerator> generatorMap = new HashMap<>();
//private World seedWorldEnd;
private BiomeProvider boxedBiomeProvider;
private BlockPopulator boxedBlockPopulator;

@Override
public void onLoad() {
Expand Down Expand Up @@ -180,29 +182,32 @@ private void createNether(String worldName) {
log("Creating Boxed Seed Nether world ...");
// This creates a vanilla base world with biomes
AbstractBoxedChunkGenerator seedBaseGen = new BoxedSeedChunkGenerator(this, Environment.NETHER);
baseWorldNether = WorldCreator
.name(worldName + "/" + SEED+NETHER+BASE)
World baseWorldNether = WorldCreator
.name(worldName + "/" + SEED + NETHER + BASE)
.generator(seedBaseGen)
.environment(Environment.NETHER)
.seed(getSettings().getSeed())
.createWorld();
baseWorldNether.setDifficulty(Difficulty.PEACEFUL);
baseWorldNether.setSpawnLocation(settings.getSeedX(), 64, settings.getSeedZ());
generatorMap.put(baseWorldNether, seedBaseGen);
getPlugin().getIWM().addWorld(baseWorldNether, this);
copyChunks(baseWorldNether, seedBaseGen);
// Create seed world
// This copies a base world with custom biomes
log("Creating Boxed Biomed Nether world ...");

seedWorldNether = WorldCreator
.name(worldName + "/" + SEED+NETHER)
.generator(new BoxedSeedChunkGenerator(this, Environment.NETHER, new NetherSeedBiomeGenerator(this, seedBaseGen)))
BoxedSeedChunkGenerator seedWorldNetherGenerator = new BoxedSeedChunkGenerator(this, Environment.NETHER, new NetherSeedBiomeGenerator(this, seedBaseGen));
World seedWorldNether = WorldCreator
.name(worldName + "/" + SEED + NETHER)
.generator(seedWorldNetherGenerator)
.environment(Environment.NETHER)
.seed(getSettings().getSeed())
.createWorld();
seedWorldNether.setDifficulty(Difficulty.EASY);

seedWorldNether.setSpawnLocation(settings.getNetherSeedX(), 64, settings.getNetherSeedZ());

generatorMap.put(seedWorldNether, seedWorldNetherGenerator);
getPlugin().getIWM().addWorld(seedWorldNether, this);
copyChunks(seedWorldNether, netherChunkGenerator);

if (getServer().getWorld(worldName + NETHER) == null) {
Expand All @@ -216,29 +221,33 @@ private void createOverWorld(String worldName) {
log("Creating Boxed Seed world ...");
// This creates a vanilla base world with biomes
AbstractBoxedChunkGenerator seedBaseGen = new BoxedSeedChunkGenerator(this, Environment.NORMAL);
baseWorld = WorldCreator
.name(worldName + "/" + SEED+BASE)
World baseWorld = WorldCreator
.name(worldName + "/" + SEED + BASE)
.generator(seedBaseGen)
.environment(Environment.NORMAL)
.seed(getSettings().getSeed())
.createWorld();
baseWorld.setDifficulty(Difficulty.PEACEFUL);
baseWorld.setSpawnLocation(settings.getSeedX(), 64, settings.getSeedZ());
generatorMap.put(baseWorld, seedBaseGen);
getPlugin().getIWM().addWorld(baseWorld, this);
copyChunks(baseWorld, seedBaseGen);
// Create seed world
// This copies a base world with custom biomes
log("Creating Boxed Biomed world ...");

BoxedSeedChunkGenerator seedWorldGenerator = new BoxedSeedChunkGenerator(this, Environment.NORMAL, new SeedBiomeGenerator(this, seedBaseGen));
seedWorld = WorldCreator
.name(worldName + "/" + SEED)
.generator(new BoxedSeedChunkGenerator(this, Environment.NORMAL, new SeedBiomeGenerator(this, seedBaseGen)))
.generator(seedWorldGenerator)
.environment(Environment.NORMAL)
.seed(getSettings().getSeed())
.createWorld();
seedWorld.setDifficulty(Difficulty.EASY);

seedWorld.setSpawnLocation(settings.getSeedX(), 64, settings.getSeedZ());

generatorMap.put(seedWorld, seedWorldGenerator);
getPlugin().getIWM().addWorld(seedWorld, this);
copyChunks(seedWorld, chunkGenerator);


Expand All @@ -251,9 +260,28 @@ private void createOverWorld(String worldName) {
islandWorld = getWorld(worldName, World.Environment.NORMAL);

}

/**
* Registers a world with world management plugins
*
* @param world the World to register
*/
private void registerToWorldManagementPlugins(@NonNull World world) {
if (getPlugin().getHooks() != null) {
for (Hook hook : getPlugin().getHooks().getHooks()) {
if (hook instanceof final WorldManagementHook worldManagementHook) {
if (Bukkit.isPrimaryThread()) {
worldManagementHook.registerWorld(world, true);
} else {
Bukkit.getScheduler().runTask(getPlugin(), () -> worldManagementHook.registerWorld(world, true));
}
}
}
}
}

/**
* Copies chunks from the seed world so they can be pasted in the game world
* Copies chunks from the seed world, so they can be pasted in the game world
* @param world - source world
* @param gen - generator to store the chunks
*/
Expand Down Expand Up @@ -307,17 +335,18 @@ private World getWorld(String worldName2, Environment env) {
worldName2 = env.equals(World.Environment.NETHER) ? worldName2 + NETHER : worldName2;
worldName2 = env.equals(World.Environment.THE_END) ? worldName2 + THE_END : worldName2;
boxedBiomeProvider = new BoxedBiomeGenerator(this);
boxedBlockPopulator = new BoxedBlockPopulator(this);
World w = WorldCreator
.name(worldName2)
.generator(env.equals(World.Environment.NETHER) ? netherChunkGenerator : chunkGenerator)
.generator(getChunkGenerator(env))
.environment(env)
.seed(seedWorld.getSeed()) // For development
.createWorld();
// Set spawn rates
if (w != null) {
setSpawnRates(w);
}
// Store main generators
generatorMap.put(w, getChunkGenerator(env));
return w;

}
Expand Down Expand Up @@ -357,7 +386,12 @@ public WorldSettings getWorldSettings() {

@Override
public @Nullable ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
return worldName.endsWith(NETHER) ? netherChunkGenerator : chunkGenerator;
for (Entry<World, ChunkGenerator> en : generatorMap.entrySet()) {
if (en.getKey().getName().equalsIgnoreCase(worldName)) {
return en.getValue();
}
}
return null;
}

@Override
Expand All @@ -374,6 +408,9 @@ public void saveWorldSettings() {
public void allLoaded() {
// Save settings. This will occur after all addons have loaded
this.saveWorldSettings();
// Register generators for worlds with multiverse etc.
this.log("Registering Boxed worlds with other plugins (if applicable)...");
generatorMap.keySet().forEach(this::registerToWorldManagementPlugins);
}

/**
Expand All @@ -383,13 +420,6 @@ public AdvancementsManager getAdvManager() {
return advManager;
}

/**
* @return the boxedBlockPopulator
*/
public BlockPopulator getBoxedBlockPopulator() {
return boxedBlockPopulator;
}

@Override
public boolean isUsesNewChunkGeneration() {
return true;
Expand Down
Loading

0 comments on commit 470f893

Please sign in to comment.