Skip to content

Commit

Permalink
Merge branch 'refs/heads/walshy/mc-1.21' into walshy/mc-1.21-itemstac…
Browse files Browse the repository at this point in the history
…ks-of

# Conflicts:
#	pom.xml
#	src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java
  • Loading branch information
Intybyte committed Oct 1, 2024
2 parents 3cd90ba + 00da02c commit c3d9a6c
Show file tree
Hide file tree
Showing 18 changed files with 253 additions and 50 deletions.
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
default: help

.PHONY: help
help:
@echo " * gen-biomes version=<version> - Generate biomes for the given version"

.PHONY: gen-biomes
gen-biomes:
@echo "Generating biomes for $(version)"
@curl "https://raw.githubusercontent.com/MockBukkit/MockBukkit/refs/heads/v$(version)/src/main/resources/keyed/worldgen/biome.json" -s \
| jq '[ .values[].key]' \
> "src/test/resources/biomes/$(version).x.json"
7 changes: 4 additions & 3 deletions jitpack.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
before_install:
- sdk install java 17.0.1-open
- sdk use java 17.0.1-open
- sdk install java 21.0.2-open
- sdk use java 21.0.2-open
- sdk install maven

jdk:
- openjdk17
- openjdk21
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
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 @@ -371,7 +371,8 @@
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.21.1-R0.1-SNAPSHOT</version>
<version>${paper.version}-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<!-- Testing dependencies -->
Expand All @@ -394,10 +395,9 @@
</dependency>
<!-- This needs to be before Spigot because MockBukkit will fail otherwise. -->
<dependency>
<groupId>com.github.seeseemelk</groupId>
<groupId>com.github.MockBukkit</groupId>
<artifactId>MockBukkit</artifactId>
<!-- <version>3.123.0</version> -->
<version>dev-3fec4e7b</version>
<version>v3.130.2</version>
<scope>test</scope>

<exclusions>
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.x"),

