Compare commits

...

70 Commits

Author SHA1 Message Date
tastybento
2843a8e3ed Fix YAML #359 2024-09-07 18:05:56 -07:00
tastybento
d8fb2de177
Merge branch 'master' into develop 2024-09-03 15:01:18 -07:00
gitlocalize-app[bot]
9cf7107c04
Spanish translation (#357)
* Translate es.yml via GitLocalize

* Translate es.yml via GitLocalize

* Translate es.yml via GitLocalize

---------

Co-authored-by: Christhian Arias <droidenauta@gmail.com>
Co-authored-by: tastybento <tastybento@wasteofplastic.com>
Co-authored-by: mt-gitlocalize <mt@gitlocalize.com>
2024-09-03 14:50:04 -07:00
gitlocalize-app[bot]
eacf76e8a3
Czech - needs placeholder fixing (#356)
* Translate cs.yml via GitLocalize

* Translate cs.yml via GitLocalize

* Translate cs.yml via GitLocalize

* Update cs.yml

Fix placeholders

---------

Co-authored-by: mt-gitlocalize <mt@gitlocalize.com>
Co-authored-by: tastybento <tastybento@wasteofplastic.com>
Co-authored-by: Lishak <testrgamess@gmail.com>
Co-authored-by: tastybento <tastybento@users.noreply.github.com>
2024-09-03 14:30:10 -07:00
gitlocalize-app[bot]
20b71d7cf3
Translate fr.yml via GitLocalize (#355)
Co-authored-by: tastybento <tastybento@wasteofplastic.com>
2024-09-03 14:04:50 -07:00
tastybento
e4319b2fb7 Update Java version for Gihub Action 2024-08-21 08:21:22 -07:00
gitlocalize-app[bot]
59edce4d0d
German translation (#353)
* Translate de.yml via GitLocalize

* Translate de.yml via GitLocalize

---------

Co-authored-by: mt-gitlocalize <mt@gitlocalize.com>
Co-authored-by: tastybento <tastybento@wasteofplastic.com>
2024-08-21 07:59:43 -07:00
tastybento
7ddf865430 Give some info on where to find the files if a connection to Github
is not possible.
2024-08-10 10:32:10 -07:00
tastybento
f811c7ca1d Update to latest BentoBox API and Shade plugin versions 2024-08-10 10:26:33 -07:00
tastybento
253428b223 Version 1.3.2
Java version 21
2024-08-10 10:18:30 -07:00
tastybento
4438c36b61
Release 1.3.1 (#351)
* 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

* Chinese translation (#343)

* Translate zh-CN.yml via GitLocalize

* Translate zh-CN.yml via GitLocalize

* Translate zh-CN.yml via GitLocalize

* Translate zh-CN.yml via GitLocalize

* Translate zh-CN.yml via GitLocalize

---------

Co-authored-by: Jeansou <bettertreebot@gmail.com>
Co-authored-by: CuteLittleSky <2173204318@qq.com>
Co-authored-by: RUYSUE <ruysue@outlook.com>
Co-authored-by: Clexus <528373858@qq.com>
Co-authored-by: mt-gitlocalize <mt@gitlocalize.com>

* French translation (#342)

* Translate fr.yml via GitLocalize

* Translate fr.yml via GitLocalize

* Translate fr.yml via GitLocalize

---------

Co-authored-by: Aksel <afgameytb@gmail.com>
Co-authored-by: organizatsiya <organizatsiya.wildguns@gmail.com>
Co-authored-by: mt-gitlocalize <mt@gitlocalize.com>

* Spanish translation (#341)

* Translate es.yml via GitLocalize

* Translate es.yml via GitLocalize

* Translate es.yml via GitLocalize

---------

Co-authored-by: sergyops <lince885@gmail.com>
Co-authored-by: mt-gitlocalize <mt@gitlocalize.com>
Co-authored-by: Amfetas <artodetodoo@gmail.com>

* Fixes 345 (#346)

Use the object's name if it already has a display name

* return the pladdon that was generated.

* Version 1.3.1

* Translate zh-CN.yml via GitLocalize (#348)

Co-authored-by: RUYSUE <ruysue@outlook.com>

* French translation (#347)

* Translate fr.yml via GitLocalize

* Translate fr.yml via GitLocalize

* Translate fr.yml via GitLocalize

* Translate fr.yml via GitLocalize

---------

Co-authored-by: gitlocalize-app[bot] <55277160+gitlocalize-app[bot]@users.noreply.github.com>
Co-authored-by: Aksel <afgameytb@gmail.com>
Co-authored-by: organizatsiya <organizatsiya.wildguns@gmail.com>
Co-authored-by: mt-gitlocalize <mt@gitlocalize.com>

---------

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>
Co-authored-by: Jeansou <bettertreebot@gmail.com>
Co-authored-by: CuteLittleSky <2173204318@qq.com>
Co-authored-by: RUYSUE <ruysue@outlook.com>
Co-authored-by: Clexus <528373858@qq.com>
Co-authored-by: Aksel <afgameytb@gmail.com>
Co-authored-by: organizatsiya <organizatsiya.wildguns@gmail.com>
Co-authored-by: sergyops <lince885@gmail.com>
Co-authored-by: Amfetas <artodetodoo@gmail.com>
2024-08-10 10:08:40 -07:00
tastybento
30d191f94e
Merge branch 'master' into develop 2024-07-28 15:05:05 -07:00
gitlocalize-app[bot]
e265a58be6
French translation (#347)
* Translate fr.yml via GitLocalize

* Translate fr.yml via GitLocalize

* Translate fr.yml via GitLocalize

* Translate fr.yml via GitLocalize

---------

Co-authored-by: gitlocalize-app[bot] <55277160+gitlocalize-app[bot]@users.noreply.github.com>
Co-authored-by: Aksel <afgameytb@gmail.com>
Co-authored-by: organizatsiya <organizatsiya.wildguns@gmail.com>
Co-authored-by: mt-gitlocalize <mt@gitlocalize.com>
2024-07-28 15:04:10 -07:00
gitlocalize-app[bot]
d69f084ba6
Translate zh-CN.yml via GitLocalize (#348)
Co-authored-by: RUYSUE <ruysue@outlook.com>
2024-07-28 15:03:53 -07:00
tastybento
adb7d1eb47 Version 1.3.1 2024-07-28 15:02:29 -07:00
tastybento
7441b7717f return the pladdon that was generated. 2024-07-02 09:31:01 -07:00
tastybento
e424560c37
Fixes 345 (#346)
Use the object's name if it already has a display name
2024-06-15 06:33:23 -07:00
gitlocalize-app[bot]
7fb20e74f3
Spanish translation (#341)
* Translate es.yml via GitLocalize

* Translate es.yml via GitLocalize

* Translate es.yml via GitLocalize

---------

Co-authored-by: sergyops <lince885@gmail.com>
Co-authored-by: mt-gitlocalize <mt@gitlocalize.com>
Co-authored-by: Amfetas <artodetodoo@gmail.com>
2024-06-08 10:21:45 -07:00
gitlocalize-app[bot]
1916f3f267
French translation (#342)
* Translate fr.yml via GitLocalize

* Translate fr.yml via GitLocalize

* Translate fr.yml via GitLocalize

---------

Co-authored-by: Aksel <afgameytb@gmail.com>
Co-authored-by: organizatsiya <organizatsiya.wildguns@gmail.com>
Co-authored-by: mt-gitlocalize <mt@gitlocalize.com>
2024-06-08 10:21:33 -07:00
gitlocalize-app[bot]
78cfa51641
Chinese translation (#343)
* Translate zh-CN.yml via GitLocalize

* Translate zh-CN.yml via GitLocalize

* Translate zh-CN.yml via GitLocalize

* Translate zh-CN.yml via GitLocalize

* Translate zh-CN.yml via GitLocalize

---------

Co-authored-by: Jeansou <bettertreebot@gmail.com>
Co-authored-by: CuteLittleSky <2173204318@qq.com>
Co-authored-by: RUYSUE <ruysue@outlook.com>
Co-authored-by: Clexus <528373858@qq.com>
Co-authored-by: mt-gitlocalize <mt@gitlocalize.com>
2024-06-08 10:21:19 -07:00
tastybento
7c1deb9384
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 09:13:01 -07:00
tastybento
ec6b950304 Fix tests. 2024-03-10 18:44:57 -07:00
tastybento
d0588303c0 Reference latest BentoBox release version 2024-03-10 16:11:22 -07:00
BONNe
7483ff0e0f
Update en-US.yml 2024-02-11 17:13:24 +02:00
tastybento
005d49a756 Update TIPPED_ARROW to latest API in panels 2024-01-21 09:02:19 -08:00
tastybento
fe9e63f1c7 Fix tests for creative user inventory challenge completion 2024-01-13 08:23:41 -08:00
BONNe
8a8124f36e 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
2024-01-11 09:40:20 +02:00
BONNe
74cd97fb80 Upgrade PanelUtils to 1.2.0 2024-01-03 14:11:22 +02:00
BONNe
c351225e9a
Fixes enchanted book meta not displayed (#328)
Apparently in Spigot EnchantmentStorage has a map that is not used for enchantment storing. Nice.

Fixes #327
2023-12-20 11:06:16 +02:00
tastybento
a90d17d70d
Update README.md 2023-11-26 19:06:04 -08:00
tastybento
b6bd3d3a2e
Update README.md 2023-11-26 19:04:43 -08:00
tastybento
b82defe3b5 Show money as formatted. Addresses #324 2023-11-26 18:52:39 -08:00
gitlocalize-app[bot]
a6a3a3e12d
Translate uk.yml via GitLocalize (#325)
Co-authored-by: GIGABAIT <freebitcoin93@gmail.com>
Co-authored-by: tastybento <tastybento@users.noreply.github.com>
2023-11-26 10:09:27 -08:00
gitlocalize-app[bot]
48f388c7f6
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>
2023-11-26 10:00:06 -08:00
tastybento
56d7eb4259 Update to BentoBox 2.0.0
Had to ignore some tests because PowerMockito can't mock them for some
reason.
2023-11-12 13:23:22 -08:00
tastybento
34d280d5bf
Update pom.xml 2023-07-10 21:41:20 -07:00
tastybento
9e34910f07 Update Jacoco 2023-07-10 21:22:34 -07:00
tastybento
1fdcfdd7ef Remove offending test. Was not that useful anyway. 2023-07-08 11:42:52 -07:00
tastybento
1759ef7123 Try adding maven dependency to fix test issue 2023-07-08 11:37:45 -07:00
tastybento
bba54aa08b Remove duplicate plugin reference in POM 2023-07-08 11:28:40 -07:00
tastybento
ebd0b46656 Update POM versions to use latest API 2023-07-08 10:50:47 -07:00
gitlocalize-app[bot]
98052d1797
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>
2023-07-08 10:43:57 -07:00
BONNe
d74cfbfe96 Merge remote-tracking branch 'origin/develop' into develop 2023-07-03 12:36:59 +03:00
BONNe
3b36f38b7c Fixes the admin GUI crash.
Add shade plugin that was missing for dependencies.
2023-07-03 12:35:55 +03:00
tastybento
125a3249ac Add required distribution 2023-06-24 13:52:45 -07:00
tastybento
9da197de21 Update Github Action build script 2023-06-24 13:02:26 -07:00
tastybento
480ffd8eb4 Fixed ChallengesManagerTest 2023-06-04 10:49:16 -07:00
tastybento
ddebdf0e62 Fixed ChallengesCommandTest 2023-06-04 10:41:18 -07:00
tastybento
82ba144038 Fixed CompleteChallengeCommandTest 2023-06-04 10:38:45 -07:00
tastybento
53f0a0cb37 Fixed TryToComplete test class 2023-06-04 10:31:52 -07:00
BONNe
550e348428 Fixes a crash with written/writable books.
The issue was with generating description message for written books without title or author.

Fixes #318
2023-04-24 15:01:56 +03:00
BONNe
01bd7b82bb
Remove dependency to org.apache.commons
Replace org.apache.commons.lang.ArrayUtils to a default Java implementation.
2023-04-13 18:56:17 +03:00
BONNe
a608c8b765
Create plugin.yml (#316)
* Create plugin.yml

* Update pom.xml

* Update ChallengesPladdon.java
2023-04-08 18:30:40 +03:00
BONNe
5ab4237df4 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
2023-04-02 14:47:10 +03:00
BONNe
de7172ef75 Update ChallengesManagerTest methods with world parameter. 2023-03-31 11:26:54 +03:00
BONNe
9953459e50 Add support for gamemode-specific translations.
This was a request from Floris
2023-03-31 11:12:08 +03:00
tastybento
e0377fd352 Updated pladdon annotations 2023-03-25 10:05:36 -07:00
tastybento
09adbde004
Update build.yml
Java 17 for Surefire
2023-02-10 15:36:55 -08:00
tastybento
84a38f4d8c Updated Jacoco POM section 2023-02-10 10:50:41 -08:00
tastybento
1b585a22c8
Add ${argLine} to get jacoco coverage 2023-02-09 15:14:35 -08:00
JamesMCL44
9ed92733c7
Add locale of Chinese-Hong Kong (zh-HK) (#313)
Addition of locale updated to latest version
2023-02-05 18:36:33 +02:00
BONNe
431aaf46fc Add requirement-not-met-material and requirement-not-met-entity to display statistic required item on error. 2023-02-02 23:29:06 +02:00
BONNe
ee8eaf8e84 Fixes a crash that prevented STATISTICS entity and material/item challenges to be completed. 2023-02-02 23:24:22 +02:00
BONNe
5ba7c681de Merge remote-tracking branch 'origin/develop' into develop 2023-01-30 23:54:36 +02:00
BONNe
468232cabc Fixes a regex bug that replaced every [player] char instead of whole word. 2023-01-30 23:54:29 +02:00
EpicMo
1faf3b55be
Edit some unfit translation (#312)
Edit some unfit translation
2023-01-20 04:44:29 +02:00
BONNe
0d69459738 Merge remote-tracking branch 'origin/develop' into develop 2023-01-19 12:47:29 +02:00
BONNe
e94d2349c3 Init 1.2.0 version 2023-01-19 12:47:21 +02:00
BONNe
8b81101ef0 Fixes #311 localization errors in zn-CN.
Original translation author translated `[]` placeholders which broke locale
2023-01-19 12:47:20 +02:00
BONNe
1da624002d
Init 1.2.0 version 2023-01-05 21:49:39 +02:00
23 changed files with 8214 additions and 4965 deletions

View File

@ -11,21 +11,22 @@ jobs:
name: Build name: Build
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
with: with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 17 - name: Set up JDK 21
uses: actions/setup-java@v1 uses: actions/setup-java@v3
with: with:
java-version: 17 distribution: 'adopt'
java-version: 21
- name: Cache SonarCloud packages - name: Cache SonarCloud packages
uses: actions/cache@v1 uses: actions/cache@v3
with: with:
path: ~/.sonar/cache path: ~/.sonar/cache
key: ${{ runner.os }}-sonar key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages - name: Cache Maven packages
uses: actions/cache@v1 uses: actions/cache@v3
with: with:
path: ~/.m2 path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} 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) [![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/) [![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 ![Challenges](https://github.com/BentoBoxWorld/Challenges/assets/4407265/9b3c5278-3a9d-45f2-9ee1-2c1fc1199a8d)
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.
## How to use ## How to use
@ -27,21 +12,32 @@ Unfortunately, default challenges come only in English translation. But with ver
2. Restart the server 2. Restart the server
3. Edit the config.yml how you want. 3. Edit the config.yml how you want.
4. Restart the server 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 run time only Admin GUI will be accessible. 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, which importing also are available via Admin GUI. Default challenges contains 5 levels and 57 challenges. Admins can create their own challenges or import some default challenges. 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. 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 ## Compatibility
- [x] BentoBox - 1.14 versions - [x] BentoBok
- [x] BSkyBlock - [x] BSkyBlock
- [x] AcidIsland - [x] AcidIsland
- [x] SkyGrid - [x] SkyGrid
- [x] CaveBlock - [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/).

85
pom.xml
View File

@ -32,19 +32,19 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>17</java.version> <java.version>21</java.version>
<powermock.version>2.0.9</powermock.version> <powermock.version>2.0.9</powermock.version>
<!-- More visible way how to change dependency versions --> <!-- More visible way how to change dependency versions -->
<spigot.version>1.17.1-R0.1-SNAPSHOT</spigot.version> <spigot.version>1.21-R0.1-SNAPSHOT</spigot.version>
<spigot-annotations.version>1.2.3-SNAPSHOT</spigot-annotations.version> <spigot-annotations.version>1.2.3-SNAPSHOT</spigot-annotations.version>
<bentobox.version>1.21.0</bentobox.version> <bentobox.version>2.4.2</bentobox.version>
<level.version>2.6.3</level.version> <level.version>2.6.3</level.version>
<vault.version>1.7</vault.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 variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision> <revision>${build.version}-SNAPSHOT</revision>
<!-- This allows to change between versions and snapshots. --> <!-- This allows to change between versions and snapshots. -->
<build.version>1.2.0</build.version> <build.version>1.3.2</build.version>
<build.number>-LOCAL</build.number> <build.number>-LOCAL</build.number>
<!-- Sonar Cloud --> <!-- Sonar Cloud -->
<sonar.projectKey>BentoBoxWorld_Challenges</sonar.projectKey> <sonar.projectKey>BentoBoxWorld_Challenges</sonar.projectKey>
@ -120,6 +120,12 @@
</repositories> </repositories>
<dependencies> <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 --> <!-- Spigot API -->
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
@ -187,6 +193,11 @@
<version>1.5.21</version> <version>1.5.21</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
@ -217,6 +228,38 @@
</resource> </resource>
</resources> </resources>
<plugins> <plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.0</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> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId> <artifactId>maven-clean-plugin</artifactId>
@ -325,40 +368,15 @@
<plugin> <plugin>
<groupId>org.jacoco</groupId> <groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId> <artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</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>
</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>
<configuration> <configuration>
<append>true</append> <append>true</append>
<excludes> <excludes>
<!-- This is required to prevent Jacoco from adding <!-- This is required to prevent Jacoco from adding
synthetic fields to a JavaBean class (causes errors in testing) --> synthetic fields to a JavaBean class (causes errors in testing) -->
<exclude>**/*Names*</exclude> <exclude>**/*Names*</exclude>
<!-- Prevents the Material is too large to mock error -->
<exclude>org/bukkit/Material*</exclude>
</excludes> </excludes>
</configuration> </configuration>
<executions> <executions>
@ -378,6 +396,7 @@
<format>XML</format> <format>XML</format>
</formats> </formats>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>

View File

@ -15,9 +15,13 @@ import world.bentobox.bentobox.api.addons.Pladdon;
*/ */
public class ChallengesPladdon extends Pladdon public class ChallengesPladdon extends Pladdon
{ {
private Addon addon;
@Override @Override
public Addon getAddon() public Addon getAddon()
{ {
return new ChallengesAddon(); if (addon == null) {
addon = new ChallengesAddon();
}
return addon;
} }
} }

View File

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

View File

@ -7,11 +7,19 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Set; 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.enchantments.Enchantment;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack; 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.PotionData;
import org.bukkit.potion.PotionType; import org.bukkit.potion.PotionType;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
@ -558,6 +566,13 @@ public class Utils
{ {
return ""; return "";
} }
// Return the display name if it already has one
if (object.hasItemMeta()) {
ItemMeta im = object.getItemMeta();
if (im.hasDisplayName()) {
return im.getDisplayName();
}
}
// Find addon structure with: // Find addon structure with:
// [addon]: // [addon]:
@ -823,7 +838,7 @@ public class Utils
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
enchantmentMeta.getEnchants().forEach((enchantment, level) -> { enchantmentMeta.getStoredEnchants().forEach((enchantment, level) -> {
builder.append("\n"); builder.append("\n");
builder.append(user.getTranslationOrNothing(Constants.ITEM_STACKS + "meta.enchant-meta", builder.append(user.getTranslationOrNothing(Constants.ITEM_STACKS + "meta.enchant-meta",
"[type]", prettifyObject(enchantment, user), "[type]", prettifyObject(enchantment, user),
@ -868,8 +883,8 @@ public class Utils
final String metaReference = Constants.ITEM_STACKS + "meta."; final String metaReference = Constants.ITEM_STACKS + "meta.";
String meta = user.getTranslationOrNothing(metaReference + "book-meta", String meta = user.getTranslationOrNothing(metaReference + "book-meta",
"[title]", bookMeta.getTitle(), "[title]", bookMeta.hasTitle() ? bookMeta.getTitle() : "",
"[author]", bookMeta.getAuthor()); "[author]", bookMeta.hasAuthor() ? bookMeta.getAuthor() : "");
return user.getTranslationOrNothing(Constants.ITEM_STACKS + "generic", return user.getTranslationOrNothing(Constants.ITEM_STACKS + "generic",
"[type]", prettifyObject(itemType, user), "[type]", prettifyObject(itemType, user),

View File

@ -151,6 +151,11 @@ public class WebManager
if (this.plugin.getSettings().isLogGithubDownloadData()) if (this.plugin.getSettings().isLogGithubDownloadData())
{ {
this.plugin.log("Could not connect to GitHub."); this.plugin.log("Could not connect to GitHub.");
this.plugin.log(
"JSON files can be found at https://github.com/BentoBoxWorld/weblink/tree/master/challenges/library");
user.sendRawMessage("Could not connect to GitHub.");
user.sendRawMessage(
"JSON files can be found at https://github.com/BentoBoxWorld/weblink/tree/master/challenges/library");
} }
} }
catch (Exception e) catch (Exception e)

File diff suppressed because it is too large Load Diff

View File

@ -649,6 +649,12 @@ challenges:
visible: Zeigen Sie sichtbare Herausforderungen visible: Zeigen Sie sichtbare Herausforderungen
hidden: Alle Herausforderungen anzeigen hidden: Alle Herausforderungen anzeigen
toggleable: Umschalten zulassen toggleable: Umschalten zulassen
include_undeployed:
name: "&f&l Nicht bereitgestellte Herausforderungen einschließen"
description: "&7 Gibt an, ob nicht bereitgestellte \n&7 Herausforderungen
\n&7 für den Abschluss von Level \n&7 angerechnet werden sollen."
enabled: "&2 Aktiviert"
disabled: "&c Deaktiviert"
download: download:
name: "&f&l Bibliotheken herunterladen" name: "&f&l Bibliotheken herunterladen"
description: |- description: |-
@ -851,7 +857,7 @@ challenges:
environment-single: "&7 Limitiert auf [environment]" environment-single: "&7 Limitiert auf [environment]"
environment-title: "&7 Limitiert auf:" environment-title: "&7 Limitiert auf:"
environment-list: " &7 - &e [environment]" environment-list: " &7 - &e [environment]"
permission-single: "&c Requires [permissions] permission" permission-single: "&c Erfordert die Berechtigung [permission]"
permissions-title: "&c Erfordert Berechtigungen:" permissions-title: "&c Erfordert Berechtigungen:"
permissions-list: " &c - [permission]" permissions-list: " &c - [permission]"
island: island:
@ -998,9 +1004,9 @@ challenges:
write-reward-commands: "&e Bitte geben Sie pro Zeile im Chat einen neuen Belohnungsbefehl write-reward-commands: "&e Bitte geben Sie pro Zeile im Chat einen neuen Belohnungsbefehl
ein und beenden Sie den Chat in einer eigenen Zeile." ein und beenden Sie den Chat in einer eigenen Zeile."
reward-commands-changed: "&a Erfolg, die Belohnungsbefehle wurden aktualisiert." reward-commands-changed: "&a Erfolg, die Belohnungsbefehle wurden aktualisiert."
write-repeat-reward-commands: "&e Bitte geben Sie pro Zeile im Chat einen neuen write-repeat-reward-commands: "&e Geben Sie bitte pro Zeile im Chat einen neuen
Belohnungswiederholungsbefehl ein und beenden Sie den Chat in einer eigenen Befehl zur Wiederholung der Belohnung ein und klicken Sie zum Beenden auf „Beenden“
Zeile." in einer eigenen Zeile."
repeat-reward-commands-changed: "&a Erfolg, die Wiederholungsbelohnungsbefehle repeat-reward-commands-changed: "&a Erfolg, die Wiederholungsbelohnungsbefehle
wurden aktualisiert." wurden aktualisiert."
challenge-removed: "&a Herausforderungen [challende] für [gamemode] wird aus der challenge-removed: "&a Herausforderungen [challende] für [gamemode] wird aus der
@ -1098,6 +1104,12 @@ challenges:
not-hooked: "&c Challenges Addon konnte keinen GameMode finden." not-hooked: "&c Challenges Addon konnte keinen GameMode finden."
timeout: "&c Diese Abfrage erfordert eine Wartezeit von [timeout] zwischen den timeout: "&c Diese Abfrage erfordert eine Wartezeit von [timeout] zwischen den
Vervollständigungen. Sie müssen [wait-time] warten, bis Sie es erneut abschließen." Vervollständigungen. Sie müssen [wait-time] warten, bis Sie es erneut abschließen."
requirement-not-met: "&c Für diese Herausforderung muss [statistic] [number] haben.
Sie haben nur [value]."
requirement-not-met-entity: "&c Für diese Herausforderung muss [statistic] [entity]
über [number] verfügen. Sie haben nur [value]."
requirement-not-met-material: "&c Diese Herausforderung erfordert, dass [statistic]
[material] [number] hat. Sie haben nur [value]."
protection: protection:
flags: flags:
CHALLENGES_ISLAND_PROTECTION: CHALLENGES_ISLAND_PROTECTION:

View File

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

File diff suppressed because it is too large Load Diff

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

View File

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

View File

@ -82,7 +82,7 @@ public class ChallengesManagerTest {
// Mocks // Mocks
@Mock @Mock
private ChallengesAddon addon; private ChallengesAddon addon;
@Mock
private Settings settings; private Settings settings;
@Mock @Mock
private IslandWorldManager iwm; private IslandWorldManager iwm;
@ -134,9 +134,11 @@ public class ChallengesManagerTest {
when(s.getDatabaseType()).thenReturn(DatabaseType.JSON); when(s.getDatabaseType()).thenReturn(DatabaseType.JSON);
// Addon Settings // Addon Settings
settings = new Settings();
when(addon.getChallengesSettings()).thenReturn(settings); when(addon.getChallengesSettings()).thenReturn(settings);
when(settings.isStoreHistory()).thenReturn(true); settings.setStoreAsIslandData(false);
when(settings.getLifeSpan()).thenReturn(10); settings.setStoreHistory(true);
settings.setLifeSpan(10);
// Database // Database
database = new File("database"); database = new File("database");
@ -264,7 +266,7 @@ public class ChallengesManagerTest {
assertTrue(cm.loadChallenge(challenge, world, false, user, true)); assertTrue(cm.loadChallenge(challenge, world, false, user, true));
// load twice - no overwrite, not silent // load twice - no overwrite, not silent
assertFalse(cm.loadChallenge(challenge, world, false, user, false)); 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)); assertTrue(cm.loadChallenge(challenge, world, false, user, true));
// overwrite // overwrite
assertTrue(cm.loadChallenge(challenge, world, true, user, true)); 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)); assertTrue(cm.loadChallenge(challenge, world, false, user, true));
// overwrite not silent // overwrite not silent
assertTrue(cm.loadChallenge(challenge, world, true, user, false)); 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)); assertTrue(cm.loadLevel(level, world, false, user, true));
// load twice - no overwrite, not silent // load twice - no overwrite, not silent
assertFalse(cm.loadLevel(level, world, false, user, false)); 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)); assertTrue(cm.loadLevel(level, world, false, user, true));
// overwrite // overwrite
assertTrue(cm.loadLevel(level, world, true, user, true)); 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)); assertTrue(cm.loadLevel(level, world, false, user, true));
// overwrite not silent // overwrite not silent
assertTrue(cm.loadLevel(level, world, true, user, false)); 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.any;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@ -17,7 +16,6 @@ import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFactory; 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.addons.GameModeAddon;
import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.configuration.WorldSettings; 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.api.user.User;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.CommandsManager; 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.managers.IslandsManager;
import world.bentobox.bentobox.util.Util; import world.bentobox.bentobox.util.Util;
import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.managers.ChallengesManager;
import world.bentobox.challenges.config.Settings; import world.bentobox.challenges.config.Settings;
import world.bentobox.challenges.config.SettingsUtils.VisibilityMode; import world.bentobox.challenges.config.SettingsUtils.VisibilityMode;
import world.bentobox.challenges.managers.ChallengesManager;
/** /**
* @author tastybento * @author tastybento
* *
*/ */
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class, BentoBox.class, ChatColor.class, Util.class}) @PrepareForTest({ Bukkit.class, BentoBox.class, Util.class })
public class ChallengesCommandTest { public class ChallengesCommandTest {
@Mock @Mock
@ -143,10 +140,6 @@ public class ChallengesCommandTest {
// Challenges exist // Challenges exist
when(chm.hasAnyChallengeData(any(World.class))).thenReturn(true); 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 settings = new Settings(); Settings settings = new Settings();
when(addon.getChallengesSettings()).thenReturn(settings); when(addon.getChallengesSettings()).thenReturn(settings);
@ -161,6 +154,9 @@ public class ChallengesCommandTest {
// Util // Util
PowerMockito.mockStatic(Util.class, Mockito.RETURNS_MOCKS); PowerMockito.mockStatic(Util.class, Mockito.RETURNS_MOCKS);
when(Util.sameWorld(any(), any())).thenReturn(true); when(Util.sameWorld(any(), any())).thenReturn(true);
when(Util.translateColorCodes(anyString()))
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
// Command under test // Command under test
cc = new ChallengesPlayerCommand(addon, ic); cc = new ChallengesPlayerCommand(addon, ic);
} }
@ -172,7 +168,7 @@ public class ChallengesCommandTest {
public void testCanExecuteWrongWorld() { public void testCanExecuteWrongWorld() {
when(iwm.inWorld(any(World.class))).thenReturn(false); when(iwm.inWorld(any(World.class))).thenReturn(false);
assertFalse(cc.canExecute(user, "challenges", Collections.emptyList())); 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); when(chm.hasAnyChallengeData(any(World.class))).thenReturn(false);
assertFalse(cc.canExecute(user, "challenges", Collections.emptyList())); assertFalse(cc.canExecute(user, "challenges", Collections.emptyList()));
verify(addon).logError("There are no challenges set up in world!"); 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); when(chm.hasAnyChallengeData(any(World.class))).thenReturn(false);
assertFalse(cc.canExecute(user, "challenges", Collections.emptyList())); assertFalse(cc.canExecute(user, "challenges", Collections.emptyList()));
verify(addon).logError("There are no challenges set up in world!"); verify(addon).logError("There are no challenges set up in world!");
verify(user).getTranslation("challenges.errors.no-challenges-admin", "[command]", "bsb challenges"); verify(user).getTranslation(world, "challenges.errors.no-challenges-admin", "[command]", "bsb challenges");
verify(user, never()).getTranslation("challenges.errors.no-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); when(chm.hasAnyChallengeData(any(World.class))).thenReturn(false);
assertFalse(cc.canExecute(user, "challenges", Collections.emptyList())); assertFalse(cc.canExecute(user, "challenges", Collections.emptyList()));
verify(addon).logError("There are no challenges set up in world!"); verify(addon).logError("There are no challenges set up in world!");
verify(user).getTranslation("challenges.errors.no-challenges-admin", "[command]", "bsb challenges"); verify(user).getTranslation(world, "challenges.errors.no-challenges-admin", "[command]", "bsb challenges");
verify(user, never()).getTranslation("challenges.errors.no-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); when(chm.hasAnyChallengeData(any(World.class))).thenReturn(false);
assertFalse(cc.canExecute(user, "challenges", Collections.emptyList())); assertFalse(cc.canExecute(user, "challenges", Collections.emptyList()));
verify(addon).logError("There are no challenges set up in world!"); verify(addon).logError("There are no challenges set up in world!");
verify(user).getTranslation("challenges.errors.no-challenges-admin", "[command]", "bsb challenges"); verify(user).getTranslation(world, "challenges.errors.no-challenges-admin", "[command]", "bsb challenges");
verify(user, never()).getTranslation("challenges.errors.no-challenges"); verify(user, never()).getTranslation(world, "challenges.errors.no-challenges");
} }
/** /**
@ -234,7 +230,7 @@ public class ChallengesCommandTest {
public void testCanExecuteNoIsland() { public void testCanExecuteNoIsland() {
when(im.getIsland(any(), any(User.class))).thenReturn(null); when(im.getIsland(any(), any(User.class))).thenReturn(null);
assertFalse(cc.canExecute(user, "challenges", Collections.emptyList())); 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()); 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)}. * 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 java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFactory; 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.managers.IslandsManager;
import world.bentobox.bentobox.util.Util; import world.bentobox.bentobox.util.Util;
import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.managers.ChallengesManager;
import world.bentobox.challenges.config.Settings; import world.bentobox.challenges.config.Settings;
import world.bentobox.challenges.config.SettingsUtils.VisibilityMode; import world.bentobox.challenges.config.SettingsUtils.VisibilityMode;
import world.bentobox.challenges.database.object.Challenge; import world.bentobox.challenges.database.object.Challenge;
import world.bentobox.challenges.managers.ChallengesManager;
import world.bentobox.challenges.tasks.TryToComplete; import world.bentobox.challenges.tasks.TryToComplete;
import world.bentobox.challenges.utils.Constants;
import world.bentobox.challenges.utils.Utils; import world.bentobox.challenges.utils.Utils;
/** /**
@ -58,7 +58,7 @@ import world.bentobox.challenges.utils.Utils;
* *
*/ */
@RunWith(PowerMockRunner.class) @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 { public class CompleteChallengeCommandTest {
@Mock @Mock
@ -149,11 +149,6 @@ public class CompleteChallengeCommandTest {
List<String> nameList = Arrays.asList("world_maker", "world_placer", "bad_challenge_name", "world_breaker"); List<String> nameList = Arrays.asList("world_maker", "world_placer", "bad_challenge_name", "world_breaker");
when(chm.getAllChallengesNames(any())).thenReturn(nameList); 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 settings = new Settings(); Settings settings = new Settings();
when(addon.getChallengesSettings()).thenReturn(settings); when(addon.getChallengesSettings()).thenReturn(settings);
@ -175,6 +170,8 @@ public class CompleteChallengeCommandTest {
// Util // Util
PowerMockito.mockStatic(Util.class); PowerMockito.mockStatic(Util.class);
when(Util.tabLimit(any(), any())).thenAnswer((Answer<List<String>>) invocation -> (List<String>)invocation.getArgument(0, List.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 // Command under test
cc = new CompleteChallengeCommand(addon, ic); cc = new CompleteChallengeCommand(addon, ic);
@ -207,7 +204,8 @@ public class CompleteChallengeCommandTest {
@Test @Test
public void testExecuteUserStringListOfStringNoArgs() { public void testExecuteUserStringListOfStringNoArgs() {
assertFalse(cc.execute(user, "complete", Collections.emptyList())); 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")); verify(user).sendMessage(eq("commands.help.header"), eq(TextVariables.LABEL), eq("BSkyBlock"));
} }
@ -218,7 +216,8 @@ public class CompleteChallengeCommandTest {
public void testExecuteUserStringListOfStringUnknownChallenge() { public void testExecuteUserStringListOfStringUnknownChallenge() {
when(chm.getChallenge(anyString())).thenReturn(null); when(chm.getChallenge(anyString())).thenReturn(null);
assertFalse(cc.execute(user, "complete", Collections.singletonList("mychal"))); 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")); verify(user).sendMessage(eq("commands.help.header"), eq(TextVariables.LABEL), eq("BSkyBlock"));
} }
@ -247,7 +246,8 @@ public class CompleteChallengeCommandTest {
@Test @Test
public void testExecuteUserStringListOfStringKnownChallengeSuccessMultipleTimesNoPerm() { public void testExecuteUserStringListOfStringKnownChallengeSuccessMultipleTimesNoPerm() {
assertTrue(cc.execute(user, "complete", Arrays.asList("mychal", "5"))); 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");
} }
/** /**

View File

@ -10,6 +10,7 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -21,7 +22,6 @@ import java.util.Set;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -36,7 +36,9 @@ import org.bukkit.inventory.PlayerInventory;
import org.bukkit.util.BoundingBox; import org.bukkit.util.BoundingBox;
import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@ -60,28 +62,27 @@ import world.bentobox.bentobox.managers.LocalesManager;
import world.bentobox.bentobox.managers.PlaceholdersManager; import world.bentobox.bentobox.managers.PlaceholdersManager;
import world.bentobox.bentobox.util.Util; import world.bentobox.bentobox.util.Util;
import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.managers.ChallengesManager;
import world.bentobox.challenges.config.Settings; import world.bentobox.challenges.config.Settings;
import world.bentobox.challenges.database.object.Challenge; import world.bentobox.challenges.database.object.Challenge;
import world.bentobox.challenges.database.object.Challenge.ChallengeType; import world.bentobox.challenges.database.object.Challenge.ChallengeType;
import world.bentobox.challenges.database.object.ChallengeLevel; import world.bentobox.challenges.database.object.ChallengeLevel;
import world.bentobox.challenges.database.object.requirements.InventoryRequirements; import world.bentobox.challenges.database.object.requirements.InventoryRequirements;
import world.bentobox.challenges.database.object.requirements.IslandRequirements; import world.bentobox.challenges.database.object.requirements.IslandRequirements;
import world.bentobox.challenges.managers.ChallengesManager;
import world.bentobox.challenges.tasks.TryToComplete.ChallengeResult; import world.bentobox.challenges.tasks.TryToComplete.ChallengeResult;
import world.bentobox.challenges.utils.Utils;
/** /**
* @author tastybento * @author tastybento
* *
*/ */
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class, BentoBox.class, Util.class, Utils.class, ChatColor.class}) @PrepareForTest({ Bukkit.class, BentoBox.class, Util.class })
public class TryToCompleteTest { public class TryToCompleteTest {
// Constants // Constants
private static final String GAME_MODE_NAME = "BSkyBlock"; 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 static final String[] NAMES = { "adam", "ben", "cara", "dave", "ed", "frank", "freddy", "george", "harry",
"ian", "joe" };
private TryToComplete ttc; private TryToComplete ttc;
private Challenge challenge; private Challenge challenge;
@ -117,6 +118,7 @@ public class TryToCompleteTest {
private final ItemStack[] contents = {}; private final ItemStack[] contents = {};
@Mock @Mock
private BoundingBox bb; private BoundingBox bb;
private Set<Player> onlinePlayers;
/** /**
*/ */
@ -134,11 +136,13 @@ public class TryToCompleteTest {
when(plugin.getAddonsManager()).thenReturn(am); when(plugin.getAddonsManager()).thenReturn(am);
// One game mode // One game mode
when(am.getGameModeAddons()).thenReturn(Collections.singletonList(gameMode)); when(am.getGameModeAddons()).thenReturn(Collections.singletonList(gameMode));
AddonDescription desc2 = new AddonDescription.Builder("bentobox", GAME_MODE_NAME, "1.3").description("test").authors("tasty").build(); AddonDescription desc2 = new AddonDescription.Builder("bentobox", GAME_MODE_NAME, "1.3").description("test")
.authors("tasty").build();
when(gameMode.getDescription()).thenReturn(desc2); when(gameMode.getDescription()).thenReturn(desc2);
// Challenge Level // Challenge Level
@NonNull ChallengeLevel level = new ChallengeLevel(); @NonNull
ChallengeLevel level = new ChallengeLevel();
String levelName = GAME_MODE_NAME + "_novice"; String levelName = GAME_MODE_NAME + "_novice";
level.setUniqueId(levelName); level.setUniqueId(levelName);
level.setFriendlyName("Novice"); level.setFriendlyName("Novice");
@ -164,6 +168,8 @@ public class TryToCompleteTest {
when(Util.getWorld(any())).thenReturn(world); when(Util.getWorld(any())).thenReturn(world);
when(Util.prettifyText(anyString())).thenCallRealMethod(); when(Util.prettifyText(anyString())).thenCallRealMethod();
when(Util.stripSpaceAfterColorCodes(anyString())).thenCallRealMethod(); when(Util.stripSpaceAfterColorCodes(anyString())).thenCallRealMethod();
when(Util.translateColorCodes(anyString()))
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
// Island World Manager // Island World Manager
IslandWorldManager iwm = mock(IslandWorldManager.class); IslandWorldManager iwm = mock(IslandWorldManager.class);
@ -200,11 +206,16 @@ public class TryToCompleteTest {
when(user.hasPermission(anyString())).thenReturn(true); when(user.hasPermission(anyString())).thenReturn(true);
when(user.getPlayer()).thenReturn(player); when(user.getPlayer()).thenReturn(player);
UUID uniqueId = UUID.randomUUID(); UUID uniqueId = UUID.randomUUID();
when(player.getUniqueId()).thenReturn(uniqueId);
when(user.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()))
when(user.getTranslation(anyString(), anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class)); .thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
when(user.getTranslationOrNothing(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"); when(user.getName()).thenReturn("tastybento");
User.getInstance(player);
@Nullable @Nullable
Location userLoc = mock(Location.class); Location userLoc = mock(Location.class);
when(userLoc.toString()).thenReturn("location"); when(userLoc.toString()).thenReturn("location");
@ -219,9 +230,11 @@ public class TryToCompleteTest {
LocalesManager lm = mock(LocalesManager.class); LocalesManager lm = mock(LocalesManager.class);
when(plugin.getLocalesManager()).thenReturn(lm); 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));
when(lm.get(any(), any())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
PlaceholdersManager phm = mock(PlaceholdersManager.class); PlaceholdersManager phm = mock(PlaceholdersManager.class);
when(plugin.getPlaceholdersManager()).thenReturn(phm); when(plugin.getPlaceholdersManager()).thenReturn(phm);
when(phm.replacePlaceholders(any(), any())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class)); when(phm.replacePlaceholders(any(), any()))
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
// Survival by default // Survival by default
when(player.getGameMode()).thenReturn(GameMode.SURVIVAL); when(player.getGameMode()).thenReturn(GameMode.SURVIVAL);
@ -233,7 +246,7 @@ public class TryToCompleteTest {
// Bukkit - online players // Bukkit - online players
Map<UUID, String> online = new HashMap<>(); Map<UUID, String> online = new HashMap<>();
Set<Player> onlinePlayers = new HashSet<>(); onlinePlayers = new HashSet<>();
for (String name : NAMES) { for (String name : NAMES) {
Player p1 = mock(Player.class); Player p1 = mock(Player.class);
UUID uuid2 = UUID.randomUUID(); UUID uuid2 = UUID.randomUUID();
@ -243,7 +256,7 @@ public class TryToCompleteTest {
onlinePlayers.add(p1); onlinePlayers.add(p1);
} }
PowerMockito.mockStatic(Bukkit.class); PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getOnlinePlayers()).then((Answer<Set<Player>>) invocation -> onlinePlayers); when(Bukkit.getOnlinePlayers()).then((Answer<Set<Player>>) invocation -> Set.of(player));
// World settings // World settings
Map<String, Boolean> map = new HashMap<>(); Map<String, Boolean> map = new HashMap<>();
@ -255,66 +268,70 @@ public class TryToCompleteTest {
ItemFactory itemFactory = mock(ItemFactory.class); ItemFactory itemFactory = mock(ItemFactory.class);
when(Bukkit.getItemFactory()).thenReturn(itemFactory); when(Bukkit.getItemFactory()).thenReturn(itemFactory);
// ChatColor }
PowerMockito.mockStatic(ChatColor.class, Mockito.RETURNS_MOCKS);
when(ChatColor.stripColor(anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class)); @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 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 @Test
public void testTryToCompleteChallengesAddonUserChallengeWorldStringString() { public void testTryToCompleteChallengesAddonUserChallengeWorldStringString() {
ttc = new TryToComplete(addon, ttc = new TryToComplete(addon, user, challenge, world, topLabel, permissionPrefix);
user,
challenge,
world,
topLabel,
permissionPrefix);
verify(addon).getChallengesManager(); 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 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 @Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringNotDeployed() { public void testCompleteChallengesAddonUserChallengeWorldStringStringNotDeployed() {
challenge.setDeployed(false); challenge.setDeployed(false);
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix)); assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation("challenges.errors.not-deployed"); 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 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 @Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringWrongWorld() { public void testCompleteChallengesAddonUserChallengeWorldStringStringWrongWorld() {
challenge.setUniqueId("test"); challenge.setUniqueId("test");
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix)); assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation("general.errors.wrong-world"); 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 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 @Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringNotOnIsland() { public void testCompleteChallengesAddonUserChallengeWorldStringStringNotOnIsland() {
ChallengesAddon.CHALLENGES_WORLD_PROTECTION.setSetting(world, true); ChallengesAddon.CHALLENGES_WORLD_PROTECTION.setSetting(world, true);
when(im.locationIsOnIsland(any(Player.class), any(Location.class))).thenReturn(false); when(im.locationIsOnIsland(any(Player.class), any(Location.class))).thenReturn(false);
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix)); assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation("challenges.errors.not-on-island"); 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 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 @Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringNotOnIslandButOk() { public void testCompleteChallengesAddonUserChallengeWorldStringStringNotOnIslandButOk() {
ChallengesAddon.CHALLENGES_WORLD_PROTECTION.setSetting(world, false); ChallengesAddon.CHALLENGES_WORLD_PROTECTION.setSetting(world, false);
when(im.locationIsOnIsland(any(Player.class), any(Location.class))).thenReturn(false); when(im.locationIsOnIsland(any(Player.class), any(Location.class))).thenReturn(false);
assertTrue(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix)); assertTrue(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation("challenges.messages.you-completed-challenge", "[value]", "name"); verify(user).getTranslation(any(World.class), eq("challenges.messages.you-completed-challenge"), eq("[value]"),
eq("name"));
} }
/** /**
@ -324,22 +341,24 @@ public class TryToCompleteTest {
public void testCompleteChallengesAddonUserChallengeWorldStringStringLevelNotUnlocked() { public void testCompleteChallengesAddonUserChallengeWorldStringStringLevelNotUnlocked() {
when(cm.isLevelUnlocked(any(), any(), any())).thenReturn(false); when(cm.isLevelUnlocked(any(), any(), any())).thenReturn(false);
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix)); assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation("challenges.errors.challenge-level-not-available"); verify(user).getTranslation(any(World.class), eq("challenges.errors.challenge-level-not-available"));
} }
/** /**
* 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 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 @Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringNotRepeatable() { public void testCompleteChallengesAddonUserChallengeWorldStringStringNotRepeatable() {
challenge.setRepeatable(false); challenge.setRepeatable(false);
when(cm.isChallengeComplete(any(User.class), any(), any())).thenReturn(true); when(cm.isChallengeComplete(any(User.class), any(), any())).thenReturn(true);
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix)); assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation("challenges.errors.not-repeatable"); 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 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 @Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringNotRepeatableFirstTime() { public void testCompleteChallengesAddonUserChallengeWorldStringStringNotRepeatableFirstTime() {
@ -347,7 +366,8 @@ public class TryToCompleteTest {
challenge.setMaxTimes(0); challenge.setMaxTimes(0);
when(cm.getChallengeTimes(any(), any(), any(Challenge.class))).thenReturn(0L); when(cm.getChallengeTimes(any(), any(), any(Challenge.class))).thenReturn(0L);
assertTrue(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix)); assertTrue(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation("challenges.messages.you-completed-challenge", "[value]", "name"); verify(user).getTranslation(any(World.class), eq("challenges.messages.you-completed-challenge"), eq("[value]"),
eq("name"));
} }
/** /**
@ -357,39 +377,43 @@ public class TryToCompleteTest {
public void testCompleteChallengesAddonUserChallengeWorldStringStringNoRank() { public void testCompleteChallengesAddonUserChallengeWorldStringStringNoRank() {
when(island.isAllowed(any(), any())).thenReturn(false); when(island.isAllowed(any(), any())).thenReturn(false);
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix)); assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation("challenges.errors.no-rank"); verify(user).getTranslation(any(World.class), eq("challenges.messages.no-rank"));
} }
/** /**
* 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 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 @Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringIntZero() { public void testCompleteChallengesAddonUserChallengeWorldStringStringIntZero() {
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix, 0)); assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix, 0));
verify(user).getTranslation("challenges.errors.not-valid-integer"); 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 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 @Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringIntNegative() { public void testCompleteChallengesAddonUserChallengeWorldStringStringIntNegative() {
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix, -10)); assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix, -10));
verify(user).getTranslation("challenges.errors.not-valid-integer"); 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 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 @Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringIntPositiveWrongEnvinonment() { public void testCompleteChallengesAddonUserChallengeWorldStringStringIntPositiveWrongEnvinonment() {
challenge.setEnvironment(Collections.singleton(Environment.NETHER)); challenge.setEnvironment(Collections.singleton(Environment.NETHER));
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix, 100)); assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix, 100));
verify(user).getTranslation("challenges.errors.wrong-environment"); 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 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 @Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringIntPositiveNoPerm() { public void testCompleteChallengesAddonUserChallengeWorldStringStringIntPositiveNoPerm() {
@ -398,34 +422,41 @@ public class TryToCompleteTest {
when(user.hasPermission(anyString())).thenReturn(false); when(user.hasPermission(anyString())).thenReturn(false);
challenge.setRequirements(req); challenge.setRequirements(req);
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix, 100)); assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix, 100));
verify(user).getTranslation("general.errors.no-permission"); 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 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 @Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringSuccess() { public void testCompleteChallengesAddonUserChallengeWorldStringStringSuccess() {
assertTrue(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix)); assertTrue(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation("challenges.messages.you-completed-challenge", "[value]", "name"); 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 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 @Test
@Ignore("Method is too large for JVM")
public void testCompleteChallengesAddonUserChallengeWorldStringStringSuccessSingleReq() { public void testCompleteChallengesAddonUserChallengeWorldStringStringSuccessSingleReq() {
InventoryRequirements req = new InventoryRequirements(); InventoryRequirements req = new InventoryRequirements();
req.setRequiredItems(Collections.singletonList(new ItemStack(Material.EMERALD_BLOCK))); req.setRequiredItems(Collections.singletonList(new ItemStack(Material.EMERALD_BLOCK)));
challenge.setRequirements(req); challenge.setRequirements(req);
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix)); assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation("challenges.errors.not-enough-items", "[items]", "challenges.materials.emerald_block"); 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 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 @Test
@Ignore("Too big for JVM")
public void testCompleteChallengesAddonUserChallengeWorldStringStringSuccessMultipleReq() { public void testCompleteChallengesAddonUserChallengeWorldStringStringSuccessMultipleReq() {
InventoryRequirements req = new InventoryRequirements(); InventoryRequirements req = new InventoryRequirements();
@ -454,9 +485,11 @@ public class TryToCompleteTest {
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix)); assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
// Sufficient emerald blocks // Sufficient emerald blocks
verify(user, never()).getTranslation("challenges.errors.not-enough-items", "[items]", "challenges.materials.emerald_block"); verify(user, never()).getTranslation(any(World.class), eq("challenges.errors.not-enough-items"), eq("[items]"),
eq("challenges.materials.emerald_block"));
// Not enough books // Not enough books
verify(user).getTranslation("challenges.errors.not-enough-items", "[items]", "challenges.materials.enchanted_book"); verify(user).getTranslation(any(World.class), eq("challenges.errors.not-enough-items"), eq("[items]"),
eq("challenges.materials.enchanted_book"));
} }
/** /**
@ -466,11 +499,14 @@ public class TryToCompleteTest {
public void testCompleteChallengesAddonUserChallengeWorldStringStringSuccessCreative() { public void testCompleteChallengesAddonUserChallengeWorldStringStringSuccessCreative() {
when(player.getGameMode()).thenReturn(GameMode.CREATIVE); when(player.getGameMode()).thenReturn(GameMode.CREATIVE);
assertTrue(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix)); assertTrue(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation("challenges.messages.you-completed-challenge", "[value]", "name"); // 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");
} }
/** /**
* 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 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 @Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringIslandBBTooLarge() { public void testCompleteChallengesAddonUserChallengeWorldStringStringIslandBBTooLarge() {
@ -481,13 +517,15 @@ public class TryToCompleteTest {
// Trigger big bounding box error // Trigger big bounding box error
when(bb.getWidthX()).thenReturn(50000D); when(bb.getWidthX()).thenReturn(50000D);
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix)); 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(addon).logError(
"BoundingBox is larger than SearchRadius. | BoundingBox: BoundingBox | Search Distance: 1 | Location: location | Center: center | Range: 0");
verify(bb).expand(1); 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 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 @Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringIslandSuccessNoEntities() { public void testCompleteChallengesAddonUserChallengeWorldStringStringIslandSuccessNoEntities() {
@ -496,12 +534,14 @@ public class TryToCompleteTest {
req.setSearchRadius(1); req.setSearchRadius(1);
challenge.setRequirements(req); challenge.setRequirements(req);
assertTrue(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix)); assertTrue(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation("challenges.messages.you-completed-challenge", "[value]", "name"); 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 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 @Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringIslandFailEntities() { public void testCompleteChallengesAddonUserChallengeWorldStringStringIslandFailEntities() {
@ -512,12 +552,14 @@ public class TryToCompleteTest {
req.setSearchRadius(1); req.setSearchRadius(1);
challenge.setRequirements(req); challenge.setRequirements(req);
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix)); assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation("challenges.errors.you-still-need", "[amount]", "3", "[item]", "challenges.entities.ghast.name"); 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 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 @Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringIslandFailMultipleEntities() { public void testCompleteChallengesAddonUserChallengeWorldStringStringIslandFailMultipleEntities() {
@ -531,14 +573,18 @@ public class TryToCompleteTest {
req.setSearchRadius(1); req.setSearchRadius(1);
challenge.setRequirements(req); challenge.setRequirements(req);
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix)); assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation("challenges.errors.you-still-need", "[amount]", "3", "[item]", "challenges.entities.ghast.name"); verify(user).getTranslation(any(World.class), eq("challenges.errors.you-still-need"), eq("[amount]"), eq("3"),
verify(user).getTranslation("challenges.errors.you-still-need", "[amount]", "1", "[item]", "challenges.entities.pufferfish.name"); eq("[item]"), eq("challenges.entities.ghast.name"));
verify(user).getTranslation("challenges.errors.you-still-need", "[amount]", "5", "[item]", "challenges.entities.chicken.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 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 @Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringIslandFailPartialMultipleEntities() { public void testCompleteChallengesAddonUserChallengeWorldStringStringIslandFailPartialMultipleEntities() {
@ -558,14 +604,18 @@ public class TryToCompleteTest {
List<Entity> list = Collections.singletonList(ent); List<Entity> list = Collections.singletonList(ent);
when(world.getNearbyEntities(any(BoundingBox.class))).thenReturn(list); when(world.getNearbyEntities(any(BoundingBox.class))).thenReturn(list);
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix)); assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation("challenges.errors.you-still-need", "[amount]", "3", "[item]", "challenges.entities.ghast.name"); verify(user).getTranslation(any(World.class), eq("challenges.errors.you-still-need"), eq("[amount]"), eq("3"),
verify(user, never()).getTranslation("challenges.errors.you-still-need", "[amount]", "1", "[item]", "challenges.entities.pufferfish.name"); eq("[item]"), eq("challenges.entities.ghast.name"));
verify(user).getTranslation("challenges.errors.you-still-need", "[amount]", "5", "[item]", "challenges.entities.chicken.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 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 @Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringIslandSuccess() { public void testCompleteChallengesAddonUserChallengeWorldStringStringIslandSuccess() {
@ -583,11 +633,13 @@ public class TryToCompleteTest {
List<Entity> list = Collections.singletonList(ent); List<Entity> list = Collections.singletonList(ent);
when(world.getNearbyEntities(any(BoundingBox.class))).thenReturn(list); when(world.getNearbyEntities(any(BoundingBox.class))).thenReturn(list);
assertTrue(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix)); assertTrue(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation("challenges.messages.you-completed-challenge", "[value]", "name"); 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 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 @Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringIslandPlayerInOtherEnvironment() { public void testCompleteChallengesAddonUserChallengeWorldStringStringIslandPlayerInOtherEnvironment() {
@ -611,21 +663,26 @@ public class TryToCompleteTest {
when(world.getNearbyEntities(any(BoundingBox.class))).thenReturn(list); when(world.getNearbyEntities(any(BoundingBox.class))).thenReturn(list);
when(netherWorld.getNearbyEntities(any(BoundingBox.class))).thenReturn(Collections.emptyList()); when(netherWorld.getNearbyEntities(any(BoundingBox.class))).thenReturn(Collections.emptyList());
assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix)); assertFalse(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix));
verify(user).getTranslation("challenges.errors.you-still-need", "[amount]", "1", "[item]", "challenges.entities.pufferfish.name"); 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 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 @Test
public void testCompleteChallengesAddonUserChallengeWorldStringStringIntMultipleTimesPositiveSuccess() { public void testCompleteChallengesAddonUserChallengeWorldStringStringIntMultipleTimesPositiveSuccess() {
// Try to complete 10 times. Already done 3 times, and max is 10, so it should be only done 7 times // 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)); assertTrue(TryToComplete.complete(addon, user, challenge, world, topLabel, permissionPrefix, 10));
verify(user).getTranslation("challenges.messages.you-repeated-challenge-multiple", "[value]", "name", "[count]", "7"); 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 method for
* {@link world.bentobox.challenges.tasks.TryToComplete#build(int)}.
*/ */
@Test @Test
public void testBuild() { public void testBuild() {
@ -635,7 +692,8 @@ public class TryToCompleteTest {
} }
/** /**
* Test method for {@link world.bentobox.challenges.tasks.TryToComplete#removeItems(java.util.List, int)}. * Test method for
* {@link world.bentobox.challenges.tasks.TryToComplete#removeItems(java.util.List, int)}.
*/ */
@Test @Test
public void testRemoveItemsNothing() { public void testRemoveItemsNothing() {