Skip to content

Commit f48269b

Browse files
authored
Merge pull request #335 from BentoBoxWorld/1_23_1_update
Update to 1.21.3
2 parents b462aaa + d422622 commit f48269b

File tree

7 files changed

+155
-28
lines changed

7 files changed

+155
-28
lines changed

pom.xml

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,9 @@
4141
</issueManagement>
4242

4343
<distributionManagement>
44-
<snapshotRepository>
45-
<id>codemc-snapshots</id>
46-
<url>https://repo.codemc.org/repository/maven-snapshots</url>
47-
</snapshotRepository>
4844
<repository>
49-
<id>codemc-releases</id>
50-
<url>https://repo.codemc.org/repository/maven-releases</url>
45+
<id>bentoboxworld</id>
46+
<url>https://repo.codemc.org/repository/bentoboxworld/</url>
5147
</repository>
5248
</distributionManagement>
5349

@@ -59,7 +55,7 @@
5955
<powermock.version>2.0.9</powermock.version>
6056
<!-- More visible way how to change dependency versions -->
6157
<spigot.version>1.21.3-R0.1-SNAPSHOT</spigot.version>
62-
<bentobox.version>2.7.0</bentobox.version>
58+
<bentobox.version>2.7.1-SNAPSHOT</bentobox.version>
6359
<!-- Warps addon version -->
6460
<warps.version>1.12.0</warps.version>
6561
<!-- Visit addon version -->
@@ -127,6 +123,26 @@
127123
</pluginRepositories>
128124

129125
<repositories>
126+
<repository>
127+
<id>spigot-repo</id>
128+
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots</url>
129+
</repository>
130+
<repository>
131+
<id>codemc</id>
132+
<url>https://repo.codemc.org/repository/maven-snapshots/</url>
133+
</repository>
134+
<repository>
135+
<id>codemc-repo</id>
136+
<url>https://repo.codemc.org/repository/maven-public/</url>
137+
</repository>
138+
<repository>
139+
<id>bentoboxworld</id>
140+
<url>https://repo.codemc.org/repository/bentoboxworld/</url>
141+
</repository>
142+
<repository>
143+
<id>jitpack.io</id>
144+
<url>https://jitpack.io</url>
145+
</repository>
130146
<!--Wild Stacker repo -->
131147
<repository>
132148
<id>bg-repo</id>
@@ -142,22 +158,6 @@
142158
<id>songoda-plugins</id>
143159
<url>https://repo.songoda.com/repository/minecraft-plugins/</url>
144160
</repository>
145-
<repository>
146-
<id>spigot-repo</id>
147-
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots</url>
148-
</repository>
149-
<repository>
150-
<id>codemc-repo</id>
151-
<url>https://repo.codemc.org/repository/maven-public/</url>
152-
</repository>
153-
<repository>
154-
<id>codemc-public</id>
155-
<url>https://repo.codemc.org/repository/maven-public/</url>
156-
</repository>
157-
<repository>
158-
<id>jitpack.io</id>
159-
<url>https://jitpack.io</url>
160-
</repository>
161161
</repositories>
162162

163163
<dependencies>

