Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-25 15:50:14 +01:00
Show teams in command suggestions
Dieser Commit ist enthalten in:
Ursprung
48d78720a1
Commit
af5d03f5dd
@ -37,6 +37,7 @@ import org.geysermc.geyser.entity.type.Entity;
|
||||
import org.geysermc.geyser.entity.type.player.PlayerEntity;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.geyser.text.GeyserLocale;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
@ -132,6 +133,10 @@ public final class Scoreboard {
|
||||
team = new Team(this, teamName);
|
||||
team.addEntities(players);
|
||||
teams.put(teamName, team);
|
||||
|
||||
// Update command parameters - is safe to send even if the command enum doesn't exist on the client (as of 1.19.51)
|
||||
session.addCommandEnum("Geyser_Teams", team.getId());
|
||||
|
||||
return team;
|
||||
}
|
||||
|
||||
@ -343,9 +348,16 @@ public final class Scoreboard {
|
||||
// We need to use the direct entities list here, so #refreshSessionPlayerDisplays also updates accordingly
|
||||
// With the player's lack of a team in visibility checks
|
||||
updateEntityNames(remove, remove.getEntities(), true);
|
||||
|
||||
session.removeCommandEnum("Geyser_Teams", remove.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Contract("-> new")
|
||||
public String[] getTeamNames() {
|
||||
return teams.keySet().toArray(new String[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the display names of all entities in a given team.
|
||||
* @param teamChange the players have either joined or left the team. Used for optimizations when just the display name updated.
|
||||
|
@ -67,7 +67,9 @@ import com.nukkitx.nbt.NbtMap;
|
||||
import com.nukkitx.protocol.bedrock.BedrockPacket;
|
||||
import com.nukkitx.protocol.bedrock.BedrockServerSession;
|
||||
import com.nukkitx.protocol.bedrock.data.*;
|
||||
import com.nukkitx.protocol.bedrock.data.command.CommandEnumData;
|
||||
import com.nukkitx.protocol.bedrock.data.command.CommandPermission;
|
||||
import com.nukkitx.protocol.bedrock.data.command.SoftEnumUpdateType;
|
||||
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
|
||||
import com.nukkitx.protocol.bedrock.packet.*;
|
||||
import io.netty.channel.Channel;
|
||||
@ -1895,4 +1897,19 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
||||
sendUpstreamPacket(transferPacket);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void addCommandEnum(String name, String... enums) {
|
||||
softEnumPacket(name, SoftEnumUpdateType.ADD, enums);
|
||||
}
|
||||
|
||||
public void removeCommandEnum(String name, String... enums) {
|
||||
softEnumPacket(name, SoftEnumUpdateType.REMOVE, enums);
|
||||
}
|
||||
|
||||
private void softEnumPacket(String name, SoftEnumUpdateType type, String... enums) {
|
||||
UpdateSoftEnumPacket packet = new UpdateSoftEnumPacket();
|
||||
packet.setType(type);
|
||||
packet.setSoftEnum(new CommandEnumData(name, enums, true));
|
||||
sendUpstreamPacket(packet);
|
||||
}
|
||||
}
|
||||
|
@ -240,6 +240,7 @@ public class JavaCommandsTranslator extends PacketTranslator<ClientboundCommands
|
||||
case RESOURCE -> handleResource(context, ((ResourceProperties) node.getProperties()).getRegistryKey(), false);
|
||||
case RESOURCE_OR_TAG -> handleResource(context, ((ResourceProperties) node.getProperties()).getRegistryKey(), true);
|
||||
case DIMENSION -> context.session.getLevels();
|
||||
case TEAM -> context.getTeams(); // Note: as of Java 1.19.3, objectives are currently parsed from the server
|
||||
default -> CommandParam.STRING;
|
||||
};
|
||||
}
|
||||
@ -271,6 +272,7 @@ public class JavaCommandsTranslator extends PacketTranslator<ClientboundCommands
|
||||
private Object biomesNoTags;
|
||||
private String[] blockStates;
|
||||
private String[] entityTypes;
|
||||
private CommandEnumData teams;
|
||||
|
||||
CommandBuilderContext(GeyserSession session) {
|
||||
this.session = session;
|
||||
@ -307,6 +309,14 @@ public class JavaCommandsTranslator extends PacketTranslator<ClientboundCommands
|
||||
}
|
||||
return (entityTypes = Registries.JAVA_ENTITY_IDENTIFIERS.get().keySet().toArray(new String[0]));
|
||||
}
|
||||
|
||||
private CommandEnumData getTeams() {
|
||||
if (teams != null) {
|
||||
return teams;
|
||||
}
|
||||
return (teams = new CommandEnumData("Geyser_Teams",
|
||||
session.getWorldCache().getScoreboard().getTeamNames(), true));
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
@ -376,7 +386,10 @@ public class JavaCommandsTranslator extends PacketTranslator<ClientboundCommands
|
||||
CommandEnumData enumData = null;
|
||||
CommandParam type = null;
|
||||
boolean optional = this.paramNode.isExecutable();
|
||||
if (mappedType instanceof String[]) {
|
||||
if (mappedType instanceof CommandEnumData) {
|
||||
// Likely to specify isSoft, to be possibly updated later.
|
||||
enumData = (CommandEnumData) mappedType;
|
||||
} else if (mappedType instanceof String[]) {
|
||||
enumData = new CommandEnumData(getEnumDataName(paramNode).toLowerCase(Locale.ROOT), (String[]) mappedType, false);
|
||||
} else {
|
||||
type = (CommandParam) mappedType;
|
||||
|
@ -5,7 +5,7 @@ netty = "4.1.80.Final"
|
||||
guava = "29.0-jre"
|
||||
gson = "2.3.1" # Provided by Spigot 1.8.8
|
||||
websocket = "1.5.1"
|
||||
protocol = "2.9.15-20221129.204554-2"
|
||||
protocol = "2.9.15-20230106.005737-3"
|
||||
raknet = "1.6.28-20220125.214016-6"
|
||||
mcauthlib = "d9d773e"
|
||||
mcprotocollib = "1.19.3-20230107.194116-10"
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren