Release 1.17.0 (#509)

* Translate fr.yml via GitLocalize (#501)

Co-authored-by: gitlocalize-app[bot] <55277160+gitlocalize-app[bot]@users.noreply.github.com>

* Update Github Action build script

* Added distribution required for Github Action

* Update perms list

* Fix deprecation code for setting world settings

* Fix duplicate permission listing

* Fix typo

* Updated POM version numbers

* Update Jacoco

* Update pom.xml

* Add Modrinth publish workflow for GitHub Actions

* Fix syntax

* Syntax

* GitHub Action test

* More Action

* Update to BentoBox 2.0.0 API

* Updated island blueprints to 1.20.4

Grass was missing.

* Fix tests

---------

Co-authored-by: gitlocalize-app[bot] <55277160+gitlocalize-app[bot]@users.noreply.github.com>
This commit is contained in:
tastybento 2024-01-20 08:21:35 -08:00 committed by GitHub
parent 844996fe3a
commit 9599935527
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 483 additions and 296 deletions

1
.github/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.DS_Store

View File

@ -11,21 +11,22 @@ jobs:
name: Build name: Build
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
with: with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 17 - name: Set up JDK 17
uses: actions/setup-java@v1 uses: actions/setup-java@v3
with: with:
distribution: 'adopt'
java-version: 17 java-version: 17
- name: Cache SonarCloud packages - name: Cache SonarCloud packages
uses: actions/cache@v1 uses: actions/cache@v3
with: with:
path: ~/.sonar/cache path: ~/.sonar/cache
key: ${{ runner.os }}-sonar key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages - name: Cache Maven packages
uses: actions/cache@v1 uses: actions/cache@v3
with: with:
path: ~/.m2 path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}

15
.github/workflows/modrinth.yml vendored Normal file
View File

@ -0,0 +1,15 @@
name: Modrinth-Release
on:
release:
types: [published]
jobs:
build:
name: Deploy
runs-on: ubuntu-latest
steps:
- name: mc-publish
uses: Kir-Antipov/mc-publish@v3.3
with:
# Publish on Modrinth.
modrinth-id: bskyblock
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}

11
pom.xml
View File

@ -58,8 +58,8 @@
<!-- Non-minecraft related dependencies --> <!-- Non-minecraft related dependencies -->
<powermock.version>2.0.9</powermock.version> <powermock.version>2.0.9</powermock.version>
<!-- More visible way how to change dependency versions --> <!-- More visible way how to change dependency versions -->
<spigot.version>1.19.4-R0.1-SNAPSHOT</spigot.version> <spigot.version>1.20.4-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.23.0</bentobox.version> <bentobox.version>2.0.0-SNAPSHOT</bentobox.version>
<!-- Revision variable removes warning about dynamic version --> <!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision> <revision>${build.version}-SNAPSHOT</revision>
<!-- Do not change unless you want different name for local builds. --> <!-- Do not change unless you want different name for local builds. -->
@ -227,7 +227,8 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version> <version>3.1.2</version>
<!--suppress MavenModelInspection -->
<configuration> <configuration>
<argLine> <argLine>
${argLine} ${argLine}
@ -312,13 +313,15 @@
<plugin> <plugin>
<groupId>org.jacoco</groupId> <groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId> <artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version> <version>0.8.10</version>
<configuration> <configuration>
<append>true</append> <append>true</append>
<excludes> <excludes>
<!-- This is required to prevent Jacoco from adding <!-- This is required to prevent Jacoco from adding
synthetic fields to a JavaBean class (causes errors in testing) --> synthetic fields to a JavaBean class (causes errors in testing) -->
<exclude>**/*Names*</exclude> <exclude>**/*Names*</exclude>
<!-- Prevents the Material is too large to mock error -->
<exclude>org/bukkit/Material*</exclude>
</excludes> </excludes>
</configuration> </configuration>
<executions> <executions>

View File

