Skip to content

Commit d792b22

Browse files
committed
Merge branch 'develop' into master
# Conflicts: # pom.xml # src/main/java/world/bentobox/magiccobblestonegenerator/StoneGeneratorAddon.java # src/main/java/world/bentobox/magiccobblestonegenerator/panels/admin/BundleEditPanel.java # src/main/java/world/bentobox/magiccobblestonegenerator/panels/admin/GeneratorEditPanel.java # src/main/resources/panels/main_panel.yml # src/test/java/world/bentobox/magiccobblestonegenerator/StoneGeneratorAddonTest.java
2 parents 9e825e3 + 312210b commit d792b22

File tree

10 files changed

+98
-436
lines changed

10 files changed

+98
-436
lines changed

pom.xml

+13-28
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3434
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
3535
<java.version>17</java.version>
36-
<powermock.version>2.0.9</powermock.version>
37-
<mockito.version>4.2.0</mockito.version>
3836
<!-- More visible way how to change dependency versions -->
3937
<spigot.version>1.18-R0.1-SNAPSHOT</spigot.version>
4038
<bentobox.version>1.20.0</bentobox.version>
@@ -47,7 +45,7 @@
4745
<!-- Revision variable removes warning about dynamic version -->
4846
<revision>${build.version}-SNAPSHOT</revision>
4947
<!-- This allows to change between versions and snapshots. -->
50-
<build.version>2.4.0</build.version>
48+
<build.version>2.5.0</build.version>
5149
<build.number>-LOCAL</build.number>
5250
<!-- Sonar Cloud -->
5351
<sonar.projectKey>BentoBoxWorld_MagicCobblestoneGenerator</sonar.projectKey>
@@ -107,7 +105,7 @@
107105
<repositories>
108106
<repository>
109107
<id>spigot-repo</id>
110-
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots</url>
108+
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
111109
</repository>
112110
<repository>
113111
<id>codemc-repo</id>
@@ -116,7 +114,7 @@
116114
<!--Vault Repo is down. -->
117115
<repository>
118116
<id>vault-repo</id>
119-
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
117+
<url>https://nexus.hc.to/content/repositories/pub_releases</url>
120118
</repository>
121119
<repository>
122120
<id>jitpack.io</id>
@@ -137,25 +135,6 @@
137135
<version>1.2.3-SNAPSHOT</version>
138136
<scope>compile</scope>
139137
</dependency>
140-
<!-- Mockito (Unit testing) -->
141-
<dependency>
142-
<groupId>org.mockito</groupId>
143-
<artifactId>mockito-core</artifactId>
144-
<version>${mockito.version}</version>
145-
<scope>test</scope>
146-
</dependency>
147-
<dependency>
148-
<groupId>org.powermock</groupId>
149-
<artifactId>powermock-module-junit4</artifactId>
150-
<version>${powermock.version}</version>
151-
<scope>test</scope>
152-
</dependency>
153-
<dependency>
154-
<groupId>org.powermock</groupId>
155-
<artifactId>powermock-api-mockito2</artifactId>
156-
<version>${powermock.version}</version>
157-
<scope>test</scope>
158-
</dependency>
159138
<dependency>
160139
<groupId>world.bentobox</groupId>
161140
<artifactId>bentobox</artifactId>
@@ -224,7 +203,7 @@
224203
<plugin>
225204
<groupId>org.apache.maven.plugins</groupId>
226205
<artifactId>maven-compiler-plugin</artifactId>
227-
<version>3.7.0</version>
206+
<version>3.8.1</version>
228207
<configuration>
229208
<release>${java.version}</release>
230209
</configuration>
@@ -235,6 +214,7 @@
235214
<version>3.0.0-M5</version>
236215
<configuration>
237216
<argLine>
217+
${argLine}
238218
--add-opens java.base/java.lang=ALL-UNNAMED
239219
--add-opens java.base/java.math=ALL-UNNAMED
240220
--add-opens java.base/java.io=ALL-UNNAMED
@@ -359,7 +339,7 @@
359339
<plugin>
360340
<groupId>org.jacoco</groupId>
361341
<artifactId>jacoco-maven-plugin</artifactId>
362-
<version>0.8.3</version>
342+
<version>0.8.7</version>
363343
<configuration>
364344
<append>true</append>
365345
<excludes>
@@ -370,16 +350,21 @@
370350
</configuration>
371351
<executions>
372352
<execution>
373-
<id>pre-unit-test</id>
353+
<id>prepare-agent</id>
374354
<goals>
375355
<goal>prepare-agent</goal>
376356
</goals>
377357
</execution>
378358
<execution>
379-
<id>post-unit-test</id>
359+
<id>report</id>
380360
<goals>
381361
<goal>report</goal>
382362
</goals>
363+
<configuration>
364+
<formats>
365+
<format>XML</format>
366+
</formats>
367+
</configuration>
383368
</execution>
384369
</executions>
385370
</plugin>

