mirror of
https://github.com/Zrips/Jobs.git
synced 2024-12-01 15:03:36 +01:00
Option to translate potion/tipped arrow effect names
This commit is contained in:
parent
389b6dc724
commit
2056525a16
@ -12,6 +12,7 @@ import java.util.stream.Collectors;
|
|||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.potion.PotionType;
|
||||||
|
|
||||||
import com.gamingmesh.jobs.Jobs;
|
import com.gamingmesh.jobs.Jobs;
|
||||||
import com.gamingmesh.jobs.CMILib.CMIEnchantment;
|
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.hooks.HookManager;
|
||||||
import com.gamingmesh.jobs.stuff.Util;
|
import com.gamingmesh.jobs.stuff.Util;
|
||||||
|
|
||||||
|
import net.Zrips.CMILib.Container.CMIText;
|
||||||
import net.Zrips.CMILib.Entities.CMIEntityType;
|
import net.Zrips.CMILib.Entities.CMIEntityType;
|
||||||
import net.Zrips.CMILib.FileHandler.ConfigReader;
|
import net.Zrips.CMILib.FileHandler.ConfigReader;
|
||||||
import net.Zrips.CMILib.Items.CMIMaterial;
|
import net.Zrips.CMILib.Items.CMIMaterial;
|
||||||
|
import net.Zrips.CMILib.Logs.CMIDebug;
|
||||||
|
|
||||||
public class NameTranslatorManager {
|
public class NameTranslatorManager {
|
||||||
|
|
||||||
private final Map<CMIMaterial, NameList> listOfNames = new HashMap<>();
|
private final Map<CMIMaterial, NameList> listOfNames = new HashMap<>();
|
||||||
private final List<NameList> listOfEntities = new ArrayList<>(), listOfColors = new ArrayList<>();
|
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) {
|
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) {
|
public String translate(String materialName, ActionType action, int id, String meta, String name) {
|
||||||
// Translating name to user friendly
|
// Translating name to user friendly
|
||||||
if (Jobs.getGCManager().UseCustomNames)
|
if (materialName.toLowerCase().contains("arrow"))
|
||||||
switch (action) {
|
CMIDebug.d(materialName, meta, Util.getPotionByName(meta));
|
||||||
case BREAK:
|
if (Jobs.getGCManager().UseCustomNames)
|
||||||
case TNTBREAK:
|
switch (action) {
|
||||||
case EAT:
|
case BREAK:
|
||||||
case CRAFT:
|
case TNTBREAK:
|
||||||
case DYE:
|
case EAT:
|
||||||
case COLLECT:
|
case CRAFT:
|
||||||
case BAKE:
|
case DYE:
|
||||||
case PLACE:
|
case COLLECT:
|
||||||
case SMELT:
|
case BAKE:
|
||||||
case REPAIR:
|
case PLACE:
|
||||||
case BREW:
|
case SMELT:
|
||||||
case FISH:
|
case REPAIR:
|
||||||
case STRIPLOGS:
|
case BREW:
|
||||||
String matName = materialName;
|
case FISH:
|
||||||
materialName = materialName.replace(" ", "");
|
case STRIPLOGS:
|
||||||
|
String matName = materialName;
|
||||||
|
materialName = materialName.replace(" ", "");
|
||||||
|
|
||||||
if (materialName.contains(":"))
|
if (materialName.contains(":"))
|
||||||
materialName = materialName.split(":")[0];
|
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 (nameLs != null && !mat.isNone()) {
|
||||||
if (meta != null && !meta.isEmpty() && mat.isCanHavePotionType() && Util.getPotionByName(meta) != null) {
|
if (meta != null && !meta.isEmpty() && mat.isCanHavePotionType() && Util.getPotionByName(meta) != null) {
|
||||||
return nameLs.getName() + ":" + meta;
|
|
||||||
}
|
NameList record = listOfPotionEffects.get(meta.toLowerCase().replace("_", ""));
|
||||||
|
if (record != null)
|
||||||
|
meta = record.getMinecraftName();
|
||||||
|
|
||||||
|
return nameLs.getName() + ":" + meta;
|
||||||
|
}
|
||||||
|
|
||||||
if (name != null && !name.isEmpty()) {
|
if (name != null && !name.isEmpty()) {
|
||||||
return nameLs.getName();
|
return nameLs.getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (meta != null && !meta.isEmpty()) {
|
if (meta != null && !meta.isEmpty()) {
|
||||||
mat = CMIMaterial.get(materialName + ":" + meta);
|
mat = CMIMaterial.get(materialName + ":" + meta);
|
||||||
|
|
||||||
if ((nameLs = listOfNames.get(mat)) == null) {
|
if ((nameLs = listOfNames.get(mat)) == null) {
|
||||||
mat = CMIMaterial.get(materialName.replace(" ", ""));
|
mat = CMIMaterial.get(materialName.replace(" ", ""));
|
||||||
|
|
||||||
if ((nameLs = listOfNames.get(mat)) != null) {
|
if ((nameLs = listOfNames.get(mat)) != null) {
|
||||||
NameList nameMeta = listOfNames.get(CMIMaterial.get(meta.replace(" ", "")));
|
NameList nameMeta = listOfNames.get(CMIMaterial.get(meta.replace(" ", "")));
|
||||||
|
|
||||||
if (nameMeta != null) {
|
if (nameMeta != null) {
|
||||||
return nameLs.getName() + ":" + nameMeta.getMeta();
|
return nameLs.getName() + ":" + nameMeta.getMeta();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mat == CMIMaterial.NONE) {
|
if (mat == CMIMaterial.NONE) {
|
||||||
return Arrays.stream(matName.split("\\s|:"))
|
return Arrays.stream(matName.split("\\s|:"))
|
||||||
.map(word -> word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase())
|
.map(word -> word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase())
|
||||||
.collect(Collectors.joining(" ")); // returns capitalized word (from this -> To This)
|
.collect(Collectors.joining(" ")); // returns capitalized word (from this -> To This)
|
||||||
}
|
}
|
||||||
|
|
||||||
return mat.getName();
|
return mat.getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id > 0 && meta != null && !meta.isEmpty()) {
|
if (id > 0 && meta != null && !meta.isEmpty()) {
|
||||||
mat = CMIMaterial.get(id + ":" + meta);
|
mat = CMIMaterial.get(id + ":" + meta);
|
||||||
nameLs = listOfNames.get(mat);
|
nameLs = listOfNames.get(mat);
|
||||||
|
|
||||||
if (nameLs == null) {
|
if (nameLs == null) {
|
||||||
return mat.getName();
|
return mat.getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mat.isNone()) {
|
if (mat.isNone()) {
|
||||||
return matName;
|
return matName;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mat.getName();
|
return mat.getName();
|
||||||
case BREED:
|
case BREED:
|
||||||
case KILL:
|
case KILL:
|
||||||
case MILK:
|
case MILK:
|
||||||
case TAME:
|
case TAME:
|
||||||
for (NameList one : listOfEntities) {
|
for (NameList one : listOfEntities) {
|
||||||
String ids = one.getId() + ":" + one.getMeta();
|
String ids = one.getId() + ":" + one.getMeta();
|
||||||
|
|
||||||
if (!one.getMeta().isEmpty() && !one.getId().equals("0") && ids.equalsIgnoreCase(id + ":" + meta)) {
|
if (!one.getMeta().isEmpty() && !one.getId().equals("0") && ids.equalsIgnoreCase(id + ":" + meta)) {
|
||||||
return one.getName();
|
return one.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
ids = one.getId();
|
ids = one.getId();
|
||||||
|
|
||||||
if (!one.getId().equals("0") && ids.equalsIgnoreCase(Integer.toString(id))) {
|
if (!one.getId().equals("0") && ids.equalsIgnoreCase(Integer.toString(id))) {
|
||||||
return one.getName();
|
return one.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
ids = one.getMinecraftName();
|
ids = one.getMinecraftName();
|
||||||
|
|
||||||
if (ids.equalsIgnoreCase(name)) {
|
if (ids.equalsIgnoreCase(name)) {
|
||||||
return one.getName();
|
return one.getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ENCHANT:
|
case ENCHANT:
|
||||||
String mName = materialName;
|
String mName = materialName;
|
||||||
String level = "";
|
String level = "";
|
||||||
|
|
||||||
String[] split = materialName.split(":", 2);
|
String[] split = materialName.split(":", 2);
|
||||||
if (split.length > 1) {
|
if (split.length > 1) {
|
||||||
mName = split[0];
|
mName = split[0];
|
||||||
level = ":" + split[1];
|
level = ":" + split[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
NameList nameInfo = listOfEnchants.get(mName.toLowerCase().replace("_", ""));
|
NameList nameInfo = listOfEnchants.get(mName.toLowerCase().replace("_", ""));
|
||||||
if (nameInfo != null) {
|
if (nameInfo != null) {
|
||||||
return nameInfo.getMinecraftName() + level;
|
return nameInfo.getMinecraftName() + level;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case SHEAR:
|
case SHEAR:
|
||||||
for (NameList one : listOfColors) {
|
for (NameList one : listOfColors) {
|
||||||
if (one.getMinecraftName().equalsIgnoreCase(name)) {
|
if (one.getMinecraftName().equalsIgnoreCase(name)) {
|
||||||
return one.getName();
|
return one.getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return name == null ? "nocolor" : Arrays.stream(name.split("\\s|:|-"))
|
return name == null ? "nocolor" : Arrays.stream(name.split("\\s|:|-"))
|
||||||
.map(word -> word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase())
|
.map(word -> word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase())
|
||||||
.collect(Collectors.joining(" ")); // returns capitalized word (from this -> To This)
|
.collect(Collectors.joining(" ")); // returns capitalized word (from this -> To This)
|
||||||
case MMKILL:
|
case MMKILL:
|
||||||
NameList got = listOfMMEntities.get(materialName.toLowerCase());
|
NameList got = listOfMMEntities.get(materialName.toLowerCase());
|
||||||
|
|
||||||
if (got != null && got.getName() != null)
|
if (got != null && got.getName() != null)
|
||||||
return got.getName();
|
return got.getName();
|
||||||
|
|
||||||
return HookManager.getMythicManager() == null ? materialName : HookManager.getMythicManager().getDisplayName(materialName);
|
return HookManager.getMythicManager() == null ? materialName : HookManager.getMythicManager().getDisplayName(materialName);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return materialName;
|
return materialName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readFile() {
|
public void readFile() {
|
||||||
YmlMaker itemFile = new YmlMaker(Jobs.getFolder(), "TranslatableWords" + File.separator + "Words_"
|
YmlMaker itemFile = new YmlMaker(Jobs.getFolder(), "TranslatableWords" + File.separator + "Words_"
|
||||||
+ Jobs.getGCManager().localeString + ".yml");
|
+ Jobs.getGCManager().localeString + ".yml");
|
||||||
|
|
||||||
if (!itemFile.getConfigFile().getName().equalsIgnoreCase("en")) {
|
if (!itemFile.getConfigFile().getName().equalsIgnoreCase("en")) {
|
||||||
itemFile.saveDefaultConfig();
|
itemFile.saveDefaultConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigurationSection section = itemFile.getConfig().getConfigurationSection("ItemList");
|
ConfigurationSection section = itemFile.getConfig().getConfigurationSection("ItemList");
|
||||||
|
|
||||||
if (section != null) {
|
if (section != null) {
|
||||||
listOfNames.clear();
|
listOfNames.clear();
|
||||||
|
|
||||||
for (String one : section.getKeys(false)) {
|
for (String one : section.getKeys(false)) {
|
||||||
String[] firstSplit = one.split("-", 2);
|
String[] firstSplit = one.split("-", 2);
|
||||||
String split = firstSplit.length > 0 ? firstSplit[0] : one;
|
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 id = splitted.length > 0 ? splitted[0] : split;
|
||||||
String meta = splitted.length > 1 ? splitted[1] : "";
|
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)
|
if (listOfNames.size() > 0)
|
||||||
Jobs.consoleMsg("&eLoaded &6" + listOfNames.size() + " &ecustom item names");
|
Jobs.consoleMsg("&eLoaded &6" + listOfNames.size() + " &ecustom item names");
|
||||||
} else
|
} else
|
||||||
Jobs.consoleMsg("&cThe ItemList section not found in &6" + itemFile.fileName + " &cfile.");
|
Jobs.consoleMsg("&cThe ItemList section not found in &6" + itemFile.fileName + " &cfile.");
|
||||||
|
|
||||||
if ((section = itemFile.getConfig().getConfigurationSection("EntityList")) != null) {
|
if ((section = itemFile.getConfig().getConfigurationSection("EntityList")) != null) {
|
||||||
listOfEntities.clear();
|
listOfEntities.clear();
|
||||||
|
|
||||||
for (String one : section.getKeys(false)) {
|
for (String one : section.getKeys(false)) {
|
||||||
String[] firstSplit = one.split("-", 2);
|
String[] firstSplit = one.split("-", 2);
|
||||||
String split = firstSplit.length > 0 ? firstSplit[0] : one;
|
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 id = splitted.length > 0 ? splitted[0] : split;
|
||||||
String meta = splitted.length > 1 ? splitted[1] : "";
|
String meta = splitted.length > 1 ? splitted[1] : "";
|
||||||
String mcName = firstSplit.length > 1 ? firstSplit[1] : one;
|
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())
|
if (!listOfEntities.isEmpty())
|
||||||
Jobs.consoleMsg("&eLoaded &6" + listOfEntities.size() + " &ecustom entity names");
|
Jobs.consoleMsg("&eLoaded &6" + listOfEntities.size() + " &ecustom entity names");
|
||||||
} else
|
} else
|
||||||
Jobs.consoleMsg("&cThe EntityList section not found in &6" + itemFile.fileName + " &cfile.");
|
Jobs.consoleMsg("&cThe EntityList section not found in &6" + itemFile.fileName + " &cfile.");
|
||||||
|
|
||||||
if ((section = itemFile.getConfig().getConfigurationSection("MythicEntityList")) != null) {
|
if ((section = itemFile.getConfig().getConfigurationSection("MythicEntityList")) != null) {
|
||||||
listOfMMEntities.clear();
|
listOfMMEntities.clear();
|
||||||
|
|
||||||
for (String one : section.getKeys(false)) {
|
for (String one : section.getKeys(false)) {
|
||||||
String name = section.getString(one);
|
String name = section.getString(one);
|
||||||
listOfMMEntities.put(one.toLowerCase(), new NameList(null, null, name, name));
|
listOfMMEntities.put(one.toLowerCase(), new NameList(null, null, name, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (listOfMMEntities.size() > 0)
|
if (listOfMMEntities.size() > 0)
|
||||||
Jobs.consoleMsg("&eLoaded &6" + listOfMMEntities.size() + " &ecustom MythicMobs names");
|
Jobs.consoleMsg("&eLoaded &6" + listOfMMEntities.size() + " &ecustom MythicMobs names");
|
||||||
} else
|
} else
|
||||||
Jobs.consoleMsg("&cThe MythicEntityList section not found in &6" + itemFile.fileName + " &cfile.");
|
Jobs.consoleMsg("&cThe MythicEntityList section not found in &6" + itemFile.fileName + " &cfile.");
|
||||||
|
|
||||||
if ((section = itemFile.getConfig().getConfigurationSection("EnchantList")) != null) {
|
if ((section = itemFile.getConfig().getConfigurationSection("EnchantList")) != null) {
|
||||||
listOfEnchants.clear();
|
listOfEnchants.clear();
|
||||||
|
|
||||||
for (String one : section.getKeys(false)) {
|
for (String one : section.getKeys(false)) {
|
||||||
listOfEnchants.put(one.replace("_", "").toLowerCase(), new NameList(one, one, one, section.getString(one)));
|
listOfEnchants.put(one.replace("_", "").toLowerCase(), new NameList(one, one, one, section.getString(one)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (listOfEnchants.size() > 0)
|
if (listOfEnchants.size() > 0)
|
||||||
Jobs.consoleMsg("&eLoaded &6" + listOfEnchants.size() + " &ecustom enchant names");
|
Jobs.consoleMsg("&eLoaded &6" + listOfEnchants.size() + " &ecustom enchant names");
|
||||||
} else
|
} else
|
||||||
Jobs.consoleMsg("&cThe EnchantList section not found in &6" + itemFile.fileName + " &cfile.");
|
Jobs.consoleMsg("&cThe EnchantList section not found in &6" + itemFile.fileName + " &cfile.");
|
||||||
|
|
||||||
if ((section = itemFile.getConfig().getConfigurationSection("ColorList")) != null) {
|
if ((section = itemFile.getConfig().getConfigurationSection("PotionEffects")) != null) {
|
||||||
listOfColors.clear();
|
listOfPotionEffects.clear();
|
||||||
|
|
||||||
for (String one : section.getKeys(false)) {
|
for (String one : section.getKeys(false)) {
|
||||||
String[] split = one.split("-", 2);
|
listOfPotionEffects.put(one.replace("_", "").toLowerCase(), new NameList(one, one, one, section.getString(one)));
|
||||||
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())
|
if (listOfPotionEffects.size() > 0)
|
||||||
Jobs.consoleMsg("&eLoaded &6" + listOfColors.size() + " &ecustom color names");
|
Jobs.consoleMsg("&eLoaded &6" + listOfPotionEffects.size() + " &ecustom enchant names");
|
||||||
} else
|
} else
|
||||||
Jobs.consoleMsg("&cThe ColorList section not found in &6" + itemFile.fileName + " &cfile.");
|
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")
|
@SuppressWarnings("deprecation")
|
||||||
void load() {
|
void load() {
|
||||||
String ls = Jobs.getGCManager().localeString;
|
String ls = Jobs.getGCManager().localeString;
|
||||||
if (ls.isEmpty())
|
if (ls.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
File tWordsFolder = new File(Jobs.getFolder(), "TranslatableWords");
|
File tWordsFolder = new File(Jobs.getFolder(), "TranslatableWords");
|
||||||
tWordsFolder.mkdirs();
|
tWordsFolder.mkdirs();
|
||||||
|
|
||||||
File file = new File(Jobs.getFolder(), "TranslatableWords.yml");
|
File file = new File(Jobs.getFolder(), "TranslatableWords.yml");
|
||||||
File file2 = new File(tWordsFolder, "Words_" + ls + ".yml");
|
File file2 = new File(tWordsFolder, "Words_" + ls + ".yml");
|
||||||
if (file.exists())
|
if (file.exists())
|
||||||
file.renameTo(file2);
|
file.renameTo(file2);
|
||||||
|
|
||||||
// Just copying default language files, except en, that one will be generated
|
// Just copying default language files, except en, that one will be generated
|
||||||
List<String> languages = new ArrayList<>();
|
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.
|
// This should be present to copy over default files into TranslatableWords folder if file doesn't exist. Grabs all files from plugin file.
|
||||||
try {
|
try {
|
||||||
languages.addAll(Util.getFilesFromPackage("TranslatableWords", "Words_", "yml"));
|
languages.addAll(Util.getFilesFromPackage("TranslatableWords", "Words_", "yml"));
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
for (Iterator<String> e1 = languages.iterator(); e1.hasNext();) {
|
for (Iterator<String> e1 = languages.iterator(); e1.hasNext();) {
|
||||||
String lang = e1.next();
|
String lang = e1.next();
|
||||||
YmlMaker langFile = new YmlMaker(Jobs.getFolder(), "TranslatableWords" + File.separator + "Words_" + lang + ".yml");
|
YmlMaker langFile = new YmlMaker(Jobs.getFolder(), "TranslatableWords" + File.separator + "Words_" + lang + ".yml");
|
||||||
langFile.saveDefaultConfig();
|
langFile.saveDefaultConfig();
|
||||||
}
|
}
|
||||||
//Up to here.
|
//Up to here.
|
||||||
|
|
||||||
languages.add("en");
|
languages.add("en");
|
||||||
|
|
||||||
File customLocaleFile = new File(tWordsFolder, "Words_" + ls + ".yml");
|
File customLocaleFile = new File(tWordsFolder, "Words_" + ls + ".yml");
|
||||||
if (!customLocaleFile.exists() && !ls.equalsIgnoreCase("en"))
|
if (!customLocaleFile.exists() && !ls.equalsIgnoreCase("en"))
|
||||||
languages.add(ls);
|
languages.add(ls);
|
||||||
|
|
||||||
for (String lang : languages) {
|
for (String lang : languages) {
|
||||||
File f = new File(tWordsFolder, "Words_" + lang + ".yml");
|
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
|
// Fail safe if file get corrupted and being created with corrupted data, we need to recreate it
|
||||||
if ((f.length() / 1024) > 1024) {
|
if ((f.length() / 1024) > 1024) {
|
||||||
f.delete();
|
f.delete();
|
||||||
f = new File(tWordsFolder, "Words_" + lang + ".yml");
|
f = new File(tWordsFolder, "Words_" + lang + ".yml");
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigReader c;
|
ConfigReader c;
|
||||||
try {
|
try {
|
||||||
c = new ConfigReader(f);
|
c = new ConfigReader(f);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
c.copyDefaults(true);
|
c.copyDefaults(true);
|
||||||
|
|
||||||
for (CMIMaterial mat : CMIMaterial.values()) {
|
for (CMIMaterial mat : CMIMaterial.values()) {
|
||||||
if (mat == CMIMaterial.NONE) {
|
if (mat == CMIMaterial.NONE) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String n = mat.getLegacyId() + (mat.getLegacyData() == -1 ? "" : ":" + mat.getLegacyData());
|
String n = mat.getLegacyId() + (mat.getLegacyData() == -1 ? "" : ":" + mat.getLegacyData());
|
||||||
String name = c.getC().getString("ItemList." + mat.toString());
|
String name = c.getC().getString("ItemList." + mat.toString());
|
||||||
|
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
name = c.getC().getString("ItemList." + n + ".Name");
|
name = c.getC().getString("ItemList." + n + ".Name");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
n = mat.getLegacyId() + ":" + mat.getLegacyData();
|
n = mat.getLegacyId() + ":" + mat.getLegacyData();
|
||||||
name = c.getC().getString("ItemList." + n + ".Name");
|
name = c.getC().getString("ItemList." + n + ".Name");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
n = String.valueOf(mat.getLegacyId());
|
n = String.valueOf(mat.getLegacyId());
|
||||||
name = c.getC().getString("ItemList." + n + ".Name");
|
name = c.getC().getString("ItemList." + n + ".Name");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
n = String.valueOf(mat.getId());
|
n = String.valueOf(mat.getId());
|
||||||
name = c.getC().getString("ItemList." + n + ".Name");
|
name = c.getC().getString("ItemList." + n + ".Name");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
n = mat.getLegacyId() + ":" + mat.getLegacyData() + "-" + mat.getBukkitName();
|
n = mat.getLegacyId() + ":" + mat.getLegacyData() + "-" + mat.getBukkitName();
|
||||||
name = c.getC().getString("ItemList." + n);
|
name = c.getC().getString("ItemList." + n);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
n = mat.getLegacyId() + "-" + mat.getBukkitName();
|
n = mat.getLegacyId() + "-" + mat.getBukkitName();
|
||||||
name = c.getC().getString("ItemList." + n);
|
name = c.getC().getString("ItemList." + n);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
n = mat.getId() + "-" + mat.getBukkitName();
|
n = mat.getId() + "-" + mat.getBukkitName();
|
||||||
name = c.getC().getString("ItemList." + n);
|
name = c.getC().getString("ItemList." + n);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
name = mat.getName();
|
name = mat.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
c.get("ItemList." + mat.toString(), name);
|
c.get("ItemList." + mat.toString(), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (EntityType one : EntityType.values()) {
|
for (EntityType one : EntityType.values()) {
|
||||||
CMIEntityType ent = CMIEntityType.getByType(one);
|
CMIEntityType ent = CMIEntityType.getByType(one);
|
||||||
if (ent == null || !ent.isAlive())
|
if (ent == null || !ent.isAlive())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
String n = Integer.toString(ent.getId());
|
String n = Integer.toString(ent.getId());
|
||||||
String name = c.getC().getString("EntityList." + n + ".Name");
|
String name = c.getC().getString("EntityList." + n + ".Name");
|
||||||
|
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
n += "-" + ent.toString();
|
n += "-" + ent.toString();
|
||||||
name = c.getC().getString("EntityList." + n);
|
name = c.getC().getString("EntityList." + n);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
name = ent.getName();
|
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");
|
ConfigurationSection enchSection = c.getC().getConfigurationSection("EnchantList");
|
||||||
for (Enchantment one : Enchantment.values()) {
|
for (Enchantment one : Enchantment.values()) {
|
||||||
String enchName = CMIEnchantment.getName(one);
|
String enchName = CMIEnchantment.getName(one);
|
||||||
if (enchName.equals("Unknown"))
|
if (enchName.equals("Unknown"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
String name = enchName;
|
String name = enchName;
|
||||||
|
|
||||||
if (enchSection != null) {
|
if (enchSection != null) {
|
||||||
for (String onek : enchSection.getKeys(false)) {
|
for (String onek : enchSection.getKeys(false)) {
|
||||||
String old = enchSection.getString(onek + ".MCName");
|
String old = enchSection.getString(onek + ".MCName");
|
||||||
|
|
||||||
if (old != null && old.equalsIgnoreCase(enchName)) {
|
if (old != null && old.equalsIgnoreCase(enchName)) {
|
||||||
name = enchSection.getString(onek + ".Name");
|
name = enchSection.getString(onek + ".Name");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.get("EnchantList." + enchName, name);
|
c.get("EnchantList." + enchName, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Color list
|
for (PotionType one : PotionType.values()) {
|
||||||
c.get("ColorList.0-white", "&fWhite");
|
String potionName = CMIText.firstToUpperCase(one.name());
|
||||||
c.get("ColorList.1-orange", "&6Orange");
|
if (potionName.equals("Unknown"))
|
||||||
c.get("ColorList.2-magenta", "&dMagenta");
|
continue;
|
||||||
c.get("ColorList.3-light_blue", "&9Light Blue");
|
c.get("PotionEffects." + potionName, potionName);
|
||||||
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");
|
|
||||||
|
|
||||||
if (!c.getC().isConfigurationSection("MythicEntityList")) {
|
// Color list
|
||||||
c.get("MythicEntityList.AngrySludge", "Angry Sludge");
|
c.get("ColorList.0-white", "&fWhite");
|
||||||
c.get("MythicEntityList.SkeletalKnight", "Skeletal Knight");
|
c.get("ColorList.1-orange", "&6Orange");
|
||||||
} else {
|
c.get("ColorList.2-magenta", "&dMagenta");
|
||||||
c.set("MythicEntityList", c.getC().get("MythicEntityList"));
|
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();
|
if (!c.getC().isConfigurationSection("MythicEntityList")) {
|
||||||
}
|
c.get("MythicEntityList.AngrySludge", "Angry Sludge");
|
||||||
readFile();
|
c.get("MythicEntityList.SkeletalKnight", "Skeletal Knight");
|
||||||
|
} else {
|
||||||
|
c.set("MythicEntityList", c.getC().get("MythicEntityList"));
|
||||||
|
}
|
||||||
|
|
||||||
|
c.save();
|
||||||
|
}
|
||||||
|
readFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -55,353 +55,353 @@ public final class Util {
|
|||||||
private final static TreeMap<Integer, String> map = new TreeMap<Integer, String>();
|
private final static TreeMap<Integer, String> map = new TreeMap<Integer, String>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
map.put(1000, "M");
|
map.put(1000, "M");
|
||||||
map.put(900, "CM");
|
map.put(900, "CM");
|
||||||
map.put(500, "D");
|
map.put(500, "D");
|
||||||
map.put(400, "CD");
|
map.put(400, "CD");
|
||||||
map.put(100, "C");
|
map.put(100, "C");
|
||||||
map.put(90, "XC");
|
map.put(90, "XC");
|
||||||
map.put(50, "L");
|
map.put(50, "L");
|
||||||
map.put(40, "XL");
|
map.put(40, "XL");
|
||||||
map.put(10, "X");
|
map.put(10, "X");
|
||||||
map.put(9, "IX");
|
map.put(9, "IX");
|
||||||
map.put(5, "V");
|
map.put(5, "V");
|
||||||
map.put(4, "IV");
|
map.put(4, "IV");
|
||||||
map.put(1, "I");
|
map.put(1, "I");
|
||||||
}
|
}
|
||||||
|
|
||||||
public final static String toRoman(int number) {
|
public final static String toRoman(int number) {
|
||||||
int l = map.floorKey(number);
|
int l = map.floorKey(number);
|
||||||
if (number == l) {
|
if (number == l) {
|
||||||
return map.get(number);
|
return map.get(number);
|
||||||
}
|
}
|
||||||
return map.get(l) + toRoman(number - l);
|
return map.get(l) + toRoman(number - l);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Block> getPistonRetractBlocks(BlockPistonRetractEvent event) {
|
public static List<Block> getPistonRetractBlocks(BlockPistonRetractEvent event) {
|
||||||
if (Version.isCurrentEqualOrHigher(Version.v1_8_R1)) {
|
if (Version.isCurrentEqualOrHigher(Version.v1_8_R1)) {
|
||||||
return new ArrayList<>(event.getBlocks());
|
return new ArrayList<>(event.getBlocks());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Block> blocks = new ArrayList<>();
|
List<Block> blocks = new ArrayList<>();
|
||||||
blocks.add(event.getBlock());
|
blocks.add(event.getBlock());
|
||||||
return blocks;
|
return blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double getDistance(Location loc1, Location loc2) {
|
public static double getDistance(Location loc1, Location loc2) {
|
||||||
if (loc1 == null || loc2 == null || loc1.getWorld() != loc2.getWorld())
|
if (loc1 == null || loc2 == null || loc1.getWorld() != loc2.getWorld())
|
||||||
return Integer.MAX_VALUE;
|
return Integer.MAX_VALUE;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return loc1.distance(loc2);
|
return loc1.distance(loc2);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
return Integer.MAX_VALUE;
|
return Integer.MAX_VALUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getRealType(Entity entity) {
|
public static String getRealType(Entity entity) {
|
||||||
if (Version.isCurrentEqualOrHigher(Version.v1_11_R1)) {
|
if (Version.isCurrentEqualOrHigher(Version.v1_11_R1)) {
|
||||||
return entity.getType().name();
|
return entity.getType().name();
|
||||||
}
|
}
|
||||||
|
|
||||||
String name = entity.getType().name();
|
String name = entity.getType().name();
|
||||||
|
|
||||||
switch (entity.getType().toString()) {
|
switch (entity.getType().toString()) {
|
||||||
case "GUARDIAN":
|
case "GUARDIAN":
|
||||||
if (((org.bukkit.entity.Guardian) entity).isElder())
|
if (((org.bukkit.entity.Guardian) entity).isElder())
|
||||||
name = "GuardianElder";
|
name = "GuardianElder";
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "HORSE":
|
case "HORSE":
|
||||||
Horse horse = (Horse) entity;
|
Horse horse = (Horse) entity;
|
||||||
|
|
||||||
if (horse.getVariant().toString().equals("UNDEAD_HORSE"))
|
if (horse.getVariant().toString().equals("UNDEAD_HORSE"))
|
||||||
name = "HorseZombie";
|
name = "HorseZombie";
|
||||||
|
|
||||||
if (horse.getVariant().toString().equals("SKELETON_HORSE"))
|
if (horse.getVariant().toString().equals("SKELETON_HORSE"))
|
||||||
name = "HorseSkeleton";
|
name = "HorseSkeleton";
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "SKELETON":
|
case "SKELETON":
|
||||||
Skeleton skeleton = (Skeleton) entity;
|
Skeleton skeleton = (Skeleton) entity;
|
||||||
|
|
||||||
if (skeleton.getSkeletonType().toString().equals("WITHER"))
|
if (skeleton.getSkeletonType().toString().equals("WITHER"))
|
||||||
name = "SkeletonWither";
|
name = "SkeletonWither";
|
||||||
|
|
||||||
if (Version.isCurrentEqualOrHigher(Version.v1_10_R1) && skeleton.getSkeletonType().toString().equals("STRAY"))
|
if (Version.isCurrentEqualOrHigher(Version.v1_10_R1) && skeleton.getSkeletonType().toString().equals("STRAY"))
|
||||||
name = "SkeletonStray";
|
name = "SkeletonStray";
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "ZOMBIE":
|
case "ZOMBIE":
|
||||||
Zombie zombie = (Zombie) entity;
|
Zombie zombie = (Zombie) entity;
|
||||||
|
|
||||||
if (Version.isCurrentEqualOrHigher(Version.v1_10_R1)) {
|
if (Version.isCurrentEqualOrHigher(Version.v1_10_R1)) {
|
||||||
if (zombie.isVillager() && zombie.getVillagerProfession().toString().equals("HUSK"))
|
if (zombie.isVillager() && zombie.getVillagerProfession().toString().equals("HUSK"))
|
||||||
return "ZombieVillager";
|
return "ZombieVillager";
|
||||||
|
|
||||||
if (zombie.getVillagerProfession().toString().equals("HUSK"))
|
if (zombie.getVillagerProfession().toString().equals("HUSK"))
|
||||||
return "ZombieHusk";
|
return "ZombieHusk";
|
||||||
} else if (zombie.isVillager()) {
|
} else if (zombie.isVillager()) {
|
||||||
return "ZombieVillager";
|
return "ZombieVillager";
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double getMaxHealth(LivingEntity entity) {
|
public static double getMaxHealth(LivingEntity entity) {
|
||||||
if (Version.isCurrentEqualOrHigher(Version.v1_12_R1)) {
|
if (Version.isCurrentEqualOrHigher(Version.v1_12_R1)) {
|
||||||
org.bukkit.attribute.AttributeInstance attr = entity.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
org.bukkit.attribute.AttributeInstance attr = entity.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||||
return attr == null ? 0d : attr.getBaseValue();
|
return attr == null ? 0d : attr.getBaseValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
return entity.getMaxHealth();
|
return entity.getMaxHealth();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static short getDurability(ItemStack item) {
|
public static short getDurability(ItemStack item) {
|
||||||
if (Version.isCurrentEqualOrHigher(Version.v1_13_R1)) {
|
if (Version.isCurrentEqualOrHigher(Version.v1_13_R1)) {
|
||||||
return (short) ((Damageable) item.getItemMeta()).getDamage();
|
return (short) ((Damageable) item.getItemMeta()).getDamage();
|
||||||
}
|
}
|
||||||
return item.getDurability();
|
return item.getDurability();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setSkullOwner(SkullMeta meta, OfflinePlayer player) {
|
public static void setSkullOwner(SkullMeta meta, OfflinePlayer player) {
|
||||||
if (meta != null && player != null) {
|
if (meta != null && player != null) {
|
||||||
if (Version.isCurrentEqualOrHigher(Version.v1_13_R1)) {
|
if (Version.isCurrentEqualOrHigher(Version.v1_13_R1)) {
|
||||||
meta.setOwningPlayer(player);
|
meta.setOwningPlayer(player);
|
||||||
} else {
|
} else {
|
||||||
meta.setOwner(player.getName());
|
meta.setOwner(player.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
|
|
||||||
if (skullOwner.length() == 36) {
|
if (skullOwner.length() == 36) {
|
||||||
try {
|
try {
|
||||||
OfflinePlayer offPlayer = Bukkit.getOfflinePlayer(UUID.fromString(skullOwner));
|
OfflinePlayer offPlayer = Bukkit.getOfflinePlayer(UUID.fromString(skullOwner));
|
||||||
setSkullOwner(skullMeta, offPlayer);
|
setSkullOwner(skullMeta, offPlayer);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
skullMeta.setOwner(skullOwner);
|
skullMeta.setOwner(skullOwner);
|
||||||
|
|
||||||
item.setItemMeta(skullMeta);
|
item.setItemMeta(skullMeta);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PotionType getPotionByName(String name) {
|
public static PotionType getPotionByName(String name) {
|
||||||
for (PotionType one : PotionType.values()) {
|
for (PotionType one : PotionType.values()) {
|
||||||
if (one.toString().equalsIgnoreCase(name)) {
|
if (one.toString().equalsIgnoreCase(name)) {
|
||||||
return one;
|
return one;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<UUID, String> getJobsEditorMap() {
|
public static Map<UUID, String> getJobsEditorMap() {
|
||||||
return jobsEditorMap;
|
return jobsEditorMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<UUID, String> getQuestsEditorMap() {
|
public static Map<UUID, String> getQuestsEditorMap() {
|
||||||
return questsEditorMap;
|
return questsEditorMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Block getTargetBlock(Player player, int distance, boolean ignoreNoneSolids) {
|
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) {
|
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) {
|
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) {
|
public static Block getTargetBlock(Player player, Material lookingFor, int distance, boolean ignoreNoneSolids) {
|
||||||
int mult = 15 * 16;
|
int mult = 15 * 16;
|
||||||
if (distance > mult)
|
if (distance > mult)
|
||||||
distance = mult;
|
distance = mult;
|
||||||
|
|
||||||
if (distance < 1)
|
if (distance < 1)
|
||||||
distance = 1;
|
distance = 1;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Block bl = player.getTargetBlock(null, distance);
|
Block bl = player.getTargetBlock(null, distance);
|
||||||
|
|
||||||
if (!CMIMaterial.isAir(bl.getType())) {
|
if (!CMIMaterial.isAir(bl.getType())) {
|
||||||
return bl;
|
return bl;
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Block> blocks = new ArrayList<>();
|
List<Block> blocks = new ArrayList<>();
|
||||||
Iterator<Block> itr = new BlockIterator(player, distance);
|
Iterator<Block> itr = new BlockIterator(player, distance);
|
||||||
|
|
||||||
while (itr.hasNext()) {
|
while (itr.hasNext()) {
|
||||||
Block block = itr.next();
|
Block block = itr.next();
|
||||||
blocks.add(block);
|
blocks.add(block);
|
||||||
|
|
||||||
if (distance != 0 && blocks.size() > distance) {
|
if (distance != 0 && blocks.size() > distance) {
|
||||||
blocks.remove(0);
|
blocks.remove(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Material material = block.getType();
|
Material material = block.getType();
|
||||||
|
|
||||||
if (ignoreNoneSolids && !material.isSolid())
|
if (ignoreNoneSolids && !material.isSolid())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (lookingFor == null) {
|
if (lookingFor == null) {
|
||||||
if (!CMIMaterial.isAir(material)) {
|
if (!CMIMaterial.isAir(material)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (lookingFor == material) {
|
} else if (lookingFor == material) {
|
||||||
return block;
|
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) {
|
public static Color getColor(int a) {
|
||||||
switch (a) {
|
switch (a) {
|
||||||
case 1:
|
case 1:
|
||||||
return Color.AQUA;
|
return Color.AQUA;
|
||||||
case 2:
|
case 2:
|
||||||
return Color.BLACK;
|
return Color.BLACK;
|
||||||
case 3:
|
case 3:
|
||||||
return Color.BLUE;
|
return Color.BLUE;
|
||||||
case 4:
|
case 4:
|
||||||
return Color.FUCHSIA;
|
return Color.FUCHSIA;
|
||||||
case 5:
|
case 5:
|
||||||
return Color.GRAY;
|
return Color.GRAY;
|
||||||
case 6:
|
case 6:
|
||||||
return Color.GREEN;
|
return Color.GREEN;
|
||||||
case 7:
|
case 7:
|
||||||
return Color.LIME;
|
return Color.LIME;
|
||||||
case 8:
|
case 8:
|
||||||
return Color.MAROON;
|
return Color.MAROON;
|
||||||
case 9:
|
case 9:
|
||||||
return Color.NAVY;
|
return Color.NAVY;
|
||||||
case 10:
|
case 10:
|
||||||
return Color.OLIVE;
|
return Color.OLIVE;
|
||||||
case 11:
|
case 11:
|
||||||
return Color.ORANGE;
|
return Color.ORANGE;
|
||||||
case 12:
|
case 12:
|
||||||
return Color.PURPLE;
|
return Color.PURPLE;
|
||||||
case 13:
|
case 13:
|
||||||
return Color.RED;
|
return Color.RED;
|
||||||
case 14:
|
case 14:
|
||||||
return Color.SILVER;
|
return Color.SILVER;
|
||||||
case 15:
|
case 15:
|
||||||
return Color.TEAL;
|
return Color.TEAL;
|
||||||
case 16:
|
case 16:
|
||||||
return Color.WHITE;
|
return Color.WHITE;
|
||||||
case 17:
|
case 17:
|
||||||
return Color.YELLOW;
|
return Color.YELLOW;
|
||||||
default:
|
default:
|
||||||
return Color.BLACK;
|
return Color.BLACK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JobsWorld getJobsWorld(String name) {
|
public static JobsWorld getJobsWorld(String name) {
|
||||||
return jobsWorlds.get(name.toLowerCase());
|
return jobsWorlds.get(name.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JobsWorld getJobsWorld(int id) {
|
public static JobsWorld getJobsWorld(int id) {
|
||||||
for (JobsWorld jobsWorld : jobsWorlds.values()) {
|
for (JobsWorld jobsWorld : jobsWorlds.values()) {
|
||||||
if (jobsWorld.getId() == id) {
|
if (jobsWorld.getId() == id) {
|
||||||
return jobsWorld;
|
return jobsWorld;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, JobsWorld> getJobsWorlds() {
|
public static Map<String, JobsWorld> getJobsWorlds() {
|
||||||
return jobsWorlds;
|
return jobsWorlds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addJobsWorld(JobsWorld jobsWorld) {
|
public static void addJobsWorld(JobsWorld jobsWorld) {
|
||||||
if (jobsWorld == null || jobsWorld.getId() == 0)
|
if (jobsWorld == null || jobsWorld.getId() == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
jobsWorlds.put(jobsWorld.getName().toLowerCase(), jobsWorld);
|
jobsWorlds.put(jobsWorld.getName().toLowerCase(), jobsWorld);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getFilesFromPackage(String pckgname) throws ClassNotFoundException {
|
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 {
|
public static List<String> getFilesFromPackage(String pckgname, String cleaner, String fileType) throws ClassNotFoundException {
|
||||||
List<String> result = new ArrayList<>();
|
List<String> result = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
for (URL jarURL : ((URLClassLoader) Jobs.class.getClassLoader()).getURLs()) {
|
for (URL jarURL : ((URLClassLoader) Jobs.class.getClassLoader()).getURLs()) {
|
||||||
try {
|
try {
|
||||||
result.addAll(getFilesInSamePackageFromJar(pckgname, jarURL.toURI().getPath(), cleaner, fileType));
|
result.addAll(getFilesInSamePackageFromJar(pckgname, jarURL.toURI().getPath(), cleaner, fileType));
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (NullPointerException x) {
|
} catch (NullPointerException x) {
|
||||||
throw new ClassNotFoundException(pckgname + " does not appear to be a valid package (Null pointer exception)");
|
throw new ClassNotFoundException(pckgname + " does not appear to be a valid package (Null pointer exception)");
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getFilesInSamePackageFromJar(String packageName, String jarPath, String cleaner, String fileType) {
|
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)) {
|
try (JarFile jarFile = new JarFile(jarPath)) {
|
||||||
Enumeration<JarEntry> en = jarFile.entries();
|
Enumeration<JarEntry> en = jarFile.entries();
|
||||||
while (en.hasMoreElements()) {
|
while (en.hasMoreElements()) {
|
||||||
String entryName = en.nextElement().getName();
|
String entryName = en.nextElement().getName();
|
||||||
|
|
||||||
if (entryName.endsWith("." + fileType) && entryName.startsWith(packageName)) {
|
if (entryName.endsWith("." + fileType) && entryName.startsWith(packageName)) {
|
||||||
String name = entryName.replace(packageName, "").replace("." + fileType, "").replace("/", "");
|
String name = entryName.replace(packageName, "").replace("." + fileType, "").replace("/", "");
|
||||||
|
|
||||||
if (name.contains("$"))
|
if (name.contains("$"))
|
||||||
name = name.split("\\$", 2)[0];
|
name = name.split("\\$", 2)[0];
|
||||||
|
|
||||||
if (cleaner != null && !cleaner.isEmpty())
|
if (cleaner != null && !cleaner.isEmpty())
|
||||||
name = name.replace(cleaner, "");
|
name = name.replace(cleaner, "");
|
||||||
|
|
||||||
listOfCommands.add(name);
|
listOfCommands.add(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (java.io.IOException e) {
|
} 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) {
|
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(left);
|
||||||
difference.putAll(right);
|
difference.putAll(right);
|
||||||
difference.entrySet().removeAll(right.entrySet());
|
difference.entrySet().removeAll(right.entrySet());
|
||||||
|
|
||||||
return difference;
|
return difference;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean enchantMatchesActionInfo(String enchant, EnchantActionInfo actionInfo) {
|
public static boolean enchantMatchesActionInfo(String enchant, EnchantActionInfo actionInfo) {
|
||||||
CMIEnchantment e = CMIEnchantment.get(actionInfo.getName());
|
CMIEnchantment e = CMIEnchantment.get(actionInfo.getName());
|
||||||
String enchantName = e != null ? CMIEnchantment.get(actionInfo.getName()).toString() : actionInfo.getName();
|
String enchantName = e != null ? CMIEnchantment.get(actionInfo.getName()).toString() : actionInfo.getName();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
// Enchantment without level e.g. silk_touch
|
// Enchantment without level e.g. silk_touch
|
||||||
enchant.equalsIgnoreCase(enchantName) ||
|
enchant.equalsIgnoreCase(enchantName) ||
|
||||||
// Enchantment with level e.g. fire_aspect:1
|
// Enchantment with level e.g. fire_aspect:1
|
||||||
enchant.equalsIgnoreCase(enchantName + ":" + actionInfo.getLevel()));
|
enchant.equalsIgnoreCase(enchantName + ":" + actionInfo.getLevel()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user