mirror of
https://github.com/rockyhawk64/CommandPanels.git
synced 2025-11-18 07:14:17 +01:00
Revert duplicate to not needing toggle for commands.
This commit is contained in:
parent
51e35b1c7a
commit
faaa0ac07f
@ -111,16 +111,8 @@ public class Utils implements Listener {
|
||||
String duplicateValue = panel.getConfig().getString("item." + item + section + ".duplicate");
|
||||
|
||||
// Check if the clicked slot is in the duplicate configuration
|
||||
DuplicateResult result = isSlotInDuplicateConfig(clickedSlot, duplicateValue);
|
||||
if(result.isInDuplicate) {
|
||||
if(isSlotInDuplicate(clickedSlot, duplicateValue)) {
|
||||
foundSlot = item;
|
||||
|
||||
// If commands shouldn't be duplicated, return early after cancelling the event
|
||||
if(!result.shouldDuplicateCommands) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -207,39 +199,15 @@ public class Utils implements Listener {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Class to hold the result of duplicate check
|
||||
private static class DuplicateResult {
|
||||
public boolean isInDuplicate;
|
||||
public boolean shouldDuplicateCommands;
|
||||
//Helper method to see if the slot is a duplicate so it can copy commands.
|
||||
private boolean isSlotInDuplicate(int slot, String duplicateConfig) {
|
||||
if(duplicateConfig == null) return false;
|
||||
|
||||
public DuplicateResult(boolean isInDuplicate, boolean shouldDuplicateCommands) {
|
||||
this.isInDuplicate = isInDuplicate;
|
||||
this.shouldDuplicateCommands = shouldDuplicateCommands;
|
||||
}
|
||||
}
|
||||
|
||||
// Helper method to check if a slot is included in the duplicate configuration and if commands should be duplicated
|
||||
private DuplicateResult isSlotInDuplicateConfig(int slot, String duplicateConfig) {
|
||||
if(duplicateConfig == null) return new DuplicateResult(false, false);
|
||||
|
||||
boolean shouldDuplicateCommands = false;
|
||||
String[] dupeItems = duplicateConfig.split(",");
|
||||
|
||||
// First check if "true" is included in the config
|
||||
for(String item : dupeItems) {
|
||||
if(item.trim().equalsIgnoreCase("true")) {
|
||||
shouldDuplicateCommands = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Then check if the slot is included
|
||||
for(String dupeItem : dupeItems) {
|
||||
dupeItem = dupeItem.trim(); // Remove any whitespace
|
||||
|
||||
// Skip the "true" flag, it's not a slot designation
|
||||
if(dupeItem.equalsIgnoreCase("true")) continue;
|
||||
|
||||
if(dupeItem.contains("-")) {
|
||||
// This is a range
|
||||
String[] range = dupeItem.split("-");
|
||||
@ -247,19 +215,19 @@ public class Utils implements Listener {
|
||||
int max = Integer.parseInt(range[1]);
|
||||
|
||||
if(slot >= min && slot <= max) {
|
||||
return new DuplicateResult(true, shouldDuplicateCommands);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
// This is a single slot
|
||||
try {
|
||||
int dupeSlot = Integer.parseInt(dupeItem);
|
||||
if(dupeSlot == slot) {
|
||||
return new DuplicateResult(true, shouldDuplicateCommands);
|
||||
return true;
|
||||
}
|
||||
} catch(NumberFormatException ignored) {}
|
||||
}
|
||||
}
|
||||
|
||||
return new DuplicateResult(false, shouldDuplicateCommands);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,11 +85,6 @@ public class OpenGUI {
|
||||
try {
|
||||
String[] duplicateItems = pconfig.getString("item." + item + section + ".duplicate").split(",");
|
||||
for (String tempDupe : duplicateItems) {
|
||||
//Skip the "slot" if it is just the command setting
|
||||
if(tempDupe.equalsIgnoreCase("true")){
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tempDupe.contains("-")) {
|
||||
//if there is multiple dupe items, convert numbers to ints
|
||||
int[] bothNumbers = new int[]{Integer.parseInt(tempDupe.split("-")[0]), Integer.parseInt(tempDupe.split("-")[1])};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user