src/main/java/world/bentobox/magiccobblestonegenerator/StoneGeneratorAddon.java

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package world.bentobox.magiccobblestonegenerator;
22

33

4+
import java.util.Objects;
45
import java.util.Optional;
56

67
import org.bukkit.Bukkit;
@@ -216,6 +217,7 @@ private void registerPlaceholders(GameModeAddon addon)
216217

217218
object.getActiveGeneratorList().stream().
218219
map(this.stoneGeneratorManager::getGeneratorByID).
220+
filter(Objects::nonNull).
219221
forEach(generator -> stringBuilder.append(generator.getFriendlyName()).append(","));
220222

221223
if (stringBuilder.length() > 0)
@@ -244,6 +246,7 @@ private void registerPlaceholders(GameModeAddon addon)
244246
object.getUnlockedTiers().stream().
245247
sorted().
246248
map(this.stoneGeneratorManager::getGeneratorByID).
249+
filter(Objects::nonNull).
247250
forEach(generator -> stringBuilder.append(generator.getFriendlyName()).append(","));
248251

249252
if (stringBuilder.length() > 0)
@@ -272,6 +275,7 @@ private void registerPlaceholders(GameModeAddon addon)
272275
object.getPurchasedTiers().stream().
273276
sorted().
274277
map(this.stoneGeneratorManager::getGeneratorByID).
278+
filter(Objects::nonNull).
275279
forEach(generator -> stringBuilder.append(generator.getFriendlyName()).append(","));
276280

277281
if (stringBuilder.length() > 0)

src/main/java/world/bentobox/magiccobblestonegenerator/commands/admin/GeneratorAdminCommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public boolean execute(User user, String label, List<String> args)
233233
// Set meta data on player
234234
Island island = this.getAddon().getIslands().getIsland(this.getWorld(), targetUUID);
235235