@ -2,6 +2,7 @@ package world.bentobox.bskyblock;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.World.Environment; import org.bukkit.World.Environment;
import org.bukkit.entity.SpawnCategory;
import org.bukkit.WorldCreator; import org.bukkit.WorldCreator;
import org.bukkit.WorldType; import org.bukkit.WorldType;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -129,24 +130,25 @@ public class BSkyBlock extends GameModeAddon implements Listener {
WorldCreator wc = WorldCreator.name(worldName2).type(WorldType.FLAT).environment(env); WorldCreator wc = WorldCreator.name(worldName2).type(WorldType.FLAT).environment(env);
World w = settings.isUseOwnGenerator() ? wc.createWorld() : wc.generator(chunkGenerator2).createWorld(); World w = settings.isUseOwnGenerator() ? wc.createWorld() : wc.generator(chunkGenerator2).createWorld();
// Set spawn rates // Set spawn rates
if (w != null) { // Set spawn rates
if (w != null && getSettings() != null) {
if (getSettings().getSpawnLimitMonsters() > 0) { if (getSettings().getSpawnLimitMonsters() > 0) {
w.setMonsterSpawnLimit(getSettings().getSpawnLimitMonsters()); w.setSpawnLimit(SpawnCategory.MONSTER, getSettings().getSpawnLimitMonsters());
} }
if (getSettings().getSpawnLimitAmbient() > 0) { if (getSettings().getSpawnLimitAmbient() > 0) {
w.setAmbientSpawnLimit(getSettings().getSpawnLimitAmbient()); w.setSpawnLimit(SpawnCategory.AMBIENT, getSettings().getSpawnLimitAmbient());
} }
if (getSettings().getSpawnLimitAnimals() > 0) { if (getSettings().getSpawnLimitAnimals() > 0) {
w.setAnimalSpawnLimit(getSettings().getSpawnLimitAnimals()); w.setSpawnLimit(SpawnCategory.ANIMAL, getSettings().getSpawnLimitAnimals());
} }
if (getSettings().getSpawnLimitWaterAnimals() > 0) { if (getSettings().getSpawnLimitWaterAnimals() > 0) {
w.setWaterAnimalSpawnLimit(getSettings().getSpawnLimitWaterAnimals()); w.setSpawnLimit(SpawnCategory.WATER_ANIMAL, getSettings().getSpawnLimitWaterAnimals());
} }
if (getSettings().getTicksPerAnimalSpawns() > 0) { if (getSettings().getTicksPerAnimalSpawns() > 0) {
w.setTicksPerAnimalSpawns(getSettings().getTicksPerAnimalSpawns()); w.setTicksPerSpawns(SpawnCategory.ANIMAL, getSettings().getTicksPerAnimalSpawns());
} }
if (getSettings().getTicksPerMonsterSpawns() > 0) { if (getSettings().getTicksPerMonsterSpawns() > 0) {
w.setTicksPerMonsterSpawns(getSettings().getTicksPerMonsterSpawns()); w.setTicksPerSpawns(SpawnCategory.MONSTER, getSettings().getTicksPerMonsterSpawns());
} }
} }
return w; return w;

View File

@ -122,7 +122,7 @@ public class ChunkGeneratorWorld extends ChunkGenerator {
} }
break; break;
case 2: case 2:
// Stalatite // Stalactite
for (int i = 0; i < rand.nextInt(10); i++) { for (int i = 0; i < rand.nextInt(10); i++) {
setBlock(x, - 8 - i, z, Material.GLOWSTONE); setBlock(x, - 8 - i, z, Material.GLOWSTONE);
} }

View File

