This commit is contained in:
rockyhawk64 2024-07-11 10:30:51 +10:00
parent 6c390a98f2
commit 6f2a39d613
4 changed files with 63 additions and 67 deletions

View File

@ -1,4 +1,4 @@
version: 3.21.3.1 version: 3.21.3.2
main: me.rockyhawk.commandpanels.CommandPanels main: me.rockyhawk.commandpanels.CommandPanels
name: CommandPanels name: CommandPanels
author: RockyHawk author: RockyHawk

View File

@ -335,8 +335,8 @@ public class CommandPanels extends JavaPlugin{
assert renamedMeta != null; assert renamedMeta != null;
//hiding attributes will add an NBT tag //hiding attributes will add an NBT tag
if(hideAttributes) { if(hideAttributes) {
renamedMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
renamedMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); renamedMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
renamedMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
//HIDE_ADDITIONAL_TOOLTIP was added into 1.20.5 api //HIDE_ADDITIONAL_TOOLTIP was added into 1.20.5 api
if(legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_21) || if(legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_21) ||
(legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_20) && legacy.MINOR_VERSION >= 5)){ (legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_20) && legacy.MINOR_VERSION >= 5)){
@ -355,6 +355,10 @@ public class CommandPanels extends JavaPlugin{
if(legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_17)){ if(legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_17)){
renamedMeta.addItemFlags(ItemFlag.HIDE_DYE); renamedMeta.addItemFlags(ItemFlag.HIDE_DYE);
} }
//setAttributeModifiers was added into 1.14 api
if(legacy.MAJOR_VERSION.greaterThanOrEqualTo(MinecraftVersions.v1_14)){
renamedMeta.setAttributeModifiers(null);
}
} }
if (customName != null) { if (customName != null) {
renamedMeta.setDisplayName(customName); renamedMeta.setDisplayName(customName);

View File

@ -19,74 +19,66 @@ public class HasSections {
plugin = pl; plugin = pl;
} }
public String hasSection(Panel panel, PanelPosition position, ConfigurationSection cf, Player p){ public String hasSection(Panel panel, PanelPosition position, ConfigurationSection cf, Player p) {
for (int count = 0; cf.getKeys(false).size() > count; count++) { for (String setName : cf.getKeys(false)) {
String setName; if (!cf.isConfigurationSection(setName)) continue;
if(cf.isSet("has" + count)) {
setName = "has" + count;
}else{
continue;
}
boolean endProcess = true; ConfigurationSection currentSection = cf.getConfigurationSection(setName);
//loop through possible values and compares for hypothetical and operators int numberOfConditions = currentSection.getKeys(false).size();
for (int a = 0; cf.getConfigurationSection(setName).getKeys(false).size() > a; a++) {
if(cf.isSet(setName + ".value" + a) && cf.isSet(setName + ".compare" + a)){
//ensure the endProcess variable has been reset for another operation
endProcess = true;
//get the values of this statement
String value;
String compare;
try {
value = ChatColor.stripColor(plugin.tex.placeholders(panel, position, p, cf.getString(setName + ".value" + a)));
compare = ChatColor.stripColor(plugin.tex.placeholders(panel, position, p, cf.getString(setName + ".compare" + a)));
}catch (Exception e) {
//if errors getting text return
plugin.debug(e,p);
return "";
}
String operator = "AND"; Boolean currentBlockResult = null; // This will store the result of the current block (a set of conditions combined by AND or OR).
if(compare.endsWith(" OR")){ String previousOperator = "AND"; // Default logical operator to start with.
compare = compare.substring(0, compare.length()-3);
operator = "OR";
}else if(compare.endsWith(" AND")){
compare = compare.substring(0, compare.length()-4);
}
//list of values with the or operator for (int a = 0; a < numberOfConditions; a++) {
HashSet<String> values = doOperators(new HashSet<>(Collections.singletonList(value))); if (!currentSection.isSet("value" + a) || !currentSection.isSet("compare" + a)) {
//go through all values with the or operator continue;
for(String val : values){ }
if (hasProcess(setName, val, compare, p)) {
endProcess = false; String value = ChatColor.stripColor(plugin.tex.placeholders(panel, position, p, currentSection.getString("value" + a)));
//if it is true and it is OR, there is no need to check the next value in the line String compare = ChatColor.stripColor(plugin.tex.placeholders(panel, position, p, currentSection.getString("compare" + a)));
if(operator.equals("OR")){
a++; String operator = "AND"; // Default operator for the current condition.
} if (compare.endsWith(" OR")) {
} compare = compare.substring(0, compare.length() - 3);
} operator = "OR";
if(endProcess){ } else if (compare.endsWith(" AND")) {
//check if the operator link between the next value/compare is OR compare = compare.substring(0, compare.length() - 4);
if(operator.equals("OR")){ }
//I can just continue because the algorithm already assumes the last sequence was true
endProcess = false; HashSet<String> values = doOperators(new HashSet<>(Collections.singletonList(value)));
continue; boolean localResult = false; // This tracks the result of the current condition.
} for (String val : values) {
if (hasProcess(setName, val, compare, p)) {
localResult = true;
break; break;
} }
} }
if (currentBlockResult == null) {
// Initialize the result of the block with the result of the first condition.
currentBlockResult = localResult;
} else {
// Combine the result of the current condition with the block result based on the previous operator.
if (previousOperator.equals("AND")) {
currentBlockResult = currentBlockResult && localResult;
} else if (previousOperator.equals("OR")) {
currentBlockResult = currentBlockResult || localResult;
}
}
previousOperator = operator; // Update the operator for the next condition.
} }
//if the has section is false move to the next has section
if(endProcess){ if (currentBlockResult != null && currentBlockResult) {
continue; // If the result of this section is true, check nested sections.
return "." + setName + hasSection(panel, position, currentSection, p);
} }
//proceed if none of the values were false // If the result is false, continue to the next 'has' section.
return "." + setName + hasSection(panel, position, cf.getConfigurationSection(setName), p);
} }
return ""; return "";
} }
private HashSet<String> doOperators(HashSet<String> value){ private HashSet<String> doOperators(HashSet<String> value){
for(String val : value){ for(String val : value){
if(val.contains(" OR ")){ if(val.contains(" OR ")){

View File

@ -315,15 +315,15 @@ public class ItemCreation {
ItemMeta unbreak = s.getItemMeta(); ItemMeta unbreak = s.getItemMeta();
unbreak.setUnbreakable(true); unbreak.setUnbreakable(true);
s.setItemMeta(unbreak); s.setItemMeta(unbreak);
} }else {
try {
try { Damageable itemDamage = (Damageable) s.getItemMeta();
Damageable itemDamage = (Damageable) s.getItemMeta(); itemDamage.setDamage(Integer.parseInt(Objects.requireNonNull(plugin.tex.placeholders(panel, position, p, itemSection.getString("damage")))));
itemDamage.setDamage(Integer.parseInt(Objects.requireNonNull(plugin.tex.placeholders(panel,position,p, itemSection.getString("damage"))))); s.setItemMeta((ItemMeta) itemDamage);
s.setItemMeta((ItemMeta) itemDamage); } catch (Exception e) {
} catch (Exception e) { plugin.debug(e, p);
plugin.debug(e, p); p.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.error") + " damage: " + itemSection.getString("damage")));
p.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.error") + " damage: " + itemSection.getString("damage"))); }
} }
} }
} }