Skip to content

Commit

Permalink
Merge upstream (#44)
Browse files Browse the repository at this point in the history
* e2e testing initial

* Setup matrix

* Download tester

* Jeff's changes

* capitalized Chosen

* Update dependency org.apache.maven.plugins:maven-shade-plugin to v3.5.1

* fix breaking sf block with not unlocked item duping contents (Slimefun#3976)

* [CI skip] Update actions/setup-java action to v3.13.0

* [CI skip] Update dependency me.clip:placeholderapi to v2.11.4

* [CI skip] Update actions/checkout action to v4

* [CI skip] Update dependency com.github.LoneDev6:itemsadder-api to v3.5.0c-r5

* [CI skip] Update dependency org.apache.maven.plugins:maven-javadoc-plugin to v3.6.0

* [CI skip] Update dependency org.sonarsource.scanner.maven:sonar-maven-plugin to v3.10.0.2594

* [CI skip] Update dependency com.sk89q.worldedit:worldedit-core to v7.2.16

* [CI skip] Update dependency com.sk89q.worldedit:worldedit-bukkit to v7.2.16

* [CI skip] Update dependency com.gmail.nossr50.mcMMO:mcMMO to v2.1.224

* [CI skip] Update dependency org.mockito:mockito-core to v5.6.0

* updated dough version (Slimefun#3991)

* [CI skip] Update dependency com.github.LoneDev6:itemsadder-api to v3.6.1

* [CI skip] Update dependency com.sk89q.worldedit:worldedit-core to v7.2.17

* [CI skip] Update dependency com.sk89q.worldedit:worldedit-bukkit to v7.2.17

* [CI skip] Update dependency com.gmail.nossr50.mcMMO:mcMMO to v2.1.225

* [CI skip] Update dependency org.jacoco:jacoco-maven-plugin to v0.8.11

* [CI skip] Update actions/checkout action to v4.1.1

* [CI skip] Update thollander/actions-comment-pull-request action to v2.4.3

* [CI skip] Update dependency org.apache.maven.plugins:maven-surefire-plugin to v3.2.1

* [CI skip] Update dependency me.clip:placeholderapi to v2.11.5

* Update .github/workflows/e2e-testing.yml

* Update .github/workflows/e2e-testing.yml

* Update .github/workflows/e2e-testing.yml

* Update .github/workflows/e2e-testing.yml

* Add MultiBlockCraftEvent (Updated version of Slimefun#3439) (Slimefun#3928)

* fix taking damage on head collision while wearing elytra cap (Slimefun#3760)

* Remove Lore Check from Slimefun Guide (Slimefun#3969)

* don't consume bookbinder inputs if the output is worse than the input (Slimefun#3925)

Co-authored-by: Jeroen <[email protected]>

* Update .github/workflows/e2e-testing.yml

* Update .github/workflows/e2e-testing.yml

* fix heads showing as steve (Slimefun#4027)

* fix: clean up issues after merging

* chore(style): apply code style

---------

Co-authored-by: Jeffrey <[email protected]>
Co-authored-by: Daniel Walsh <[email protected]>
Co-authored-by: iTwins <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Jeroen <[email protected]>
Co-authored-by: TheBusyBiscuit <[email protected]>
Co-authored-by: J3fftw <[email protected]>
Co-authored-by: JustAHuman-xD <[email protected]>
Co-authored-by: Jeroen <[email protected]>
Co-authored-by: Alessio Colombo <[email protected]>
  • Loading branch information
11 people authored and StarWishsama committed Dec 4, 2023
1 parent 8aa175f commit 39fe312
Show file tree
Hide file tree
Showing 17 changed files with 365 additions and 48 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/e2e-testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: End to End Testing

on:
workflow_call:
inputs:
artifact-name:
description: 'Slimefun artifact name'
required: true
type: string

jobs:
e2e-testing:
name: End to End Testing
runs-on: ubuntu-latest
timeout-minutes: 5

strategy:
matrix:
include:
- mcVersion: '1.16.5'
javaVersion: '16'
- mcVersion: '1.17.1'
javaVersion: '17'
- mcVersion: '1.18.2'
javaVersion: '18'
- mcVersion: '1.19.4'
javaVersion: '19'
- mcVersion: '1.20.1'
javaVersion: '20'

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up JDK
uses: actions/[email protected]
with:
distribution: temurin
java-version: ${{ matrix.javaVersion }}
java-package: jdk
architecture: x64

- name: Setup server
run: |
echo 'eula=true' > eula.txt
mkdir plugins
- name: Download ${{ matrix.mcVersion }} Paper
run: |
VERSION="${{ matrix.mcVersion }}"
BUILD_JAR=$(curl -s "https://api.papermc.io/v2/projects/paper/versions/$VERSION/builds" \
| jq '.builds[-1] | "\(.build) \(.downloads.application.name)"' -r)
BUILD=$(echo "$BUILD_JAR" | awk '{print $1}')
JAR_FILE=$(echo "$BUILD_JAR" | awk '{print $2}')
curl -o paper.jar \
"https://api.papermc.io/v2/projects/paper/versions/$VERSION/builds/$BUILD/downloads/$JAR_FILE"
- name: Download Slimefun
uses: actions/download-artifact@v3
with:
name: ${{ inputs.artifact-name }}
path: plugins/

- name: Download e2e-tester
run: |
curl -o e2e-tester.jar https://preview-builds.walshy.dev/download/e2e-tester/main/latest
mv e2e-tester.jar plugins/e2e-tester.jar
- name: Run server
run: |
java -jar paper.jar --nogui
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package io.github.thebusybiscuit.slimefun4.api.events;

import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.inventory.ItemStack;

/**
* This {@link Event} is called when a {@link Player} crafts an item using a {@link MultiBlockMachine}.
* Unlike the {@link MultiBlockInteractEvent}, this event only fires if an output to a craft is expected.
* If this event is cancelled, ingredients will not be consumed and no output item results.
*
* @author char321
* @author JustAHuman
*/
public class MultiBlockCraftEvent extends PlayerEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();

private final MultiBlockMachine machine;
private final ItemStack[] input;
private ItemStack output;
private boolean cancelled;

/**
* Creates a new {@link MultiBlockCraftEvent}.
*
* @param p The player that crafts using a multiblock
* @param machine The multiblock machine used to craft
* @param input The input items of the craft
* @param output The resulting item of the craft
*/
@ParametersAreNonnullByDefault
public MultiBlockCraftEvent(Player p, MultiBlockMachine machine, ItemStack[] input, ItemStack output) {
super(p);
this.machine = machine;
this.input = input;
this.output = output;
}

/**
* Creates a new {@link MultiBlockCraftEvent}.
*
* @param p The player that crafts using a multiblock
* @param machine The multiblock machine used to craft
* @param input The input item of the craft
* @param output The resulting item of the craft
*/
@ParametersAreNonnullByDefault
public MultiBlockCraftEvent(Player p, MultiBlockMachine machine, ItemStack input, ItemStack output) {
this(p, machine, new ItemStack[] {input}, output);
}

/**
* Gets the machine that was used to craft.
*
* @return The {@link MultiBlockMachine} used to craft.
*/
public @Nonnull MultiBlockMachine getMachine() {
return machine;
}

/**
* Gets the input of the craft.
*
* @return The {@link ItemStack ItemStack[]} input that is used in the craft.
*/
public @Nonnull ItemStack[] getInput() {
return input;
}

/**
* Gets the output of the craft.
*
* @return The {@link ItemStack} output that results from the craft.
*/
public @Nonnull ItemStack getOutput() {
return output;
}

/**
* Sets the output of the craft. Keep in mind that this overwrites any existing output.
*
* @param output
* The new item for the event to produce.
*
* @return The previous {@link ItemStack} output that was replaced.
*/
public @Nullable ItemStack setOutput(@Nullable ItemStack output) {
ItemStack oldOutput = this.output;
this.output = output;
return oldOutput;
}

@Override
public boolean isCancelled() {
return cancelled;
}

@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}

public static @Nonnull HandlerList getHandlerList() {
return handlers;
}

@Override
public @Nonnull HandlerList getHandlers() {
return getHandlerList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ protected MachineRecipe findNextRecipe(BlockMenu menu) {

// Just return if no enchantments exist. This shouldn't ever happen. :NotLikeThis:
if (enchantments.size() > 0) {
if (hasIllegalEnchants(storedItemEnchantments) || hasIllegalEnchants(storedTargetEnchantments)) {
return null;
}

ItemStack book = new ItemStack(Material.ENCHANTED_BOOK);

EnchantmentStorageMeta enchantMeta = (EnchantmentStorageMeta) book.getItemMeta();
Expand All @@ -70,6 +74,12 @@ protected MachineRecipe findNextRecipe(BlockMenu menu) {
return null;
}

// If the output is the same as one of the inputs: don't consume items
if (enchantMeta.getStoredEnchants().equals(storedItemEnchantments)
|| enchantMeta.getStoredEnchants().equals(storedTargetEnchantments)) {
return null;
}

book.setItemMeta(enchantMeta);

MachineRecipe recipe = new MachineRecipe(
Expand Down Expand Up @@ -99,6 +109,21 @@ private boolean isCompatible(@Nullable ItemStack item) {
return item != null && item.getType() == Material.ENCHANTED_BOOK;
}

private boolean hasIllegalEnchants(@Nullable Map<Enchantment, Integer> enchantments) {
if (enchantments == null) {
return false;
}

for (Map.Entry<Enchantment, Integer> entry : enchantments.entrySet()) {
if (bypassVanillaMaxLevel.getValue() && entry.getValue() > customMaxLevel.getValue()
|| !bypassVanillaMaxLevel.getValue()
&& entry.getValue() > entry.getKey().getMaxLevel()) {
return true;
}
}
return false;
}

@Override
public ItemStack getProgressBar() {
return new ItemStack(Material.IRON_CHESTPLATE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks;

import io.github.bakedlibs.dough.inventory.InvUtils;
import io.github.thebusybiscuit.slimefun4.api.events.MultiBlockCraftEvent;
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
Expand All @@ -11,6 +12,7 @@
import io.papermc.lib.PaperLib;
import java.util.List;
import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
Expand Down Expand Up @@ -46,12 +48,14 @@ public void onInteract(Player p, Block b) {
if (canCraft(inv, inputs, i)) {
ItemStack output =
RecipeType.getRecipeOutputList(this, inputs.get(i)).clone();
MultiBlockCraftEvent event = new MultiBlockCraftEvent(p, this, inputs.get(i), output);

if (SlimefunUtils.canPlayerUseItem(p, output, true)) {
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled() && SlimefunUtils.canPlayerUseItem(p, output, true)) {
Inventory outputInv = findOutputInventory(output, possibleDispenser, inv);

if (outputInv != null) {
craft(p, b, inv, inputs.get(i), output, outputInv);
craft(p, b, inv, inputs.get(i), event.getOutput(), outputInv);
} else {
Slimefun.getLocalization().sendMessage(p, "machines.full-inventory", true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.github.bakedlibs.dough.items.CustomItemStack;
import io.github.bakedlibs.dough.items.ItemUtils;
import io.github.thebusybiscuit.slimefun4.api.events.MultiBlockCraftEvent;
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
Expand All @@ -11,6 +12,7 @@
import io.papermc.lib.PaperLib;
import java.util.List;
import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
Expand Down Expand Up @@ -54,9 +56,11 @@ public void onInteract(Player p, Block b) {
if (isCraftable(inv, input)) {
ItemStack output =
RecipeType.getRecipeOutputList(this, input).clone();
MultiBlockCraftEvent event = new MultiBlockCraftEvent(p, this, input, output);

if (SlimefunUtils.canPlayerUseItem(p, output, true)) {
craft(p, output, inv, possibleDispenser);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled() && SlimefunUtils.canPlayerUseItem(p, output, true)) {
craft(p, event.getOutput(), inv, possibleDispenser);
}

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.github.bakedlibs.dough.items.ItemUtils;
import io.github.bakedlibs.dough.scheduling.TaskQueue;
import io.github.thebusybiscuit.slimefun4.api.events.MultiBlockCraftEvent;
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.core.multiblocks.MultiBlockMachine;
Expand All @@ -16,6 +17,7 @@
import java.util.Optional;
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.GameMode;
import org.bukkit.Material;
Expand Down Expand Up @@ -85,6 +87,14 @@ public void onInteract(Player p, Block b) {
return;
}

MultiBlockCraftEvent event = new MultiBlockCraftEvent(p, this, input, output);

Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}

ItemStack finalOutput = event.getOutput();
if (p.getGameMode() != GameMode.CREATIVE) {
ItemUtils.consumeItem(input, false);
}
Expand All @@ -94,13 +104,13 @@ public void onInteract(Player p, Block b) {
queue.thenRepeatEvery(20, 5, () -> b.getWorld()
.playEffect(b.getRelative(BlockFace.DOWN).getLocation(), Effect.STEP_SOUND, material));
queue.thenRun(20, () -> {
if (output.getType() != Material.AIR) {
if (finalOutput.getType() != Material.AIR) {
Optional<Inventory> outputChest = OutputChest.findOutputChestFor(b.getRelative(BlockFace.DOWN), output);

if (outputChest.isPresent()) {
outputChest.get().addItem(output.clone());
outputChest.get().addItem(finalOutput.clone());
} else {
b.getWorld().dropItemNaturally(b.getLocation(), output.clone());
b.getWorld().dropItemNaturally(b.getLocation(), finalOutput.clone());
}

SoundEffect.AUTOMATED_PANNING_MACHINE_SUCCESS_SOUND.playAt(b);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks;

import io.github.bakedlibs.dough.items.CustomItemStack;
import io.github.thebusybiscuit.slimefun4.api.events.MultiBlockCraftEvent;
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
Expand All @@ -14,6 +15,7 @@
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
Expand Down Expand Up @@ -77,13 +79,19 @@ public void onInteract(Player p, Block b) {
if (recipeInput != null && SlimefunUtils.isItemSimilar(item, recipeInput, true)) {
ItemStack output = RecipeType.getRecipeOutput(this, recipeInput);
Inventory outputInv = findOutputInventory(output, dispBlock, inv);
MultiBlockCraftEvent event = new MultiBlockCraftEvent(p, this, item, output);

Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}

if (outputInv != null) {
ItemStack removing = item.clone();
removing.setAmount(recipeInput.getAmount());
inv.removeItem(removing);

craft(p, output, dispBlock, inv);
craft(p, event.getOutput(), dispBlock, inv);
} else {
Slimefun.getLocalization().sendMessage(p, "machines.full-inventory", true);
}
Expand Down
Loading

0 comments on commit 39fe312

Please sign in to comment.