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

Option to translate potion/tipped arrow effect names

This commit is contained in:
Zrips 2022-08-08 12:25:54 +03:00
parent 389b6dc724
commit 2056525a16
3 changed files with 1904 additions and 1866 deletions

View File

@ -12,6 +12,7 @@ import java.util.stream.Collectors;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.potion.PotionType;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.CMILib.CMIEnchantment;
@ -21,426 +22,456 @@ import com.gamingmesh.jobs.container.NameList;
import com.gamingmesh.jobs.hooks.HookManager;
import com.gamingmesh.jobs.stuff.Util;
import net.Zrips.CMILib.Container.CMIText;
import net.Zrips.CMILib.Entities.CMIEntityType;
import net.Zrips.CMILib.FileHandler.ConfigReader;
import net.Zrips.CMILib.Items.CMIMaterial;
import net.Zrips.CMILib.Logs.CMIDebug;
public class NameTranslatorManager {
private final Map<CMIMaterial, NameList> listOfNames = new HashMap<>();
private final List<NameList> listOfEntities = new ArrayList<>(), listOfColors = new ArrayList<>();
private final Map<String, NameList> listOfEnchants = new HashMap<>(), listOfMMEntities = new HashMap<>();
private final Map<String, NameList> listOfEnchants = new HashMap<>();
private final Map<String, NameList> listOfMMEntities = new HashMap<>();
private final Map<String, NameList> listOfPotionEffects = new HashMap<>();
public String translate(String materialName, JobInfo info) {
return translate(materialName, info.getActionType(), info.getId(), info.getMeta(), info.getName());
return translate(materialName, info.getActionType(), info.getId(), info.getMeta(), info.getName());
}
public String translate(String materialName, ActionType action, int id, String meta, String name) {
// Translating name to user friendly
if (Jobs.getGCManager().UseCustomNames)
switch (action) {
case BREAK:
case TNTBREAK:
case EAT:
case CRAFT:
case DYE:
case COLLECT:
case BAKE:
case PLACE:
case SMELT:
case REPAIR:
case BREW:
case FISH:
case STRIPLOGS:
String matName = materialName;
materialName = materialName.replace(" ", "");
// Translating name to user friendly
if (materialName.toLowerCase().contains("arrow"))
CMIDebug.d(materialName, meta, Util.getPotionByName(meta));
if (Jobs.getGCManager().UseCustomNames)
switch (action) {
case BREAK:
case TNTBREAK:
case EAT:
case CRAFT:
case DYE:
case COLLECT:
case BAKE:
case PLACE:
case SMELT:
case REPAIR:
case BREW:
case FISH:
case STRIPLOGS:
String matName = materialName;
materialName = materialName.replace(" ", "");
if (materialName.contains(":"))
materialName = materialName.split(":")[0];
if (materialName.contains(":"))
materialName = materialName.split(":")[0];
CMIMaterial mat = CMIMaterial.get(materialName);
CMIMaterial mat = CMIMaterial.get(materialName);
NameList nameLs = listOfNames.get(mat);
NameList nameLs = listOfNames.get(mat);
if (nameLs != null && !mat.isNone()) {
if (meta != null && !meta.isEmpty() && mat.isCanHavePotionType() && Util.getPotionByName(meta) != null) {
return nameLs.getName() + ":" + meta;
}
if (nameLs != null && !mat.isNone()) {
if (meta != null && !meta.isEmpty() && mat.isCanHavePotionType() && Util.getPotionByName(meta) != null) {
NameList record = listOfPotionEffects.get(meta.toLowerCase().replace("_", ""));
if (record != null)
meta = record.getMinecraftName();
return nameLs.getName() + ":" + meta;
}
if (name != null && !name.isEmpty()) {
return nameLs.getName();
}
}
if (name != null && !name.isEmpty()) {
return nameLs.getName();
}
}
if (meta != null && !meta.isEmpty()) {
mat = CMIMaterial.get(materialName + ":" + meta);
if (meta != null && !meta.isEmpty()) {
mat = CMIMaterial.get(materialName + ":" + meta);
if ((nameLs = listOfNames.get(mat)) == null) {
mat = CMIMaterial.get(materialName.replace(" ", ""));
if ((nameLs = listOfNames.get(mat)) == null) {
mat = CMIMaterial.get(materialName.replace(" ", ""));
if ((nameLs = listOfNames.get(mat)) != null) {
NameList nameMeta = listOfNames.get(CMIMaterial.get(meta.replace(" ", "")));
if ((nameLs = listOfNames.get(mat)) != null) {
NameList nameMeta = listOfNames.get(CMIMaterial.get(meta.replace(" ", "")));
if (nameMeta != null) {
return nameLs.getName() + ":" + nameMeta.getMeta();
}
}
if (nameMeta != null) {
return nameLs.getName() + ":" + nameMeta.getMeta();
}
}
if (mat == CMIMaterial.NONE) {
return Arrays.stream(matName.split("\\s|:"))
.map(word -> word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase())
.collect(Collectors.joining(" ")); // returns capitalized word (from this -> To This)
}
if (mat == CMIMaterial.NONE) {
return Arrays.stream(matName.split("\\s|:"))
.map(word -> word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase())
.collect(Collectors.joining(" ")); // returns capitalized word (from this -> To This)
}
return mat.getName();
}
}
return mat.getName();
}
}
if (id > 0 && meta != null && !meta.isEmpty()) {
mat = CMIMaterial.get(id + ":" + meta);
nameLs = listOfNames.get(mat);
if (id > 0 && meta != null && !meta.isEmpty()) {
mat = CMIMaterial.get(id + ":" + meta);
nameLs = listOfNames.get(mat);
if (nameLs == null) {
return mat.getName();
}
}
if (nameLs == null) {
return mat.getName();
}
}
if (mat.isNone()) {
return matName;
}
if (mat.isNone()) {
return matName;
}
return mat.getName();
case BREED:
case KILL:
case MILK:
case TAME:
for (NameList one : listOfEntities) {
String ids = one.getId() + ":" + one.getMeta();
return mat.getName();
case BREED:
case KILL:
case MILK:
case TAME:
for (NameList one : listOfEntities) {
String ids = one.getId() + ":" + one.getMeta();
if (!one.getMeta().isEmpty() && !one.getId().equals("0") && ids.equalsIgnoreCase(id + ":" + meta)) {
return one.getName();
}
if (!one.getMeta().isEmpty() && !one.getId().equals("0") && ids.equalsIgnoreCase(id + ":" + meta)) {
return one.getName();
}
ids = one.getId();
ids = one.getId();
if (!one.getId().equals("0") && ids.equalsIgnoreCase(Integer.toString(id))) {
return one.getName();
}
if (!one.getId().equals("0") && ids.equalsIgnoreCase(Integer.toString(id))) {
return one.getName();
}
ids = one.getMinecraftName();
ids = one.getMinecraftName();
if (ids.equalsIgnoreCase(name)) {
return one.getName();
}
}
break;
case ENCHANT:
String mName = materialName;
String level = "";
if (ids.equalsIgnoreCase(name)) {
return one.getName();
}
}
break;
case ENCHANT:
String mName = materialName;
String level = "";
String[] split = materialName.split(":", 2);
if (split.length > 1) {
mName = split[0];
level = ":" + split[1];
}
String[] split = materialName.split(":", 2);
if (split.length > 1) {
mName = split[0];
level = ":" + split[1];
}
NameList nameInfo = listOfEnchants.get(mName.toLowerCase().replace("_", ""));
if (nameInfo != null) {
return nameInfo.getMinecraftName() + level;
}
NameList nameInfo = listOfEnchants.get(mName.toLowerCase().replace("_", ""));
if (nameInfo != null) {
return nameInfo.getMinecraftName() + level;
}
break;
case SHEAR:
for (NameList one : listOfColors) {
if (one.getMinecraftName().equalsIgnoreCase(name)) {
return one.getName();
}
}
break;
case SHEAR:
for (NameList one : listOfColors) {
if (one.getMinecraftName().equalsIgnoreCase(name)) {
return one.getName();
}
}
return name == null ? "nocolor" : Arrays.stream(name.split("\\s|:|-"))
.map(word -> word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase())
.collect(Collectors.joining(" ")); // returns capitalized word (from this -> To This)
case MMKILL:
NameList got = listOfMMEntities.get(materialName.toLowerCase());
return name == null ? "nocolor" : Arrays.stream(name.split("\\s|:|-"))
.map(word -> word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase())
.collect(Collectors.joining(" ")); // returns capitalized word (from this -> To This)
case MMKILL:
NameList got = listOfMMEntities.get(materialName.toLowerCase());
if (got != null && got.getName() != null)
return got.getName();
if (got != null && got.getName() != null)
return got.getName();
return HookManager.getMythicManager() == null ? materialName : HookManager.getMythicManager().getDisplayName(materialName);
default:
break;
}
return HookManager.getMythicManager() == null ? materialName : HookManager.getMythicManager().getDisplayName(materialName);
default:
break;
}
return materialName;
return materialName;
}
public void readFile() {
YmlMaker itemFile = new YmlMaker(Jobs.getFolder(), "TranslatableWords" + File.separator + "Words_"
+ Jobs.getGCManager().localeString + ".yml");
YmlMaker itemFile = new YmlMaker(Jobs.getFolder(), "TranslatableWords" + File.separator + "Words_"
+ Jobs.getGCManager().localeString + ".yml");
if (!itemFile.getConfigFile().getName().equalsIgnoreCase("en")) {
itemFile.saveDefaultConfig();
}
if (!itemFile.getConfigFile().getName().equalsIgnoreCase("en")) {
itemFile.saveDefaultConfig();
}
ConfigurationSection section = itemFile.getConfig().getConfigurationSection("ItemList");
ConfigurationSection section = itemFile.getConfig().getConfigurationSection("ItemList");
if (section != null) {
listOfNames.clear();
if (section != null) {
listOfNames.clear();
for (String one : section.getKeys(false)) {
String[] firstSplit = one.split("-", 2);
String split = firstSplit.length > 0 ? firstSplit[0] : one;
for (String one : section.getKeys(false)) {
String[] firstSplit = one.split("-", 2);
String split = firstSplit.length > 0 ? firstSplit[0] : one;
String[] splitted = split.split(":", 2);
String[] splitted = split.split(":", 2);
String id = splitted.length > 0 ? splitted[0] : split;
String meta = splitted.length > 1 ? splitted[1] : "";
String id = splitted.length > 0 ? splitted[0] : split;
String meta = splitted.length > 1 ? splitted[1] : "";
String mcName = firstSplit.length > 1 ? firstSplit[1] : one;
String mcName = firstSplit.length > 1 ? firstSplit[1] : one;
listOfNames.put(CMIMaterial.get(one), new NameList(id, meta, section.getString(one), mcName));
}
listOfNames.put(CMIMaterial.get(one), new NameList(id, meta, section.getString(one), mcName));
}
if (listOfNames.size() > 0)
Jobs.consoleMsg("&eLoaded &6" + listOfNames.size() + " &ecustom item names");
} else
Jobs.consoleMsg("&cThe ItemList section not found in &6" + itemFile.fileName + " &cfile.");
if (listOfNames.size() > 0)
Jobs.consoleMsg("&eLoaded &6" + listOfNames.size() + " &ecustom item names");
} else
Jobs.consoleMsg("&cThe ItemList section not found in &6" + itemFile.fileName + " &cfile.");
if ((section = itemFile.getConfig().getConfigurationSection("EntityList")) != null) {
listOfEntities.clear();
if ((section = itemFile.getConfig().getConfigurationSection("EntityList")) != null) {
listOfEntities.clear();
for (String one : section.getKeys(false)) {
String[] firstSplit = one.split("-", 2);
String split = firstSplit.length > 0 ? firstSplit[0] : one;
for (String one : section.getKeys(false)) {
String[] firstSplit = one.split("-", 2);
String split = firstSplit.length > 0 ? firstSplit[0] : one;
String[] splitted = split.split(":", 2);
String[] splitted = split.split(":", 2);
String id = splitted.length > 0 ? splitted[0] : split;
String meta = splitted.length > 1 ? splitted[1] : "";
String mcName = firstSplit.length > 1 ? firstSplit[1] : one;
String id = splitted.length > 0 ? splitted[0] : split;
String meta = splitted.length > 1 ? splitted[1] : "";
String mcName = firstSplit.length > 1 ? firstSplit[1] : one;
listOfEntities.add(new NameList(id, meta, section.getString(one), mcName));
}
listOfEntities.add(new NameList(id, meta, section.getString(one), mcName));
}
if (!listOfEntities.isEmpty())
Jobs.consoleMsg("&eLoaded &6" + listOfEntities.size() + " &ecustom entity names");
} else
Jobs.consoleMsg("&cThe EntityList section not found in &6" + itemFile.fileName + " &cfile.");
if (!listOfEntities.isEmpty())
Jobs.consoleMsg("&eLoaded &6" + listOfEntities.size() + " &ecustom entity names");
} else
Jobs.consoleMsg("&cThe EntityList section not found in &6" + itemFile.fileName + " &cfile.");
if ((section = itemFile.getConfig().getConfigurationSection("MythicEntityList")) != null) {
listOfMMEntities.clear();
if ((section = itemFile.getConfig().getConfigurationSection("MythicEntityList")) != null) {
listOfMMEntities.clear();
for (String one : section.getKeys(false)) {
String name = section.getString(one);
listOfMMEntities.put(one.toLowerCase(), new NameList(null, null, name, name));
}
for (String one : section.getKeys(false)) {
String name = section.getString(one);
listOfMMEntities.put(one.toLowerCase(), new NameList(null, null, name, name));
}
if (listOfMMEntities.size() > 0)
Jobs.consoleMsg("&eLoaded &6" + listOfMMEntities.size() + " &ecustom MythicMobs names");
} else
Jobs.consoleMsg("&cThe MythicEntityList section not found in &6" + itemFile.fileName + " &cfile.");
if (listOfMMEntities.size() > 0)
Jobs.consoleMsg("&eLoaded &6" + listOfMMEntities.size() + " &ecustom MythicMobs names");
} else
Jobs.consoleMsg("&cThe MythicEntityList section not found in &6" + itemFile.fileName + " &cfile.");
if ((section = itemFile.getConfig().getConfigurationSection("EnchantList")) != null) {
listOfEnchants.clear();
if ((section = itemFile.getConfig().getConfigurationSection("EnchantList")) != null) {
listOfEnchants.clear();
for (String one : section.getKeys(false)) {
listOfEnchants.put(one.replace("_", "").toLowerCase(), new NameList(one, one, one, section.getString(one)));
}
for (String one : section.getKeys(false)) {
listOfEnchants.put(one.replace("_", "").toLowerCase(), new NameList(one, one, one, section.getString(one)));
}
if (listOfEnchants.size() > 0)
Jobs.consoleMsg("&eLoaded &6" + listOfEnchants.size() + " &ecustom enchant names");
} else
Jobs.consoleMsg("&cThe EnchantList section not found in &6" + itemFile.fileName + " &cfile.");
if (listOfEnchants.size() > 0)
Jobs.consoleMsg("&eLoaded &6" + listOfEnchants.size() + " &ecustom enchant names");
} else
Jobs.consoleMsg("&cThe EnchantList section not found in &6" + itemFile.fileName + " &cfile.");
if ((section = itemFile.getConfig().getConfigurationSection("ColorList")) != null) {
listOfColors.clear();
if ((section = itemFile.getConfig().getConfigurationSection("PotionEffects")) != null) {
listOfPotionEffects.clear();
for (String one : section.getKeys(false)) {
String[] split = one.split("-", 2);
String id = split.length > 0 ? split[0] : one;
String mcName = split.length > 1 ? split[1] : "";
listOfColors.add(new NameList(id, "", section.getString(one), mcName));
}
for (String one : section.getKeys(false)) {
listOfPotionEffects.put(one.replace("_", "").toLowerCase(), new NameList(one, one, one, section.getString(one)));
}
if (!listOfColors.isEmpty())
Jobs.consoleMsg("&eLoaded &6" + listOfColors.size() + " &ecustom color names");
} else
Jobs.consoleMsg("&cThe ColorList section not found in &6" + itemFile.fileName + " &cfile.");
if (listOfPotionEffects.size() > 0)
Jobs.consoleMsg("&eLoaded &6" + listOfPotionEffects.size() + " &ecustom enchant names");
} else
Jobs.consoleMsg("&cThe PotionEffects section not found in &6" + itemFile.fileName + " &cfile.");
if ((section = itemFile.getConfig().getConfigurationSection("ColorList")) != null) {
listOfColors.clear();
for (String one : section.getKeys(false)) {
String[] split = one.split("-", 2);
String id = split.length > 0 ? split[0] : one;
String mcName = split.length > 1 ? split[1] : "";
listOfColors.add(new NameList(id, "", section.getString(one), mcName));
}
if (!listOfColors.isEmpty())
Jobs.consoleMsg("&eLoaded &6" + listOfColors.size() + " &ecustom color names");
} else
Jobs.consoleMsg("&cThe ColorList section not found in &6" + itemFile.fileName + " &cfile.");
}
@SuppressWarnings("deprecation")
void load() {
String ls = Jobs.getGCManager().localeString;
if (ls.isEmpty())
return;
String ls = Jobs.getGCManager().localeString;
if (ls.isEmpty())
return;
File tWordsFolder = new File(Jobs.getFolder(), "TranslatableWords");
tWordsFolder.mkdirs();
File tWordsFolder = new File(Jobs.getFolder(), "TranslatableWords");
tWordsFolder.mkdirs();
File file = new File(Jobs.getFolder(), "TranslatableWords.yml");
File file2 = new File(tWordsFolder, "Words_" + ls + ".yml");
if (file.exists())
file.renameTo(file2);
File file = new File(Jobs.getFolder(), "TranslatableWords.yml");
File file2 = new File(tWordsFolder, "Words_" + ls + ".yml");
if (file.exists())
file.renameTo(file2);
// Just copying default language files, except en, that one will be generated
List<String> languages = new ArrayList<>();
// Just copying default language files, except en, that one will be generated
List<String> languages = new ArrayList<>();
// This should be present to copy over default files into TranslatableWords folder if file doesn't exist. Grabs all files from plugin file.
try {
languages.addAll(Util.getFilesFromPackage("TranslatableWords", "Words_", "yml"));
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
for (Iterator<String> e1 = languages.iterator(); e1.hasNext();) {
String lang = e1.next();
YmlMaker langFile = new YmlMaker(Jobs.getFolder(), "TranslatableWords" + File.separator + "Words_" + lang + ".yml");
langFile.saveDefaultConfig();
}
//Up to here.
// This should be present to copy over default files into TranslatableWords folder if file doesn't exist. Grabs all files from plugin file.
try {
languages.addAll(Util.getFilesFromPackage("TranslatableWords", "Words_", "yml"));
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
for (Iterator<String> e1 = languages.iterator(); e1.hasNext();) {
String lang = e1.next();
YmlMaker langFile = new YmlMaker(Jobs.getFolder(), "TranslatableWords" + File.separator + "Words_" + lang + ".yml");
langFile.saveDefaultConfig();
}
//Up to here.
languages.add("en");
languages.add("en");
File customLocaleFile = new File(tWordsFolder, "Words_" + ls + ".yml");
if (!customLocaleFile.exists() && !ls.equalsIgnoreCase("en"))
languages.add(ls);
File customLocaleFile = new File(tWordsFolder, "Words_" + ls + ".yml");
if (!customLocaleFile.exists() && !ls.equalsIgnoreCase("en"))
languages.add(ls);
for (String lang : languages) {
File f = new File(tWordsFolder, "Words_" + lang + ".yml");
for (String lang : languages) {
File f = new File(tWordsFolder, "Words_" + lang + ".yml");
// Fail safe if file get corrupted and being created with corrupted data, we need to recreate it
if ((f.length() / 1024) > 1024) {
f.delete();
f = new File(tWordsFolder, "Words_" + lang + ".yml");
}
// Fail safe if file get corrupted and being created with corrupted data, we need to recreate it
if ((f.length() / 1024) > 1024) {
f.delete();
f = new File(tWordsFolder, "Words_" + lang + ".yml");
}
ConfigReader c;
try {
c = new ConfigReader(f);
} catch (Exception e) {
e.printStackTrace();
continue;
}
c.copyDefaults(true);
ConfigReader c;
try {
c = new ConfigReader(f);
} catch (Exception e) {
e.printStackTrace();
continue;
}
c.copyDefaults(true);
for (CMIMaterial mat : CMIMaterial.values()) {
if (mat == CMIMaterial.NONE) {
continue;
}
for (CMIMaterial mat : CMIMaterial.values()) {
if (mat == CMIMaterial.NONE) {
continue;
}
String n = mat.getLegacyId() + (mat.getLegacyData() == -1 ? "" : ":" + mat.getLegacyData());
String name = c.getC().getString("ItemList." + mat.toString());
String n = mat.getLegacyId() + (mat.getLegacyData() == -1 ? "" : ":" + mat.getLegacyData());
String name = c.getC().getString("ItemList." + mat.toString());
if (name == null) {
name = c.getC().getString("ItemList." + n + ".Name");
}
if (name == null) {
name = c.getC().getString("ItemList." + n + ".Name");
}
if (name == null) {
n = mat.getLegacyId() + ":" + mat.getLegacyData();
name = c.getC().getString("ItemList." + n + ".Name");
}
if (name == null) {
n = mat.getLegacyId() + ":" + mat.getLegacyData();
name = c.getC().getString("ItemList." + n + ".Name");
}
if (name == null) {
n = String.valueOf(mat.getLegacyId());
name = c.getC().getString("ItemList." + n + ".Name");
}
if (name == null) {
n = String.valueOf(mat.getLegacyId());
name = c.getC().getString("ItemList." + n + ".Name");
}
if (name == null) {
n = String.valueOf(mat.getId());
name = c.getC().getString("ItemList." + n + ".Name");
}
if (name == null) {
n = String.valueOf(mat.getId());
name = c.getC().getString("ItemList." + n + ".Name");
}
if (name == null) {
n = mat.getLegacyId() + ":" + mat.getLegacyData() + "-" + mat.getBukkitName();
name = c.getC().getString("ItemList." + n);
}
if (name == null) {
n = mat.getLegacyId() + ":" + mat.getLegacyData() + "-" + mat.getBukkitName();
name = c.getC().getString("ItemList." + n);
}
if (name == null) {
n = mat.getLegacyId() + "-" + mat.getBukkitName();
name = c.getC().getString("ItemList." + n);
}
if (name == null) {
n = mat.getLegacyId() + "-" + mat.getBukkitName();
name = c.getC().getString("ItemList." + n);
}
if (name == null) {
n = mat.getId() + "-" + mat.getBukkitName();
name = c.getC().getString("ItemList." + n);
}
if (name == null) {
n = mat.getId() + "-" + mat.getBukkitName();
name = c.getC().getString("ItemList." + n);
}
if (name == null) {
name = mat.getName();
}
if (name == null) {
name = mat.getName();
}
c.get("ItemList." + mat.toString(), name);
}
c.get("ItemList." + mat.toString(), name);
}
for (EntityType one : EntityType.values()) {
CMIEntityType ent = CMIEntityType.getByType(one);
if (ent == null || !ent.isAlive())
continue;
for (EntityType one : EntityType.values()) {
CMIEntityType ent = CMIEntityType.getByType(one);
if (ent == null || !ent.isAlive())
continue;
String n = Integer.toString(ent.getId());
String name = c.getC().getString("EntityList." + n + ".Name");
String n = Integer.toString(ent.getId());
String name = c.getC().getString("EntityList." + n + ".Name");
if (name == null) {
n += "-" + ent.toString();
name = c.getC().getString("EntityList." + n);
}
if (name == null) {
n += "-" + ent.toString();
name = c.getC().getString("EntityList." + n);
}
if (name == null) {
name = ent.getName();
}
if (name == null) {
name = ent.getName();
}
c.get("EntityList." + ent.getId() + "-" + ent.toString(), name);
}
c.get("EntityList." + ent.getId() + "-" + ent.toString(), name);
}
ConfigurationSection enchSection = c.getC().getConfigurationSection("EnchantList");
for (Enchantment one : Enchantment.values()) {
String enchName = CMIEnchantment.getName(one);
if (enchName.equals("Unknown"))
continue;
ConfigurationSection enchSection = c.getC().getConfigurationSection("EnchantList");
for (Enchantment one : Enchantment.values()) {
String enchName = CMIEnchantment.getName(one);
if (enchName.equals("Unknown"))
continue;
String name = enchName;
String name = enchName;
if (enchSection != null) {
for (String onek : enchSection.getKeys(false)) {
String old = enchSection.getString(onek + ".MCName");
if (enchSection != null) {
for (String onek : enchSection.getKeys(false)) {
String old = enchSection.getString(onek + ".MCName");
if (old != null && old.equalsIgnoreCase(enchName)) {
name = enchSection.getString(onek + ".Name");
break;
}
}
}
if (old != null && old.equalsIgnoreCase(enchName)) {
name = enchSection.getString(onek + ".Name");
break;
}
}
}
c.get("EnchantList." + enchName, name);
}
c.get("EnchantList." + enchName, name);
}
// Color list
c.get("ColorList.0-white", "&fWhite");
c.get("ColorList.1-orange", "&6Orange");
c.get("ColorList.2-magenta", "&dMagenta");
c.get("ColorList.3-light_blue", "&9Light Blue");
c.get("ColorList.4-yellow", "&eYellow");
c.get("ColorList.5-lime", "&aLime");
c.get("ColorList.6-pink", "&dPink");
c.get("ColorList.7-gray", "&8Gray");
c.get("ColorList.8-light_gray", "&7Light Gray");
c.get("ColorList.9-cyan", "&3Cyan");
c.get("ColorList.10-purple", "&5Purple");
c.get("ColorList.11-blue", "&1Blue");
c.get("ColorList.12-brown", "&4Brown");
c.get("ColorList.13-green", "&2Green");
c.get("ColorList.14-red", "&cRed");
c.get("ColorList.15-black", "&0Black");
for (PotionType one : PotionType.values()) {
String potionName = CMIText.firstToUpperCase(one.name());
if (potionName.equals("Unknown"))
continue;
c.get("PotionEffects." + potionName, potionName);
}
if (!c.getC().isConfigurationSection("MythicEntityList")) {
c.get("MythicEntityList.AngrySludge", "Angry Sludge");
c.get("MythicEntityList.SkeletalKnight", "Skeletal Knight");
} else {
c.set("MythicEntityList", c.getC().get("MythicEntityList"));
}
// Color list
c.get("ColorList.0-white", "&fWhite");
c.get("ColorList.1-orange", "&6Orange");
c.get("ColorList.2-magenta", "&dMagenta");
c.get("ColorList.3-light_blue", "&9Light Blue");
c.get("ColorList.4-yellow", "&eYellow");
c.get("ColorList.5-lime", "&aLime");
c.get("ColorList.6-pink", "&dPink");
c.get("ColorList.7-gray", "&8Gray");
c.get("ColorList.8-light_gray", "&7Light Gray");
c.get("ColorList.9-cyan", "&3Cyan");
c.get("ColorList.10-purple", "&5Purple");
c.get("ColorList.11-blue", "&1Blue");
c.get("ColorList.12-brown", "&4Brown");
c.get("ColorList.13-green", "&2Green");
c.get("ColorList.14-red", "&cRed");
c.get("ColorList.15-black", "&0Black");
c.save();
}
readFile();
if (!c.getC().isConfigurationSection("MythicEntityList")) {
c.get("MythicEntityList.AngrySludge", "Angry Sludge");
c.get("MythicEntityList.SkeletalKnight", "Skeletal Knight");
} else {
c.set("MythicEntityList", c.getC().get("MythicEntityList"));
}
c.save();
}
readFile();
}
}

View File

@ -55,353 +55,353 @@ public final class Util {
private final static TreeMap<Integer, String> map = new TreeMap<Integer, String>();
static {
map.put(1000, "M");
map.put(900, "CM");
map.put(500, "D");
map.put(400, "CD");
map.put(100, "C");
map.put(90, "XC");
map.put(50, "L");
map.put(40, "XL");
map.put(10, "X");
map.put(9, "IX");
map.put(5, "V");
map.put(4, "IV");
map.put(1, "I");
map.put(1000, "M");
map.put(900, "CM");
map.put(500, "D");
map.put(400, "CD");
map.put(100, "C");
map.put(90, "XC");
map.put(50, "L");
map.put(40, "XL");
map.put(10, "X");
map.put(9, "IX");
map.put(5, "V");
map.put(4, "IV");
map.put(1, "I");
}
public final static String toRoman(int number) {
int l = map.floorKey(number);
if (number == l) {
return map.get(number);
}
return map.get(l) + toRoman(number - l);
int l = map.floorKey(number);
if (number == l) {
return map.get(number);
}
return map.get(l) + toRoman(number - l);
}
public static List<Block> getPistonRetractBlocks(BlockPistonRetractEvent event) {
if (Version.isCurrentEqualOrHigher(Version.v1_8_R1)) {
return new ArrayList<>(event.getBlocks());
}
if (Version.isCurrentEqualOrHigher(Version.v1_8_R1)) {
return new ArrayList<>(event.getBlocks());
}
List<Block> blocks = new ArrayList<>();
blocks.add(event.getBlock());
return blocks;
List<Block> blocks = new ArrayList<>();
blocks.add(event.getBlock());
return blocks;
}
public static double getDistance(Location loc1, Location loc2) {
if (loc1 == null || loc2 == null || loc1.getWorld() != loc2.getWorld())
return Integer.MAX_VALUE;
if (loc1 == null || loc2 == null || loc1.getWorld() != loc2.getWorld())
return Integer.MAX_VALUE;
try {
return loc1.distance(loc2);
} catch (Throwable e) {
return Integer.MAX_VALUE;
}
try {
return loc1.distance(loc2);
} catch (Throwable e) {
return Integer.MAX_VALUE;
}
}
public static String getRealType(Entity entity) {
if (Version.isCurrentEqualOrHigher(Version.v1_11_R1)) {
return entity.getType().name();
}
if (Version.isCurrentEqualOrHigher(Version.v1_11_R1)) {
return entity.getType().name();
}
String name = entity.getType().name();
String name = entity.getType().name();
switch (entity.getType().toString()) {
case "GUARDIAN":
if (((org.bukkit.entity.Guardian) entity).isElder())
name = "GuardianElder";
switch (entity.getType().toString()) {
case "GUARDIAN":
if (((org.bukkit.entity.Guardian) entity).isElder())
name = "GuardianElder";
break;
case "HORSE":
Horse horse = (Horse) entity;
break;
case "HORSE":
Horse horse = (Horse) entity;
if (horse.getVariant().toString().equals("UNDEAD_HORSE"))
name = "HorseZombie";
if (horse.getVariant().toString().equals("UNDEAD_HORSE"))
name = "HorseZombie";
if (horse.getVariant().toString().equals("SKELETON_HORSE"))
name = "HorseSkeleton";
if (horse.getVariant().toString().equals("SKELETON_HORSE"))
name = "HorseSkeleton";
break;
case "SKELETON":
Skeleton skeleton = (Skeleton) entity;
break;
case "SKELETON":
Skeleton skeleton = (Skeleton) entity;
if (skeleton.getSkeletonType().toString().equals("WITHER"))
name = "SkeletonWither";
if (skeleton.getSkeletonType().toString().equals("WITHER"))
name = "SkeletonWither";
if (Version.isCurrentEqualOrHigher(Version.v1_10_R1) && skeleton.getSkeletonType().toString().equals("STRAY"))
name = "SkeletonStray";
if (Version.isCurrentEqualOrHigher(Version.v1_10_R1) && skeleton.getSkeletonType().toString().equals("STRAY"))
name = "SkeletonStray";
break;
case "ZOMBIE":
Zombie zombie = (Zombie) entity;
break;
case "ZOMBIE":
Zombie zombie = (Zombie) entity;
if (Version.isCurrentEqualOrHigher(Version.v1_10_R1)) {
if (zombie.isVillager() && zombie.getVillagerProfession().toString().equals("HUSK"))
return "ZombieVillager";
if (Version.isCurrentEqualOrHigher(Version.v1_10_R1)) {
if (zombie.isVillager() && zombie.getVillagerProfession().toString().equals("HUSK"))
return "ZombieVillager";
if (zombie.getVillagerProfession().toString().equals("HUSK"))
return "ZombieHusk";
} else if (zombie.isVillager()) {
return "ZombieVillager";
}
if (zombie.getVillagerProfession().toString().equals("HUSK"))
return "ZombieHusk";
} else if (zombie.isVillager()) {
return "ZombieVillager";
}
break;
default:
break;
}
break;
default:
break;
}
return name;
return name;
}
public static double getMaxHealth(LivingEntity entity) {
if (Version.isCurrentEqualOrHigher(Version.v1_12_R1)) {
org.bukkit.attribute.AttributeInstance attr = entity.getAttribute(Attribute.GENERIC_MAX_HEALTH);
return attr == null ? 0d : attr.getBaseValue();
}
if (Version.isCurrentEqualOrHigher(Version.v1_12_R1)) {
org.bukkit.attribute.AttributeInstance attr = entity.getAttribute(Attribute.GENERIC_MAX_HEALTH);
return attr == null ? 0d : attr.getBaseValue();
}
return entity.getMaxHealth();
return entity.getMaxHealth();
}
public static short getDurability(ItemStack item) {
if (Version.isCurrentEqualOrHigher(Version.v1_13_R1)) {
return (short) ((Damageable) item.getItemMeta()).getDamage();
}
return item.getDurability();
if (Version.isCurrentEqualOrHigher(Version.v1_13_R1)) {
return (short) ((Damageable) item.getItemMeta()).getDamage();
}
return item.getDurability();
}
public static void setSkullOwner(SkullMeta meta, OfflinePlayer player) {
if (meta != null && player != null) {
if (Version.isCurrentEqualOrHigher(Version.v1_13_R1)) {
meta.setOwningPlayer(player);
} else {
meta.setOwner(player.getName());
}
}
if (meta != null && player != null) {
if (Version.isCurrentEqualOrHigher(Version.v1_13_R1)) {
meta.setOwningPlayer(player);
} else {
meta.setOwner(player.getName());
}
}
}
public static ItemStack getSkull(String skullOwner) {
ItemStack item = CMIMaterial.PLAYER_HEAD.newItemStack();
SkullMeta skullMeta = (SkullMeta) item.getItemMeta();
ItemStack item = CMIMaterial.PLAYER_HEAD.newItemStack();
SkullMeta skullMeta = (SkullMeta) item.getItemMeta();
if (skullOwner.length() == 36) {
try {
OfflinePlayer offPlayer = Bukkit.getOfflinePlayer(UUID.fromString(skullOwner));
setSkullOwner(skullMeta, offPlayer);
} catch (IllegalArgumentException e) {
}
} else
skullMeta.setOwner(skullOwner);
if (skullOwner.length() == 36) {
try {
OfflinePlayer offPlayer = Bukkit.getOfflinePlayer(UUID.fromString(skullOwner));
setSkullOwner(skullMeta, offPlayer);
} catch (IllegalArgumentException e) {
}
} else
skullMeta.setOwner(skullOwner);
item.setItemMeta(skullMeta);
return item;
item.setItemMeta(skullMeta);
return item;
}
public static PotionType getPotionByName(String name) {
for (PotionType one : PotionType.values()) {
if (one.toString().equalsIgnoreCase(name)) {
return one;
}
}
for (PotionType one : PotionType.values()) {
if (one.toString().equalsIgnoreCase(name)) {
return one;
}
}
return null;
return null;
}
public static Map<UUID, String> getJobsEditorMap() {
return jobsEditorMap;
return jobsEditorMap;
}
public static Map<UUID, String> getQuestsEditorMap() {
return questsEditorMap;
return questsEditorMap;
}
public static Block getTargetBlock(Player player, int distance, boolean ignoreNoneSolids) {
return getTargetBlock(player, null, distance, ignoreNoneSolids);
return getTargetBlock(player, null, distance, ignoreNoneSolids);
}
public static Block getTargetBlock(Player player, int distance) {
return getTargetBlock(player, null, distance, false);
return getTargetBlock(player, null, distance, false);
}
public static Block getTargetBlock(Player player, Material lookingFor, int distance) {
return getTargetBlock(player, lookingFor, distance, false);
return getTargetBlock(player, lookingFor, distance, false);
}
public static Block getTargetBlock(Player player, Material lookingFor, int distance, boolean ignoreNoneSolids) {
int mult = 15 * 16;
if (distance > mult)
distance = mult;
int mult = 15 * 16;
if (distance > mult)
distance = mult;
if (distance < 1)
distance = 1;
if (distance < 1)
distance = 1;
try {
Block bl = player.getTargetBlock(null, distance);
try {
Block bl = player.getTargetBlock(null, distance);
if (!CMIMaterial.isAir(bl.getType())) {
return bl;
}
} catch (Throwable e) {
}
if (!CMIMaterial.isAir(bl.getType())) {
return bl;
}
} catch (Throwable e) {
}
List<Block> blocks = new ArrayList<>();
Iterator<Block> itr = new BlockIterator(player, distance);
List<Block> blocks = new ArrayList<>();
Iterator<Block> itr = new BlockIterator(player, distance);
while (itr.hasNext()) {
Block block = itr.next();
blocks.add(block);
while (itr.hasNext()) {
Block block = itr.next();
blocks.add(block);
if (distance != 0 && blocks.size() > distance) {
blocks.remove(0);
}
if (distance != 0 && blocks.size() > distance) {
blocks.remove(0);
}
Material material = block.getType();
Material material = block.getType();
if (ignoreNoneSolids && !material.isSolid())
continue;
if (ignoreNoneSolids && !material.isSolid())
continue;
if (lookingFor == null) {
if (!CMIMaterial.isAir(material)) {
break;
}
} else if (lookingFor == material) {
return block;
}
}
if (lookingFor == null) {
if (!CMIMaterial.isAir(material)) {
break;
}
} else if (lookingFor == material) {
return block;
}
}
return !blocks.isEmpty() ? blocks.get(blocks.size() - 1) : null;
return !blocks.isEmpty() ? blocks.get(blocks.size() - 1) : null;
}
public static Color getColor(int a) {
switch (a) {
case 1:
return Color.AQUA;
case 2:
return Color.BLACK;
case 3:
return Color.BLUE;
case 4:
return Color.FUCHSIA;
case 5:
return Color.GRAY;
case 6:
return Color.GREEN;
case 7:
return Color.LIME;
case 8:
return Color.MAROON;
case 9:
return Color.NAVY;
case 10:
return Color.OLIVE;
case 11:
return Color.ORANGE;
case 12:
return Color.PURPLE;
case 13:
return Color.RED;
case 14:
return Color.SILVER;
case 15:
return Color.TEAL;
case 16:
return Color.WHITE;
case 17:
return Color.YELLOW;
default:
return Color.BLACK;
}
switch (a) {
case 1:
return Color.AQUA;
case 2:
return Color.BLACK;
case 3:
return Color.BLUE;
case 4:
return Color.FUCHSIA;
case 5:
return Color.GRAY;
case 6:
return Color.GREEN;
case 7:
return Color.LIME;
case 8:
return Color.MAROON;
case 9:
return Color.NAVY;
case 10:
return Color.OLIVE;
case 11:
return Color.ORANGE;
case 12:
return Color.PURPLE;
case 13:
return Color.RED;
case 14:
return Color.SILVER;
case 15:
return Color.TEAL;
case 16:
return Color.WHITE;
case 17:
return Color.YELLOW;
default:
return Color.BLACK;
}
}
public static JobsWorld getJobsWorld(String name) {
return jobsWorlds.get(name.toLowerCase());
return jobsWorlds.get(name.toLowerCase());
}
public static JobsWorld getJobsWorld(int id) {
for (JobsWorld jobsWorld : jobsWorlds.values()) {
if (jobsWorld.getId() == id) {
return jobsWorld;
}
}
for (JobsWorld jobsWorld : jobsWorlds.values()) {
if (jobsWorld.getId() == id) {
return jobsWorld;
}
}
return null;
return null;
}
public static Map<String, JobsWorld> getJobsWorlds() {
return jobsWorlds;
return jobsWorlds;
}
public static void addJobsWorld(JobsWorld jobsWorld) {
if (jobsWorld == null || jobsWorld.getId() == 0)
return;
if (jobsWorld == null || jobsWorld.getId() == 0)
return;
jobsWorlds.put(jobsWorld.getName().toLowerCase(), jobsWorld);
jobsWorlds.put(jobsWorld.getName().toLowerCase(), jobsWorld);
}
public static List<String> getFilesFromPackage(String pckgname) throws ClassNotFoundException {
return getFilesFromPackage(pckgname, null, "class");
return getFilesFromPackage(pckgname, null, "class");
}
public static List<String> getFilesFromPackage(String pckgname, String cleaner, String fileType) throws ClassNotFoundException {
List<String> result = new ArrayList<>();
try {
for (URL jarURL : ((URLClassLoader) Jobs.class.getClassLoader()).getURLs()) {
try {
result.addAll(getFilesInSamePackageFromJar(pckgname, jarURL.toURI().getPath(), cleaner, fileType));
} catch (URISyntaxException e) {
}
}
} catch (NullPointerException x) {
throw new ClassNotFoundException(pckgname + " does not appear to be a valid package (Null pointer exception)");
}
return result;
List<String> result = new ArrayList<>();
try {
for (URL jarURL : ((URLClassLoader) Jobs.class.getClassLoader()).getURLs()) {
try {
result.addAll(getFilesInSamePackageFromJar(pckgname, jarURL.toURI().getPath(), cleaner, fileType));
} catch (URISyntaxException e) {
}
}
} catch (NullPointerException x) {
throw new ClassNotFoundException(pckgname + " does not appear to be a valid package (Null pointer exception)");
}
return result;
}
public static List<String> getFilesInSamePackageFromJar(String packageName, String jarPath, String cleaner, String fileType) {
packageName = packageName.replace('.', '/');
packageName = packageName.replace('.', '/');
List<String> listOfCommands = new ArrayList<>();
List<String> listOfCommands = new ArrayList<>();
try (JarFile jarFile = new JarFile(jarPath)) {
Enumeration<JarEntry> en = jarFile.entries();
while (en.hasMoreElements()) {
String entryName = en.nextElement().getName();
try (JarFile jarFile = new JarFile(jarPath)) {
Enumeration<JarEntry> en = jarFile.entries();
while (en.hasMoreElements()) {
String entryName = en.nextElement().getName();
if (entryName.endsWith("." + fileType) && entryName.startsWith(packageName)) {
String name = entryName.replace(packageName, "").replace("." + fileType, "").replace("/", "");
if (entryName.endsWith("." + fileType) && entryName.startsWith(packageName)) {
String name = entryName.replace(packageName, "").replace("." + fileType, "").replace("/", "");
if (name.contains("$"))
name = name.split("\\$", 2)[0];
if (name.contains("$"))
name = name.split("\\$", 2)[0];
if (cleaner != null && !cleaner.isEmpty())
name = name.replace(cleaner, "");
if (cleaner != null && !cleaner.isEmpty())
name = name.replace(cleaner, "");
listOfCommands.add(name);
}
}
} catch (java.io.IOException e) {
}
listOfCommands.add(name);
}
}
} catch (java.io.IOException e) {
}
return listOfCommands;
return listOfCommands;
}
public static <K, V> Map<K, V> mapUnique(Map<K, V> left, Map<K, V> right) {
Map<K, V> difference = new HashMap<>();
Map<K, V> difference = new HashMap<>();
difference.putAll(left);
difference.putAll(right);
difference.entrySet().removeAll(right.entrySet());
difference.putAll(left);
difference.putAll(right);
difference.entrySet().removeAll(right.entrySet());
return difference;
return difference;
}
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.get(actionInfo.getName());
String enchantName = e != null ? CMIEnchantment.get(actionInfo.getName()).toString() : actionInfo.getName();
return (
// Enchantment without level e.g. silk_touch
enchant.equalsIgnoreCase(enchantName) ||
// Enchantment with level e.g. fire_aspect:1
enchant.equalsIgnoreCase(enchantName + ":" + actionInfo.getLevel()));
return (
// Enchantment without level e.g. silk_touch
enchant.equalsIgnoreCase(enchantName) ||
// Enchantment with level e.g. fire_aspect:1
enchant.equalsIgnoreCase(enchantName + ":" + actionInfo.getLevel()));
}
}