From e9656dedce61266b431e6bf6d434ee9ff7fbd28b Mon Sep 17 00:00:00 2001 From: tastybento Date: Thu, 13 Aug 2020 12:34:18 -0700 Subject: [PATCH 01/14] 1.14.3 --- pom.xml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4515a2c..d7617c2 100644 --- a/pom.xml +++ b/pom.xml @@ -65,7 +65,7 @@ -LOCAL - 1.14.2 + 1.14.3 @@ -135,6 +135,10 @@ + + ess-repo + https://ci.ender.zone/plugin/repository/everything/ + spigot-repo https://hub.spigotmc.org/nexus/content/repositories/snapshots @@ -151,6 +155,13 @@ + + + net.ess3 + EssentialsX + 2.17.2 + provided + org.spigotmc From 9193bb9cbd2a9229eaeee96a0e289ff160ee92e7 Mon Sep 17 00:00:00 2001 From: tastybento Date: Thu, 13 Aug 2020 12:34:45 -0700 Subject: [PATCH 02/14] Prevents damage to players with Essnetials God Mode on https://github.com/BentoBoxWorld/AcidIsland/issues/93 --- .../acidisland/listeners/AcidEffect.java | 23 ++++++++++++++- .../acidisland/listeners/AcidEffectTest.java | 29 ++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java b/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java index ed3ee5b..1353d7f 100644 --- a/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java +++ b/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; @@ -29,6 +30,8 @@ import org.bukkit.potion.PotionEffectType; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; +import com.earth2me.essentials.Essentials; + import world.bentobox.acidisland.AcidIsland; import world.bentobox.acidisland.events.AcidEvent; import world.bentobox.acidisland.events.AcidRainEvent; @@ -45,6 +48,8 @@ public class AcidEffect implements Listener { private final AcidIsland addon; private final Map burningPlayers = new HashMap<>(); private final Map wetPlayers = new HashMap<>(); + private Essentials essentials; + private boolean essentialsCheck; private static final List EFFECTS = Arrays.asList( PotionEffectType.BLINDNESS, PotionEffectType.CONFUSION, @@ -176,7 +181,8 @@ public class AcidEffect implements Listener { * @return true if they are safe */ private boolean isSafeFromRain(Player player) { - if (player.getWorld().getEnvironment().equals(Environment.NETHER) + if (isEssentialsGodMode(player) + || player.getWorld().getEnvironment().equals(Environment.NETHER) || player.getWorld().getEnvironment().equals(Environment.THE_END) || (addon.getSettings().isHelmetProtection() && (player.getInventory().getHelmet() != null && player.getInventory().getHelmet().getType().name().contains("HELMET"))) || (!addon.getSettings().isAcidDamageSnow() && player.getLocation().getBlock().getTemperature() < 0.1) // snow falls @@ -200,6 +206,8 @@ public class AcidEffect implements Listener { * @return true if player is safe */ private boolean isSafeFromAcid(Player player) { + // Check for GodMode + if (isEssentialsGodMode(player)) return true; // Not in liquid or on snow if (!player.getLocation().getBlock().getType().equals(Material.WATER) && !player.getLocation().getBlock().getType().equals(Material.BUBBLE_COLUMN) @@ -221,6 +229,19 @@ public class AcidEffect implements Listener { return player.getActivePotionEffects().stream().map(PotionEffect::getType).anyMatch(IMMUNE_EFFECTS::contains); } + /** + * Checks if player has Essentials God Mode enabled. + * @param player - player + * @return true if God Mode enabled, false if not or if Essentials plug does not exist + */ + private boolean isEssentialsGodMode(Player player) { + if (!essentialsCheck && essentials == null) { + essentials = (Essentials)Bukkit.getPluginManager().getPlugin("Essentials"); + essentialsCheck = true; + } + return essentials != null && essentials.getUser(player).isGodModeEnabled(); + } + /** * Checks what protection armor provides and slightly damages it as a result of the acid * @param le - player diff --git a/src/test/java/world/bentobox/acidisland/listeners/AcidEffectTest.java b/src/test/java/world/bentobox/acidisland/listeners/AcidEffectTest.java index ab7e93c..898d106 100644 --- a/src/test/java/world/bentobox/acidisland/listeners/AcidEffectTest.java +++ b/src/test/java/world/bentobox/acidisland/listeners/AcidEffectTest.java @@ -34,6 +34,7 @@ import org.bukkit.inventory.ItemFactory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.plugin.PluginManager; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.scheduler.BukkitScheduler; @@ -44,10 +45,14 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; +import org.mockito.Mockito; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; +import com.earth2me.essentials.Essentials; +import com.earth2me.essentials.User; + import world.bentobox.acidisland.AISettings; import world.bentobox.acidisland.AcidIsland; import world.bentobox.bentobox.managers.PlayersManager; @@ -91,6 +96,12 @@ public class AcidEffectTest { private PlayerInventory inv; @Mock private ItemMeta itemMeta; + @Mock + private PluginManager pim; + @Mock + private Essentials essentials; + @Mock + private User essentialsUser; /** @@ -98,11 +109,16 @@ public class AcidEffectTest { */ @Before public void setUp() throws Exception { - PowerMockito.mockStatic(Bukkit.class); + PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS); 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); @@ -235,6 +251,17 @@ public class AcidEffectTest { verify(settings, times(2)).getAcidDamageDelay(); } + /** + * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. + */ + @Test + public void testOnPlayerMoveGodModeNoAcidAndRainDamage() { + when(essentialsUser.isGodModeEnabled()).thenReturn(true); + PlayerMoveEvent e = new PlayerMoveEvent(player, from, to); + ae.onPlayerMove(e); + verify(settings, never()).getAcidDamageDelay(); + } + /** * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. */ From cfbda44e1f416ca8e285a061ea1ceb300076d98e Mon Sep 17 00:00:00 2001 From: tastybento Date: Thu, 13 Aug 2020 16:51:14 -0700 Subject: [PATCH 03/14] 1.16.2 spigot API --- pom.xml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index d7617c2..01ad2ed 100644 --- a/pom.xml +++ b/pom.xml @@ -58,7 +58,7 @@ 2.0.4 - 1.16.1-R0.1-SNAPSHOT + 1.16.2-R0.1-SNAPSHOT 1.14.0 ${build.version}-SNAPSHOT @@ -135,10 +135,6 @@ - - ess-repo - https://ci.ender.zone/plugin/repository/everything/ - spigot-repo https://hub.spigotmc.org/nexus/content/repositories/snapshots @@ -151,17 +147,14 @@ codemc-repo https://repo.codemc.org/repository/maven-public/ + + ess-repo + https://ci.ender.zone/plugin/repository/everything/ + - - - net.ess3 - EssentialsX - 2.17.2 - provided - org.spigotmc @@ -203,6 +196,13 @@ org.eclipse.jdt.annotation 2.2.200 + + + net.ess3 + EssentialsX + 2.17.2 + provided + From 6708937c17eb9a7380ad95b060261434609d48b5 Mon Sep 17 00:00:00 2001 From: tastybento Date: Fri, 14 Aug 2020 15:31:07 -0700 Subject: [PATCH 04/14] Protects visitors from acid damage. Sets default for to allow acid damage for visitors. Fixes https://github.com/BentoBoxWorld/AcidIsland/issues/93 --- .../acidisland/listeners/AcidEffect.java | 13 ++++- .../bentobox/acidisland/world/AcidTask.java | 1 - src/main/resources/config.yml | 1 - .../acidisland/listeners/AcidEffectTest.java | 51 +++++++++++++++++-- 4 files changed, 59 insertions(+), 7 deletions(-) diff --git a/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java b/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java index 1353d7f..a17f255 100644 --- a/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java +++ b/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java @@ -19,6 +19,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.inventory.EntityEquipment; @@ -36,6 +37,7 @@ import world.bentobox.acidisland.AcidIsland; import world.bentobox.acidisland.events.AcidEvent; import world.bentobox.acidisland.events.AcidRainEvent; import world.bentobox.acidisland.world.AcidTask; +import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.util.Util; /** @@ -188,6 +190,9 @@ public class AcidEffect implements Listener { || (!addon.getSettings().isAcidDamageSnow() && player.getLocation().getBlock().getTemperature() < 0.1) // snow falls || player.getLocation().getBlock().getHumidity() == 0 // dry || (player.getActivePotionEffects().stream().map(PotionEffect::getType).anyMatch(IMMUNE_EFFECTS::contains)) + // Protect visitors + || (addon.getPlugin().getIWM().getIvSettings(player.getWorld()).contains(DamageCause.CUSTOM.name()) + && !addon.getIslands().userIsOnIsland(player.getWorld(), User.getInstance(player))) ) { return true; } @@ -207,7 +212,13 @@ public class AcidEffect implements Listener { */ private boolean isSafeFromAcid(Player player) { // Check for GodMode - if (isEssentialsGodMode(player)) return true; + if (isEssentialsGodMode(player) + // Protect visitors + || (addon.getPlugin().getIWM().getIvSettings(player.getWorld()).contains(DamageCause.CUSTOM.name()) + && !addon.getIslands().userIsOnIsland(player.getWorld(), User.getInstance(player))) + ) { + return true; + } // Not in liquid or on snow if (!player.getLocation().getBlock().getType().equals(Material.WATER) && !player.getLocation().getBlock().getType().equals(Material.BUBBLE_COLUMN) diff --git a/src/main/java/world/bentobox/acidisland/world/AcidTask.java b/src/main/java/world/bentobox/acidisland/world/AcidTask.java index 80a98f1..1407e39 100644 --- a/src/main/java/world/bentobox/acidisland/world/AcidTask.java +++ b/src/main/java/world/bentobox/acidisland/world/AcidTask.java @@ -22,7 +22,6 @@ import org.bukkit.scheduler.BukkitTask; import world.bentobox.acidisland.AcidIsland; import world.bentobox.acidisland.listeners.AcidEffect; -import world.bentobox.bentobox.BentoBox; public class AcidTask { private final AcidIsland addon; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index f87f224..3fa9fc3 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -443,7 +443,6 @@ protection: invincible-visitors: - BLOCK_EXPLOSION - CONTACT - - CUSTOM - DROWNING - ENTITY_ATTACK - ENTITY_EXPLOSION diff --git a/src/test/java/world/bentobox/acidisland/listeners/AcidEffectTest.java b/src/test/java/world/bentobox/acidisland/listeners/AcidEffectTest.java index 898d106..5027fd5 100644 --- a/src/test/java/world/bentobox/acidisland/listeners/AcidEffectTest.java +++ b/src/test/java/world/bentobox/acidisland/listeners/AcidEffectTest.java @@ -12,6 +12,7 @@ import static org.mockito.Mockito.when; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -55,6 +56,9 @@ import com.earth2me.essentials.User; import world.bentobox.acidisland.AISettings; import world.bentobox.acidisland.AcidIsland; +import world.bentobox.bentobox.BentoBox; +import world.bentobox.bentobox.managers.IslandWorldManager; +import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.PlayersManager; import world.bentobox.bentobox.util.Util; @@ -102,6 +106,12 @@ public class AcidEffectTest { private Essentials essentials; @Mock private User essentialsUser; + @Mock + private BentoBox plugin; + @Mock + private IslandWorldManager iwm; + @Mock + private IslandsManager im; /** @@ -165,6 +175,16 @@ public class AcidEffectTest { when(world.getMaxHeight()).thenReturn(5); 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); } @@ -251,6 +271,29 @@ public class AcidEffectTest { verify(settings, times(2)).getAcidDamageDelay(); } + /** + * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. + */ + @Test + public void testOnPlayerMoveVisitorNoAcidAndRainDamage() { + when(im.userIsOnIsland(any(), any())).thenReturn(false); + PlayerMoveEvent e = new PlayerMoveEvent(player, from, to); + ae.onPlayerMove(e); + verify(settings, never()).getAcidDamageDelay(); + } + + /** + * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. + */ + @Test + public void testOnPlayerMoveVisitorAcidAndRainDamage() { + // No protection against CUSTOM damage + when(iwm.getIvSettings(any())).thenReturn(Collections.emptyList()); + PlayerMoveEvent e = new PlayerMoveEvent(player, from, to); + ae.onPlayerMove(e); + verify(settings, times(2)).getAcidDamageDelay(); + } + /** * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. */ @@ -346,8 +389,8 @@ public class AcidEffectTest { PlayerMoveEvent e = new PlayerMoveEvent(player, from, to); ae.onPlayerMove(e); - // 2 times only - verify(addon, times(2)).getPlugin(); + // 3 times only + verify(addon, times(3)).getPlugin(); } /** @@ -362,8 +405,8 @@ public class AcidEffectTest { PlayerMoveEvent e = new PlayerMoveEvent(player, from, to); ae.onPlayerMove(e); - // 2 times only - verify(addon, times(2)).getPlugin(); + // 3 times only + verify(addon, times(3)).getPlugin(); } /** From fc84ea32bbf892e7a4d8e06a028c29e4c5722c07 Mon Sep 17 00:00:00 2001 From: tastybento Date: Mon, 17 Aug 2020 16:12:04 -0700 Subject: [PATCH 05/14] Add cleanstone removal to nether and end Fixes https://github.com/BentoBoxWorld/AcidIsland/issues/94 --- .../acidisland/listeners/LavaCheck.java | 11 +- .../acidisland/listeners/LavaCheckTest.java | 196 ++++++++++++++++++ 2 files changed, 202 insertions(+), 5 deletions(-) create mode 100644 src/test/java/world/bentobox/acidisland/listeners/LavaCheckTest.java diff --git a/src/main/java/world/bentobox/acidisland/listeners/LavaCheck.java b/src/main/java/world/bentobox/acidisland/listeners/LavaCheck.java index a0669a0..1cc0c3e 100644 --- a/src/main/java/world/bentobox/acidisland/listeners/LavaCheck.java +++ b/src/main/java/world/bentobox/acidisland/listeners/LavaCheck.java @@ -1,5 +1,6 @@ package world.bentobox.acidisland.listeners; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.event.EventHandler; @@ -8,6 +9,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.BlockFromToEvent; import world.bentobox.acidisland.AcidIsland; +import world.bentobox.bentobox.util.Util; public class LavaCheck implements Listener { @@ -26,14 +28,13 @@ public class LavaCheck implements Listener { */ @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onCleanstoneGen(BlockFromToEvent e) { - // Only do this in AcidIsland over world - if (!e.getBlock().getWorld().equals(addon.getOverWorld()) || addon.getSettings().getAcidDamage() <= 0 - // TODO: backward compatibility hack - || !(e.getToBlock().getType().name().equals("WATER"))) { + if (!(e.getToBlock().getType().equals(Material.WATER) + || !addon.getOverWorld().equals(Util.getWorld(e.getBlock().getWorld())) + || addon.getSettings().getAcidDamage() <= 0)) { return; } Material prev = e.getToBlock().getType(); - addon.getServer().getScheduler().runTask(addon.getPlugin(), () -> { + Bukkit.getScheduler().runTask(addon.getPlugin(), () -> { if (e.getToBlock().getType().equals(Material.STONE)) { e.getToBlock().setType(prev); e.getToBlock().getWorld().playSound(e.getToBlock().getLocation(), Sound.ENTITY_CREEPER_PRIMED, 1F, 2F); diff --git a/src/test/java/world/bentobox/acidisland/listeners/LavaCheckTest.java b/src/test/java/world/bentobox/acidisland/listeners/LavaCheckTest.java new file mode 100644 index 0000000..fbec17e --- /dev/null +++ b/src/test/java/world/bentobox/acidisland/listeners/LavaCheckTest.java @@ -0,0 +1,196 @@ +package world.bentobox.acidisland.listeners; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyFloat; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.event.block.BlockFromToEvent; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.plugin.PluginManager; +import org.bukkit.scheduler.BukkitScheduler; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import com.earth2me.essentials.Essentials; +import com.earth2me.essentials.User; + +import world.bentobox.acidisland.AISettings; +import world.bentobox.acidisland.AcidIsland; +import world.bentobox.bentobox.BentoBox; +import world.bentobox.bentobox.managers.IslandWorldManager; +import world.bentobox.bentobox.managers.IslandsManager; +import world.bentobox.bentobox.managers.PlayersManager; +import world.bentobox.bentobox.util.Util; + +/** + * @author tastybento + * + */ +@RunWith(PowerMockRunner.class) +@PrepareForTest({Bukkit.class, Util.class}) +public class LavaCheckTest { + @Mock + private AcidIsland addon; + @Mock + private BukkitScheduler scheduler; + private AISettings settings; + @Mock + private Location from; + @Mock + private Location to; + @Mock + private World world; + @Mock + private Location location; + @Mock + private PlayersManager pm; + @Mock + private Block block; + @Mock + private Block airBlock; + @Mock + private Block solidBlock; + @Mock + private PlayerInventory inv; + @Mock + private ItemMeta itemMeta; + @Mock + private PluginManager pim; + @Mock + private Essentials essentials; + @Mock + private User essentialsUser; + @Mock + private BentoBox plugin; + @Mock + private IslandWorldManager iwm; + @Mock + private IslandsManager im; + + private LavaCheck lc; + + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS); + when(Bukkit.getScheduler()).thenReturn(scheduler); + settings = new AISettings(); + when(addon.getSettings()).thenReturn(settings); + when(addon.getOverWorld()).thenReturn(world); + // Blocks + when(block.getType()).thenReturn(Material.WATER); + when(block.getWorld()).thenReturn(world); + when(block.getLocation()).thenReturn(location); + + // CUT + lc = new LavaCheck(addon); + } + + /** + * @throws java.lang.Exception + */ + @After + public void tearDown() throws Exception { + } + + /** + * Test method for {@link world.bentobox.acidisland.listeners.LavaCheck#onCleanstoneGen(org.bukkit.event.block.BlockFromToEvent)}. + */ + @Test + public void testOnCleanstoneGen() { + ArgumentCaptor argument = ArgumentCaptor.forClass(Runnable.class); + + BlockFromToEvent e = new BlockFromToEvent(airBlock, block); + lc.onCleanstoneGen(e); + + verify(scheduler).runTask(any(), argument.capture()); + // make block now be stone + when(block.getType()).thenReturn(Material.STONE); + // Run runnable + argument.getValue().run(); + verify(block).setType(eq(Material.WATER)); + verify(world).playSound(eq(location), eq(Sound.ENTITY_CREEPER_PRIMED), eq(1F), eq(2F)); + } + + /** + * Test method for {@link world.bentobox.acidisland.listeners.LavaCheck#onCleanstoneGen(org.bukkit.event.block.BlockFromToEvent)}. + */ + @Test + public void testOnCleanstoneGenNoStone() { + ArgumentCaptor argument = ArgumentCaptor.forClass(Runnable.class); + + BlockFromToEvent e = new BlockFromToEvent(airBlock, block); + lc.onCleanstoneGen(e); + + verify(scheduler).runTask(any(), argument.capture()); + // make block now be obsidian + when(block.getType()).thenReturn(Material.OBSIDIAN); + // Run runnable + argument.getValue().run(); + verify(block, never()).setType(any()); + verify(world, never()).playSound(any(Location.class), any(Sound.class), anyFloat(),anyFloat()); + } + + /** + * Test method for {@link world.bentobox.acidisland.listeners.LavaCheck#onCleanstoneGen(org.bukkit.event.block.BlockFromToEvent)}. + */ + @Test + public void testOnCleanstoneGenWrongWorld() { + when(block.getWorld()).thenReturn(Mockito.mock(World.class)); + + BlockFromToEvent e = new BlockFromToEvent(airBlock, block); + lc.onCleanstoneGen(e); + verify(block, never()).setType(any()); + verify(world, never()).playSound(any(Location.class), any(Sound.class), anyFloat(),anyFloat()); + } + + /** + * Test method for {@link world.bentobox.acidisland.listeners.LavaCheck#onCleanstoneGen(org.bukkit.event.block.BlockFromToEvent)}. + */ + @Test + public void testOnCleanstoneGenNotWater() { + when(block.getType()).thenReturn(Material.LAVA); + + BlockFromToEvent e = new BlockFromToEvent(airBlock, block); + lc.onCleanstoneGen(e); + verify(block, never()).setType(any()); + verify(world, never()).playSound(any(Location.class), any(Sound.class), anyFloat(),anyFloat()); + } + + /** + * Test method for {@link world.bentobox.acidisland.listeners.LavaCheck#onCleanstoneGen(org.bukkit.event.block.BlockFromToEvent)}. + */ + @Test + public void testOnCleanstoneGenNoAcid() { + // No acid damage + settings.setAcidDamage(0); + + BlockFromToEvent e = new BlockFromToEvent(airBlock, block); + lc.onCleanstoneGen(e); + + verify(block, never()).setType(any()); + verify(world, never()).playSound(any(Location.class), any(Sound.class), anyFloat(),anyFloat()); + } + + +} From 7f2216da8a4b5d4bfe011ab09eaeda5b6a57036e Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 12 Sep 2020 12:06:49 -0700 Subject: [PATCH 06/14] Code smell reduction (#100) --- .../java/world/bentobox/acidisland/AcidIsland.java | 2 +- .../java/world/bentobox/acidisland/world/AcidTask.java | 6 +++--- .../bentobox/acidisland/world/ChunkGeneratorWorld.java | 4 ++-- .../bentobox/acidisland/events/AcidEventTest.java | 5 ++--- .../bentobox/acidisland/events/AcidRainEventTest.java | 5 ++--- .../bentobox/acidisland/listeners/AcidEffectTest.java | 6 ++---- .../bentobox/acidisland/listeners/LavaCheckTest.java | 6 ++---- .../world/bentobox/acidisland/world/AcidTaskTest.java | 10 +++------- .../acidisland/world/ChunkGeneratorWorldTest.java | 6 ++---- 9 files changed, 19 insertions(+), 31 deletions(-) diff --git a/src/main/java/world/bentobox/acidisland/AcidIsland.java b/src/main/java/world/bentobox/acidisland/AcidIsland.java index 92e05d1..fa29337 100644 --- a/src/main/java/world/bentobox/acidisland/AcidIsland.java +++ b/src/main/java/world/bentobox/acidisland/AcidIsland.java @@ -30,7 +30,7 @@ public class AcidIsland extends GameModeAddon { private @Nullable AISettings settings; private @Nullable AcidTask acidTask; private @Nullable ChunkGenerator chunkGenerator; - private Config config = new Config<>(this, AISettings.class); + private final Config config = new Config<>(this, AISettings.class); private static final String NETHER = "_nether"; private static final String THE_END = "_the_end"; diff --git a/src/main/java/world/bentobox/acidisland/world/AcidTask.java b/src/main/java/world/bentobox/acidisland/world/AcidTask.java index 1407e39..baa9720 100644 --- a/src/main/java/world/bentobox/acidisland/world/AcidTask.java +++ b/src/main/java/world/bentobox/acidisland/world/AcidTask.java @@ -27,7 +27,7 @@ public class AcidTask { private final AcidIsland addon; private static final List IMMUNE = Arrays.asList(EntityType.TURTLE, EntityType.POLAR_BEAR, EntityType.DROWNED); private Map itemsInWater = new ConcurrentHashMap<>(); - private BukkitTask findMobsTask; + private final BukkitTask findMobsTask; /** * Runs repeating tasks to deliver acid damage to mobs, etc. @@ -35,7 +35,7 @@ public class AcidTask { */ public AcidTask(AcidIsland addon) { this.addon = addon; - findMobsTask = Bukkit.getScheduler().runTaskTimerAsynchronously(addon.getPlugin(), () -> findEntities(), 0L, 20L); + findMobsTask = Bukkit.getScheduler().runTaskTimerAsynchronously(addon.getPlugin(), this::findEntities, 0L, 20L); } void findEntities() { @@ -60,7 +60,7 @@ public class AcidTask { } } // Remove any entities not on the burn list - itemsInWater.keySet().removeIf(i -> !burnList.keySet().contains(i)); + itemsInWater.keySet().removeIf(i -> !burnList.containsKey(i)); if (!burnList.isEmpty()) { Bukkit.getScheduler().runTask(addon.getPlugin(), () -> diff --git a/src/main/java/world/bentobox/acidisland/world/ChunkGeneratorWorld.java b/src/main/java/world/bentobox/acidisland/world/ChunkGeneratorWorld.java index 6704ba0..69e094d 100644 --- a/src/main/java/world/bentobox/acidisland/world/ChunkGeneratorWorld.java +++ b/src/main/java/world/bentobox/acidisland/world/ChunkGeneratorWorld.java @@ -27,8 +27,8 @@ public class ChunkGeneratorWorld extends ChunkGenerator { private final AcidIsland addon; private final Random rand = new Random(); - private Map seaHeight = new EnumMap<>(Environment.class); - private Map roofChunk = new HashMap<>(); + private final Map seaHeight = new EnumMap<>(Environment.class); + private final Map roofChunk = new HashMap<>(); /** * @param addon - addon diff --git a/src/test/java/world/bentobox/acidisland/events/AcidEventTest.java b/src/test/java/world/bentobox/acidisland/events/AcidEventTest.java index cef6f3d..d049cfa 100644 --- a/src/test/java/world/bentobox/acidisland/events/AcidEventTest.java +++ b/src/test/java/world/bentobox/acidisland/events/AcidEventTest.java @@ -21,12 +21,11 @@ public class AcidEventTest { @Mock private Player player; - private List effects; private AcidEvent e; @Before - public void setUp() throws Exception { - effects = Arrays.asList(PotionEffectType.values()); + public void setUp() { + List effects = Arrays.asList(PotionEffectType.values()); e = new AcidEvent(player, 10, 5, effects); } diff --git a/src/test/java/world/bentobox/acidisland/events/AcidRainEventTest.java b/src/test/java/world/bentobox/acidisland/events/AcidRainEventTest.java index c8899a6..d4c28db 100644 --- a/src/test/java/world/bentobox/acidisland/events/AcidRainEventTest.java +++ b/src/test/java/world/bentobox/acidisland/events/AcidRainEventTest.java @@ -21,12 +21,11 @@ public class AcidRainEventTest { @Mock private Player player; - private List effects; private AcidRainEvent e; @Before - public void setUp() throws Exception { - effects = Arrays.asList(PotionEffectType.values()); + public void setUp() { + List effects = Arrays.asList(PotionEffectType.values()); e = new AcidRainEvent(player, 10, 5, effects); } diff --git a/src/test/java/world/bentobox/acidisland/listeners/AcidEffectTest.java b/src/test/java/world/bentobox/acidisland/listeners/AcidEffectTest.java index 5027fd5..99aab9d 100644 --- a/src/test/java/world/bentobox/acidisland/listeners/AcidEffectTest.java +++ b/src/test/java/world/bentobox/acidisland/listeners/AcidEffectTest.java @@ -115,10 +115,9 @@ public class AcidEffectTest { /** - * @throws java.lang.Exception */ @Before - public void setUp() throws Exception { + public void setUp() { PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS); when(Bukkit.getScheduler()).thenReturn(scheduler); when(addon.getSettings()).thenReturn(settings); @@ -189,10 +188,9 @@ public class AcidEffectTest { } /** - * @throws java.lang.Exception */ @After - public void tearDown() throws Exception { + public void tearDown() { } /** diff --git a/src/test/java/world/bentobox/acidisland/listeners/LavaCheckTest.java b/src/test/java/world/bentobox/acidisland/listeners/LavaCheckTest.java index fbec17e..c23c29a 100644 --- a/src/test/java/world/bentobox/acidisland/listeners/LavaCheckTest.java +++ b/src/test/java/world/bentobox/acidisland/listeners/LavaCheckTest.java @@ -88,10 +88,9 @@ public class LavaCheckTest { private LavaCheck lc; /** - * @throws java.lang.Exception */ @Before - public void setUp() throws Exception { + public void setUp() { PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS); when(Bukkit.getScheduler()).thenReturn(scheduler); settings = new AISettings(); @@ -107,10 +106,9 @@ public class LavaCheckTest { } /** - * @throws java.lang.Exception */ @After - public void tearDown() throws Exception { + public void tearDown() { } /** diff --git a/src/test/java/world/bentobox/acidisland/world/AcidTaskTest.java b/src/test/java/world/bentobox/acidisland/world/AcidTaskTest.java index 00a0a8d..057e381 100644 --- a/src/test/java/world/bentobox/acidisland/world/AcidTaskTest.java +++ b/src/test/java/world/bentobox/acidisland/world/AcidTaskTest.java @@ -64,8 +64,6 @@ public class AcidTaskTest { @Mock private World world; - private List mob; - @Mock private @Nullable World nether; @Mock @@ -81,10 +79,9 @@ public class AcidTaskTest { /** - * @throws java.lang.Exception */ @Before - public void setUp() throws Exception { + public void setUp() { PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS); when(Bukkit.getScheduler()).thenReturn(scheduler); when(scheduler.runTaskTimerAsynchronously(any(), any(Runnable.class), anyLong(), anyLong())).thenReturn(task); @@ -101,7 +98,7 @@ public class AcidTaskTest { // Default squid - mob = new ArrayList<>(); + List mob = new ArrayList<>(); Squid squid = mock(Squid.class); when(squid.getType()).thenReturn(EntityType.SQUID); when(squid.getLocation()).thenReturn(l); @@ -141,10 +138,9 @@ public class AcidTaskTest { } /** - * @throws java.lang.Exception */ @After - public void tearDown() throws Exception { + public void tearDown() { } /** diff --git a/src/test/java/world/bentobox/acidisland/world/ChunkGeneratorWorldTest.java b/src/test/java/world/bentobox/acidisland/world/ChunkGeneratorWorldTest.java index 2f02b53..9decf0e 100644 --- a/src/test/java/world/bentobox/acidisland/world/ChunkGeneratorWorldTest.java +++ b/src/test/java/world/bentobox/acidisland/world/ChunkGeneratorWorldTest.java @@ -54,10 +54,9 @@ public class ChunkGeneratorWorldTest { private ChunkData data; /** - * @throws java.lang.Exception */ @Before - public void setUp() throws Exception { + public void setUp() { // Bukkit PowerMockito.mockStatic(Bukkit.class); Server server = mock(Server.class); @@ -76,10 +75,9 @@ public class ChunkGeneratorWorldTest { } /** - * @throws java.lang.Exception */ @After - public void tearDown() throws Exception { + public void tearDown() { } /** From 15ffdfd4269b3690decd51c76083fb5cce054ff3 Mon Sep 17 00:00:00 2001 From: "gitlocalize-app[bot]" <55277160+gitlocalize-app[bot]@users.noreply.github.com> Date: Fri, 2 Oct 2020 14:42:34 -0700 Subject: [PATCH 07/14] Translate vi.yml via GitLocalize (#102) Co-authored-by: Nguyen Minh An --- src/main/resources/locales/vi.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/resources/locales/vi.yml diff --git a/src/main/resources/locales/vi.yml b/src/main/resources/locales/vi.yml new file mode 100644 index 0000000..ec990e9 --- /dev/null +++ b/src/main/resources/locales/vi.yml @@ -0,0 +1,7 @@ +--- +acidisland: + sign: + line0: "&1Đảo Axit" + line1: "[tên]" + line2: Nước là axit! + line3: Hãy cẩn thận! &c<3 From 388d386ef8a33ec728579d144e480de301acd9ae Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 10 Oct 2020 14:12:20 -0700 Subject: [PATCH 08/14] Updated to compile in Travis under JDK11 for sonar cloud --- .travis.yml | 2 +- pom.xml | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index af3496c..62d57c1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ addons: organization: "bentobox-world" jdk: - - openjdk8 + - openjdk11 script: # JaCoCo is used to have code coverage, the agent has to be activated diff --git a/pom.xml b/pom.xml index 01ad2ed..df27bd5 100644 --- a/pom.xml +++ b/pom.xml @@ -278,11 +278,13 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.0.1 + 3.2.0 + 8 public false -Xdoclint:none + ${java.home}/bin/javadoc From 91ff1422542ed10ca2f5149a8d7cedb3937c91ed Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 10 Oct 2020 14:21:48 -0700 Subject: [PATCH 09/14] Consolidated Acid events using an abscract event --- pom.xml | 2 +- .../world/bentobox/acidisland/AcidIsland.java | 2 +- .../acidisland/events/AbstractAcidEvent.java | 99 +++++++++++++++++++ .../bentobox/acidisland/events/AcidEvent.java | 69 +------------ .../acidisland/events/AcidRainEvent.java | 85 ++-------------- 5 files changed, 109 insertions(+), 148 deletions(-) create mode 100644 src/main/java/world/bentobox/acidisland/events/AbstractAcidEvent.java diff --git a/pom.xml b/pom.xml index df27bd5..f329fb0 100644 --- a/pom.xml +++ b/pom.xml @@ -284,7 +284,7 @@ public false -Xdoclint:none - ${java.home}/bin/javadoc + diff --git a/src/main/java/world/bentobox/acidisland/AcidIsland.java b/src/main/java/world/bentobox/acidisland/AcidIsland.java index fa29337..e00db0e 100644 --- a/src/main/java/world/bentobox/acidisland/AcidIsland.java +++ b/src/main/java/world/bentobox/acidisland/AcidIsland.java @@ -161,7 +161,7 @@ public class AcidIsland extends GameModeAddon { @Override public WorldSettings getWorldSettings() { - return settings; + return getSettings(); } @Override diff --git a/src/main/java/world/bentobox/acidisland/events/AbstractAcidEvent.java b/src/main/java/world/bentobox/acidisland/events/AbstractAcidEvent.java new file mode 100644 index 0000000..c98e9a6 --- /dev/null +++ b/src/main/java/world/bentobox/acidisland/events/AbstractAcidEvent.java @@ -0,0 +1,99 @@ +package world.bentobox.acidisland.events; + +import java.util.List; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.bukkit.potion.PotionEffectType; + +/** + * This event is fired when a player is going to be burned by acid or acid rain + * + * @author tastybento + * + */ +public abstract class AbstractAcidEvent extends Event implements Cancellable { + private static final HandlerList handlers = new HandlerList(); + + private Player player; + private final double protection; + /** + * @since 1.9.1 + */ + private List potionEffects; + + private boolean cancelled; + + + /** + * @param player + * @param rainDamage + * @param protection + */ + public AbstractAcidEvent(Player player, double protection, List potionEffects) { + this.player = player; + this.protection = protection; + this.potionEffects = potionEffects; + } + + /** + * @return the player being damaged by acid rain + */ + public Player getPlayer() { + return player; + } + + /** + * @param player the player to set + */ + public void setPlayer(Player player) { + this.player = player; + } + + /** + * Get the amount the damage was reduced for this player due to armor, etc. + * @return the protection + */ + public double getProtection() { + return protection; + } + + /** + * Returns the potion effects that will be applied to the player. + * @return list of potion effect types + * @since 1.9.1 + */ + public List getPotionEffects() { + return potionEffects; + } + + /** + * + * @param potionEffects the potionEffects to set + * @since 1.9.1 + */ + public void setPotionEffects(List potionEffects) { + this.potionEffects = potionEffects; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } +} diff --git a/src/main/java/world/bentobox/acidisland/events/AcidEvent.java b/src/main/java/world/bentobox/acidisland/events/AcidEvent.java index 48cf8f0..132b55e 100644 --- a/src/main/java/world/bentobox/acidisland/events/AcidEvent.java +++ b/src/main/java/world/bentobox/acidisland/events/AcidEvent.java @@ -3,9 +3,6 @@ package world.bentobox.acidisland.events; import java.util.List; import org.bukkit.entity.Player; -import org.bukkit.event.Cancellable; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; import org.bukkit.potion.PotionEffectType; /** @@ -14,13 +11,9 @@ import org.bukkit.potion.PotionEffectType; * @author tastybento * */ -public class AcidEvent extends Event implements Cancellable { - private static final HandlerList handlers = new HandlerList(); +public class AcidEvent extends AbstractAcidEvent { - private Player player; private double totalDamage; - private final double protection; - private List potionEffects; /** * @param player - player @@ -29,26 +22,8 @@ public class AcidEvent extends Event implements Cancellable { * @param potionEffects - potion effects given to the player */ public AcidEvent(Player player, double totalDamage, double protection, List potionEffects) { - this.player = player; + super(player, protection, potionEffects); this.totalDamage = totalDamage; - this.protection = protection; - this.potionEffects = potionEffects; - } - - private boolean cancelled; - - /** - * @return the player being damaged by acid rain - */ - public Player getPlayer() { - return player; - } - - /** - * @param player the player to set - */ - public void setPlayer(Player player) { - this.player = player; } /** @@ -59,14 +34,6 @@ public class AcidEvent extends Event implements Cancellable { return totalDamage; } - /** - * Get the amount the damage was reduced for this player due to armor, etc. - * @return the protection - */ - public double getProtection() { - return protection; - } - /** * @param totalDamage to set */ @@ -74,36 +41,4 @@ public class AcidEvent extends Event implements Cancellable { this.totalDamage = totalDamage; } - /** - * @return the potionEffects - */ - public List getPotionEffects() { - return potionEffects; - } - - /** - * @param potionEffects the potionEffects to set - */ - public void setPotionEffects(List potionEffects) { - this.potionEffects = potionEffects; - } - - @Override - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } - - @Override - public boolean isCancelled() { - return cancelled; - } - - @Override - public void setCancelled(boolean cancel) { - this.cancelled = cancel; - } } diff --git a/src/main/java/world/bentobox/acidisland/events/AcidRainEvent.java b/src/main/java/world/bentobox/acidisland/events/AcidRainEvent.java index f1ab40e..f83d8a4 100644 --- a/src/main/java/world/bentobox/acidisland/events/AcidRainEvent.java +++ b/src/main/java/world/bentobox/acidisland/events/AcidRainEvent.java @@ -3,9 +3,6 @@ package world.bentobox.acidisland.events; import java.util.List; import org.bukkit.entity.Player; -import org.bukkit.event.Cancellable; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; import org.bukkit.potion.PotionEffectType; /** @@ -14,44 +11,18 @@ import org.bukkit.potion.PotionEffectType; * @author tastybento * */ -public class AcidRainEvent extends Event implements Cancellable { - private static final HandlerList handlers = new HandlerList(); - - private Player player; +public class AcidRainEvent extends AbstractAcidEvent { private double rainDamage; - private final double protection; - /** - * @since 1.9.1 - */ - private List potionEffects; - - private boolean cancelled; - /** - * @param player - * @param rainDamage - * @param protection + * @param player - player + * @param rainDamage - rain damage caused + * @param protection - protection reducer to damage + * @param potionEffects - potion effects to apply if acid rain affects player */ public AcidRainEvent(Player player, double rainDamage, double protection, List potionEffects) { - this.player = player; + super(player, protection, potionEffects); this.rainDamage = rainDamage; - this.protection = protection; - this.potionEffects = potionEffects; - } - - /** - * @return the player being damaged by acid rain - */ - public Player getPlayer() { - return player; - } - - /** - * @param player the player to set - */ - public void setPlayer(Player player) { - this.player = player; } /** @@ -62,14 +33,6 @@ public class AcidRainEvent extends Event implements Cancellable { return rainDamage; } - /** - * Get the amount the damage was reduced for this player due to armor, etc. - * @return the protection - */ - public double getProtection() { - return protection; - } - /** * @param rainDamage the rainDamage to set */ @@ -77,40 +40,4 @@ public class AcidRainEvent extends Event implements Cancellable { this.rainDamage = rainDamage; } - /** - * Returns the potion effects that will be applied to the player. - * @return list of potion effect types - * @since 1.9.1 - */ - public List getPotionEffects() { - return potionEffects; - } - - /** - * - * @param potionEffects the potionEffects to set - * @since 1.9.1 - */ - public void setPotionEffects(List potionEffects) { - this.potionEffects = potionEffects; - } - - @Override - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } - - @Override - public boolean isCancelled() { - return cancelled; - } - - @Override - public void setCancelled(boolean cancel) { - this.cancelled = cancel; - } } From d1e13f1c958ac7cac70ace04c572ff313db2e576 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 10 Oct 2020 14:40:33 -0700 Subject: [PATCH 10/14] Refactored AcidEffect to make it easier to understand --- .../acidisland/events/AbstractAcidEvent.java | 2 +- .../events/ItemFillWithAcidEvent.java | 1 - .../acidisland/listeners/AcidEffect.java | 125 +++++++++++------- 3 files changed, 75 insertions(+), 53 deletions(-) diff --git a/src/main/java/world/bentobox/acidisland/events/AbstractAcidEvent.java b/src/main/java/world/bentobox/acidisland/events/AbstractAcidEvent.java index c98e9a6..93e47e0 100644 --- a/src/main/java/world/bentobox/acidisland/events/AbstractAcidEvent.java +++ b/src/main/java/world/bentobox/acidisland/events/AbstractAcidEvent.java @@ -80,7 +80,7 @@ public abstract class AbstractAcidEvent extends Event implements Cancellable { @Override public HandlerList getHandlers() { - return handlers; + return getHandlerList(); } public static HandlerList getHandlerList() { diff --git a/src/main/java/world/bentobox/acidisland/events/ItemFillWithAcidEvent.java b/src/main/java/world/bentobox/acidisland/events/ItemFillWithAcidEvent.java index f93d30c..f2a2d24 100644 --- a/src/main/java/world/bentobox/acidisland/events/ItemFillWithAcidEvent.java +++ b/src/main/java/world/bentobox/acidisland/events/ItemFillWithAcidEvent.java @@ -15,7 +15,6 @@ public class ItemFillWithAcidEvent extends IslandBaseEvent { private final Player player; private final ItemStack item; - // TODO: dispenser? public ItemFillWithAcidEvent(Island island, Player player, ItemStack item) { super(island); this.player = player; diff --git a/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java b/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java index a17f255..a7b6161 100644 --- a/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java +++ b/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java @@ -1,13 +1,13 @@ package world.bentobox.acidisland.listeners; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.GameMode; -import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.World.Environment; @@ -48,24 +48,35 @@ import world.bentobox.bentobox.util.Util; public class AcidEffect implements Listener { private final AcidIsland addon; - private final Map burningPlayers = new HashMap<>(); - private final Map wetPlayers = new HashMap<>(); + private final Map burningPlayers; + private final Map wetPlayers; private Essentials essentials; private boolean essentialsCheck; - private static final List EFFECTS = Arrays.asList( - PotionEffectType.BLINDNESS, - PotionEffectType.CONFUSION, - PotionEffectType.HUNGER, - PotionEffectType.SLOW, - PotionEffectType.SLOW_DIGGING, - PotionEffectType.WEAKNESS, - PotionEffectType.POISON); - private static final List IMMUNE_EFFECTS = Arrays.asList( - PotionEffectType.WATER_BREATHING, - PotionEffectType.CONDUIT_POWER); + private static final List EFFECTS; + static { + List pe = Arrays.asList( + PotionEffectType.BLINDNESS, + PotionEffectType.CONFUSION, + PotionEffectType.HUNGER, + PotionEffectType.SLOW, + PotionEffectType.SLOW_DIGGING, + PotionEffectType.WEAKNESS, + PotionEffectType.POISON); + EFFECTS = Collections.unmodifiableList(pe); + } + + private static final List IMMUNE_EFFECTS; + static { + List im = Arrays.asList( + PotionEffectType.WATER_BREATHING, + PotionEffectType.CONDUIT_POWER); + IMMUNE_EFFECTS = Collections.unmodifiableList(im); + } public AcidEffect(AcidIsland addon) { this.addon = addon; + burningPlayers = new HashMap<>(); + wetPlayers = new HashMap<>(); // Burn monsters or animals that fall into the acid new AcidTask(addon); } @@ -100,7 +111,6 @@ public class AcidEffect implements Listener { return; } // Slow checks - Location playerLoc = player.getLocation(); // Check for acid rain if (addon.getSettings().getAcidRainDamage() > 0D && addon.getOverWorld().hasStorm()) { if (isSafeFromRain(player)) { @@ -117,24 +127,10 @@ public class AcidEffect implements Listener { @Override public void run() { // Check if it is still raining or player is safe or dead or there is no damage - if (!addon.getOverWorld().hasStorm() || player.isDead() || isSafeFromRain(player) || addon.getSettings().getAcidRainDamage() <= 0D) { - wetPlayers.remove(player); + if (checkForRain(player)) { this.cancel(); - // Check they are still in this world - } else if (wetPlayers.containsKey(player) && wetPlayers.get(player) < System.currentTimeMillis()) { - 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); - 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 - if (event.getRainDamage() > 0D) { - player.damage(event.getRainDamage()); - player.getWorld().playSound(playerLoc, Sound.ENTITY_CREEPER_PRIMED, 3F, 3F); - } - } } + } }.runTaskTimer(addon.getPlugin(), 0L, 20L); } @@ -142,10 +138,7 @@ public class AcidEffect implements Listener { } // If they are already burning in acid then return - if (burningPlayers.containsKey(player)) { - return; - } - if (isSafeFromAcid(player)) { + if (burningPlayers.containsKey(player) || isSafeFromAcid(player)) { return; } // ACID! @@ -156,27 +149,57 @@ public class AcidEffect implements Listener { new BukkitRunnable() { @Override public void run() { - if (player.isDead() || isSafeFromAcid(player)) { - burningPlayers.remove(player); + if (continuouslyHurtPlayer(player)) { this.cancel(); - } else if (burningPlayers.containsKey(player) && burningPlayers.get(player) < System.currentTimeMillis()) { - double protection = addon.getSettings().getAcidDamage() * getDamageReduced(player); - double totalDamage = Math.max(0, addon.getSettings().getAcidDamage() - protection); - AcidEvent acidEvent = new AcidEvent(player, totalDamage, protection, addon.getSettings().getAcidEffects()); - addon.getServer().getPluginManager().callEvent(acidEvent); - if (!acidEvent.isCancelled()) { - acidEvent.getPotionEffects().stream().filter(EFFECTS::contains).forEach(t -> player.addPotionEffect(new PotionEffect(t, addon.getSettings().getAcidEffectDuation() * 20, 1))); - // Apply damage if there is any - if (acidEvent.getTotalDamage() > 0D) { - player.damage(acidEvent.getTotalDamage()); - player.getWorld().playSound(playerLoc, Sound.ENTITY_CREEPER_PRIMED, 3F, 3F); - } - } } + } }.runTaskTimer(addon.getPlugin(), 0L, 20L); } + protected boolean checkForRain(Player player) { + if (!addon.getOverWorld().hasStorm() || player.isDead() || isSafeFromRain(player) || addon.getSettings().getAcidRainDamage() <= 0D) { + wetPlayers.remove(player); + return true; + // Check they are still in this world + } else if (wetPlayers.containsKey(player) && wetPlayers.get(player) < System.currentTimeMillis()) { + 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); + 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 + if (event.getRainDamage() > 0D) { + player.damage(event.getRainDamage()); + player.getWorld().playSound(player.getLocation(), Sound.ENTITY_CREEPER_PRIMED, 3F, 3F); + } + } + } + return false; + } + + protected boolean continuouslyHurtPlayer(Player player) { + if (player.isDead() || isSafeFromAcid(player)) { + burningPlayers.remove(player); + return true; + } else if (burningPlayers.containsKey(player) && burningPlayers.get(player) < System.currentTimeMillis()) { + double protection = addon.getSettings().getAcidDamage() * getDamageReduced(player); + double totalDamage = Math.max(0, addon.getSettings().getAcidDamage() - protection); + AcidEvent event = new AcidEvent(player, totalDamage, protection, addon.getSettings().getAcidEffects()); + addon.getServer().getPluginManager().callEvent(event); + if (!event.isCancelled()) { + event.getPotionEffects().stream().filter(EFFECTS::contains).forEach(t -> player.addPotionEffect(new PotionEffect(t, addon.getSettings().getAcidEffectDuation() * 20, 1))); + // Apply damage if there is any + if (event.getTotalDamage() > 0D) { + player.damage(event.getTotalDamage()); + player.getWorld().playSound(player.getLocation(), Sound.ENTITY_CREEPER_PRIMED, 3F, 3F); + } + } + } + return false; + } + /** * Check if player is safe from rain * @param player - player @@ -213,7 +236,7 @@ public class AcidEffect implements Listener { private boolean isSafeFromAcid(Player player) { // Check for GodMode if (isEssentialsGodMode(player) - // Protect visitors + // Protect visitors || (addon.getPlugin().getIWM().getIvSettings(player.getWorld()).contains(DamageCause.CUSTOM.name()) && !addon.getIslands().userIsOnIsland(player.getWorld(), User.getInstance(player))) ) { From 2cc574d7b0575776050ecae399315275e1618a45 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 10 Oct 2020 19:00:49 -0700 Subject: [PATCH 11/14] Added AISettings test class --- .../world/bentobox/acidisland/AISettings.java | 11 +- .../bentobox/acidisland/AISettingsTest.java | 1815 +++++++++++++++++ 2 files changed, 1822 insertions(+), 4 deletions(-) create mode 100644 src/test/java/world/bentobox/acidisland/AISettingsTest.java diff --git a/src/main/java/world/bentobox/acidisland/AISettings.java b/src/main/java/world/bentobox/acidisland/AISettings.java index 36b40ce..5b6d690 100644 --- a/src/main/java/world/bentobox/acidisland/AISettings.java +++ b/src/main/java/world/bentobox/acidisland/AISettings.java @@ -153,7 +153,7 @@ public class AISettings implements WorldSettings { @ConfigComment("World difficulty setting - PEACEFUL, EASY, NORMAL, HARD") @ConfigComment("Other plugins may override this setting") @ConfigEntry(path = "world.difficulty") - private Difficulty difficulty; + private Difficulty difficulty = Difficulty.NORMAL; @ConfigComment("Spawn limits. These override the limits set in bukkit.yml") @ConfigComment("If set to a negative number, the server defaults will be used") @@ -175,7 +175,6 @@ public class AISettings implements WorldSettings { private int ticksPerMonsterSpawns = -1; @ConfigComment("Radius of island in blocks. (So distance between islands is twice this)") - @ConfigComment("Will be rounded up to the nearest 16 blocks.") @ConfigComment("It is the same for every dimension : Overworld, Nether and End.") @ConfigComment("This value cannot be changed mid-game and the plugin will not start if it is different.") @ConfigEntry(path = "world.distance-between-islands", needsReset = true) @@ -1080,7 +1079,9 @@ public class AISettings implements WorldSettings { /** * @param adminCommand what you want your admin command to be */ - public void setAdminCommand(String adminCommand) { this.adminCommandAliases = adminCommand; } + public void setAdminCommand(String adminCommand) { + this.adminCommandAliases = adminCommand; + } /** * @param allowSetHomeInNether the allowSetHomeInNether to set */ @@ -1194,7 +1195,9 @@ public class AISettings implements WorldSettings { /** * @param islandCommand what you want your island command to be */ - public void setIslandCommand(String islandCommand) { this.playerCommandAliases = islandCommand; } + public void setIslandCommand(String islandCommand) { + this.playerCommandAliases = islandCommand; + } /** * @param islandDistance the islandDistance to set diff --git a/src/test/java/world/bentobox/acidisland/AISettingsTest.java b/src/test/java/world/bentobox/acidisland/AISettingsTest.java new file mode 100644 index 0000000..afe106a --- /dev/null +++ b/src/test/java/world/bentobox/acidisland/AISettingsTest.java @@ -0,0 +1,1815 @@ +package world.bentobox.acidisland; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.Collections; +import java.util.List; + +import org.bukkit.Difficulty; +import org.bukkit.GameMode; +import org.bukkit.block.Biome; +import org.bukkit.entity.EntityType; +import org.bukkit.potion.PotionEffectType; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import world.bentobox.bentobox.lists.Flags; + +/** + * @author tastybento + * + */ +public class AISettingsTest { + + /** + * Class under test + */ + private AISettings s; + + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + s = new AISettings(); + } + + /** + * @throws java.lang.Exception + */ + @After + public void tearDown() throws Exception { + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getAcidDamage()}. + */ + @Test + public void testGetAcidDamage() { + assertEquals(10, s.getAcidDamage()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getAcidDamageAnimal()}. + */ + @Test + public void testGetAcidDamageAnimal() { + assertEquals(1, s.getAcidDamageAnimal()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getAcidDamageDelay()}. + */ + @Test + public void testGetAcidDamageDelay() { + assertEquals(2, s.getAcidDamageDelay()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getAcidDamageMonster()}. + */ + @Test + public void testGetAcidDamageMonster() { + assertEquals(5, s.getAcidDamageMonster()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getAcidDestroyItemTime()}. + */ + @Test + public void testGetAcidDestroyItemTime() { + assertEquals(0, s.getAcidDestroyItemTime()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getAcidEffects()}. + */ + @Test + public void testGetAcidEffects() { + assertTrue(s.getAcidEffects().isEmpty()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getAcidRainDamage()}. + */ + @Test + public void testGetAcidRainDamage() { + assertEquals(1, s.getAcidRainDamage()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getBanLimit()}. + */ + @Test + public void testGetBanLimit() { + assertEquals(-1, s.getBanLimit()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getCustomRanks()}. + */ + @Test + public void testGetCustomRanks() { + assertTrue(s.getCustomRanks().isEmpty()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getDeathsMax()}. + */ + @Test + public void testGetDeathsMax() { + assertEquals(10, s.getDeathsMax()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getDefaultBiome()}. + */ + @Test + public void testGetDefaultBiome() { + assertEquals(Biome.WARM_OCEAN, s.getDefaultBiome()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getDefaultGameMode()}. + */ + @Test + public void testGetDefaultGameMode() { + assertEquals(GameMode.SURVIVAL, s.getDefaultGameMode()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getDefaultIslandFlags()}. + */ + @Test + public void testGetDefaultIslandFlags() { + assertTrue(s.getDefaultIslandFlags().isEmpty()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getDefaultIslandSettings()}. + */ + @Test + public void testGetDefaultIslandSettings() { + assertTrue(s.getDefaultIslandSettings().isEmpty()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getDifficulty()}. + */ + @Test + public void testGetDifficulty() { + assertEquals(Difficulty.NORMAL, s.getDifficulty()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getEndSeaHeight()}. + */ + @Test + public void testGetEndSeaHeight() { + assertEquals(54, s.getEndSeaHeight()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getFriendlyName()}. + */ + @Test + public void testGetFriendlyName() { + assertEquals("AcidIsland", s.getFriendlyName()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getGeoLimitSettings()}. + */ + @Test + public void testGetGeoLimitSettings() { + assertTrue(s.getGeoLimitSettings().isEmpty()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getIslandDistance()}. + */ + @Test + public void testGetIslandDistance() { + assertEquals(192, s.getIslandDistance()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getIslandHeight()}. + */ + @Test + public void testGetIslandHeight() { + assertEquals(50, s.getIslandHeight()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getIslandProtectionRange()}. + */ + @Test + public void testGetIslandProtectionRange() { + assertEquals(100, s.getIslandProtectionRange()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getIslandStartX()}. + */ + @Test + public void testGetIslandStartX() { + assertEquals(0, s.getIslandStartX()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getIslandStartZ()}. + */ + @Test + public void testGetIslandStartZ() { + assertEquals(0, s.getIslandStartZ()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getIslandXOffset()}. + */ + @Test + public void testGetIslandXOffset() { + assertEquals(0, s.getIslandXOffset()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getIslandZOffset()}. + */ + @Test + public void testGetIslandZOffset() { + assertEquals(0, s.getIslandZOffset()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getIvSettings()}. + */ + @Test + public void testGetIvSettings() { + assertTrue(s.getIvSettings().isEmpty()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getMaxHomes()}. + */ + @Test + public void testGetMaxHomes() { + assertEquals(5, s.getMaxHomes()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getMaxIslands()}. + */ + @Test + public void testGetMaxIslands() { + assertEquals(-1, s.getMaxIslands()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getMaxTeamSize()}. + */ + @Test + public void testGetMaxTeamSize() { + assertEquals(4, s.getMaxTeamSize()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getNetherSeaHeight()}. + */ + @Test + public void testGetNetherSeaHeight() { + assertEquals(54, s.getNetherSeaHeight()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getNetherSpawnRadius()}. + */ + @Test + public void testGetNetherSpawnRadius() { + assertEquals(32, s.getNetherSpawnRadius()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getPermissionPrefix()}. + */ + @Test + public void testGetPermissionPrefix() { + assertEquals("acidisland", s.getPermissionPrefix()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getRemoveMobsWhitelist()}. + */ + @Test + public void testGetRemoveMobsWhitelist() { + assertTrue(s.getRemoveMobsWhitelist().isEmpty()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getResetEpoch()}. + */ + @Test + public void testGetResetEpoch() { + assertEquals(0, s.getResetEpoch()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getResetLimit()}. + */ + @Test + public void testGetResetLimit() { + assertEquals(-1, s.getResetLimit()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getSeaHeight()}. + */ + @Test + public void testGetSeaHeight() { + assertEquals(54, s.getSeaHeight()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getHiddenFlags()}. + */ + @Test + public void testGetHiddenFlags() { + assertTrue(s.getHiddenFlags().isEmpty()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getVisitorBannedCommands()}. + */ + @Test + public void testGetVisitorBannedCommands() { + assertTrue(s.getVisitorBannedCommands().isEmpty()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getFallingBannedCommands()}. + */ + @Test + public void testGetFallingBannedCommands() { + assertTrue(s.getFallingBannedCommands().isEmpty()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getWorldFlags()}. + */ + @Test + public void testGetWorldFlags() { + assertTrue(s.getWorldFlags().isEmpty()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getWorldName()}. + */ + @Test + public void testGetWorldName() { + assertEquals("acidisland_world", s.getWorldName()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isAcidDamageChickens()}. + */ + @Test + public void testIsAcidDamageChickens() { + assertFalse(s.isAcidDamageChickens()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isAcidDamageOp()}. + */ + @Test + public void testIsAcidDamageOp() { + assertFalse(s.isAcidDamageOp()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isAllowSetHomeInNether()}. + */ + @Test + public void testIsAllowSetHomeInNether() { + assertTrue(s.isAllowSetHomeInNether()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isAllowSetHomeInTheEnd()}. + */ + @Test + public void testIsAllowSetHomeInTheEnd() { + assertTrue(s.isAllowSetHomeInTheEnd()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isDeathsCounted()}. + */ + @Test + public void testIsDeathsCounted() { + assertTrue(s.isDeathsCounted()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isDragonSpawn()}. + */ + @Test + public void testIsDragonSpawn() { + assertFalse(s.isDragonSpawn()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isEndGenerate()}. + */ + @Test + public void testIsEndGenerate() { + assertTrue(s.isEndGenerate()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isEndIslands()}. + */ + @Test + public void testIsEndIslands() { + assertTrue(s.isEndIslands()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isFullArmorProtection()}. + */ + @Test + public void testIsFullArmorProtection() { + assertFalse(s.isFullArmorProtection()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isHelmetProtection()}. + */ + @Test + public void testIsHelmetProtection() { + assertFalse(s.isHelmetProtection()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isKickedKeepInventory()}. + */ + @Test + public void testIsKickedKeepInventory() { + assertFalse(s.isKickedKeepInventory()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isCreateIslandOnFirstLoginEnabled()}. + */ + @Test + public void testIsCreateIslandOnFirstLoginEnabled() { + assertFalse(s.isCreateIslandOnFirstLoginEnabled()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getCreateIslandOnFirstLoginDelay()}. + */ + @Test + public void testGetCreateIslandOnFirstLoginDelay() { + assertEquals(5, s.getCreateIslandOnFirstLoginDelay()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isCreateIslandOnFirstLoginAbortOnLogout()}. + */ + @Test + public void testIsCreateIslandOnFirstLoginAbortOnLogout() { + assertTrue(s.isCreateIslandOnFirstLoginAbortOnLogout()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isLeaversLoseReset()}. + */ + @Test + public void testIsLeaversLoseReset() { + assertFalse(s.isLeaversLoseReset()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isNetherGenerate()}. + */ + @Test + public void testIsNetherGenerate() { + assertTrue(s.isNetherGenerate()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isNetherIslands()}. + */ + @Test + public void testIsNetherIslands() { + assertTrue(s.isNetherIslands()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isNetherRoof()}. + */ + @Test + public void testIsNetherRoof() { + assertTrue(s.isNetherRoof()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isOnJoinResetEnderChest()}. + */ + @Test + public void testIsOnJoinResetEnderChest() { + assertFalse(s.isOnJoinResetEnderChest()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isOnJoinResetInventory()}. + */ + @Test + public void testIsOnJoinResetInventory() { + assertFalse(s.isOnJoinResetInventory()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isOnJoinResetMoney()}. + */ + @Test + public void testIsOnJoinResetMoney() { + assertFalse(s.isOnJoinResetMoney()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isOnLeaveResetEnderChest()}. + */ + @Test + public void testIsOnLeaveResetEnderChest() { + assertFalse(s.isOnLeaveResetEnderChest()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isOnLeaveResetInventory()}. + */ + @Test + public void testIsOnLeaveResetInventory() { + assertFalse(s.isOnLeaveResetInventory()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isOnLeaveResetMoney()}. + */ + @Test + public void testIsOnLeaveResetMoney() { + assertFalse(s.isOnLeaveResetMoney()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isRequireConfirmationToSetHomeInNether()}. + */ + @Test + public void testIsRequireConfirmationToSetHomeInNether() { + assertTrue(s.isRequireConfirmationToSetHomeInNether()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isRequireConfirmationToSetHomeInTheEnd()}. + */ + @Test + public void testIsRequireConfirmationToSetHomeInTheEnd() { + assertTrue(s.isRequireConfirmationToSetHomeInTheEnd()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isTeamJoinDeathReset()}. + */ + @Test + public void testIsTeamJoinDeathReset() { + assertTrue(s.isTeamJoinDeathReset()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isUseOwnGenerator()}. + */ + @Test + public void testIsUseOwnGenerator() { + assertFalse(s.isUseOwnGenerator()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isWaterUnsafe()}. + */ + @Test + public void testIsWaterUnsafe() { + assertTrue(s.isWaterUnsafe()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setAcidDamage(int)}. + */ + @Test + public void testSetAcidDamage() { + s.setAcidDamage(99); + assertEquals(99, s.getAcidDamage()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setAcidDamageAnimal(int)}. + */ + @Test + public void testSetAcidDamageAnimal() { + s.setAcidDamageAnimal(99); + assertEquals(99, s.getAcidDamageAnimal()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setAcidDamageChickens(boolean)}. + */ + @Test + public void testSetAcidDamageChickens() { + s.setAcidDamageChickens(true); + assertTrue(s.isAcidDamageChickens()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setAcidDamageDelay(long)}. + */ + @Test + public void testSetAcidDamageDelay() { + s.setAcidDamageDelay(99); + assertEquals(99, s.getAcidDamageDelay()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setAcidDamageMonster(int)}. + */ + @Test + public void testSetAcidDamageMonster() { + s.setAcidDamageMonster(99); + assertEquals(99, s.getAcidDamageMonster()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setAcidDamageOp(boolean)}. + */ + @Test + public void testSetAcidDamageOp() { + s.setAcidDamageOp(true); + assertTrue(s.isAcidDamageOp()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setAcidDestroyItemTime(long)}. + */ + @Test + public void testSetAcidDestroyItemTime() { + s.setAcidDestroyItemTime(99); + assertEquals(99, s.getAcidDestroyItemTime()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setAcidEffects(java.util.List)}. + */ + @Test + public void testSetAcidEffects() { + List list = Collections.singletonList(PotionEffectType.ABSORPTION); + s.setAcidEffects(list); + assertEquals(list, s.getAcidEffects()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setAcidRainDamage(int)}. + */ + @Test + public void testSetAcidRainDamage() { + s.setAcidRainDamage(99); + assertEquals(99, s.getAcidRainDamage()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setAdminCommand(java.lang.String)}. + */ + @Test + public void testSetAdminCommand() { + s.setAdminCommand("admin"); + assertEquals("admin", s.getAdminCommandAliases()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setAllowSetHomeInNether(boolean)}. + */ + @Test + public void testSetAllowSetHomeInNether() { + s.setAllowSetHomeInNether(false); + assertFalse(s.isAllowSetHomeInNether()); + s.setAllowSetHomeInNether(true); + assertTrue(s.isAllowSetHomeInNether()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setAllowSetHomeInTheEnd(boolean)}. + */ + @Test + public void testSetAllowSetHomeInTheEnd() { + s.setAllowSetHomeInTheEnd(false); + assertFalse(s.isAllowSetHomeInTheEnd()); + s.setAllowSetHomeInTheEnd(true); + assertTrue(s.isAllowSetHomeInTheEnd()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setBanLimit(int)}. + */ + @Test + public void testSetBanLimit() { + s.setBanLimit(99); + assertEquals(99, s.getBanLimit()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setCustomRanks(java.util.Map)}. + */ + @Test + public void testSetCustomRanks() { + s.setCustomRanks(Collections.singletonMap("string", 10)); + assertEquals(10, (int)s.getCustomRanks().get("string")); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setDeathsCounted(boolean)}. + */ + @Test + public void testSetDeathsCounted() { + s.setDeathsCounted(false); + assertFalse(s.isDeathsCounted()); + s.setDeathsCounted(true); + assertTrue(s.isDeathsCounted()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setDeathsMax(int)}. + */ + @Test + public void testSetDeathsMax() { + s.setDeathsMax(99); + assertEquals(99, s.getDeathsMax()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setDefaultBiome(org.bukkit.block.Biome)}. + */ + @Test + public void testSetDefaultBiome() { + s.setDefaultBiome(Biome.BADLANDS); + assertEquals(Biome.BADLANDS, s.getDefaultBiome()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setDefaultGameMode(org.bukkit.GameMode)}. + */ + @Test + public void testSetDefaultGameMode() { + s.setDefaultGameMode(GameMode.SPECTATOR); + assertEquals(GameMode.SPECTATOR, s.getDefaultGameMode()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setDefaultIslandFlags(java.util.Map)}. + */ + @Test + public void testSetDefaultIslandFlags() { + s.setDefaultIslandFlags(Collections.singletonMap(Flags.ANIMAL_NATURAL_SPAWN, 10)); + assertEquals(10, (int)s.getDefaultIslandFlags().get(Flags.ANIMAL_NATURAL_SPAWN)); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setDefaultIslandSettings(java.util.Map)}. + */ + @Test + public void testSetDefaultIslandSettings() { + s.setDefaultIslandSettings(Collections.singletonMap(Flags.ANIMAL_NATURAL_SPAWN, 10)); + assertEquals(10, (int)s.getDefaultIslandSettings().get(Flags.ANIMAL_NATURAL_SPAWN)); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setDifficulty(org.bukkit.Difficulty)}. + */ + @Test + public void testSetDifficulty() { + s.setDifficulty(Difficulty.PEACEFUL); + assertEquals(Difficulty.PEACEFUL, s.getDifficulty()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setDragonSpawn(boolean)}. + */ + @Test + public void testSetDragonSpawn() { + s.setDragonSpawn(false); + assertFalse(s.isDragonSpawn()); + s.setDragonSpawn(true); + assertTrue(s.isDragonSpawn()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setEndGenerate(boolean)}. + */ + @Test + public void testSetEndGenerate() { + s.setEndGenerate(false); + assertFalse(s.isEndGenerate()); + s.setEndGenerate(true); + assertTrue(s.isEndGenerate()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setEndIslands(boolean)}. + */ + @Test + public void testSetEndIslands() { + s.setEndIslands(false); + assertFalse(s.isEndIslands()); + s.setEndIslands(true); + assertTrue(s.isEndIslands()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setFriendlyName(java.lang.String)}. + */ + @Test + public void testSetFriendlyName() { + s.setFriendlyName("hshshs"); + assertEquals("hshshs", s.getFriendlyName()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setFullArmorProtection(boolean)}. + */ + @Test + public void testSetFullArmorProtection() { + s.setFullArmorProtection(false); + assertFalse(s.isFullArmorProtection()); + s.setFullArmorProtection(true); + assertTrue(s.isFullArmorProtection()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setGeoLimitSettings(java.util.List)}. + */ + @Test + public void testSetGeoLimitSettings() { + s.setGeoLimitSettings(Collections.singletonList("ghghhg")); + assertEquals("ghghhg", s.getGeoLimitSettings().get(0)); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setHelmetProtection(boolean)}. + */ + @Test + public void testSetHelmetProtection() { + s.setHelmetProtection(false); + assertFalse(s.isHelmetProtection()); + s.setHelmetProtection(true); + assertTrue(s.isHelmetProtection()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setIslandCommand(java.lang.String)}. + */ + @Test + public void testSetIslandCommand() { + s.setIslandCommand("command"); + assertEquals("command", s.getPlayerCommandAliases()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setIslandDistance(int)}. + */ + @Test + public void testSetIslandDistance() { + s.setIslandDistance(99); + assertEquals(99, s.getIslandDistance()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setIslandHeight(int)}. + */ + @Test + public void testSetIslandHeight() { + s.setIslandHeight(99); + assertEquals(99, s.getIslandHeight()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setIslandProtectionRange(int)}. + */ + @Test + public void testSetIslandProtectionRange() { + s.setIslandProtectionRange(99); + assertEquals(99, s.getIslandProtectionRange()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setIslandStartX(int)}. + */ + @Test + public void testSetIslandStartX() { + s.setIslandStartX(99); + assertEquals(99, s.getIslandStartX()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setIslandStartZ(int)}. + */ + @Test + public void testSetIslandStartZ() { + s.setIslandStartZ(99); + assertEquals(99, s.getIslandStartZ()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setIslandXOffset(int)}. + */ + @Test + public void testSetIslandXOffset() { + s.setIslandXOffset(99); + assertEquals(99, s.getIslandXOffset()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setIslandZOffset(int)}. + */ + @Test + public void testSetIslandZOffset() { + s.setIslandZOffset(99); + assertEquals(99, s.getIslandZOffset()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setIvSettings(java.util.List)}. + */ + @Test + public void testSetIvSettings() { + s.setIvSettings(Collections.singletonList("ffff")); + assertEquals("ffff", s.getIvSettings().get(0)); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setKickedKeepInventory(boolean)}. + */ + @Test + public void testSetKickedKeepInventory() { + s.setKickedKeepInventory(false); + assertFalse(s.isKickedKeepInventory()); + s.setKickedKeepInventory(true); + assertTrue(s.isKickedKeepInventory()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setLeaversLoseReset(boolean)}. + */ + @Test + public void testSetLeaversLoseReset() { + s.setLeaversLoseReset(false); + assertFalse(s.isLeaversLoseReset()); + s.setLeaversLoseReset(true); + assertTrue(s.isLeaversLoseReset()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setMaxHomes(int)}. + */ + @Test + public void testSetMaxHomes() { + s.setMaxHomes(99); + assertEquals(99, s.getMaxHomes()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setMaxIslands(int)}. + */ + @Test + public void testSetMaxIslands() { + s.setMaxIslands(99); + assertEquals(99, s.getMaxIslands()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setMaxTeamSize(int)}. + */ + @Test + public void testSetMaxTeamSize() { + s.setMaxTeamSize(99); + assertEquals(99, s.getMaxTeamSize()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setNetherGenerate(boolean)}. + */ + @Test + public void testSetNetherGenerate() { + s.setNetherGenerate(false); + assertFalse(s.isNetherGenerate()); + s.setNetherGenerate(true); + assertTrue(s.isNetherGenerate()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setNetherIslands(boolean)}. + */ + @Test + public void testSetNetherIslands() { + s.setNetherIslands(false); + assertFalse(s.isNetherIslands()); + s.setNetherIslands(true); + assertTrue(s.isNetherIslands()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setNetherRoof(boolean)}. + */ + @Test + public void testSetNetherRoof() { + s.setNetherRoof(false); + assertFalse(s.isNetherRoof()); + s.setNetherRoof(true); + assertTrue(s.isNetherRoof()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setNetherSpawnRadius(int)}. + */ + @Test + public void testSetNetherSpawnRadius() { + s.setNetherSpawnRadius(99); + assertEquals(99,s.getNetherSpawnRadius()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setOnJoinResetEnderChest(boolean)}. + */ + @Test + public void testSetOnJoinResetEnderChest() { + s.setOnJoinResetEnderChest(false); + assertFalse(s.isOnJoinResetEnderChest()); + s.setOnJoinResetEnderChest(true); + assertTrue(s.isOnJoinResetEnderChest()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setOnJoinResetInventory(boolean)}. + */ + @Test + public void testSetOnJoinResetInventory() { + s.setOnJoinResetInventory(false); + assertFalse(s.isOnJoinResetInventory()); + s.setOnJoinResetInventory(true); + assertTrue(s.isOnJoinResetInventory()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setOnJoinResetMoney(boolean)}. + */ + @Test + public void testSetOnJoinResetMoney() { + s.setOnJoinResetMoney(false); + assertFalse(s.isOnJoinResetMoney()); + s.setOnJoinResetMoney(true); + assertTrue(s.isOnJoinResetMoney()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setOnLeaveResetEnderChest(boolean)}. + */ + @Test + public void testSetOnLeaveResetEnderChest() { + s.setOnLeaveResetEnderChest(false); + assertFalse(s.isOnLeaveResetEnderChest()); + s.setOnLeaveResetEnderChest(true); + assertTrue(s.isOnLeaveResetEnderChest()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setOnLeaveResetInventory(boolean)}. + */ + @Test + public void testSetOnLeaveResetInventory() { + s.setOnLeaveResetInventory(false); + assertFalse(s.isOnLeaveResetInventory()); + s.setOnLeaveResetInventory(true); + assertTrue(s.isOnLeaveResetInventory()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setOnLeaveResetMoney(boolean)}. + */ + @Test + public void testSetOnLeaveResetMoney() { + s.setOnLeaveResetMoney(false); + assertFalse(s.isOnLeaveResetMoney()); + s.setOnLeaveResetMoney(true); + assertTrue(s.isOnLeaveResetMoney()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setRemoveMobsWhitelist(java.util.Set)}. + */ + @Test + public void testSetRemoveMobsWhitelist() { + s.setRemoveMobsWhitelist(Collections.singleton(EntityType.GHAST)); + assertTrue(s.getRemoveMobsWhitelist().contains(EntityType.GHAST)); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setRequireConfirmationToSetHomeInNether(boolean)}. + */ + @Test + public void testSetRequireConfirmationToSetHomeInNether() { + s.setRequireConfirmationToSetHomeInNether(false); + assertFalse(s.isRequireConfirmationToSetHomeInNether()); + s.setRequireConfirmationToSetHomeInNether(true); + assertTrue(s.isRequireConfirmationToSetHomeInNether()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setRequireConfirmationToSetHomeInTheEnd(boolean)}. + */ + @Test + public void testSetRequireConfirmationToSetHomeInTheEnd() { + s.setRequireConfirmationToSetHomeInTheEnd(false); + assertFalse(s.isRequireConfirmationToSetHomeInTheEnd()); + s.setRequireConfirmationToSetHomeInTheEnd(true); + assertTrue(s.isRequireConfirmationToSetHomeInTheEnd()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setResetEpoch(long)}. + */ + @Test + public void testSetResetEpoch() { + s.setResetEpoch(3456L); + assertEquals(3456L, s.getResetEpoch()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setResetLimit(int)}. + */ + @Test + public void testSetResetLimit() { + s.setResetLimit(99); + assertEquals(99, s.getResetLimit()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setSeaHeight(int)}. + */ + @Test + public void testSetSeaHeight() { + s.setSeaHeight(99); + assertEquals(99, s.getSeaHeight()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setNetherSeaHeight(int)}. + */ + @Test + public void testSetNetherSeaHeight() { + s.setNetherSeaHeight(99); + assertEquals(99, s.getNetherSeaHeight()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setEndSeaHeight(int)}. + */ + @Test + public void testSetEndSeaHeight() { + s.setEndSeaHeight(99); + assertEquals(99, s.getEndSeaHeight()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setTeamJoinDeathReset(boolean)}. + */ + @Test + public void testSetTeamJoinDeathReset() { + s.setTeamJoinDeathReset(false); + assertFalse(s.isTeamJoinDeathReset()); + s.setTeamJoinDeathReset(true); + assertTrue(s.isTeamJoinDeathReset()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setUseOwnGenerator(boolean)}. + */ + @Test + public void testSetUseOwnGenerator() { + s.setUseOwnGenerator(false); + assertFalse(s.isUseOwnGenerator()); + s.setUseOwnGenerator(true); + assertTrue(s.isUseOwnGenerator()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setHiddenFlags(java.util.List)}. + */ + @Test + public void testSetHiddenFlags() { + s.setHiddenFlags(Collections.singletonList("flag")); + assertEquals("flag", s.getHiddenFlags().get(0)); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setVisitorBannedCommands(java.util.List)}. + */ + @Test + public void testSetVisitorBannedCommands() { + s.setVisitorBannedCommands(Collections.singletonList("flag")); + assertEquals("flag", s.getVisitorBannedCommands().get(0)); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setFallingBannedCommands(java.util.List)}. + */ + @Test + public void testSetFallingBannedCommands() { + s.setFallingBannedCommands(Collections.singletonList("flag")); + assertEquals("flag", s.getFallingBannedCommands().get(0)); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setWorldFlags(java.util.Map)}. + */ + @Test + public void testSetWorldFlags() { + s.setWorldFlags(Collections.singletonMap("flag", true)); + assertTrue(s.getWorldFlags().get("flag")); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setWorldName(java.lang.String)}. + */ + @Test + public void testSetWorldName() { + s.setWorldName("ugga"); + assertEquals("ugga", s.getWorldName()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isAcidDamageSnow()}. + */ + @Test + public void testIsAcidDamageSnow() { + assertFalse(s.isAcidDamageSnow()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setAcidDamageSnow(boolean)}. + */ + @Test + public void testSetAcidDamageSnow() { + s.setAcidDamageSnow(false); + assertFalse(s.isAcidDamageSnow()); + s.setAcidDamageSnow(true); + assertTrue(s.isAcidDamageSnow()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isDeathsResetOnNewIsland()}. + */ + @Test + public void testIsDeathsResetOnNewIsland() { + assertTrue(s.isDeathsResetOnNewIsland()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setDeathsResetOnNewIsland(boolean)}. + */ + @Test + public void testSetDeathsResetOnNewIsland() { + s.setDeathsResetOnNewIsland(false); + assertFalse(s.isDeathsResetOnNewIsland()); + s.setDeathsResetOnNewIsland(true); + assertTrue(s.isDeathsResetOnNewIsland()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getOnJoinCommands()}. + */ + @Test + public void testGetOnJoinCommands() { + assertTrue(s.getOnJoinCommands().isEmpty()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setOnJoinCommands(java.util.List)}. + */ + @Test + public void testSetOnJoinCommands() { + s.setOnJoinCommands(Collections.singletonList("command")); + assertEquals("command", s.getOnJoinCommands().get(0)); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getOnLeaveCommands()}. + */ + @Test + public void testGetOnLeaveCommands() { + assertTrue(s.getOnLeaveCommands().isEmpty()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setOnLeaveCommands(java.util.List)}. + */ + @Test + public void testSetOnLeaveCommands() { + s.setOnLeaveCommands(Collections.singletonList("command")); + assertEquals("command", s.getOnLeaveCommands().get(0)); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isOnJoinResetHealth()}. + */ + @Test + public void testIsOnJoinResetHealth() { + assertTrue(s.isOnJoinResetHealth()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setOnJoinResetHealth(boolean)}. + */ + @Test + public void testSetOnJoinResetHealth() { + s.setOnJoinResetHealth(false); + assertFalse(s.isOnJoinResetHealth()); + s.setOnJoinResetHealth(true); + assertTrue(s.isOnJoinResetHealth()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isOnJoinResetHunger()}. + */ + @Test + public void testIsOnJoinResetHunger() { + assertTrue(s.isOnJoinResetHunger()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setOnJoinResetHunger(boolean)}. + */ + @Test + public void testSetOnJoinResetHunger() { + s.setOnJoinResetHunger(false); + assertFalse(s.isOnJoinResetHunger()); + s.setOnJoinResetHunger(true); + assertTrue(s.isOnJoinResetHunger()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isOnJoinResetXP()}. + */ + @Test + public void testIsOnJoinResetXP() { + assertFalse(s.isOnJoinResetXP()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setOnJoinResetXP(boolean)}. + */ + @Test + public void testSetOnJoinResetXP() { + s.setOnJoinResetXP(false); + assertFalse(s.isOnJoinResetXP()); + s.setOnJoinResetXP(true); + assertTrue(s.isOnJoinResetXP()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isOnLeaveResetHealth()}. + */ + @Test + public void testIsOnLeaveResetHealth() { + assertFalse(s.isOnLeaveResetHealth()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setOnLeaveResetHealth(boolean)}. + */ + @Test + public void testSetOnLeaveResetHealth() { + s.setOnLeaveResetHealth(false); + assertFalse(s.isOnLeaveResetHealth()); + s.setOnLeaveResetHealth(true); + assertTrue(s.isOnLeaveResetHealth()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isOnLeaveResetHunger()}. + */ + @Test + public void testIsOnLeaveResetHunger() { + assertFalse(s.isOnLeaveResetHunger()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setOnLeaveResetHunger(boolean)}. + */ + @Test + public void testSetOnLeaveResetHunger() { + s.setOnLeaveResetHunger(false); + assertFalse(s.isOnLeaveResetHunger()); + s.setOnLeaveResetHunger(true); + assertTrue(s.isOnLeaveResetHunger()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isOnLeaveResetXP()}. + */ + @Test + public void testIsOnLeaveResetXP() { + assertFalse(s.isOnLeaveResetXP()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setOnLeaveResetXP(boolean)}. + */ + @Test + public void testSetOnLeaveResetXP() { + + s.setOnLeaveResetXP(false); + assertFalse(s.isOnLeaveResetXP()); + s.setOnLeaveResetXP(true); + assertTrue(s.isOnLeaveResetXP()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setCreateIslandOnFirstLoginEnabled(boolean)}. + */ + @Test + public void testSetCreateIslandOnFirstLoginEnabled() { + s.setCreateIslandOnFirstLoginEnabled(false); + assertFalse(s.isCreateIslandOnFirstLoginEnabled()); + s.setCreateIslandOnFirstLoginEnabled(true); + assertTrue(s.isCreateIslandOnFirstLoginEnabled()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setCreateIslandOnFirstLoginDelay(int)}. + */ + @Test + public void testSetCreateIslandOnFirstLoginDelay() { + s.setCreateIslandOnFirstLoginDelay(40); + assertEquals(40, s.getCreateIslandOnFirstLoginDelay()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setCreateIslandOnFirstLoginAbortOnLogout(boolean)}. + */ + @Test + public void testSetCreateIslandOnFirstLoginAbortOnLogout() { + s.setCreateIslandOnFirstLoginAbortOnLogout(false); + assertFalse(s.isCreateIslandOnFirstLoginAbortOnLogout()); + s.setCreateIslandOnFirstLoginAbortOnLogout(true); + assertTrue(s.isCreateIslandOnFirstLoginAbortOnLogout()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#isPasteMissingIslands()}. + */ + @Test + public void testIsPasteMissingIslands() { + assertFalse(s.isPasteMissingIslands()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setPasteMissingIslands(boolean)}. + */ + @Test + public void testSetPasteMissingIslands() { + s.setPasteMissingIslands(false); + assertFalse(s.isPasteMissingIslands()); + s.setPasteMissingIslands(true); + assertTrue(s.isPasteMissingIslands()); + + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getAcidRainEffects()}. + */ + @Test + public void testGetAcidRainEffects() { + assertTrue(s.getAcidRainEffects().isEmpty()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setAcidRainEffects(java.util.List)}. + */ + @Test + public void testSetAcidRainEffects() { + s.setAcidRainEffects(Collections.singletonList(PotionEffectType.BAD_OMEN)); + assertEquals(PotionEffectType.BAD_OMEN, s.getAcidRainEffects().get(0)); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getRainEffectDuation()}. + */ + @Test + public void testGetRainEffectDuation() { + assertEquals(10, s.getRainEffectDuation()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setRainEffectDuation(int)}. + */ + @Test + public void testSetRainEffectDuation() { + s.setRainEffectDuation(99); + assertEquals(99, s.getRainEffectDuation()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getAcidEffectDuation()}. + */ + @Test + public void testGetAcidEffectDuation() { + assertEquals(30, s.getAcidEffectDuation()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setAcidEffectDuation(int)}. + */ + @Test + public void testSetAcidEffectDuation() { + s.setAcidEffectDuation(99); + assertEquals(99, s.getAcidEffectDuation()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getSpawnLimitMonsters()}. + */ + @Test + public void testGetSpawnLimitMonsters() { + assertEquals(-1, s.getSpawnLimitMonsters()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setSpawnLimitMonsters(int)}. + */ + @Test + public void testSetSpawnLimitMonsters() { + s.setSpawnLimitMonsters(99); + assertEquals(99, s.getSpawnLimitMonsters()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getSpawnLimitAnimals()}. + */ + @Test + public void testGetSpawnLimitAnimals() { + assertEquals(-1, s.getSpawnLimitAnimals()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setSpawnLimitAnimals(int)}. + */ + @Test + public void testSetSpawnLimitAnimals() { + s.setSpawnLimitAnimals(99); + assertEquals(99, s.getSpawnLimitAnimals()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getSpawnLimitWaterAnimals()}. + */ + @Test + public void testGetSpawnLimitWaterAnimals() { + assertEquals(-1, s.getSpawnLimitWaterAnimals()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setSpawnLimitWaterAnimals(int)}. + */ + @Test + public void testSetSpawnLimitWaterAnimals() { + s.setSpawnLimitWaterAnimals(99); + assertEquals(99, s.getSpawnLimitWaterAnimals()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getSpawnLimitAmbient()}. + */ + @Test + public void testGetSpawnLimitAmbient() { + assertEquals(-1, s.getSpawnLimitAmbient()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setSpawnLimitAmbient(int)}. + */ + @Test + public void testSetSpawnLimitAmbient() { + s.setSpawnLimitAmbient(99); + assertEquals(99, s.getSpawnLimitAmbient()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getTicksPerAnimalSpawns()}. + */ + @Test + public void testGetTicksPerAnimalSpawns() { + assertEquals(-1, s.getTicksPerAnimalSpawns()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setTicksPerAnimalSpawns(int)}. + */ + @Test + public void testSetTicksPerAnimalSpawns() { + s.setTicksPerAnimalSpawns(99); + assertEquals(99, s.getTicksPerAnimalSpawns()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getTicksPerMonsterSpawns()}. + */ + @Test + public void testGetTicksPerMonsterSpawns() { + assertEquals(-1, s.getTicksPerMonsterSpawns()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setTicksPerMonsterSpawns(int)}. + */ + @Test + public void testSetTicksPerMonsterSpawns() { + s.setTicksPerMonsterSpawns(99); + assertEquals(99, s.getTicksPerMonsterSpawns()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getMaxCoopSize()}. + */ + @Test + public void testGetMaxCoopSize() { + assertEquals(4, s.getMaxCoopSize()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setMaxCoopSize(int)}. + */ + @Test + public void testSetMaxCoopSize() { + s.setMaxCoopSize(99); + assertEquals(99, s.getMaxCoopSize()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getMaxTrustSize()}. + */ + @Test + public void testGetMaxTrustSize() { + assertEquals(4, s.getMaxTrustSize()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setMaxTrustSize(int)}. + */ + @Test + public void testSetMaxTrustSize() { + s.setMaxTrustSize(99); + assertEquals(99, s.getMaxTrustSize()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getPlayerCommandAliases()}. + */ + @Test + public void testGetPlayerCommandAliases() { + assertEquals("ai", s.getPlayerCommandAliases()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setPlayerCommandAliases(java.lang.String)}. + */ + @Test + public void testSetPlayerCommandAliases() { + s.setPlayerCommandAliases("adm"); + assertEquals("adm", s.getPlayerCommandAliases()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getAdminCommandAliases()}. + */ + @Test + public void testGetAdminCommandAliases() { + assertEquals("acid", s.getAdminCommandAliases()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setAdminCommandAliases(java.lang.String)}. + */ + @Test + public void testSetAdminCommandAliases() { + s.setAdminCommand("adm"); + assertEquals("adm", s.getAdminCommandAliases()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getDefaultNewPlayerAction()}. + */ + @Test + public void testGetDefaultNewPlayerAction() { + assertEquals("create", s.getDefaultNewPlayerAction()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setDefaultNewPlayerAction(java.lang.String)}. + */ + @Test + public void testSetDefaultNewPlayerAction() { + s.setDefaultNewPlayerAction("cr"); + assertEquals("cr", s.getDefaultNewPlayerAction()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getDefaultPlayerAction()}. + */ + @Test + public void testGetDefaultPlayerAction() { + assertEquals("go", s.getDefaultPlayerAction()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setDefaultPlayerAction(java.lang.String)}. + */ + @Test + public void testSetDefaultPlayerAction() { + s.setDefaultPlayerAction("go2"); + assertEquals("go2", s.getDefaultPlayerAction()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getDefaultNetherBiome()}. + */ + @Test + public void testGetDefaultNetherBiome() { + assertEquals(Biome.NETHER_WASTES, s.getDefaultNetherBiome()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setDefaultNetherBiome(org.bukkit.block.Biome)}. + */ + @Test + public void testSetDefaultNetherBiome() { + s.setDefaultNetherBiome(Biome.END_BARRENS); + assertEquals(Biome.END_BARRENS, s.getDefaultNetherBiome()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#getDefaultEndBiome()}. + */ + @Test + public void testGetDefaultEndBiome() { + assertEquals(Biome.THE_END, s.getDefaultEndBiome()); + } + + /** + * Test method for {@link world.bentobox.acidisland.AISettings#setDefaultEndBiome(org.bukkit.block.Biome)}. + */ + @Test + public void testSetDefaultEndBiome() { + s.setDefaultEndBiome(Biome.END_BARRENS); + assertEquals(Biome.END_BARRENS, s.getDefaultEndBiome()); + } + +} From b01c1551a6e4b10815eb2519c2c11ce0b2cdfff2 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 10 Oct 2020 19:00:59 -0700 Subject: [PATCH 12/14] Removed code smell --- .../world/bentobox/acidisland/events/AbstractAcidEvent.java | 2 +- .../world/bentobox/acidisland/events/AcidEventTest.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/world/bentobox/acidisland/events/AbstractAcidEvent.java b/src/main/java/world/bentobox/acidisland/events/AbstractAcidEvent.java index 93e47e0..130414c 100644 --- a/src/main/java/world/bentobox/acidisland/events/AbstractAcidEvent.java +++ b/src/main/java/world/bentobox/acidisland/events/AbstractAcidEvent.java @@ -32,7 +32,7 @@ public abstract class AbstractAcidEvent extends Event implements Cancellable { * @param rainDamage * @param protection */ - public AbstractAcidEvent(Player player, double protection, List potionEffects) { + protected AbstractAcidEvent(Player player, double protection, List potionEffects) { this.player = player; this.protection = protection; this.potionEffects = potionEffects; diff --git a/src/test/java/world/bentobox/acidisland/events/AcidEventTest.java b/src/test/java/world/bentobox/acidisland/events/AcidEventTest.java index d049cfa..c3d2c6b 100644 --- a/src/test/java/world/bentobox/acidisland/events/AcidEventTest.java +++ b/src/test/java/world/bentobox/acidisland/events/AcidEventTest.java @@ -48,18 +48,18 @@ public class AcidEventTest { @Test public void testGetTotalDamage() { - assertTrue(e.getTotalDamage() == 10D); + assertEquals(10D, e.getTotalDamage(), 0D); } @Test public void testGetProtection() { - assertTrue(e.getProtection() == 5D); + assertEquals(5D, e.getProtection(), 0D); } @Test public void testSetTotalDamage() { e.setTotalDamage(50); - assertTrue(e.getTotalDamage() == 50D); + assertEquals(50D, e.getTotalDamage(), 0D); } @Test From bba53387a450d50c6ba5d39ac3545fdf51f74469 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 10 Oct 2020 19:27:30 -0700 Subject: [PATCH 13/14] Added AcidIsland test class --- .../world/bentobox/acidisland/AcidIsland.java | 14 +- .../bentobox/acidisland/AISettingsTest.java | 2 +- .../bentobox/acidisland/AcidIslandTest.java | 269 ++++++++++++++++++ 3 files changed, 275 insertions(+), 10 deletions(-) create mode 100644 src/test/java/world/bentobox/acidisland/AcidIslandTest.java diff --git a/src/main/java/world/bentobox/acidisland/AcidIsland.java b/src/main/java/world/bentobox/acidisland/AcidIsland.java index e00db0e..ccedb2c 100644 --- a/src/main/java/world/bentobox/acidisland/AcidIsland.java +++ b/src/main/java/world/bentobox/acidisland/AcidIsland.java @@ -1,5 +1,6 @@ package world.bentobox.acidisland; +import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.World.Environment; import org.bukkit.WorldCreator; @@ -100,33 +101,28 @@ public class AcidIsland extends GameModeAddon { return settings; } - @Override - public void log(String string) { - getPlugin().log(string); - } - /* (non-Javadoc) * @see world.bentobox.bentobox.api.addons.GameModeAddon#createWorlds() */ @Override public void createWorlds() { String worldName = settings.getWorldName().toLowerCase(); - if (getServer().getWorld(worldName) == null) { - getLogger().info("Creating AcidIsland..."); + if (Bukkit.getWorld(worldName) == null) { + log("Creating AcidIsland..."); } // Create the world if it does not exist chunkGenerator = new ChunkGeneratorWorld(this); islandWorld = getWorld(worldName, World.Environment.NORMAL, chunkGenerator); // Make the nether if it does not exist if (settings.isNetherGenerate()) { - if (getServer().getWorld(worldName + NETHER) == null) { + if (Bukkit.getWorld(worldName + NETHER) == null) { log("Creating AcidIsland's Nether..."); } netherWorld = settings.isNetherIslands() ? getWorld(worldName, World.Environment.NETHER, chunkGenerator) : getWorld(worldName, World.Environment.NETHER, null); } // Make the end if it does not exist if (settings.isEndGenerate()) { - if (getServer().getWorld(worldName + THE_END) == null) { + if (Bukkit.getWorld(worldName + THE_END) == null) { log("Creating AcidIsland's End World..."); } endWorld = settings.isEndIslands() ? getWorld(worldName, World.Environment.THE_END, chunkGenerator) : getWorld(worldName, World.Environment.THE_END, null); diff --git a/src/test/java/world/bentobox/acidisland/AISettingsTest.java b/src/test/java/world/bentobox/acidisland/AISettingsTest.java index afe106a..0278808 100644 --- a/src/test/java/world/bentobox/acidisland/AISettingsTest.java +++ b/src/test/java/world/bentobox/acidisland/AISettingsTest.java @@ -1740,7 +1740,7 @@ public class AISettingsTest { */ @Test public void testSetAdminCommandAliases() { - s.setAdminCommand("adm"); + s.setAdminCommandAliases("adm"); assertEquals("adm", s.getAdminCommandAliases()); } diff --git a/src/test/java/world/bentobox/acidisland/AcidIslandTest.java b/src/test/java/world/bentobox/acidisland/AcidIslandTest.java new file mode 100644 index 0000000..59dda5e --- /dev/null +++ b/src/test/java/world/bentobox/acidisland/AcidIslandTest.java @@ -0,0 +1,269 @@ +/** + * + */ +package world.bentobox.acidisland; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +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.List; +import java.util.UUID; +import java.util.jar.JarEntry; +import java.util.jar.JarOutputStream; +import java.util.logging.Logger; + +import org.bukkit.Bukkit; +import org.bukkit.Server; +import org.bukkit.entity.Player; +import org.bukkit.plugin.PluginManager; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.stubbing.Answer; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.reflect.Whitebox; + +import world.bentobox.acidisland.world.ChunkGeneratorWorld; +import world.bentobox.bentobox.BentoBox; +import world.bentobox.bentobox.Settings; +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.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; + +/** + * @author tastybento + * + */ +@RunWith(PowerMockRunner.class) +@PrepareForTest({Bukkit.class, BentoBox.class, User.class, Config.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(); + } + +} From d72cc11ab61d3399ee029c937f5b23f4632af88c Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 10 Oct 2020 19:53:10 -0700 Subject: [PATCH 14/14] Merge if statements --- .../acidisland/listeners/AcidEffect.java | 37 +++++++------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java b/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java index a7b6161..47a7d2d 100644 --- a/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java +++ b/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java @@ -291,35 +291,24 @@ public class AcidEffect implements Listener { ItemStack helmet = inv.getHelmet(); ItemStack chest = inv.getChestplate(); ItemStack pants = inv.getLeggings(); - if (helmet != null) { - // Damage if helmet - if (helmet.getType().name().contains("HELMET") && damage(helmet)) { - le.getWorld().playSound(le.getLocation(), Sound.ENTITY_ITEM_BREAK, 1F, 1F); - inv.setHelmet(null); - } + // Damage if helmet + if (helmet != null&& helmet.getType().name().contains("HELMET") && damage(helmet)) { + le.getWorld().playSound(le.getLocation(), Sound.ENTITY_ITEM_BREAK, 1F, 1F); + inv.setHelmet(null); } - if (boots != null) { - // Damage - if (damage(boots)) { - le.getWorld().playSound(le.getLocation(), Sound.ENTITY_ITEM_BREAK, 1F, 1F); - inv.setBoots(null); - } + if (boots != null && damage(boots)) { + le.getWorld().playSound(le.getLocation(), Sound.ENTITY_ITEM_BREAK, 1F, 1F); + inv.setBoots(null); } // Pants - if (pants != null) { - // Damage - if (damage(pants)) { - le.getWorld().playSound(le.getLocation(), Sound.ENTITY_ITEM_BREAK, 1F, 1F); - inv.setLeggings(null); - } + if (pants != null && damage(pants)) { + le.getWorld().playSound(le.getLocation(), Sound.ENTITY_ITEM_BREAK, 1F, 1F); + inv.setLeggings(null); } // Chest plate - if (chest != null) { - // Damage - if (damage(chest)) { - le.getWorld().playSound(le.getLocation(), Sound.ENTITY_ITEM_BREAK, 1F, 1F); - inv.setChestplate(null); - } + if (chest != null && damage(chest)) { + le.getWorld().playSound(le.getLocation(), Sound.ENTITY_ITEM_BREAK, 1F, 1F); + inv.setChestplate(null); } return red; }