mirror of
https://github.com/Zrips/Jobs.git
synced 2024-12-01 23:13:48 +01:00
So lets properly recognize materials with name and data
This commit is contained in:
parent
ecb189b03e
commit
76b050a788
@ -1406,7 +1406,18 @@ public enum CMIMaterial {
|
||||
id = split[0];
|
||||
|
||||
CMIMaterial mat = ItemManager.byName.get(id + ":" + data);
|
||||
if (mat != null && mat.getLegacyId() > 0 && (mat = get(mat.getLegacyId(), data)) != null) {
|
||||
|
||||
if (mat == null)
|
||||
mat = ItemManager.byName.get(id);
|
||||
|
||||
if (mat != null) {
|
||||
if (mat.getLegacyId() > 0) {
|
||||
CMIMaterial m = get(mat.getLegacyId(), data);
|
||||
|
||||
if (m != null)
|
||||
mat = m;
|
||||
}
|
||||
|
||||
return mat;
|
||||
}
|
||||
} catch (NumberFormatException ex) {
|
||||
|
@ -44,7 +44,7 @@ public class HookEconomyTask implements Runnable {
|
||||
Jobs.getPluginLogger().severe("Vault is required by this plugin for economy support!");
|
||||
Jobs.getPluginLogger().severe("Please install them first!");
|
||||
Jobs.getPluginLogger().severe("You can find the latest versions here:");
|
||||
Jobs.getPluginLogger().severe("https://www.spigotmc.org/resources/vault.34315/");
|
||||
Jobs.getPluginLogger().severe("https://www.spigotmc.org/resources/34315/");
|
||||
Jobs.getPluginLogger().severe("==============================================");
|
||||
}
|
||||
|
||||
|
@ -156,7 +156,11 @@ public class PermissionManager {
|
||||
* @return the max value
|
||||
*/
|
||||
public double getMaxPermission(JobsPlayer jPlayer, String perm, boolean force, boolean cumulative) {
|
||||
if (jPlayer == null || jPlayer.getPlayer() == null)
|
||||
if (jPlayer == null)
|
||||
return 0D;
|
||||
|
||||
Player player = jPlayer.getPlayer();
|
||||
if (player == null)
|
||||
return 0D;
|
||||
|
||||
perm = perm.toLowerCase();
|
||||
@ -165,7 +169,7 @@ public class PermissionManager {
|
||||
|
||||
Map<String, Boolean> permissions = jPlayer.getPermissionsCache();
|
||||
if (force || permissions == null || getDelay(perm) + jPlayer.getLastPermissionUpdate() < System.currentTimeMillis()) {
|
||||
permissions = getAll(jPlayer.getPlayer());
|
||||
permissions = getAll(player);
|
||||
jPlayer.setPermissionsCache(permissions);
|
||||
jPlayer.setLastPermissionUpdate(System.currentTimeMillis());
|
||||
}
|
||||
@ -190,12 +194,16 @@ public class PermissionManager {
|
||||
}
|
||||
|
||||
public boolean hasPermission(JobsPlayer jPlayer, String perm) {
|
||||
if (jPlayer == null || jPlayer.getPlayer() == null)
|
||||
if (jPlayer == null)
|
||||
return false;
|
||||
|
||||
Player player = jPlayer.getPlayer();
|
||||
if (player == null)
|
||||
return false;
|
||||
|
||||
Map<String, Boolean> permissions = jPlayer.getPermissionsCache();
|
||||
if (permissions == null || getDelay(perm) + jPlayer.getLastPermissionUpdate() < System.currentTimeMillis()) {
|
||||
permissions = getAll(jPlayer.getPlayer());
|
||||
permissions = getAll(player);
|
||||
jPlayer.setPermissionsCache(permissions);
|
||||
jPlayer.setLastPermissionUpdate(System.currentTimeMillis());
|
||||
}
|
||||
|
@ -660,7 +660,7 @@ public class ConfigManager {
|
||||
break;
|
||||
}
|
||||
|
||||
// Break and Place actions MUST be blocks
|
||||
// These actions MUST be blocks
|
||||
if (actionType == ActionType.BREAK || actionType == ActionType.PLACE || actionType == ActionType.STRIPLOGS) {
|
||||
if (!material.isBlock() || material.getMaterial().toString().equalsIgnoreCase("AIR")) {
|
||||
Jobs.getPluginLogger().warning("Job " + jobName + " has an invalid " + actionType.getName() + " type property: " + material
|
||||
@ -987,17 +987,14 @@ public class ConfigManager {
|
||||
|
||||
String description = CMIChatColor.translate(jobSection.getString("description", ""));
|
||||
|
||||
List<String> fDescription = new ArrayList<>();
|
||||
if (jobSection.contains("FullDescription")) {
|
||||
List<String> fDescription = jobSection.getStringList("FullDescription");
|
||||
|
||||
if (jobSection.isString("FullDescription"))
|
||||
fDescription.add(jobSection.getString("FullDescription"));
|
||||
else if (jobSection.isList("FullDescription"))
|
||||
fDescription.addAll(jobSection.getStringList("FullDescription"));
|
||||
|
||||
for (int i = 0; i < fDescription.size(); i++) {
|
||||
fDescription.set(i, CMIChatColor.translate(fDescription.get(i)));
|
||||
}
|
||||
}
|
||||
|
||||
CMIChatColor color = CMIChatColor.WHITE;
|
||||
String c = jobSection.getString("ChatColour");
|
||||
@ -1218,11 +1215,10 @@ public class ConfigManager {
|
||||
continue;
|
||||
}
|
||||
|
||||
List<String> commands = new ArrayList<>();
|
||||
List<String> commands = commandSection.getStringList("command");
|
||||
|
||||
if (commandSection.isString("command"))
|
||||
commands.add(commandSection.getString("command"));
|
||||
else if (commandSection.isList("command"))
|
||||
commands.addAll(commandSection.getStringList("command"));
|
||||
|
||||
int levelFrom = commandSection.getInt("levelFrom", 0);
|
||||
int levelUntil = commandSection.getInt("levelUntil", maxLevel);
|
||||
@ -1374,21 +1370,17 @@ public class ConfigManager {
|
||||
continue;
|
||||
|
||||
Quest quest = new Quest(sqsection.getString("Name", one), job);
|
||||
|
||||
if (sqsection.isString("Target")) {
|
||||
ActionType actionType = ActionType.getByName(sqsection.getString("Action"));
|
||||
|
||||
if (actionType == null)
|
||||
continue;
|
||||
|
||||
if (actionType != null) {
|
||||
KeyValues kv = getKeyValue(sqsection.getString("Target").toUpperCase(), actionType, jobFullName);
|
||||
|
||||
if (kv != null) {
|
||||
int amount = sqsection.getInt("Amount", 1);
|
||||
quest.addObjective(new QuestObjective(actionType, kv.getId(), kv.getMeta(), (kv.getType() + kv.getSubType()).toUpperCase(), amount));
|
||||
}
|
||||
}
|
||||
|
||||
if (sqsection.isList("Objectives")) {
|
||||
for (String oneObjective : sqsection.getStringList("Objectives")) {
|
||||
String[] split = oneObjective.split(";", 3);
|
||||
|
||||
@ -1398,24 +1390,22 @@ public class ConfigManager {
|
||||
}
|
||||
|
||||
try {
|
||||
ActionType actionType = ActionType.getByName(split[0]);
|
||||
if (actionType == null)
|
||||
if ((actionType = ActionType.getByName(split[0])) == null)
|
||||
continue;
|
||||
|
||||
String mats = split[1].toUpperCase();
|
||||
String[] co = mats.split(",");
|
||||
|
||||
int amount = 1;
|
||||
if (split.length <= 3) {
|
||||
if (split.length <= 3)
|
||||
amount = Integer.parseInt(split[2]);
|
||||
}
|
||||
|
||||
if (co.length > 0) {
|
||||
for (String materials : co) {
|
||||
KeyValues kv = getKeyValue(materials, actionType, jobFullName);
|
||||
if (kv == null) {
|
||||
|
||||
if (kv == null)
|
||||
continue;
|
||||
}
|
||||
|
||||
QuestObjective objective = new QuestObjective(actionType, kv.getId(), kv.getMeta(),
|
||||
(kv.getType() + kv.getSubType()).toUpperCase(), amount);
|
||||
@ -1423,6 +1413,7 @@ public class ConfigManager {
|
||||
}
|
||||
} else {
|
||||
KeyValues kv = getKeyValue(mats, actionType, jobFullName);
|
||||
|
||||
if (kv != null) {
|
||||
QuestObjective objective = new QuestObjective(actionType, kv.getId(), kv.getMeta(),
|
||||
(kv.getType() + kv.getSubType()).toUpperCase(), amount);
|
||||
@ -1433,13 +1424,6 @@ public class ConfigManager {
|
||||
log.warning("Job " + jobKey + " has incorrect quest objective (" + oneObjective + ")!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int chance = sqsection.getInt("Chance", 100);
|
||||
|
||||
List<String> commands = sqsection.getStringList("RewardCommands"),
|
||||
desc = sqsection.getStringList("RewardDesc"),
|
||||
areas = sqsection.getStringList("RestrictedAreas");
|
||||
|
||||
quest.setMinLvl(sqsection.getInt("fromLevel"));
|
||||
|
||||
@ -1447,10 +1431,11 @@ public class ConfigManager {
|
||||
quest.setMaxLvl(sqsection.getInt("toLevel"));
|
||||
|
||||
quest.setConfigName(one);
|
||||
quest.setChance(chance);
|
||||
quest.setRewardCmds(commands);
|
||||
quest.setDescription(desc);
|
||||
quest.setRestrictedArea(areas);
|
||||
quest.setChance(sqsection.getInt("Chance", 100));
|
||||
quest.setRewardCmds(sqsection.getStringList("RewardCommands"));
|
||||
quest.setDescription(sqsection.getStringList("RewardDesc"));
|
||||
quest.setRestrictedArea(sqsection.getStringList("RestrictedAreas"));
|
||||
|
||||
quests.add(quest);
|
||||
} catch (Exception e) {
|
||||
Jobs.consoleMsg("&c[Jobs] Can't load " + one + " quest for " + jobFullName);
|
||||
|
@ -46,35 +46,9 @@ public class NameTranslatorManager {
|
||||
case BREW:
|
||||
case FISH:
|
||||
case STRIPLOGS:
|
||||
String matName = materialName;
|
||||
materialName = materialName.replace(" ", "");
|
||||
|
||||
if (meta != null && !meta.isEmpty()) {
|
||||
CMIMaterial mat = CMIMaterial.get(materialName + ":" + meta);
|
||||
NameList nameLs = listOfNames.get(mat);
|
||||
|
||||
if (nameLs == null) {
|
||||
mat = CMIMaterial.get(materialName.replace(" ", ""));
|
||||
|
||||
if ((nameLs = listOfNames.get(mat)) != null) {
|
||||
NameList nameMeta = listOfNames.get(CMIMaterial.get(meta.replace(" ", "")));
|
||||
|
||||
if (nameMeta != null) {
|
||||
return nameLs + ":" + nameMeta;
|
||||
}
|
||||
}
|
||||
|
||||
if (mat == CMIMaterial.NONE) {
|
||||
String fallbackMaterialName = Arrays.stream(materialName.split("\\s|:"))
|
||||
.map(word -> word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase())
|
||||
.collect(Collectors.joining(" ")); // returns capitalized word (from this -> To This)
|
||||
|
||||
return fallbackMaterialName;
|
||||
}
|
||||
|
||||
return mat.getName();
|
||||
}
|
||||
}
|
||||
|
||||
CMIMaterial mat = CMIMaterial.get(materialName);
|
||||
NameList nameLs = listOfNames.get(mat);
|
||||
|
||||
@ -88,6 +62,30 @@ public class NameTranslatorManager {
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
NameList nameMeta = listOfNames.get(CMIMaterial.get(meta.replace(" ", "")));
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
return mat.getName();
|
||||
}
|
||||
}
|
||||
|
||||
if (id > 0 && meta != null && !meta.isEmpty()) {
|
||||
mat = CMIMaterial.get(id + ":" + meta);
|
||||
nameLs = listOfNames.get(mat);
|
||||
@ -145,10 +143,9 @@ public class NameTranslatorManager {
|
||||
}
|
||||
}
|
||||
|
||||
String fallbackColorName = 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())
|
||||
.collect(Collectors.joining(" ")); // returns capitalized word (from this -> To This)
|
||||
return fallbackColorName;
|
||||
case MMKILL:
|
||||
NameList got = listOfMMEntities.get(materialName.toLowerCase());
|
||||
|
||||
@ -311,57 +308,41 @@ public class NameTranslatorManager {
|
||||
}
|
||||
|
||||
String n = mat.getLegacyId() + (mat.getLegacyData() == -1 ? "" : ":" + mat.getLegacyData());
|
||||
String name = null;
|
||||
String name = c.getC().getString("ItemList." + mat.toString());
|
||||
|
||||
if (c.getC().isString("ItemList." + mat.toString())) {
|
||||
name = c.getC().getString("ItemList." + mat.toString());
|
||||
}
|
||||
|
||||
if (name == null && c.getC().isConfigurationSection("ItemList." + n)) {
|
||||
if (name == null) {
|
||||
name = c.getC().getString("ItemList." + n + ".Name");
|
||||
}
|
||||
|
||||
if (name == null) {
|
||||
n = mat.getLegacyId() + ":" + mat.getLegacyData();
|
||||
if (c.getC().isConfigurationSection("ItemList." + n)) {
|
||||
name = c.getC().getString("ItemList." + n + ".Name");
|
||||
}
|
||||
}
|
||||
|
||||
if (name == null) {
|
||||
n = String.valueOf(mat.getLegacyId());
|
||||
if (c.getC().isConfigurationSection("ItemList." + n)) {
|
||||
name = c.getC().getString("ItemList." + n + ".Name");
|
||||
}
|
||||
}
|
||||
|
||||
if (name == null) {
|
||||
n = String.valueOf(mat.getId());
|
||||
if (c.getC().isConfigurationSection("ItemList." + n)) {
|
||||
name = c.getC().getString("ItemList." + n + ".Name");
|
||||
}
|
||||
}
|
||||
|
||||
if (name == null) {
|
||||
n = mat.getLegacyId() + ":" + mat.getLegacyData() + "-" + mat.getBukkitName();
|
||||
if (c.getC().isString("ItemList." + n)) {
|
||||
name = c.getC().getString("ItemList." + n);
|
||||
}
|
||||
}
|
||||
|
||||
if (name == null) {
|
||||
n = String.valueOf(mat.getLegacyId()) + "-" + mat.getBukkitName();
|
||||
if (c.getC().isString("ItemList." + n)) {
|
||||
n = mat.getLegacyId() + "-" + mat.getBukkitName();
|
||||
name = c.getC().getString("ItemList." + n);
|
||||
}
|
||||
}
|
||||
|
||||
if (name == null) {
|
||||
n = String.valueOf(mat.getId()) + "-" + mat.getBukkitName();
|
||||
if (c.getC().isString("ItemList." + n)) {
|
||||
n = mat.getId() + "-" + mat.getBukkitName();
|
||||
name = c.getC().getString("ItemList." + n);
|
||||
}
|
||||
}
|
||||
|
||||
if (name == null) {
|
||||
name = mat.getName();
|
||||
@ -376,19 +357,12 @@ public class NameTranslatorManager {
|
||||
continue;
|
||||
|
||||
String n = Integer.toString(ent.getId());
|
||||
|
||||
String name = null;
|
||||
|
||||
if (c.getC().isConfigurationSection("EntityList." + n)) {
|
||||
name = c.getC().getString("EntityList." + n + ".Name");
|
||||
}
|
||||
String name = c.getC().getString("EntityList." + n + ".Name");
|
||||
|
||||
if (name == null) {
|
||||
n += "-" + ent.toString();
|
||||
if (c.getC().isConfigurationSection("EntityList." + n)) {
|
||||
name = c.getC().getString("EntityList." + n);
|
||||
}
|
||||
}
|
||||
|
||||
if (name == null) {
|
||||
name = ent.getName();
|
||||
|
@ -399,7 +399,7 @@ public class ShopManager {
|
||||
if (itemSection.isString("Id"))
|
||||
id = itemSection.getString("Id");
|
||||
else {
|
||||
Jobs.getPluginLogger().severe("Shop item " + category + " has an invalid GiveItems name property. Skipping!");
|
||||
Jobs.getPluginLogger().severe("Shop item " + category + " has an invalid GiveItems item id property. Skipping!");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -54,11 +54,15 @@ public enum ActionType {
|
||||
}
|
||||
|
||||
public static ActionType getByName(String name) {
|
||||
if (name != null) {
|
||||
name = name.replace("_", "");
|
||||
|
||||
for (ActionType one : ActionType.values()) {
|
||||
if (one.name.equalsIgnoreCase(name))
|
||||
return one;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user