diff --git a/pom.xml b/pom.xml index 2bdcfc5..a6263e6 100644 --- a/pom.xml +++ b/pom.xml @@ -1,254 +1,336 @@ - 4.0.0 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - world.bentobox - acidisland - 1.5.0 + world.bentobox + acidisland + ${revision} - AcidIsland - AcidIsland is an add-on for BentoBox, an expandable Minecraft Bukkit plugin for island-type games like SkyBlock or AcidIsland. - https://github.com/BentoBoxWorld/AcidIsland - 2017 + AcidIsland + AcidIsland is an add-on for BentoBox, an expandable Minecraft Bukkit plugin for island-type games like SkyBlock or AcidIsland. + https://github.com/BentoBoxWorld/AcidIsland + 2017 - - scm:git:https://github.com/BentoBoxWorld/AcidIsland.git - scm:git:git@github.com:BentoBoxWorld/AcidIsland.git - https://github.com/BentoBoxWorld/AcidIsland - + + + tastybento + tastybento@bentobox.world + -8 + + Lead Developer + + + - - jenkins - http://ci.codemc.org/job/BentoBoxWorld/job/AcidIsland - + + scm:git:https://github.com/BentoBoxWorld/AcidIsland.git + scm:git:git@github.com:BentoBoxWorld/AcidIsland.git + https://github.com/BentoBoxWorld/AcidIsland + - - GitHub - https://github.com/BentoBoxWorld/AcidIsland/issues - + + jenkins + http://ci.codemc.org/job/BentoBoxWorld/job/AcidIsland + - - - codemc-snapshots - https://repo.codemc.org/repository/maven-snapshots - - - codemc-releases - https://repo.codemc.org/repository/maven-releases - - + + GitHub + https://github.com/BentoBoxWorld/AcidIsland/issues + - - UTF-8 - UTF-8 - 1.8 - 1.7.4 - + + + codemc-snapshots + https://repo.codemc.org/repository/maven-snapshots + + + codemc-releases + https://repo.codemc.org/repository/maven-releases + + - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots - - - codemc-repo - https://repo.codemc.org/repository/maven-public/ - - + + UTF-8 + UTF-8 + 1.8 + + 2.0.2 + + 1.13.2-R0.1-SNAPSHOT + 1.6.0-SNAPSHOT + + ${build.version}-SNAPSHOT + + -LOCAL + + 1.6.0 + - - - org.spigotmc - spigot-api - 1.14.1-R0.1-SNAPSHOT - provided - - - org.mockito - mockito-all - 1.10.19 - test - - - org.powermock - powermock-module-junit4 - ${powermock.version} - test - - - org.powermock - powermock-api-mockito - ${powermock.version} - test - - - world.bentobox - bentobox - 1.5.0 - provided - - + + + + + + ci + + + env.BUILD_NUMBER + + + + + -b${env.BUILD_NUMBER} + + + + + + + + master + + + env.GIT_BRANCH + origin/master + + + + + ${build.version} + + + + + + sonar + + https://sonarcloud.io + tastybento-github + + + + + org.sonarsource.scanner.maven + sonar-maven-plugin + 3.4.1.1168 + + + verify + + sonar + + + + + + + + - - clean package - - - src/main/resources - true - - - src/main/resources/locales - ./locales - false - - *.yml - - - - src/main/resources/blueprints - ./blueprints - false - - *.blu - *.json - - - - - - org.apache.maven.plugins - maven-clean-plugin - 3.1.0 - - - org.apache.maven.plugins - maven-resources-plugin - 3.1.0 - - - blu - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - ${java.version} - ${java.version} - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.22.0 - - - org.apache.maven.plugins - maven-jar-plugin - 3.1.0 - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.0.1 - - public - false - -Xdoclint:none - - - - attach-javadocs - - jar - - - - - - org.apache.maven.plugins - maven-source-plugin - 3.0.1 - - - attach-sources - - jar-no-fork - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.1.1 - - false - - - - org.apache.maven.plugins - maven-install-plugin - 2.5.2 - - - org.apache.maven.plugins - maven-deploy-plugin - 2.8.2 - - - org.jacoco - jacoco-maven-plugin - 0.8.1 - - true - - - - pre-unit-test - - prepare-agent - - - - post-unit-test - - report - - - - - - + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots + + + codemc + https://repo.codemc.org/repository/maven-snapshots/ + + + codemc-repo + https://repo.codemc.org/repository/maven-public/ + + - - - sonar - - https://sonarcloud.io - tastybento-github - - - - - org.sonarsource.scanner.maven - sonar-maven-plugin - 3.4.1.1168 - - - verify - - sonar - - - - - - - - + + + + + org.spigotmc + spigot-api + ${spigot.version} + provided + + + + org.mockito + mockito-core + 3.0.0 + test + + + org.powermock + powermock-module-junit4 + ${powermock.version} + test + + + org.powermock + powermock-api-mockito2 + ${powermock.version} + test + + + world.bentobox + bentobox + ${bentobox.version} + provided + + + + + + + + + + + ${project.name}-${revision}${build.number} + + clean package + + + src/main/resources + true + + + src/main/resources/locales + ./locales + false + + *.yml + + + + src/main/resources/blueprints + ./blueprints + false + + *.blu + *.json + + + + + + org.apache.maven.plugins + maven-clean-plugin + 3.1.0 + + + org.apache.maven.plugins + maven-resources-plugin + 3.1.0 + + + blu + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.7.0 + + ${java.version} + ${java.version} + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.0 + + + org.apache.maven.plugins + maven-jar-plugin + 3.1.0 + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.0.1 + + public + false + -Xdoclint:none + + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-source-plugin + 3.0.1 + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.1.1 + + false + + + + org.apache.maven.plugins + maven-install-plugin + 2.5.2 + + + org.apache.maven.plugins + maven-deploy-plugin + 2.8.2 + + + org.jacoco + jacoco-maven-plugin + 0.8.3 + + true + + + **/*Names* + + + + + pre-unit-test + + prepare-agent + + + + post-unit-test + + report + + + + + + \ No newline at end of file diff --git a/src/main/java/world/bentobox/acidisland/AISettings.java b/src/main/java/world/bentobox/acidisland/AISettings.java index 381379d..dc31d85 100644 --- a/src/main/java/world/bentobox/acidisland/AISettings.java +++ b/src/main/java/world/bentobox/acidisland/AISettings.java @@ -194,11 +194,6 @@ public class AISettings implements WorldSettings { @ConfigEntry(path = "world.nether.sea-height", needsReset = true) private int netherSeaHeight = 54; - @ConfigComment("Nether trees are made if a player grows a tree in the nether (gravel and glowstone)") - @ConfigComment("Applies to both vanilla and islands Nether") - @ConfigEntry(path = "world.nether.trees") - private boolean netherTrees = true; - @ConfigComment("Make the nether roof, if false, there is nothing up there") @ConfigComment("Change to false if lag is a problem from the generation") @ConfigComment("Only applies to islands Nether") @@ -367,6 +362,10 @@ public class AISettings implements WorldSettings { @ConfigEntry(path = "island.deaths.team-join-reset") private boolean teamJoinDeathReset = true; + @ConfigComment("Reset player death count when they start a new island or reset and island") + @ConfigEntry(path = "island.deaths.reset-on-new-island") + private boolean deathsResetOnNewIsland = true; + // Ranks @ConfigEntry(path = "island.customranks") private Map customRanks = new HashMap<>(); @@ -772,13 +771,6 @@ public class AISettings implements WorldSettings { public boolean isNetherRoof() { return netherRoof; } - /** - * @return the netherTrees - */ - @Override - public boolean isNetherTrees() { - return netherTrees; - } /** * @return the onJoinResetEnderChest */ @@ -1141,12 +1133,6 @@ public class AISettings implements WorldSettings { public void setNetherSpawnRadius(int netherSpawnRadius) { this.netherSpawnRadius = netherSpawnRadius; } - /** - * @param netherTrees the netherTrees to set - */ - public void setNetherTrees(boolean netherTrees) { - this.netherTrees = netherTrees; - } /** * @param onJoinResetEnderChest the onJoinResetEnderChest to set */ @@ -1286,5 +1272,18 @@ public class AISettings implements WorldSettings { public void setAcidDamageSnow(boolean acidDamageSnow) { this.acidDamageSnow = acidDamageSnow; } + /** + * @return the deathsResetOnNewIsland + */ + @Override + public boolean isDeathsResetOnNewIsland() { + return deathsResetOnNewIsland; + } + /** + * @param deathsResetOnNewIsland the deathsResetOnNewIsland to set + */ + public void setDeathsResetOnNewIsland(boolean deathsResetOnNewIsland) { + this.deathsResetOnNewIsland = deathsResetOnNewIsland; + } } diff --git a/src/main/java/world/bentobox/acidisland/AcidIsland.java b/src/main/java/world/bentobox/acidisland/AcidIsland.java index e254e4f..1f05cb0 100644 --- a/src/main/java/world/bentobox/acidisland/AcidIsland.java +++ b/src/main/java/world/bentobox/acidisland/AcidIsland.java @@ -27,6 +27,7 @@ public class AcidIsland extends GameModeAddon { private AISettings settings; private AcidTask acidTask; private @NonNull ChunkGenerator chunkGenerator; + private Config config = new Config<>(this, AISettings.class); private static final String NETHER = "_nether"; private static final String THE_END = "_the_end"; @@ -45,7 +46,7 @@ public class AcidIsland extends GameModeAddon { } private boolean loadSettings() { - settings = new Config<>(this, AISettings.class).loadConfigObject(); + settings = config.loadConfigObject(); if (settings == null) { // Woops this.logError("AcidIsland settings could not load! Addon disabled."); @@ -65,6 +66,11 @@ public class AcidIsland extends GameModeAddon { if (settings == null) { return; } + // Set default access to boats + Flags.BOAT.setDefaultSetting(islandWorld, true); + if (netherWorld != null) Flags.BOAT.setDefaultSetting(netherWorld, true); + if (endWorld != null) Flags.BOAT.setDefaultSetting(endWorld, true); + // Register listeners // Acid Effects registerListener(new AcidEffect(this)); @@ -92,6 +98,9 @@ public class AcidIsland extends GameModeAddon { getPlugin().log(string); } + /* (non-Javadoc) + * @see world.bentobox.bentobox.api.addons.GameModeAddon#createWorlds() + */ @Override public void createWorlds() { String worldName = settings.getWorldName().toLowerCase(); @@ -102,8 +111,6 @@ public class AcidIsland extends GameModeAddon { chunkGenerator = new ChunkGeneratorWorld(this); islandWorld = WorldCreator.name(worldName).type(WorldType.FLAT).environment(World.Environment.NORMAL).generator(chunkGenerator) .createWorld(); - // Set default access to boats - Flags.BOAT.setDefaultSetting(islandWorld, true); // Make the nether if it does not exist if (settings.isNetherGenerate()) { if (getServer().getWorld(worldName + NETHER) == null) { @@ -111,7 +118,7 @@ public class AcidIsland extends GameModeAddon { } if (!settings.isNetherIslands()) { netherWorld = WorldCreator.name(worldName + NETHER).type(WorldType.NORMAL).environment(World.Environment.NETHER).createWorld(); - Flags.BOAT.setDefaultSetting(netherWorld, true); + } else { netherWorld = WorldCreator.name(worldName + NETHER).type(WorldType.FLAT).generator(chunkGenerator) .environment(World.Environment.NETHER).createWorld(); @@ -124,7 +131,6 @@ public class AcidIsland extends GameModeAddon { } if (!settings.isEndIslands()) { endWorld = WorldCreator.name(worldName + THE_END).type(WorldType.NORMAL).environment(World.Environment.THE_END).createWorld(); - Flags.BOAT.setDefaultSetting(endWorld, true); } else { endWorld = WorldCreator.name(worldName + THE_END).type(WorldType.FLAT).generator(chunkGenerator) .environment(World.Environment.THE_END).createWorld(); @@ -152,7 +158,7 @@ public class AcidIsland extends GameModeAddon { @Override public void saveWorldSettings() { if (settings != null) { - new Config<>(this, AISettings.class).saveConfigObject(settings); + config.saveConfigObject(settings); } } diff --git a/src/main/java/world/bentobox/acidisland/commands/AcidCommand.java b/src/main/java/world/bentobox/acidisland/commands/AcidCommand.java index 162babf..d1cf37a 100644 --- a/src/main/java/world/bentobox/acidisland/commands/AcidCommand.java +++ b/src/main/java/world/bentobox/acidisland/commands/AcidCommand.java @@ -13,6 +13,7 @@ import world.bentobox.bentobox.api.commands.admin.AdminReloadCommand; import world.bentobox.bentobox.api.commands.admin.AdminResetFlagsCommand; import world.bentobox.bentobox.api.commands.admin.AdminSetrankCommand; import world.bentobox.bentobox.api.commands.admin.AdminSetspawnCommand; +import world.bentobox.bentobox.api.commands.admin.AdminSettingsCommand; import world.bentobox.bentobox.api.commands.admin.AdminSwitchCommand; import world.bentobox.bentobox.api.commands.admin.AdminSwitchtoCommand; import world.bentobox.bentobox.api.commands.admin.AdminTeleportCommand; @@ -22,6 +23,7 @@ import world.bentobox.bentobox.api.commands.admin.AdminVersionCommand; import world.bentobox.bentobox.api.commands.admin.AdminWhyCommand; import world.bentobox.bentobox.api.commands.admin.blueprints.AdminBlueprintCommand; import world.bentobox.bentobox.api.commands.admin.deaths.AdminDeathsCommand; +import world.bentobox.bentobox.api.commands.admin.purge.AdminPurgeCommand; import world.bentobox.bentobox.api.commands.admin.range.AdminRangeCommand; import world.bentobox.bentobox.api.commands.admin.resets.AdminResetsResetCommand; import world.bentobox.bentobox.api.commands.admin.team.AdminTeamAddCommand; @@ -85,6 +87,10 @@ public class AcidCommand extends CompositeCommand { new AdminSwitchtoCommand(this); // Switch new AdminSwitchCommand(this); + // Purge + new AdminPurgeCommand(this); + // Settings + new AdminSettingsCommand(this); } @Override diff --git a/src/main/java/world/bentobox/acidisland/commands/AiCommand.java b/src/main/java/world/bentobox/acidisland/commands/AiCommand.java index 1308731..b4e228e 100644 --- a/src/main/java/world/bentobox/acidisland/commands/AiCommand.java +++ b/src/main/java/world/bentobox/acidisland/commands/AiCommand.java @@ -12,6 +12,7 @@ import world.bentobox.bentobox.api.commands.island.IslandExpelCommand; import world.bentobox.bentobox.api.commands.island.IslandGoCommand; import world.bentobox.bentobox.api.commands.island.IslandInfoCommand; import world.bentobox.bentobox.api.commands.island.IslandLanguageCommand; +import world.bentobox.bentobox.api.commands.island.IslandNearCommand; import world.bentobox.bentobox.api.commands.island.IslandResetCommand; import world.bentobox.bentobox.api.commands.island.IslandResetnameCommand; import world.bentobox.bentobox.api.commands.island.IslandSethomeCommand; @@ -54,6 +55,7 @@ public class AiCommand extends CompositeCommand { new IslandUnbanCommand(this); new IslandBanlistCommand(this); new IslandExpelCommand(this); + new IslandNearCommand(this); // Team commands new IslandTeamCommand(this); } @@ -69,10 +71,10 @@ public class AiCommand extends CompositeCommand { if (args.isEmpty()) { // If in world, go if (getPlugin().getIslands().getIsland(getWorld(), user.getUniqueId()) != null) { - return getSubCommand("go").map(goCmd -> goCmd.execute(user, label, new ArrayList<>())).orElse(false); + return getSubCommand("go").map(goCmd -> goCmd.call(user, label, new ArrayList<>())).orElse(false); } // No islands currently - return getSubCommand("create").map(createCmd -> createCmd.execute(user, label, new ArrayList<>())).orElse(false); + return getSubCommand("create").map(createCmd -> createCmd.call(user, label, new ArrayList<>())).orElse(false); } user.sendMessage("general.errors.unknown-command", TextVariables.LABEL, getLabel()); return false; diff --git a/src/main/resources/addon.yml b/src/main/resources/addon.yml index e598392..90c9979 100755 --- a/src/main/resources/addon.yml +++ b/src/main/resources/addon.yml @@ -1,6 +1,6 @@ name: AcidIsland main: world.bentobox.acidisland.AcidIsland -version: ${project.version} +version: ${version}${build.number} metrics: true repository: "BentoBoxWorld/AcidIsland" icon: "OAK_BOAT" diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 48cf0ae..4cffb98 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -283,6 +283,8 @@ island: max: 10 # When a player joins a team, reset their death count team-join-reset: true + # Reset player death count when they start a new island or reset and island + reset-on-new-island: true customranks: {} protection: # Geo restrict mobs. diff --git a/src/test/java/world/bentobox/acidisland/commands/AcidCommandTest.java b/src/test/java/world/bentobox/acidisland/commands/AcidCommandTest.java index 54b3d78..c24f1f7 100644 --- a/src/test/java/world/bentobox/acidisland/commands/AcidCommandTest.java +++ b/src/test/java/world/bentobox/acidisland/commands/AcidCommandTest.java @@ -1,6 +1,3 @@ -/** - * - */ package world.bentobox.acidisland.commands; import static org.junit.Assert.assertEquals; @@ -17,6 +14,7 @@ import org.bukkit.entity.Player; 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.core.classloader.annotations.PrepareForTest; @@ -37,7 +35,8 @@ import world.bentobox.bentobox.managers.CommandsManager; @PrepareForTest({Bukkit.class, BentoBox.class, User.class }) public class AcidCommandTest { - private static final int NUM_COMMANDS = 27; + private static final int NUM_COMMANDS = 29; + @Mock private User user; /** @@ -56,7 +55,6 @@ public class AcidCommandTest { // Player Player p = mock(Player.class); // Sometimes use Mockito.withSettings().verboseLogging() - user = mock(User.class); when(user.isOp()).thenReturn(false); UUID uuid = UUID.randomUUID(); when(user.getUniqueId()).thenReturn(uuid); @@ -66,7 +64,7 @@ public class AcidCommandTest { // Locales // Return the reference (USE THIS IN THE FUTURE) - when(user.getTranslation(Mockito.anyString())).thenAnswer((Answer) invocation -> invocation.getArgumentAt(0, String.class)); + when(user.getTranslation(Mockito.anyString())).thenAnswer((Answer) invocation -> invocation.getArgument(0, String.class)); } diff --git a/src/test/java/world/bentobox/acidisland/commands/AiCommandTest.java b/src/test/java/world/bentobox/acidisland/commands/AiCommandTest.java index 0b0d7b8..420ca43 100644 --- a/src/test/java/world/bentobox/acidisland/commands/AiCommandTest.java +++ b/src/test/java/world/bentobox/acidisland/commands/AiCommandTest.java @@ -1,33 +1,43 @@ -/** - * - */ package world.bentobox.acidisland.commands; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.util.Collections; +import java.util.HashMap; +import java.util.Map; import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.bukkit.plugin.PluginManager; +import org.bukkit.scheduler.BukkitScheduler; 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.AISettings; +import world.bentobox.acidisland.AcidIsland; import world.bentobox.bentobox.BentoBox; -import world.bentobox.bentobox.api.addons.Addon; +import world.bentobox.bentobox.Settings; import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.user.User; +import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBundle; import world.bentobox.bentobox.database.objects.Island; +import world.bentobox.bentobox.managers.BlueprintsManager; import world.bentobox.bentobox.managers.CommandsManager; import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandsManager; @@ -40,9 +50,15 @@ import world.bentobox.bentobox.managers.IslandsManager; @PrepareForTest({Bukkit.class, BentoBox.class, User.class }) public class AiCommandTest { + private static final int NUMBER_OF_COMMANDS = 18; + @Mock private User user; + @Mock private IslandsManager im; + @Mock private Island island; + @Mock + private AcidIsland addon; /** * @throws java.lang.Exception @@ -60,28 +76,53 @@ public class AiCommandTest { // Player Player p = mock(Player.class); // Sometimes use Mockito.withSettings().verboseLogging() - user = mock(User.class); when(user.isOp()).thenReturn(false); UUID uuid = UUID.randomUUID(); when(user.getUniqueId()).thenReturn(uuid); when(user.getPlayer()).thenReturn(p); when(user.getName()).thenReturn("tastybento"); + when(user.isPlayer()).thenReturn(true); User.setPlugin(plugin); // Island World Manager IslandWorldManager iwm = mock(IslandWorldManager.class); when(plugin.getIWM()).thenReturn(iwm); + // Settings + Settings s = mock(Settings.class); + when(plugin.getSettings()).thenReturn(s); // Player has island to begin with - im = mock(IslandsManager.class); - 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.getArgumentAt(0, String.class)); + when(user.getTranslation(Mockito.anyString())).thenAnswer((Answer) invocation -> invocation.getArgument(0, String.class)); + + // Addon settings + AISettings settings = mock(AISettings.class); + when(settings.getIslandCommand()).thenReturn("ai"); + when(addon.getSettings()).thenReturn(settings); + + // Blueprints + BlueprintsManager bpm = mock(BlueprintsManager.class); + Map map = new HashMap<>(); + BlueprintBundle bun = mock(BlueprintBundle.class); + when(bun.getDisplayName()).thenReturn("aaa", "bbb"); + map.put("aaa", bun); + map.put("bbb", bun); + when(bun.getUniqueId()).thenReturn("unique1", "unique2"); + when(bun.isRequirePermission()).thenReturn(true); + when(bpm.getBlueprintBundles(Mockito.any())).thenReturn(map); + when(plugin.getBlueprintsManager()).thenReturn(bpm); + + // Bukkit + PowerMockito.mockStatic(Bukkit.class); + PluginManager pim = mock(PluginManager.class); + when(Bukkit.getPluginManager()).thenReturn(pim); + BukkitScheduler sch = mock(BukkitScheduler.class); + when(Bukkit.getScheduler()).thenReturn(sch); } @@ -91,7 +132,6 @@ public class AiCommandTest { */ @Test public void testAiCommand() { - Addon addon = mock(Addon.class); AiCommand cmd = new AiCommand(addon, "ai"); assertEquals("ai", cmd.getLabel()); } @@ -101,15 +141,13 @@ public class AiCommandTest { */ @Test public void testSetup() { - Addon addon = mock(Addon.class); when(addon.getPermissionPrefix()).thenReturn("acidisland."); AiCommand cmd = new AiCommand(addon, "ai"); assertEquals("acidisland.island", cmd.getPermission()); assertTrue(cmd.isOnlyPlayer()); - assertEquals("commands.ai.parameters", cmd.getParameters()); assertEquals("commands.island.help.description", cmd.getDescription()); // Number of commands = sub commands + help - assertEquals("Number of sub commands registered", 17, cmd.getSubCommands().values().size()); + assertEquals("Number of sub commands registered", NUMBER_OF_COMMANDS, cmd.getSubCommands().values().size()); } @@ -118,9 +156,8 @@ public class AiCommandTest { */ @Test public void testExecuteUserStringListOfStringNullUsers() { - Addon addon = mock(Addon.class); AiCommand cmd = new AiCommand(addon, "ai"); - assertFalse(cmd.execute(null, "ai", Collections.emptyList())); + assertFalse(cmd.execute(null, "island", Collections.emptyList())); } @@ -129,31 +166,75 @@ public class AiCommandTest { */ @Test public void testExecuteUserStringListOfStringUnknownCommand() { - Addon addon = mock(Addon.class); AiCommand cmd = new AiCommand(addon, "ai"); - assertFalse(cmd.execute(user, "ai", Collections.singletonList("unknown"))); - Mockito.verify(user).sendMessage("general.errors.unknown-command", TextVariables.LABEL, "ai"); + assertFalse(cmd.execute(user, "island", Collections.singletonList("unknown"))); + verify(user).sendMessage("general.errors.unknown-command", TextVariables.LABEL, "ai"); } /** * Test method for {@link world.bentobox.acidisland.commands.AiCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. */ @Test - public void testExecuteUserStringListOfStringNoArgs() { - Addon addon = mock(Addon.class); + public void testExecuteUserStringListOfStringNoArgsNoPermission() { AiCommand cmd = new AiCommand(addon, "ai"); - assertTrue(cmd.execute(user, "ai", Collections.emptyList())); + assertFalse(cmd.execute(user, "island", Collections.emptyList())); + verify(user).sendMessage("general.errors.no-permission", "[permission]", "island.home"); } /** * Test method for {@link world.bentobox.acidisland.commands.AiCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. */ @Test - public void testExecuteUserStringListOfStringNoArgsNoIsland() { - island = null; - Addon addon = mock(Addon.class); + public void testExecuteUserStringListOfStringNoArgsSuccess() { + when(user.hasPermission(anyString())).thenReturn(true); AiCommand cmd = new AiCommand(addon, "ai"); - assertTrue(cmd.execute(user, "ai", Collections.emptyList())); + assertTrue(cmd.execute(user, "island", Collections.emptyList())); + } + + /** + * Test method for {@link world.bentobox.acidisland.commands.AiCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. + */ + @Test + public void testExecuteUserStringListOfStringNoArgsConsole() { + when(user.isPlayer()).thenReturn(false); + AiCommand cmd = new AiCommand(addon, "ai"); + assertFalse(cmd.execute(user, "island", Collections.emptyList())); + verify(user).sendMessage("general.errors.use-in-game"); + } + + /** + * Test method for {@link world.bentobox.acidisland.commands.AiCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. + */ + @Test + public void testExecuteUserStringListOfStringNoArgsNoIslandConsole() { + when(user.isPlayer()).thenReturn(false); + when(im.getIsland(any(), any(UUID.class))).thenReturn(null); + AiCommand cmd = new AiCommand(addon, "ai"); + assertFalse(cmd.execute(user, "island", Collections.emptyList())); + verify(user).sendMessage("general.errors.use-in-game"); + } + + /** + * Test method for {@link world.bentobox.acidisland.commands.AiCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. + */ + @Test + public void testExecuteUserStringListOfStringNoArgsNoIslandNoPermission() { + when(im.getIsland(any(), any(UUID.class))).thenReturn(null); + AiCommand cmd = new AiCommand(addon, "ai"); + assertFalse(cmd.execute(user, "island", Collections.emptyList())); + verify(user).sendMessage("general.errors.no-permission", "[permission]", "island.create"); + } + + /** + * Test method for {@link world.bentobox.acidisland.commands.AiCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. + */ + @Test + public void testExecuteUserStringListOfStringNoArgsNoIslandCreateSuccess() { + when(im.getIsland(any(), any(UUID.class))).thenReturn(null); + when(user.hasPermission(Mockito.eq("island.create"))).thenReturn(true); + AiCommand cmd = new AiCommand(addon, "ai"); + assertTrue(cmd.execute(user, "island", Collections.emptyList())); + verify(user).getTranslation("commands.island.create.pick"); } } diff --git a/src/test/java/world/bentobox/acidisland/events/AcidEventTest.java b/src/test/java/world/bentobox/acidisland/events/AcidEventTest.java index e7adce0..cef6f3d 100644 --- a/src/test/java/world/bentobox/acidisland/events/AcidEventTest.java +++ b/src/test/java/world/bentobox/acidisland/events/AcidEventTest.java @@ -15,16 +15,17 @@ import org.bukkit.potion.PotionEffectType; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.mockito.Mock; public class AcidEventTest { + @Mock private Player player; private List effects; private AcidEvent e; @Before public void setUp() throws Exception { - player = mock(Player.class); 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 964068c..7aac502 100644 --- a/src/test/java/world/bentobox/acidisland/events/AcidRainEventTest.java +++ b/src/test/java/world/bentobox/acidisland/events/AcidRainEventTest.java @@ -9,15 +9,16 @@ import static org.mockito.Mockito.mock; import org.bukkit.entity.Player; import org.junit.Before; import org.junit.Test; +import org.mockito.Mock; public class AcidRainEventTest { + @Mock private Player player; private AcidRainEvent e; @Before public void setUp() throws Exception { - player = mock(Player.class); e = new AcidRainEvent(player, 10, 5); } diff --git a/src/test/java/world/bentobox/acidisland/world/AcidTaskTest.java b/src/test/java/world/bentobox/acidisland/world/AcidTaskTest.java index 77637da..1b80dac 100644 --- a/src/test/java/world/bentobox/acidisland/world/AcidTaskTest.java +++ b/src/test/java/world/bentobox/acidisland/world/AcidTaskTest.java @@ -1,6 +1,10 @@ package world.bentobox.acidisland.world; -import static org.mockito.Mockito.mock; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import org.bukkit.Bukkit; @@ -8,7 +12,7 @@ import org.bukkit.scheduler.BukkitScheduler; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Mockito; +import org.mockito.Mock; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; @@ -20,17 +24,17 @@ import world.bentobox.acidisland.AcidIsland; @PrepareForTest({Bukkit.class}) public class AcidTaskTest { + @Mock private BukkitScheduler scheduler; + @Mock private AISettings settings; + @Mock private AcidIsland addon; @Before public void setUp() throws Exception { PowerMockito.mockStatic(Bukkit.class); - scheduler = mock(BukkitScheduler.class); when(Bukkit.getScheduler()).thenReturn(scheduler); - addon = mock(AcidIsland.class); - settings = mock(AISettings.class); when(settings.getAcidDestroyItemTime()).thenReturn(0L); when(addon.getSettings()).thenReturn(settings); } @@ -38,22 +42,22 @@ public class AcidTaskTest { @Test public void testAcidTaskDoNotDestroyItems() { new AcidTask(addon); - Mockito.verify(scheduler).scheduleSyncRepeatingTask(Mockito.any(), Mockito.any(Runnable.class), Mockito.eq(0L), Mockito.eq(20L)); + verify(scheduler).scheduleSyncRepeatingTask(any(), any(Runnable.class), eq(0L), eq(20L)); } @Test public void testAcidTaskDestroyItems() { when(settings.getAcidDestroyItemTime()).thenReturn(5L); new AcidTask(addon); - Mockito.verify(scheduler).scheduleSyncRepeatingTask(Mockito.any(), Mockito.any(Runnable.class), Mockito.eq(0L), Mockito.eq(20L)); - Mockito.verify(scheduler).scheduleSyncRepeatingTask(Mockito.any(), Mockito.any(Runnable.class), Mockito.eq(100L), Mockito.eq(100L)); + verify(scheduler).scheduleSyncRepeatingTask(any(), any(Runnable.class), eq(0L), eq(20L)); + verify(scheduler).scheduleSyncRepeatingTask(any(), any(Runnable.class), eq(100L), eq(100L)); } @Test public void testAcidTaskCancelTasks() { AcidTask task = new AcidTask(addon); task.cancelTasks(); - Mockito.verify(scheduler).cancelTask(Mockito.anyInt()); + verify(scheduler).cancelTask(anyInt()); } @Test @@ -61,7 +65,7 @@ public class AcidTaskTest { when(settings.getAcidDestroyItemTime()).thenReturn(5L); AcidTask task = new AcidTask(addon); task.cancelTasks(); - Mockito.verify(scheduler, Mockito.times(2)).cancelTask(Mockito.anyInt()); + verify(scheduler, times(2)).cancelTask(anyInt()); }