Skip to content

Commit 5b8a7aa

Browse files
committed
specifically use immutable collections
1 parent 4cf5f0a commit 5b8a7aa

File tree

2 files changed

+21
-19
lines changed
  • AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/commands/aef
  • AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/commands/aef

2 files changed

+21
-19
lines changed

AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/commands/aef/AEFCmd.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package me.xginko.aef.commands.aef;
22

3+
import com.google.common.collect.ImmutableList;
4+
import com.google.common.collect.ImmutableSet;
35
import me.xginko.aef.AnarchyExploitFixes;
46
import me.xginko.aef.commands.AEFCommand;
57
import me.xginko.aef.commands.SubCommand;
@@ -19,12 +21,13 @@
1921
import java.util.Collections;
2022
import java.util.List;
2123
import java.util.Locale;
24+
import java.util.Set;
2225
import java.util.stream.Collectors;
2326
import java.util.stream.Stream;
2427

2528
public class AEFCmd extends Command implements AEFCommand {
2629

27-
private final @NotNull List<SubCommand> subCommands;
30+
private final @NotNull Set<SubCommand> subCommands;
2831
private final @NotNull List<String> tabCompletes;
2932
private final @NotNull List<Component> overview;
3033

@@ -48,16 +51,17 @@ public AEFCmd() {
4851
" <#00edff>/aef bytesize <mainhand/inventory> (player) (utf8/utf16)",
4952
" <#869699>- <#e2fdff>Get the byte size of an item or inventory.",
5053
""
51-
).map(MiniMessage.miniMessage()::deserialize).toList();
52-
this.subCommands = List.of(
54+
).map(MiniMessage.miniMessage()::deserialize)
55+
.collect(Collectors.collectingAndThen(Collectors.toList(), ImmutableList::copyOf));
56+
this.subCommands = ImmutableSet.of(
5357
new ReloadSubCmd(),
5458
new VersionSubCmd(),
5559
new DisableSubCmd(),
5660
new LagSubCmd(),
5761
new ElytraSubCmd(),
58-
new GearedSubCmd()
59-
);
60-
this.tabCompletes = subCommands.stream().map(SubCommand::label).sorted().toList();
62+
new GearedSubCmd());
63+
this.tabCompletes = subCommands.stream().map(SubCommand::label).sorted()
64+
.collect(Collectors.collectingAndThen(Collectors.toList(), ImmutableList::copyOf));
6165
}
6266

6367
@Override

AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/commands/aef/AEFCmd.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
11
package me.xginko.aef.commands.aef;
22

3+
import com.google.common.collect.ImmutableList;
4+
import com.google.common.collect.ImmutableSet;
35
import me.xginko.aef.AnarchyExploitFixes;
46
import me.xginko.aef.commands.AEFCommand;
57
import me.xginko.aef.commands.SubCommand;
6-
import me.xginko.aef.commands.aef.subcommands.DataValueSubCmd;
78
import me.xginko.aef.commands.aef.subcommands.DisableSubCmd;
89
import me.xginko.aef.commands.aef.subcommands.ElytraSubCmd;
910
import me.xginko.aef.commands.aef.subcommands.GearedSubCmd;
1011
import me.xginko.aef.commands.aef.subcommands.LagSubCmd;
1112
import me.xginko.aef.commands.aef.subcommands.ReloadSubCmd;
1213
import me.xginko.aef.commands.aef.subcommands.VersionSubCmd;
13-
import me.xginko.aef.commands.aef.subcommands.bytesize.ByteSizeSubCmd;
1414
import org.bukkit.ChatColor;
1515
import org.bukkit.command.Command;
1616
import org.bukkit.command.CommandException;
1717
import org.bukkit.command.CommandSender;
1818
import org.jetbrains.annotations.NotNull;
1919

20-
import java.util.Arrays;
2120
import java.util.Collections;
2221
import java.util.List;
2322
import java.util.Locale;
23+
import java.util.Set;
2424
import java.util.stream.Collectors;
2525
import java.util.stream.Stream;
2626

2727
public class AEFCmd extends Command implements AEFCommand {
2828

29-
private final List<SubCommand> subCommands;
30-
private final List<String> tabCompletes;
31-
private final List<String> overview;
29+
private final Set<SubCommand> subCommands;
30+
private final List<String> tabCompletes, overview;
3231

3332
public AEFCmd() {
3433
super(
@@ -51,18 +50,17 @@ public AEFCmd() {
5150
" &b/aef bytesize <mainhand/inventory> (player) (utf8/utf16)",
5251
" &8- &fGet the byte size of an item or inventory.",
5352
""
54-
).map(line -> ChatColor.translateAlternateColorCodes('&', line)).collect(Collectors.toList());
55-
this.subCommands = Arrays.asList(
53+
).map(line -> ChatColor.translateAlternateColorCodes('&', line))
54+
.collect(Collectors.collectingAndThen(Collectors.toList(), ImmutableList::copyOf));
55+
this.subCommands = ImmutableSet.of(
5656
new ReloadSubCmd(),
5757
new VersionSubCmd(),
5858
new DisableSubCmd(),
5959
new LagSubCmd(),
6060
new ElytraSubCmd(),
61-
new GearedSubCmd(),
62-
new DataValueSubCmd(),
63-
new ByteSizeSubCmd()
64-
);
65-
this.tabCompletes = subCommands.stream().map(SubCommand::label).sorted().collect(Collectors.toList());
61+
new GearedSubCmd());
62+
this.tabCompletes = subCommands.stream().map(SubCommand::label).sorted()
63+
.collect(Collectors.collectingAndThen(Collectors.toList(), ImmutableList::copyOf));
6664
}
6765

6866
@Override

0 commit comments

Comments
 (0)