From 46b0c89d3ee9376b1940670396f2ba36e190a88f Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 14 May 2023 08:30:45 -0700 Subject: [PATCH 01/14] Version 1.18.1 staging --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 723d2fe..23d646b 100644 --- a/pom.xml +++ b/pom.xml @@ -65,7 +65,7 @@ -LOCAL - 1.18.0 + 1.18.1 BentoBoxWorld_AcidIsland bentobox-world From 9647338a2f80d3285981741942bb84c041ebcb64 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 24 Jun 2023 12:57:11 -0700 Subject: [PATCH 02/14] Update Github Action build script --- .github/workflows/build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 682e6d2..35b2b32 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,22 +11,22 @@ jobs: name: Build and analyze 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') }} From 9db846a76e95a6a977b14469a2c4912e7fe25c45 Mon Sep 17 00:00:00 2001 From: tastybento Date: Mon, 3 Jul 2023 11:08:03 -0700 Subject: [PATCH 03/14] Updated permissions in addon.yml --- src/main/resources/addon.yml | 449 +++++++++++++++++++++++++---------- 1 file changed, 317 insertions(+), 132 deletions(-) diff --git a/src/main/resources/addon.yml b/src/main/resources/addon.yml index b65d47c..ffff1f8 100755 --- a/src/main/resources/addon.yml +++ b/src/main/resources/addon.yml @@ -9,147 +9,332 @@ icon: "OAK_BOAT" authors: tastybento permissions: - acidisland.admin.clearresetall: - default: op - description: "Allow clearing of island reset limit of all players" - acidisland.admin.delete: - default: op - description: "Let a player completely remove a player (including island)" - acidisland.admin.noban: - default: op - description: "Player cannot be banned from an island" - acidisland.admin.noexpel: - default: op - description: "Player cannot be expelled from an island" - acidisland.admin.register: - default: op - description: "Let a player register the nearest island to another player." - acidisland.admin.reload: - default: op - description: "Reload the config.yml" - acidisland.admin.setlanguage: - default: op - description: "Resets all player languages and sets the default language" - acidisland.admin.setrange: - default: op - description: "Allows setting of island protection range" - acidisland.admin.setspawn: - default: op - description: "Allows use of spawn tools" - acidisland.admin.settingsreset: - default: op - description: "Resets all the islands to default protection settings" - acidisland.admin.tp: - default: op - description: "Allows teleport to an island" - acidisland.admin.unregister: - default: op - description: "Removes a player from an island without deleting the island blocks." - acidisland.island: - default: true - description: "Allow island command usage" - acidisland.island.ban: - default: true - description: "Allows banning of visitors" - acidisland.island.create: - default: true - description: "Allow island creation" - acidisland.island.expel: - default: true - description: "Allows expelling of visitors" - acidisland.island.home: - default: true - description: "Allow teleporting to player island" - acidisland.island.info: - default: true - description: "Let the player check other players info" - acidisland.island.language: - default: true - description: "Player can select a language" - acidisland.island.lock: - default: true - description: "Allows island locking" - acidisland.island.name: - default: true - description: "Player can set the name of their island" - acidisland.island.near: + # Non-command permissions + acidisland.island.lock: + description: Allows island locking in settings default: true - description: "Players can see nearby island names" - acidisland.island.reset: + acidisland.settings.*: + description: Allow use of settings on island default: true - description: "Player can use the island reset or restart command" - acidisland.island.sethome: - default: true - description: "Let the player use the sethome command" - acidisland.island.settings: - default: true - description: "Player can see server settings" - acidisland.island.spawn: - default: true - description: "Player can use the island spawn command if spawn exists" - acidisland.island.team: - default: true - description: "Let a player use team command" - acidisland.island.team.accept: - default: true - description: "Let a player accept invitations" - acidisland.island.team.coop: - default: true - description: "Let a player use team coop commands" - acidisland.island.team.invite: - default: true - description: "Let a player invite others" - acidisland.island.team.kick: - default: true - description: "Let a player kick team members" - acidisland.island.team.leave: - default: true - description: "Let a player leave the team" - acidisland.island.team.promote: - default: true - description: "Let a player use promote commands" - acidisland.island.team.reject: - default: true - description: "Let a player reject invites" - acidisland.island.team.setowner: - default: true - description: "Let a player change the team owner" - acidisland.island.team.trust: - default: true - description: "Let a player use team trust commands" - acidisland.mod.bypassban: - default: op - description: "Bypasses island ban" - acidisland.mod.bypasscooldowns: + acidisland.mod.clearreset: + description: Allow clearing of island reset limit + default: false + acidisland.mod.bypasscooldowns: + description: Allow moderator to bypass cooldowns default: op - description: "Allow moderator to bypass cooldowns" - acidisland.mod.bypassdelays: + acidisland.mod.bypassdelays: + description: Allow moderator to bypass delays default: op - description: "Allow moderator to bypass delays" - acidisland.mod.bypassexpel: + acidisland.mod.bypassprotect: + description: Allow moderator to bypass island protection default: op - description: "Allow moderator to bypass island expulsion" - acidisland.mod.bypasslock: + acidisland.mod.bypassexpel: + description: Allow moderator to bypass island expulsion default: op - description: "Bypasses an island lock" - acidisland.mod.bypassprotect: + acidisland.mod.lock: + description: Allows lock or unlock of an island default: op - description: "Allow moderator to bypass island protection" - acidisland.mod.clearreset: - default: false - description: "Allow clearing of island reset limit" - acidisland.mod.info: + acidisland.mod.bypasslock: + description: Bypasses an island lock default: op - description: "Let a moderator see info on a player" - acidisland.mod.lock: + acidisland.mod.bypassban: + description: Bypasses island ban default: op - description: "Locks or unlocks an island" acidisland.mod.noburn: default: op description: "Give mod acid protection" - acidisland.mod.team: - default: false - description: "Enables modification of teams via kick and add commands" - acidisland.settings.*: - default: true - description: "Allow use of settings on island" + acidisland.admin.noban: + description: Player cannot be banned from an island + default: op + acidisland.admin.noexpel: + description: Player cannot be expelled from an island + default: op + # Command permissions + acidisland.island: + description: Allow use of '/ai' command - the main island command + default: TRUE + acidisland.island.home: + description: Allow use of '/ai go' command - teleport you to your island + default: TRUE + acidisland.island.spawn: + description: Allow use of '/ai spawn' command - teleport you to the spawn + default: TRUE + acidisland.island.create: + description: Allow use of '/ai create' command - create an island, using optional blueprint (requires permission) + default: TRUE + acidisland.island.reset: + description: Allow use of '/ai reset' command - restart your island and remove the old one + default: TRUE + acidisland.island.info: + description: Allow use of '/ai info' command - display info about your island or the player's island + default: TRUE + acidisland.island.settings: + description: Allow use of '/ai settings' command - display island settings + default: TRUE + acidisland.island.name: + description: Allow use of '/ai setname' command - set a name for your island + default: TRUE + acidisland.island.name: + description: Allow use of '/ai resetname' command - reset your island name + default: TRUE + acidisland.island.language: + description: Allow use of '/ai language' command - select language + default: TRUE + acidisland.island.ban: + description: Allow use of '/ai ban' command - ban a player from your island + default: TRUE + acidisland.island.ban: + description: Allow use of '/ai unban' command - unban a player from your island + default: TRUE + acidisland.island.ban: + description: Allow use of '/ai banlist' command - list banned players + default: TRUE + acidisland.island.expel: + description: Allow use of '/ai expel' command - expel a player from your island + default: TRUE + acidisland.island.near: + description: Allow use of '/ai near' command - show the name of neighboring islands around you + default: TRUE + acidisland.island.team: + description: Allow use of '/ai team' command - manage your team + default: TRUE + acidisland.island.team.invite: + description: Allow use of '/ai team invite' command - invite a player to join your island + default: TRUE + acidisland.island.team.leave: + description: Allow use of '/ai team leave' command - leave your island + default: TRUE + acidisland.island.team.setowner: + description: Allow use of '/ai team setowner' command - transfer your island ownership to a member + default: TRUE + acidisland.island.team.kick: + description: Allow use of '/ai team kick' command - remove a member from your island + default: TRUE + acidisland.island.team.accept: + description: Allow use of '/ai team accept' command - accept an invitation + default: TRUE + acidisland.island.team.reject: + description: Allow use of '/ai team reject' command - reject an invitation + default: TRUE + acidisland.island.team.coop: + description: Allow use of '/ai team coop' command - make a player coop rank on your island + default: TRUE + acidisland.island.team.coop: + description: Allow use of '/ai team uncoop' command - remove a coop rank from player + default: TRUE + acidisland.island.team.trust: + description: Allow use of '/ai team trust' command - give a player trusted rank on your island + default: TRUE + acidisland.island.team.trust: + description: Allow use of '/ai team untrust' command - remove trusted player rank from player + default: TRUE + acidisland.island.team.promote: + description: Allow use of '/ai team promote' command - promote a player on your island up a rank + default: TRUE + acidisland.island.team.promote: + description: Allow use of '/ai team demote' command - demote a player on your island down a rank + default: TRUE + acidisland.island.sethome: + description: Allow use of '/ai sethome' command - set your home teleport point + default: TRUE + acidisland.island.deletehome: + description: Allow use of '/ai deletehome' command - delete a home location + default: OP + acidisland.island.renamehome: + description: Allow use of '/ai renamehome' command - rename a home location + default: OP + acidisland.island.homes: + description: Allow use of '/ai homes' command - list your homes + default: OP + acidisland.admin: + description: Allow use of '/acid' command - admin command + default: OP + acidisland.admin.version: + description: Allow use of '/acid version' command - display BentoBox and addons versions + default: OP + acidisland.admin.tp: + description: Allow use of '/acid tp' command - teleport to a player's island + default: OP + acidisland.admin.tp: + description: Allow use of '/acid tpnether' command - teleport to a player's island + default: OP + acidisland.admin.tp: + description: Allow use of '/acid tpend' command - teleport to a player's island + default: OP + acidisland.admin.getrank: + description: Allow use of '/acid getrank' command - get a player's rank on their island or the island of the owner + default: OP + acidisland.admin.setrank: + description: Allow use of '/acid setrank' command - set a player's rank on their island or the island of the owner + default: OP + acidisland.mod.info: + description: Allow use of '/acid info' command - get info on where you are or player's island + default: OP + acidisland.mod.team: + description: Allow use of '/acid team' command - manage teams + default: FALSE + acidisland.mod.team.add: + description: Allow use of '/acid team add' command - add player to owner's team + default: OP + acidisland.mod.team.disband: + description: Allow use of '/acid team disband' command - disband owner's team + default: OP + acidisland.mod.team.fix: + description: Allow use of '/acid team fix' command - scans and fixes cross island membership in database + default: OP + acidisland.mod.team.kick: + description: Allow use of '/acid team kick' command - kick a player from a team + default: OP + acidisland.mod.team.setowner: + description: Allow use of '/acid team setowner' command - transfers island ownership to the player + default: OP + acidisland.mod.team.add: + description: Allow use of '/acid add' command - add player to owner's team + default: OP + acidisland.mod.team.kick: + description: Allow use of '/acid kick' command - kick a player from a team + default: OP + acidisland.mod.team.disband: + description: Allow use of '/acid disband' command - disband owner's team + default: OP + acidisland.mod.team.setowner: + description: Allow use of '/acid setowner' command - transfers island ownership to the player + default: OP + acidisland.mod.team.fix: + description: Allow use of '/acid fix' command - scans and fixes cross island membership in database + default: OP + acidisland.admin.blueprint: + description: Allow use of '/acid blueprint' command - manipulate blueprints + default: OP + acidisland.admin.blueprint.load: + description: Allow use of '/acid blueprint load' command - load blueprint into the clipboard + default: OP + acidisland.admin.blueprint.paste: + description: Allow use of '/acid blueprint paste' command - paste the clipboard to your location + default: OP + acidisland.admin.blueprint.origin: + description: Allow use of '/acid blueprint origin' command - set the blueprint's origin to your position + default: OP + acidisland.admin.blueprint.copy: + description: Allow use of '/acid blueprint copy' command - copy the clipboard set by pos1 and pos2 and optionally the air blocks + default: OP + acidisland.admin.blueprint.save: + description: Allow use of '/acid blueprint save' command - save the copied clipboard + default: OP + acidisland.admin.blueprint.rename: + description: Allow use of '/acid blueprint rename' command - rename a blueprint + default: OP + acidisland.admin.blueprint.delete: + description: Allow use of '/acid blueprint delete' command - delete the blueprint + default: OP + acidisland.admin.blueprint.pos1: + description: Allow use of '/acid blueprint pos1' command - set 1st corner of cuboid clipboard + default: OP + acidisland.admin.blueprint.pos2: + description: Allow use of '/acid blueprint pos2' command - set 2nd corner of cuboid clipboard + default: OP + acidisland.admin.blueprint.list: + description: Allow use of '/acid blueprint list' command - list available blueprints + default: OP + acidisland.admin.register: + description: Allow use of '/acid register' command - register player to unowned island you are on + default: OP + acidisland.admin.unregister: + description: Allow use of '/acid unregister' command - unregister owner from island, but keep island blocks + default: OP + acidisland.admin.range: + description: Allow use of '/acid range' command - admin island range command + default: OP + acidisland.admin.range.display: + description: Allow use of '/acid range display' command - show/hide island range indicators + default: OP + acidisland.admin.range.set: + description: Allow use of '/acid range set' command - sets the island protected range + default: OP + acidisland.admin.range.reset: + description: Allow use of '/acid range reset' command - resets the island protected range to the world default + default: OP + acidisland.admin.range.add: + description: Allow use of '/acid range add' command - increases the island protected range + default: OP + acidisland.admin.range.remove: + description: Allow use of '/acid range remove' command - decreases the island protected range + default: OP + acidisland.admin.resets: + description: Allow use of '/acid resets' command - edit player reset values + default: OP + acidisland.admin.resets.set: + description: Allow use of '/acid resets set' command - sets how many times this player has reset his island + default: OP + acidisland.admin.resets.remove: + description: Allow use of '/acid resets reset' command - sets the player's island reset count to 0 + default: OP + acidisland.admin.resets.add: + description: Allow use of '/acid resets add' command - adds this player's island reset count + default: OP + acidisland.admin.resets.remove: + description: Allow use of '/acid resets remove' command - reduces the player's island reset count + default: OP + acidisland.admin.delete: + description: Allow use of '/acid delete' command - deletes a player's island + default: OP + acidisland.admin.why: + description: Allow use of '/acid why' command - toggle console protection debug reporting + default: OP + acidisland.admin.deaths: + description: Allow use of '/acid deaths' command - edit deaths of players + default: OP + acidisland.admin.deaths.reset: + description: Allow use of '/acid deaths reset' command - resets deaths of the player + default: OP + acidisland.admin.deaths.set: + description: Allow use of '/acid deaths set' command - sets deaths of the player + default: OP + acidisland.admin.deaths.add: + description: Allow use of '/acid deaths add' command - adds deaths to the player + default: OP + acidisland.admin.deaths.remove: + description: Allow use of '/acid deaths remove' command - removes deaths to the player + default: OP + acidisland.admin.reload: + description: Allow use of '/acid reload' command - reload + default: OP + acidisland.admin.setspawn: + description: Allow use of '/acid setspawn' command - set an island as spawn for this gamemode + default: OP + acidisland.admin.setspawnpoint: + description: Allow use of '/acid setspawnpoint' command - set current location as spawn point for this island + default: OP + acidisland.admin.resetflags: + description: Allow use of '/acid resetflags' command - Reset all islands to default flag settings in config.yml + default: OP + acidisland.mod.switch: + description: Allow use of '/acid switch' command - switch on/off protection bypass + default: OP + acidisland.admin.purge: + description: Allow use of '/acid purge' command - purge islands abandoned for more than [days] + default: OP + acidisland.admin.purge.status: + description: Allow use of '/acid purge status' command - displays the status of the purge + default: OP + acidisland.admin.purge.stop: + description: Allow use of '/acid purge stop' command - stop a purge in progress + default: OP + acidisland.admin.purge.unowned: + description: Allow use of '/acid purge unowned' command - purge unowned islands + default: OP + acidisland.admin.purge.protect: + description: Allow use of '/acid purge protect' command - toggle island purge protection + default: OP + acidisland.admin.settings: + description: Allow use of '/acid settings' command - open settings GUI or set settings + default: OP + acidisland.admin.setprotectionlocation: + description: Allow use of '/acid setprotectionlocation' command - set current location or [x y z] as center of island's protection area + default: OP + acidisland.mod.deletehomes: + description: Allow use of '/acid deletehomes' command - deletes all named homes from an island + default: OP + acidisland.mod.resetname: + description: Allow use of '/acid resetname' command - reset player island name + default: OP \ No newline at end of file From 817ae621306160942a8c1ca67d2c59f8d713212a Mon Sep 17 00:00:00 2001 From: tastybento Date: Tue, 4 Jul 2023 17:03:53 -0700 Subject: [PATCH 04/14] Update versions in POM --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 23d646b..c692413 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.1-R0.1-SNAPSHOT + 1.24.0 ${build.version}-SNAPSHOT From 85835a40b9f3c6bed9bfe5bade0b673a66bf4801 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 8 Jul 2023 16:09:29 -0700 Subject: [PATCH 05/14] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 452ab5a..d3f3a3d 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ You're on an island, in a sea of acid! If you like Skyblock, try the AcidIsland Instead of falling you must contend with acid water when expanding your island, and players can boat to each other's islands. +acidislandart + ## Download You can download from GitHub, or ready made plugin packs from [https://download.bentobox.world](https://download.bentobox.world). From 1dd3b1bf85e43620d1414b639274e8c174a97ad5 Mon Sep 17 00:00:00 2001 From: 4o4E <869951226@qq.com> Date: Mon, 10 Jul 2023 22:27:10 +0800 Subject: [PATCH 06/14] fix: unbreakable item still damaged by acid --- .../java/world/bentobox/acidisland/listeners/AcidEffect.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java b/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java index 4d61814..3e4cbc6 100644 --- a/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java +++ b/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java @@ -324,7 +324,7 @@ public static double getDamageReduced(LivingEntity le) { private static boolean damage(ItemStack item) { ItemMeta im = item.getItemMeta(); - if (im instanceof Damageable d) { + if (im instanceof Damageable d && !im.isUnbreakable()) { d.setDamage(d.getDamage() + 1); item.setItemMeta(d); return d.getDamage() >= item.getType().getMaxDurability(); From 533aee12cb869f51499cf4eef562ab7b604c560d Mon Sep 17 00:00:00 2001 From: tastybento Date: Mon, 10 Jul 2023 21:19:55 -0700 Subject: [PATCH 07/14] Update Jacoco --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c692413..58acbce 100644 --- a/pom.xml +++ b/pom.xml @@ -341,7 +341,7 @@ org.jacoco jacoco-maven-plugin - 0.8.7 + 0.8.10 true From 39a7df44ee0d4dedc6a7f4fae15e15b03a8677de Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 22 Jul 2023 15:42:53 -0700 Subject: [PATCH 08/14] Added acidrain test method --- .../acidisland/listeners/AcidEffect.java | 7 +- .../acidisland/listeners/AcidEffectTest.java | 154 +++++++++++++----- 2 files changed, 115 insertions(+), 46 deletions(-) diff --git a/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java b/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java index 3e4cbc6..8230b2d 100644 --- a/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java +++ b/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java @@ -159,6 +159,11 @@ public void run() { }.runTaskTimer(addon.getPlugin(), 0L, 20L); } + /** + * Check if it is still raining or player is safe or dead or there is no damage + * @param player player + * @return true if the acid raid damage should stop + */ protected boolean checkForRain(Player player) { if (!addon.getOverWorld().hasStorm() || player.isDead() || isSafeFromRain(player) || addon.getSettings().getAcidRainDamage() <= 0D) { wetPlayers.remove(player); @@ -168,7 +173,7 @@ protected boolean checkForRain(Player player) { double protection = addon.getSettings().getAcidRainDamage() * getDamageReduced(player); double totalDamage = Math.max(0, addon.getSettings().getAcidRainDamage() - protection); AcidRainEvent event = new AcidRainEvent(player, totalDamage, protection, addon.getSettings().getAcidRainEffects()); - addon.getServer().getPluginManager().callEvent(event); + Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { event.getPotionEffects().stream().filter(EFFECTS::contains).forEach(t -> player.addPotionEffect(new PotionEffect(t, addon.getSettings().getRainEffectDuation() * 20, 1))); // Apply damage if there is any diff --git a/src/test/java/world/bentobox/acidisland/listeners/AcidEffectTest.java b/src/test/java/world/bentobox/acidisland/listeners/AcidEffectTest.java index c5cd966..eef157c 100644 --- a/src/test/java/world/bentobox/acidisland/listeners/AcidEffectTest.java +++ b/src/test/java/world/bentobox/acidisland/listeners/AcidEffectTest.java @@ -1,5 +1,6 @@ package world.bentobox.acidisland.listeners; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; @@ -18,6 +19,7 @@ import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.Server; import org.bukkit.World; import org.bukkit.World.Environment; import org.bukkit.attribute.Attribute; @@ -69,7 +71,7 @@ @RunWith(PowerMockRunner.class) @PrepareForTest({Bukkit.class, Util.class}) public class AcidEffectTest { - + @Mock private AcidIsland addon; @Mock @@ -112,7 +114,9 @@ public class AcidEffectTest { private IslandWorldManager iwm; @Mock private IslandsManager im; - + @Mock + private Server server; + /** */ @@ -122,12 +126,12 @@ public void setUp() { when(Bukkit.getScheduler()).thenReturn(scheduler); when(addon.getSettings()).thenReturn(settings); when(addon.getOverWorld()).thenReturn(world); - + // Essentials when(Bukkit.getPluginManager()).thenReturn(pim); when(pim.getPlugin(eq("Essentials"))).thenReturn(essentials); when(essentials.getUser(any(Player.class))).thenReturn(essentialsUser); - + // Player when(player.getGameMode()).thenReturn(GameMode.SURVIVAL); when(player.getWorld()).thenReturn(world); @@ -136,12 +140,12 @@ public void setUp() { when(player.getInventory()).thenReturn(inv); ItemStack[] armor = { new ItemStack(Material.CHAINMAIL_HELMET) }; when(inv.getArmorContents()).thenReturn(armor); - + // Location when(location.getBlockY()).thenReturn(-66); when(location.getWorld()).thenReturn(world); when(location.getBlock()).thenReturn(block); - + // Blocks when(block.getType()).thenReturn(Material.WATER); when(block.getTemperature()).thenReturn(0.5D); @@ -149,42 +153,43 @@ public void setUp() { when(block.getRelative(any())).thenReturn(block); when(airBlock.getType()).thenReturn(Material.AIR); when(solidBlock.getType()).thenReturn(Material.CHISELED_RED_SANDSTONE); - + // Settings when(settings.getAcidDestroyItemTime()).thenReturn(0L); when(settings.getAcidRainDamage()).thenReturn(10); when(settings.getAcidDamage()).thenReturn(10); when(settings.getAcidDamageDelay()).thenReturn(60L); - + // Players Manager when(addon.getPlayers()).thenReturn(pm); - + // Mock item factory (for itemstacks) ItemFactory itemFactory = mock(ItemFactory.class); when(Bukkit.getItemFactory()).thenReturn(itemFactory); when(itemFactory.getItemMeta(any())).thenReturn(itemMeta); - + // Util PowerMockito.mockStatic(Util.class); when(Util.sameWorld(any(), any())).thenReturn(true); - + // World when(world.hasStorm()).thenReturn(true); when(world.getBlockAt(anyInt(), anyInt(), anyInt())).thenReturn(airBlock); when(world.getMaxHeight()).thenReturn(5); when(world.getMinHeight()).thenReturn(-65); when(world.getEnvironment()).thenReturn(Environment.NORMAL); - + // Plugin when(addon.getPlugin()).thenReturn(plugin); when(plugin.getIWM()).thenReturn(iwm); // CUSTOM damage protection when(iwm.getIvSettings(any())).thenReturn(Collections.singletonList("CUSTOM")); - + // Island manager when(addon.getIslands()).thenReturn(im); when(im.userIsOnIsland(any(), any())).thenReturn(true); - + + ae = new AcidEffect(addon); } @@ -215,7 +220,7 @@ public void testOnSeaBounce() { verify(player).setVelocity(argument.capture()); assertTrue(argument.getValue().getBlockY() == 1D); } - + /** * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onSeaBounce(org.bukkit.event.player.PlayerMoveEvent)}. */ @@ -226,7 +231,7 @@ public void testOnSeaBounceCreative() { ae.onSeaBounce(e); verify(player, never()).setVelocity(any()); } - + /** * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onSeaBounce(org.bukkit.event.player.PlayerMoveEvent)}. */ @@ -237,7 +242,7 @@ public void testOnSeaBounceSpectator() { ae.onSeaBounce(e); verify(player, never()).setVelocity(any()); } - + /** * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onSeaBounce(org.bukkit.event.player.PlayerMoveEvent)}. */ @@ -248,7 +253,7 @@ public void testOnSeaBounceWrongWorld() { ae.onSeaBounce(e); verify(player, never()).setVelocity(any()); } - + /** * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onSeaBounce(org.bukkit.event.player.PlayerMoveEvent)}. */ @@ -269,7 +274,7 @@ public void testOnPlayerMoveAcidAndRainDamage() { ae.onPlayerMove(e); verify(settings, times(2)).getAcidDamageDelay(); } - + /** * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. */ @@ -280,7 +285,7 @@ public void testOnPlayerMoveVisitorNoAcidAndRainDamage() { ae.onPlayerMove(e); verify(settings, never()).getAcidDamageDelay(); } - + /** * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. */ @@ -292,7 +297,7 @@ public void testOnPlayerMoveVisitorAcidAndRainDamage() { ae.onPlayerMove(e); verify(settings, times(2)).getAcidDamageDelay(); } - + /** * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. */ @@ -303,7 +308,7 @@ public void testOnPlayerMoveGodModeNoAcidAndRainDamage() { ae.onPlayerMove(e); verify(settings, never()).getAcidDamageDelay(); } - + /** * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. */ @@ -314,7 +319,7 @@ public void testOnPlayerMoveDryNoDamage() { ae.onPlayerMove(e); verify(settings).getAcidDamageDelay(); } - + /** * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. */ @@ -326,7 +331,7 @@ public void testOnPlayerMoveSnowDamage() { ae.onPlayerMove(e); verify(settings, times(2)).getAcidDamageDelay(); } - + /** * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. */ @@ -338,7 +343,7 @@ public void testOnPlayerMoveNoSnowDamage() { ae.onPlayerMove(e); verify(settings).getAcidDamageDelay(); } - + /** * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. */ @@ -351,7 +356,7 @@ public void testOnPlayerMoveHelmetProtection() { ae.onPlayerMove(e); verify(settings).getAcidDamageDelay(); } - + /** * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. */ @@ -364,7 +369,7 @@ public void testOnPlayerMoveNoHelmetProtection() { ae.onPlayerMove(e); verify(settings, times(2)).getAcidDamageDelay(); } - + /** * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. */ @@ -375,7 +380,7 @@ public void testOnPlayerMoveUnderObject() { ae.onPlayerMove(e); verify(settings).getAcidDamageDelay(); } - + /** * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. */ @@ -383,15 +388,15 @@ public void testOnPlayerMoveUnderObject() { public void testOnPlayerMoveAcidRainWrongWorld() { World nether = mock(World.class); when(nether.getName()).thenReturn("world_nether"); - when(nether.getEnvironment()).thenReturn(Environment.NETHER); + when(nether.getEnvironment()).thenReturn(Environment.NETHER); when(player.getWorld()).thenReturn(nether); - + PlayerMoveEvent e = new PlayerMoveEvent(player, from, to); ae.onPlayerMove(e); // 3 times only verify(addon, times(3)).getPlugin(); } - + /** * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. */ @@ -399,15 +404,15 @@ public void testOnPlayerMoveAcidRainWrongWorld() { public void testOnPlayerMoveAcidRainWrongWorldEnd() { World end = mock(World.class); when(end.getName()).thenReturn("world_end"); - when(end.getEnvironment()).thenReturn(Environment.THE_END); + when(end.getEnvironment()).thenReturn(Environment.THE_END); when(player.getWorld()).thenReturn(end); - + PlayerMoveEvent e = new PlayerMoveEvent(player, from, to); ae.onPlayerMove(e); // 3 times only verify(addon, times(3)).getPlugin(); } - + /** * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. */ @@ -418,7 +423,7 @@ public void testOnPlayerMoveNoAcidRain() { ae.onPlayerMove(e); verify(settings).getAcidDamageDelay(); } - + /** * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. */ @@ -430,7 +435,7 @@ public void testOnPlayerMoveNoAcidDamage() { ae.onPlayerMove(e); verify(settings, never()).getAcidDamageDelay(); } - + /** * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. */ @@ -442,7 +447,7 @@ public void testOnPlayerMoveBubbleColumn() { ae.onPlayerMove(e); verify(settings).getAcidDamageDelay(); } - + /** * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. */ @@ -455,7 +460,7 @@ public void testOnPlayerMoveSnow() { ae.onPlayerMove(e); verify(settings).getAcidDamageDelay(); } - + /** * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. */ @@ -468,7 +473,7 @@ public void testOnPlayerMoveNoSnowAcidDamage() { ae.onPlayerMove(e); verify(settings, never()).getAcidDamageDelay(); } - + /** * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. */ @@ -482,7 +487,7 @@ public void testOnPlayerMoveInBoat() { ae.onPlayerMove(e); verify(settings, never()).getAcidDamageDelay(); } - + /** * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. */ @@ -508,7 +513,7 @@ public void testOnPlayerMoveFullArmor() { ae.onPlayerMove(e); verify(settings, never()).getAcidDamageDelay(); } - + /** * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. */ @@ -522,7 +527,7 @@ public void testOnPlayerMoveNotFullArmor() { ae.onPlayerMove(e); verify(settings).getAcidDamageDelay(); } - + /** * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. */ @@ -535,7 +540,7 @@ public void testOnPlayerMoveActivePotions() { ae.onPlayerMove(e); verify(settings, never()).getAcidDamageDelay(); } - + /** * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. */ @@ -548,7 +553,7 @@ public void testOnPlayerMoveActivePotionsConduit() { ae.onPlayerMove(e); verify(settings, never()).getAcidDamageDelay(); } - + /** * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. */ @@ -579,7 +584,66 @@ public void testGetDamageReducedFullDiamond() { when(player.getEquipment()).thenReturn(equip); double a = AcidEffect.getDamageReduced(player); assertTrue(a == 0.8); - + + } + + /** + * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#checkForRain(Player)}. + */ + @Test + public void testCheckForRain() { + when(world.hasStorm()).thenReturn(true); + when(player.isDead()).thenReturn(false); + when(settings.getAcidRainDamage()).thenReturn(10); + when(world.getEnvironment()).thenReturn(Environment.NORMAL); + assertFalse(ae.checkForRain(player)); + when(world.hasStorm()).thenReturn(false); + when(player.isDead()).thenReturn(false); + when(settings.getAcidRainDamage()).thenReturn(10); + when(world.getEnvironment()).thenReturn(Environment.NORMAL); + assertTrue(ae.checkForRain(player)); + when(world.hasStorm()).thenReturn(true); + when(player.isDead()).thenReturn(true); + when(settings.getAcidRainDamage()).thenReturn(10); + when(world.getEnvironment()).thenReturn(Environment.NORMAL); + assertTrue(ae.checkForRain(player)); + when(world.hasStorm()).thenReturn(true); + when(player.isDead()).thenReturn(false); + when(settings.getAcidRainDamage()).thenReturn(0); + when(world.getEnvironment()).thenReturn(Environment.NORMAL); + assertTrue(ae.checkForRain(player)); + when(world.hasStorm()).thenReturn(true); + when(player.isDead()).thenReturn(false); + when(settings.getAcidRainDamage()).thenReturn(10); + when(world.getEnvironment()).thenReturn(Environment.NETHER); + assertTrue(ae.checkForRain(player)); + } + + /** + * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#checkForRain(Player)}. + */ + @Test + public void testCheckForRainWetPlayer() { + AttributeInstance value = mock(AttributeInstance.class); + when(value.getValue()).thenReturn(20D); + // Diamond armor + when(player.getAttribute(eq(Attribute.GENERIC_ARMOR))).thenReturn(value); + EntityEquipment equip = mock(EntityEquipment.class); + when(equip.getBoots()).thenReturn(new ItemStack(Material.DIAMOND_BOOTS)); + when(equip.getHelmet()).thenReturn(new ItemStack(Material.DIAMOND_HELMET)); + when(equip.getLeggings()).thenReturn(new ItemStack(Material.DIAMOND_LEGGINGS)); + when(equip.getChestplate()).thenReturn(new ItemStack(Material.DIAMOND_CHESTPLATE)); + when(player.getEquipment()).thenReturn(equip); + + when(settings.getAcidDamageDelay()).thenReturn(0L); + when(world.hasStorm()).thenReturn(true); + when(player.isDead()).thenReturn(false); + when(settings.getAcidRainDamage()).thenReturn(10); + when(world.getEnvironment()).thenReturn(Environment.NORMAL); + testOnPlayerMoveAcidAndRainDamage(); + + assertFalse(ae.checkForRain(player)); + verify(player).damage(2.0d); // Reduced due to armor } } From a689d36f57be30454f184b52a47fa70434b83f20 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 5 Nov 2023 06:45:30 -0800 Subject: [PATCH 09/14] Make ocean floor default to on --- src/main/resources/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 4cbb953..587040f 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -138,7 +138,7 @@ world: # Ocean Floor # This creates an ocean floor environment, with vanilla elements. # /!\ BentoBox currently does not support changing this value mid-game. If you do need to change it, do a full reset of your databases and worlds. - ocean-floor: false + ocean-floor: true # Maximum number of islands in the world. Set to -1 or 0 for unlimited. # If the number of islands is greater than this number, no new island will be created. max-islands: 0 From 7384711a6457f3605e649498f58333e695efd4a9 Mon Sep 17 00:00:00 2001 From: tastybento Date: Thu, 9 Nov 2023 22:06:13 -0800 Subject: [PATCH 10/14] Shifted island height to 65 --- pom.xml | 2 +- src/main/resources/config.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 58acbce..f3f5dbf 100644 --- a/pom.xml +++ b/pom.xml @@ -58,7 +58,7 @@ 2.0.9 - 1.20.1-R0.1-SNAPSHOT + 1.20.2-R0.1-SNAPSHOT 1.24.0 ${build.version}-SNAPSHOT diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 587040f..ce2df30 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -124,14 +124,14 @@ world: offset-z: 0 # Island height - Lowest is 5. # It is the y coordinate of the bedrock block in the schem. - island-height: 50 + island-height: 60 # Use your own world generator for this world. # In this case, the plugin will not generate anything. # /!\ This feature is experimental and might not work as expected or might not work at all. use-own-generator: false # Sea height (don't changes this mid-game unless you delete the world) # Minimum is 0, which means you are playing Skyblock! - sea-height: 54 + sea-height: 64 # Water block. This should usually stay as WATER, but may be LAVA for fun # /!\ BentoBox currently does not support changing this value mid-game. If you do need to change it, do a full reset of your databases and worlds. water-block: WATER From ac999a044aa5dabfbcf639a7db59bbc2e7b6952e Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 12 Nov 2023 09:40:50 -0800 Subject: [PATCH 11/14] User 2.0.0 BentoBox API --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f3f5dbf..2677002 100644 --- a/pom.xml +++ b/pom.xml @@ -59,7 +59,7 @@ 2.0.9 1.20.2-R0.1-SNAPSHOT - 1.24.0 + 2.0.0-SNAPSHOT ${build.version}-SNAPSHOT From 8ee933f2f2cd1d9dab7dec63fdf92c6d61fe28a0 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 12 Nov 2023 12:31:33 -0800 Subject: [PATCH 12/14] Fix test to enable RanksManager database --- .../bentobox/acidisland/AcidIslandTest.java | 446 ++++++++++-------- 1 file changed, 243 insertions(+), 203 deletions(-) diff --git a/src/test/java/world/bentobox/acidisland/AcidIslandTest.java b/src/test/java/world/bentobox/acidisland/AcidIslandTest.java index 59dda5e..32a2f66 100644 --- a/src/test/java/world/bentobox/acidisland/AcidIslandTest.java +++ b/src/test/java/world/bentobox/acidisland/AcidIslandTest.java @@ -7,21 +7,27 @@ 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.ArgumentMatchers.anyString; 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; @@ -32,6 +38,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; @@ -48,222 +55,255 @@ 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; import world.bentobox.bentobox.managers.FlagsManager; import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandsManager; +import world.bentobox.bentobox.managers.RanksManager; /** * @author tastybento * */ @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 AcidIslandTest { - /** - * Class under test - */ - private AcidIsland addon; - - @Mock - private User user; - @Mock - private IslandsManager im; - @Mock - private Island island; - @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, Mockito.RETURNS_MOCKS); - Server server = mock(Server.class); - when(Bukkit.getServer()).thenReturn(server); - when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger()); - when(Bukkit.getPluginManager()).thenReturn(mock(PluginManager.class)); - when(Bukkit.getWorld(anyString())).thenReturn(null); - - // Addon - addon = new AcidIsland(); - File jFile = new File("addon.jar"); - List lines = Arrays.asList("# AcidIsland 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/AcidIsland"); - addon.setDataFolder(dataFolder); - addon.setFile(jFile); - AddonDescription desc = new AddonDescription.Builder("bentobox", "AcidIsland", "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/acidisland","config.yml").delete(); - new File("addons/acidisland").delete(); - new File("addons").delete(); - } - - /** - * Test method for {@link world.bentobox.acidisland.AcidIsland#onLoad()}. - */ - @Test - public void testOnLoad() { - addon.onLoad(); - // Check that config.yml file has been saved - File check = new File("addons/AcidIsland","config.yml"); - assertTrue(check.exists()); - } - - /** - * Test method for {@link world.bentobox.acidisland.AcidIsland#onEnable()}. - */ - @Test - public void testOnEnable() { - testOnLoad(); - addon.onEnable(); - assertTrue(addon.getPlayerCommand().isPresent()); - assertTrue(addon.getAdminCommand().isPresent()); - } - - /** - * Test method for {@link world.bentobox.acidisland.AcidIsland#onReload()}. - */ - @Test - public void testOnReload() { - addon.onReload(); - // Check that config.yml file has been saved - File check = new File("addons/AcidIsland","config.yml"); - assertTrue(check.exists()); - } - - /** - * Test method for {@link world.bentobox.acidisland.AcidIsland#createWorlds()}. - */ - @Test - public void testCreateWorlds() { - addon.onLoad(); - addon.createWorlds(); - Mockito.verify(plugin).log("[AcidIsland] Creating AcidIsland..."); - Mockito.verify(plugin).log("[AcidIsland] Creating AcidIsland's Nether..."); - Mockito.verify(plugin).log("[AcidIsland] Creating AcidIsland's End World..."); - } - - /** - * Test method for {@link world.bentobox.acidisland.AcidIsland#getSettings()}. - */ - @Test - public void testGetSettings() { - addon.onLoad(); - assertNotNull(addon.getSettings()); - } - - /** - * Test method for {@link world.bentobox.acidisland.AcidIsland#getWorldSettings()}. - */ - @Test - public void testGetWorldSettings() { - addon.onLoad(); - assertEquals(addon.getSettings(), addon.getWorldSettings()); - } - - /** - * Test method for {@link world.bentobox.acidisland.AcidIsland#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); - } - - /** - * Test method for {@link world.bentobox.acidisland.AcidIsland#allLoaded()}. - */ - @Test - public void testAllLoaded() { - addon.allLoaded(); - } - - - /** - * Test method for {@link world.bentobox.acidisland.AcidIsland#saveWorldSettings()}. - */ - @Test - public void testSaveWorldSettings() { - addon.saveWorldSettings(); - } + /** + * Class under test + */ + private AcidIsland addon; + + @Mock + private User user; + @Mock + private IslandsManager im; + @Mock + private Island island; + @Mock + private BentoBox plugin; + @Mock + private FlagsManager fm; + @Mock + private Settings settings; + + private static AbstractDatabaseHandler 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 + */ + @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, Mockito.RETURNS_MOCKS); + Server server = mock(Server.class); + when(Bukkit.getServer()).thenReturn(server); + when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger()); + when(Bukkit.getPluginManager()).thenReturn(mock(PluginManager.class)); + when(Bukkit.getWorld(anyString())).thenReturn(null); + + // Addon + addon = new AcidIsland(); + File jFile = new File("addon.jar"); + List lines = Arrays.asList("# AcidIsland 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/AcidIsland"); + addon.setDataFolder(dataFolder); + addon.setFile(jFile); + AddonDescription desc = new AddonDescription.Builder("bentobox", "AcidIsland", "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); + + // RanksManager + RanksManager rm = new RanksManager(); + when(plugin.getRanksManager()).thenReturn(rm); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AcidIsland#onLoad()}. + */ + @Test + public void testOnLoad() { + addon.onLoad(); + // Check that config.yml file has been saved + File check = new File("addons/AcidIsland", "config.yml"); + assertTrue(check.exists()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AcidIsland#onEnable()}. + */ + @Test + public void testOnEnable() { + testOnLoad(); + addon.onEnable(); + assertTrue(addon.getPlayerCommand().isPresent()); + assertTrue(addon.getAdminCommand().isPresent()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AcidIsland#onReload()}. + */ + @Test + public void testOnReload() { + addon.onReload(); + // Check that config.yml file has been saved + File check = new File("addons/AcidIsland", "config.yml"); + assertTrue(check.exists()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AcidIsland#createWorlds()}. + */ + @Test + public void testCreateWorlds() { + addon.onLoad(); + addon.createWorlds(); + Mockito.verify(plugin).log("[AcidIsland] Creating AcidIsland..."); + Mockito.verify(plugin).log("[AcidIsland] Creating AcidIsland's Nether..."); + Mockito.verify(plugin).log("[AcidIsland] Creating AcidIsland's End World..."); + } + + /** + * Test method for {@link world.bentobox.acidisland.AcidIsland#getSettings()}. + */ + @Test + public void testGetSettings() { + addon.onLoad(); + assertNotNull(addon.getSettings()); + } + + /** + * Test method for + * {@link world.bentobox.acidisland.AcidIsland#getWorldSettings()}. + */ + @Test + public void testGetWorldSettings() { + addon.onLoad(); + assertEquals(addon.getSettings(), addon.getWorldSettings()); + } + + /** + * Test method for + * {@link world.bentobox.acidisland.AcidIsland#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); + } + + /** + * Test method for {@link world.bentobox.acidisland.AcidIsland#allLoaded()}. + */ + @Test + public void testAllLoaded() { + addon.allLoaded(); + } + + /** + * Test method for + * {@link world.bentobox.acidisland.AcidIsland#saveWorldSettings()}. + */ + @Test + public void testSaveWorldSettings() { + addon.saveWorldSettings(); + } } From 6f3da078863b0d4336c890bed58a6d666fc09076 Mon Sep 17 00:00:00 2001 From: mt-gitlocalize Date: Sun, 26 Nov 2023 10:43:21 +0000 Subject: [PATCH 13/14] Translate uk.yml via GitLocalize --- src/main/resources/locales/uk.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/resources/locales/uk.yml diff --git a/src/main/resources/locales/uk.yml b/src/main/resources/locales/uk.yml new file mode 100644 index 0000000..30af60b --- /dev/null +++ b/src/main/resources/locales/uk.yml @@ -0,0 +1,7 @@ +--- +acidisland: + sign: + line0: "&1Кислотний острів" + line1: "[ім'я]" + line2: Вода кислотна! + line3: Будь обережний! &c<3 From 4a1642f403fe90aec5129a13cc6e9ba38bb056ed Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 26 Nov 2023 10:23:22 -0800 Subject: [PATCH 14/14] Update uk.yml --- src/main/resources/locales/uk.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/locales/uk.yml b/src/main/resources/locales/uk.yml index 30af60b..e144148 100644 --- a/src/main/resources/locales/uk.yml +++ b/src/main/resources/locales/uk.yml @@ -2,6 +2,6 @@ acidisland: sign: line0: "&1Кислотний острів" - line1: "[ім'я]" + line1: "[name]" line2: Вода кислотна! line3: Будь обережний! &c<3