236-
if (island == null || island.getOwner() == null)
236+
if (island == null || island.getOwner() == null || !island.getOwner().equals(targetUUID))
237237
{
238238
Utils.sendMessage(user,
239239
user.getTranslation("general.errors.player-is-not-owner"));

src/main/java/world/bentobox/magiccobblestonegenerator/managers/StoneGeneratorManager.java

+32-14
Original file line numberDiff line numberDiff line change
@@ -824,9 +824,12 @@ private void addIslandData(@NotNull Island island)
824824
pd.setIslandBundle(null);
825825

826826
// Update owner data.
827-
this.updateOwnerBundle(island, pd);
828-
this.updateOwnerGeneratorCount(island, pd);
829-
this.updateOwnerWorkingRange(island, pd);
827+
if (!island.isSpawn())
828+
{
829+
this.updateOwnerBundle(island, pd);
830+
this.updateOwnerGeneratorCount(island, pd);
831+
this.updateOwnerWorkingRange(island, pd);
832+
}
830833

831834
// Save data.
832835
this.saveGeneratorData(pd);
@@ -907,11 +910,16 @@ private void addIslandData(@NotNull Island island)
907910
*/
908911
private void updateOwnerWorkingRange(@NotNull Island island, @NotNull GeneratorDataObject dataObject)
909912
{
910-
User owner = User.getInstance(island.getOwner());
911-
912913
// Permission check can be done only to a player object.
913-
if (owner != null && owner.isPlayer())
914+
if (island.getOwner() != null)
914915
{
916+
User owner = User.getInstance(island.getOwner());
917+
918+
if (!owner.isPlayer())
919+
{
920+
return;
921+
}
922+
915923
// Update max island generation range.
916924
int permissionRange = Utils.getPermissionValue(owner,
917925
Utils.getPermissionString(island.getWorld(), "[gamemode].stone-generator.max-range"),
@@ -929,11 +937,16 @@ private void updateOwnerWorkingRange(@NotNull Island island, @NotNull GeneratorD
929937
*/
930938
private void updateOwnerGeneratorCount(@NotNull Island island, @NotNull GeneratorDataObject dataObject)
931939
{
932-
User owner = User.getInstance(island.getOwner());
933-
934940
// Permission check can be done only to a player object.
935-
if (owner != null && owner.isPlayer())
941+
if (island.getOwner() != null)
936942
{
943+
User owner = User.getInstance(island.getOwner());
944+
945+
if (!owner.isPlayer())
946+
{
947+
return;
948+
}
949+
937950
// Update max active generator count.
938951
int permissionSize = Utils.getPermissionValue(owner,
939952
Utils.getPermissionString(island.getWorld(), "[gamemode].stone-generator.active-generators"),
@@ -951,11 +964,16 @@ private void updateOwnerGeneratorCount(@NotNull Island island, @NotNull Generato
951964
*/
952965
private void updateOwnerBundle(@NotNull Island island, @NotNull GeneratorDataObject dataObject)
953966
{
954-
User owner = User.getInstance(island.getOwner());
955-
956967
// Permission check can be done only to a player object.
957-
if (owner != null && owner.isPlayer())
968+
if (island.getOwner() != null)
958969
{
970+
User owner = User.getInstance(island.getOwner());
971+
972+
if (!owner.isPlayer())
973+
{
974+
return;
975+
}
976+
959977
// Update max island generation range.
960978
String permissionBundle = Utils.getPermissionValue(owner,
961979
Utils.getPermissionString(island.getWorld(), "[gamemode].stone-generator.bundle"),
@@ -994,7 +1012,7 @@ public void checkGeneratorUnlockStatus(Island island, @Nullable User user, @Null
9941012

9951013
// If level is null, check value from addon.
9961014
final long islandLevel = level == null ? this.getIslandLevel(island) : level;
997-
final User owner = User.getInstance(island.getOwner());
1015+
final User owner = island.isSpawn() ? null : User.getInstance(island.getOwner());
9981016

9991017
this.getIslandGeneratorTiers(island.getWorld(), dataObject).stream().
10001018
// Filter out default generators. They are always unlocked and active.
@@ -1368,7 +1386,7 @@ public boolean canPurchaseGenerator(@NotNull User user,
13681386
@NotNull GeneratorDataObject generatorData,
13691387
@NotNull GeneratorTierObject generatorTier)
13701388
{
1371-
final User owner = User.getInstance(island.getOwner());
1389+
final User owner = island.isSpawn() ? null : User.getInstance(island.getOwner());
13721390

13731391
if (generatorData.getPurchasedTiers().contains(generatorTier.getUniqueId()))
13741392
{

src/main/java/world/bentobox/magiccobblestonegenerator/panels/admin/BundleEditPanel.java

+13
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ private void populateInfo(PanelBuilder panelBuilder)
143143
{
144144
// Users should see only icon
145145
panelBuilder.item(13, this.createButton(Button.BUNDLE_NAME));
146+
panelBuilder.item(22, this.createButton(Button.BUNDLE_ID));
146147
panelBuilder.item(11, this.createButton(Button.BUNDLE_ICON));
147148
panelBuilder.item(14, this.createButton(Button.BUNDLE_DESCRIPTION));
148149
}
@@ -228,6 +229,14 @@ private PanelItem createButton(Button button)
228229
description.add("");
229230
description.add(this.user.getTranslation(Constants.TIPS + "click-to-change"));
230231
}
232+
case BUNDLE_ID -> {
233+
itemStack = new ItemStack(Material.COMMAND_BLOCK);
234+
235+
clickHandler = (panel, user, clickType, i) -> true;
236+
237+
description.add(this.user.getTranslation(reference + ".value",
238+
Constants.ID, this.bundle.getUniqueId()));
239+
}
231240
case BUNDLE_ICON -> {
232241
itemStack = this.bundle.getGeneratorIcon();
233242

@@ -641,6 +650,10 @@ private enum Button
641650
* Holds Name type that allows to interact with bundle name.
642651
*/
643652
BUNDLE_NAME,
653+
/**
654+
* Holds ID type.
655+
*/
656+
BUNDLE_ID,
644657
/**
645658
* Holds Name type that allows to interact with bundle icon.
646659
*/

src/main/java/world/bentobox/magiccobblestonegenerator/panels/admin/GeneratorEditPanel.java

+13
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ private void populateHeader(PanelBuilder panelBuilder)
151151
private void populateInfo(PanelBuilder panelBuilder)
152152
{
153153
panelBuilder.item(10, this.createButton(Button.NAME));
154+
panelBuilder.item(11, this.createButton(Button.ID));
154155
panelBuilder.item(19, this.createButton(Button.ICON));
155156
panelBuilder.item(28, this.createButton(Button.DESCRIPTION));
156157

@@ -370,6 +371,14 @@ private PanelItem createButton(Button button)
370371
description.add("");
371372
description.add(this.user.getTranslation(Constants.TIPS + "click-to-change"));
372373
}
374+
case ID -> {
375+
description.add(this.user.getTranslation(reference + ".value",
376+
Constants.ID, this.generatorTier.getUniqueId()));
377+
378+
itemStack = new ItemStack(Material.COMMAND_BLOCK);
379+
380+
clickHandler = (panel, user, clickType, i) -> true;
381+
}
373382
case ICON, LOCKED_ICON -> {
374383
itemStack = button == Button.LOCKED_ICON ?
375384
this.generatorTier.getLockedIcon() :
@@ -1560,6 +1569,10 @@ private enum Button
15601569
* Holds Name type that allows to interact with generator treasure chance.
15611570
*/
15621571
TREASURE_CHANCE,
1572+
/**
1573+
* Holds ID of the generator ID.
1574+
*/
1575+
ID,
15631576
}
15641577

15651578

src/main/java/world/bentobox/magiccobblestonegenerator/utils/Why.java

+10-44
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,22 @@ public class Why
3030
public static void report(@NotNull Location location, String why)
3131
{
3232
BentoBox.getInstance().getIslands().getIslandAt(location).ifPresent(island -> {
33-
User owner = User.getInstance(island.getOwner());
34-
35-
Why.report(StoneGeneratorAddon.getInstance(), owner, location, why);
33+
if (island.getOwner() != null)
34+
{
35+
User owner = User.getInstance(island.getOwner());
36+
Why.report(StoneGeneratorAddon.getInstance(), owner, location, why);
37+
}
3638
});
3739
}
3840

3941

4042
public static void report(@NotNull Island island, Location location, String why)
4143
{
42-
User owner = User.getInstance(island.getOwner());
43-
Why.report(StoneGeneratorAddon.getInstance(), owner, location, why);
44+
if (island.getOwner() != null)
45+
{
46+
User owner = User.getInstance(island.getOwner());
47+
Why.report(StoneGeneratorAddon.getInstance(), owner, location, why);
48+
}
4449
}
4550

4651

@@ -89,43 +94,4 @@ public static void report(Addon addon, @Nullable User user, @NotNull Location lo
8994
}
9095
}
9196
}
92-
93-
94-
/**
95-
* This is a general Reason enum that contains all possible values for reporting an debug message.
96-
*/
97-
public enum Reason
98-
{
99-
UNDEFINED("name", "value");
100-
101-
102-
Reason(String key, String value)
103-
{
104-
this.key = key;
105-
this.value = value;
106-
}
107-
108-
109-
public String getKey()
110-
{
111-
return key;
112-
}
113-
114-
115-
public String getValue()
116-
{
117-
return value;
118-
}
119-
120-
121-
/**
122-
* This variable stores string text for key.
123-
*/
124-
private String key;
125-
126-
/**
127-
* This variable stores text.
128-
*/
129-
private String value;
130-
}
13197
}

0 commit comments

Comments
 (0)