Skip to content

Commit

Permalink
Added color support to anvils
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Jan 30, 2021
1 parent f5e3425 commit 0f91aa8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public void onAnvilPrepare(@NotNull final PrepareAnvilEvent event) {
ItemStack out = event.getResult();
String name = event.getInventory().getRenameText();


if (event.getViewers().isEmpty()) {
return; // Prevent ArrayIndexOutOfBoundsException when using AnvilGUI
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -63,6 +67,12 @@ public Pair<ItemStack, Integer> doMerge(@Nullable final ItemStack left,
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();
Expand Down
4 changes: 4 additions & 0 deletions eco-core/core-plugin/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 0f91aa8

Please sign in to comment.