fix: players appearing as allays

This commit is contained in:
ineanto 2023-12-03 23:25:42 +01:00
parent d75aad6596
commit fcc4590396
6 changed files with 37 additions and 106 deletions

View file

@ -51,10 +51,6 @@ public class NickoBukkit extends JavaPlugin {
public void onEnable() { public void onEnable() {
plugin = this; plugin = this;
if (!MinecraftVersion.VILLAGE_UPDATE.atOrAbove()) {
getLogger().severe("This version (" + MinecraftVersion.getCurrentVersion().getVersion() + ") is not supported by Nicko!");
}
configurationManager = new ConfigurationManager(getDataFolder()); configurationManager = new ConfigurationManager(getDataFolder());
configurationManager.saveDefaultConfig(); configurationManager.saveDefaultConfig();
@ -62,6 +58,12 @@ public class NickoBukkit extends JavaPlugin {
dataStore = new PlayerDataStore(mojangAPI, getNickoConfig()); dataStore = new PlayerDataStore(mojangAPI, getNickoConfig());
nameStore = new PlayerNameStore(); nameStore = new PlayerNameStore();
if (!MinecraftVersion.VILLAGE_UPDATE.atOrAbove()) {
getLogger().severe("This version (" + MinecraftVersion.getCurrentVersion().getVersion() + ") is not supported by Nicko!");
dataStore.getStorage().setError(true);
Bukkit.getPluginManager().disablePlugin(this);
}
getLogger().info("Loading persistence..."); getLogger().info("Loading persistence...");
if (!dataStore.getStorage().getProvider().init()) { if (!dataStore.getStorage().getProvider().init()) {
dataStore.getStorage().setError(true); dataStore.getStorage().setError(true);

View file

@ -35,7 +35,7 @@ public class WrapperPlayServerEntityDestroy extends AbstractPacket {
* @param value New value for field 'entityIds' * @param value New value for field 'entityIds'
*/ */
public void setEntityIds(IntList value) { public void setEntityIds(IntList value) {
this.handle.getModifier().withType(IntList.class, Converters.passthrough(IntList.class)).write(0, value); this.handle.getModifier().withType(IntList.class, Converters.passthrough(IntList.class)).writeSafely(0, value);
} }
} }

View file

@ -52,65 +52,65 @@ public class WrapperPlayServerRespawn extends AbstractPacket {
if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) { if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) {
// 1.20.2 // 1.20.2
final InternalStructure dimensionType = commonPlayerSpawnInfoStructure.getStructures().read(0); final InternalStructure dimensionType = commonPlayerSpawnInfoStructure.getStructures().read(0);
dimensionType.getMinecraftKeys().write(0, new MinecraftKey("minecraft", "dimension_type")); dimensionType.getMinecraftKeys().writeSafely(0, new MinecraftKey("minecraft", "dimension_type"));
dimensionType.getMinecraftKeys().write(1, new MinecraftKey("minecraft", "overworld")); dimensionType.getMinecraftKeys().writeSafely(1, new MinecraftKey("minecraft", "overworld"));
commonPlayerSpawnInfoStructure.getStructures().write(0, dimensionType); commonPlayerSpawnInfoStructure.getStructures().writeSafely(0, dimensionType);
commonPlayerSpawnInfoStructure.getWorldKeys().write(0, value); commonPlayerSpawnInfoStructure.getWorldKeys().writeSafely(0, value);
} else if (MinecraftVersion.WILD_UPDATE.atOrAbove()) { } else if (MinecraftVersion.WILD_UPDATE.atOrAbove()) {
// 1.19 to 1.20.1 // 1.19 to 1.20.1
// Thank you lukalt! // Thank you lukalt!
final InternalStructure dimensionType = handle.getStructures().read(0); final InternalStructure dimensionType = handle.getStructures().read(0);
dimensionType.getMinecraftKeys().write(0, new MinecraftKey("minecraft", "dimension_type")); dimensionType.getMinecraftKeys().writeSafely(0, new MinecraftKey("minecraft", "dimension_type"));
dimensionType.getMinecraftKeys().write(1, new MinecraftKey("minecraft", "overworld")); dimensionType.getMinecraftKeys().writeSafely(1, new MinecraftKey("minecraft", "overworld"));
handle.getStructures().write(0, dimensionType); handle.getStructures().writeSafely(0, dimensionType);
handle.getWorldKeys().write(0, value); handle.getWorldKeys().writeSafely(0, value);
} else if (MinecraftVersion.CAVES_CLIFFS_2.atOrAbove()) { } else if (MinecraftVersion.CAVES_CLIFFS_2.atOrAbove()) {
// 1.18 // 1.18
handle.getHolders( handle.getHolders(
MinecraftReflection.getDimensionManager(), MinecraftReflection.getDimensionManager(),
BukkitConverters.getDimensionConverter() BukkitConverters.getDimensionConverter()
).write(0, value); ).writeSafely(0, value);
} else { } else {
// 1.17 and below (untested) // 1.17 and below (untested)
handle.getDimensions().write(0, value.getEnvironment().ordinal()); handle.getDimensions().writeSafely(0, value.getEnvironment().ordinal());
} }
} }
public void setGameMode(GameMode value) { public void setGameMode(GameMode value) {
if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) { if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) {
commonPlayerSpawnInfoStructure.getGameModes().write(0, EnumWrappers.NativeGameMode.fromBukkit(value)); commonPlayerSpawnInfoStructure.getGameModes().writeSafely(0, EnumWrappers.NativeGameMode.fromBukkit(value));
return; return;
} }
handle.getGameModes().write(0, EnumWrappers.NativeGameMode.fromBukkit(value)); handle.getGameModes().writeSafely(0, EnumWrappers.NativeGameMode.fromBukkit(value));
} }
public void setPreviousGameMode(GameMode value) { public void setPreviousGameMode(GameMode value) {
if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) { if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) {
commonPlayerSpawnInfoStructure.getGameModes().write(1, EnumWrappers.NativeGameMode.fromBukkit(value)); commonPlayerSpawnInfoStructure.getGameModes().writeSafely(1, EnumWrappers.NativeGameMode.fromBukkit(value));
return; return;
} }
handle.getGameModes().write(1, EnumWrappers.NativeGameMode.fromBukkit(value)); handle.getGameModes().writeSafely(1, EnumWrappers.NativeGameMode.fromBukkit(value));
} }
public void setCopyMetadata(boolean value) { public void setCopyMetadata(boolean value) {
if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) return; if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) return;
if (MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) { if (MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) {
handle.getBytes().write(0, ((byte) (value ? 0x01 : 0x00))); handle.getBytes().writeSafely(0, ((byte) (value ? 0x01 : 0x00)));
} else { } else {
handle.getBooleans().write(0, value); handle.getBooleans().writeSafely(0, value);
} }
} }
public void setSeed(long value) { public void setSeed(long value) {
if (MinecraftVersion.BEE_UPDATE.atOrAbove() && !MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) { if (MinecraftVersion.BEE_UPDATE.atOrAbove() && !MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) {
handle.getLongs().write(0, Hashing.sha256().hashLong(value).asLong()); handle.getLongs().writeSafely(0, Hashing.sha256().hashLong(value).asLong());
} }
} }
public void setDifficulty(Difficulty difficulty) { public void setDifficulty(Difficulty difficulty) {
if (difficulty != null && !MinecraftVersion.VILLAGE_UPDATE.atOrAbove()) { if (difficulty != null && !MinecraftVersion.VILLAGE_UPDATE.atOrAbove()) {
handle.getDifficulties().write(0, EnumWrappers.Difficulty.valueOf(difficulty.name())); handle.getDifficulties().writeSafely(0, EnumWrappers.Difficulty.valueOf(difficulty.name()));
} }
} }
} }

