Fix netPacket errors

This commit is contained in:
cnaude 2017-06-15 21:49:18 -07:00
parent dda8c31780
commit eb3c75b139
6 changed files with 84 additions and 64 deletions

View File

@ -130,6 +130,14 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>spigot-112</artifactId>
<version>1.12</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<!-- PircBotX --> <!-- PircBotX -->
<dependency> <dependency>
<groupId>com.cnaude.pircbotx</groupId> <groupId>com.cnaude.pircbotx</groupId>

View File

@ -19,7 +19,6 @@ package com.cnaude.purpleirc.Hooks;
import com.cnaude.purpleirc.PurpleIRC; import com.cnaude.purpleirc.PurpleIRC;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.metadata.MetadataValue; import org.bukkit.metadata.MetadataValue;
import org.kitteh.vanish.staticaccess.VanishNoPacket;
/** /**
* *
@ -46,12 +45,10 @@ public class VanishHook {
// Try SuperVanish first // Try SuperVanish first
if (plugin.superVanishHook != null) { if (plugin.superVanishHook != null) {
return plugin.superVanishHook.isVanished(player); return plugin.superVanishHook.isVanished(player);
} else if (plugin.vanishNoPacketHook != null) {
return plugin.vanishNoPacketHook.isVanished(player);
} else { } else {
// Fallback to other Vanish // Fallback to other Vanish
if (player.hasMetadata("vanished")) { if (player.hasMetadata("vanished")) {
plugin.logDebug("Player " + player.getName() + " has vanished metadata" + player.getMetadata("vanished").get(0).asString()); plugin.logDebug("Player " + player.getName() + " has vanished metadata" + player.getMetadata("vanished").get(0));
MetadataValue md = player.getMetadata("vanished").get(0); MetadataValue md = player.getMetadata("vanished").get(0);
if (md.asBoolean()) { if (md.asBoolean()) {
plugin.logDebug("Player " + player.getName() + " is vanished."); plugin.logDebug("Player " + player.getName() + " is vanished.");

View File

@ -1,56 +0,0 @@
/*
* Copyright (C) 2017 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 <http://www.gnu.org/licenses/>.
*/
package com.cnaude.purpleirc.Hooks;
import com.cnaude.purpleirc.PurpleIRC;
import org.bukkit.entity.Player;
import org.kitteh.vanish.staticaccess.VanishNoPacket;
import org.kitteh.vanish.staticaccess.VanishNotLoadedException;
/**
*
* @author cnaude
*/
public class VanishNoPacketHook {
private final PurpleIRC plugin;
/**
*
* @param plugin the PurpleIRC plugin
*/
public VanishNoPacketHook(PurpleIRC plugin) {
this.plugin = plugin;
}
public boolean isVanished(Player player) {
try {
if (VanishNoPacket.isVanished(player.getName())) {
plugin.logDebug("Player " + player.getName() + " is vanished.");
return true;
} else {
plugin.logDebug("Player " + player.getName() + " is NOT vanished.");
return false;
}
} catch (VanishNotLoadedException ex) {
plugin.logError("VanishNoPacketHook: " + ex.getMessage());
return false;
}
}
}

View File

@ -63,7 +63,6 @@ import com.cnaude.purpleirc.Hooks.ShortifyHook;
import com.cnaude.purpleirc.Hooks.SuperVanishHook; import com.cnaude.purpleirc.Hooks.SuperVanishHook;
import com.cnaude.purpleirc.Hooks.TownyChatHook; import com.cnaude.purpleirc.Hooks.TownyChatHook;
import com.cnaude.purpleirc.Hooks.VanishHook; import com.cnaude.purpleirc.Hooks.VanishHook;
import com.cnaude.purpleirc.Hooks.VanishNoPacketHook;
import com.cnaude.purpleirc.Hooks.VaultHook; import com.cnaude.purpleirc.Hooks.VaultHook;
import com.cnaude.purpleirc.Utilities.CaseInsensitiveMap; import com.cnaude.purpleirc.Utilities.CaseInsensitiveMap;
import com.cnaude.purpleirc.Utilities.ChatTokenizer; import com.cnaude.purpleirc.Utilities.ChatTokenizer;
@ -225,7 +224,6 @@ public class PurpleIRC extends JavaPlugin {
public VaultHook vaultHelpers; public VaultHook vaultHelpers;
public VanishHook vanishHook; public VanishHook vanishHook;
public SuperVanishHook superVanishHook; public SuperVanishHook superVanishHook;
public VanishNoPacketHook vanishNoPacketHook;
private YamlConfiguration heroConfig; private YamlConfiguration heroConfig;
private final File cacheFile; private final File cacheFile;
private final File uuidCacheFile; private final File uuidCacheFile;
@ -1728,7 +1726,6 @@ public class PurpleIRC extends JavaPlugin {
if (isPluginEnabled(PL_VANISHNOPACKET)) { if (isPluginEnabled(PL_VANISHNOPACKET)) {
hookList.add(hookFormat(PL_VANISHNOPACKET, true)); hookList.add(hookFormat(PL_VANISHNOPACKET, true));
getServer().getPluginManager().registerEvents(new VanishNoPacketListener(this), this); getServer().getPluginManager().registerEvents(new VanishNoPacketListener(this), this);
vanishNoPacketHook = new VanishNoPacketHook(this);
} else { } else {
hookList.add(hookFormat(PL_VANISHNOPACKET, false)); hookList.add(hookFormat(PL_VANISHNOPACKET, false));
} }

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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_12_R1.EntityPlayer;
import net.minecraft.server.v1_12_R1.MinecraftServer;
import net.minecraft.server.v1_12_R1.PacketPlayOutPlayerInfo;
import net.minecraft.server.v1_12_R1.PlayerInteractManager;
/**
*
* @author Chris Naude
*/
public class NetPacket_112 {
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);
}
}

View File

@ -194,6 +194,17 @@ public class NetPackets {
} catch (Exception ex) { } catch (Exception ex) {
plugin.logError("tabPacket: " + ex.getMessage()); plugin.logError("tabPacket: " + ex.getMessage());
} }
} else if (version.contains("MC: 1.12")) {
try {
if (add) {
return NetPacket_112.add(displayName);
} else {
plugin.logDebug("T112: Removing: " + name);
return NetPacket_112.rem(displayName);
}
} catch (Exception ex) {
plugin.logError("tabPacket: " + ex.getMessage());
}
} else { } else {
plugin.logDebug("tabPacket: deprecated "); plugin.logDebug("tabPacket: deprecated ");
playerListConstructor = protocolManager.createPacketConstructor(Packets.Server.PLAYER_INFO, "", false, (int) 0); playerListConstructor = protocolManager.createPacketConstructor(Packets.Server.PLAYER_INFO, "", false, (int) 0);