/**
* This constant represents Minecraft (Java Edition) Version 1.21
* ("Tricky Trials")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.thebusybiscuit.slimefun4.core.guide.options;

import java.util.List;
import java.util.Optional;

import org.bukkit.Material;
Expand Down Expand Up @@ -31,7 +32,13 @@ public Optional<ItemStack> getDisplayItem(Player p, ItemStack guide) {

if (registry.isResearchingEnabled() && registry.isResearchFireworkEnabled()) {
boolean enabled = getSelectedOption(p, guide).orElse(true);
ItemStack item = new CustomItemStack(Material.FIREWORK_ROCKET, "&bFireworks: &" + (enabled ? "aYes" : "4No"), "", "&7You can now toggle whether you", "&7will be presented with a big firework", "&7upon researching an item.", "", "&7\u21E8 &eClick to " + (enabled ? "disable" : "enable") + " your fireworks");

String optionState = enabled ? "enabled" : "disabled";
List<String> lore = Slimefun.getLocalization().getMessages(p, "guide.options.fireworks." + optionState + ".text");
lore.add("");
lore.add("&7\u21E8 " + Slimefun.getLocalization().getMessage(p, "guide.options.fireworks." + optionState + ".click"));

ItemStack item = new CustomItemStack(Material.FIREWORK_ROCKET, lore);
return Optional.of(item);
} else {
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ public Optional<ItemStack> getDisplayItem(Player p, ItemStack guide) {
}

ItemMeta meta = item.getItemMeta();
meta.setDisplayName(ChatColor.GRAY + "Slimefun Guide Type: " + ChatColor.YELLOW + ChatUtils.humanize(selectedMode.name()));
meta.setDisplayName(ChatColor.GRAY + Slimefun.getLocalization().getMessage(p, "guide.modes.selected") +
ChatColor.YELLOW + Slimefun.getLocalization().getMessage(p, "guide.modes." + selectedMode.name()));
List<String> lore = new ArrayList<>();
lore.add("");
lore.add((selectedMode == SlimefunGuideMode.SURVIVAL_MODE ? ChatColor.GREEN : ChatColor.GRAY) + "Survival Mode");
lore.add((selectedMode == SlimefunGuideMode.CHEAT_MODE ? ChatColor.GREEN : ChatColor.GRAY) + "Cheat Sheet");
lore.add((selectedMode == SlimefunGuideMode.SURVIVAL_MODE ? ChatColor.GREEN : ChatColor.GRAY) + Slimefun.getLocalization().getMessage(p, "guide.modes.SURVIVAL_MODE"));
lore.add((selectedMode == SlimefunGuideMode.CHEAT_MODE ? ChatColor.GREEN : ChatColor.GRAY) + Slimefun.getLocalization().getMessage(p, "guide.modes.CHEAT_MODE"));

lore.add("");
lore.add(ChatColor.GRAY + "\u21E8 " + ChatColor.YELLOW + "Click to change the type");
lore.add(ChatColor.GRAY + "\u21E8 " + ChatColor.YELLOW + Slimefun.getLocalization().getMessage(p, "guide.modes.change"));
meta.setLore(lore);
item.setItemMeta(meta);

Expand Down Expand Up @@ -115,4 +116,4 @@ public void setSelectedOption(Player p, ItemStack guide, SlimefunGuideMode value
guide.setItemMeta(SlimefunGuide.getItem(value).getItemMeta());
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ private boolean download(int version) {
downloadMonitor(HttpResponse.BodyHandlers.ofFile(file.toPath()))
);


if (response.statusCode() >= 200 && response.statusCode() < 300) {
plugin.getLogger().log(Level.INFO, "Successfully downloaded {0} build: #{1}", new Object[] { JAR_NAME, version });

Expand All @@ -246,6 +245,8 @@ private boolean download(int version) {
metricVersion = String.valueOf(version);
hasDownloadedUpdate = true;
return true;
} else {
plugin.getLogger().log(Level.WARNING, "Failed to download the latest jar file from GitHub. Response code: {0}", response.statusCode());
}
} catch (InterruptedException | JsonParseException e) {
plugin.getLogger().log(Level.WARNING, "Failed to fetch the latest jar file from the builds page. Perhaps GitHub is down? Response: {0}", e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ 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;
if (mat.isLegacy() || !mat.isItem()) continue;

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
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;
Expand All @@ -18,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 @@ -49,6 +52,17 @@ 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 {
if (Slimefun.getMinecraftVersion().isBefore(MinecraftVersion.MINECRAFT_1_21)) {
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 @@ -192,7 +206,19 @@ private BlockExplodeEvent createNewBlockExplodeEvent(
List<Block> blocks,
float yield
) {
// TODO: Support older vers
return new BlockExplodeEvent(block, block.getState(), blocks, yield, ExplosionResult.DESTROY);
var version = Slimefun.getMinecraftVersion();
if (version.isAtLeast(MinecraftVersion.MINECRAFT_1_21)) {
return new BlockExplodeEvent(block, block.getState(), blocks, yield, ExplosionResult.DESTROY);
} else if (pre21ExplodeEventConstructor != null) {
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;
} else {
throw new IllegalStateException("BlockExplodeEvent constructor not found");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@ public String toJSON() {
return new GsonBuilder().create().toJson(data);
}

}
}
21 changes: 21 additions & 0 deletions src/main/resources/languages/en/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,28 @@ guide:
name: '&aIs something missing?'
lore: 'Click to add your own translation'

modes:
selected: 'Slimefun Guide Type: '
change: 'Click to change the type'
SURVIVAL_MODE: 'Survival Mode'
CHEAT_MODE: 'Cheat Sheet'

options:
fireworks:
enabled:
text:
- '&bFireworks: &aYes'
- ''
- '&7You can now toggle whether you'
- '&7will see fireworks upon researching an item.'
click: '&eClick to disable your fireworks'
disabled:
text:
- '&bFireworks: &4No'
- ''
- '&7You can now toggle whether you'
- '&7will see fireworks upon researching an item.'
click: '&eClick to enable your fireworks'
learning-animation:
enabled:
text:
Expand Down
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
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
package io.github.thebusybiscuit.slimefun4.implementation.listeners;

import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import be.seeseemelk.mockbukkit.MockBukkit;
import be.seeseemelk.mockbukkit.ServerMock;
import be.seeseemelk.mockbukkit.entity.ItemEntityMock;
import io.github.bakedlibs.dough.items.CustomItemStack;
import io.github.thebusybiscuit.slimefun4.api.exceptions.TagMisconfigurationException;
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.player.PlayerBackpack;
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.SlimefunBackpack;
import io.github.thebusybiscuit.slimefun4.test.TestUtilities;
import io.github.thebusybiscuit.slimefun4.test.mocks.InventoryViewWrapper;
import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
Expand All @@ -26,21 +36,10 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

import io.github.bakedlibs.dough.items.CustomItemStack;
import io.github.thebusybiscuit.slimefun4.api.exceptions.TagMisconfigurationException;
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.player.PlayerBackpack;
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.SlimefunBackpack;
import io.github.thebusybiscuit.slimefun4.test.TestUtilities;
import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;

import be.seeseemelk.mockbukkit.MockBukkit;
import be.seeseemelk.mockbukkit.ServerMock;
import be.seeseemelk.mockbukkit.entity.ItemEntityMock;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

class TestBackpackListener {

Expand Down Expand Up @@ -147,10 +146,11 @@ void testBackpackDropNormalItem() throws InterruptedException {
private boolean isAllowed(String id, ItemStack item) throws InterruptedException {
Player player = server.addPlayer();
Inventory inv = openMockBackpack(player, id, 9).getInventory();
InventoryView playerInv = InventoryViewWrapper.wrap(player.getOpenInventory());

int slot = 7;
inv.setItem(slot, item);
InventoryClickEvent event = new InventoryClickEvent(player.getOpenInventory(), SlotType.CONTAINER, slot, ClickType.LEFT, InventoryAction.PICKUP_ONE);
InventoryClickEvent event = new InventoryClickEvent(playerInv, SlotType.CONTAINER, slot, ClickType.LEFT, InventoryAction.PICKUP_ONE);
listener.onClick(event);
return !event.isCancelled();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package io.github.thebusybiscuit.slimefun4.test.mocks;

import be.seeseemelk.mockbukkit.inventory.InventoryViewMock;
import org.bukkit.entity.HumanEntity;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* Temporary class which implements {@link #getItem(int)} and {@link #setItem(int, ItemStack)}
* provided {@link #getInventory(int)} and {@link #convertSlot(int)} are implemented by the backing
* {@link InventoryView}
* <p>
* This class should be replaced by MockBukkit when <a href="https://github.com/MockBukkit/MockBukkit/pull/1011">this pr</a>
* is merged.
* <br>
* Code is taken directly from CraftBukkit <a href="https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/browse/src/main/java/org/bukkit/craftbukkit/inventory/CraftAbstractInventoryView.java">here</a>.
*
* @author md5sha256
*/
public class InventoryViewWrapper extends InventoryViewMock {

private InventoryViewWrapper(HumanEntity player,
String name,
Inventory top,
Inventory bottom,
InventoryType type) {
super(player, name, top, bottom, type);
}

@Nonnull
public static InventoryViewWrapper wrap(@Nonnull InventoryView inventoryView) {
HumanEntity player = inventoryView.getPlayer();
String name = inventoryView.getTitle();
Inventory top = inventoryView.getTopInventory();
Inventory bottom = inventoryView.getBottomInventory();
InventoryType inventoryType = inventoryView.getType();
return new InventoryViewWrapper(player, name, top, bottom, inventoryType);
}

@Override
@Nullable
public ItemStack getItem(int slot) {
Inventory inventory = getInventory(slot);
return (inventory == null) ? null : inventory.getItem(convertSlot(slot));
}

@Override
public void setItem(int slot, @Nullable ItemStack item) {
Inventory inventory = getInventory(slot);
if (inventory != null) {
inventory.setItem(convertSlot(slot), item);
}
}
}
Loading

0 comments on commit c3d9a6c

Please sign in to comment.