diff --git a/src/main/java/net/Indyuce/mmoitems/stat/data/CommandData.java b/src/main/java/net/Indyuce/mmoitems/stat/data/CommandData.java index 689178ec..0ed222e2 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/data/CommandData.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/data/CommandData.java @@ -7,19 +7,6 @@ public class CommandData { private final double delay; private final boolean console, op; - @Override - public boolean equals(Object obj) { - if (!(obj instanceof CommandData)) { return false; } - - // Any difference in these will cause this to not be equal - if (((CommandData) obj).getDelay() != getDelay()) { return false; } - if (((CommandData) obj).isConsoleCommand() != isConsoleCommand()) { return false; } - if (((CommandData) obj).hasOpPerms() != hasOpPerms()) { return false; } - - // Finally, if the command strings match. - return ((CommandData) obj).getCommand().equals(getCommand()); - } - public CommandData(String command, double delay, boolean console, boolean op) { Validate.notNull(command, "Command cannot be null"); @@ -48,4 +35,12 @@ public class CommandData { public boolean hasOpPerms() { return op; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CommandData that = (CommandData) o; + return Double.compare(that.delay, delay) == 0 && console == that.console && op == that.op && command.equals(that.command); + } } \ No newline at end of file diff --git a/src/main/java/net/Indyuce/mmoitems/stat/data/CommandListData.java b/src/main/java/net/Indyuce/mmoitems/stat/data/CommandListData.java index 5cd2d8e4..0bb8467b 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/data/CommandListData.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/data/CommandListData.java @@ -1,10 +1,7 @@ package net.Indyuce.mmoitems.stat.data; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; +import java.util.*; -import io.lumine.mythic.lib.api.util.ui.SilentNumbers; import org.apache.commons.lang.Validate; import net.Indyuce.mmoitems.api.item.build.MMOItemBuilder; @@ -14,47 +11,33 @@ import net.Indyuce.mmoitems.stat.data.type.StatData; import org.jetbrains.annotations.NotNull; public class CommandListData implements StatData, Mergeable, RandomStatData { - @NotNull private final Set commands; + @NotNull private final List commands; - public CommandListData(@NotNull Set commands) { + public CommandListData(@NotNull List commands) { this.commands = commands; } public CommandListData(CommandData... commands) { - this(new HashSet<>()); + this(new ArrayList<>()); add(commands); } public void add(CommandData... commands) { - this.commands.addAll(Arrays.asList(commands)); + for (CommandData data : commands) + this.commands.add(data); } - @NotNull public Set getCommands() { + @NotNull public List getCommands() { return commands; } @Override - public boolean equals(Object obj) { - if (!(obj instanceof CommandListData)) { return false; } - if (((CommandListData) obj).getCommands().size() != getCommands().size()) { return false; } - - for (CommandData objCommand : ((CommandListData) obj).getCommands()) { - - if (objCommand == null) { continue; } - - // Compare to mine - boolean unmatched = true; - for (CommandData thisCommand : getCommands()) { - - // Unequal? Fail - if (objCommand.equals(thisCommand)) { unmatched = false; break; } } - - if (unmatched) { return false; } - } - - // Success - return true; + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CommandListData that = (CommandListData) o; + return commands.equals(that.commands); } @Override @@ -73,6 +56,6 @@ public class CommandListData implements StatData, Mergeable, RandomStatData { @Override public StatData randomize(MMOItemBuilder builder) { - return new CommandListData(new HashSet<>(commands)); + return new CommandListData(new ArrayList<>(commands)); } } \ No newline at end of file