updating /disguise

This commit is contained in:
Sarah 2015-12-31 12:01:24 +01:00
parent 55cdf4148a
commit 8ef1a524c1

View File

@ -3,7 +3,6 @@ package nautilus.game.arcade.command;
import java.lang.reflect.Field;
import java.util.UUID;
import mineplex.core.NCPDataManFix;
import mineplex.core.account.CoreClient;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
@ -21,8 +20,21 @@ import mineplex.core.treasure.event.TreasureStartEvent;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.Game.GameState;
import net.minecraft.server.v1_8_R3.ChatComponentText;
import net.minecraft.server.v1_8_R3.EntityHuman;
import net.minecraft.server.v1_8_R3.EntityPlayer;
import net.minecraft.server.v1_8_R3.EnumDifficulty;
import net.minecraft.server.v1_8_R3.IChatBaseComponent;
import net.minecraft.server.v1_8_R3.PacketPlayOutAnimation;
import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo;
import net.minecraft.server.v1_8_R3.WorldType;
import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo.EnumPlayerInfoAction;
import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo.PlayerInfoData;
import net.minecraft.server.v1_8_R3.PacketPlayOutRespawn;
import net.minecraft.server.v1_8_R3.PacketPlayOutWindowData;
import net.minecraft.server.v1_8_R3.PacketPlayOutWorldEvent;
import net.minecraft.server.v1_8_R3.WorldSettings.EnumGamemode;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -52,10 +64,9 @@ public class DisguiseCommand extends CommandBase<ArcadeManager> implements Liste
public DisguiseCommand(ArcadeManager plugin)
{
super(plugin, Rank.JNR_DEV, new Rank[]
{ Rank.YOUTUBE, Rank.TWITCH }, "disguise");
super(plugin, Rank.JNR_DEV, new Rank[] {Rank.YOUTUBE, Rank.TWITCH, Rank.YOUTUBE_SMALL}, "disguise");
plugin.getPluginManager().registerEvents(this, Plugin.getPlugin());
new NCPDataManFix();
}
@Override
@ -65,11 +76,12 @@ public class DisguiseCommand extends CommandBase<ArcadeManager> implements Liste
{
if(!Plugin.GetDisguise().isDisguised(caller))
{
UtilPlayer.message(caller, C.cRed + C.Bold + "please use /disguise <name> first");
UtilPlayer.message(caller, F.main("Disguise", "please use /disguise <name> first"));
return;
}
try
{
GameProfile profile = _disguisedPlayers.get(caller);
_disguisedPlayers.remove(caller);
_disguisedPlayerDisguises.remove(caller);
Plugin.GetDisguise().undisguise(caller);
@ -81,7 +93,28 @@ public class DisguiseCommand extends CommandBase<ArcadeManager> implements Liste
client.setDisguised(false);
changeName(caller, playerName, true);
for(Player other : UtilServer.getPlayers())
updateTabInfo(((CraftPlayer) caller).getProfile(), profile, other, false);
Field field;
try
{
field = GameProfile.class.getDeclaredField("id");
field.setAccessible(true);
UUID old = ((CraftPlayer) caller).getProfile().getId();
UUID newUUID = profile.getId();
field.set(profile, old);
field.set(((CraftPlayer) caller).getProfile(), newUUID);
}
catch(Exception e)
{
e.printStackTrace();
}
PacketPlayOutRespawn packet = new PacketPlayOutRespawn(0, EnumDifficulty.getById(caller.getWorld().getDifficulty().getValue()), WorldType.NORMAL, EnumGamemode.getById(caller.getGameMode().getValue()));
UtilPlayer.sendPacket(caller, packet);
for(Player other : UtilServer.getPlayers())
{
for(Team team : other.getScoreboard().getTeams())
@ -91,7 +124,7 @@ public class DisguiseCommand extends CommandBase<ArcadeManager> implements Liste
other.getScoreboard().getTeam(Plugin.GetClients().Get(caller).GetRank().Name).addPlayer(caller);
}
UtilPlayer.message(caller, C.cRed + C.Bold + "You are no longer disguised!");
UtilPlayer.message(caller, F.main("Disguise", "You are no longer disguised!"));
return;
} catch(Exception ex)
{
@ -100,7 +133,7 @@ public class DisguiseCommand extends CommandBase<ArcadeManager> implements Liste
}
if(args != null && args.length > 1)
{
UtilPlayer.message(caller, C.cRed + C.Bold + "/disguise <name>");
UtilPlayer.message(caller, F.main("Disguise", "/disguise <name>"));
return;
}
@ -111,40 +144,41 @@ public class DisguiseCommand extends CommandBase<ArcadeManager> implements Liste
{
if(Plugin.GetDisguise().isDisguised(caller))
{
UtilPlayer.message(caller, C.cRed + C.Bold + "please use /disguise first");
UtilPlayer.message(caller, F.main("Disguise", "please use /disguise first"));
return;
}
for(Player other : UtilServer.getPlayers())
{
if(other.getName().equalsIgnoreCase(args[0]))
{
UtilPlayer.message(caller, C.cRed + C.Bold + "this name is already in use!");
UtilPlayer.message(caller, C.cRed + F.main("Disguise", "this name is already in use!"));
return;
}
}
if(_disguisedPlayersNames.containsValue(args[0]))
{
UtilPlayer.message(caller, C.cRed + C.Bold + "this name is already in use!");
UtilPlayer.message(caller, C.cRed + F.main("Disguise", "this name is already in use!"));
return;
}
if(args[0].length() > 16)
{
UtilPlayer.message(caller, C.cRed + C.Bold + "Invalid Disguise Name: " + ChatColor.RESET + args[0]);
UtilPlayer.message(caller, F.main("Disguise", "Invalid Disguise Name: " + ChatColor.RESET + args[0]));
return;
}
try
{
CoreClient client = Plugin.GetClients().Get(caller);
UUID uuid = UUIDFetcher.getUUIDOf(args[0]);
UUID uuid = UUID.randomUUID();
GameProfile profile = null;
try
{
uuid = UUIDFetcher.getUUIDOf(args[0]);
profile = new ProfileLoader(uuid.toString(), args[0]).loadProfile();
} catch(Exception e)
} catch (Exception e)
{
uuid = UUIDFetcher.getUUIDOf("Alex");
profile = new ProfileLoader(uuid.toString(), args[0]).loadProfile();
uuid = UUID.randomUUID();
profile = new ProfileLoader(null, args[0]).loadProfile();
}
Rank otherRank = Rank.ALL;
@ -157,7 +191,7 @@ public class DisguiseCommand extends CommandBase<ArcadeManager> implements Liste
{}
if(otherRank.has(Rank.TWITCH))
{
UtilPlayer.message(caller, C.cRed + C.Bold + "You can't disguise as staff!");
UtilPlayer.message(caller, F.main("Disguise", "You can't disguise as staff!"));
return;
}
_disguisedPlayers.put(caller, profile);
@ -172,16 +206,100 @@ public class DisguiseCommand extends CommandBase<ArcadeManager> implements Liste
Plugin.getCosmeticManager().getGadgetManager().removeGadgetType(caller, GadgetType.Item);
Bukkit.broadcastMessage(ChatColor.DARK_GRAY + "Quit> " + ChatColor.GRAY + _disguisedPlayersNames.get(caller));
UtilPlayer.message(caller, C.cGreen + C.Bold + "Disguise Active: " + ChatColor.RESET + args[0]);
UtilPlayer.message(caller, F.main("Disguise", "Disguise Active: " + ChatColor.RESET + args[0]));
Field field;
try
{
field = GameProfile.class.getDeclaredField("id");
field.setAccessible(true);
UUID old = ((CraftPlayer) caller).getProfile().getId();
UUID newUUID = profile.getId();
field.set(profile, old);
field.set(((CraftPlayer) caller).getProfile(), newUUID);
}
catch(Exception e)
{
e.printStackTrace();
}
PacketPlayOutRespawn packet = new PacketPlayOutRespawn(0, EnumDifficulty.getById(caller.getWorld().getDifficulty().getValue()), WorldType.NORMAL, EnumGamemode.getById(caller.getGameMode().getValue()));
UtilPlayer.sendPacket(caller, packet);
tablistRefresh(caller);
} catch(Exception e)
{
e.printStackTrace();
UtilPlayer.message(caller, C.cRed + C.Bold + "Invalid Disguise Name: " + ChatColor.RESET + args[0]);
UtilPlayer.message(caller, F.main("Disguise", "Invalid Disguise Name: " + ChatColor.RESET + args[0]));
return;
}
}
});
}
@EventHandler
public void refreshTabNames(UpdateEvent event)
{
if(event.getType() != UpdateType.FAST)
return;
for(Player player : _disguisedPlayers.keySet())
{
if(!player.isOnline())
return;
tablistRefresh(player);
}
}
public void tablistRefresh(Player player)
{
for (Player other : UtilServer.getPlayers())
{
if (player.canSee(other))
{
updateTabInfo(_disguisedPlayers.get(player), ((CraftPlayer) player).getProfile(), other, false);
}
}
}
public void updateTabInfo(GameProfile profileToAdd, GameProfile profileToRemove, Player target, boolean refreshOnly)
{
ChatColor team = ChatColor.WHITE;
Player player = Bukkit.getPlayer(profileToAdd.getName());
EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
if(Plugin.GetGame().GetTeam(player) != null)
{
team = Plugin.GetGame().GetTeam(player).GetColor();
}
String tag = Plugin.GetClients().Get(player).GetRank().getTag(true, true) + " ";
if(Plugin.GetClients().Get(player).isDisguised())
{
tag = Plugin.GetClients().Get(player).getDisguisedRank().getTag(true, true) + " ";
}
if(Plugin.GetGame().GetState() != GameState.Recruit)
tag = "";
IChatBaseComponent component = new ChatComponentText(tag + team + player.getName());
if(!refreshOnly)
{
PacketPlayOutPlayerInfo removePacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER);
PlayerInfoData removeData = removePacket.new PlayerInfoData(profileToRemove, entityPlayer.ping, EnumGamemode.SURVIVAL, component);
removePacket.b.add(removeData);
UtilPlayer.sendPacket(target, removePacket);
PacketPlayOutPlayerInfo addPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER);
PlayerInfoData addData = addPacket.new PlayerInfoData(profileToAdd, entityPlayer.ping, EnumGamemode.SURVIVAL, component);
addPacket.b.add(addData);
UtilPlayer.sendPacket(target, addPacket);
}
PacketPlayOutPlayerInfo updatePacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.UPDATE_DISPLAY_NAME);
PlayerInfoData updateData = updatePacket.new PlayerInfoData(profileToAdd, entityPlayer.ping, EnumGamemode.SURVIVAL, component);
updatePacket.b.add(updateData);
UtilPlayer.sendPacket(target, updatePacket);
}
@EventHandler
public void updateDisguises(UpdateEvent event)