Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-26 00:00:41 +01:00
Update to 1.19.3-rc1; various changes and fixes
Dieser Commit ist enthalten in:
Ursprung
309f9737bb
Commit
cc3037d6c5
@ -38,7 +38,7 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.inventory.meta.BookMeta;
|
import org.bukkit.inventory.meta.BookMeta;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.geysermc.geyser.level.GameRule;
|
import org.geysermc.geyser.level.GameRule;
|
||||||
import org.geysermc.geyser.level.GeyserWorldManager;
|
import org.geysermc.geyser.level.WorldManager;
|
||||||
import org.geysermc.geyser.level.block.BlockStateValues;
|
import org.geysermc.geyser.level.block.BlockStateValues;
|
||||||
import org.geysermc.geyser.registry.BlockRegistries;
|
import org.geysermc.geyser.registry.BlockRegistries;
|
||||||
import org.geysermc.geyser.session.GeyserSession;
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
@ -51,7 +51,7 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* The base world manager to use when there is no supported NMS revision
|
* The base world manager to use when there is no supported NMS revision
|
||||||
*/
|
*/
|
||||||
public class GeyserSpigotWorldManager extends GeyserWorldManager {
|
public class GeyserSpigotWorldManager extends WorldManager {
|
||||||
private final Plugin plugin;
|
private final Plugin plugin;
|
||||||
|
|
||||||
public GeyserSpigotWorldManager(Plugin plugin) {
|
public GeyserSpigotWorldManager(Plugin plugin) {
|
||||||
@ -151,12 +151,12 @@ public class GeyserSpigotWorldManager extends GeyserWorldManager {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean getGameRuleBool(GeyserSession session, GameRule gameRule) {
|
public boolean getGameRuleBool(GeyserSession session, GameRule gameRule) {
|
||||||
String value = Bukkit.getPlayer(session.getPlayerEntity().getUsername()).getWorld().getGameRuleValue(gameRule.getJavaID());
|
String value = Bukkit.getPlayer(session.getPlayerEntity().getUsername()).getWorld().getGameRuleValue(gameRule.getJavaID());
|
||||||
if (!value.isEmpty()) {
|
if (!value.isEmpty()) {
|
||||||
return Boolean.parseBoolean(value);
|
return Boolean.parseBoolean(value);
|
||||||
}
|
}
|
||||||
return (Boolean) gameRule.getDefaultValue();
|
return gameRule.getDefaultBooleanValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -165,7 +165,7 @@ public class GeyserSpigotWorldManager extends GeyserWorldManager {
|
|||||||
if (!value.isEmpty()) {
|
if (!value.isEmpty()) {
|
||||||
return Integer.parseInt(value);
|
return Integer.parseInt(value);
|
||||||
}
|
}
|
||||||
return (int) gameRule.getDefaultValue();
|
return gameRule.getDefaultIntValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -32,43 +32,41 @@ import lombok.Getter;
|
|||||||
* It is used to construct the list for the settings menu
|
* It is used to construct the list for the settings menu
|
||||||
*/
|
*/
|
||||||
public enum GameRule {
|
public enum GameRule {
|
||||||
ANNOUNCEADVANCEMENTS("announceAdvancements", Boolean.class, true), // JE only
|
ANNOUNCEADVANCEMENTS("announceAdvancements", true), // JE only
|
||||||
COMMANDBLOCKOUTPUT("commandBlockOutput", Boolean.class, true),
|
COMMANDBLOCKOUTPUT("commandBlockOutput", true),
|
||||||
DISABLEELYTRAMOVEMENTCHECK("disableElytraMovementCheck", Boolean.class, false), // JE only
|
DISABLEELYTRAMOVEMENTCHECK("disableElytraMovementCheck", false), // JE only
|
||||||
DISABLERAIDS("disableRaids", Boolean.class, false), // JE only
|
DISABLERAIDS("disableRaids", false), // JE only
|
||||||
DODAYLIGHTCYCLE("doDaylightCycle", Boolean.class, true),
|
DODAYLIGHTCYCLE("doDaylightCycle", true),
|
||||||
DOENTITYDROPS("doEntityDrops", Boolean.class, true),
|
DOENTITYDROPS("doEntityDrops", true),
|
||||||
DOFIRETICK("doFireTick", Boolean.class, true),
|
DOFIRETICK("doFireTick", true),
|
||||||
DOIMMEDIATERESPAWN("doImmediateRespawn", Boolean.class, false),
|
DOIMMEDIATERESPAWN("doImmediateRespawn", false),
|
||||||
DOINSOMNIA("doInsomnia", Boolean.class, true),
|
DOINSOMNIA("doInsomnia", true),
|
||||||
DOLIMITEDCRAFTING("doLimitedCrafting", Boolean.class, false), // JE only
|
DOLIMITEDCRAFTING("doLimitedCrafting", false), // JE only
|
||||||
DOMOBLOOT("doMobLoot", Boolean.class, true),
|
DOMOBLOOT("doMobLoot", true),
|
||||||
DOMOBSPAWNING("doMobSpawning", Boolean.class, true),
|
DOMOBSPAWNING("doMobSpawning", true),
|
||||||
DOPATROLSPAWNING("doPatrolSpawning", Boolean.class, true), // JE only
|
DOPATROLSPAWNING("doPatrolSpawning", true), // JE only
|
||||||
DOTILEDROPS("doTileDrops", Boolean.class, true),
|
DOTILEDROPS("doTileDrops", true),
|
||||||
DOTRADERSPAWNING("doTraderSpawning", Boolean.class, true), // JE only
|
DOTRADERSPAWNING("doTraderSpawning", true), // JE only
|
||||||
DOWEATHERCYCLE("doWeatherCycle", Boolean.class, true),
|
DOWEATHERCYCLE("doWeatherCycle", true),
|
||||||
DROWNINGDAMAGE("drowningDamage", Boolean.class, true),
|
DROWNINGDAMAGE("drowningDamage", true),
|
||||||
FALLDAMAGE("fallDamage", Boolean.class, true),
|
FALLDAMAGE("fallDamage", true),
|
||||||
FIREDAMAGE("fireDamage", Boolean.class, true),
|
FIREDAMAGE("fireDamage", true),
|
||||||
FREEZEDAMAGE("freezeDamage", Boolean.class, true),
|
FREEZEDAMAGE("freezeDamage", true),
|
||||||
FORGIVEDEADPLAYERS("forgiveDeadPlayers", Boolean.class, true), // JE only
|
FORGIVEDEADPLAYERS("forgiveDeadPlayers", true), // JE only
|
||||||
KEEPINVENTORY("keepInventory", Boolean.class, false),
|
KEEPINVENTORY("keepInventory", false),
|
||||||
LOGADMINCOMMANDS("logAdminCommands", Boolean.class, true), // JE only
|
LOGADMINCOMMANDS("logAdminCommands", true), // JE only
|
||||||
MAXCOMMANDCHAINLENGTH("maxCommandChainLength", Integer.class, 65536),
|
MAXCOMMANDCHAINLENGTH("maxCommandChainLength", 65536),
|
||||||
MAXENTITYCRAMMING("maxEntityCramming", Integer.class, 24), // JE only
|
MAXENTITYCRAMMING("maxEntityCramming", 24), // JE only
|
||||||
MOBGRIEFING("mobGriefing", Boolean.class, true),
|
MOBGRIEFING("mobGriefing", true),
|
||||||
NATURALREGENERATION("naturalRegeneration", Boolean.class, true),
|
NATURALREGENERATION("naturalRegeneration", true),
|
||||||
PLAYERSSLEEPINGPERCENTAGE("playersSleepingPercentage", Integer.class, 100), // JE only
|
PLAYERSSLEEPINGPERCENTAGE("playersSleepingPercentage", 100), // JE only
|
||||||
RANDOMTICKSPEED("randomTickSpeed", Integer.class, 3),
|
RANDOMTICKSPEED("randomTickSpeed", 3),
|
||||||
REDUCEDDEBUGINFO("reducedDebugInfo", Boolean.class, false), // JE only
|
REDUCEDDEBUGINFO("reducedDebugInfo", false), // JE only
|
||||||
SENDCOMMANDFEEDBACK("sendCommandFeedback", Boolean.class, true),
|
SENDCOMMANDFEEDBACK("sendCommandFeedback", true),
|
||||||
SHOWDEATHMESSAGES("showDeathMessages", Boolean.class, true),
|
SHOWDEATHMESSAGES("showDeathMessages", true),
|
||||||
SPAWNRADIUS("spawnRadius", Integer.class, 10),
|
SPAWNRADIUS("spawnRadius", 10),
|
||||||
SPECTATORSGENERATECHUNKS("spectatorsGenerateChunks", Boolean.class, true), // JE only
|
SPECTATORSGENERATECHUNKS("spectatorsGenerateChunks", true), // JE only
|
||||||
UNIVERSALANGER("universalAnger", Boolean.class, false), // JE only
|
UNIVERSALANGER("universalAnger", false); // JE only
|
||||||
|
|
||||||
UNKNOWN("unknown", Object.class);
|
|
||||||
|
|
||||||
public static final GameRule[] VALUES = values();
|
public static final GameRule[] VALUES = values();
|
||||||
|
|
||||||
@ -78,48 +76,25 @@ public enum GameRule {
|
|||||||
@Getter
|
@Getter
|
||||||
private final Class<?> type;
|
private final Class<?> type;
|
||||||
|
|
||||||
@Getter
|
private final int defaultValue;
|
||||||
private final Object defaultValue;
|
|
||||||
|
|
||||||
GameRule(String javaID, Class<?> type) {
|
GameRule(String javaID, boolean defaultValue) {
|
||||||
this(javaID, type, null);
|
this.javaID = javaID;
|
||||||
|
this.type = Boolean.class;
|
||||||
|
this.defaultValue = defaultValue ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GameRule(String javaID, Class<?> type, Object defaultValue) {
|
GameRule(String javaID, int defaultValue) {
|
||||||
this.javaID = javaID;
|
this.javaID = javaID;
|
||||||
this.type = type;
|
this.type = Integer.class;
|
||||||
this.defaultValue = defaultValue;
|
this.defaultValue = defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public boolean getDefaultBooleanValue() {
|
||||||
* Convert a string to an object of the correct type for the current gamerule
|
return defaultValue != 0;
|
||||||
*
|
|
||||||
* @param value The string value to convert
|
|
||||||
* @return The converted and formatted value
|
|
||||||
*/
|
|
||||||
public Object convertValue(String value) {
|
|
||||||
if (type.equals(Boolean.class)) {
|
|
||||||
return Boolean.parseBoolean(value);
|
|
||||||
} else if (type.equals(Integer.class)) {
|
|
||||||
return Integer.parseInt(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public int getDefaultIntValue() {
|
||||||
* Fetch a game rule by the given Java ID
|
return defaultValue;
|
||||||
*
|
|
||||||
* @param id The ID of the gamerule
|
|
||||||
* @return A {@link GameRule} object representing the requested ID or {@link GameRule#UNKNOWN}
|
|
||||||
*/
|
|
||||||
public static GameRule fromJavaID(String id) {
|
|
||||||
for (GameRule gamerule : VALUES) {
|
|
||||||
if (gamerule.javaID.equals(id)) {
|
|
||||||
return gamerule;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return UNKNOWN;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
|
|
||||||
package org.geysermc.geyser.level;
|
package org.geysermc.geyser.level;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.setting.Difficulty;
|
|
||||||
import com.nukkitx.nbt.NbtMap;
|
import com.nukkitx.nbt.NbtMap;
|
||||||
import com.nukkitx.nbt.NbtMapBuilder;
|
import com.nukkitx.nbt.NbtMapBuilder;
|
||||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||||
@ -36,11 +34,8 @@ import org.geysermc.geyser.session.GeyserSession;
|
|||||||
import org.geysermc.geyser.session.cache.ChunkCache;
|
import org.geysermc.geyser.session.cache.ChunkCache;
|
||||||
import org.geysermc.geyser.translator.inventory.LecternInventoryTranslator;
|
import org.geysermc.geyser.translator.inventory.LecternInventoryTranslator;
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
public class GeyserWorldManager extends WorldManager {
|
public class GeyserWorldManager extends WorldManager {
|
||||||
|
private final Object2ObjectMap<String, String> gameruleCache = new Object2ObjectOpenHashMap<>();
|
||||||
private static final Object2ObjectMap<String, String> gameruleCache = new Object2ObjectOpenHashMap<>();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBlockAt(GeyserSession session, int x, int y, int z) {
|
public int getBlockAt(GeyserSession session, int x, int y, int z) {
|
||||||
@ -82,18 +77,18 @@ public class GeyserWorldManager extends WorldManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setGameRule(GeyserSession session, String name, Object value) {
|
public void setGameRule(GeyserSession session, String name, Object value) {
|
||||||
session.sendCommand("gamerule " + name + " " + value);
|
super.setGameRule(session, name, value);
|
||||||
gameruleCache.put(name, String.valueOf(value));
|
gameruleCache.put(name, String.valueOf(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean getGameRuleBool(GeyserSession session, GameRule gameRule) {
|
public boolean getGameRuleBool(GeyserSession session, GameRule gameRule) {
|
||||||
String value = gameruleCache.get(gameRule.getJavaID());
|
String value = gameruleCache.get(gameRule.getJavaID());
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
return Boolean.parseBoolean(value);
|
return Boolean.parseBoolean(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return gameRule.getDefaultValue() != null ? (Boolean) gameRule.getDefaultValue() : false;
|
return gameRule.getDefaultBooleanValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -103,17 +98,7 @@ public class GeyserWorldManager extends WorldManager {
|
|||||||
return Integer.parseInt(value);
|
return Integer.parseInt(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return gameRule.getDefaultValue() != null ? (int) gameRule.getDefaultValue() : 0;
|
return gameRule.getDefaultIntValue();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setPlayerGameMode(GeyserSession session, GameMode gameMode) {
|
|
||||||
session.sendCommand("gamemode " + gameMode.name().toLowerCase(Locale.ROOT));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setDifficulty(GeyserSession session, Difficulty difficulty) {
|
|
||||||
session.sendCommand("difficulty " + difficulty.name().toLowerCase(Locale.ROOT));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -31,6 +31,8 @@ import com.nukkitx.math.vector.Vector3i;
|
|||||||
import com.nukkitx.nbt.NbtMap;
|
import com.nukkitx.nbt.NbtMap;
|
||||||
import org.geysermc.geyser.session.GeyserSession;
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that manages or retrieves various information
|
* Class that manages or retrieves various information
|
||||||
* from the world. Everything in this class should be
|
* from the world. Everything in this class should be
|
||||||
@ -105,7 +107,9 @@ public abstract class WorldManager {
|
|||||||
* @param name The gamerule to change
|
* @param name The gamerule to change
|
||||||
* @param value The new value for the gamerule
|
* @param value The new value for the gamerule
|
||||||
*/
|
*/
|
||||||
public abstract void setGameRule(GeyserSession session, String name, Object value);
|
public void setGameRule(GeyserSession session, String name, Object value) {
|
||||||
|
session.sendCommand("gamerule " + name + " " + value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a gamerule value as a boolean
|
* Gets a gamerule value as a boolean
|
||||||
@ -114,7 +118,7 @@ public abstract class WorldManager {
|
|||||||
* @param gameRule The gamerule to fetch the value of
|
* @param gameRule The gamerule to fetch the value of
|
||||||
* @return The boolean representation of the value
|
* @return The boolean representation of the value
|
||||||
*/
|
*/
|
||||||
public abstract Boolean getGameRuleBool(GeyserSession session, GameRule gameRule);
|
public abstract boolean getGameRuleBool(GeyserSession session, GameRule gameRule);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a gamerule value as an integer
|
* Get a gamerule value as an integer
|
||||||
@ -131,7 +135,9 @@ public abstract class WorldManager {
|
|||||||
* @param session The session of the player to change the game mode of
|
* @param session The session of the player to change the game mode of
|
||||||
* @param gameMode The game mode to change the player to
|
* @param gameMode The game mode to change the player to
|
||||||
*/
|
*/
|
||||||
public abstract void setPlayerGameMode(GeyserSession session, GameMode gameMode);
|
public void setPlayerGameMode(GeyserSession session, GameMode gameMode) {
|
||||||
|
session.sendCommand("gamemode " + gameMode.name().toLowerCase(Locale.ROOT));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change the difficulty of the Java server
|
* Change the difficulty of the Java server
|
||||||
@ -139,7 +145,9 @@ public abstract class WorldManager {
|
|||||||
* @param session The session of the user that requested the change
|
* @param session The session of the user that requested the change
|
||||||
* @param difficulty The difficulty to change to
|
* @param difficulty The difficulty to change to
|
||||||
*/
|
*/
|
||||||
public abstract void setDifficulty(GeyserSession session, Difficulty difficulty);
|
public void setDifficulty(GeyserSession session, Difficulty difficulty) {
|
||||||
|
session.sendCommand("difficulty " + difficulty.name().toLowerCase(Locale.ROOT));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the given session's player has a permission
|
* Checks if the given session's player has a permission
|
||||||
|
@ -234,18 +234,18 @@ public class JavaCommandsTranslator extends PacketTranslator<ClientboundCommands
|
|||||||
case OPERATION -> CommandParam.OPERATOR; // ">=", "==", etc
|
case OPERATION -> CommandParam.OPERATOR; // ">=", "==", etc
|
||||||
case BLOCK_STATE -> BlockRegistries.JAVA_TO_BEDROCK_IDENTIFIERS.get().keySet().toArray(new String[0]);
|
case BLOCK_STATE -> BlockRegistries.JAVA_TO_BEDROCK_IDENTIFIERS.get().keySet().toArray(new String[0]);
|
||||||
case ITEM_STACK -> session.getItemMappings().getItemNames();
|
case ITEM_STACK -> session.getItemMappings().getItemNames();
|
||||||
case ITEM_ENCHANTMENT -> Enchantment.JavaEnchantment.ALL_JAVA_IDENTIFIERS;
|
|
||||||
case ENTITY_SUMMON -> Registries.JAVA_ENTITY_IDENTIFIERS.get().keySet().toArray(new String[0]);
|
|
||||||
case COLOR -> VALID_COLORS;
|
case COLOR -> VALID_COLORS;
|
||||||
case SCOREBOARD_SLOT -> VALID_SCOREBOARD_SLOTS;
|
case SCOREBOARD_SLOT -> VALID_SCOREBOARD_SLOTS;
|
||||||
case MOB_EFFECT -> ALL_EFFECT_IDENTIFIERS;
|
|
||||||
case RESOURCE, RESOURCE_OR_TAG -> {
|
case RESOURCE, RESOURCE_OR_TAG -> {
|
||||||
String resource = ((ResourceProperties) node.getProperties()).getRegistryKey();
|
String resource = ((ResourceProperties) node.getProperties()).getRegistryKey();
|
||||||
if (resource.equals("minecraft:attribute")) {
|
yield switch (resource) {
|
||||||
yield ATTRIBUTES;
|
// minecraft:worldgen/biome is also valid but we currently don't cache biome IDs
|
||||||
} else {
|
case "minecraft:attribute" -> ATTRIBUTES;
|
||||||
yield CommandParam.STRING;
|
case "minecraft:enchantment" -> Enchantment.JavaEnchantment.ALL_JAVA_IDENTIFIERS;
|
||||||
}
|
case "minecraft:entity_type" -> Registries.JAVA_ENTITY_IDENTIFIERS.get().keySet().toArray(new String[0]);
|
||||||
|
case "minecraft:mob_effect" -> ALL_EFFECT_IDENTIFIERS;
|
||||||
|
default -> CommandParam.STRING;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
default -> CommandParam.STRING;
|
default -> CommandParam.STRING;
|
||||||
};
|
};
|
||||||
@ -325,7 +325,7 @@ public class JavaCommandsTranslator extends PacketTranslator<ClientboundCommands
|
|||||||
CommandParam type = null;
|
CommandParam type = null;
|
||||||
boolean optional = this.paramNode.isExecutable();
|
boolean optional = this.paramNode.isExecutable();
|
||||||
if (mappedType instanceof String[]) {
|
if (mappedType instanceof String[]) {
|
||||||
enumData = new CommandEnumData(paramNode.getParser().name().toLowerCase(Locale.ROOT), (String[]) mappedType, false);
|
enumData = new CommandEnumData(getEnumDataName(paramNode).toLowerCase(Locale.ROOT), (String[]) mappedType, false);
|
||||||
} else {
|
} else {
|
||||||
type = (CommandParam) mappedType;
|
type = (CommandParam) mappedType;
|
||||||
// Bedrock throws a fit if an optional message comes after a string or target
|
// Bedrock throws a fit if an optional message comes after a string or target
|
||||||
@ -347,6 +347,21 @@ public class JavaCommandsTranslator extends PacketTranslator<ClientboundCommands
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mitigates https://github.com/GeyserMC/Geyser/issues/3411. Not a perfect solution.
|
||||||
|
*/
|
||||||
|
private static String getEnumDataName(CommandNode node) {
|
||||||
|
if (node.getProperties() instanceof ResourceProperties properties) {
|
||||||
|
String registryKey = properties.getRegistryKey();
|
||||||
|
int identifierSplit = registryKey.indexOf(':');
|
||||||
|
if (identifierSplit != -1) {
|
||||||
|
return registryKey.substring(identifierSplit);
|
||||||
|
}
|
||||||
|
return registryKey;
|
||||||
|
}
|
||||||
|
return node.getParser().name();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comparing CommandNode type a and b, determine if they are in the same overload.
|
* Comparing CommandNode type a and b, determine if they are in the same overload.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -40,6 +40,6 @@ public class JavaSoundEntityTranslator extends PacketTranslator<ClientboundSound
|
|||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SoundUtils.playBuiltinSound(session, packet.getSound(), entity.getPosition(), packet.getVolume(), packet.getPitch());
|
SoundUtils.playSound(session, packet.getSound(), entity.getPosition(), packet.getVolume(), packet.getPitch());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,8 +58,6 @@ public class JavaPlayerInfoRemoveTranslator extends PacketTranslator<Clientbound
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!translate.getEntries().isEmpty()) {
|
session.sendUpstreamPacket(translate);
|
||||||
session.sendUpstreamPacket(translate);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,28 +50,23 @@ public class JavaPlayerInfoUpdateTranslator extends PacketTranslator<Clientbound
|
|||||||
translate.setAction(PlayerListPacket.Action.ADD);
|
translate.setAction(PlayerListPacket.Action.ADD);
|
||||||
|
|
||||||
for (PlayerListEntry entry : packet.getEntries()) {
|
for (PlayerListEntry entry : packet.getEntries()) {
|
||||||
for (PlayerListEntryAction action : packet.getActions()) {
|
GameProfile profile = entry.getProfile();
|
||||||
if (action != PlayerListEntryAction.ADD_PLAYER) {
|
PlayerEntity playerEntity;
|
||||||
continue;
|
boolean self = profile.getId().equals(session.getPlayerEntity().getUuid());
|
||||||
}
|
|
||||||
|
|
||||||
GameProfile profile = entry.getProfile();
|
if (self) {
|
||||||
PlayerEntity playerEntity;
|
// Entity is ourself
|
||||||
boolean self = profile.getId().equals(session.getPlayerEntity().getUuid());
|
playerEntity = session.getPlayerEntity();
|
||||||
|
} else {
|
||||||
|
playerEntity = session.getEntityCache().getPlayerEntity(profile.getId());
|
||||||
|
}
|
||||||
|
|
||||||
if (self) {
|
GameProfile.Property textures = profile.getProperty("textures");
|
||||||
// Entity is ourself
|
String texturesProperty = textures == null ? null : textures.getValue();
|
||||||
playerEntity = session.getPlayerEntity();
|
|
||||||
} else {
|
|
||||||
playerEntity = session.getEntityCache().getPlayerEntity(profile.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
GameProfile.Property textures = profile.getProperty("textures");
|
if (playerEntity == null) {
|
||||||
String texturesProperty = textures == null ? null : textures.getValue();
|
// It's a new player
|
||||||
|
playerEntity = new PlayerEntity(
|
||||||
if (playerEntity == null) {
|
|
||||||
// It's a new player
|
|
||||||
playerEntity = new PlayerEntity(
|
|
||||||
session,
|
session,
|
||||||
-1,
|
-1,
|
||||||
session.getEntityCache().getNextEntityId().incrementAndGet(),
|
session.getEntityCache().getNextEntityId().incrementAndGet(),
|
||||||
@ -81,28 +76,27 @@ public class JavaPlayerInfoUpdateTranslator extends PacketTranslator<Clientbound
|
|||||||
0, 0, 0,
|
0, 0, 0,
|
||||||
profile.getName(),
|
profile.getName(),
|
||||||
texturesProperty
|
texturesProperty
|
||||||
);
|
);
|
||||||
|
|
||||||
session.getEntityCache().addPlayerEntity(playerEntity);
|
session.getEntityCache().addPlayerEntity(playerEntity);
|
||||||
} else {
|
} else {
|
||||||
playerEntity.setUsername(profile.getName());
|
playerEntity.setUsername(profile.getName());
|
||||||
playerEntity.setTexturesProperty(texturesProperty);
|
playerEntity.setTexturesProperty(texturesProperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
playerEntity.setPlayerList(true);
|
playerEntity.setPlayerList(true);
|
||||||
|
|
||||||
// We'll send our own PlayerListEntry in requestAndHandleSkinAndCape
|
// We'll send our own PlayerListEntry in requestAndHandleSkinAndCape
|
||||||
// But we need to send other player's entries so they show up in the player list
|
// But we need to send other player's entries so they show up in the player list
|
||||||
// without processing their skin information - that'll be processed when they spawn in
|
// without processing their skin information - that'll be processed when they spawn in
|
||||||
if (self) {
|
if (self) {
|
||||||
SkinManager.requestAndHandleSkinAndCape(playerEntity, session, skinAndCape ->
|
SkinManager.requestAndHandleSkinAndCape(playerEntity, session, skinAndCape ->
|
||||||
GeyserImpl.getInstance().getLogger().debug("Loaded Local Bedrock Java Skin Data for " + session.getClientData().getUsername()));
|
GeyserImpl.getInstance().getLogger().debug("Loaded Local Bedrock Java Skin Data for " + session.getClientData().getUsername()));
|
||||||
} else {
|
} else {
|
||||||
playerEntity.setValid(true);
|
playerEntity.setValid(true);
|
||||||
PlayerListPacket.Entry playerListEntry = SkinManager.buildCachedEntry(session, playerEntity);
|
PlayerListPacket.Entry playerListEntry = SkinManager.buildCachedEntry(session, playerEntity);
|
||||||
|
|
||||||
translate.getEntries().add(playerListEntry);
|
translate.getEntries().add(playerListEntry);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*
|
|
||||||
* @author GeyserMC
|
|
||||||
* @link https://github.com/GeyserMC/Geyser
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.geysermc.geyser.translator.protocol.java.level;
|
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundCustomSoundPacket;
|
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
|
||||||
import com.nukkitx.protocol.bedrock.packet.PlaySoundPacket;
|
|
||||||
import org.geysermc.geyser.session.GeyserSession;
|
|
||||||
import org.geysermc.geyser.translator.protocol.PacketTranslator;
|
|
||||||
import org.geysermc.geyser.translator.protocol.Translator;
|
|
||||||
import org.geysermc.geyser.util.SoundUtils;
|
|
||||||
|
|
||||||
@Translator(packet = ClientboundCustomSoundPacket.class)
|
|
||||||
public class JavaCustomSoundTranslator extends PacketTranslator<ClientboundCustomSoundPacket> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void translate(GeyserSession session, ClientboundCustomSoundPacket packet) {
|
|
||||||
PlaySoundPacket playSoundPacket = new PlaySoundPacket();
|
|
||||||
playSoundPacket.setSound(SoundUtils.translatePlaySound(packet.getSound()));
|
|
||||||
playSoundPacket.setPosition(Vector3f.from(packet.getX(), packet.getY(), packet.getZ()));
|
|
||||||
playSoundPacket.setVolume(packet.getVolume());
|
|
||||||
playSoundPacket.setPitch(packet.getPitch());
|
|
||||||
|
|
||||||
session.sendUpstreamPacket(playSoundPacket);
|
|
||||||
}
|
|
||||||
}
|
|
@ -38,6 +38,6 @@ public class JavaSoundTranslator extends PacketTranslator<ClientboundSoundPacket
|
|||||||
@Override
|
@Override
|
||||||
public void translate(GeyserSession session, ClientboundSoundPacket packet) {
|
public void translate(GeyserSession session, ClientboundSoundPacket packet) {
|
||||||
Vector3f position = Vector3f.from(packet.getX(), packet.getY(), packet.getZ());
|
Vector3f position = Vector3f.from(packet.getX(), packet.getY(), packet.getZ());
|
||||||
SoundUtils.playBuiltinSound(session, packet.getSound(), position, packet.getVolume(), packet.getPitch());
|
SoundUtils.playSound(session, packet.getSound(), position, packet.getVolume(), packet.getPitch());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,11 +100,7 @@ public class SettingsUtils {
|
|||||||
.translator(MinecraftLocale::getLocaleString); // we need translate gamerules next
|
.translator(MinecraftLocale::getLocaleString); // we need translate gamerules next
|
||||||
|
|
||||||
WorldManager worldManager = GeyserImpl.getInstance().getWorldManager();
|
WorldManager worldManager = GeyserImpl.getInstance().getWorldManager();
|
||||||
for (GameRule gamerule : GameRule.values()) {
|
for (GameRule gamerule : GameRule.VALUES) {
|
||||||
if (gamerule.equals(GameRule.UNKNOWN)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the relevant form item based on the gamerule type
|
// Add the relevant form item based on the gamerule type
|
||||||
if (Boolean.class.equals(gamerule.getType())) {
|
if (Boolean.class.equals(gamerule.getType())) {
|
||||||
builder.toggle("gamerule." + gamerule.getJavaID(), worldManager.getGameRuleBool(session, gamerule));
|
builder.toggle("gamerule." + gamerule.getJavaID(), worldManager.getGameRuleBool(session, gamerule));
|
||||||
@ -146,10 +142,6 @@ public class SettingsUtils {
|
|||||||
|
|
||||||
if (showGamerules) {
|
if (showGamerules) {
|
||||||
for (GameRule gamerule : GameRule.VALUES) {
|
for (GameRule gamerule : GameRule.VALUES) {
|
||||||
if (gamerule.equals(GameRule.UNKNOWN)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Boolean.class.equals(gamerule.getType())) {
|
if (Boolean.class.equals(gamerule.getType())) {
|
||||||
boolean value = response.next();
|
boolean value = response.next();
|
||||||
if (value != session.getGeyser().getWorldManager().getGameRuleBool(session, gamerule)) {
|
if (value != session.getGeyser().getWorldManager().getGameRuleBool(session, gamerule)) {
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
|
|
||||||
package org.geysermc.geyser.util;
|
package org.geysermc.geyser.util;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.level.sound.BuiltinSound;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.level.sound.CustomSound;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.level.sound.Sound;
|
import com.github.steveice10.mc.protocol.data.game.level.sound.Sound;
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
import com.nukkitx.protocol.bedrock.data.LevelEventType;
|
import com.nukkitx.protocol.bedrock.data.LevelEventType;
|
||||||
@ -63,30 +61,20 @@ public final class SoundUtils {
|
|||||||
/**
|
/**
|
||||||
* Translates a Java Custom or Builtin Sound to its Bedrock equivalent
|
* Translates a Java Custom or Builtin Sound to its Bedrock equivalent
|
||||||
*
|
*
|
||||||
* @param sound the sound to translate
|
* @param javaIdentifier the sound to translate
|
||||||
* @return a Bedrock sound
|
* @return a Bedrock sound
|
||||||
*/
|
*/
|
||||||
public static String translatePlaySound(Sound sound) {
|
public static String translatePlaySound(String javaIdentifier) {
|
||||||
String packetSound;
|
|
||||||
if (sound instanceof BuiltinSound builtinSound) {
|
|
||||||
packetSound = builtinSound.getName();
|
|
||||||
} else if (sound instanceof CustomSound customSound) {
|
|
||||||
packetSound = customSound.getName();
|
|
||||||
} else {
|
|
||||||
GeyserImpl.getInstance().getLogger().debug("Unknown sound, we were unable to map this. " + sound);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Drop the Minecraft namespace if applicable
|
// Drop the Minecraft namespace if applicable
|
||||||
if (packetSound.startsWith("minecraft:")) {
|
if (javaIdentifier.startsWith("minecraft:")) {
|
||||||
packetSound = packetSound.substring("minecraft:".length());
|
javaIdentifier = javaIdentifier.substring("minecraft:".length());
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundMapping soundMapping = Registries.SOUNDS.get(packetSound);
|
SoundMapping soundMapping = Registries.SOUNDS.get(javaIdentifier);
|
||||||
if (soundMapping == null || soundMapping.getPlaysound() == null) {
|
if (soundMapping == null || soundMapping.getPlaysound() == null) {
|
||||||
// no mapping
|
// no mapping
|
||||||
GeyserImpl.getInstance().getLogger().debug("[PlaySound] Defaulting to sound server gave us for " + sound);
|
GeyserImpl.getInstance().getLogger().debug("[PlaySound] Defaulting to sound server gave us for " + javaIdentifier);
|
||||||
return packetSound;
|
return javaIdentifier;
|
||||||
}
|
}
|
||||||
return soundMapping.getPlaysound();
|
return soundMapping.getPlaysound();
|
||||||
}
|
}
|
||||||
@ -99,7 +87,7 @@ public final class SoundUtils {
|
|||||||
* @param position the position
|
* @param position the position
|
||||||
* @param pitch the pitch
|
* @param pitch the pitch
|
||||||
*/
|
*/
|
||||||
public static void playBuiltinSound(GeyserSession session, BuiltinSound javaSound, Vector3f position, float volume, float pitch) {
|
public static void playSound(GeyserSession session, Sound javaSound, Vector3f position, float volume, float pitch) {
|
||||||
String packetSound = javaSound.getName();
|
String packetSound = javaSound.getName();
|
||||||
|
|
||||||
SoundMapping soundMapping = Registries.SOUNDS.get(packetSound);
|
SoundMapping soundMapping = Registries.SOUNDS.get(packetSound);
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren