Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions .github/workflows/auto-merge-dependabot.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ on:
jobs:
build:
runs-on: ubuntu-latest
name: Build Java 17
name: Build Java 21
steps:
- uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-version: '17'
java-version: '21'
cache: 'maven'

- name: Cache SonarCloud packages
Expand Down
35 changes: 30 additions & 5 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,33 @@ on:
jobs:
run-ci:
uses: Jikoo/PlanarActions/.github/workflows/ci_maven.yml@master
store-dependabot-pr-data:
if: "github.actor == 'dependabot[bot]' && github.event_name == 'pull_request'"
uses: Jikoo/PlanarActions/.github/workflows/pr_automerge_prep.yml@master
with:
pr-number: ${{ github.event.number }}
approve-and-merge-dependabot:
if: "github.event_name == 'pull_request' && github.event.pull_request.user.login == 'dependabot[bot]'"
needs: [ "run-ci" ]
runs-on: "ubuntu-latest"
permissions:
contents: write
pull-requests: write
steps:
# Always approve PRs from Dependabot.
- name: Approve
run: gh pr review --approve "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}

# Fetch Dependabot metadata for finer decisionmaking later.
- name: Fetch Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@21025c705c08248db411dc16f3619e6b5f9ea21a
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"

# Enable auto-merge for the PR.
# Auto-merge is used rather than a direct merge so that any other required checks can pass.
- name: Enable auto-merge for minor/patch updates
if: steps.metadata.outputs.update-type == 'version-update:semver-patch' || steps.metadata.outputs.update-type == 'version-update:semver-minor'
run: gh pr merge --auto --squash "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ install:
build_script:
- mvn clean package -B -DskipTests
test_script:
- mvn surefire:test -B
- mvn dependency:properties surefire:test -B
cache:
- C:\Users\appveyor\.m2
artifacts:
Expand Down
41 changes: 23 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,23 @@
<groupId>com.github.jikoo</groupId>
<artifactId>enchantableblocks</artifactId>
<name>EnchantableBlocks</name>
<version>4.1.1-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.release>17</maven.compiler.release>
<maven.compiler.release>21</maven.compiler.release>
<versions.fastutil>8.5.18</versions.fastutil>
<!-- Required so ${argLine} can be evaluated and edited by plugins (i.e. jacoco) before surefire -->
<argLine/>
</properties>

<profiles>
<profile>
<id>sonarcloud</id>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<sonar.projectKey>Jikoo_EnchantableBlocks</sonar.projectKey>
<sonar.projectKey>jikoo_enchantableblocks</sonar.projectKey>
<sonar.organization>jikoo</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.language>java</sonar.language>
Expand Down Expand Up @@ -61,8 +59,8 @@

<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>jitpack.io</id>
Expand All @@ -78,9 +76,9 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.21-R0.1-SNAPSHOT</version>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.21.11-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -93,7 +91,7 @@
<dependency>
<groupId>com.github.jikoo</groupId>
<artifactId>planarenchanting</artifactId>
<version>2.0.1</version>
<version>fe946163f8</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -144,13 +142,25 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.14.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>properties</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.4</version>
<configuration>
<forkCount>2</forkCount>
<reuseForks>false</reuseForks>
<argLine>@{argLine} -javaagent:${org.mockito:mockito-core:jar} -Xshare:off</argLine>
</configuration>
</plugin>
<plugin>
Expand All @@ -165,11 +175,6 @@
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
<!--
~ Unfortunately, the minimizeJar option actually breaks build.
~ As a (hopefully temporary) workaround, explicitly declare classes used.
~ Watch MSHADE-366 for a fix.
-->
<filters>
<filter>
<artifact>com.github.jikoo:*</artifact>
Expand Down
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## EnchantableBlocks
[![Build](https://github.com/Jikoo/EnchantableBlocks/actions/workflows/ci.yml/badge.svg)](https://github.com/Jikoo/EnchantableBlocks/actions/workflows/ci.yml)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=Jikoo_EnchantableBlocks&metric=alert_status)](https://sonarcloud.io/dashboard?id=Jikoo_EnchantableBlocks)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=Jikoo_EnchantableBlocks&metric=coverage)](https://sonarcloud.io/dashboard?id=Jikoo_EnchantableBlocks)
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=Jikoo_EnchantableBlocks&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=Jikoo_EnchantableBlocks)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=jikoo_enchantableblocks&metric=alert_status)](https://sonarcloud.io/dashboard?id=jikoo_enchantableblocks)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=jikoo_enchantableblocks&metric=coverage)](https://sonarcloud.io/dashboard?id=jikoo_enchantableblocks)
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=jikoo_enchantableblocks&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=jikoo_enchantableblocks)

EnchantableBlocks is a Bukkit plugin adding effects for enchantments on blocks.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
import com.github.jikoo.enchantableblocks.listener.TableEnchanter;
import com.github.jikoo.enchantableblocks.listener.WorldListener;
import com.github.jikoo.enchantableblocks.registry.EnchantableBlockManager;
import java.io.File;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.java.JavaPluginLoader;
import org.jetbrains.annotations.NotNull;

