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() {
plugin = this;
if (!MinecraftVersion.VILLAGE_UPDATE.atOrAbove()) {
getLogger().severe("This version (" + MinecraftVersion.getCurrentVersion().getVersion() + ") is not supported by Nicko!");
}
configurationManager = new ConfigurationManager(getDataFolder());
configurationManager.saveDefaultConfig();
@ -62,6 +58,12 @@ public class NickoBukkit extends JavaPlugin {
dataStore = new PlayerDataStore(mojangAPI, getNickoConfig());
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...");
if (!dataStore.getStorage().getProvider().init()) {
dataStore.getStorage().setError(true);

View file

@ -35,7 +35,7 @@ public class WrapperPlayServerEntityDestroy extends AbstractPacket {
* @param value New value for field 'entityIds'
*/
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()) {
// 1.20.2
final InternalStructure dimensionType = commonPlayerSpawnInfoStructure.getStructures().read(0);
dimensionType.getMinecraftKeys().write(0, new MinecraftKey("minecraft", "dimension_type"));
dimensionType.getMinecraftKeys().write(1, new MinecraftKey("minecraft", "overworld"));
commonPlayerSpawnInfoStructure.getStructures().write(0, dimensionType);
commonPlayerSpawnInfoStructure.getWorldKeys().write(0, value);
dimensionType.getMinecraftKeys().writeSafely(0, new MinecraftKey("minecraft", "dimension_type"));
dimensionType.getMinecraftKeys().writeSafely(1, new MinecraftKey("minecraft", "overworld"));
commonPlayerSpawnInfoStructure.getStructures().writeSafely(0, dimensionType);
commonPlayerSpawnInfoStructure.getWorldKeys().writeSafely(0, value);
} else if (MinecraftVersion.WILD_UPDATE.atOrAbove()) {
// 1.19 to 1.20.1
// Thank you lukalt!
final InternalStructure dimensionType = handle.getStructures().read(0);
dimensionType.getMinecraftKeys().write(0, new MinecraftKey("minecraft", "dimension_type"));
dimensionType.getMinecraftKeys().write(1, new MinecraftKey("minecraft", "overworld"));
handle.getStructures().write(0, dimensionType);
handle.getWorldKeys().write(0, value);
dimensionType.getMinecraftKeys().writeSafely(0, new MinecraftKey("minecraft", "dimension_type"));
dimensionType.getMinecraftKeys().writeSafely(1, new MinecraftKey("minecraft", "overworld"));
handle.getStructures().writeSafely(0, dimensionType);
handle.getWorldKeys().writeSafely(0, value);
} else if (MinecraftVersion.CAVES_CLIFFS_2.atOrAbove()) {
// 1.18
handle.getHolders(
MinecraftReflection.getDimensionManager(),
BukkitConverters.getDimensionConverter()
).write(0, value);
).writeSafely(0, value);
} else {
// 1.17 and below (untested)
handle.getDimensions().write(0, value.getEnvironment().ordinal());
handle.getDimensions().writeSafely(0, value.getEnvironment().ordinal());
}
}
public void setGameMode(GameMode value) {
if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) {
commonPlayerSpawnInfoStructure.getGameModes().write(0, EnumWrappers.NativeGameMode.fromBukkit(value));
commonPlayerSpawnInfoStructure.getGameModes().writeSafely(0, EnumWrappers.NativeGameMode.fromBukkit(value));
return;
}
handle.getGameModes().write(0, EnumWrappers.NativeGameMode.fromBukkit(value));
handle.getGameModes().writeSafely(0, EnumWrappers.NativeGameMode.fromBukkit(value));
}
public void setPreviousGameMode(GameMode value) {
if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) {
commonPlayerSpawnInfoStructure.getGameModes().write(1, EnumWrappers.NativeGameMode.fromBukkit(value));
commonPlayerSpawnInfoStructure.getGameModes().writeSafely(1, EnumWrappers.NativeGameMode.fromBukkit(value));
return;
}
handle.getGameModes().write(1, EnumWrappers.NativeGameMode.fromBukkit(value));
handle.getGameModes().writeSafely(1, EnumWrappers.NativeGameMode.fromBukkit(value));
}
public void setCopyMetadata(boolean value) {
if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) return;
if (MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) {
handle.getBytes().write(0, ((byte) (value ? 0x01 : 0x00)));
handle.getBytes().writeSafely(0, ((byte) (value ? 0x01 : 0x00)));
} else {
handle.getBooleans().write(0, value);
handle.getBooleans().writeSafely(0, value);
}
}
public void setSeed(long value) {
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) {
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.events.PacketContainer;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.EntityType;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.UUID;
/**
@ -26,31 +25,14 @@ public class WrapperPlayServerSpawnEntity extends AbstractPacket {
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
*
* @param value New value for field 'entityId'
*/
public void setEntityId(int value) {
this.handle.getIntegers().write(0, value);
}
/**
* Retrieves the unique id of the player
*
* @return 'playerId'
*/
public UUID getPlayerId() {
return this.handle.getUUIDs().read(0);
this.handle.getIntegers().writeSafely(0, value);
this.handle.getEntityTypeModifier().writeSafely(0, EntityType.PLAYER);
}
/**
@ -59,16 +41,7 @@ public class WrapperPlayServerSpawnEntity extends AbstractPacket {
* @param value New value for field 'playerId'
*/
public void setPlayerId(UUID value) {
this.handle.getUUIDs().write(0, value);
}
/**
* Retrieves the value of field 'x'
*
* @return 'x'
*/
public double getX() {
return this.handle.getDoubles().read(0);
this.handle.getUUIDs().writeSafely(0, value);
}
/**
@ -77,16 +50,7 @@ public class WrapperPlayServerSpawnEntity extends AbstractPacket {
* @param value New value for field 'x'
*/
public void setX(double value) {
this.handle.getDoubles().write(0, value);
}
/**
* Retrieves the value of field 'y'
*
* @return 'y'
*/
public double getY() {
return this.handle.getDoubles().read(1);
this.handle.getDoubles().writeSafely(0, value);
}
/**
@ -95,16 +59,7 @@ public class WrapperPlayServerSpawnEntity extends AbstractPacket {
* @param value New value for field 'y'
*/
public void setY(double value) {
this.handle.getDoubles().write(1, value);
}
/**
* Retrieves the value of field 'z'
*
* @return 'z'
*/
public double getZ() {
return this.handle.getDoubles().read(2);
this.handle.getDoubles().writeSafely(1, value);
}
/**
@ -116,31 +71,13 @@ public class WrapperPlayServerSpawnEntity extends AbstractPacket {
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)
*
* @param value New value for field 'yRot'
*/
public void setYRotRaw(byte value) {
this.handle.getBytes().write(0, value);
}
/**
* Retrieves the value of field 'xRot'
*
* @return 'xRot'
*/
public byte getXRotRaw() {
return this.handle.getBytes().read(1);
this.handle.getBytes().writeSafely(0, value);
}
/**
@ -149,11 +86,7 @@ public class WrapperPlayServerSpawnEntity extends AbstractPacket {
* @param value New value for field 'xRot'
*/
public void setXRotRaw(byte value) {
this.handle.getBytes().write(1, value);
}
public Location getLocation(@Nullable World world) {
return new Location(world, getX(), getY(), getZ(), angleToDegrees(getYRotRaw()), angleToDegrees(getXRotRaw()));
this.handle.getBytes().writeSafely(1, value);
}
public void setLocation(@Nonnull Location location) {
@ -164,10 +97,6 @@ public class WrapperPlayServerSpawnEntity extends AbstractPacket {
setXRotRaw(degreesToAngle(location.getPitch()));
}
private float angleToDegrees(byte rawAngle) {
return rawAngle / 256.0F * 360.0F;
}
private byte degreesToAngle(float degree) {
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) {
if (MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) {
handle.getPlayerInfoActions().write(0, value);
handle.getPlayerInfoActions().writeSafely(0, value);
} 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) {
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) {
handle.getUUIDLists().write(0, value);
handle.getUUIDLists().writeSafely(0, value);
}
}