From c127d278e3c31596c3fabf1ac760a6cbc6022356 Mon Sep 17 00:00:00 2001 From: cnaude Date: Fri, 13 May 2016 21:51:08 -0700 Subject: [PATCH] Update for MC 194. --- pom.xml | 8 +++ .../purpleirc/Utilities/NetPacket_194.java | 63 +++++++++++++++++++ .../purpleirc/Utilities/NetPackets.java | 11 ++++ 3 files changed, 82 insertions(+) create mode 100644 src/main/java/com/cnaude/purpleirc/Utilities/NetPacket_194.java diff --git a/pom.xml b/pom.xml index c557904..ac1ca6c 100644 --- a/pom.xml +++ b/pom.xml @@ -109,6 +109,14 @@ jar provided + + + org.bukkit + spigot-194 + 1.9.4 + jar + provided + diff --git a/src/main/java/com/cnaude/purpleirc/Utilities/NetPacket_194.java b/src/main/java/com/cnaude/purpleirc/Utilities/NetPacket_194.java new file mode 100644 index 0000000..40b753b --- /dev/null +++ b/src/main/java/com/cnaude/purpleirc/Utilities/NetPacket_194.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2015 cnaude + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.cnaude.purpleirc.Utilities; + +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.wrappers.WrappedGameProfile; +import com.google.common.base.Charsets; +import com.mojang.authlib.GameProfile; +import java.util.UUID; +import net.minecraft.server.v1_9_R2.EntityPlayer; +import net.minecraft.server.v1_9_R2.MinecraftServer; +import net.minecraft.server.v1_9_R2.PacketPlayOutPlayerInfo; +import net.minecraft.server.v1_9_R2.PlayerInteractManager; + +/** + * + * @author Chris Naude + */ +public class NetPacket_194 { + + public static PacketContainer add(String displayName) { + UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + displayName).getBytes(Charsets.UTF_8)); + EntityPlayer pl = new EntityPlayer( + MinecraftServer.getServer(), + MinecraftServer.getServer().getWorldServer(0), + (GameProfile) (new WrappedGameProfile(uuid, displayName)).getHandle(), + new PlayerInteractManager(MinecraftServer.getServer().getWorldServer(0)) + ); + PacketPlayOutPlayerInfo pi + = new PacketPlayOutPlayerInfo( + PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, pl); + return PacketContainer.fromPacket(pi); + } + + public static PacketContainer rem(String displayName) { + UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + displayName).getBytes(Charsets.UTF_8)); + EntityPlayer pl = new EntityPlayer( + MinecraftServer.getServer(), + MinecraftServer.getServer().getWorldServer(0), + (GameProfile) (new WrappedGameProfile(uuid, displayName)).getHandle(), + new PlayerInteractManager(MinecraftServer.getServer().getWorldServer(0)) + ); + PacketPlayOutPlayerInfo pi + = new PacketPlayOutPlayerInfo( + PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, pl); + return PacketContainer.fromPacket(pi); + } + +} diff --git a/src/main/java/com/cnaude/purpleirc/Utilities/NetPackets.java b/src/main/java/com/cnaude/purpleirc/Utilities/NetPackets.java index 689777d..2e3fc4f 100644 --- a/src/main/java/com/cnaude/purpleirc/Utilities/NetPackets.java +++ b/src/main/java/com/cnaude/purpleirc/Utilities/NetPackets.java @@ -150,6 +150,17 @@ public class NetPackets { } catch (Exception ex) { plugin.logError("tabPacket: " + ex.getMessage()); } + } else if (version.contains("MC: 1.9.4")) { + try { + if (add) { + return NetPacket_194.add(displayName); + } else { + plugin.logDebug("T194: Removing: " + name); + return NetPacket_194.rem(displayName); + } + } catch (Exception ex) { + plugin.logError("tabPacket: " + ex.getMessage()); + } } else if (version.contains("MC: 1.9")) { try { if (add) {