1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-02-21 14:51:19 +01:00

Add sub name ("-all") for materials to detect all materials that same with another one like wool colors (#812)

Closes #271
This commit is contained in:
kikelkik 2020-06-09 22:07:08 +02:00 committed by GitHub
parent c23475e1e5
commit 0a08dcf402
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 31 deletions

View File

@ -1197,7 +1197,7 @@ public enum CMIMaterial {
for (CMIMaterial one : CMIMaterial.values()) {
if (one.getLegacyId() == null)
continue;
if (one.getLegacyId() != mat.getLegacyId())
if (!one.getLegacyId().equals(mat.getLegacyId()))
continue;
ls.add(one);
}
@ -1228,7 +1228,7 @@ public enum CMIMaterial {
for (CMIMaterial one : CMIMaterial.values()) {
if (one.getLegacyId() == null)
continue;
if (one.getLegacyId() != mat.getLegacyId())
if (!one.getLegacyId().equals(mat.getLegacyId()))
continue;
if (one.getLegacyData() == id)
return one;
@ -1240,9 +1240,9 @@ public enum CMIMaterial {
public static CMIMaterial get(String id) {
if (id == null)
return CMIMaterial.NONE;
Integer ids = null;
Integer data = null;
id = id.replace("_", "").replace(" ", "").replace("minecraft:", "").toLowerCase();
Integer ids;
Integer data;
id = id.replaceAll("_| |minecraft:", "").toLowerCase();
if (id.contains(":")) {
try {
@ -1251,7 +1251,7 @@ public enum CMIMaterial {
if (ids <= 0)
return CMIMaterial.NONE;
return get(ids, data);
} catch (Exception ex) {
} catch (Exception ignored) {
}
try {
@ -1268,7 +1268,7 @@ public enum CMIMaterial {
return mat;
}
}
} catch (Exception ex) {
} catch (Exception ignored) {
}
}
@ -1290,7 +1290,7 @@ public enum CMIMaterial {
if (mat != null) {
return mat;
}
} catch (Exception ex) {
} catch (Exception ignored) {
}
return CMIMaterial.NONE;
@ -2508,4 +2508,20 @@ public enum CMIMaterial {
public void setBukkitName(String bukkitName) {
this.bukkitName = bukkitName;
}
public static String getGeneralMaterialName(String fullName) {
String newName = fullName.toUpperCase();
if (newName.startsWith("STRIPPED")) {
return newName.replaceFirst("_[^_]+", "");
}
else if (newName.matches("^(DARK|LIGHT).+")) {
return newName.replaceFirst(".+?_.+?_", "");
}
else if (newName.matches(
"^(WHITE|ORANGE|MAGENTA|YELLOW|LIME|PINK|GRAY|CYAN|PURPLE|BLUE|BROWN|GREEN|RED|BLACK|" +
"OAK|SPRUCE|BIRCH|JUNGLE|ACACIA).+")) {
return newName.replaceFirst(".+?_", "");
}
return fullName;
}
}

View File

@ -1229,7 +1229,7 @@ public class ConfigManager {
Integer matId = null;
try {
matId = Integer.valueOf(myKey);
} catch (NumberFormatException e) {
} catch (NumberFormatException ignored) {
}
if (matId != null) {
material = CMIMaterial.get(matId);
@ -1402,11 +1402,14 @@ public class ConfigManager {
subType = myKey.split(":")[1];
}
}
if (type == null) {
log.warning("Job " + jobKey + " has an invalid " + actionType.getName() + " type property: " + key + "!");
continue;
}
if (":ALL".equalsIgnoreCase(subType)) {
meta = "ALL";
type = CMIMaterial.getGeneralMaterialName(type);
}
if (actionType == ActionType.TNTBREAK)
Jobs.getGCManager().setTntFinder(true);

View File

@ -1,11 +1,8 @@
package com.gamingmesh.jobs.config;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
@ -51,6 +48,9 @@ public class NameTranslatorManager {
case BREW:
case FISH:
case STRIPLOGS:
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)
materialName = materialName.replace(" ", "");
CMIMaterial mat = CMIMaterial.get(materialName.replace(" ", ""));
@ -83,6 +83,9 @@ public class NameTranslatorManager {
if (nameLs != null && nameMeta != null) {
return nameLs + ":" + nameMeta;
}
if (mat.equals(CMIMaterial.NONE)) {
return fallbackMaterialName;
}
return mat.getName();
}

View File

@ -18,7 +18,9 @@
package com.gamingmesh.jobs.container;
import com.gamingmesh.jobs.CMILib.CMIMaterial;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.actions.PotionItemActionInfo;
import com.gamingmesh.jobs.resources.jfep.Parser;
import com.gamingmesh.jobs.stuff.ChatColor;
@ -224,23 +226,24 @@ public class Job {
}
public JobInfo getJobInfo(ActionInfo action, int level) {
BiPredicate<JobInfo, ActionInfo> condition = (jobInfo, actionInfo) -> {
return jobInfo.getName().equalsIgnoreCase(action.getNameWithSub()) ||
(jobInfo.getName() + ":" + jobInfo.getMeta()).equalsIgnoreCase(action.getNameWithSub()) ||
jobInfo.getName().equalsIgnoreCase(action.getName());
};
BiPredicate<JobInfo, ActionInfo> condition = (jobInfo, actionInfo) ->
jobInfo.getName().equalsIgnoreCase(action.getNameWithSub()) ||
(jobInfo.getName() + ":" + jobInfo.getMeta()).equalsIgnoreCase(action.getNameWithSub()) ||
jobInfo.getName().equalsIgnoreCase(action.getName());
for (JobInfo info : getJobInfo(action.getType())) {
if (condition.test(info, action)) {
if (!info.isInLevelRange(level)) {
break;
}
return info;
}
}
return null;
String shortActionName = CMIMaterial.getGeneralMaterialName(action.getName());
for (JobInfo info : getJobInfo(action.getType())) {
if (condition.test(info, action)) {
if (!info.isInLevelRange(level)) {
break;
}
return info;
}
if ((shortActionName + ":ALL").equalsIgnoreCase(info.getName())) {
return info;
}
}
return null;
}
/**