Merge remote-tracking branch 'origin/master' into master

# Conflicts:
#	Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java
#	Plugin/src/main/resources/plugin.yml
This commit is contained in:
Auxilor
2020-11-06 17:08:56 +00:00
14 changed files with 117 additions and 24 deletions

View File

@@ -24,7 +24,7 @@ public class EcoEnchantsPlugin extends JavaPlugin {
/**
* NMS version
*/
public static final String nmsVersion = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
public static final String NMS_VERSION = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
/**
* ProtocolLib

View File

@@ -7,6 +7,7 @@ import com.willfp.ecoenchants.config.ConfigManager;
import com.willfp.ecoenchants.display.EnchantmentCache;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.util.StringUtils;
import org.apache.commons.lang.WordUtils;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@@ -77,7 +78,7 @@ public final class CommandEnchantinfo extends AbstractCommand {
if(allConflicts.length() >= 2) {
allConflicts = allConflicts.substring(0, allConflicts.length() -2);
} else {
allConflicts = ChatColor.translateAlternateColorCodes('&', ConfigManager.getLang().getString("no-conflicts"));
allConflicts = StringUtils.translate(ConfigManager.getLang().getString("no-conflicts"));
}
Set<Material> targets = enchantment.getTarget();
@@ -110,7 +111,7 @@ public final class CommandEnchantinfo extends AbstractCommand {
if(allTargets.length() >= 2) {
allTargets = allTargets.substring(0, allTargets.length() - 2);
} else {
allTargets = ChatColor.translateAlternateColorCodes('&', ConfigManager.getLang().getString("no-targets"));
allTargets = StringUtils.translate(ConfigManager.getLang().getString("no-targets"));
}
String maxLevel = String.valueOf(enchantment.getMaxLevel());

View File

@@ -7,6 +7,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget;
import com.willfp.ecoenchants.util.NumberUtils;
import com.willfp.ecoenchants.util.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
@@ -73,11 +74,11 @@ public final class EnchantDisplay {
* Update config values
*/
public static void update() {
descriptionColor = ChatColor.translateAlternateColorCodes('&', ConfigManager.getLang().getString("description-color"));
curseColor = ChatColor.translateAlternateColorCodes('&', ConfigManager.getLang().getString("curse-color"));
specialColor = ChatColor.translateAlternateColorCodes('&', ConfigManager.getLang().getString("special-color"));
artifactColor = ChatColor.translateAlternateColorCodes('&', ConfigManager.getLang().getString("artifact-color"));
normalColor = ChatColor.translateAlternateColorCodes('&', ConfigManager.getLang().getString("not-curse-color"));
descriptionColor = StringUtils.translate(ConfigManager.getLang().getString("description-color"));
curseColor = StringUtils.translate(ConfigManager.getLang().getString("curse-color"));
specialColor = StringUtils.translate(ConfigManager.getLang().getString("special-color"));
artifactColor = StringUtils.translate(ConfigManager.getLang().getString("artifact-color"));
normalColor = StringUtils.translate(ConfigManager.getLang().getString("not-curse-color"));
useNumerals = ConfigManager.getConfig().getBool("lore.use-numerals");
numbersThreshold = ConfigManager.getConfig().getInt("lore.use-numbers-above-threshold");

View File

@@ -54,7 +54,7 @@ public final class PacketOpenWindowMerchant extends AbstractPacketAdapter {
modifiersField.setInt(fSelling, fSelling.getModifiers() & ~Modifier.FINAL);
// Reflectively access CraftItemStack.class for respective version
Class<?> craftItemStack = Class.forName("org.bukkit.craftbukkit." + EcoEnchantsPlugin.nmsVersion + ".inventory.CraftItemStack");
Class<?> craftItemStack = Class.forName("org.bukkit.craftbukkit." + EcoEnchantsPlugin.NMS_VERSION + ".inventory.CraftItemStack");
// Bukkit Result ItemStack from NMS Result ItemStack
ItemStack nmsSelling = (ItemStack) craftItemStack.getMethod("asBukkitCopy", selling.getClass()).invoke(null, selling);

View File

@@ -5,6 +5,7 @@ import com.willfp.ecoenchants.config.ConfigManager;
import com.willfp.ecoenchants.config.configs.EnchantmentConfig;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity;
import com.willfp.ecoenchants.enchantments.util.Watcher;
import com.willfp.ecoenchants.util.StringUtils;
import com.willfp.ecoenchants.util.interfaces.Registerable;
import com.willfp.ecoenchants.util.optional.Prerequisite;
import net.md_5.bungee.api.ChatColor;
@@ -82,8 +83,8 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist
canGetFromVillager = config.getBool(EcoEnchants.OBTAINING_LOCATION + "villager");
canGetFromLoot = config.getBool(EcoEnchants.OBTAINING_LOCATION + "loot");
maxLvl = config.getInt(EcoEnchants.GENERAL_LOCATION + "maximum-level", 1);
name = ChatColor.translateAlternateColorCodes('&', config.getString("name"));
description = ChatColor.translateAlternateColorCodes('&', config.getString("description"));
name = StringUtils.translate(config.getString("name"));
description = StringUtils.translate(config.getString("description"));
target.clear();
targetMaterials.clear();
target.addAll(config.getTargets());

View File

@@ -235,7 +235,7 @@ public class EcoEnchants {
public static final EcoEnchant WARPED_ARTIFACT = new WarpedArtifact();
public static final EcoEnchant TEAR_ARTIFACT = new TearArtifact();
public static final EcoEnchant BACKSTAB = new Backstab();
public static final EcoEnchant DWELLER = new Dweller();
public static final EcoEnchant EXTRACTION = new Extraction();
/**
* Get all registered {@link EcoEnchant}s

View File

@@ -0,0 +1,46 @@
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
import com.willfp.ecoenchants.queue.DropQueue;
import com.willfp.ecoenchants.util.NumberUtils;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
public final class Extraction extends EcoEnchant {
public Extraction() {
super(
"extraction", EnchantmentType.NORMAL
);
}
// START OF LISTENERS
@Override
public void onBlockBreak(Player player, Block block, int level, BlockBreakEvent event) {
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR)
return;
if(!EnchantmentUtils.passedChance(this, level))
return;
Material material = null;
if(block.getType().equals(Material.GOLD_ORE)) material = Material.GOLD_NUGGET;
if(block.getType().equals(Material.IRON_ORE)) material = Material.IRON_NUGGET;
if(material == null) return;
ItemStack item = new ItemStack(material, 1);
new DropQueue(player)
.setLocation(block.getLocation())
.addItem(item)
.push();
}
}

View File

@@ -1,6 +1,7 @@
package com.willfp.ecoenchants.enchantments.meta;
import com.willfp.ecoenchants.config.ConfigManager;
import com.willfp.ecoenchants.util.StringUtils;
import com.willfp.ecoenchants.util.interfaces.Registerable;
import org.bukkit.ChatColor;
@@ -128,7 +129,7 @@ public class EnchantmentRarity implements Registerable {
double lootProbability = ConfigManager.getRarity().getDouble("rarities." + rarity + ".loot-probability");
String customColor = null;
if(ConfigManager.getRarity().getBool("rarities." + rarity + ".custom-color.enabled")) {
customColor = ChatColor.translateAlternateColorCodes('&', ConfigManager.getRarity().getString("rarities." + rarity + ".custom-color.color"));
customColor = StringUtils.translate(ConfigManager.getRarity().getString("rarities." + rarity + ".custom-color.color"));
}
new EnchantmentRarity(name, probability, minimumLevel, villagerProbability, lootProbability, customColor).register();

View File

@@ -44,6 +44,7 @@ import com.willfp.ecoenchants.nms.Cooldown;
import com.willfp.ecoenchants.nms.RepairCost;
import com.willfp.ecoenchants.nms.TridentStack;
import com.willfp.ecoenchants.util.Logger;
import com.willfp.ecoenchants.util.StringUtils;
import com.willfp.ecoenchants.util.UpdateChecker;
import com.willfp.ecoenchants.util.interfaces.EcoRunnable;
import com.willfp.ecoenchants.util.optional.Prerequisite;
@@ -213,9 +214,9 @@ public class Loader {
Logger.info(EcoEnchants.getAll().size() + " Enchantments Loaded:");
EcoEnchants.getAll().forEach((ecoEnchant -> {
if(ecoEnchant.getType().equals(EcoEnchant.EnchantmentType.SPECIAL)) {
Logger.info(ChatColor.translateAlternateColorCodes('&', ConfigManager.getLang().getString("special-color")) + "- " + ecoEnchant.getName() + ": " + ecoEnchant.getKey().toString());
Logger.info(StringUtils.translate(ConfigManager.getLang().getString("special-color")) + "- " + ecoEnchant.getName() + ": " + ecoEnchant.getKey().toString());
} else if(ecoEnchant.getType().equals(EcoEnchant.EnchantmentType.ARTIFACT)) {
Logger.info(ChatColor.translateAlternateColorCodes('&', ConfigManager.getLang().getString("artifact-color")) + "- " + ecoEnchant.getName() + ": " + ecoEnchant.getKey().toString());
Logger.info(StringUtils.translate(ConfigManager.getLang().getString("artifact-color")) + "- " + ecoEnchant.getName() + ": " + ecoEnchant.getKey().toString());
} else {
Logger.info("- " + ecoEnchant.getName() + ": " + ecoEnchant.getKey().toString());
}

View File

@@ -10,7 +10,7 @@ public class BlockBreak {
public static boolean init() {
try {
final Class<?> class2 = Class.forName("com.willfp.ecoenchants." + EcoEnchantsPlugin.nmsVersion + ".BlockBreak");
final Class<?> class2 = Class.forName("com.willfp.ecoenchants." + EcoEnchantsPlugin.NMS_VERSION + ".BlockBreak");
if (BlockBreakWrapper.class.isAssignableFrom(class2)) {
blockBreakWrapper = (BlockBreakWrapper) class2.getConstructor().newInstance();
}

View File

@@ -1,10 +1,7 @@
package com.willfp.ecoenchants.nms;
import com.willfp.ecoenchants.EcoEnchantsPlugin;
import com.willfp.ecoenchants.nms.API.BlockBreakWrapper;
import com.willfp.ecoenchants.nms.API.RepairCostWrapper;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class RepairCost {
@@ -12,7 +9,7 @@ public class RepairCost {
public static boolean init() {
try {
final Class<?> class2 = Class.forName("com.willfp.ecoenchants." + EcoEnchantsPlugin.nmsVersion + ".RepairCost");
final Class<?> class2 = Class.forName("com.willfp.ecoenchants." + EcoEnchantsPlugin.NMS_VERSION + ".RepairCost");
if (RepairCostWrapper.class.isAssignableFrom(class2)) {
repairCostWrapper = (RepairCostWrapper) class2.getConstructor().newInstance();
}

View File

@@ -2,8 +2,28 @@ package com.willfp.ecoenchants.util;
import net.md_5.bungee.api.ChatColor;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static net.md_5.bungee.api.ChatColor.COLOR_CHAR;
public class StringUtils {
public static String translate(String message){
return ChatColor.translateAlternateColorCodes('&', message);
return ChatColor.translateAlternateColorCodes('&', translateHexColorCodes("&#", "", message));
}
private static String translateHexColorCodes(String startTag, String endTag, String message) {
Pattern hexPattern = Pattern.compile(startTag + "([A-Fa-f0-9]{6})" + endTag);
Matcher matcher = hexPattern.matcher(message);
StringBuffer buffer = new StringBuffer(message.length() + 4 * 8);
while(matcher.find()) {
String group = matcher.group(1);
matcher.appendReplacement(buffer, COLOR_CHAR + "x"
+ COLOR_CHAR + group.charAt(0) + COLOR_CHAR + group.charAt(1)
+ COLOR_CHAR + group.charAt(2) + COLOR_CHAR + group.charAt(3)
+ COLOR_CHAR + group.charAt(4) + COLOR_CHAR + group.charAt(5));
}
return matcher.appendTail(buffer).toString();
}
}