addon-challenges/src/test/java/world/bentobox/challenges/tasks/TryToCompleteTest.java

706 lines
33 KiB
Java
Raw Normal View History

package world.bentobox.challenges.tasks;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
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;
import static org.mockito.Mockito.when;
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>
2024-03-16 17:13:01 +01:00
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFactory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.util.BoundingBox;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
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>
2024-03-16 17:13:01 +01:00
import org.junit.After;
import org.junit.Before;
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>
2024-03-16 17:13:01 +01:00
import org.junit.Ignore;
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.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.AddonDescription;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.configuration.WorldSettings;
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.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.bentobox.managers.LocalesManager;
import world.bentobox.bentobox.managers.PlaceholdersManager;
import world.bentobox.bentobox.util.Util;
import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.config.Settings;
import world.bentobox.challenges.database.object.Challenge;
import world.bentobox.challenges.database.object.Challenge.ChallengeType;
import world.bentobox.challenges.database.object.ChallengeLevel;
import world.bentobox.challenges.database.object.requirements.InventoryRequirements;
import world.bentobox.challenges.database.object.requirements.IslandRequirements;
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>
2024-03-16 17:13:01 +01:00
import world.bentobox.challenges.managers.ChallengesManager;
import world.bentobox.challenges.tasks.TryToComplete.ChallengeResult;
/**
* @author tastybento
*
*/
@RunWith(PowerMockRunner.class)
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>
2024-03-16 17:13:01 +01:00
@PrepareForTest({ Bukkit.class, BentoBox.class, Util.class })
public class TryToCompleteTest {
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>
2024-03-16 17:13:01 +01:00
// Constants
private static final String GAME_MODE_NAME = "BSkyBlock";
private static final String[] NAMES = { "adam", "ben", "cara", "dave", "ed", "frank", "freddy", "george", "harry",
"ian", "joe" };
private TryToComplete ttc;
private Challenge challenge;
@Mock
private ChallengesAddon addon;
@Mock
private User user;
@Mock
private World world;
private final String topLabel = "island";
private final String permissionPrefix = "perm.";
@Mock
private ChallengesManager cm;
@Mock
private BentoBox plugin;
@Mock
private GameModeAddon gameMode;
@Mock
private AddonsManager am;
@Mock
private IslandsManager im;
@Mock
private Island island;
@Mock
private Player player;
@Mock
private Settings settings;
@Mock
private WorldSettings mySettings;
@Mock
private @Nullable PlayerInventory inv;
private final ItemStack[] contents = {};
@Mock
private BoundingBox bb;
private Set<Player> onlinePlayers;
/**
*/
@Before
public void setUp() {
// Set up plugin
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
when(addon.getPlugin()).thenReturn(plugin);
// World
when(user.getWorld()).thenReturn(world);
when(world.getName()).thenReturn("world");
when(world.getEnvironment()).thenReturn(Environment.NORMAL);
// Addons manager
when(plugin.getAddonsManager()).thenReturn(am);
// One game mode
when(am.getGameModeAddons()).thenReturn(Collections.singletonList(gameMode));
AddonDescription desc2 = new AddonDescription.Builder("bentobox", GAME_MODE_NAME, "1.3").description("test")
.authors("tasty").build();
when(gameMode.getDescription()).thenReturn(desc2);
// Challenge Level
@NonNull
ChallengeLevel level = new ChallengeLevel();
String levelName = GAME_MODE_NAME + "_novice";
level.setUniqueId(levelName);
level.setFriendlyName("Novice");
// Set up challenge
String uuid = UUID.randomUUID().toString();
challenge = new Challenge();
challenge.setUniqueId(GAME_MODE_NAME + "_" + uuid);
challenge.setFriendlyName("name");
challenge.setLevel(GAME_MODE_NAME + "_novice");
challenge.setDescription(Collections.singletonList("A description"));
challenge.setChallengeType(ChallengeType.INVENTORY_TYPE);
challenge.setDeployed(true);
challenge.setIcon(new ItemStack(Material.EMERALD));
challenge.setEnvironment(Collections.singleton(World.Environment.NORMAL));
challenge.setLevel(levelName);
challenge.setRepeatable(true);
challenge.setMaxTimes(10);
InventoryRequirements req = new InventoryRequirements();
challenge.setRequirements(req);
// Util
PowerMockito.mockStatic(Util.class);
when(Util.getWorld(any())).thenReturn(world);
when(Util.prettifyText(anyString())).thenCallRealMethod();
when(Util.stripSpaceAfterColorCodes(anyString())).thenCallRealMethod();
when(Util.translateColorCodes(anyString()))
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
// Island World Manager
IslandWorldManager iwm = mock(IslandWorldManager.class);
when(plugin.getIWM()).thenReturn(iwm);
Optional<GameModeAddon> optionalGameMode = Optional.of(gameMode);
when(iwm.getAddon(any())).thenReturn(optionalGameMode);
when(iwm.getIslandDistance(any())).thenReturn(400);
when(iwm.inWorld(any(World.class))).thenReturn(true);
// Island Manager
when(addon.getIslands()).thenReturn(im);
Optional<Island> opIsland = Optional.of(island);
when(im.getIslandAt(any())).thenReturn(opIsland);
when(im.getIsland(any(), any(User.class))).thenReturn(island);
// Player is on island
when(im.locationIsOnIsland(any(), any())).thenReturn(true);
// Island flags - everything is allowed by default
when(island.isAllowed(any(), any())).thenReturn(true);
// Island
@Nullable
Location loc = mock(Location.class);
when(loc.toString()).thenReturn("center");
when(island.getCenter()).thenReturn(loc);
// Challenges Manager
when(addon.getChallengesManager()).thenReturn(cm);
// All levels unlocked by default
when(cm.isLevelUnlocked(any(), any(), any())).thenReturn(true);
// Player has done this challenge 3 times (default max is 10)
when(cm.getChallengeTimes(any(), any(), any(Challenge.class))).thenReturn(3L);
// User has all perms by default
when(user.hasPermission(anyString())).thenReturn(true);
when(user.getPlayer()).thenReturn(player);
UUID uniqueId = UUID.randomUUID();
when(player.getUniqueId()).thenReturn(uniqueId);
when(user.getUniqueId()).thenReturn(uniqueId);
when(user.getTranslation(anyString()))
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
when(user.getTranslation(anyString(), anyString()))
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
when(user.getTranslationOrNothing(anyString()))
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
when(user.getName()).thenReturn("tastybento");
User.getInstance(player);
@Nullable
Location userLoc = mock(Location.class);
when(userLoc.toString()).thenReturn("location");
when(user.getLocation()).thenReturn(userLoc);
when(user.getInventory()).thenReturn(inv);
when(inv.getContents()).thenReturn(contents);
when(player.getBoundingBox()).thenReturn(bb);
when(bb.clone()).thenReturn(bb);
when(bb.toString()).thenReturn("BoundingBox");
// Locales
User.setPlugin(plugin);
LocalesManager lm = mock(LocalesManager.class);
when(plugin.getLocalesManager()).thenReturn(lm);
when(lm.get(any(), any())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
when(lm.get(any(), any())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
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>
2024-03-16 17:13:01 +01:00
PlaceholdersManager phm = mock(PlaceholdersManager.class);
when(plugin.getPlaceholdersManager()).thenReturn(phm);
when(phm.replacePlaceholders(any(), any()))
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
// Survival by default
when(player.getGameMode()).thenReturn(GameMode.SURVIVAL);
// Addon
when(addon.getChallengesSettings()).thenReturn(settings);
when(settings.isBroadcastMessages()).thenReturn(true);
// Bukkit - online players
Map<UUID, String> online = new HashMap<>();
onlinePlayers = new HashSet<>();
for (String name : NAMES) {
Player p1 = mock(Player.class);
UUID uuid2 = UUID.randomUUID();
when(p1.getUniqueId()).thenReturn(uuid2);
when(p1.getName()).thenReturn(name);
online.put(uuid2, name);
onlinePlayers.add(p1);
}
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getOnlinePlayers()).then((Answer<Set<Player>>) invocation -> Set.of(player));
// World settings
Map<String, Boolean> map = new HashMap<>();
when(mySettings.getWorldFlags()).thenReturn(map);
when(iwm.getWorldSettings(any())).thenReturn(mySettings);
ChallengesAddon.CHALLENGES_WORLD_PROTECTION.setSetting(world, true);
// ItemFactory
ItemFactory itemFactory = mock(ItemFactory.class);
when(Bukkit.getItemFactory()).thenReturn(itemFactory);
}
@After
public void tearDown() throws IOException {
User.clearUsers();
Mockito.framework().clearInlineMocks();
}
/**
* Test method for
* {@link world.bentobox.challenges.tasks.TryToComplete#TryToComplete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String)}.
*/
@Test
public void testTryToCompleteChallengesAddonUserChallengeWorldStringString() {
ttc = new TryToComplete(addon, user, challenge, world, topLabel, permissionPrefix);
verify(addon).getChallengesManager();
}
/**
* Test method for
* {@link world.bentobox.challenges.tasks.TryToComplete#complete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String)}.
*/
@Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringNotDeployed() {
challenge.setDeployed(false);
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation(any(World.class), eq("challenges.errors.not-deployed"));
}
/**
* Test method for
* {@link world.bentobox.challenges.tasks.TryToComplete#complete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String)}.
*/
@Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringWrongWorld() {
challenge.setUniqueId("test");
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation(any(World.class), eq("general.errors.wrong-world"));
}
/**
* Test method for
* {@link world.bentobox.challenges.tasks.TryToComplete#complete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String)}.
*/
@Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringNotOnIsland() {
ChallengesAddon.CHALLENGES_WORLD_PROTECTION.setSetting(world, true);
when(im.locationIsOnIsland(any(Player.class), any(Location.class))).thenReturn(false);
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation(any(World.class), eq("challenges.messages.not-on-island"));
}
/**
* Test method for
* {@link world.bentobox.challenges.tasks.TryToComplete#complete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String)}.
*/
@Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringNotOnIslandButOk() {
ChallengesAddon.CHALLENGES_WORLD_PROTECTION.setSetting(world, false);
when(im.locationIsOnIsland(any(Player.class), any(Location.class))).thenReturn(false);
assertTrue(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation(any(World.class), eq("challenges.messages.you-completed-challenge"), eq("[value]"),
eq("name"));
}
/**
* Test method for {@link world.bentobox.challenges.tasks.TryToComplete#complete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String)}.
*/
@Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringLevelNotUnlocked() {
when(cm.isLevelUnlocked(any(), any(), any())).thenReturn(false);
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
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>
2024-03-16 17:13:01 +01:00
verify(user).getTranslation(any(World.class), eq("challenges.errors.challenge-level-not-available"));
}
2019-11-03 23:12:09 +01:00
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>
2024-03-16 17:13:01 +01:00
/**
* Test method for
* {@link world.bentobox.challenges.tasks.TryToComplete#complete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String)}.
*/
@Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringNotRepeatable() {
challenge.setRepeatable(false);
when(cm.isChallengeComplete(any(User.class), any(), any())).thenReturn(true);
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation(any(World.class), eq("challenges.errors.not-repeatable"));
}
/**
* Test method for
* {@link world.bentobox.challenges.tasks.TryToComplete#complete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String)}.
*/
@Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringNotRepeatableFirstTime() {
challenge.setRepeatable(false);
challenge.setMaxTimes(0);
when(cm.getChallengeTimes(any(), any(), any(Challenge.class))).thenReturn(0L);
assertTrue(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation(any(World.class), eq("challenges.messages.you-completed-challenge"), eq("[value]"),
eq("name"));
}
/**
* Test method for {@link world.bentobox.challenges.tasks.TryToComplete#complete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String)}.
*/
@Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringNoRank() {
when(island.isAllowed(any(), any())).thenReturn(false);
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
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>
2024-03-16 17:13:01 +01:00
verify(user).getTranslation(any(World.class), eq("challenges.messages.no-rank"));
}
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>
2024-03-16 17:13:01 +01:00
/**
* Test method for
* {@link world.bentobox.challenges.tasks.TryToComplete#complete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String, int)}.
*/
@Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringIntZero() {
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix, 0));
verify(user).getTranslation(any(World.class), eq("challenges.errors.not-valid-integer"));
}
/**
* Test method for
* {@link world.bentobox.challenges.tasks.TryToComplete#complete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String, int)}.
*/
@Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringIntNegative() {
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix, -10));
verify(user).getTranslation(any(World.class), eq("challenges.errors.not-valid-integer"));
}
/**
* Test method for
* {@link world.bentobox.challenges.tasks.TryToComplete#complete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String, int)}.
*/
@Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringIntPositiveWrongEnvinonment() {
challenge.setEnvironment(Collections.singleton(Environment.NETHER));
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix, 100));
verify(user).getTranslation(any(World.class), eq("challenges.errors.wrong-environment"));
}
/**
* Test method for
* {@link world.bentobox.challenges.tasks.TryToComplete#complete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String, int)}.
*/
@Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringIntPositiveNoPerm() {
InventoryRequirements req = new InventoryRequirements();
req.setRequiredPermissions(Collections.singleton("perm-you-dont-have"));
when(user.hasPermission(anyString())).thenReturn(false);
challenge.setRequirements(req);
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix, 100));
verify(user).getTranslation(any(World.class), eq("challenges.errors.no-permission"));
}
/**
* Test method for
* {@link world.bentobox.challenges.tasks.TryToComplete#complete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String)}.
*/
@Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringSuccess() {
assertTrue(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation(any(World.class), eq("challenges.messages.you-completed-challenge"), eq("[value]"),
eq("name"));
}
/**
* Test method for
* {@link world.bentobox.challenges.tasks.TryToComplete#complete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String)}.
*/
@Test
@Ignore("Method is too large for JVM")
public void testCompleteChallengesAddonUserChallengeWorldStringStringSuccessSingleReq() {
InventoryRequirements req = new InventoryRequirements();
req.setRequiredItems(Collections.singletonList(new ItemStack(Material.EMERALD_BLOCK)));
challenge.setRequirements(req);
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation(any(World.class), eq("challenges.errors.not-enough-items"), eq("[items]"),
eq("challenges.materials.emerald_block"));
}
/**
* Test method for
* {@link world.bentobox.challenges.tasks.TryToComplete#complete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String)}.
*/
@Test
@Ignore("Too big for JVM")
public void testCompleteChallengesAddonUserChallengeWorldStringStringSuccessMultipleReq() {
InventoryRequirements req = new InventoryRequirements();
ItemStack itemStackMock = mock(ItemStack.class);
when(itemStackMock.getAmount()).thenReturn(3);
when(itemStackMock.getType()).thenReturn(Material.EMERALD_BLOCK);
when(itemStackMock.clone()).thenReturn(itemStackMock);
ItemStack itemStackMock2 = mock(ItemStack.class);
when(itemStackMock2.getType()).thenReturn(Material.ENCHANTED_BOOK);
when(itemStackMock2.getAmount()).thenReturn(10);
when(itemStackMock2.clone()).thenReturn(itemStackMock2);
ItemStack itemStackMock3 = mock(ItemStack.class);
when(itemStackMock3.getType()).thenReturn(Material.EMERALD_BLOCK);
when(itemStackMock3.getAmount()).thenReturn(15);
when(itemStackMock3.clone()).thenReturn(itemStackMock3);
// itemStackMock and 3 are same type
when(itemStackMock3.isSimilar(eq(itemStackMock))).thenReturn(true);
when(itemStackMock.isSimilar(eq(itemStackMock3))).thenReturn(true);
req.setRequiredItems(Arrays.asList(itemStackMock, itemStackMock2));
challenge.setRequirements(req);
ItemStack[] newContents = { itemStackMock3 };
when(inv.getContents()).thenReturn(newContents);
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
// Sufficient emerald blocks
verify(user, never()).getTranslation(any(World.class), eq("challenges.errors.not-enough-items"), eq("[items]"),
eq("challenges.materials.emerald_block"));
// Not enough books
verify(user).getTranslation(any(World.class), eq("challenges.errors.not-enough-items"), eq("[items]"),
eq("challenges.materials.enchanted_book"));
}
/**
* Test method for {@link world.bentobox.challenges.tasks.TryToComplete#complete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String)}.
*/
@Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringSuccessCreative() {
when(player.getGameMode()).thenReturn(GameMode.CREATIVE);
assertTrue(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
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>
2024-03-16 17:13:01 +01:00
// Creative players automatically complete inventory challenges twice - they have infinite inventory
verify(user).getTranslation(world, "challenges.messages.you-repeated-challenge-multiple", "[value]", "name",
"[count]", "2");
}
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>
2024-03-16 17:13:01 +01:00
/**
* Test method for
* {@link world.bentobox.challenges.tasks.TryToComplete#complete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String)}.
*/
@Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringIslandBBTooLarge() {
challenge.setChallengeType(ChallengeType.ISLAND_TYPE);
IslandRequirements req = new IslandRequirements();
req.setSearchRadius(1);
challenge.setRequirements(req);
// Trigger big bounding box error
when(bb.getWidthX()).thenReturn(50000D);
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(addon).logError(
"BoundingBox is larger than SearchRadius. | BoundingBox: BoundingBox | Search Distance: 1 | Location: location | Center: center | Range: 0");
verify(bb).expand(1);
}
/**
* Test method for
* {@link world.bentobox.challenges.tasks.TryToComplete#complete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String)}.
*/
@Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringIslandSuccessNoEntities() {
challenge.setChallengeType(ChallengeType.ISLAND_TYPE);
IslandRequirements req = new IslandRequirements();
req.setSearchRadius(1);
challenge.setRequirements(req);
assertTrue(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation(any(World.class), eq("challenges.messages.you-completed-challenge"), eq("[value]"),
eq("name"));
}
/**
* Test method for
* {@link world.bentobox.challenges.tasks.TryToComplete#complete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String)}.
*/
@Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringIslandFailEntities() {
challenge.setChallengeType(ChallengeType.ISLAND_TYPE);
IslandRequirements req = new IslandRequirements();
Map<EntityType, Integer> requiredEntities = Collections.singletonMap(EntityType.GHAST, 3);
req.setRequiredEntities(requiredEntities);
req.setSearchRadius(1);
challenge.setRequirements(req);
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation(any(World.class), eq("challenges.errors.you-still-need"), eq("[amount]"), eq("3"),
eq("[item]"), eq("challenges.entities.ghast.name"));
}
/**
* Test method for
* {@link world.bentobox.challenges.tasks.TryToComplete#complete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String)}.
*/
@Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringIslandFailMultipleEntities() {
challenge.setChallengeType(ChallengeType.ISLAND_TYPE);
IslandRequirements req = new IslandRequirements();
Map<EntityType, Integer> requiredEntities = new HashMap<>();
requiredEntities.put(EntityType.GHAST, 3);
requiredEntities.put(EntityType.CHICKEN, 5);
requiredEntities.put(EntityType.PUFFERFISH, 1);
req.setRequiredEntities(requiredEntities);
req.setSearchRadius(1);
challenge.setRequirements(req);
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation(any(World.class), eq("challenges.errors.you-still-need"), eq("[amount]"), eq("3"),
eq("[item]"), eq("challenges.entities.ghast.name"));
verify(user).getTranslation(any(World.class), eq("challenges.errors.you-still-need"), eq("[amount]"), eq("1"),
eq("[item]"), eq("challenges.entities.pufferfish.name"));
verify(user).getTranslation(any(World.class), eq("challenges.errors.you-still-need"), eq("[amount]"), eq("5"),
eq("[item]"), eq("challenges.entities.chicken.name"));
}
/**
* Test method for
* {@link world.bentobox.challenges.tasks.TryToComplete#complete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String)}.
*/
@Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringIslandFailPartialMultipleEntities() {
challenge.setChallengeType(ChallengeType.ISLAND_TYPE);
IslandRequirements req = new IslandRequirements();
Map<EntityType, Integer> requiredEntities = new HashMap<>();
requiredEntities.put(EntityType.GHAST, 3);
requiredEntities.put(EntityType.CHICKEN, 5);
requiredEntities.put(EntityType.PUFFERFISH, 1);
req.setRequiredEntities(requiredEntities);
req.setSearchRadius(1);
challenge.setRequirements(req);
Entity ent = mock(Entity.class);
when(ent.getType()).thenReturn(EntityType.PUFFERFISH);
Location loc = mock(Location.class);
when(ent.getLocation()).thenReturn(loc);
List<Entity> list = Collections.singletonList(ent);
when(world.getNearbyEntities(any(BoundingBox.class))).thenReturn(list);
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation(any(World.class), eq("challenges.errors.you-still-need"), eq("[amount]"), eq("3"),
eq("[item]"), eq("challenges.entities.ghast.name"));
verify(user, never()).getTranslation(any(World.class), eq("challenges.errors.you-still-need"), eq("[amount]"),
eq("1"), eq("[item]"), eq("challenges.entities.pufferfish.name"));
verify(user).getTranslation(any(World.class), eq("challenges.errors.you-still-need"), eq("[amount]"), eq("5"),
eq("[item]"), eq("challenges.entities.chicken.name"));
}
/**
* Test method for
* {@link world.bentobox.challenges.tasks.TryToComplete#complete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String)}.
*/
@Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringIslandSuccess() {
challenge.setChallengeType(ChallengeType.ISLAND_TYPE);
IslandRequirements req = new IslandRequirements();
Map<EntityType, Integer> requiredEntities = new HashMap<>();
requiredEntities.put(EntityType.PUFFERFISH, 1);
req.setRequiredEntities(requiredEntities);
req.setSearchRadius(1);
challenge.setRequirements(req);
Entity ent = mock(Entity.class);
when(ent.getType()).thenReturn(EntityType.PUFFERFISH);
Location loc = mock(Location.class);
when(ent.getLocation()).thenReturn(loc);
List<Entity> list = Collections.singletonList(ent);
when(world.getNearbyEntities(any(BoundingBox.class))).thenReturn(list);
assertTrue(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation(any(World.class), eq("challenges.messages.you-completed-challenge"), eq("[value]"),
eq("name"));
}
/**
* Test method for
* {@link world.bentobox.challenges.tasks.TryToComplete#complete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String)}.
*/
@Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringIslandPlayerInOtherEnvironment() {
challenge.setEnvironment(Collections.singleton(Environment.NETHER));
World netherWorld = mock(World.class);
when(user.getWorld()).thenReturn(netherWorld);
when(netherWorld.getName()).thenReturn("world_nether");
when(netherWorld.getEnvironment()).thenReturn(Environment.NETHER);
challenge.setChallengeType(ChallengeType.ISLAND_TYPE);
IslandRequirements req = new IslandRequirements();
Map<EntityType, Integer> requiredEntities = new HashMap<>();
requiredEntities.put(EntityType.PUFFERFISH, 1);
req.setRequiredEntities(requiredEntities);
req.setSearchRadius(1);
challenge.setRequirements(req);
Entity ent = mock(Entity.class);
when(ent.getType()).thenReturn(EntityType.PUFFERFISH);
Location loc = mock(Location.class);
when(ent.getLocation()).thenReturn(loc);
List<Entity> list = Collections.singletonList(ent);
when(world.getNearbyEntities(any(BoundingBox.class))).thenReturn(list);
when(netherWorld.getNearbyEntities(any(BoundingBox.class))).thenReturn(Collections.emptyList());
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation(any(World.class), eq("challenges.errors.you-still-need"), eq("[amount]"), eq("1"),
eq("[item]"), eq("challenges.entities.pufferfish.name"));
}
/**
* Test method for
* {@link world.bentobox.challenges.tasks.TryToComplete#complete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String, int)}.
*/
@Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringIntMultipleTimesPositiveSuccess() {
// Try to complete 10 times. Already done 3 times, and max is 10, so it should
// be only done 7 times
assertTrue(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix, 10));
verify(user).getTranslation(any(World.class), eq("challenges.messages.you-repeated-challenge-multiple"),
eq("[value]"), eq("name"), eq("[count]"), eq("7"));
}
/**
* Test method for
* {@link world.bentobox.challenges.tasks.TryToComplete#build(int)}.
*/
@Test
public void testBuild() {
this.testTryToCompleteChallengesAddonUserChallengeWorldStringString();
ChallengeResult result = this.ttc.build(10);
assertTrue(result.isMeetsRequirements());
}
/**
* Test method for
* {@link world.bentobox.challenges.tasks.TryToComplete#removeItems(java.util.List, int)}.
*/
@Test
public void testRemoveItemsNothing() {
this.testTryToCompleteChallengesAddonUserChallengeWorldStringString();
assertTrue(ttc.removeItems(Collections.emptyList(), 1).isEmpty());
}
}