View file

@ -3,10 +3,9 @@ package xyz.atnrch.nicko.wrapper;
import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.entity.EntityType;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.UUID; import java.util.UUID;
/** /**
@ -26,31 +25,14 @@ public class WrapperPlayServerSpawnEntity extends AbstractPacket {
handle.getModifier().writeDefaults(); handle.getModifier().writeDefaults();
} }
/**
* Retrieves entity id of the player
*
* @return 'entityId'
*/
public int getEntityId() {
return this.handle.getIntegers().read(0);
}
/** /**
* Sets the entity id of the player * Sets the entity id of the player
* *
* @param value New value for field 'entityId' * @param value New value for field 'entityId'
*/ */
public void setEntityId(int value) { public void setEntityId(int value) {
this.handle.getIntegers().write(0, value); this.handle.getIntegers().writeSafely(0, value);
} this.handle.getEntityTypeModifier().writeSafely(0, EntityType.PLAYER);
/**
* Retrieves the unique id of the player
*
* @return 'playerId'
*/
public UUID getPlayerId() {
return this.handle.getUUIDs().read(0);
} }
/** /**
@ -59,16 +41,7 @@ public class WrapperPlayServerSpawnEntity extends AbstractPacket {
* @param value New value for field 'playerId' * @param value New value for field 'playerId'
*/ */
public void setPlayerId(UUID value) { public void setPlayerId(UUID value) {
this.handle.getUUIDs().write(0, value); this.handle.getUUIDs().writeSafely(0, value);
}
/**
* Retrieves the value of field 'x'
*
* @return 'x'
*/
public double getX() {
return this.handle.getDoubles().read(0);
} }
/** /**
@ -77,16 +50,7 @@ public class WrapperPlayServerSpawnEntity extends AbstractPacket {
* @param value New value for field 'x' * @param value New value for field 'x'
*/ */
public void setX(double value) { public void setX(double value) {
this.handle.getDoubles().write(0, value); this.handle.getDoubles().writeSafely(0, value);
}
/**
* Retrieves the value of field 'y'
*
* @return 'y'
*/
public double getY() {
return this.handle.getDoubles().read(1);
} }
/** /**
@ -95,16 +59,7 @@ public class WrapperPlayServerSpawnEntity extends AbstractPacket {
* @param value New value for field 'y' * @param value New value for field 'y'
*/ */
public void setY(double value) { public void setY(double value) {
this.handle.getDoubles().write(1, value); this.handle.getDoubles().writeSafely(1, value);
}
/**
* Retrieves the value of field 'z'
*
* @return 'z'
*/
public double getZ() {
return this.handle.getDoubles().read(2);
} }
/** /**
@ -116,31 +71,13 @@ public class WrapperPlayServerSpawnEntity extends AbstractPacket {
this.handle.getDoubles().write(2, value); this.handle.getDoubles().write(2, value);
} }
/**
* Retrieves the discrete rotation around the y-axis (yaw)
*
* @return 'yRot'
*/
public byte getYRotRaw() {
return this.handle.getBytes().read(0);
}
/** /**
* Sets the discrete rotation around the y-axis (yaw) * Sets the discrete rotation around the y-axis (yaw)
* *
* @param value New value for field 'yRot' * @param value New value for field 'yRot'
*/ */
public void setYRotRaw(byte value) { public void setYRotRaw(byte value) {
this.handle.getBytes().write(0, value); this.handle.getBytes().writeSafely(0, value);
}
/**
* Retrieves the value of field 'xRot'
*
* @return 'xRot'
*/
public byte getXRotRaw() {
return this.handle.getBytes().read(1);
} }
/** /**
@ -149,11 +86,7 @@ public class WrapperPlayServerSpawnEntity extends AbstractPacket {
* @param value New value for field 'xRot' * @param value New value for field 'xRot'
*/ */
public void setXRotRaw(byte value) { public void setXRotRaw(byte value) {
this.handle.getBytes().write(1, value); this.handle.getBytes().writeSafely(1, value);
}
public Location getLocation(@Nullable World world) {
return new Location(world, getX(), getY(), getZ(), angleToDegrees(getYRotRaw()), angleToDegrees(getXRotRaw()));
} }
public void setLocation(@Nonnull Location location) { public void setLocation(@Nonnull Location location) {
@ -164,10 +97,6 @@ public class WrapperPlayServerSpawnEntity extends AbstractPacket {
setXRotRaw(degreesToAngle(location.getPitch())); setXRotRaw(degreesToAngle(location.getPitch()));
} }
private float angleToDegrees(byte rawAngle) {
return rawAngle / 256.0F * 360.0F;
}
private byte degreesToAngle(float degree) { private byte degreesToAngle(float degree) {
return (byte)((int)(degree * 256.0F / 360.0F)); return (byte)((int)(degree * 256.0F / 360.0F));
} }

View file

@ -25,13 +25,13 @@ public class WrapperPlayerServerPlayerInfo extends AbstractPacket {
public void setActions(Set<EnumWrappers.PlayerInfoAction> value) { public void setActions(Set<EnumWrappers.PlayerInfoAction> value) {
if (MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) { if (MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) {
handle.getPlayerInfoActions().write(0, value); handle.getPlayerInfoActions().writeSafely(0, value);
} else { } else {
handle.getPlayerInfoAction().write(0, value.stream().iterator().next()); // Get the first Value. handle.getPlayerInfoAction().writeSafely(0, value.stream().iterator().next()); // Get the first Value.
} }
} }
public void setData(List<PlayerInfoData> value) { public void setData(List<PlayerInfoData> value) {
handle.getPlayerInfoDataLists().write(1, value); handle.getPlayerInfoDataLists().writeSafely(1, value);
} }
} }

View file

@ -22,6 +22,6 @@ public class WrapperPlayerServerPlayerInfoRemove extends AbstractPacket {
} }
public void setUUIDs(List<UUID> value) { public void setUUIDs(List<UUID> value) {
handle.getUUIDLists().write(0, value); handle.getUUIDLists().writeSafely(0, value);
} }
} }