feat(wrapper): only support 1.20/1.21 (not working for >1.20.2?)
This commit is contained in:
parent
d45ce65c3b
commit
a98d5a75bd
4 changed files with 45 additions and 52 deletions
|
@ -64,8 +64,9 @@ public class NickoBukkit extends JavaPlugin {
|
||||||
|
|
||||||
dataStore = new PlayerDataStore(mojangAPI, getNickoConfig());
|
dataStore = new PlayerDataStore(mojangAPI, getNickoConfig());
|
||||||
|
|
||||||
if (!MinecraftVersion.WILD_UPDATE.atOrAbove()) {
|
if (!MinecraftVersion.TRAILS_AND_TAILS.atOrAbove()) {
|
||||||
getLogger().severe("This version (" + MinecraftVersion.getCurrentVersion().getVersion() + ") is not supported by Nicko!");
|
getLogger().severe("This version (" + MinecraftVersion.getCurrentVersion().getVersion() + ") is not supported by Nicko!");
|
||||||
|
getLogger().severe("As of version 1.0.7, Nicko only supports the latest two majors Minecraft versions. (Currently 1.20.X-1.21.X)");
|
||||||
dataStore.getStorage().setError(true);
|
dataStore.getStorage().setError(true);
|
||||||
Bukkit.getPluginManager().disablePlugin(this);
|
Bukkit.getPluginManager().disablePlugin(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,7 +151,7 @@ public class AppearanceManager {
|
||||||
respawn.setGameMode(player.getGameMode());
|
respawn.setGameMode(player.getGameMode());
|
||||||
respawn.setPreviousGameMode(player.getGameMode());
|
respawn.setPreviousGameMode(player.getGameMode());
|
||||||
respawn.setCopyMetadata(true);
|
respawn.setCopyMetadata(true);
|
||||||
respawn.sendPacket(player);
|
//respawn.sendPacket(player);
|
||||||
player.teleport(player.getLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN);
|
player.teleport(player.getLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||||
player.setAllowFlight(wasAllowedToFly);
|
player.setAllowFlight(wasAllowedToFly);
|
||||||
player.setFlying(wasFlying);
|
player.setFlying(wasFlying);
|
||||||
|
|
|
@ -3,95 +3,87 @@ package xyz.ineanto.nicko.wrapper;
|
||||||
import com.comphenix.protocol.PacketType;
|
import com.comphenix.protocol.PacketType;
|
||||||
import com.comphenix.protocol.events.InternalStructure;
|
import com.comphenix.protocol.events.InternalStructure;
|
||||||
import com.comphenix.protocol.events.PacketContainer;
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
import com.comphenix.protocol.reflect.StructureModifier;
|
|
||||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||||
import com.comphenix.protocol.wrappers.*;
|
import com.comphenix.protocol.wrappers.BukkitConverters;
|
||||||
|
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||||
|
import com.comphenix.protocol.wrappers.MinecraftKey;
|
||||||
import com.google.common.hash.Hashing;
|
import com.google.common.hash.Hashing;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PacketPlayServerRespawn Wrapper class (1.19 to 1.21 (one day))
|
* PacketPlayServerRespawn Wrapper class (1.20.X to 1.21.X)
|
||||||
*
|
|
||||||
* @author ineanto, based on work from dmulloy2 and Kristian S. Strangeland
|
|
||||||
* <p>
|
* <p>
|
||||||
* In 1.20.2, all the fields were replaced with a
|
* In 1.20.2, all the fields were merged inside a
|
||||||
* single "CommonPlayerSpawnInfo" record object.
|
* single "CommonPlayerSpawnInfo" record.
|
||||||
|
*
|
||||||
|
* @author inenato (w/ additional help from lukalt), based on work from dmulloy2 and Kristian S. Strangeland
|
||||||
*/
|
*/
|
||||||
public class WrapperPlayServerRespawn extends AbstractPacket {
|
public class WrapperPlayServerRespawn extends AbstractPacket {
|
||||||
public static final PacketType TYPE = PacketType.Play.Server.RESPAWN;
|
public static final PacketType TYPE = PacketType.Play.Server.RESPAWN;
|
||||||
|
|
||||||
private final InternalStructure commonPlayerSpawnInfoStructure;
|
private final InternalStructure spawnInfoStructure;
|
||||||
|
|
||||||
public WrapperPlayServerRespawn() {
|
public WrapperPlayServerRespawn() {
|
||||||
super(new PacketContainer(TYPE), TYPE);
|
super(new PacketContainer(TYPE), TYPE);
|
||||||
handle.getModifier().writeDefaults();
|
handle.getModifier().writeDefaults();
|
||||||
commonPlayerSpawnInfoStructure = handle.getStructures().readSafely(0);
|
spawnInfoStructure = handle.getStructures().readSafely(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDimension(World value) {
|
public void setDimension(World value) {
|
||||||
if (commonPlayerSpawnInfoStructure == null) {
|
if (!MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) {
|
||||||
System.out.println("cPSIS null");
|
// 1.20 to 1.20.1 (by lukalt)
|
||||||
// 1.19 to 1.20.1, props to lukalt for helping me figure this out.
|
final InternalStructure dimensionType = handle.getStructures().read(0);
|
||||||
writeDimensionToStructure(value, handle.getStructures(), handle.getWorldKeys());
|
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);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1.20.2 to 1.21
|
// 1.20.2 to 1.21
|
||||||
writeDimensionToStructure(value, commonPlayerSpawnInfoStructure.getStructures(), commonPlayerSpawnInfoStructure.getWorldKeys());
|
if (MinecraftVersion.TRAILS_AND_TAILS.atOrAbove() && !MinecraftVersion.v1_21_0.atOrAbove()) {
|
||||||
|
spawnInfoStructure.getHolders(
|
||||||
|
MinecraftReflection.getDimensionManager(),
|
||||||
|
BukkitConverters.getDimensionConverter()
|
||||||
|
).write(0, value);
|
||||||
|
spawnInfoStructure.getWorldKeys().writeSafely(0, value);
|
||||||
|
handle.getStructures().writeSafely(0, spawnInfoStructure);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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().writeSafely(0, EnumWrappers.NativeGameMode.fromBukkit(value));
|
// 1.20 to 1.20.1
|
||||||
|
handle.getGameModes().writeSafely(0, EnumWrappers.NativeGameMode.fromBukkit(value));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
handle.getGameModes().writeSafely(0, EnumWrappers.NativeGameMode.fromBukkit(value));
|
|
||||||
|
spawnInfoStructure.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().writeSafely(1, EnumWrappers.NativeGameMode.fromBukkit(value));
|
// 1.20 to 1.20.1
|
||||||
|
handle.getGameModes().writeSafely(1, EnumWrappers.NativeGameMode.fromBukkit(value));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
handle.getGameModes().writeSafely(1, EnumWrappers.NativeGameMode.fromBukkit(value));
|
|
||||||
|
spawnInfoStructure.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()) {
|
|
||||||
handle.getBytes().writeSafely(0, ((byte) (value ? 0x01 : 0x00)));
|
// 1.20 to 1.20.1
|
||||||
} else {
|
handle.getBooleans().writeSafely(0, value);
|
||||||
handle.getBooleans().writeSafely(0, value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSeed(long value) {
|
public void setSeed(long value) {
|
||||||
if (MinecraftVersion.WILD_UPDATE.atOrAbove() && !MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) {
|
if (!MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) {
|
||||||
|
// 1.20 to 1.20.1
|
||||||
handle.getLongs().writeSafely(0, Hashing.sha256().hashLong(value).asLong());
|
handle.getLongs().writeSafely(0, Hashing.sha256().hashLong(value).asLong());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeDimensionToStructure(World value, StructureModifier<InternalStructure> structures, StructureModifier<World> worldKeys) {
|
|
||||||
if (MinecraftVersion.TRAILS_AND_TAILS.atOrAbove() && !MinecraftVersion.v1_20_5.atOrAbove()) {
|
|
||||||
final InternalStructure dimensionType = structures.readSafely(0);
|
|
||||||
if (dimensionType != null) {
|
|
||||||
// 1.20.2 to 1.20.5
|
|
||||||
dimensionType.getMinecraftKeys().writeSafely(0, new MinecraftKey("minecraft", "dimension_type"));
|
|
||||||
dimensionType.getMinecraftKeys().writeSafely(1, new MinecraftKey("minecraft", "overworld"));
|
|
||||||
structures.writeSafely(0, dimensionType);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 1.20.5/6 to 1.21
|
|
||||||
final StructureModifier<World> worldHolder = commonPlayerSpawnInfoStructure.getHolders(
|
|
||||||
MinecraftReflection.getDimensionManager(),
|
|
||||||
Converters.holder(BukkitConverters.getDimensionConverter(),
|
|
||||||
WrappedRegistry.getDimensionRegistry())
|
|
||||||
);
|
|
||||||
worldHolder.writeSafely(0, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
worldKeys.writeSafely(0, value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ main: xyz.ineanto.nicko.NickoBukkit
|
||||||
version: ${version}
|
version: ${version}
|
||||||
author: Ineanto
|
author: Ineanto
|
||||||
description: "The feature packed, next generation disguise plugin for Minecraft."
|
description: "The feature packed, next generation disguise plugin for Minecraft."
|
||||||
api-version: 1.19
|
api-version: 1.20
|
||||||
softdepend: [ PlaceholderAPI ]
|
softdepend: [ PlaceholderAPI ]
|
||||||
depend:
|
depend:
|
||||||
- ProtocolLib
|
- ProtocolLib
|
||||||
|
|
Loading…
Reference in a new issue