Skip to content

Commit

Permalink
[Commands] Reuse the same list of valid properties
Browse files Browse the repository at this point in the history
  • Loading branch information
NEZNAMY committed Nov 5, 2024
1 parent 380b3dd commit c3d2f9a
Showing 1 changed file with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package me.neznamy.tab.shared.command;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import me.neznamy.tab.shared.TabConstants;
import me.neznamy.tab.shared.config.PropertyConfiguration;
import me.neznamy.tab.shared.platform.TabPlayer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public abstract class PropertyCommand extends SubCommand {
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/** All properties assignable with a command */
private static final List<String> allProperties = Arrays.asList("tabprefix", "customtabname", "tabsuffix", "tagprefix", "tagsuffix");
public abstract class PropertyCommand extends SubCommand {

protected PropertyCommand(String name) {
super(name, null);
Expand All @@ -21,7 +19,7 @@ protected PropertyCommand(String name) {
@Override
public @NotNull List<String> complete(@Nullable TabPlayer sender, @NotNull String[] arguments) {
if (arguments.length != 2) return Collections.emptyList();
return getStartingArgument(allProperties, arguments[1]);
return getStartingArgument(PropertyConfiguration.VALID_PROPERTIES, arguments[1]);
}

protected void help(@Nullable TabPlayer sender) {
Expand All @@ -47,7 +45,7 @@ protected void trySaveEntity(@Nullable TabPlayer sender, @NotNull String[] args)
value = value.substring(1, value.length()-1);
}
String property = args[1].toLowerCase();
if (allProperties.contains(property)) {
if (PropertyConfiguration.VALID_PROPERTIES.contains(property)) {
if (hasPermission(sender, TabConstants.Permission.COMMAND_PROPERTY_CHANGE_PREFIX + property)) {
saveEntity(sender, args[0], property, value, server, world);
} else {
Expand Down

0 comments on commit c3d2f9a

Please sign in to comment.