Added color support to anvils

This commit is contained in:
Auxilor 2021-01-30 10:55:50 +00:00
parent f5e34258a9
commit 0f91aa8a75
3 changed files with 16 additions and 3 deletions

View File

@ -53,7 +53,6 @@ public class AnvilListeners extends PluginDependent implements Listener {
ItemStack out = event.getResult();
String name = event.getInventory().getRenameText();
if (event.getViewers().isEmpty()) {
return; // Prevent ArrayIndexOutOfBoundsException when using AnvilGUI
}

View File

@ -1,5 +1,6 @@
package com.willfp.ecoenchants.enchantments.support.merging.anvil;
import com.willfp.eco.util.StringUtils;
import com.willfp.eco.util.tuplets.Pair;
import com.willfp.ecoenchants.EcoEnchantsPlugin;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
@ -39,17 +40,20 @@ public class AnvilMerge {
* @param left The {@link ItemStack} on the left of the anvil.
* @param right The {@link ItemStack} in the middle of the anvil.
* @param old The previous {@link ItemStack} result.
* @param name The anvil display name.
* @param itemName The anvil display name.
* @param player The player merging (for permissions).
* @return The result, stored as a {@link Pair} of {@link ItemStack} and {@link Integer}.
*/
public Pair<ItemStack, Integer> doMerge(@Nullable final ItemStack left,
@Nullable final ItemStack right,
@Nullable final ItemStack old,
@NotNull final String name,
@NotNull final String itemName,
@NotNull final Player player) {
// Here so it can be accessed later (scope)
// Copied to non-final string.
String name = itemName;
int outDamage = -1;
if (old != null && old.getItemMeta() instanceof Damageable) {
outDamage = ((Damageable) old.getItemMeta()).getDamage();
@ -63,6 +67,12 @@ public class AnvilMerge {
return new Pair<>(null, null);
}
name = name.replace("§", "&");
if (player.hasPermission("ecoenchants.anvil.color")) {
name = StringUtils.translate(name);
}
if (!EnchantmentTarget.ALL.getMaterials().contains(left.getType()) || right == null || !EnchantmentTarget.ALL.getMaterials().contains(right.getType())) {
ItemStack out = left.clone();
ItemMeta outMeta = out.getItemMeta();

View File

@ -50,6 +50,7 @@ permissions:
default: op
children:
ecoenchants.anvil.bypasshardcap: true
ecoenchants.anvil.color: true
ecoenchants.fromtable.*:
description: Allows getting all enchantments from an enchanting table
default: true
@ -69,6 +70,9 @@ permissions:
ecoenchants.anvil.bypasshardcap:
description: Allows bypassing the anvil hard cap
default: op
ecoenchants.anvil.color:
description: Allows color from anvil renames
default: op
# Perks
ecoenchants.cooldowntime.half: