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
27 changes: 3 additions & 24 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,9 @@ jobs:
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"
uses: Jikoo/PlanarActions/.github/workflows/dependabot_automerge.yml@master
with:
pr-url: ${{github.event.pull_request.html_url}}
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}}
13 changes: 8 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@

<repositories>
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
<id>spigotmc</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>jitpack.io</id>
Expand All @@ -76,8 +76,8 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.21.11-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
Expand All @@ -91,7 +91,7 @@
<dependency>
<groupId>com.github.jikoo</groupId>
<artifactId>planarenchanting</artifactId>
<version>fe946163f8</version>
<version>3.0.4</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -175,6 +175,9 @@
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
<filters>
<filter>
<artifact>com.github.jikoo:*</artifact>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,12 @@ public class EnchantableBlocksPlugin extends JavaPlugin {

private EnchantableBlockManager blockManager;

@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();

this.blockManager = new EnchantableBlockManager(this);

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

this.reloadConfig();
this.blockManager.getRegistry().reload();
sender.sendMessage(
"[EnchantableBlocks v"
+ getPluginMeta().getVersion()
+ getDescription().getVersion()
+ "] Reloaded config and registry cache.");
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import com.github.jikoo.enchantableblocks.block.EnchantableBlock;
import com.github.jikoo.enchantableblocks.registry.EnchantableBlockManager;
import com.github.jikoo.enchantableblocks.util.MathHelper;
import com.github.jikoo.planarenchanting.util.ItemUtil;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Furnace;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.event.Event;
import org.bukkit.event.inventory.FurnaceSmeltEvent;
import org.bukkit.event.block.BlockCookEvent;
import org.bukkit.inventory.CookingRecipe;
import org.bukkit.inventory.FurnaceInventory;
import org.bukkit.inventory.ItemStack;
Expand All @@ -20,6 +19,8 @@
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.VisibleForTesting;

import java.lang.reflect.Method;

/**
* Track and manage effects for enchanted furnace variants.
*/
Expand Down Expand Up @@ -144,15 +145,31 @@ 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.
if (event instanceof BlockCookEvent cookEvent) {
// Special case BlockCookEvent: smelt has not completed, input and result are different.
// On Paper, the BlockCookEvent also provides recipes.
try {
Method getRecipe = BlockCookEvent.class.getDeclaredMethod("getRecipe");
recipe = (CookingRecipe<?>) getRecipe.invoke(cookEvent);
} catch (ReflectiveOperationException | ClassCastException e) {
recipe = null;
}
// Decrease input for post-smelt
input = smeltEvent.getSource().clone();
input = cookEvent.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();
result = cookEvent.getResult();
ItemStack output = furnace.getInventory().getResult();
if (output != null && output.getType() != Material.AIR) {
// There's an edge case where a plugin messes with the event and the existing result might mismatch.
// This will cause undefined implementation-specific behavior. Just let it go.
if (!output.isSimilar(result)) {
return false;
}
// Otherwise, clone and add up amounts.
result = result.clone();
result.setAmount(result.getAmount() + output.getAmount());
}
} else {
// In all other cases use current contents of furnace.
FurnaceInventory inventory = furnace.getInventory();
Expand Down Expand Up @@ -198,13 +215,13 @@ private boolean isFreezableState(
@Nullable CookingRecipe<?> recipe
) {
// Is there no input?
if (ItemUtil.isEmpty(input)) {
if (input == null || input.getType() == Material.AIR || input.getAmount() <= 0) {
return true;
}

// Is the result slot too full for more product?
if (!ItemUtil.isEmpty(result)) {
int stack = result.getType().getMaxStackSize();
if (result != null && result.getType() != Material.AIR) {
int stack = result.getMaxStackSize();
if (result.getAmount() >= stack) {
return true;
}
Expand Down Expand Up @@ -278,9 +295,12 @@ public boolean resume(boolean checkState) {
return false;
}

furnace.setBurnTime(
MathHelper.clampPositiveShort(((long) furnace.getBurnTime()) + this.getFrozenTicks()));
furnace.update(true);
// If the furnace is burning for longer than the client can display correctly, don't clamp it.
// Whoever caused the problem should probably deal with it.
if (furnace.getBurnTime() < Short.MAX_VALUE) {
furnace.setBurnTime(MathHelper.clampPositiveShort(furnace.getBurnTime() + this.getFrozenTicks()));
furnace.update(true);
}
this.setFrozenTicks((short) 0);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void applyFortune(
@NotNull FurnaceSmeltEvent event,
@NotNull IntSupplier bonusCalculator) {
ItemStack result = event.getResult();
int tillFullStack = result.getType().getMaxStackSize() - result.getAmount();
int tillFullStack = result.getMaxStackSize() - result.getAmount();

// Ignore results that are already full.
if (tillFullStack == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ protected EnchantableBlockConfig(@NotNull ConfigurationSection configurationSect
this.tableEnchantability = new EnchantabilitySetting(
section,
"tableEnchantability",
Enchantability.STONE);
new Enchantability(5)
);
this.tableDisabledEnchants = new SetEnchantSetting(
section,
"tableDisabledEnchantments",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.github.jikoo.enchantableblocks.config.data;

import com.github.jikoo.planarenchanting.table.Enchantability;
import com.github.jikoo.planarenchanting.table.EnchantabilityCategory;
import com.github.jikoo.planarwrappers.config.ParsedSimpleSetting;
import java.lang.reflect.Field;
import java.util.Locale;
import org.bukkit.configuration.ConfigurationSection;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -31,17 +30,7 @@ public EnchantabilitySetting(
} catch (NumberFormatException ignored) {
// Not a number, may be a field name.
}
value = value.toUpperCase(Locale.ROOT);
try {
Field field = Enchantability.class.getDeclaredField(value);
Object fieldValue = field.get(null);
if (fieldValue instanceof Enchantability enchantability) {
return enchantability;
}
return null;
} catch (NoSuchFieldException | IllegalAccessException e) {
return null;
}
return EnchantabilityCategory.get(value);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@

import com.github.jikoo.enchantableblocks.registry.EnchantableBlockRegistry;
import com.github.jikoo.enchantableblocks.util.enchant.BlockAnvil;
import com.github.jikoo.enchantableblocks.util.enchant.BlockAnvilBehavior;
import com.github.jikoo.planarenchanting.anvil.AnvilResult;
import com.github.jikoo.planarenchanting.util.ItemUtil;
import com.github.jikoo.planarenchanting.anvil.ComponentAnvilFunctions;
import com.github.jikoo.planarenchanting.anvil.ComponentTemperer;
import com.github.jikoo.planarenchanting.anvil.ComponentViewState;
import com.github.jikoo.planarenchanting.anvil.MetaAnvilFunctions;
import com.github.jikoo.planarenchanting.anvil.MetaTemperer;
import com.github.jikoo.planarenchanting.anvil.MetaViewState;
import com.github.jikoo.planarenchanting.anvil.WorkPiece;
import com.github.jikoo.planarenchanting.util.ServerCapabilities;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand All @@ -23,6 +31,7 @@ public class AnvilEnchanter implements Listener {

private final Plugin plugin;
private final EnchantableBlockRegistry registry;
private final BlockAnvil<?> anvil;

/**
* Construct a new {@code AnvilEnchanter} to provide enchantments for blocks.
Expand All @@ -33,6 +42,18 @@ public class AnvilEnchanter implements Listener {
public AnvilEnchanter(@NotNull Plugin plugin, @NotNull EnchantableBlockRegistry registry) {
this.plugin = plugin;
this.registry = registry;

if (ServerCapabilities.DATA_COMPONENT) {
anvil = new BlockAnvil<>(
view1 -> new WorkPiece<>(new ComponentViewState(view1), ComponentTemperer.INSTANCE),
ComponentAnvilFunctions.INSTANCE
);
} else {
anvil = new BlockAnvil<>(
view1 -> new WorkPiece<>(new MetaViewState(view1), MetaTemperer.INSTANCE),
MetaAnvilFunctions.INSTANCE
);
}
}

@EventHandler(priority = EventPriority.HIGH)
Expand All @@ -55,8 +76,7 @@ void onPrepareAnvil(@NotNull PrepareAnvilEvent event) {
return;
}

var operation = new BlockAnvil(registration, clicker.getWorld().getName());
final var result = operation.getResult(view);
final var result = anvil.getResult(view, new BlockAnvilBehavior<>(registration, clicker.getWorld().getName()));

if (result == AnvilResult.EMPTY) {
return;
Expand Down Expand Up @@ -95,9 +115,11 @@ void onPrepareAnvil(@NotNull PrepareAnvilEvent event) {
boolean areItemsInvalid(
@Nullable ItemStack base,
@Nullable ItemStack addition) {
return ItemUtil.isEmpty(base)
return base == null
|| base.getType() == Material.AIR
|| base.getAmount() != 1
|| ItemUtil.isEmpty(addition)
|| addition == null
|| addition.getAmount() < 1
|| (addition.getType() != Material.ENCHANTED_BOOK && addition.getType() != base.getType());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import com.github.jikoo.planarenchanting.table.EnchantingTable;
import com.github.jikoo.planarenchanting.table.TableEnchantListener;
import com.google.common.collect.Multimap;
import java.util.ArrayList;
import java.util.function.BiPredicate;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
Expand All @@ -14,10 +12,14 @@
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.VisibleForTesting;

import java.util.ArrayList;
import java.util.function.BiPredicate;

/**
* Listener for handling enchanting in an enchantment table.
*/
public class TableEnchanter extends TableEnchantListener {

private final EnchantableBlockRegistry registry;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ public EmptyCookingRecipe(@NotNull NamespacedKey key) {
key,
new ItemStack(Material.DIRT),
new RecipeChoice() {
@NotNull
/**
* @deprecated This exists only because the Bukkit API is very, very backwards-compatibility-friendly.
* @return an empty ItemStack
*/
@Deprecated(since = "1.13.1")
@Override
public ItemStack getItemStack() {
public @NotNull ItemStack getItemStack() {
return new ItemStack(Material.AIR);
}

@NotNull
@Override
public RecipeChoice clone() {
public @NotNull RecipeChoice clone() {
try {
return (RecipeChoice) super.clone();
} catch (CloneNotSupportedException e) {
Expand All @@ -56,7 +59,8 @@ public int hashCode() {
}
},
0,
0);
0
);
}

@Override
Expand Down
Loading
Loading