@ -9,87 +9,13 @@ repository: "BentoBoxWorld/BSkyBlock"
authors: tastybento authors: tastybento
permissions: permissions:
bskyblock.island: # Non-command permissions
description: Allow island command usage
default: true
bskyblock.island.create:
description: Allow island creation
default: true
bskyblock.island.home:
description: Allow teleporting to player island
default: true
bskyblock.island.homes:
description: Allow use of the homes command
default: true
bskyblock.island.sethome:
description: Let the player use the sethome command
default: true
bskyblock.island.info:
description: Let the player use the island info command
default: true
bskyblock.island.lock: bskyblock.island.lock:
description: Allows island locking description: Allows island locking in settings
default: true
bskyblock.island.near:
description: Players can see nearby island names
default: true
bskyblock.island.expel:
description: Allows expelling of visitors
default: true
bskyblock.island.ban:
description: Allows banning of visitors
default: true
bskyblock.island.settings:
description: Player can see server settings
default: true
bskyblock.island.language:
description: Player can select a language
default: true
bskyblock.island.name:
description: Player can set the name of their island
default: true
bskyblock.island.spawn:
description: Player can use the island spawn command if spawn exists
default: true
bskyblock.island.reset:
description: Player can use the island reset or restart command
default: true
bskyblock.island.team:
description: Let a player use team command
default: true
bskyblock.island.team.setowner:
description: Let a player change the team owner
default: true
bskyblock.island.team.invite:
description: Let a player invite others
default: true
bskyblock.island.team.reject:
description: Let a player reject invites
default: true
bskyblock.island.team.leave:
description: Let a player leave the team
default: true
bskyblock.island.team.kick:
description: Let a player kick team members
default: true
bskyblock.island.team.accept:
description: Let a player accept invitations
default: true
bskyblock.island.team.trust:
description: Let a player use team trust commands
default: true
bskyblock.island.team.coop:
description: Let a player use team coop commands
default: true
bskyblock.island.team.promote:
description: Let a player use promote commands
default: true default: true
bskyblock.settings.*: bskyblock.settings.*:
description: Allow use of settings on island description: Allow use of settings on island
default: true default: true
bskyblock.mod.info:
description: Let a moderator see info on a player
default: op
bskyblock.mod.clearreset: bskyblock.mod.clearreset:
description: Allow clearing of island reset limit description: Allow clearing of island reset limit
default: false default: false
@ -105,11 +31,8 @@ permissions:
bskyblock.mod.bypassexpel: bskyblock.mod.bypassexpel:
description: Allow moderator to bypass island expulsion description: Allow moderator to bypass island expulsion
default: op default: op
bskyblock.mod.switch:
description: Allows moderator to switch bypass protection on and off
default: op
bskyblock.mod.lock: bskyblock.mod.lock:
description: Locks or unlocks an island description: Allows lock or unlock of an island
default: op default: op
bskyblock.mod.bypasslock: bskyblock.mod.bypasslock:
description: Bypasses an island lock description: Bypasses an island lock
@ -117,49 +40,256 @@ permissions:
bskyblock.mod.bypassban: bskyblock.mod.bypassban:
description: Bypasses island ban description: Bypasses island ban
default: op default: op
bskyblock.mod.team:
description: Enables modification of teams via kick and add commands
default: false
bskyblock.admin.tp:
description: Allows teleport to an island
default: op
bskyblock.admin.clearresetall:
description: Allow clearing of island reset limit of all players
default: op
bskyblock.admin.reload:
description: Reload the config.yml
default: op
bskyblock.admin.delete:
description: Let a player completely remove a player (including island)
default: op
bskyblock.admin.register:
description: Let a player register the nearest island to another player.
default: op
bskyblock.admin.unregister:
description: Removes a player from an island without deleting the island blocks.
default: op
bskyblock.admin.setspawn:
description: Allows use of spawn tools
default: op
bskyblock.admin.setrange:
description: Allows setting of island protection range
default: op
bskyblock.admin.settingsreset:
description: Resets all the islands to default protection settings
default: op
bskyblock.admin.noban: bskyblock.admin.noban:
description: Player cannot be banned from an island description: Player cannot be banned from an island
default: op default: op
bskyblock.admin.noexpel: bskyblock.admin.noexpel:
description: Player cannot be expelled from an island description: Player cannot be expelled from an island
default: op default: op
bskyblock.admin.setlanguage: # Command permissions
description: Resets all player languages and sets the default language bskyblock.island:
default: op description: Allow use of '/island' command - the main island command
default: TRUE
bskyblock.island.home:
description: Allow use of '/island go' command - teleport you to your island
default: TRUE
bskyblock.island.spawn:
description: Allow use of '/island spawn' command - teleport you to the spawn
default: TRUE
bskyblock.island.create:
description: Allow use of '/island create' command - create an island, using optional blueprint (requires permission)
default: TRUE
bskyblock.island.reset:
description: Allow use of '/island reset' command - restart your island and remove the old one
default: TRUE
bskyblock.island.info:
description: Allow use of '/island info' command - display info about your island or the player's island
default: TRUE
bskyblock.island.settings:
description: Allow use of '/island settings' command - display island settings
default: TRUE
bskyblock.island.name:
description: Allow use of '/island setname' or '/island resetname' command - your island name
default: TRUE
bskyblock.island.language:
description: Allow use of '/island language' command - select language
default: TRUE
bskyblock.island.ban:
description: Allow use of '/island ban' or '/island unban' or '/island banlist' command - banned players
default: TRUE
bskyblock.island.expel:
description: Allow use of '/island expel' command - expel a player from your island
default: TRUE
bskyblock.island.near:
description: Allow use of '/island near' command - show the name of neighboring islands around you
default: TRUE
bskyblock.island.team:
description: Allow use of '/island team' command - manage your team
default: TRUE
bskyblock.island.team.invite:
description: Allow use of '/island team invite' command - invite a player to join your island
default: TRUE
bskyblock.island.team.leave:
description: Allow use of '/island team leave' command - leave your island
default: TRUE
bskyblock.island.team.setowner:
description: Allow use of '/island team setowner' command - transfer your island ownership to a member
default: TRUE
bskyblock.island.team.kick:
description: Allow use of '/island team kick' command - remove a member from your island
default: TRUE
bskyblock.island.team.accept:
description: Allow use of '/island team accept' command - accept an invitation
default: TRUE
bskyblock.island.team.reject:
description: Allow use of '/island team reject' command - reject an invitation
default: TRUE
bskyblock.island.team.coop:
description: Allow use of '/island team coop' or '/island team uncoop' command - coop rank from player
default: TRUE
bskyblock.island.team.trust:
description: Allow use of '/island team trust' or '/island team untrust' command - trusted player rank for player
default: TRUE
bskyblock.island.team.promote:
description: Allow use of '/island team promote' or '/island team demote' command - move a player's rank on your island
default: TRUE
bskyblock.island.sethome:
description: Allow use of '/island sethome' command - set your home teleport point
default: TRUE
bskyblock.island.deletehome:
description: Allow use of '/island deletehome' command - delete a home location
default: OP
bskyblock.island.renamehome:
description: Allow use of '/island renamehome' command - rename a home location
default: OP
bskyblock.island.homes:
description: Allow use of '/island homes' command - list your homes
default: TRUE
bskyblock.admin:
description: Allow use of '/bsbadmin' command - admin command
default: OP
bskyblock.admin.version:
description: Allow use of '/bsbadmin version' command - display BentoBox and addons versions
default: OP
bskyblock.admin.tp:
description: Allow use of '/bsbadmin tp/tpnether/tpend' command - teleport to a player's island
default: OP
bskyblock.admin.getrank: bskyblock.admin.getrank:
description: Get a player's rank description: Allow use of '/bsbadmin getrank' command - get a player's rank on their island or the island of the owner
default: op default: OP
bskyblock.admin.setrank: bskyblock.admin.setrank:
description: Set a player's rank description: Allow use of '/bsbadmin setrank' command - set a player's rank on their island or the island of the owner
default: op default: OP
bskyblock.mod.info:
description: Allow use of '/bsbadmin info' command - get info on where you are or player's island
default: OP
bskyblock.mod.team:
description: Allow use of '/bsbadmin team' command - manage teams
default: FALSE
bskyblock.mod.team.add:
description: Allow use of '/bsbadmin team add' command - add player to owner's team
default: OP
bskyblock.mod.team.disband:
description: Allow use of '/bsbadmin team disband' command - disband owner's team
default: OP
bskyblock.mod.team.fix:
description: Allow use of '/bsbadmin team fix' command - scans and fixes cross island membership in database
default: OP
bskyblock.mod.team.kick:
description: Allow use of '/bsbadmin team kick' command - kick a player from a team
default: OP
bskyblock.mod.team.setowner:
description: Allow use of '/bsbadmin team setowner' command - transfers island ownership to the player
default: OP
bskyblock.admin.blueprint:
description: Allow use of '/bsbadmin blueprint' command - manipulate blueprints
default: OP
bskyblock.admin.blueprint.load:
description: Allow use of '/bsbadmin blueprint load' command - load blueprint into the clipboard
default: OP
bskyblock.admin.blueprint.paste:
description: Allow use of '/bsbadmin blueprint paste' command - paste the clipboard to your location
default: OP
bskyblock.admin.blueprint.origin:
description: Allow use of '/bsbadmin blueprint origin' command - set the blueprint's origin to your position
default: OP
bskyblock.admin.blueprint.copy:
description: Allow use of '/bsbadmin blueprint copy' command - copy the clipboard set by pos1 and pos2 and optionally the air blocks
default: OP
bskyblock.admin.blueprint.save:
description: Allow use of '/bsbadmin blueprint save' command - save the copied clipboard
default: OP
bskyblock.admin.blueprint.rename:
description: Allow use of '/bsbadmin blueprint rename' command - rename a blueprint
default: OP
bskyblock.admin.blueprint.delete:
description: Allow use of '/bsbadmin blueprint delete' command - delete the blueprint
default: OP
bskyblock.admin.blueprint.pos1:
description: Allow use of '/bsbadmin blueprint pos1' command - set 1st corner of cuboid clipboard
default: OP
bskyblock.admin.blueprint.pos2:
description: Allow use of '/bsbadmin blueprint pos2' command - set 2nd corner of cuboid clipboard
default: OP
bskyblock.admin.blueprint.list:
description: Allow use of '/bsbadmin blueprint list' command - list available blueprints
default: OP
bskyblock.admin.register:
description: Allow use of '/bsbadmin register' command - register player to unowned island you are on
default: OP
bskyblock.admin.unregister:
description: Allow use of '/bsbadmin unregister' command - unregister owner from island, but keep island blocks
default: OP
bskyblock.admin.range:
description: Allow use of '/bsbadmin range' command - admin island range command
default: OP
bskyblock.admin.range.display:
description: Allow use of '/bsbadmin range display' command - show/hide island range indicators
default: OP
bskyblock.admin.range.set:
description: Allow use of '/bsbadmin range set' command - sets the island protected range
default: OP
bskyblock.admin.range.reset:
description: Allow use of '/bsbadmin range reset' command - resets the island protected range to the world default
default: OP
bskyblock.admin.range.add:
description: Allow use of '/bsbadmin range add' command - increases the island protected range
default: OP
bskyblock.admin.range.remove:
description: Allow use of '/bsbadmin range remove' command - decreases the island protected range
default: OP
bskyblock.admin.resets:
description: Allow use of '/bsbadmin resets' command - edit player reset values
default: OP
bskyblock.admin.resets.set:
description: Allow use of '/bsbadmin resets set' command - sets how many times this player has reset his island
default: OP
bskyblock.admin.resets.add:
description: Allow use of '/bsbadmin resets add' command - adds this player's island reset count
default: OP
bskyblock.admin.resets.remove:
description: Allow use of '/bsbadmin resets remove' command - reduces the player's island reset count
default: OP
bskyblock.admin.delete:
description: Allow use of '/bsbadmin delete' command - deletes a player's island
default: OP
bskyblock.admin.why:
description: Allow use of '/bsbadmin why' command - toggle console protection debug reporting
default: OP
bskyblock.admin.deaths:
description: Allow use of '/bsbadmin deaths' command - edit deaths of players
default: OP
bskyblock.admin.deaths.reset:
description: Allow use of '/bsbadmin deaths reset' command - resets deaths of the player
default: OP
bskyblock.admin.deaths.set:
description: Allow use of '/bsbadmin deaths set' command - sets deaths of the player
default: OP
bskyblock.admin.deaths.add:
description: Allow use of '/bsbadmin deaths add' command - adds deaths to the player
default: OP
bskyblock.admin.deaths.remove:
description: Allow use of '/bsbadmin deaths remove' command - removes deaths to the player
default: OP
bskyblock.admin.reload:
description: Allow use of '/bsbadmin reload' command - reload
default: OP
bskyblock.admin.setspawn:
description: Allow use of '/bsbadmin setspawn' command - set an island as spawn for this gamemode
default: OP
bskyblock.admin.setspawnpoint:
description: Allow use of '/bsbadmin setspawnpoint' command - set current location as spawn point for this island
default: OP
bskyblock.admin.resetflags:
description: Allow use of '/bsbadmin resetflags' command - Reset all islands to default flag settings in config.yml
default: OP
bskyblock.mod.switch:
description: Allow use of '/bsbadmin switch' command - switch on/off protection bypass
default: OP
bskyblock.admin.purge:
description: Allow use of '/bsbadmin purge' command - purge islands abandoned for more than [days]
default: OP
bskyblock.admin.purge.status:
description: Allow use of '/bsbadmin purge status' command - displays the status of the purge
default: OP
bskyblock.admin.purge.stop:
description: Allow use of '/bsbadmin purge stop' command - stop a purge in progress
default: OP
bskyblock.admin.purge.unowned:
description: Allow use of '/bsbadmin purge unowned' command - purge unowned islands
default: OP
bskyblock.admin.purge.protect:
description: Allow use of '/bsbadmin purge protect' command - toggle island purge protection
default: OP
bskyblock.admin.settings:
description: Allow use of '/bsbadmin settings' command - open settings GUI or set settings
default: OP
bskyblock.admin.setprotectionlocation:
description: Allow use of '/bsbadmin setprotectionlocation' command - set current location or [x y z] as center of island's protection area
default: OP
bskyblock.mod.deletehomes:
description: Allow use of '/bsbadmin deletehomes' command - deletes all named homes from an island
default: OP
bskyblock.mod.resetname:
description: Allow use of '/bsbadmin resetname' command - reset player island name
default: OP

