Skip to content

Commit

Permalink
Update to 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
WalshyDev committed Oct 1, 2024
1 parent 0a7fea8 commit 9f175bf
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 25 deletions.
32 changes: 13 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<packaging>jar</packaging>

<!-- Project Info -->
<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>
<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>
<url>https://github.com/Slimefun/Slimefun4</url>

<properties>
Expand All @@ -29,8 +29,8 @@
<maven.compiler.testTarget>21</maven.compiler.testTarget>

<!-- Spigot properties -->
<spigot.version>1.20.6</spigot.version>
<spigot.javadocs>https://hub.spigotmc.org/javadocs/spigot/</spigot.javadocs>
<paper.version>1.21.1</paper.version>
<paper.javadocs>https://hub.spigotmc.org/javadocs/spigot/</paper.javadocs>

<!-- Default settings for sonarcloud.io -->
<sonar.projectKey>Slimefun_Slimefun4</sonar.projectKey>
Expand Down Expand Up @@ -238,7 +238,7 @@
<!-- Javadocs -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.7.0</version>
<version>3.10.0</version>

<configuration>
<reportOutputDirectory>${project.basedir}</reportOutputDirectory>
Expand All @@ -251,7 +251,7 @@

<links>
<!-- We can reference the Spigot API in our Javadocs -->
<link>${spigot.javadocs}</link>
<link>${paper.javadocs}</link>
</links>

<!-- We can group packages together in our Javadocs -->
Expand Down Expand Up @@ -367,6 +367,13 @@
<scope>compile</scope>
</dependency>

<!-- Paper -->
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>${paper.version}-R0.1-SNAPSHOT</version>
</dependency>

<!-- Testing dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand All @@ -389,7 +396,7 @@
<dependency>
<groupId>com.github.MockBukkit</groupId>
<artifactId>MockBukkit</artifactId>
<version>c7cc678834</version>
<version>v3.130.2</version>
<scope>test</scope>

<exclusions>
Expand All @@ -401,13 +408,6 @@
</exclusion>
</exclusions>
</dependency>
<!-- Override Spigot with Paper tests as a CommandMap ctor which MockBukkit uses only exists on Paper but not in Spigot -->
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.20.6-R0.1-SNAPSHOT</version>
<scope>test</scope>
</dependency>

<!-- Third party plugin integrations / soft dependencies -->
<dependency>
Expand Down Expand Up @@ -515,12 +515,6 @@
<version>2.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>${spigot.version}-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>authlib</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ public enum MinecraftVersion {
*/
MINECRAFT_1_20_5(20, 5, "1.20.5+"),

/**
* This constant represents Minecraft (Java Edition) Version 1.21
* ("Tricky Trials")
*/
MINECRAFT_1_21(21, 0, "1.21+"),

/**
* This constant represents an exceptional state in which we were unable
* to identify the Minecraft Version we are using
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public void lock() {

@Override
public ItemStack clone() {
return new SlimefunItemStack(id, this);
return new SlimefunItemStack(id, super.clone());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public EnchantmentRune(ItemGroup itemGroup, SlimefunItemStack item, RecipeType r
super(itemGroup, item, recipeType, recipe);

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.tools;

import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;

import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;

import dev.lone.itemsadder.api.CustomBlock;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.ExplosionResult;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
Expand All @@ -17,6 +20,7 @@
import org.bukkit.inventory.ItemStack;

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

private static Constructor<?> pre21ExplodeEventConstructor;
static {
try {
pre21ExplodeEventConstructor = BlockExplodeEvent.class.getConstructor(Block.class, List.class, float.class);
} catch (Exception e) {
Slimefun.logger().log(Level.SEVERE, "Could not find constructor for BlockExplodeEvent", e);
}
}

@ParametersAreNonnullByDefault
public ExplosiveTool(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(itemGroup, item, recipeType, recipe);
Expand Down Expand Up @@ -78,7 +91,7 @@ private void breakBlocks(BlockBreakEvent e, Player p, ItemStack item, Block b, L
List<Block> blocksToDestroy = new ArrayList<>();

if (callExplosionEvent.getValue()) {
BlockExplodeEvent blockExplodeEvent = new BlockExplodeEvent(b, blocks, 0);
BlockExplodeEvent blockExplodeEvent = createNewBlockExplodeEvent(b, blocks, 0);
Bukkit.getServer().getPluginManager().callEvent(blockExplodeEvent);

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

private BlockExplodeEvent createNewBlockExplodeEvent(
Block block,
List<Block> blocks,
float yield
) {
var version = Slimefun.getMinecraftVersion();
if (version.isAtLeast(MinecraftVersion.MINECRAFT_1_21)) {
return new BlockExplodeEvent(block, block.getState(), blocks, yield, ExplosionResult.DESTROY);
} else {
try {
return (BlockExplodeEvent) pre21ExplodeEventConstructor.newInstance(block, blocks, yield);
} catch (Exception e) {
Slimefun.logger().log(Level.SEVERE, "Could not find constructor for BlockExplodeEvent", e);
}

return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import io.github.bakedlibs.dough.items.CustomItemStack;
import io.github.thebusybiscuit.slimefun4.api.exceptions.UnregisteredItemException;
Expand Down Expand Up @@ -110,7 +108,7 @@ void testRecipeType() {
void testIsItem() {
ItemStack item = new CustomItemStack(Material.BEACON, "&cItem Test");
String id = "IS_ITEM_TEST";
SlimefunItem sfItem = TestUtilities.mockSlimefunItem(plugin, id, item);
SlimefunItem sfItem = TestUtilities.mockSlimefunItem(plugin, id, new CustomItemStack(Material.BEACON, "&cItem Test"));
sfItem.register(plugin);

Assertions.assertTrue(sfItem.isItem(sfItem.getItem()));
Expand Down

0 comments on commit 9f175bf

Please sign in to comment.