1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-29 05:55:27 +01:00

Enchantment recognition update

This commit is contained in:
Zrips 2024-04-15 12:38:25 +03:00
parent c96b24bb10
commit f5001efa96
12 changed files with 59 additions and 292 deletions

View File

@ -199,7 +199,7 @@
<artifactId>CMILib</artifactId>
<version>latest</version>
<scope>system</scope>
<systemPath>${basedir}/libs/CMILib1.4.3.1.jar</systemPath>
<systemPath>${basedir}/libs/CMILib1.4.6.2.jar</systemPath>
</dependency>
<!-- WildStacker -->
<dependency>

View File

@ -1,230 +0,0 @@
package com.gamingmesh.jobs.CMILib;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.enchantments.Enchantment;
import net.Zrips.CMILib.Container.CMIText;
public enum CMIEnchantment {
AQUA_AFFINITY("WATER_WORKER"),
BANE_OF_ARTHROPODS("DAMAGE_ARTHROPODS", "ARTHROPODS_DAMAGE"),
BINDING_CURSE,
BLAST_PROTECTION("PROTECTION_EXPLOSIONS", "EXPLOSION_PROTECTION", "EXPLOSIONS_PROTECTION"),
CHANNELING,
DEPTH_STRIDER,
EFFICIENCY("DIG_SPEED"),
FEATHER_FALLING("PROTECTION_FALL", "FALL_PROTECTION"),
FIRE_ASPECT,
FIRE_PROTECTION("PROTECTION_FIRE"),
FLAME("ARROW_FIRE", "FIRE_ARROW"),
FORTUNE("LOOT_BONUS_BLOCKS"),
FROST_WALKER,
IMPALING,
INFINITY("ARROW_INFINITE", "INFINITE_ARROW"),
KNOCKBACK,
LOOTING("LOOT_BONUS_MOBS"),
LOYALTY,
LUCK_OF_THE_SEA("LUCK"),
LURE,
MENDING,
MULTISHOT("MULTSHOT"),
PIERCING,
POWER("ARROW_DAMAGE"),
PROJECTILE_PROTECTION("PROTECTION_PROJECTILE"),
PROTECTION("PROTECTION_ENVIRONMENTAL", "ENVIRONMENTAL_PROTECTION"),
PUNCH("ARROW_KNOCKBACK", "KNOCKBACK_ARROW"),
QUICK_CHARGE,
RESPIRATION("OXYGEN"),
RIPTIDE,
SHARPNESS("DAMAGE_ALL"),
SILK_TOUCH,
SMITE("DAMAGE_UNDEAD", "UNDEAD_DAMAGE"),
SOUL_SPEED,
SWEEPING("SWEEPING_EDGE"),
THORNS,
UNBREAKING("DURABILITY"),
VANISHING_CURSE;
private static final Map<String, CMIEnchantment> map = new HashMap<>();
private static final Map<Enchantment, CMIEnchantment> emap = new HashMap<>();
private static final Map<String, Enchantment> gmap = new HashMap<>();
private final List<String> subName = new ArrayList<>();
private List<String> customNames = new ArrayList<>();
private Enchantment enchantment;
@SuppressWarnings("deprecation")
CMIEnchantment(String... subName) {
if (subName != null)
this.subName.addAll(Arrays.asList(subName));
String temp = toString().toLowerCase().replace("_", "");
for (Enchantment one : Enchantment.values()) {
try {
if (one.getName().toLowerCase().replace("_", "").equalsIgnoreCase(temp)) {
enchantment = one;
break;
}
} catch (Exception | Error e) {
try {
if (one.getKey().toString().split(":", 2)[1].toLowerCase().replace("_", "").equalsIgnoreCase(temp)) {
enchantment = one;
break;
}
} catch (Exception | Error ex) {
}
}
}
// Worst case scenario
if (enchantment == null) {
for (Enchantment one : Enchantment.values()) {
if (one.toString().toLowerCase().replace("_", "").equalsIgnoreCase(temp)) {
enchantment = one;
break;
}
}
}
// now checks for subnames
if (enchantment == null) {
en: for (Enchantment one : Enchantment.values()) {
for (String subs : this.subName) {
try {
if (one.getName().toLowerCase().replace("_", "").equalsIgnoreCase(subs.toLowerCase().replace("_", ""))) {
enchantment = one;
break en;
}
} catch (Exception | Error e) {
try {
if (one.getKey().toString().split(":", 2)[1].toLowerCase().replace("_", "").equalsIgnoreCase(temp)) {
enchantment = one;
break en;
}
} catch (Exception | Error ex) {
}
}
}
}
}
if (enchantment == null) {
o: for (Enchantment one : Enchantment.values()) {
for (String subs : this.subName) {
if (one.toString().toLowerCase().replace("_", "").equalsIgnoreCase(subs.toLowerCase().replace("_", ""))) {
enchantment = one;
break o;
}
}
}
}
}
public List<String> getSubNames() {
return subName;
}
private static void fillUpMap() {
map.clear();
emap.clear();
for (CMIEnchantment one : CMIEnchantment.values()) {
map.put(one.toString().toLowerCase().replace("_", ""), one);
for (String oneC : one.getSubNames()) {
map.put(oneC.toLowerCase().replace("_", ""), one);
}
for (String oneC : one.getCustomNames()) {
map.put(oneC.toLowerCase().replace("_", ""), one);
}
emap.put(one.getEnchantment(), one);
}
try {
for (Enchantment one : Enchantment.values()) {
String name = one.getKey().getKey().toLowerCase().replace("_", "").replace("minecraft:", "");
if (!map.containsKey(name)) {
gmap.put(name, one);
}
}
} catch (Throwable e) {
}
}
public static CMIEnchantment get(String name) {
if (map.isEmpty())
fillUpMap();
String[] split = name.split(":", 2);
if (split.length > 0 || (split = name.split("-", 2)).length > 0) {
name = split[0];
}
return map.get(name.toLowerCase().replace("_", ""));
}
public static Enchantment getEnchantment(String name) {
if (map.isEmpty())
fillUpMap();
String[] split = name.split(":", 2);
if (split.length > 0 || (split = name.split("-", 2)).length > 0) {
name = split[0];
}
name = name.toLowerCase().replace("_", "");
CMIEnchantment ec = map.get(name);
if (ec == null) {
return gmap.get(name);
}
return ec.getEnchantment();
}
public static CMIEnchantment get(Enchantment enchantment) {
if (map.isEmpty())
fillUpMap();
return emap.get(enchantment);
}
public List<String> getCustomNames() {
return customNames;
}
public void setCustomNames(List<String> customNames) {
this.customNames = customNames;
fillUpMap();
}
public void addCustomName(String customName) {
this.customNames.add(customName);
fillUpMap();
}
public Enchantment getEnchantment() {
return enchantment;
}
public String getName() {
return CMIText.firstToUpperCase(toString());
}
public static String getName(Enchantment enchant) {
CMIEnchantment ce = get(enchant);
if (ce == null)
return "Unknown";
return ce.getName();
}
}