View File

@ -4,20 +4,26 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.beans.IntrospectionException;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream; import java.util.jar.JarOutputStream;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -28,6 +34,7 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@ -43,6 +50,8 @@ import world.bentobox.bentobox.Settings;
import world.bentobox.bentobox.api.addons.AddonDescription; import world.bentobox.bentobox.api.addons.AddonDescription;
import world.bentobox.bentobox.api.configuration.Config; import world.bentobox.bentobox.api.configuration.Config;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.AbstractDatabaseHandler;
import world.bentobox.bentobox.database.DatabaseSetup;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.AddonsManager; import world.bentobox.bentobox.managers.AddonsManager;
import world.bentobox.bentobox.managers.CommandsManager; import world.bentobox.bentobox.managers.CommandsManager;
@ -56,7 +65,7 @@ import world.bentobox.bskyblock.generators.ChunkGeneratorWorld;
* *
*/ */
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class, BentoBox.class, User.class, Config.class }) @PrepareForTest({ Bukkit.class, BentoBox.class, User.class, Config.class, DatabaseSetup.class })
public class BSkyBlockTest { public class BSkyBlockTest {
@Mock @Mock
@ -74,6 +83,41 @@ public class BSkyBlockTest {
@Mock @Mock
private Settings settings; private Settings settings;
private static AbstractDatabaseHandler<Object> h;
@SuppressWarnings("unchecked")
@BeforeClass
public static void beforeClass() throws IllegalAccessException, InvocationTargetException, IntrospectionException {
// This has to be done beforeClass otherwise the tests will interfere with each
// other
h = mock(AbstractDatabaseHandler.class);
// Database
PowerMockito.mockStatic(DatabaseSetup.class);
DatabaseSetup dbSetup = mock(DatabaseSetup.class);
when(DatabaseSetup.getDatabase()).thenReturn(dbSetup);
when(dbSetup.getHandler(any())).thenReturn(h);
when(h.saveObject(any())).thenReturn(CompletableFuture.completedFuture(true));
}
@After
public void tearDown() throws IOException {
User.clearUsers();
Mockito.framework().clearInlineMocks();
deleteAll(new File("database"));
deleteAll(new File("database_backup"));
deleteAll(new File("addon.jar"));
deleteAll(new File("config.yml"));
deleteAll(new File("addons"));
}
private void deleteAll(File file) throws IOException {
if (file.exists()) {
Files.walk(file.toPath()).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
}
}
/** /**
* @throws java.lang.Exception * @throws java.lang.Exception
*/ */
@ -100,7 +144,6 @@ public class BSkyBlockTest {
IslandWorldManager iwm = mock(IslandWorldManager.class); IslandWorldManager iwm = mock(IslandWorldManager.class);
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
// Player has island to begin with // Player has island to begin with
island = mock(Island.class); island = mock(Island.class);
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island); when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
@ -108,7 +151,8 @@ public class BSkyBlockTest {
// Locales // Locales
// Return the reference (USE THIS IN THE FUTURE) // Return the reference (USE THIS IN THE FUTURE)
when(user.getTranslation(Mockito.anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class)); when(user.getTranslation(Mockito.anyString()))
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
// Server // Server
PowerMockito.mockStatic(Bukkit.class); PowerMockito.mockStatic(Bukkit.class);
@ -139,7 +183,8 @@ public class BSkyBlockTest {
File dataFolder = new File("addons/BSkyBlock"); File dataFolder = new File("addons/BSkyBlock");
addon.setDataFolder(dataFolder); addon.setDataFolder(dataFolder);
addon.setFile(jFile); addon.setFile(jFile);
AddonDescription desc = new AddonDescription.Builder("bentobox", "bskyblock", "1.3").description("test").authors("tasty").build(); AddonDescription desc = new AddonDescription.Builder("bentobox", "bskyblock", "1.3").description("test")
.authors("tasty").build();
addon.setDescription(desc); addon.setDescription(desc);
// Addons manager // Addons manager
AddonsManager am = mock(AddonsManager.class); AddonsManager am = mock(AddonsManager.class);
@ -154,18 +199,6 @@ public class BSkyBlockTest {
} }
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
new File("addon.jar").delete();
new File("config.yml").delete();
new File("addons/BSkyBlock","config.yml").delete();
new File("addons/BSkyBlock").delete();
new File("addons").delete();
}
/** /**
* Test method for {@link world.bentobox.bskyblock.BSkyBlock#onLoad()}. * Test method for {@link world.bentobox.bskyblock.BSkyBlock#onLoad()}.
*/ */
@ -221,7 +254,8 @@ public class BSkyBlockTest {
} }
/** /**
* Test method for {@link world.bentobox.bskyblock.BSkyBlock#getWorldSettings()}. * Test method for
* {@link world.bentobox.bskyblock.BSkyBlock#getWorldSettings()}.
*/ */
@Test @Test
public void testGetWorldSettings() { public void testGetWorldSettings() {
@ -230,7 +264,8 @@ public class BSkyBlockTest {
} }
/** /**
* Test method for {@link world.bentobox.bskyblock.BSkyBlock#getDefaultWorldGenerator(java.lang.String, java.lang.String)}. * Test method for
* {@link world.bentobox.bskyblock.BSkyBlock#getDefaultWorldGenerator(java.lang.String, java.lang.String)}.
*/ */
@Test @Test
public void testGetDefaultWorldGeneratorStringString() { public void testGetDefaultWorldGeneratorStringString() {