Skip to content

Commit

Permalink
specifically use immutable collections
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Jan 1, 2025
1 parent 4cf5f0a commit 5b8a7aa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package me.xginko.aef.commands.aef;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import me.xginko.aef.AnarchyExploitFixes;
import me.xginko.aef.commands.AEFCommand;
import me.xginko.aef.commands.SubCommand;
Expand All @@ -19,12 +21,13 @@
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class AEFCmd extends Command implements AEFCommand {

private final @NotNull List<SubCommand> subCommands;
private final @NotNull Set<SubCommand> subCommands;
private final @NotNull List<String> tabCompletes;
private final @NotNull List<Component> overview;

Expand All @@ -48,16 +51,17 @@ public AEFCmd() {
" <#00edff>/aef bytesize <mainhand/inventory> (player) (utf8/utf16)",
" <#869699>- <#e2fdff>Get the byte size of an item or inventory.",
""
).map(MiniMessage.miniMessage()::deserialize).toList();
this.subCommands = List.of(
).map(MiniMessage.miniMessage()::deserialize)
.collect(Collectors.collectingAndThen(Collectors.toList(), ImmutableList::copyOf));
this.subCommands = ImmutableSet.of(
new ReloadSubCmd(),
new VersionSubCmd(),
new DisableSubCmd(),
new LagSubCmd(),
new ElytraSubCmd(),
new GearedSubCmd()
);
this.tabCompletes = subCommands.stream().map(SubCommand::label).sorted().toList();
new GearedSubCmd());
this.tabCompletes = subCommands.stream().map(SubCommand::label).sorted()
.collect(Collectors.collectingAndThen(Collectors.toList(), ImmutableList::copyOf));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
package me.xginko.aef.commands.aef;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import me.xginko.aef.AnarchyExploitFixes;
import me.xginko.aef.commands.AEFCommand;
import me.xginko.aef.commands.SubCommand;
import me.xginko.aef.commands.aef.subcommands.DataValueSubCmd;
import me.xginko.aef.commands.aef.subcommands.DisableSubCmd;
import me.xginko.aef.commands.aef.subcommands.ElytraSubCmd;
import me.xginko.aef.commands.aef.subcommands.GearedSubCmd;
import me.xginko.aef.commands.aef.subcommands.LagSubCmd;
import me.xginko.aef.commands.aef.subcommands.ReloadSubCmd;
import me.xginko.aef.commands.aef.subcommands.VersionSubCmd;
import me.xginko.aef.commands.aef.subcommands.bytesize.ByteSizeSubCmd;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class AEFCmd extends Command implements AEFCommand {

private final List<SubCommand> subCommands;
private final List<String> tabCompletes;
private final List<String> overview;
private final Set<SubCommand> subCommands;
private final List<String> tabCompletes, overview;

public AEFCmd() {
super(
Expand All @@ -51,18 +50,17 @@ public AEFCmd() {
" &b/aef bytesize <mainhand/inventory> (player) (utf8/utf16)",
" &8- &fGet the byte size of an item or inventory.",
""
).map(line -> ChatColor.translateAlternateColorCodes('&', line)).collect(Collectors.toList());
this.subCommands = Arrays.asList(
).map(line -> ChatColor.translateAlternateColorCodes('&', line))
.collect(Collectors.collectingAndThen(Collectors.toList(), ImmutableList::copyOf));
this.subCommands = ImmutableSet.of(
new ReloadSubCmd(),
new VersionSubCmd(),
new DisableSubCmd(),
new LagSubCmd(),
new ElytraSubCmd(),
new GearedSubCmd(),
new DataValueSubCmd(),
new ByteSizeSubCmd()
);
this.tabCompletes = subCommands.stream().map(SubCommand::label).sorted().collect(Collectors.toList());
new GearedSubCmd());
this.tabCompletes = subCommands.stream().map(SubCommand::label).sorted()
.collect(Collectors.collectingAndThen(Collectors.toList(), ImmutableList::copyOf));
}

@Override
Expand Down

0 comments on commit 5b8a7aa

Please sign in to comment.