/**
Expand All @@ -22,25 +19,22 @@ public class EnchantableBlocksPlugin extends JavaPlugin {

private EnchantableBlockManager blockManager;

public EnchantableBlocksPlugin() {
super();
}

public EnchantableBlocksPlugin(
@NotNull JavaPluginLoader loader,
@NotNull PluginDescriptionFile description,
@NotNull File dataFolder,
@NotNull File file) {
super(loader, description, dataFolder, file);
}

@Override
public void onLoad() {
this.blockManager = new EnchantableBlockManager(this);
}

@Override
public void onEnable() {
try {
Class.forName("io.papermc.paper.configuration.ServerConfiguration");
} catch (ClassNotFoundException e) {
getLogger().severe("EnchantableBlocks requires Paper; Spigot's enchantment API is missing features.");
getLogger().severe("Please vote for https://hub.spigotmc.org/jira/browse/SPIGOT-7838 for Spigot support.");
getServer().getPluginManager().disablePlugin(this);
return;
}

this.saveDefaultConfig();

// Register generic listeners for block management.
Expand Down Expand Up @@ -85,15 +79,15 @@ public boolean onCommand(
@NotNull String label,
@NotNull String @NotNull [] args) {
if (args.length < 1 || !args[0].equalsIgnoreCase("reload")) {
sender.sendMessage("EnchantableBlocks v" + getDescription().getVersion());
sender.sendMessage("EnchantableBlocks v" + getPluginMeta().getVersion());
return false;
}

this.reloadConfig();
this.blockManager.getRegistry().reload();
sender.sendMessage(
"[EnchantableBlocks v"
+ getDescription().getVersion()
+ getPluginMeta().getVersion()
+ "] Reloaded config and registry cache.");
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,21 +143,25 @@ public boolean shouldPause(final @Nullable Event event) {

ItemStack input;
ItemStack result;
CookingRecipe<?> recipe;
if (event instanceof FurnaceSmeltEvent smeltEvent) {
// Special case FurnaceSmeltEvent: smelt has not completed, input and result are different.
// Decrease input for post-smelt
input = smeltEvent.getSource().clone();
input.setAmount(input.getAmount() - 1);
// Use post-smelt result
result = smeltEvent.getResult();
// FurnaceSmeltEvent is the only pause event that provides the active recipe.
recipe = smeltEvent.getRecipe();
} else {
// In all other cases use current contents of furnace.
FurnaceInventory inventory = furnace.getInventory();
input = inventory.getSmelting();
result = inventory.getResult();
recipe = null;
}

return shouldPause(furnace, input, result);
return shouldPause(furnace, input, result, recipe);
}

/**
Expand All @@ -172,7 +176,9 @@ public boolean shouldPause(final @Nullable Event event) {
private boolean shouldPause(
final @NotNull Furnace furnace,
final @Nullable ItemStack input,
final @Nullable ItemStack result) {
final @Nullable ItemStack result,
final @Nullable CookingRecipe<?> recipe
) {
if (!this.canPause()) {
return false;
}
Expand All @@ -182,13 +188,15 @@ private boolean shouldPause(
return false;
}

return isFreezableState(furnace.getInventory(), input, result);
return isFreezableState(furnace.getInventory(), input, result, recipe);
}

private boolean isFreezableState(
final @NotNull FurnaceInventory inventory,
final @Nullable ItemStack input,
final @Nullable ItemStack result) {
final @Nullable ItemStack result,
@Nullable CookingRecipe<?> recipe
) {
// Is there no input?
if (ItemUtil.isEmpty(input)) {
return true;
Expand All @@ -202,7 +210,10 @@ private boolean isFreezableState(
}
}

CookingRecipe<?> recipe = getRegistration().getFurnaceRecipe(inventory);
// If the recipe wasn't provided, look it up.
if (recipe == null) {
recipe = getRegistration().getFurnaceRecipe(inventory);
}

// Does the current smelting item not have a recipe?
if (recipe == null) {
Expand Down Expand Up @@ -263,7 +274,7 @@ public boolean resume(boolean checkState) {
}

FurnaceInventory inventory = furnace.getInventory();
if (checkState && isFreezableState(inventory, inventory.getSmelting(), inventory.getResult())) {
if (checkState && isFreezableState(inventory, inventory.getSmelting(), inventory.getResult(), null)) {
return false;
}

Expand Down Expand Up @@ -377,7 +388,7 @@ static void update(

plugin.getServer().getScheduler().runTask(plugin, () -> {
boolean shouldPause =
enchantableFurnace.shouldPause(furnace, inventory.getSmelting(), inventory.getResult());
enchantableFurnace.shouldPause(furnace, inventory.getSmelting(), inventory.getResult(), null);
if (enchantableFurnace.isPaused() == shouldPause) {
enchantableFurnace.updating = false;
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.github.jikoo.enchantableblocks.block.impl.furnace;

import com.github.jikoo.enchantableblocks.registry.EnchantableBlockManager;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.IntSupplier;
import org.bukkit.block.Furnace;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand All @@ -19,6 +17,9 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.VisibleForTesting;

import java.util.concurrent.ThreadLocalRandom;
import java.util.function.IntSupplier;

/**
* Listener for furnace-specific events.
*/
Expand Down
Loading