src/main/java/world/bentobox/level/calculators/IslandLevelCalculator.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@ public class IslandLevelCalculator {
6262
Material.LIME_SHULKER_BOX, Material.MAGENTA_SHULKER_BOX, Material.ORANGE_SHULKER_BOX,
6363
Material.PINK_SHULKER_BOX, Material.PURPLE_SHULKER_BOX, Material.RED_SHULKER_BOX, Material.RED_SHULKER_BOX,
6464
Material.WHITE_SHULKER_BOX, Material.YELLOW_SHULKER_BOX, Material.COMPOSTER, Material.BARREL,
65-
Material.DISPENSER, Material.DROPPER, Material.SMOKER, Material.BLAST_FURNACE);
65+
Material.DISPENSER, Material.DROPPER, Material.SMOKER, Material.BLAST_FURNACE, Material.BUNDLE,
66+
Material.RED_BUNDLE, Material.BLACK_BUNDLE, Material.BLUE_BUNDLE, Material.BROWN_BUNDLE,
67+
Material.CYAN_BUNDLE, Material.GRAY_BUNDLE, Material.GREEN_BUNDLE, Material.LIGHT_BLUE_BUNDLE,
68+
Material.LIGHT_GRAY_BUNDLE, Material.LIME_BUNDLE, Material.MAGENTA_BUNDLE, Material.ORANGE_BUNDLE,
69+
Material.PINK_BUNDLE, Material.PURPLE_BUNDLE, Material.RED_BUNDLE, Material.WHITE_BUNDLE,
70+
Material.YELLOW_BUNDLE);
6671
private static final int CHUNKS_TO_SCAN = 100;
6772
private final Level addon;
6873
private final Queue<Pair<Integer, Integer>> chunksToCheck;
@@ -469,6 +474,7 @@ private void scanAsync(ChunkPair cp) {
469474

470475
// Scan chests
471476
if (addon.getSettings().isIncludeChests() && CHESTS.contains(m)) {
477+
472478
chestBlocks.add(cp.chunk);
473479
}
474480
// Add the value of the block's material

src/main/java/world/bentobox/level/config/BlockConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import org.bukkit.Bukkit;
1515
import org.bukkit.Material;
16+
import org.bukkit.Registry;
1617
import org.bukkit.World;
1718
import org.bukkit.configuration.ConfigurationSection;
1819
import org.bukkit.configuration.file.YamlConfiguration;
@@ -96,7 +97,7 @@ private Map<Material, Integer> loadBlockValues(YamlConfiguration blockValues2) {
9697
ConfigurationSection blocks = Objects.requireNonNull(blockValues2.getConfigurationSection("blocks"));
9798
Map<Material, Integer> bv = new EnumMap<>(Material.class);
9899
// Update blockvalues to latest settings
99-
Arrays.stream(Material.values()).filter(Material::isBlock)
100+
Registry.MATERIAL.stream().filter(Material::isBlock)
100101
.filter(m -> !m.name().startsWith("LEGACY_"))
101102
.filter(m -> !m.isAir())
102103
.filter(m -> !m.equals(Material.WATER))

src/main/resources/addon.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Level
22
main: world.bentobox.level.Level
33
version: ${version}${build.number}
44
icon: DIAMOND
5-
api-version: 2.5.1
5+
api-version: 2.7.1
66

77
authors: tastybento
88

src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: BentoBox-Level
22
main: world.bentobox.level.LevelPladdon
33
version: ${project.version}${build.number}
4-
api-version: "1.19"
4+
api-version: "1.21"
55

66
authors: [tastybento]
77
contributors: ["The BentoBoxWorld Community"]

src/test/java/world/bentobox/level/LevelTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import world.bentobox.level.config.ConfigSettings;
6767
import world.bentobox.level.listeners.IslandActivitiesListeners;
6868
import world.bentobox.level.listeners.JoinLeaveListener;
69+
import world.bentobox.level.mocks.ServerMocks;
6970

7071
/**
7172
* @author tastybento
@@ -147,6 +148,7 @@ public static void beforeClass() throws IOException {
147148
*/
148149
@Before
149150
public void setUp() throws Exception {
151+
Server server = ServerMocks.newServer();
150152
// Set up plugin
151153
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
152154
when(plugin.getLogger()).thenReturn(Logger.getAnonymousLogger());
@@ -186,7 +188,6 @@ public void setUp() throws Exception {
186188

187189
// Server
188190
PowerMockito.mockStatic(Bukkit.class);
189-
Server server = mock(Server.class);
190191
when(Bukkit.getServer()).thenReturn(server);
191192
when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
192193
when(Bukkit.getPluginManager()).thenReturn(mock(PluginManager.class));
@@ -252,6 +253,7 @@ public void setUp() throws Exception {
252253
*/
253254
@After
254255
public void tearDown() throws Exception {
256+
ServerMocks.unsetBukkitServer();
255257
deleteAll(new File("database"));
256258
}
257259

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package world.bentobox.level.mocks;
2+
3+
import static org.mockito.ArgumentMatchers.notNull;
4+
import static org.mockito.Mockito.doAnswer;
5+
import static org.mockito.Mockito.doReturn;
6+
import static org.mockito.Mockito.mock;
7+
import static org.mockito.Mockito.when;
8+
9+
import java.lang.reflect.Field;
10+
import java.util.HashMap;
11+
import java.util.Locale;
12+
import java.util.Map;
13+
import java.util.Set;
14+
import java.util.logging.Logger;
15+
16+
import org.bukkit.Bukkit;
17+
import org.bukkit.Keyed;
18+
import org.bukkit.NamespacedKey;
19+
import org.bukkit.Registry;
20+
import org.bukkit.Server;
21+
import org.bukkit.Tag;
22+
import org.bukkit.UnsafeValues;
23+
import org.eclipse.jdt.annotation.NonNull;
24+
25+
public final class ServerMocks {
26+
27+
public static @NonNull Server newServer() {
28+
Server mock = mock(Server.class);
29+
30+
Logger noOp = mock(Logger.class);
31+
when(mock.getLogger()).thenReturn(noOp);
32+
when(mock.isPrimaryThread()).thenReturn(true);
33+
34+
// Unsafe
35+
UnsafeValues unsafe = mock(UnsafeValues.class);
36+
when(mock.getUnsafe()).thenReturn(unsafe);
37+
38+
// Server must be available before tags can be mocked.
39+
Bukkit.setServer(mock);
40+
41+
// Bukkit has a lot of static constants referencing registry values. To initialize those, the
42+
// registries must be able to be fetched before the classes are touched.
43+
Map<Class<? extends Keyed>, Object> registers = new HashMap<>();
44+
45+
doAnswer(invocationGetRegistry -> registers.computeIfAbsent(invocationGetRegistry.getArgument(0), clazz -> {
46+
Registry<?> registry = mock(Registry.class);
47+
Map<NamespacedKey, Keyed> cache = new HashMap<>();
48+
doAnswer(invocationGetEntry -> {
49+
NamespacedKey key = invocationGetEntry.getArgument(0);
50+
// Some classes (like BlockType and ItemType) have extra generics that will be
51+
// erased during runtime calls. To ensure accurate typing, grab the constant's field.
52+
// This approach also allows us to return null for unsupported keys.
53+
Class<? extends Keyed> constantClazz;
54+
try {
55+
//noinspection unchecked
56+
constantClazz = (Class<? extends Keyed>) clazz
57+
.getField(key.getKey().toUpperCase(Locale.ROOT).replace('.', '_')).getType();
58+
} catch (ClassCastException e) {
59+
throw new RuntimeException(e);
60+
} catch (NoSuchFieldException e) {
61+
return null;
62+
}
63+
64+
return cache.computeIfAbsent(key, key1 -> {
65+
Keyed keyed = mock(constantClazz);
66+
doReturn(key).when(keyed).getKey();
67+
return keyed;
68+
});
69+
}).when(registry).get(notNull());
70+
return registry;
71+
})).when(mock).getRegistry(notNull());
72+
73+
// Tags are dependent on registries, but use a different method.
74+
// This will set up blank tags for each constant; all that needs to be done to render them
75+
// functional is to re-mock Tag#getValues.
76+
doAnswer(invocationGetTag -> {
77+
Tag<?> tag = mock(Tag.class);
78+
doReturn(invocationGetTag.getArgument(1)).when(tag).getKey();
79+
doReturn(Set.of()).when(tag).getValues();
80+
doAnswer(invocationIsTagged -> {
81+
Keyed keyed = invocationIsTagged.getArgument(0);
82+
Class<?> type = invocationGetTag.getArgument(2);
83+
if (!type.isAssignableFrom(keyed.getClass())) {
84+
return null;
85+
}
86+
// Since these are mocks, the exact instance might not be equal. Consider equal keys equal.
87+
return tag.getValues().contains(keyed)
88+
|| tag.getValues().stream().anyMatch(value -> value.getKey().equals(keyed.getKey()));
89+
}).when(tag).isTagged(notNull());
90+
return tag;
91+
}).when(mock).getTag(notNull(), notNull(), notNull());
92+
93+
// Once the server is all set up, touch BlockType and ItemType to initialize.
94+
// This prevents issues when trying to access dependent methods from a Material constant.
95+
try {
96+
Class.forName("org.bukkit.inventory.ItemType");
97+
Class.forName("org.bukkit.block.BlockType");
98+
} catch (ClassNotFoundException e) {
99+
throw new RuntimeException(e);
100+
}
101+
102+
return mock;
103+
}
104+
105+
public static void unsetBukkitServer() {
106+
try {
107+
Field server = Bukkit.class.getDeclaredField("server");
108+
server.setAccessible(true);
109+
server.set(null, null);
110+
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
111+
throw new RuntimeException(e);
112+
}
113+
}
114+
115+
private ServerMocks() {
116+
}
117+
118+
}

0 commit comments

Comments
 (0)