Release 1.3.0 (#331)

* Init 1.2.0 version

* Fixes #311 localization errors in zn-CN.

Original translation author translated `[]` placeholders which broke locale

* Init 1.2.0 version

* Edit some unfit translation (#312)

Edit some unfit translation

* Fixes a regex bug that replaced every [player] char instead of whole word.

* Fixes a crash that prevented STATISTICS entity and material/item challenges to be completed.

* Add requirement-not-met-material and requirement-not-met-entity to display statistic required item on error.

* Add locale of Chinese-Hong Kong (zh-HK) (#313)

Addition of locale updated to latest version

* Add ${argLine} to get jacoco coverage

* Updated Jacoco POM section

* Update build.yml

Java 17 for Surefire

* Updated pladdon annotations

* Add support for gamemode-specific translations.

This was a request from Floris

* Update ChallengesManagerTest methods with world parameter.

* Implement option that excludes undeployed challenges

The new option allows to toggle if undeployed challenges should be included in level completion count. Disabling option will not include these challenges for level completion.

Fixes #315

* Create plugin.yml (#316)

* Create plugin.yml

* Update pom.xml

* Update ChallengesPladdon.java

* Remove dependency to org.apache.commons

Replace org.apache.commons.lang.ArrayUtils to a default Java implementation.

* Fixes a crash with written/writable books.

The issue was with generating description message for written books without title or author.

Fixes #318

* Fixed TryToComplete test class

* Fixed CompleteChallengeCommandTest

* Fixed ChallengesCommandTest

* Fixed ChallengesManagerTest

* Update Github Action build script

* Add required distribution

* Fixes the admin GUI crash.

Add shade plugin that was missing for dependencies.

* Update Hungarian translation (#301)

* Translate hu.yml via GitLocalize

* Translate hu.yml via GitLocalize

* Translate hu.yml via GitLocalize

* Translate hu.yml via GitLocalize

* Update hu.yml

Fix color codes and placeholders

---------

Co-authored-by: driverdakid <tamascsiszar99@icloud.com>
Co-authored-by: mt-gitlocalize <mt@gitlocalize.com>
Co-authored-by: BONNe <bonne@bonne.id.lv>
Co-authored-by: slimcraft <davidelek12@gmail.com>
Co-authored-by: tastybento <tastybento@users.noreply.github.com>

* Update POM versions to use latest API

* Remove duplicate plugin reference in POM

* Try adding maven dependency to fix test issue

* Remove offending test. Was not that useful anyway.

* Update Jacoco

* Update pom.xml

* Update to BentoBox 2.0.0

Had to ignore some tests because PowerMockito can't mock them for some
reason.

* Add Ukrainian locale (#326)

* Translate uk.yml via GitLocalize

* Translate uk.yml via GitLocalize

---------

Co-authored-by: mt-gitlocalize <mt@gitlocalize.com>
Co-authored-by: GIGABAIT <freebitcoin93@gmail.com>

* Translate uk.yml via GitLocalize (#325)

Co-authored-by: GIGABAIT <freebitcoin93@gmail.com>
Co-authored-by: tastybento <tastybento@users.noreply.github.com>

* Show money as formatted. Addresses #324

* Update README.md

* Update README.md

* Fixes enchanted book meta not displayed (#328)

Apparently in Spigot EnchantmentStorage has a map that is not used for enchantment storing. Nice.

Fixes #327

* Upgrade PanelUtils to 1.2.0

* Fixes crash when player in CREATIVE shift+clicks on INVENTORY challenge.

Limit completion time to 2, if player is in creative instead of Integer.MAX_VALUE

Fixes #330

* Fix tests for creative user inventory challenge completion

* Update TIPPED_ARROW to latest API in panels

* Update en-US.yml

* Reference latest BentoBox release version

---------

Co-authored-by: BONNe <bonne@bonne.id.lv>
Co-authored-by: EpicMo <1982742309@qq.com>
Co-authored-by: JamesMCL44 <epicquarters@gmail.com>
Co-authored-by: gitlocalize-app[bot] <55277160+gitlocalize-app[bot]@users.noreply.github.com>
Co-authored-by: driverdakid <tamascsiszar99@icloud.com>
Co-authored-by: mt-gitlocalize <mt@gitlocalize.com>
Co-authored-by: slimcraft <davidelek12@gmail.com>
Co-authored-by: GIGABAIT <freebitcoin93@gmail.com>
This commit is contained in:
tastybento 2024-03-16 09:13:01 -07:00 committed by GitHub
parent b1fa9a9da7
commit 7c1deb9384
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 4675 additions and 2944 deletions

View File

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

View File

@ -2,24 +2,9 @@
[![Discord](https://img.shields.io/discord/272499714048524288.svg?logo=discord)](https://discord.bentobox.world)
[![Build Status](https://ci.codemc.org/buildStatus/icon?job=BentoBoxWorld/Challenges)](https://ci.codemc.org/job/BentoBoxWorld/job/Challenges/)
Add-on for BentoBox to provide challenges for any BentoBox GameMode.
Add-on for BentoBox to provide challenges for any BentoBox GameMode. Challenges can be to collect items, to have items or blocks nearby, to amass an amount of money or island levels, or to have accomplished some player statistic. Each challenge can reward the player with money, experience points, blocks, items, or other things, like permissions, Pre-built challenges are available and there is also a Web Library of pre-built ones. Customize them to fit your needs!
## Where to find
Currently Challenges Addon is in **Beta stage**, so it may or may not contain bugs... a lot of bugs. Also it means, that some features are not working or implemented.
Latest official **Beta Release is 0.8.3**, and you can download it from [Release tab](https://github.com/BentoBoxWorld/Challenges/releases)
But it will work with BentoBox 1.14.
Latest development builds will be based on **Minecraft 1.16.1** and **BentoBox 1.14.0**.
**Nightly builds** are available in [Jenkins Server](https://ci.codemc.org/job/BentoBoxWorld/job/Challenges/lastStableBuild/).
If you like this addon but something is missing or is not working as you want, you can always submit an [Issue request](https://github.com/BentoBoxWorld/Challenges/issues) or get a support in Discord [BentoBox ![icon](https://avatars2.githubusercontent.com/u/41555324?s=15&v=4)](https://discord.bentobox.world)
## Translations
As most of BentoBox projects, Challenges Addon is translatable in any language. Everyone can contribute, and translate some parts of the addon in their language via [GitLocalize](https://gitlocalize.com/repo/2896).
If your language is not in the list, please contact to developers via Discord and it will be added there.
Unfortunately, default challenges come only in English translation. But with version 0.8.0 there will be access to different challenges libraries, where everyone could share their challenges with their translations. More information will come soon.
![Challenges](https://github.com/BentoBoxWorld/Challenges/assets/4407265/9b3c5278-3a9d-45f2-9ee1-2c1fc1199a8d)
## How to use
@ -27,21 +12,32 @@ Unfortunately, default challenges come only in English translation. But with ver
2. Restart the server
3. Edit the config.yml how you want.
4. Restart the server
5. Run the Admin challenges command to set up challenges for your game mode.
#### Challenges
#### Installation
By default, challenges addon comes without any challenge or level. On first runtime only Admin GUI will be accessible.
Admins can create their own challenges or import some default challenges, which importing also are available via Admin GUI. Default challenges contains 5 levels and 57 challenges.
There exist also Web Library, where users can download public challenges. It is accessible with Admin GUI by clicking on Web icon.
By default, challenges addon comes without any challenge or level. On first run time only Admin GUI will be accessible.
Admins can create their own challenges or import some default challenges. Default challenges contains 5 levels and 57 challenges.
There also exists a Web Library, where admins can download public challenges. It is accessible from the Admin GUI by clicking on the Web icon.
## Compatibility
- [x] BentoBox - 1.14 versions
- [x] BentoBok
- [x] BSkyBlock
- [x] AcidIsland
- [x] SkyGrid
- [x] CaveBlock
## Information
## Translations
As with most of BentoBox projects, Challenges Addon is translatable into any language. Everyone can contribute, and translate some parts of the addon in their language via [GitLocalize](https://gitlocalize.com/repo/2896).
If your language is not in the list, please contact the developers via Discord and it will be added there.
Unfortunately, default challenges come only be in English, but there are different challenges libraries where everyone can share their challenges with their translations.
## Documentation
More information can be found in the docs: https://docs.bentobox.world/en/latest/addons/Challenges/
## Bugs or feature requests
If you like this addon but something is missing or is not working as you want, you can always submit an [Issue request](https://github.com/BentoBoxWorld/Challenges/issues) or get a support in Discord [BentoBox ![icon](https://avatars2.githubusercontent.com/u/41555324?s=15&v=4)](https://discord.bentobox.world)
More information can be found in [Wiki Pages](https://docs.bentobox.world/en/latest/addons/Challenges/).

83
pom.xml
View File

@ -35,16 +35,16 @@
<java.version>17</java.version>
<powermock.version>2.0.9</powermock.version>
<!-- More visible way how to change dependency versions -->
<spigot.version>1.17.1-R0.1-SNAPSHOT</spigot.version>
<spigot.version>1.20.4-R0.1-SNAPSHOT</spigot.version>
<spigot-annotations.version>1.2.3-SNAPSHOT</spigot-annotations.version>
<bentobox.version>1.21.0</bentobox.version>
<bentobox.version>2.1.0</bentobox.version>
<level.version>2.6.3</level.version>
<vault.version>1.7</vault.version>
<panelutils.version>1.1.0</panelutils.version>
<panelutils.version>1.2.0</panelutils.version>
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
<!-- This allows to change between versions and snapshots. -->
<build.version>1.2.0</build.version>
<build.version>1.3.0</build.version>
<build.number>-LOCAL</build.number>
<!-- Sonar Cloud -->
<sonar.projectKey>BentoBoxWorld_Challenges</sonar.projectKey>
@ -120,6 +120,12 @@
</repositories>
<dependencies>
<!-- This is required for PowerMockito to work and must be placed before it -->
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.30.2-GA</version>
</dependency>
<!-- Spigot API -->
<dependency>
<groupId>org.spigotmc</groupId>
@ -187,6 +193,11 @@
<version>1.5.21</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
</dependencies>
<build>
@ -217,6 +228,38 @@
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.1-SNAPSHOT</version>
<configuration>
<minimizeJar>true</minimizeJar>
<artifactSet>
<includes>
<include>lv.id.bonne:panelutils:*</include>
</includes>
</artifactSet>
<transformers>
<!-- Add a transformer to exclude any other manifest files (possibly from dependencies). -->
<transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
<resource>MANIFEST.MF</resource>
</transformer>
<!-- Add a transformer to include your custom manifest file. -->
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>META-INF/MANIFEST.MF</resource>
<file>src/main/resources/META-INF/MANIFEST.MF</file>
</transformer>
</transformers>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
@ -325,40 +368,15 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
<configuration>
<append>true</append>
<excludes>
<!-- This is required to prevent Jacoco from adding
synthetic fields to a JavaBean class (causes errors in testing) -->
<exclude>**/*Names*</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<version>0.8.10</version>
<configuration>
<append>true</append>
<excludes>
<!-- This is required to prevent Jacoco from adding
synthetic fields to a JavaBean class (causes errors in testing) -->
<exclude>**/*Names*</exclude>
<!-- Prevents the Material is too large to mock error -->
<exclude>org/bukkit/Material*</exclude>
</excludes>
</configuration>
<executions>
@ -378,6 +396,7 @@
<format>XML</format>
</formats>
</configuration>
</execution>
</executions>
</plugin>

View File

@ -952,6 +952,8 @@ public class TryToComplete
else
{
requiredItems = Collections.emptyList();
// Set maxTime to 2, to not crash client when completing 2147483647 times.
maxTimes = 2;
}
// Return the result

View File

@ -7,11 +7,19 @@ import java.util.List;
import java.util.Locale;
import java.util.Set;
import org.bukkit.*;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Statistic;
import org.bukkit.World;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.*;
import org.bukkit.inventory.meta.BookMeta;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionType;
import org.eclipse.jdt.annotation.Nullable;
@ -823,7 +831,7 @@ public class Utils
StringBuilder builder = new StringBuilder();
enchantmentMeta.getEnchants().forEach((enchantment, level) -> {
enchantmentMeta.getStoredEnchants().forEach((enchantment, level) -> {
builder.append("\n");
builder.append(user.getTranslationOrNothing(Constants.ITEM_STACKS + "meta.enchant-meta",
"[type]", prettifyObject(enchantment, user),
@ -868,8 +876,8 @@ public class Utils
final String metaReference = Constants.ITEM_STACKS + "meta.";
String meta = user.getTranslationOrNothing(metaReference + "book-meta",
"[title]", bookMeta.getTitle(),
"[author]", bookMeta.getAuthor());
"[title]", bookMeta.hasTitle() ? bookMeta.getTitle() : "",
"[author]", bookMeta.hasAuthor() ? bookMeta.getAuthor() : "");
return user.getTranslationOrNothing(Constants.ITEM_STACKS + "generic",
"[type]", prettifyObject(itemType, user),

View File

@ -907,7 +907,7 @@ challenges:
# Message that will be added after environment-title-multiple.
environment-list: " &7 - &e [environment]"
# Message that will replace [permissions] placeholder if there is just a single permission.
permission-single: "&c Requires [permissions] permission"
permission-single: "&c Requires [permission] permission"
# Message that will replace [permissions] placeholder if there are multiple permissions.
permissions-title: "&c Requires permissions: "
# Message that will be added after permissions-title-multiple.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -15,7 +15,7 @@ gamemode_panel:
content:
2:
1:
icon: TIPPED_ARROW:INSTANT_HEAL::::1
icon: tipped_arrow{CustomPotionColor:11546150}
title: challenges.gui.buttons.previous.name
description: challenges.gui.buttons.previous.description
data:
@ -33,7 +33,7 @@ gamemode_panel:
7: gamemode
8: gamemode
9:
icon: TIPPED_ARROW:JUMP::::1
icon: tipped_arrow{CustomPotionColor:8439583}
title: challenges.gui.buttons.next.name
description: challenges.gui.buttons.next.description
data:

View File

@ -23,7 +23,7 @@ main_panel:
8: challenge_button
3:
1:
icon: TIPPED_ARROW:INSTANT_HEAL::::1
icon: tipped_arrow{CustomPotionColor:11546150}
title: challenges.gui.buttons.previous.name
description: challenges.gui.buttons.previous.description
data:
@ -41,7 +41,7 @@ main_panel:
7: challenge_button
8: challenge_button
9:
icon: TIPPED_ARROW:JUMP::::1
icon: tipped_arrow{CustomPotionColor:8439583}
title: challenges.gui.buttons.next.name
description: challenges.gui.buttons.next.description
data:
@ -53,7 +53,7 @@ main_panel:
tooltip: challenges.gui.tips.click-to-next
5:
1:
icon: TIPPED_ARROW:INSTANT_HEAL::::1
icon: tipped_arrow{CustomPotionColor:11546150}
title: challenges.gui.buttons.previous.name
description: challenges.gui.buttons.previous.description
data:
@ -71,7 +71,7 @@ main_panel:
7: level_button
8: level_button
9:
icon: TIPPED_ARROW:JUMP::::1
icon: tipped_arrow{CustomPotionColor:8439583}
title: challenges.gui.buttons.next.name
description: challenges.gui.buttons.next.description
data:

View File

@ -82,7 +82,7 @@ public class ChallengesManagerTest {
// Mocks
@Mock
private ChallengesAddon addon;
@Mock
private Settings settings;
@Mock
private IslandWorldManager iwm;
@ -134,9 +134,11 @@ public class ChallengesManagerTest {
when(s.getDatabaseType()).thenReturn(DatabaseType.JSON);
// Addon Settings
settings = new Settings();
when(addon.getChallengesSettings()).thenReturn(settings);
when(settings.isStoreHistory()).thenReturn(true);
when(settings.getLifeSpan()).thenReturn(10);
settings.setStoreAsIslandData(false);
settings.setStoreHistory(true);
settings.setLifeSpan(10);
// Database
database = new File("database");
@ -264,7 +266,7 @@ public class ChallengesManagerTest {
assertTrue(cm.loadChallenge(challenge, world, false, user, true));
// load twice - no overwrite, not silent
assertFalse(cm.loadChallenge(challenge, world, false, user, false));
verify(user).getTranslation("challenges.messages.load-skipping", "[value]", "name");
verify(user).getTranslation(world, "challenges.messages.load-skipping", "[value]", "name");
}
/**
@ -276,7 +278,7 @@ public class ChallengesManagerTest {
assertTrue(cm.loadChallenge(challenge, world, false, user, true));
// overwrite
assertTrue(cm.loadChallenge(challenge, world, true, user, true));
verify(user, never()).getTranslation(anyString(), anyString(), anyString());
verify(user, never()).getTranslation(any(World.class), anyString(), anyString(), anyString());
}
/**
@ -288,7 +290,7 @@ public class ChallengesManagerTest {
assertTrue(cm.loadChallenge(challenge, world, false, user, true));
// overwrite not silent
assertTrue(cm.loadChallenge(challenge, world, true, user, false));
verify(user).getTranslation("challenges.messages.load-overwriting", "[value]", "name");
verify(user).getTranslation(world, "challenges.messages.load-overwriting", "[value]", "name");
}
/**
@ -311,7 +313,7 @@ public class ChallengesManagerTest {
assertTrue(cm.loadLevel(level, world, false, user, true));
// load twice - no overwrite, not silent
assertFalse(cm.loadLevel(level, world, false, user, false));
verify(user).getTranslation("challenges.messages.load-skipping", "[value]", "Novice");
verify(user).getTranslation(world, "challenges.messages.load-skipping", "[value]", "Novice");
}
/**
@ -323,7 +325,7 @@ public class ChallengesManagerTest {
assertTrue(cm.loadLevel(level, world, false, user, true));
// overwrite
assertTrue(cm.loadLevel(level, world, true, user, true));
verify(user, never()).getTranslation(anyString(), anyString(), anyString());
verify(user, never()).getTranslation(any(World.class), anyString(), anyString(), anyString());
}
/**
@ -335,7 +337,7 @@ public class ChallengesManagerTest {
assertTrue(cm.loadLevel(level, world, false, user, true));
// overwrite not silent
assertTrue(cm.loadLevel(level, world, true, user, false));
verify(user).getTranslation("challenges.messages.load-overwriting", "[value]", "Novice");
verify(user).getTranslation(world, "challenges.messages.load-overwriting", "[value]", "Novice");
}
/**

View File

@ -6,7 +6,6 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
@ -17,7 +16,6 @@ import java.util.Optional;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFactory;
@ -38,7 +36,6 @@ import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.configuration.WorldSettings;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.CommandsManager;
@ -46,16 +43,16 @@ import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.bentobox.util.Util;
import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.managers.ChallengesManager;
import world.bentobox.challenges.config.Settings;
import world.bentobox.challenges.config.SettingsUtils.VisibilityMode;
import world.bentobox.challenges.managers.ChallengesManager;
/**
* @author tastybento
*
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class, BentoBox.class, ChatColor.class, Util.class})
@PrepareForTest({ Bukkit.class, BentoBox.class, Util.class })
public class ChallengesCommandTest {
@Mock
@ -104,7 +101,7 @@ public class ChallengesCommandTest {
Optional<GameModeAddon> optionalAddon = Optional.of(gameModeAddon);
when(iwm.getAddon(any())).thenReturn(optionalAddon);
when(plugin.getIWM()).thenReturn(iwm);
@NonNull
WorldSettings ws = new TestWorldSetting();
when(iwm.getWorldSettings(any())).thenReturn(ws);
@ -143,10 +140,6 @@ public class ChallengesCommandTest {
// Challenges exist
when(chm.hasAnyChallengeData(any(World.class))).thenReturn(true);
// ChatColor
PowerMockito.mockStatic(ChatColor.class);
when(ChatColor.translateAlternateColorCodes(any(char.class), anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
// Settings
Settings settings = new Settings();
when(addon.getChallengesSettings()).thenReturn(settings);
@ -161,6 +154,9 @@ public class ChallengesCommandTest {
// Util
PowerMockito.mockStatic(Util.class, Mockito.RETURNS_MOCKS);
when(Util.sameWorld(any(), any())).thenReturn(true);
when(Util.translateColorCodes(anyString()))
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
// Command under test
cc = new ChallengesPlayerCommand(addon, ic);
}
@ -172,7 +168,7 @@ public class ChallengesCommandTest {
public void testCanExecuteWrongWorld() {
when(iwm.inWorld(any(World.class))).thenReturn(false);
assertFalse(cc.canExecute(user, "challenges", Collections.emptyList()));
verify(user).getTranslation("general.errors.wrong-world");
verify(user).getTranslation(world, "general.errors.wrong-world");
}
/**
@ -184,7 +180,7 @@ public class ChallengesCommandTest {
when(chm.hasAnyChallengeData(any(World.class))).thenReturn(false);
assertFalse(cc.canExecute(user, "challenges", Collections.emptyList()));
verify(addon).logError("There are no challenges set up in world!");
verify(user).getTranslation("challenges.errors.no-challenges");
verify(user).getTranslation(world, "challenges.errors.no-challenges");
}
/**
@ -196,8 +192,8 @@ public class ChallengesCommandTest {
when(chm.hasAnyChallengeData(any(World.class))).thenReturn(false);
assertFalse(cc.canExecute(user, "challenges", Collections.emptyList()));
verify(addon).logError("There are no challenges set up in world!");
verify(user).getTranslation("challenges.errors.no-challenges-admin", "[command]", "bsb challenges");
verify(user, never()).getTranslation("challenges.errors.no-challenges");
verify(user).getTranslation(world, "challenges.errors.no-challenges-admin", "[command]", "bsb challenges");
verify(user, never()).getTranslation(world, "challenges.errors.no-challenges");
}
/**
@ -209,8 +205,8 @@ public class ChallengesCommandTest {
when(chm.hasAnyChallengeData(any(World.class))).thenReturn(false);
assertFalse(cc.canExecute(user, "challenges", Collections.emptyList()));
verify(addon).logError("There are no challenges set up in world!");
verify(user).getTranslation("challenges.errors.no-challenges-admin", "[command]", "bsb challenges");
verify(user, never()).getTranslation("challenges.errors.no-challenges");
verify(user).getTranslation(world, "challenges.errors.no-challenges-admin", "[command]", "bsb challenges");
verify(user, never()).getTranslation(world, "challenges.errors.no-challenges");
}
/**
@ -223,8 +219,8 @@ public class ChallengesCommandTest {
when(chm.hasAnyChallengeData(any(World.class))).thenReturn(false);
assertFalse(cc.canExecute(user, "challenges", Collections.emptyList()));
verify(addon).logError("There are no challenges set up in world!");
verify(user).getTranslation("challenges.errors.no-challenges-admin", "[command]", "bsb challenges");
verify(user, never()).getTranslation("challenges.errors.no-challenges");
verify(user).getTranslation(world, "challenges.errors.no-challenges-admin", "[command]", "bsb challenges");
verify(user, never()).getTranslation(world, "challenges.errors.no-challenges");
}
/**
@ -234,7 +230,7 @@ public class ChallengesCommandTest {
public void testCanExecuteNoIsland() {
when(im.getIsland(any(), any(User.class))).thenReturn(null);
assertFalse(cc.canExecute(user, "challenges", Collections.emptyList()));
verify(user).getTranslation("general.errors.no-island");
verify(user).getTranslation(world, "general.errors.no-island");
}
/**
@ -246,16 +242,6 @@ public class ChallengesCommandTest {
verify(user, never()).sendMessage(anyString());
}
/**
* Test method for {@link ChallengesPlayerCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testExecuteUserStringListOfStringConsole() {
User console = mock(User.class);
assertFalse(cc.execute(console, "challenges", Collections.emptyList()));
verify(console).sendMessage(eq("commands.help.header"), eq(TextVariables.LABEL), eq("BSkyBlock"));
}
/**
* Test method for {@link ChallengesPlayerCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/

View File

@ -19,7 +19,6 @@ import java.util.Optional;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFactory;
@ -46,11 +45,12 @@ import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.bentobox.util.Util;
import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.managers.ChallengesManager;
import world.bentobox.challenges.config.Settings;
import world.bentobox.challenges.config.SettingsUtils.VisibilityMode;
import world.bentobox.challenges.database.object.Challenge;
import world.bentobox.challenges.managers.ChallengesManager;
import world.bentobox.challenges.tasks.TryToComplete;
import world.bentobox.challenges.utils.Constants;
import world.bentobox.challenges.utils.Utils;
/**
@ -58,7 +58,7 @@ import world.bentobox.challenges.utils.Utils;
*
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class, BentoBox.class, ChatColor.class, Utils.class, TryToComplete.class, Util.class})
@PrepareForTest({ Bukkit.class, BentoBox.class, Utils.class, TryToComplete.class, Util.class })
public class CompleteChallengeCommandTest {
@Mock
@ -149,11 +149,6 @@ public class CompleteChallengeCommandTest {
List<String> nameList = Arrays.asList("world_maker", "world_placer", "bad_challenge_name", "world_breaker");
when(chm.getAllChallengesNames(any())).thenReturn(nameList);
// ChatColor
PowerMockito.mockStatic(ChatColor.class);
when(ChatColor.translateAlternateColorCodes(any(char.class), anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
// Settings
Settings settings = new Settings();
when(addon.getChallengesSettings()).thenReturn(settings);
@ -175,6 +170,8 @@ public class CompleteChallengeCommandTest {
// Util
PowerMockito.mockStatic(Util.class);
when(Util.tabLimit(any(), any())).thenAnswer((Answer<List<String>>) invocation -> (List<String>)invocation.getArgument(0, List.class));
when(Util.translateColorCodes(anyString()))
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
// Command under test
cc = new CompleteChallengeCommand(addon, ic);
@ -207,7 +204,8 @@ public class CompleteChallengeCommandTest {
@Test
public void testExecuteUserStringListOfStringNoArgs() {
assertFalse(cc.execute(user, "complete", Collections.emptyList()));
verify(user).getTranslation(eq("challenges.errors.no-name"));
PowerMockito.verifyStatic(Utils.class);
Utils.sendMessage(user, world, Constants.ERRORS + "no-name");
verify(user).sendMessage(eq("commands.help.header"), eq(TextVariables.LABEL), eq("BSkyBlock"));
}
@ -218,7 +216,8 @@ public class CompleteChallengeCommandTest {
public void testExecuteUserStringListOfStringUnknownChallenge() {
when(chm.getChallenge(anyString())).thenReturn(null);
assertFalse(cc.execute(user, "complete", Collections.singletonList("mychal")));
verify(user).getTranslation(eq("challenges.errors.unknown-challenge"));
PowerMockito.verifyStatic(Utils.class);
Utils.sendMessage(user, world, Constants.ERRORS + "unknown-challenge");
verify(user).sendMessage(eq("commands.help.header"), eq(TextVariables.LABEL), eq("BSkyBlock"));
}
@ -247,7 +246,8 @@ public class CompleteChallengeCommandTest {
@Test
public void testExecuteUserStringListOfStringKnownChallengeSuccessMultipleTimesNoPerm() {
assertTrue(cc.execute(user, "complete", Arrays.asList("mychal", "5")));
verify(user).getTranslation(eq("challenges.error.no-multiple-permission"));
PowerMockito.verifyStatic(Utils.class);
Utils.sendMessage(user, world, Constants.ERRORS + "no-multiple-permission");
}
/**