Skip to content

Commit 9f175bf

Browse files
committed
Update to 1.21
1 parent 0a7fea8 commit 9f175bf

File tree

6 files changed

+55
-25
lines changed

6 files changed

+55
-25
lines changed

pom.xml

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<packaging>jar</packaging>
1515

1616
<!-- Project Info -->
17-
<description>Slimefun is a Spigot/Paper plugin that simulates a modpack-like atmosphere by adding over 500 new items and recipes to your Minecraft Server.</description>
17+
<description>Slimefun is a Paper plugin that simulates a modpack-like atmosphere by adding over 500 new items and recipes to your Minecraft Server.</description>
1818
<url>https://github.com/Slimefun/Slimefun4</url>
1919

2020
<properties>
@@ -29,8 +29,8 @@
2929
<maven.compiler.testTarget>21</maven.compiler.testTarget>
3030

3131
<!-- Spigot properties -->
32-
<spigot.version>1.20.6</spigot.version>
33-
<spigot.javadocs>https://hub.spigotmc.org/javadocs/spigot/</spigot.javadocs>
32+
<paper.version>1.21.1</paper.version>
33+
<paper.javadocs>https://hub.spigotmc.org/javadocs/spigot/</paper.javadocs>
3434

3535
<!-- Default settings for sonarcloud.io -->
3636
<sonar.projectKey>Slimefun_Slimefun4</sonar.projectKey>
@@ -238,7 +238,7 @@
238238
<!-- Javadocs -->
239239
<groupId>org.apache.maven.plugins</groupId>
240240
<artifactId>maven-javadoc-plugin</artifactId>
241-
<version>3.7.0</version>
241+
<version>3.10.0</version>
242242

243243
<configuration>
244244
<reportOutputDirectory>${project.basedir}</reportOutputDirectory>
@@ -251,7 +251,7 @@
251251

252252
<links>
253253
<!-- We can reference the Spigot API in our Javadocs -->
254-
<link>${spigot.javadocs}</link>
254+
<link>${paper.javadocs}</link>
255255
</links>
256256

257257
<!-- We can group packages together in our Javadocs -->
@@ -367,6 +367,13 @@
367367
<scope>compile</scope>
368368
</dependency>
369369

370+
<!-- Paper -->
371+
<dependency>
372+
<groupId>io.papermc.paper</groupId>
373+
<artifactId>paper-api</artifactId>
374+
<version>${paper.version}-R0.1-SNAPSHOT</version>
375+
</dependency>
376+
370377
<!-- Testing dependencies -->
371378
<dependency>
372379
<groupId>org.junit.jupiter</groupId>
@@ -389,7 +396,7 @@
389396
<dependency>
390397
<groupId>com.github.MockBukkit</groupId>
391398
<artifactId>MockBukkit</artifactId>
392-
<version>c7cc678834</version>
399+
<version>v3.130.2</version>
393400
<scope>test</scope>
394401

395402
<exclusions>
@@ -401,13 +408,6 @@
401408
</exclusion>
402409
</exclusions>
403410
</dependency>
404-
<!-- Override Spigot with Paper tests as a CommandMap ctor which MockBukkit uses only exists on Paper but not in Spigot -->
405-
<dependency>
406-
<groupId>io.papermc.paper</groupId>
407-
<artifactId>paper-api</artifactId>
408-
<version>1.20.6-R0.1-SNAPSHOT</version>
409-
<scope>test</scope>
410-
</dependency>
411411

412412
<!-- Third party plugin integrations / soft dependencies -->
413413
<dependency>
@@ -515,12 +515,6 @@
515515
<version>2.6</version>
516516
<scope>compile</scope>
517517
</dependency>
518-
<dependency>
519-
<groupId>org.spigotmc</groupId>
520-
<artifactId>spigot-api</artifactId>
521-
<version>${spigot.version}-R0.1-SNAPSHOT</version>
522-
<scope>provided</scope>
523-
</dependency>
524518
<dependency>
525519
<groupId>com.mojang</groupId>
526520
<artifactId>authlib</artifactId>

