Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d23dc10bc5 | ||
|
|
46c2e3f90a | ||
|
|
1776b668a4 | ||
|
|
10dccd0f38 | ||
|
|
f1918eb1ec | ||
|
|
436b33fde2 |
@@ -9,16 +9,11 @@ import org.bukkit.inventory.MerchantRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
public final class VillagerTrade implements VillagerTradeProxy {
|
||||
@Override
|
||||
public void displayTrade(@NotNull final MerchantRecipe merchantRecipe) {
|
||||
try {
|
||||
// Enables removing final modifier
|
||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
||||
modifiersField.setAccessible(true);
|
||||
|
||||
// Bukkit MerchantRecipe result
|
||||
Field fResult = MerchantRecipe.class.getDeclaredField("result");
|
||||
fResult.setAccessible(true);
|
||||
@@ -31,11 +26,9 @@ public final class VillagerTrade implements VillagerTradeProxy {
|
||||
Field fHandle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
||||
fHandle.setAccessible(true);
|
||||
net.minecraft.server.v1_15_R1.MerchantRecipe handle = (net.minecraft.server.v1_15_R1.MerchantRecipe) fHandle.get(merchantRecipe); // NMS Recipe
|
||||
modifiersField.setInt(fHandle, fHandle.getModifiers() & ~Modifier.FINAL); // Remove final
|
||||
|
||||
Field fSelling = net.minecraft.server.v1_15_R1.MerchantRecipe.class.getDeclaredField("sellingItem");
|
||||
fSelling.setAccessible(true);
|
||||
modifiersField.setInt(fSelling, fSelling.getModifiers() & ~Modifier.FINAL);
|
||||
|
||||
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
|
||||
Display.displayAndFinalize(selling);
|
||||
|
||||
@@ -9,16 +9,11 @@ import org.bukkit.inventory.MerchantRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
public final class VillagerTrade implements VillagerTradeProxy {
|
||||
@Override
|
||||
public void displayTrade(@NotNull final MerchantRecipe merchantRecipe) {
|
||||
try {
|
||||
// Enables removing final modifier
|
||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
||||
modifiersField.setAccessible(true);
|
||||
|
||||
// Bukkit MerchantRecipe result
|
||||
Field fResult = MerchantRecipe.class.getDeclaredField("result");
|
||||
fResult.setAccessible(true);
|
||||
@@ -30,11 +25,9 @@ public final class VillagerTrade implements VillagerTradeProxy {
|
||||
Field fHandle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
||||
fHandle.setAccessible(true);
|
||||
net.minecraft.server.v1_16_R1.MerchantRecipe handle = (net.minecraft.server.v1_16_R1.MerchantRecipe) fHandle.get(merchantRecipe); // NMS Recipe
|
||||
modifiersField.setInt(fHandle, fHandle.getModifiers() & ~Modifier.FINAL); // Remove final
|
||||
|
||||
Field fSelling = net.minecraft.server.v1_16_R1.MerchantRecipe.class.getDeclaredField("sellingItem");
|
||||
fSelling.setAccessible(true);
|
||||
modifiersField.setInt(fSelling, fSelling.getModifiers() & ~Modifier.FINAL);
|
||||
|
||||
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
|
||||
Display.displayAndFinalize(selling);
|
||||
|
||||
@@ -9,16 +9,11 @@ import org.bukkit.inventory.MerchantRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
public final class VillagerTrade implements VillagerTradeProxy {
|
||||
@Override
|
||||
public void displayTrade(@NotNull final MerchantRecipe merchantRecipe) {
|
||||
try {
|
||||
// Enables removing final modifier
|
||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
||||
modifiersField.setAccessible(true);
|
||||
|
||||
// Bukkit MerchantRecipe result
|
||||
Field fResult = MerchantRecipe.class.getDeclaredField("result");
|
||||
fResult.setAccessible(true);
|
||||
@@ -30,11 +25,9 @@ public final class VillagerTrade implements VillagerTradeProxy {
|
||||
Field fHandle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
||||
fHandle.setAccessible(true);
|
||||
net.minecraft.server.v1_16_R2.MerchantRecipe handle = (net.minecraft.server.v1_16_R2.MerchantRecipe) fHandle.get(merchantRecipe); // NMS Recipe
|
||||
modifiersField.setInt(fHandle, fHandle.getModifiers() & ~Modifier.FINAL); // Remove final
|
||||
|
||||
Field fSelling = net.minecraft.server.v1_16_R2.MerchantRecipe.class.getDeclaredField("sellingItem");
|
||||
fSelling.setAccessible(true);
|
||||
modifiersField.setInt(fSelling, fSelling.getModifiers() & ~Modifier.FINAL);
|
||||
|
||||
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
|
||||
Display.displayAndFinalize(selling);
|
||||
|
||||
@@ -9,16 +9,11 @@ import org.bukkit.inventory.MerchantRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
public final class VillagerTrade implements VillagerTradeProxy {
|
||||
@Override
|
||||
public void displayTrade(@NotNull final MerchantRecipe merchantRecipe) {
|
||||
try {
|
||||
// Enables removing final modifier
|
||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
||||
modifiersField.setAccessible(true);
|
||||
|
||||
// Bukkit MerchantRecipe result
|
||||
Field fResult = MerchantRecipe.class.getDeclaredField("result");
|
||||
fResult.setAccessible(true);
|
||||
@@ -29,12 +24,10 @@ public final class VillagerTrade implements VillagerTradeProxy {
|
||||
// Get NMS MerchantRecipe from CraftMerchantRecipe
|
||||
Field fHandle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
||||
fHandle.setAccessible(true);
|
||||
net.minecraft.server.v1_16_R3.MerchantRecipe handle = (net.minecraft.server.v1_16_R3.MerchantRecipe) fHandle.get(merchantRecipe); // NMS Recipe
|
||||
modifiersField.setInt(fHandle, fHandle.getModifiers() & ~Modifier.FINAL); // Remove final
|
||||
net.minecraft.server.v1_16_R3.MerchantRecipe handle = (net.minecraft.server.v1_16_R3.MerchantRecipe) fHandle.get(merchantRecipe); // NMS RecipeR
|
||||
|
||||
Field fSelling = net.minecraft.server.v1_16_R3.MerchantRecipe.class.getDeclaredField("sellingItem");
|
||||
fSelling.setAccessible(true);
|
||||
modifiersField.setInt(fSelling, fSelling.getModifiers() & ~Modifier.FINAL);
|
||||
|
||||
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
|
||||
Display.displayAndFinalize(selling);
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.willfp.eco.spigot.integrations.antigrief.AntigriefTowny;
|
||||
import com.willfp.eco.spigot.integrations.antigrief.AntigriefWorldGuard;
|
||||
import com.willfp.eco.spigot.integrations.mcmmo.McmmoIntegrationImpl;
|
||||
import com.willfp.eco.util.command.AbstractCommand;
|
||||
import com.willfp.eco.util.display.Display;
|
||||
import com.willfp.eco.util.drops.internal.FastCollatedDropQueue;
|
||||
import com.willfp.eco.util.events.armorequip.ArmorListener;
|
||||
import com.willfp.eco.util.events.armorequip.DispenserArmorListener;
|
||||
@@ -48,6 +49,7 @@ public class EcoPlugin extends AbstractEcoPlugin {
|
||||
public EcoPlugin() {
|
||||
super("eco", 87955, 10043, "com.willfp.eco.proxy", "&a");
|
||||
instance = this;
|
||||
Display.setFinalizeKey(this.getNamespacedKeyFactory().create("finalized"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -29,6 +29,10 @@ public class AntigriefKingdoms implements AntigriefWrapper {
|
||||
|
||||
Land land = Land.getLand(block);
|
||||
|
||||
if (land == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
DefaultKingdomPermission permission = land.isNexusLand() ? DefaultKingdomPermission.NEXUS_BUILD : DefaultKingdomPermission.BUILD;
|
||||
if (!kp.hasPermission(permission)) {
|
||||
return false;
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
package com.willfp.eco.util.display;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -24,15 +30,9 @@ public class Display {
|
||||
private static final List<Function<ItemStack, ItemStack>> REVERT_FUNCTIONS = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Registered finalize functions.
|
||||
* NamespacedKey for finalizing.
|
||||
*/
|
||||
public static final List<Function<ItemStack, ItemStack>> FINALIZE_FUNCTIONS = new ArrayList<>();
|
||||
|
||||
|
||||
/**
|
||||
* Registered finalize test functions.
|
||||
*/
|
||||
public static final List<Predicate<ItemStack>> FINALIZE_TEST_FUNCTIONS = new ArrayList<>();
|
||||
private static NamespacedKey finalizeKey;
|
||||
|
||||
/**
|
||||
* Register display module.
|
||||
@@ -66,24 +66,6 @@ public class Display {
|
||||
REVERT_FUNCTIONS.add(function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register finalize function.
|
||||
*
|
||||
* @param function The function.
|
||||
*/
|
||||
public void registerFinalizeModule(@NotNull final Function<ItemStack, ItemStack> function) {
|
||||
FINALIZE_FUNCTIONS.add(function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register finalize test function.
|
||||
*
|
||||
* @param function The function.
|
||||
*/
|
||||
public void registerFinalizeTestModule(@NotNull final Predicate<ItemStack> function) {
|
||||
FINALIZE_TEST_FUNCTIONS.add(function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display on ItemStacks.
|
||||
*
|
||||
@@ -91,6 +73,13 @@ public class Display {
|
||||
* @return The itemstack.
|
||||
*/
|
||||
public ItemStack display(@NotNull final ItemStack itemStack) {
|
||||
if (isFinalized(itemStack)) {
|
||||
unfinalize(itemStack);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
revert(itemStack);
|
||||
|
||||
for (Map<String, Function<ItemStack, ItemStack>> displayFunctions : DISPLAY_FUNCTIONS) {
|
||||
if (displayFunctions == null) {
|
||||
continue;
|
||||
@@ -121,9 +110,15 @@ public class Display {
|
||||
* @return The itemstack.
|
||||
*/
|
||||
public ItemStack revert(@NotNull final ItemStack itemStack) {
|
||||
if (isFinalized(itemStack)) {
|
||||
unfinalize(itemStack);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
for (Function<ItemStack, ItemStack> displayFunction : REVERT_FUNCTIONS) {
|
||||
displayFunction.apply(itemStack);
|
||||
}
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@@ -134,26 +129,82 @@ public class Display {
|
||||
* @return The itemstack.
|
||||
*/
|
||||
public ItemStack finalize(@NotNull final ItemStack itemStack) {
|
||||
for (Function<ItemStack, ItemStack> function : FINALIZE_FUNCTIONS) {
|
||||
function.apply(itemStack);
|
||||
Validate.notNull(finalizeKey, "Key cannot be null!");
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
if (meta == null) {
|
||||
return itemStack;
|
||||
}
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
container.set(finalizeKey, PersistentDataType.INTEGER, 1);
|
||||
itemStack.setItemMeta(meta);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalize an ItemStacks.
|
||||
* Unfinalize an ItemStacks.
|
||||
*
|
||||
* @param itemStack The item.
|
||||
* @return The itemstack.
|
||||
*/
|
||||
public ItemStack unfinalize(@NotNull final ItemStack itemStack) {
|
||||
Validate.notNull(finalizeKey, "Key cannot be null!");
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
if (meta == null) {
|
||||
return itemStack;
|
||||
}
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
container.remove(finalizeKey);
|
||||
itemStack.setItemMeta(meta);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* If an item is finalized.
|
||||
*
|
||||
* @param itemStack The item.
|
||||
* @return If finalized.
|
||||
*/
|
||||
public boolean isFinalized(@NotNull final ItemStack itemStack) {
|
||||
for (Predicate<ItemStack> function : FINALIZE_TEST_FUNCTIONS) {
|
||||
if (function.test(itemStack)) {
|
||||
return true;
|
||||
}
|
||||
Validate.notNull(finalizeKey, "Key cannot be null!");
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
if (meta == null) {
|
||||
return false;
|
||||
}
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
return container.has(finalizeKey, PersistentDataType.INTEGER);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
/**
|
||||
* Register finalize function.
|
||||
*
|
||||
* @param function The function.
|
||||
* @deprecated Not needed.
|
||||
*/
|
||||
@Deprecated
|
||||
public void registerFinalizeModule(@NotNull final Function<ItemStack, ItemStack> function) {
|
||||
// This function is not needed.
|
||||
}
|
||||
|
||||
/**
|
||||
* Register finalize test function.
|
||||
*
|
||||
* @param function The function.
|
||||
* @deprecated Not needed.
|
||||
*/
|
||||
@Deprecated
|
||||
public void registerFinalizeTestModule(@NotNull final Predicate<ItemStack> function) {
|
||||
// This isn't needed.
|
||||
}
|
||||
|
||||
/**
|
||||
* Set key to be used for finalization.
|
||||
*
|
||||
* @param finalizeKey The key.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public static void setFinalizeKey(@NotNull final NamespacedKey finalizeKey) {
|
||||
Display.finalizeKey = finalizeKey;
|
||||
}
|
||||
|
||||
static {
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
version = 3.3.2
|
||||
version = 3.4.0
|
||||
plugin-name = eco
|
||||
Reference in New Issue
Block a user