Skip to content

Commit

Permalink
Upgrade Spigot dependency to 1.21.4
Browse files Browse the repository at this point in the history
AnvilInventory methods that are deprecated are replaced with AnvilView methods... that are still marked experimental. Not much that can be done here.
  • Loading branch information
Jikoo committed Dec 18, 2024
1 parent d1c22f9 commit 8a2c982
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
3 changes: 1 addition & 2 deletions README.MD
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# PlanarEnchanting

![Build](https://github.com/Jikoo/PlanarEnchanting/workflows/Build/badge.svg)
[![Build](https://github.com/Jikoo/PlanarEnchanting/actions/workflows/ci.yml/badge.svg)](https://github.com/Jikoo/PlanarEnchanting/actions/workflows/ci.yml)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=Jikoo_PlanarEnchanting&metric=coverage)](https://sonarcloud.io/dashboard?id=Jikoo_PlanarEnchanting)
Yet another Bukkit-related library.

## About

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.20.6-R0.1-SNAPSHOT</version>
<version>1.21.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private EnchantData(
* report their secondary list as being the primary. For treasure enchantments, the primary tag is
* empty if not available (unlike vanilla).
*
* @return
* @return the corresponding tag
*/
public @NotNull Tag<Material> getPrimaryItems() {
return primaryItems == null ? secondaryItems : primaryItems;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.bukkit.event.enchantment.EnchantItemEvent;
import org.bukkit.event.enchantment.PrepareItemEnchantEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.view.EnchantmentView;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.Plugin;
Expand Down Expand Up @@ -247,7 +248,7 @@ void testSeedChangedPostEnchant() {
private @NotNull PrepareItemEnchantEvent prepareEvent(int bonus) {
return new PrepareItemEnchantEvent(
player,
player.getOpenInventory(),
(EnchantmentView) player.getOpenInventory(),
player.getLocation().getBlock(),
itemStack,
new EnchantmentOffer[3],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.bukkit.Server;
import org.bukkit.Tag;
import org.jetbrains.annotations.NotNull;
import org.mockito.stubbing.Answer;

public final class ServerMocks {

Expand All @@ -41,7 +42,8 @@ public final class ServerMocks {
registers.computeIfAbsent(invocationGetRegistry.getArgument(0), clazz -> {
Registry<?> registry = mock();
Map<NamespacedKey, Keyed> cache = new HashMap<>();
doAnswer(invocationGetEntry -> {

Answer<Keyed> getOrThrow = invocationGetEntry -> {
NamespacedKey key = invocationGetEntry.getArgument(0);
// Some classes (like BlockType and ItemType) have extra generics that will be
// erased during runtime calls. To ensure accurate typing, grab the constant's field.
Expand All @@ -50,18 +52,30 @@ public final class ServerMocks {
try {
//noinspection unchecked
constantClazz = (Class<? extends Keyed>) clazz.getField(key.getKey().toUpperCase(Locale.ROOT).replace('.', '_')).getType();
} catch (ClassCastException e) {
} catch (ClassCastException | NoSuchFieldException e) {
throw new RuntimeException(e);
} catch (NoSuchFieldException e) {
return null;
}

return cache.computeIfAbsent(key, key1 -> {
Keyed keyed = mock(constantClazz);
doReturn(key).when(keyed).getKey();
return keyed;
});
};

doAnswer(getOrThrow).when(registry).getOrThrow(notNull());
// For get, return null for nonexistant constants.
doAnswer(invocation -> {
try {
return getOrThrow.answer(invocation);
} catch (RuntimeException e) {
if (e.getCause() instanceof NoSuchFieldException) {
return null;
}
throw e;
}
}).when(registry).get(notNull());

return registry;
}))
.when(mock).getRegistry(notNull());
Expand Down

0 comments on commit 8a2c982

Please sign in to comment.