diff --git a/.github/.gitignore b/.github/.gitignore
new file mode 100644
index 0000000..e43b0f9
--- /dev/null
+++ b/.github/.gitignore
@@ -0,0 +1 @@
+.DS_Store
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index c771fd5..825b18d 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -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') }}
diff --git a/.github/workflows/modrinth.yml b/.github/workflows/modrinth.yml
new file mode 100644
index 0000000..7f3d1c7
--- /dev/null
+++ b/.github/workflows/modrinth.yml
@@ -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 }}
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 6ef3add..5f8f021 100644
--- a/pom.xml
+++ b/pom.xml
@@ -58,8 +58,8 @@
2.0.9
- 1.19.4-R0.1-SNAPSHOT
- 1.23.0
+ 1.20.4-R0.1-SNAPSHOT
+ 2.0.0-SNAPSHOT${build.version}-SNAPSHOT
@@ -227,7 +227,8 @@
org.apache.maven.pluginsmaven-surefire-plugin
- 3.0.0-M5
+ 3.1.2
+
${argLine}
@@ -312,13 +313,15 @@
org.jacocojacoco-maven-plugin
- 0.8.7
+ 0.8.10true**/*Names*
+
+ org/bukkit/Material*
diff --git a/src/main/java/world/bentobox/bskyblock/BSkyBlock.java b/src/main/java/world/bentobox/bskyblock/BSkyBlock.java
index bfad495..1a485ff 100644
--- a/src/main/java/world/bentobox/bskyblock/BSkyBlock.java
+++ b/src/main/java/world/bentobox/bskyblock/BSkyBlock.java
@@ -2,6 +2,7 @@
import org.bukkit.World;
import org.bukkit.World.Environment;
+import org.bukkit.entity.SpawnCategory;
import org.bukkit.WorldCreator;
import org.bukkit.WorldType;
import org.bukkit.event.Listener;
@@ -129,24 +130,25 @@ private World getWorld(String worldName2, Environment env, ChunkGeneratorWorld c
WorldCreator wc = WorldCreator.name(worldName2).type(WorldType.FLAT).environment(env);
World w = settings.isUseOwnGenerator() ? wc.createWorld() : wc.generator(chunkGenerator2).createWorld();
// Set spawn rates
- if (w != null) {
+ // Set spawn rates
+ if (w != null && getSettings() != null) {
if (getSettings().getSpawnLimitMonsters() > 0) {
- w.setMonsterSpawnLimit(getSettings().getSpawnLimitMonsters());
+ w.setSpawnLimit(SpawnCategory.MONSTER, getSettings().getSpawnLimitMonsters());
}
if (getSettings().getSpawnLimitAmbient() > 0) {
- w.setAmbientSpawnLimit(getSettings().getSpawnLimitAmbient());
+ w.setSpawnLimit(SpawnCategory.AMBIENT, getSettings().getSpawnLimitAmbient());
}
if (getSettings().getSpawnLimitAnimals() > 0) {
- w.setAnimalSpawnLimit(getSettings().getSpawnLimitAnimals());
+ w.setSpawnLimit(SpawnCategory.ANIMAL, getSettings().getSpawnLimitAnimals());
}
if (getSettings().getSpawnLimitWaterAnimals() > 0) {
- w.setWaterAnimalSpawnLimit(getSettings().getSpawnLimitWaterAnimals());
+ w.setSpawnLimit(SpawnCategory.WATER_ANIMAL, getSettings().getSpawnLimitWaterAnimals());
}
if (getSettings().getTicksPerAnimalSpawns() > 0) {
- w.setTicksPerAnimalSpawns(getSettings().getTicksPerAnimalSpawns());
+ w.setTicksPerSpawns(SpawnCategory.ANIMAL, getSettings().getTicksPerAnimalSpawns());
}
if (getSettings().getTicksPerMonsterSpawns() > 0) {
- w.setTicksPerMonsterSpawns(getSettings().getTicksPerMonsterSpawns());
+ w.setTicksPerSpawns(SpawnCategory.MONSTER, getSettings().getTicksPerMonsterSpawns());
}
}
return w;
diff --git a/src/main/java/world/bentobox/bskyblock/generators/ChunkGeneratorWorld.java b/src/main/java/world/bentobox/bskyblock/generators/ChunkGeneratorWorld.java
index 6edd388..36f5223 100644
--- a/src/main/java/world/bentobox/bskyblock/generators/ChunkGeneratorWorld.java
+++ b/src/main/java/world/bentobox/bskyblock/generators/ChunkGeneratorWorld.java
@@ -122,7 +122,7 @@ private void makeNetherRoof() {
}
break;
case 2:
- // Stalatite
+ // Stalactite
for (int i = 0; i < rand.nextInt(10); i++) {
setBlock(x, - 8 - i, z, Material.GLOWSTONE);
}
diff --git a/src/main/resources/addon.yml b/src/main/resources/addon.yml
index 389261e..9fc3c75 100755
--- a/src/main/resources/addon.yml
+++ b/src/main/resources/addon.yml
@@ -8,88 +8,14 @@ repository: "BentoBoxWorld/BSkyBlock"
authors: tastybento
-permissions:
- bskyblock.island:
- 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
+permissions:
+# Non-command permissions
bskyblock.island.lock:
- description: Allows island locking
- 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
+ description: Allows island locking in settings
default: true
bskyblock.settings.*:
description: Allow use of settings on island
default: true
- bskyblock.mod.info:
- description: Let a moderator see info on a player
- default: op
bskyblock.mod.clearreset:
description: Allow clearing of island reset limit
default: false
@@ -105,47 +31,14 @@ permissions:
bskyblock.mod.bypassexpel:
description: Allow moderator to bypass island expulsion
default: op
- bskyblock.mod.switch:
- description: Allows moderator to switch bypass protection on and off
- default: op
bskyblock.mod.lock:
- description: Locks or unlocks an island
+ description: Allows lock or unlock of an island
default: op
bskyblock.mod.bypasslock:
description: Bypasses an island lock
default: op
bskyblock.mod.bypassban:
description: Bypasses island ban
- 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:
description: Player cannot be banned from an island
@@ -153,13 +46,250 @@ permissions:
bskyblock.admin.noexpel:
description: Player cannot be expelled from an island
default: op
- bskyblock.admin.setlanguage:
- description: Resets all player languages and sets the default language
- default: op
+ # Command permissions
+ bskyblock.island:
+ 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:
- description: Get a player's rank
- default: op
+ description: Allow use of '/bsbadmin getrank' command - get a player's rank on their island or the island of the owner
+ default: OP
bskyblock.admin.setrank:
- description: Set a player's rank
- default: op
-
\ No newline at end of file
+ description: Allow use of '/bsbadmin setrank' command - set a player's rank on their island or the island of the owner
+ 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
diff --git a/src/main/resources/blueprints/classic-lshape.blu b/src/main/resources/blueprints/classic-lshape.blu
index 00b76b6..5a8562a 100644
Binary files a/src/main/resources/blueprints/classic-lshape.blu and b/src/main/resources/blueprints/classic-lshape.blu differ
diff --git a/src/main/resources/blueprints/double.blu b/src/main/resources/blueprints/double.blu
index 5e4c439..05c6823 100644
Binary files a/src/main/resources/blueprints/double.blu and b/src/main/resources/blueprints/double.blu differ
diff --git a/src/test/java/world/bentobox/bskyblock/BSkyBlockTest.java b/src/test/java/world/bentobox/bskyblock/BSkyBlockTest.java
index 97cad7e..9254a84 100644
--- a/src/test/java/world/bentobox/bskyblock/BSkyBlockTest.java
+++ b/src/test/java/world/bentobox/bskyblock/BSkyBlockTest.java
@@ -4,20 +4,26 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import java.beans.IntrospectionException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import java.util.logging.Logger;
@@ -28,6 +34,7 @@
import org.bukkit.plugin.PluginManager;
import org.junit.After;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -43,6 +50,8 @@
import world.bentobox.bentobox.api.addons.AddonDescription;
import world.bentobox.bentobox.api.configuration.Config;
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.managers.AddonsManager;
import world.bentobox.bentobox.managers.CommandsManager;
@@ -56,189 +65,215 @@
*
*/
@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 {
- @Mock
- private User user;
- @Mock
- private IslandsManager im;
- @Mock
- private Island island;
-
- private BSkyBlock addon;
- @Mock
- private BentoBox plugin;
- @Mock
- private FlagsManager fm;
- @Mock
- private Settings settings;
-
- /**
- * @throws java.lang.Exception
- */
- @Before
- public void setUp() throws Exception {
- // Set up plugin
- Whitebox.setInternalState(BentoBox.class, "instance", plugin);
- when(plugin.getLogger()).thenReturn(Logger.getAnonymousLogger());
- // Command manager
- CommandsManager cm = mock(CommandsManager.class);
- when(plugin.getCommandsManager()).thenReturn(cm);
-
- // Player
- Player p = mock(Player.class);
- // Sometimes use Mockito.withSettings().verboseLogging()
- when(user.isOp()).thenReturn(false);
- UUID uuid = UUID.randomUUID();
- when(user.getUniqueId()).thenReturn(uuid);
- when(user.getPlayer()).thenReturn(p);
- when(user.getName()).thenReturn("tastybento");
- User.setPlugin(plugin);
-
- // Island World Manager
- IslandWorldManager iwm = mock(IslandWorldManager.class);
- when(plugin.getIWM()).thenReturn(iwm);
-
-
- // Player has island to begin with
- island = mock(Island.class);
- when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
- when(plugin.getIslands()).thenReturn(im);
-
- // Locales
- // Return the reference (USE THIS IN THE FUTURE)
- when(user.getTranslation(Mockito.anyString())).thenAnswer((Answer) invocation -> invocation.getArgument(0, String.class));
-
- // Server
- PowerMockito.mockStatic(Bukkit.class);
- Server server = mock(Server.class);
- when(Bukkit.getServer()).thenReturn(server);
- when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
- when(Bukkit.getPluginManager()).thenReturn(mock(PluginManager.class));
-
- // Addon
- addon = new BSkyBlock();
- File jFile = new File("addon.jar");
- List lines = Arrays.asList("# BSkyBlock Configuration", "uniqueId: config");
- Path path = Paths.get("config.yml");
- Files.write(path, lines, Charset.forName("UTF-8"));
- try (JarOutputStream tempJarOutputStream = new JarOutputStream(new FileOutputStream(jFile))) {
- //Added the new files to the jar.
- try (FileInputStream fis = new FileInputStream(path.toFile())) {
-
- byte[] buffer = new byte[1024];
- int bytesRead = 0;
- JarEntry entry = new JarEntry(path.toString());
- tempJarOutputStream.putNextEntry(entry);
- while((bytesRead = fis.read(buffer)) != -1) {
- tempJarOutputStream.write(buffer, 0, bytesRead);
- }
- }
- }
- File dataFolder = new File("addons/BSkyBlock");
- addon.setDataFolder(dataFolder);
- addon.setFile(jFile);
- AddonDescription desc = new AddonDescription.Builder("bentobox", "bskyblock", "1.3").description("test").authors("tasty").build();
- addon.setDescription(desc);
- // Addons manager
- AddonsManager am = mock(AddonsManager.class);
- when(plugin.getAddonsManager()).thenReturn(am);
-
- // Flags manager
- when(plugin.getFlagsManager()).thenReturn(fm);
- when(fm.getFlags()).thenReturn(Collections.emptyList());
-
- // Settings
- when(plugin.getSettings()).thenReturn(settings);
-
- }
-
- /**
- * @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
- public void testOnLoad() {
- addon.onLoad();
- // Check that config.yml file has been saved
- File check = new File("addons/BSkyBlock","config.yml");
- assertTrue(check.exists());
- }
-
- /**
- * Test method for {@link world.bentobox.bskyblock.BSkyBlock#onEnable()}.
- */
- @Test
- public void testOnEnable() {
- testOnLoad();
- addon.onEnable();
- assertTrue(addon.getPlayerCommand().isPresent());
- assertTrue(addon.getAdminCommand().isPresent());
- }
-
- /**
- * Test method for {@link world.bentobox.bskyblock.BSkyBlock#onReload()}.
- */
- @Test
- public void testOnReload() {
- addon.onReload();
- // Check that config.yml file has been saved
- File check = new File("addons/BSkyBlock","config.yml");
- assertTrue(check.exists());
- }
-
- /**
- * Test method for {@link world.bentobox.bskyblock.BSkyBlock#createWorlds()}.
- */
- @Test
- public void testCreateWorlds() {
- addon.onLoad();
- addon.createWorlds();
- Mockito.verify(plugin).log("[bskyblock] Creating BSkyBlock world ...");
- Mockito.verify(plugin).log("[bskyblock] Creating BSkyBlock's Nether...");
- Mockito.verify(plugin).log("[bskyblock] Creating BSkyBlock's End World...");
- }
-
- /**
- * Test method for {@link world.bentobox.bskyblock.BSkyBlock#getSettings()}.
- */
- @Test
- public void testGetSettings() {
- addon.onLoad();
- assertNotNull(addon.getSettings());
- }
-
- /**
- * Test method for {@link world.bentobox.bskyblock.BSkyBlock#getWorldSettings()}.
- */
- @Test
- public void testGetWorldSettings() {
- addon.onLoad();
- assertEquals(addon.getSettings(), addon.getWorldSettings());
- }
-
- /**
- * Test method for {@link world.bentobox.bskyblock.BSkyBlock#getDefaultWorldGenerator(java.lang.String, java.lang.String)}.
- */
- @Test
- public void testGetDefaultWorldGeneratorStringString() {
- assertNull(addon.getDefaultWorldGenerator("", ""));
- addon.onLoad();
- addon.createWorlds();
- assertNotNull(addon.getDefaultWorldGenerator("", ""));
- assertTrue(addon.getDefaultWorldGenerator("", "") instanceof ChunkGeneratorWorld);
- }
+ @Mock
+ private User user;
+ @Mock
+ private IslandsManager im;
+ @Mock
+ private Island island;
+
+ private BSkyBlock addon;
+ @Mock
+ private BentoBox plugin;
+ @Mock
+ private FlagsManager fm;
+ @Mock
+ private Settings settings;
+
+ private static AbstractDatabaseHandler