From e67cb99cad655a22fc89a4e6edceabc0e8fb8797 Mon Sep 17 00:00:00 2001 From: games647 Date: Fri, 10 Jun 2016 15:11:31 +0200 Subject: [PATCH] Workaround the bukkit teleport API to sucessfull teleport players (Fixes #15) --- CHANGELOG.md | 1 + .../changeskin/bukkit/tasks/SkinUpdater.java | 20 +++++++++++++------ .../games647/changeskin/core/SkinStorage.java | 2 -- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21f2da1a..fcdf6853 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ##### 1.4.1 * Fixed instant updates for BungeeCord servers +* Fix chunk loading issues on instant updates ##### 1.4 diff --git a/bukkit/src/main/java/com/github/games647/changeskin/bukkit/tasks/SkinUpdater.java b/bukkit/src/main/java/com/github/games647/changeskin/bukkit/tasks/SkinUpdater.java index 72a2bf16..17bdc9f1 100644 --- a/bukkit/src/main/java/com/github/games647/changeskin/bukkit/tasks/SkinUpdater.java +++ b/bukkit/src/main/java/com/github/games647/changeskin/bukkit/tasks/SkinUpdater.java @@ -21,7 +21,7 @@ import java.util.logging.Level; import org.bukkit.Bukkit; -import org.bukkit.Chunk; +import org.bukkit.Location; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -100,6 +100,18 @@ private void sendUpdateSelf(WrappedGameProfile gameProfile) throws FieldAccessEx respawn.getGameModes().write(0, gamemode); respawn.getWorldTypeModifier().write(0, receiver.getWorld().getWorldType()); + Location location = receiver.getLocation().clone(); + + PacketContainer teleport = protocolManager.createPacket(PacketType.Play.Server.POSITION); + teleport.getModifier().writeDefaults(); + teleport.getDoubles().write(0, location.getX()); + teleport.getDoubles().write(1, location.getY()); + teleport.getDoubles().write(2, location.getZ()); + teleport.getFloat().write(0, location.getYaw()); + teleport.getFloat().write(1, location.getPitch()); + //send an invalid teleport id in order to let bukkit ignore the incoming confirm packet + teleport.getIntegers().writeSafely(0, -1); + try { //remove the old skin - client updates it only on a complete remove and add protocolManager.sendServerPacket(receiver, removeInfo); @@ -108,12 +120,8 @@ private void sendUpdateSelf(WrappedGameProfile gameProfile) throws FieldAccessEx //notify the client that it should update the own skin protocolManager.sendServerPacket(receiver, respawn); - //refresh the chunk - Chunk chunk = receiver.getWorld().getChunkAt(receiver.getLocation()); - receiver.getWorld().refreshChunk(chunk.getX(), chunk.getZ()); - //prevent the moved too quickly message - receiver.teleport(receiver.getLocation().clone()); + protocolManager.sendServerPacket(receiver, teleport); //send the current inventory - otherwise player would have an empty inventory receiver.updateInventory(); diff --git a/core/src/main/java/com/github/games647/changeskin/core/SkinStorage.java b/core/src/main/java/com/github/games647/changeskin/core/SkinStorage.java index 904eb4e5..ecad67f3 100644 --- a/core/src/main/java/com/github/games647/changeskin/core/SkinStorage.java +++ b/core/src/main/java/com/github/games647/changeskin/core/SkinStorage.java @@ -69,8 +69,6 @@ public void createTables() throws ClassNotFoundException, SQLException { + "`SkinURL` VARCHAR(255) NOT NULL, " + "`CapeURL` VARCHAR(255), " + "`Signature` BLOB NOT NULL" - //SQLite doesn't support this on a create table statement - //+ "INDEX(`UUID`)" + ")"; String createPreferencesStmt = "CREATE TABLE IF NOT EXISTS " + PREFERENCES_TABLE + " ("