Add support for Minecraft 1.8.4.

This commit is contained in:
cnaude 2015-05-21 18:23:01 -07:00
parent 5654897419
commit 0a3a8c3a53
5 changed files with 196 additions and 37 deletions

View File

@ -133,13 +133,19 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>spigot-api</artifactId>
<version>1.8.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>spigot-183</artifactId>
<version>1.8.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>spigot</artifactId>
<version>1.8.3</version>
<artifactId>spigot-184</artifactId>
<version>1.8.4</version>
<scope>provided</scope>
</dependency>
<dependency>
@ -356,7 +362,7 @@
<properties>
<build.number>SNAPSHOT</build.number>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<bukkit.version>1.8.3</bukkit.version>
<bukkit.version>1.8.4</bukkit.version>
</properties>
</project>

14
pom.xml
View File

@ -6,7 +6,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Bukkit API Version, change if out dated -->
<bukkit.version>1.8.3</bukkit.version>
<bukkit.version>1.8.4</bukkit.version>
<build.number>SNAPSHOT</build.number>
</properties>
@ -79,8 +79,16 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>spigot</artifactId>
<version>${bukkit.version}</version>
<artifactId>spigot-183</artifactId>
<version>1.8.3</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>spigot-184</artifactId>
<version>1.8.4</version>
<type>jar</type>
<scope>provided</scope>
</dependency>

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_8_R2.EntityPlayer;
import net.minecraft.server.v1_8_R2.MinecraftServer;
import net.minecraft.server.v1_8_R2.PacketPlayOutPlayerInfo;
import net.minecraft.server.v1_8_R2.PlayerInteractManager;
/**
*
* @author cnaude
*/
public class NetPacket_183 {
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

@ -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_8_R2.EntityPlayer;
import net.minecraft.server.v1_8_R2.MinecraftServer;
import net.minecraft.server.v1_8_R2.PacketPlayOutPlayerInfo;
import net.minecraft.server.v1_8_R2.PlayerInteractManager;
/**
*
* @author cnaude
*/
public class NetPacket_184 {
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

@ -18,19 +18,16 @@ package com.cnaude.purpleirc.Utilities;
import com.cnaude.purpleirc.PurpleBot;
import com.cnaude.purpleirc.PurpleIRC;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.Packets;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.injector.PacketConstructor;
import com.comphenix.protocol.reflect.FieldAccessException;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.google.common.base.Charsets;
import com.mojang.authlib.GameProfile;
import java.lang.reflect.InvocationTargetException;
import java.util.UUID;
import net.minecraft.server.v1_8_R2.EntityPlayer;
import net.minecraft.server.v1_8_R2.MinecraftServer;
import net.minecraft.server.v1_8_R2.PacketPlayOutPlayerInfo;
import net.minecraft.server.v1_8_R2.PlayerInteractManager;
import org.bukkit.entity.Player;
import org.pircbotx.Channel;
import org.pircbotx.User;
@ -43,6 +40,7 @@ public class NetPackets {
PurpleIRC plugin;
private final ProtocolManager protocolManager;
private PacketConstructor playerListConstructor;
/**
*
@ -63,6 +61,9 @@ public class NetPackets {
if (!plugin.customTabList) {
return;
}
if (isPlayerOnline(name, ircBot, channel.getName())) {
return;
}
String channelName = channel.getName();
if (ircBot.tabIgnoreNicks.containsKey(channelName)) {
for (String s : ircBot.tabIgnoreNicks.get(channelName)) {
@ -112,39 +113,43 @@ public class NetPackets {
String displayName = truncateName(plugin.customTabPrefix + name);
PacketContainer packet = null;
String version = plugin.getServer().getVersion();
if (version.contains("MC: 1.8.3")) {
if (version.contains("MC: 1.7.10")) {
try {
UUID uuid = null; // = plugin.getPlayerUuid(name);
if (uuid == null) {
uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + displayName).getBytes(Charsets.UTF_8));
packet = protocolManager.createPacket(PacketType.Play.Server.PLAYER_INFO);
packet.getIntegers().write(0, (add ? 0 : 4));
packet.getGameProfiles().write(0, new WrappedGameProfile(java.util.UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)), displayName));
packet.getIntegers().write(1, 0);
packet.getIntegers().write(2, 0);
packet.getStrings().write(0, displayName);
} catch (Exception ex) {
plugin.logError("tabPacket: " + ex.getMessage());
}
} else if (version.contains("MC: 1.8.3")) {
try {
if (add) {
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);
return NetPacket_183.add(displayName);
} else {
plugin.logDebug("T: Removing: " + name);
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);
return NetPacket_183.rem(displayName);
}
} catch (Exception ex) {
plugin.logError("tabPacket: " + ex.getMessage());
}
} else if (version.contains("MC: 1.8.4")) {
try {
if (add) {
return NetPacket_184.add(displayName);
} else {
plugin.logDebug("T: Removing: " + name);
return NetPacket_184.rem(displayName);
}
} catch (Exception ex) {
plugin.logError("tabPacket: " + ex.getMessage());
}
} else {
plugin.logDebug("tabPacket: deprecated ");
playerListConstructor = protocolManager.createPacketConstructor(Packets.Server.PLAYER_INFO, "", false, (int) 0);
packet = playerListConstructor.createPacket(displayName, add, 0);
}
return packet;
}
@ -193,4 +198,18 @@ public class NetPackets {
return name;
}
}
private boolean isPlayerOnline(String name, PurpleBot ircBot, String channel) {
if (ircBot.tabIgnoreDuplicates.containsKey(channel)) {
if (ircBot.tabIgnoreDuplicates.get(channel)) {
for (Player player : plugin.getServer().getOnlinePlayers()) {
if (name.equalsIgnoreCase(player.getName())) {
plugin.logDebug("Not adidng to tab list due to player with same name.");
return true;
}
}
}
}
return false;
}
}