mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-02 17:00:41 +01:00
Fix section resize performance
This commit is contained in:
parent
41d61e7df6
commit
5e385c7c9b
@ -8,13 +8,16 @@ import net.minestom.server.command.builder.arguments.ArgumentDynamicWord;
|
||||
import net.minestom.server.command.builder.arguments.ArgumentType;
|
||||
import net.minestom.server.command.builder.arguments.minecraft.SuggestionType;
|
||||
import net.minestom.server.command.builder.condition.CommandCondition;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Represents a command which has suggestion/auto-completion.
|
||||
@ -42,6 +45,7 @@ public class Command {
|
||||
|
||||
private final String name;
|
||||
private final String[] aliases;
|
||||
private final String[] names;
|
||||
|
||||
private CommandExecutor defaultExecutor;
|
||||
private CommandCondition condition;
|
||||
@ -59,6 +63,7 @@ public class Command {
|
||||
public Command(@NotNull String name, @Nullable String... aliases) {
|
||||
this.name = name;
|
||||
this.aliases = aliases;
|
||||
this.names = Stream.concat(Arrays.stream(aliases), Stream.of(name)).toArray(String[]::new);
|
||||
|
||||
this.subcommands = new ArrayList<>();
|
||||
this.syntaxes = new ArrayList<>();
|
||||
@ -223,8 +228,7 @@ public class Command {
|
||||
*
|
||||
* @return the main command's name
|
||||
*/
|
||||
@NotNull
|
||||
public String getName() {
|
||||
public @NotNull String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@ -233,11 +237,21 @@ public class Command {
|
||||
*
|
||||
* @return the command aliases, can be null or empty
|
||||
*/
|
||||
@Nullable
|
||||
public String[] getAliases() {
|
||||
public @Nullable String[] getAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the possible names for this command.
|
||||
* <p>
|
||||
* Include {@link #getName()} and {@link #getAliases()}.
|
||||
*
|
||||
* @return this command names
|
||||
*/
|
||||
public @NotNull String[] getNames() {
|
||||
return names;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default {@link CommandExecutor} which is called when there is no argument
|
||||
* or if no corresponding syntax has been found.
|
||||
@ -266,8 +280,7 @@ public class Command {
|
||||
* @return a collection containing all this command syntaxes
|
||||
* @see #addSyntax(CommandExecutor, Argument[])
|
||||
*/
|
||||
@NotNull
|
||||
public Collection<CommandSyntax> getSyntaxes() {
|
||||
public @NotNull Collection<CommandSyntax> getSyntaxes() {
|
||||
return syntaxes;
|
||||
}
|
||||
|
||||
@ -280,8 +293,7 @@ public class Command {
|
||||
* @param text the whole player's text
|
||||
* @return the array containing all the suggestion for the current arg (split SPACE), can be null
|
||||
*/
|
||||
@Nullable
|
||||
public String[] onDynamicWrite(@NotNull CommandSender sender, @NotNull String text) {
|
||||
public @Nullable String[] onDynamicWrite(@NotNull CommandSender sender, @NotNull String text) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -300,15 +312,29 @@ public class Command {
|
||||
public void globalListener(@NotNull CommandSender sender, @NotNull CommandContext context, @NotNull String command) {
|
||||
}
|
||||
|
||||
@Beta
|
||||
public @NotNull Set<String> getSyntaxesStrings() {
|
||||
Set<String> syntaxes = new HashSet<>();
|
||||
|
||||
Consumer<String> syntaxConsumer = syntaxString -> {
|
||||
for (String name : getNames()) {
|
||||
final String syntax = name + StringUtils.SPACE + syntaxString;
|
||||
syntaxes.add(syntax);
|
||||
}
|
||||
};
|
||||
|
||||
this.subcommands.forEach(subcommand -> subcommand.getSyntaxesStrings().forEach(syntaxConsumer));
|
||||
|
||||
this.syntaxes.forEach(commandSyntax -> syntaxConsumer.accept(commandSyntax.getSyntaxString()));
|
||||
|
||||
return syntaxes;
|
||||
}
|
||||
|
||||
public static boolean isValidName(@NotNull Command command, @NotNull String name) {
|
||||
if (command.getName().equals(name))
|
||||
return true;
|
||||
final String[] aliases = command.getAliases();
|
||||
if (aliases == null)
|
||||
return false;
|
||||
for (String alias : aliases) {
|
||||
if (alias.equals(name))
|
||||
for (String commandName : command.getNames()) {
|
||||
if (commandName.equals(name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ public class Section implements PublicCloneable<Section> {
|
||||
section.paletteBlockMap = paletteBlockMap;
|
||||
section.blockPaletteMap = blockPaletteMap;
|
||||
|
||||
for (int y = 0; y < Chunk.CHUNK_SIZE_Y; y++) {
|
||||
for (int y = 0; y < Chunk.CHUNK_SECTION_SIZE; y++) {
|
||||
for (int x = 0; x < Chunk.CHUNK_SIZE_X; x++) {
|
||||
for (int z = 0; z < Chunk.CHUNK_SIZE_Z; z++) {
|
||||
final short blockId = getBlockAt(x, y, z);
|
||||
|
Loading…
Reference in New Issue
Block a user