Some command framework cleanup

Most notably, remove the synchronization on the commands map, which is unnecessary since it is not modified after startup.
This commit is contained in:
Camotoy 2021-11-29 10:31:31 -05:00
parent af8c26a4a5
commit 2ae34b69af
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
4 changed files with 14 additions and 10 deletions

View file

@ -80,8 +80,8 @@ public class CommandExecutor {
Map<String, GeyserCommand> commands = geyser.getCommandManager().getCommands();
// Only show commands they have permission to use
for (String name : commands.keySet()) {
GeyserCommand geyserCommand = commands.get(name);
for (Map.Entry<String, GeyserCommand> entry : commands.entrySet()) {
GeyserCommand geyserCommand = entry.getValue();
if (sender.hasPermission(geyserCommand.getPermission())) {
if (geyserCommand.isBedrockOnly()) {
@ -89,7 +89,7 @@ public class CommandExecutor {
continue;
}
availableCommands.add(name);
availableCommands.add(entry.getKey());
}
}

View file

@ -38,7 +38,7 @@ import java.util.*;
public abstract class CommandManager {
@Getter
private final Map<String, GeyserCommand> commands = Collections.synchronizedMap(new HashMap<>());
private final Map<String, GeyserCommand> commands = new HashMap<>();
private final GeyserImpl geyser;

View file

@ -25,6 +25,7 @@
package org.geysermc.geyser.command.defaults;
import org.geysermc.common.PlatformType;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.CommandSender;
import org.geysermc.geyser.command.GeyserCommand;
@ -60,16 +61,17 @@ public class HelpCommand extends GeyserCommand {
sender.sendMessage(header);
Map<String, GeyserCommand> cmds = geyser.getCommandManager().getCommands();
for (String cmdName : cmds.keySet()) {
GeyserCommand cmd = cmds.get(cmdName);
for (Map.Entry<String, GeyserCommand> entry : cmds.entrySet()) {
GeyserCommand cmd = entry.getValue();
if (sender.hasPermission(cmd.getPermission())) {
// Standalone hack-in since it doesn't have a concept of permissions
if (geyser.getPlatformType() == PlatformType.STANDALONE || sender.hasPermission(cmd.getPermission())) {
// Only list commands the player can actually run
if (cmd.isBedrockOnly() && session == null) {
continue;
}
sender.sendMessage(ChatColor.YELLOW + "/geyser " + cmdName + ChatColor.WHITE + ": " +
sender.sendMessage(ChatColor.YELLOW + "/geyser " + entry.getKey() + ChatColor.WHITE + ": " +
GeyserLocale.getPlayerLocaleString(cmd.getDescription(), sender.getLocale()));
}
}

View file

@ -37,6 +37,8 @@ import org.geysermc.geyser.session.cache.ChunkCache;
import org.geysermc.geyser.translator.inventory.LecternInventoryTranslator;
import org.geysermc.geyser.level.block.BlockStateValues;
import java.util.Locale;
public class GeyserWorldManager extends WorldManager {
private static final Object2ObjectMap<String, String> gameruleCache = new Object2ObjectOpenHashMap<>();
@ -107,12 +109,12 @@ public class GeyserWorldManager extends WorldManager {
@Override
public void setPlayerGameMode(GeyserSession session, GameMode gameMode) {
session.sendDownstreamPacket(new ServerboundChatPacket("/gamemode " + gameMode.name().toLowerCase()));
session.sendDownstreamPacket(new ServerboundChatPacket("/gamemode " + gameMode.name().toLowerCase(Locale.ROOT)));
}
@Override
public void setDifficulty(GeyserSession session, Difficulty difficulty) {
session.sendDownstreamPacket(new ServerboundChatPacket("/difficulty " + difficulty.name().toLowerCase()));
session.sendDownstreamPacket(new ServerboundChatPacket("/difficulty " + difficulty.name().toLowerCase(Locale.ROOT)));
}
@Override