1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-01 23:13:48 +01:00

Improve enchantment recognition in cmilib

This commit is contained in:
montlikadani 2021-06-20 19:05:53 +02:00
parent cbc22cb491
commit 9b8ee92c36
8 changed files with 34 additions and 41 deletions

View File

@ -51,12 +51,13 @@ public enum CMIEnchantment {
UNBREAKING("DURABILITY"), UNBREAKING("DURABILITY"),
VANISHING_CURSE; VANISHING_CURSE;
private static Map<String, CMIEnchantment> map = new HashMap<>(); private static final Map<String, CMIEnchantment> map = new HashMap<>();
private static Map<Enchantment, CMIEnchantment> emap = new HashMap<>(); private static final Map<Enchantment, CMIEnchantment> emap = new HashMap<>();
private static Map<String, Enchantment> gmap = new HashMap<>(); private static final Map<String, Enchantment> gmap = new HashMap<>();
private List<String> subName = new ArrayList<>(); private final List<String> subName = new ArrayList<>();
private List<String> customNames = new ArrayList<>(); private List<String> customNames = new ArrayList<>();
private Enchantment enchantment; private Enchantment enchantment;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -160,15 +161,25 @@ public enum CMIEnchantment {
if (map.isEmpty()) if (map.isEmpty())
fillUpMap(); fillUpMap();
name = name.contains(":") ? name.split(":", 2)[0] : name.contains("-") ? name.split("-", 2)[0] : name; String[] split = name.split(":", 2);
name = name.toLowerCase().replace("_", "");
return map.get(name); 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) { public static Enchantment getEnchantment(String name) {
if (map.isEmpty()) if (map.isEmpty())
fillUpMap(); fillUpMap();
name = name.contains(":") ? name.split(":", 2)[0] : name.contains("-") ? name.split("-", 2)[0] : name;
String[] split = name.split(":", 2);
if (split.length > 0 || (split = name.split("-", 2)).length > 0) {
name = split[0];
}
name = name.toLowerCase().replace("_", ""); name = name.toLowerCase().replace("_", "");
CMIEnchantment ec = map.get(name); CMIEnchantment ec = map.get(name);

View File

@ -23,7 +23,7 @@ import net.Zrips.CMILib.Colors.CMIChatColor;
import net.Zrips.CMILib.FileHandler.ConfigReader; import net.Zrips.CMILib.FileHandler.ConfigReader;
import net.Zrips.CMILib.Items.CMIMaterial; import net.Zrips.CMILib.Items.CMIMaterial;
public class ItemBoostManager { public final class ItemBoostManager {
private static final Map<String, JobItems> ITEMS = new HashMap<>(); private static final Map<String, JobItems> ITEMS = new HashMap<>();
private static final Map<String, JobItems> LEGACY = new HashMap<>(); private static final Map<String, JobItems> LEGACY = new HashMap<>();

View File

@ -117,7 +117,7 @@ import net.Zrips.CMILib.Items.CMIMaterial;
import net.Zrips.CMILib.RawMessages.RawMessage; import net.Zrips.CMILib.RawMessages.RawMessage;
import net.Zrips.CMILib.Version.Version; import net.Zrips.CMILib.Version.Version;
public class Jobs extends JavaPlugin { public final class Jobs extends JavaPlugin {
private static PlayerManager pManager; private static PlayerManager pManager;
private static JobsCommands cManager; private static JobsCommands cManager;

View File

@ -54,6 +54,7 @@ public class JobConditions {
requiresPerm.add(one.replace("p:", "")); requiresPerm.add(one.replace("p:", ""));
} }
} }
for (String one : perform) { for (String one : perform) {
one = one.toLowerCase(); one = one.toLowerCase();
@ -61,8 +62,9 @@ public class JobConditions {
continue; continue;
String clean = one.substring("p:".length()); String clean = one.substring("p:".length());
if (clean.contains("-")) {
String[] split = clean.split("-", 2); String[] split = clean.split("-", 2);
if (split.length > 1) {
performPerm.put(split[0], split[1].equalsIgnoreCase("true")); performPerm.put(split[0], split[1].equalsIgnoreCase("true"));
} else { } else {
performPerm.put(clean, true); performPerm.put(clean, true);

View File

@ -28,7 +28,6 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
@ -303,7 +302,7 @@ public class JobsPlayer {
* @return {@link Player} or null if not exist * @return {@link Player} or null if not exist
*/ */
public Player getPlayer() { public Player getPlayer() {
return playerUUID != null ? Bukkit.getPlayer(playerUUID) : null; return playerUUID != null ? plugin.getServer().getPlayer(playerUUID) : null;
} }
/** /**
@ -1300,7 +1299,7 @@ public class JobsPlayer {
setSaved(false); setSaved(false);
if (questSignUpdateShed == null) { if (questSignUpdateShed == null) {
questSignUpdateShed = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> { questSignUpdateShed = plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
Jobs.getSignUtil().signUpdate(job, SignTopType.questtoplist); Jobs.getSignUtil().signUpdate(job, SignTopType.questtoplist);
questSignUpdateShed = null; questSignUpdateShed = null;
}, Jobs.getGCManager().getSavePeriod() * 60 * 20L); }, Jobs.getGCManager().getSavePeriod() * 60 * 20L);

View File

@ -13,7 +13,7 @@ import org.bukkit.inventory.meta.ItemMeta;
import net.Zrips.CMILib.Colors.CMIChatColor; import net.Zrips.CMILib.Colors.CMIChatColor;
import net.Zrips.CMILib.Items.CMIMaterial; import net.Zrips.CMILib.Items.CMIMaterial;
public class GiveItem { public final class GiveItem {
public static void giveItemForPlayer(Player player, int id, int meta, int qty, String name, List<String> lore, public static void giveItemForPlayer(Player player, int id, int meta, int qty, String name, List<String> lore,
java.util.Map<Enchantment, Integer> enchants) { java.util.Map<Enchantment, Integer> enchants) {

View File

@ -39,7 +39,8 @@ import com.gamingmesh.jobs.container.JobsWorld;
import net.Zrips.CMILib.Items.CMIMaterial; import net.Zrips.CMILib.Items.CMIMaterial;
import net.Zrips.CMILib.Version.Version; import net.Zrips.CMILib.Version.Version;
public class Util { @SuppressWarnings("deprecation")
public final class Util {
private static Map<UUID, String> jobsEditorMap = new HashMap<>(), questsEditorMap = new HashMap<>(); private static Map<UUID, String> jobsEditorMap = new HashMap<>(), questsEditorMap = new HashMap<>();
@ -136,7 +137,6 @@ public class Util {
} }
} }
@SuppressWarnings("deprecation")
public static ItemStack getSkull(String skullOwner) { public static ItemStack getSkull(String skullOwner) {
ItemStack item = CMIMaterial.PLAYER_HEAD.newItemStack(); ItemStack item = CMIMaterial.PLAYER_HEAD.newItemStack();
SkullMeta skullMeta = (SkullMeta) item.getItemMeta(); SkullMeta skullMeta = (SkullMeta) item.getItemMeta();

View File

@ -7,13 +7,12 @@ import java.net.URLConnection;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
public class VersionChecker { public final class VersionChecker {
private Jobs plugin; private Jobs plugin;
@ -21,37 +20,19 @@ public class VersionChecker {
this.plugin = plugin; this.plugin = plugin;
} }
public Integer convertVersion(String v) {
v = v.replaceAll("[^\\d.]", "");
Integer version = 0;
if (v.contains(".")) {
String lVersion = "";
for (String one : v.split("\\.")) {
String s = one;
if (s.length() == 1)
s = "0" + s;
lVersion += s;
}
version = Integer.parseInt(lVersion);
} else {
version = Integer.parseInt(v);
}
return version;
}
public void VersionCheck(final Player player) { public void VersionCheck(final Player player) {
if (!Jobs.getGCManager().isShowNewVersion()) if (!Jobs.getGCManager().isShowNewVersion())
return; return;
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
String newVersion = getNewVersion(); String newVersion = getNewVersion();
if (newVersion == null) if (newVersion == null)
return; return;
int currentVersion = Integer.parseInt(plugin.getDescription().getVersion().replace(".", "")); int currentVersion = Integer.parseInt(plugin.getDescription().getVersion().replace(".", ""));
if (Integer.parseInt(newVersion.replace(".", "")) <= currentVersion || currentVersion >= int newVer = Integer.parseInt(newVersion.replace(".", ""));
Integer.parseInt(newVersion.replace(".", "")))
if (newVer <= currentVersion || currentVersion >= newVer)
return; return;
List<String> msg = Arrays.asList( List<String> msg = Arrays.asList(