View File

@ -11,7 +11,6 @@ import java.util.Set;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import com.gamingmesh.jobs.CMILib.CMIEnchantment;
import com.gamingmesh.jobs.container.BoostMultiplier;
import com.gamingmesh.jobs.container.CurrencyType;
import com.gamingmesh.jobs.container.Job;
@ -19,6 +18,7 @@ import com.gamingmesh.jobs.container.JobItems;
import net.Zrips.CMILib.Colors.CMIChatColor;
import net.Zrips.CMILib.Container.CMIList;
import net.Zrips.CMILib.Enchants.CMIEnchantment;
import net.Zrips.CMILib.FileHandler.ConfigReader;
import net.Zrips.CMILib.Items.CMIItemStack;
import net.Zrips.CMILib.Items.CMIMaterial;
@ -147,7 +147,7 @@ public final class ItemBoostManager {
if (split.length == 0)
continue;
Enchantment ench = CMIEnchantment.getEnchantment(split[0]);
Enchantment ench = CMIEnchantment.getByName(split[0]);
if (ench == null)
continue;

View File

@ -1182,33 +1182,31 @@ public class PlayerManager {
if (!Jobs.getGCManager().AutoJobJoinUse || player == null || player.isOp())
return;
CMIScheduler.get().runTaskLater(new Runnable() {
@Override
public void run() {
if (!player.isOnline())
CMIScheduler.runTaskLater(() -> {
if (!player.isOnline())
return;
JobsPlayer jPlayer = getJobsPlayer(player);
if (jPlayer == null || player.hasPermission("jobs.*"))
return;
int playerMaxJobs = getMaxJobs(jPlayer);
int playerCurrentJobs = jPlayer.getJobProgression().size();
if (playerMaxJobs == 0 || playerMaxJobs != -1 && playerCurrentJobs >= playerMaxJobs)
return;
for (Job one : Jobs.getJobs()) {
if (playerMaxJobs != -1 && jPlayer.getJobProgression().size() >= playerMaxJobs)
return;
JobsPlayer jPlayer = getJobsPlayer(player);
if (jPlayer == null || player.hasPermission("jobs.*"))
return;
if (one.getMaxSlots() != null && Jobs.getUsedSlots(one) >= one.getMaxSlots())
continue;
int playerMaxJobs = getMaxJobs(jPlayer);
int playerCurrentJobs = jPlayer.getJobProgression().size();
if (playerMaxJobs == 0 || playerMaxJobs != -1 && playerCurrentJobs >= playerMaxJobs)
return;
for (Job one : Jobs.getJobs()) {
if (playerMaxJobs != -1 && jPlayer.getJobProgression().size() >= playerMaxJobs)
return;
if (one.getMaxSlots() != null && Jobs.getUsedSlots(one) >= one.getMaxSlots())
continue;
if (!jPlayer.isInJob(one) && player.hasPermission("jobs.autojoin." + one.getName().toLowerCase()))
joinJob(jPlayer, one);
}
if (!jPlayer.isInJob(one) && player.hasPermission("jobs.autojoin." + one.getName().toLowerCase()))
joinJob(jPlayer, one);
}
}, Jobs.getGCManager().AutoJobJoinDelay * 20L);
}
}

View File

@ -0,0 +1 @@
/howmuch.java

View File

@ -37,7 +37,6 @@ import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import com.gamingmesh.jobs.ItemBoostManager;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.CMILib.CMIEnchantment;
import com.gamingmesh.jobs.Gui.GuiItem;
import com.gamingmesh.jobs.container.ActionType;
import com.gamingmesh.jobs.container.BoostMultiplier;
@ -57,6 +56,7 @@ import com.gamingmesh.jobs.stuff.Util;
import net.Zrips.CMILib.Colors.CMIChatColor;
import net.Zrips.CMILib.Container.CMIList;
import net.Zrips.CMILib.Enchants.CMIEnchantment;
import net.Zrips.CMILib.Entities.CMIEntityType;
import net.Zrips.CMILib.Equations.ParseError;
import net.Zrips.CMILib.Equations.Parser;
@ -624,8 +624,8 @@ public class ConfigManager {
}
if (matId != null && (material = CMIMaterial.get(matId)) != CMIMaterial.NONE) {
Jobs.getPluginLogger().warning("Job " + jobName + " " + actionType.getName() + " is using ID: " + myKey + "!");
Jobs.getPluginLogger().warning("Please use the Material name instead: " + material.toString() + "!");
CMIMessages.consoleMessage("Job " + jobName + " " + actionType.getName() + " is using ID: " + myKey + "!");
CMIMessages.consoleMessage("Please use the Material name instead: " + material.toString() + "!");
}
}
@ -638,7 +638,7 @@ public class ConfigManager {
return null;
if (material.getMaterial() != null && material.isAir()) {
Jobs.getPluginLogger().warning("Job " + jobName + " " + actionType.getName() + " can't recognize material! (" + myKey + ")");
CMIMessages.consoleMessage("Job " + jobName + " " + actionType.getName() + " can't recognize material! (" + myKey + ")");
return null;
}
@ -675,7 +675,7 @@ public class ConfigManager {
// These actions MUST be blocks
if (actionType == ActionType.BREAK || actionType == ActionType.PLACE || actionType == ActionType.STRIPLOGS) {
if (!material.isBlock() || material.getMaterial().toString().equalsIgnoreCase("AIR")) {
Jobs.getPluginLogger().warning("Job " + jobName + " has an invalid " + actionType.getName() + " type property: " + material
CMIMessages.consoleMessage("Job " + jobName + " has an invalid " + actionType.getName() + " type property: " + material
+ " (" + myKey + ")! Material must be a block! Use \"/jobs blockinfo\" on a target block");
return null;
}
@ -693,14 +693,14 @@ public class ConfigManager {
* configurations broken.
*/
if (material == CMIMaterial.REDSTONE_ORE && actionType == ActionType.BREAK && Version.isCurrentLower(Version.v1_13_R1)) {
Jobs.getPluginLogger().warning("Job " + jobName + " is using REDSTONE_ORE instead of GLOWING_REDSTONE_ORE.");
Jobs.getPluginLogger().warning("Automatically changing block to GLOWING_REDSTONE_ORE. Please update your configuration.");
Jobs.getPluginLogger().warning("In vanilla minecraft, REDSTONE_ORE changes to GLOWING_REDSTONE_ORE when interacted with.");
Jobs.getPluginLogger().warning("In the future, Jobs using REDSTONE_ORE instead of GLOWING_REDSTONE_ORE may fail to work correctly.");
CMIMessages.consoleMessage("Job " + jobName + " is using REDSTONE_ORE instead of GLOWING_REDSTONE_ORE.");
CMIMessages.consoleMessage("Automatically changing block to GLOWING_REDSTONE_ORE. Please update your configuration.");
CMIMessages.consoleMessage("In vanilla minecraft, REDSTONE_ORE changes to GLOWING_REDSTONE_ORE when interacted with.");
CMIMessages.consoleMessage("In the future, Jobs using REDSTONE_ORE instead of GLOWING_REDSTONE_ORE may fail to work correctly.");
material = CMIMaterial.LEGACY_GLOWING_REDSTONE_ORE;
} else if (material == CMIMaterial.LEGACY_GLOWING_REDSTONE_ORE && actionType == ActionType.BREAK && Version.isCurrentEqualOrHigher(Version.v1_13_R1)) {
Jobs.getPluginLogger().warning("Job " + jobName + " is using GLOWING_REDSTONE_ORE instead of REDSTONE_ORE.");
Jobs.getPluginLogger().warning("Automatically changing block to REDSTONE_ORE. Please update your configuration.");
CMIMessages.consoleMessage("Job " + jobName + " is using GLOWING_REDSTONE_ORE instead of REDSTONE_ORE.");
CMIMessages.consoleMessage("Automatically changing block to REDSTONE_ORE. Please update your configuration.");
material = CMIMaterial.REDSTONE_ORE;
}
// END HACK
@ -777,16 +777,15 @@ public class ConfigManager {
}
}
} else if (actionType == ActionType.ENCHANT) {
Enchantment enchant = CMIEnchantment.getEnchantment(myKey);
if (enchant == null && material == CMIMaterial.NONE) {
Jobs.getPluginLogger().warning("Job " + jobName + " has an invalid " + actionType.getName() + " type property: " + myKey + "!");
CMIEnchantment cmiEnchant = CMIEnchantment.getCMIByName(myKey);
if (cmiEnchant == null && material == CMIMaterial.NONE) {
CMIMessages.consoleMessage("Job " + jobName + " has an invalid " + actionType.getName() + " type property: " + myKey + "!");
return null;
}
CMIEnchantment cmiEnchant = CMIEnchantment.get(enchant);
type = cmiEnchant != null ? cmiEnchant.toString() : enchant == null ? myKey : enchant.getKey().getKey().toLowerCase().replace("_", "").replace("minecraft:", "");
type = cmiEnchant != null ? cmiEnchant.getKeyName() : myKey;
} else if (actionType == ActionType.CUSTOMKILL || actionType == ActionType.COLLECT || actionType == ActionType.MMKILL
|| actionType == ActionType.BAKE || actionType == ActionType.SMELT) {
@ -798,7 +797,7 @@ public class ConfigManager {
try {
amount = Integer.valueOf(myKey);
} catch (NumberFormatException e) {
Jobs.getPluginLogger().warning("Job " + jobName + " has an invalid " + actionType.getName() + " type property: " + myKey + "!");
CMIMessages.consoleMessage("Job " + jobName + " has an invalid " + actionType.getName() + " type property: " + myKey + "!");
return null;
}
@ -822,7 +821,7 @@ public class ConfigManager {
}
if (type == null) {
Jobs.getPluginLogger().warning("Job " + jobName + " has an invalid " + actionType.getName() + " type property: " + myKey + "!");
CMIMessages.consoleMessage("Job " + jobName + " has an invalid " + actionType.getName() + " type property: " + myKey + "!");
return null;
}
@ -1230,7 +1229,7 @@ public class ConfigManager {
if (id.length < 2)
continue;
Enchantment enchant = CMIEnchantment.getEnchantment(id[0]);
Enchantment enchant = CMIEnchantment.getByName(id[0]);
if (enchant == null)
continue;
@ -1369,7 +1368,7 @@ public class ConfigManager {
if (split.length == 0)
continue;
Enchantment ench = CMIEnchantment.getEnchantment(split[0]);
Enchantment ench = CMIEnchantment.getByName(split[0]);
if (ench == null)
continue;

View File

@ -35,12 +35,12 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.CMILib.CMIEnchantment;
import com.gamingmesh.jobs.container.CurrencyLimit;
import com.gamingmesh.jobs.container.CurrencyType;
import net.Zrips.CMILib.CMILib;
import net.Zrips.CMILib.Container.CMIList;
import net.Zrips.CMILib.Enchants.CMIEnchantment;
import net.Zrips.CMILib.Equations.Parser;
import net.Zrips.CMILib.FileHandler.ConfigReader;
import net.Zrips.CMILib.Items.CMIItemStack;
@ -582,7 +582,7 @@ public class GeneralConfigManager {
Enchantment enchant = null;
if (ench != null) {
enchant = CMIEnchantment.getEnchantment(ench);
enchant = CMIEnchantment.getByName(ench);
}
Integer level = null;

View File

@ -15,7 +15,6 @@ import org.bukkit.entity.EntityType;
import org.bukkit.potion.PotionType;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.CMILib.CMIEnchantment;
import com.gamingmesh.jobs.container.ActionType;
import com.gamingmesh.jobs.container.JobInfo;
import com.gamingmesh.jobs.container.NameList;
@ -23,6 +22,7 @@ import com.gamingmesh.jobs.hooks.HookManager;
import com.gamingmesh.jobs.stuff.Util;
import net.Zrips.CMILib.Container.CMIText;
import net.Zrips.CMILib.Enchants.CMIEnchantment;
import net.Zrips.CMILib.Entities.CMIEntityType;
import net.Zrips.CMILib.FileHandler.ConfigReader;
import net.Zrips.CMILib.Items.CMIMaterial;

View File

@ -18,7 +18,6 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionType;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.CMILib.CMIEnchantment;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobItems;
import com.gamingmesh.jobs.container.JobProgression;
@ -28,6 +27,7 @@ import com.gamingmesh.jobs.stuff.GiveItem;
import net.Zrips.CMILib.Colors.CMIChatColor;
import net.Zrips.CMILib.Container.CMIList;
import net.Zrips.CMILib.Enchants.CMIEnchantment;
import net.Zrips.CMILib.GUI.CMIGui;
import net.Zrips.CMILib.GUI.CMIGuiButton;
import net.Zrips.CMILib.GUI.GUIManager.GUIClickType;
@ -494,7 +494,7 @@ public class ShopManager {
if (split.length == 0)
continue;
Enchantment ench = CMIEnchantment.getEnchantment(split[0]);
Enchantment ench = CMIEnchantment.getByName(split[0]);
if (ench == null)
continue;

View File

@ -95,7 +95,6 @@ import org.jetbrains.annotations.NotNull;
import com.bgsoftware.wildstacker.api.enums.StackSplit;
import com.gamingmesh.jobs.ItemBoostManager;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.CMILib.CMIEnchantment;
import com.gamingmesh.jobs.actions.BlockActionInfo;
import com.gamingmesh.jobs.actions.BlockCollectInfo;
import com.gamingmesh.jobs.actions.CustomKillInfo;
@ -128,6 +127,8 @@ import net.Zrips.CMILib.CMILib;
import net.Zrips.CMILib.ActionBar.CMIActionBar;
import net.Zrips.CMILib.Colors.CMIChatColor;
import net.Zrips.CMILib.Container.CMILocation;
import net.Zrips.CMILib.Enchants.CMIEnchantEnum;
import net.Zrips.CMILib.Enchants.CMIEnchantment;
import net.Zrips.CMILib.Entities.CMIEntityType;
import net.Zrips.CMILib.Items.CMIItemStack;
import net.Zrips.CMILib.Items.CMIMC;
@ -469,7 +470,7 @@ public final class JobsPaymentListener implements Listener {
if (item.getType() != Material.AIR && Jobs.getBpManager().isInBp(block)) {
for (Enchantment one : item.getEnchantments().keySet()) {
if (CMIEnchantment.get(one) == CMIEnchantment.SILK_TOUCH) {
if (CMIEnchantment.get(one).equalEnum(CMIEnchantEnum.SILK_TOUCH)) {
return;
}
}
@ -840,13 +841,11 @@ public final class JobsPaymentListener implements Listener {
private static String getEnchantName(Enchantment enchant) {
try {
return enchant.getKey().getKey().toLowerCase().replace("_", "").replace("minecraft:", "");
} catch (Throwable e) {
CMIEnchantment cmiEnchant = CMIEnchantment.get(enchant);
if (cmiEnchant != null)
return cmiEnchant.toString();
return cmiEnchant.getKeyName();
}
return null;
}

View File

@ -35,10 +35,10 @@ import org.bukkit.potion.PotionType;
import org.bukkit.util.BlockIterator;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.CMILib.CMIEnchantment;
import com.gamingmesh.jobs.actions.EnchantActionInfo;
import com.gamingmesh.jobs.container.JobsWorld;
import net.Zrips.CMILib.Enchants.CMIEnchantment;
import net.Zrips.CMILib.Items.CMIMaterial;
import net.Zrips.CMILib.Version.Version;
@ -382,8 +382,8 @@ public final class Util {
}
public static boolean enchantMatchesActionInfo(String enchant, EnchantActionInfo actionInfo) {
CMIEnchantment e = CMIEnchantment.get(actionInfo.getName());
String enchantName = e != null ? CMIEnchantment.get(actionInfo.getName()).toString() : actionInfo.getName();
CMIEnchantment e = CMIEnchantment.getCMIByName(actionInfo.getName());
String enchantName = e != null ? e.getKeyName() : actionInfo.getName();
return (
// Enchantment without level e.g. silk_touch