src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ public enum MinecraftVersion {
5555
*/
5656
MINECRAFT_1_20_5(20, 5, "1.20.5+"),
5757

58+
/**
59+
* This constant represents Minecraft (Java Edition) Version 1.21
60+
* ("Tricky Trials")
61+
*/
62+
MINECRAFT_1_21(21, 0, "1.21+"),
63+
5864
/**
5965
* This constant represents an exceptional state in which we were unable
6066
* to identify the Minecraft Version we are using

src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItemStack.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public void lock() {
307307

308308
@Override
309309
public ItemStack clone() {
310-
return new SlimefunItemStack(id, this);
310+
return new SlimefunItemStack(id, super.clone());
311311
}
312312

313313
@Override

src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/runes/EnchantmentRune.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ public EnchantmentRune(ItemGroup itemGroup, SlimefunItemStack item, RecipeType r
5050
super(itemGroup, item, recipeType, recipe);
5151

5252
for (Material mat : Material.values()) {
53-
if (Slimefun.instance().isUnitTest() && mat.isLegacy()) continue;
53+
// TODO: FIgure out behaviour here - we fail on WATER because it isn't an item
54+
if (Slimefun.instance().isUnitTest() && (mat.isLegacy() || !mat.isItem())) continue;
5455

5556
List<Enchantment> enchantments = new ArrayList<>();
5657

src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package io.github.thebusybiscuit.slimefun4.implementation.items.tools;
22

3+
import java.lang.reflect.Constructor;
34
import java.util.ArrayList;
45
import java.util.List;
6+
import java.util.logging.Level;
57

68
import javax.annotation.Nonnull;
79
import javax.annotation.ParametersAreNonnullByDefault;
810

911
import dev.lone.itemsadder.api.CustomBlock;
1012
import org.bukkit.Bukkit;
1113
import org.bukkit.Effect;
14+
import org.bukkit.ExplosionResult;
1215
import org.bukkit.Material;
1316
import org.bukkit.block.Block;
1417
import org.bukkit.entity.Player;
@@ -17,6 +20,7 @@
1720
import org.bukkit.inventory.ItemStack;
1821

1922
import io.github.bakedlibs.dough.protection.Interaction;
23+
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
2024
import io.github.thebusybiscuit.slimefun4.api.events.ExplosiveToolBreakBlocksEvent;
2125
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
2226
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
@@ -48,6 +52,15 @@ public class ExplosiveTool extends SimpleSlimefunItem<ToolUseHandler> implements
4852
private final ItemSetting<Boolean> damageOnUse = new ItemSetting<>(this, "damage-on-use", true);
4953
private final ItemSetting<Boolean> callExplosionEvent = new ItemSetting<>(this, "call-explosion-event", false);
5054

55+
private static Constructor<?> pre21ExplodeEventConstructor;
56+
static {
57+
try {
58+
pre21ExplodeEventConstructor = BlockExplodeEvent.class.getConstructor(Block.class, List.class, float.class);
59+
} catch (Exception e) {
60+
Slimefun.logger().log(Level.SEVERE, "Could not find constructor for BlockExplodeEvent", e);
61+
}
62+
}
63+
5164
@ParametersAreNonnullByDefault
5265
public ExplosiveTool(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
5366
super(itemGroup, item, recipeType, recipe);
@@ -78,7 +91,7 @@ private void breakBlocks(BlockBreakEvent e, Player p, ItemStack item, Block b, L
7891
List<Block> blocksToDestroy = new ArrayList<>();
7992

8093
if (callExplosionEvent.getValue()) {
81-
BlockExplodeEvent blockExplodeEvent = new BlockExplodeEvent(b, blocks, 0);
94+
BlockExplodeEvent blockExplodeEvent = createNewBlockExplodeEvent(b, blocks, 0);
8295
Bukkit.getServer().getPluginManager().callEvent(blockExplodeEvent);
8396

8497
if (!blockExplodeEvent.isCancelled()) {
@@ -186,4 +199,22 @@ private void breakBlock(BlockBreakEvent e, Player p, ItemStack item, Block b, Li
186199
damageItem(p, item);
187200
}
188201

202+
private BlockExplodeEvent createNewBlockExplodeEvent(
203+
Block block,
204+
List<Block> blocks,
205+
float yield
206+
) {
207+
var version = Slimefun.getMinecraftVersion();
208+
if (version.isAtLeast(MinecraftVersion.MINECRAFT_1_21)) {
209+
return new BlockExplodeEvent(block, block.getState(), blocks, yield, ExplosionResult.DESTROY);
210+
} else {
211+
try {
212+
return (BlockExplodeEvent) pre21ExplodeEventConstructor.newInstance(block, blocks, yield);
213+
} catch (Exception e) {
214+
Slimefun.logger().log(Level.SEVERE, "Could not find constructor for BlockExplodeEvent", e);
215+
}
216+
217+
return null;
218+
}
219+
}
189220
}

src/test/java/io/github/thebusybiscuit/slimefun4/implementation/items/TestSlimefunItem.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
import org.junit.jupiter.api.BeforeAll;
1010
import org.junit.jupiter.api.DisplayName;
1111
import org.junit.jupiter.api.Test;
12-
import org.junit.jupiter.params.ParameterizedTest;
13-
import org.junit.jupiter.params.provider.ValueSource;
1412

1513
import io.github.bakedlibs.dough.items.CustomItemStack;
1614
import io.github.thebusybiscuit.slimefun4.api.exceptions.UnregisteredItemException;
@@ -110,7 +108,7 @@ void testRecipeType() {
110108
void testIsItem() {
111109
ItemStack item = new CustomItemStack(Material.BEACON, "&cItem Test");
112110
String id = "IS_ITEM_TEST";
113-
SlimefunItem sfItem = TestUtilities.mockSlimefunItem(plugin, id, item);
111+
SlimefunItem sfItem = TestUtilities.mockSlimefunItem(plugin, id, new CustomItemStack(Material.BEACON, "&cItem Test"));
114112
sfItem.register(plugin);
115113

116114
Assertions.assertTrue(sfItem.isItem(sfItem.getItem()));

0 commit comments

Comments
 (0)