diff --git a/Plugins/Mineplex.Core/src/mineplex/core/disguise/DisguisePlayerBean.java b/Plugins/Mineplex.Core/src/mineplex/core/disguise/DisguisePlayerBean.java new file mode 100644 index 000000000..3403768bb --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/disguise/DisguisePlayerBean.java @@ -0,0 +1,34 @@ +package mineplex.core.disguise; + +import mineplex.serverdata.data.Data; + +public class DisguisePlayerBean implements Data +{ + private int _accountID; + private String _disguisedPlayer; + private String _playerName; + public DisguisePlayerBean(int playerAccountID, String playerName, String disguiseAs) + { + this._accountID = playerAccountID; + this._disguisedPlayer = disguiseAs; + this._playerName = playerName; + + } + public int getAccountID() + { + return _accountID; + } + public String getDisguisedPlayer() + { + return _disguisedPlayer; + } + public String getPlayerName() + { + return _playerName; + } + @Override + public String getDataId() + { + return _accountID+_playerName; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/disguise/PlayerDisguiseManager.java b/Plugins/Mineplex.Core/src/mineplex/core/disguise/PlayerDisguiseManager.java new file mode 100644 index 000000000..d7edc247a --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/disguise/PlayerDisguiseManager.java @@ -0,0 +1,68 @@ +package mineplex.core.disguise; + +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitRunnable; + +import mineplex.core.MiniPlugin; +import mineplex.core.account.CoreClient; +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.Rank; +import mineplex.serverdata.Region; +import mineplex.serverdata.redis.RedisDataRepository; + +public class PlayerDisguiseManager extends MiniPlugin +{ + private CoreClientManager _clients; + private RedisDataRepository _redis; + public PlayerDisguiseManager(JavaPlugin plugin, CoreClientManager clients) + { + super("Player Disguise Manager", plugin); + this._clients = clients; + + _redis = new RedisDataRepository(Region.ALL, DisguisePlayerBean.class, "disguisedPlayer"); + } + + @EventHandler + public void onDisguisedPlayerQuit(PlayerQuitEvent event) + { + CoreClient client = _clients.Get(event.getPlayer()); + if(client.isDisguised()) + { + _redis.addElement(new DisguisePlayerBean(client.getAccountId(), client.GetPlayerName(), client.getDisguisedAs()), 60*60*12); // 12 hours + } + } + + @EventHandler + public void onDisguisedPlayerJoin(PlayerJoinEvent event) + { + new BukkitRunnable() + { + @Override + public void run() + { + CoreClient client = _clients.Get(event.getPlayer()); + + if(!client.GetRank().has(Rank.JNR_DEV) && client.GetRank() != Rank.YOUTUBE_SMALL && client.GetRank() != Rank.TWITCH && client.GetRank() != Rank.YOUTUBE) + return; + + if(_redis.elementExists(client.getAccountId()+client.GetPlayerName())) + { + DisguisePlayerBean bean = _redis.getElement(client.getAccountId()+client.GetPlayerName()); + Bukkit.getPluginManager().callEvent(new PlayerCommandPreprocessEvent(event.getPlayer(), "/Disguise " + bean.getDisguisedPlayer())); + } + } + }.runTaskLater(getPlugin(), 7); + } + + @EventHandler + public void onPlayerUndisguise(PlayerUndisguiseEvent event) + { + CoreClient client = _clients.Get(event.getPlayer()); + _redis.removeElement(client.getAccountId()+client.GetPlayerName()); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/disguise/PlayerUndisguiseEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/disguise/PlayerUndisguiseEvent.java new file mode 100644 index 000000000..ad8d9a9d0 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/disguise/PlayerUndisguiseEvent.java @@ -0,0 +1,31 @@ +package mineplex.core.disguise; + +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class PlayerUndisguiseEvent extends Event +{ + private static final HandlerList handlers = new HandlerList(); + private Player _player; + public PlayerUndisguiseEvent(Player disguisee) + { + this._player = disguisee; + } + + public Player getPlayer() + { + return _player; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/message/commands/AdminCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/message/commands/AdminCommand.java index 5735a2dc4..f9c2242d1 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/message/commands/AdminCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/message/commands/AdminCommand.java @@ -10,6 +10,7 @@ import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.message.MessageManager; +import mineplex.core.visibility.VisibilityManager; public class AdminCommand extends CommandBase { @@ -52,7 +53,12 @@ public class AdminCommand extends CommandBase { if (!to.equals(caller)) UtilPlayer.message(to, F.rank(Plugin.GetClientManager().Get(caller).GetRank()) + " " + caller.getName() + " " + C.cPurple + message); - + + if(Plugin.GetClientManager().Get(to).GetRank().has(Rank.JNR_DEV)) + { + if(Plugin.GetClientManager().Get(to).isDisguised() || !caller.canSee(to)) + continue; + } staff = true; //Sound diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index 55d00076d..24be3b3dc 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -33,6 +33,7 @@ import mineplex.core.common.util.UtilWorld; import mineplex.core.cosmetic.CosmeticManager; import mineplex.core.customdata.CustomDataManager; import mineplex.core.disguise.DisguiseManager; +import mineplex.core.disguise.PlayerDisguiseManager; import mineplex.core.disguise.disguises.DisguiseSlime; import mineplex.core.donation.DonationManager; import mineplex.core.gadget.GadgetManager; @@ -249,7 +250,7 @@ public class HubManager extends MiniClientPlugin // _halloweenManager = new HalloweenSpookinessManager(this); new HolidayGiftManager(plugin, clientManager, donationManager, inventoryManager, taskManager); - + new PlayerDisguiseManager(plugin, _clientManager); // NotificationManager notificationManager = new NotificationManager(plugin, clientManager, donationManager); // new MailManager(_plugin, notificationManager); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/DisguiseCommand.java b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/DisguiseCommand.java index bb078b3bb..a74c4e858 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/DisguiseCommand.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/DisguiseCommand.java @@ -3,7 +3,6 @@ package mineplex.hub.commands; 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; @@ -14,17 +13,26 @@ import mineplex.core.common.util.ProfileLoader; import mineplex.core.common.util.UUIDFetcher; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; +import mineplex.core.disguise.PlayerUndisguiseEvent; import mineplex.core.disguise.disguises.DisguisePlayer; -import mineplex.core.donation.Donor; import mineplex.core.gadget.event.GadgetEnableEvent; -import mineplex.core.gadget.types.Gadget; import mineplex.core.gadget.types.GadgetType; import mineplex.core.treasure.event.TreasureStartEvent; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.hub.HubManager; +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.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.WorldSettings.EnumGamemode; +import net.minecraft.server.v1_8_R3.WorldType; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -38,13 +46,12 @@ import org.bukkit.event.block.Action; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerLoginEvent; -import org.bukkit.event.player.PlayerToggleSneakEvent; import org.bukkit.event.player.PlayerLoginEvent.Result; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerToggleSneakEvent; import org.bukkit.scoreboard.Team; import com.mojang.authlib.GameProfile; -import com.mysql.jdbc.BalanceStrategy; public class DisguiseCommand extends CommandBase implements Listener { @@ -55,11 +62,9 @@ public class DisguiseCommand extends CommandBase implements Listener public DisguiseCommand(HubManager 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 @@ -69,36 +74,56 @@ public class DisguiseCommand extends CommandBase implements Listener { 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; } try { + GameProfile profile = _disguisedPlayers.get(caller); _disguisedPlayers.remove(caller); _disguisedPlayerDisguises.remove(caller); Plugin.GetDisguise().undisguise(caller); String playerName = _disguisedPlayersNames.get(caller); + Plugin.getPluginManager().callEvent(new PlayerUndisguiseEvent(caller)); CoreClient client = Plugin.GetClients().Get(caller); client.setDisguisedRank(null); client.setDisguisedAs(null); client.setDisguised(false); - changeName(caller, playerName); + 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()) { - if(team.hasPlayer(caller)) - { - team.removePlayer(caller); - } + team.removePlayer(caller); } 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) { @@ -107,12 +132,10 @@ public class DisguiseCommand extends CommandBase implements Listener } if(args != null && args.length > 1) { - UtilPlayer.message(caller, C.cRed + C.Bold + "/disguise "); + UtilPlayer.message(caller, F.main("Disguise", "/disguise ")); return; } - final Rank rank = Plugin.GetClients().Get(caller).GetRank(); - Bukkit.getServer().getScheduler().runTaskAsynchronously(Plugin.getPlugin(), new Runnable() { @Override @@ -120,40 +143,41 @@ public class DisguiseCommand extends CommandBase implements Listener { 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; @@ -164,9 +188,9 @@ public class DisguiseCommand extends CommandBase implements Listener otherRank = other.GetRank(); } catch(NullPointerException exception) {} - if(otherRank.has(Rank.TWITCH) && !rank.has(Rank.OWNER)) + 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, Youtubers or Twitchers!")); return; } _disguisedPlayers.put(caller, profile); @@ -176,20 +200,99 @@ public class DisguiseCommand extends CommandBase implements Listener client.setDisguisedAs(args[0]); - changeName(caller, args[0]); + changeName(caller, args[0], true); Plugin.GetGadget().removeGadgetType(caller, GadgetType.Item); - UtilPlayer.message(caller, C.cGreen + C.Bold + "Disguise Active: " + ChatColor.RESET + args[0]); + Bukkit.broadcastMessage(ChatColor.DARK_GRAY + "Quit> " + ChatColor.GRAY + _disguisedPlayersNames.get(caller)); + 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(); + 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) + " "; + } + + 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) @@ -206,15 +309,11 @@ public class DisguiseCommand extends CommandBase implements Listener { try { - for(Team team : other.getScoreboard().getTeams()) + if(other.getScoreboard().getTeam(Plugin.GetClients().Get(player).GetRank().Name).getPlayers().contains(player)) { - if(team.hasPlayer(player)) - { - team.removePlayer(player); - } + other.getScoreboard().getTeam(Plugin.GetClients().Get(player).GetRank().Name).removePlayer(player); + other.getScoreboard().getTeam(Plugin.GetClients().Get(player).getDisguisedRank().Name).addPlayer(player); } - other.getScoreboard().getTeam(Plugin.GetClients().Get(player).getDisguisedRank().Name).addPlayer(player); - } catch(NullPointerException exp) {} } @@ -228,18 +327,17 @@ public class DisguiseCommand extends CommandBase implements Listener } } - public void changeName(Player player, String changedName) + public void changeName(final Player player, String changedName, boolean skin) { try { - Field name = GameProfile.class.getDeclaredField("name"); - Field declaredProfile = EntityHuman.class.getDeclaredField("bH"); - declaredProfile.setAccessible(true); - GameProfile gameProfile = (GameProfile) declaredProfile.get(((CraftHumanEntity) ((CraftPlayer) player)).getHandle()); + GameProfile gameProfile = ((CraftPlayer) player).getProfile(); + Field name = GameProfile.class.getDeclaredField("name"); name.setAccessible(true); name.set(gameProfile, changedName); name.setAccessible(false); + } catch(Exception ex) { ex.printStackTrace(); @@ -266,7 +364,7 @@ public class DisguiseCommand extends CommandBase implements Listener client.setDisguisedAs(null); client.setDisguised(false); - changeName(player, playerName); + changeName(player, playerName, true); } catch(Exception ex) { ex.printStackTrace(); @@ -321,6 +419,21 @@ public class DisguiseCommand extends CommandBase implements Listener } } + @EventHandler + public void onPlayerLeftClick(PlayerInteractEvent event) + { + Player player = event.getPlayer(); + + if(event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) + { + if(_disguisedPlayers.containsKey(player)) + { + EntityHuman human = (((CraftHumanEntity) ((CraftPlayer) player)).getHandle()); + human.world.broadcastEntityEffect(human, (byte) 0); + } + } + } + @EventHandler(priority = EventPriority.LOWEST) public void onDPlayerChat(AsyncPlayerChatEvent event) { @@ -353,5 +466,4 @@ public class DisguiseCommand extends CommandBase implements Listener } } } - } diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/RedisDataRepository.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/RedisDataRepository.java index a49de5b64..caea6188b 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/RedisDataRepository.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/RedisDataRepository.java @@ -55,6 +55,7 @@ public class RedisDataRepository implements DataRepository _region = region; _elementType = elementType; _elementLabel = elementLabel; + } public RedisDataRepository(ConnectionData conn, Region region, Class elementType, String elementLabel) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java index 943be1a3e..db787f98e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -3,6 +3,7 @@ package nautilus.game.arcade; import java.io.File; import java.util.ArrayList; import java.util.HashSet; + import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.GameMode; @@ -51,6 +52,7 @@ import mineplex.core.cosmetic.CosmeticManager; import mineplex.core.creature.Creature; import mineplex.core.customdata.CustomDataManager; import mineplex.core.disguise.DisguiseManager; +import mineplex.core.disguise.PlayerDisguiseManager; import mineplex.core.donation.DonationManager; import mineplex.core.elo.EloManager; import mineplex.core.energy.Energy; @@ -291,6 +293,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation TitanGiveawayManager titanGiveaway = new TitanGiveawayManager(getPlugin(), clientManager, serverStatusManager); new HolidayManager(this, titanGiveaway); new GameTestingManager(this); + new PlayerDisguiseManager(plugin, _clientManager); // Game Addons new CompassAddon(plugin, this); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/DisguiseCommand.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/DisguiseCommand.java index 7111ae370..873adf239 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/DisguiseCommand.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/command/DisguiseCommand.java @@ -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; @@ -14,6 +13,7 @@ import mineplex.core.common.util.ProfileLoader; import mineplex.core.common.util.UUIDFetcher; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; +import mineplex.core.disguise.PlayerUndisguiseEvent; import mineplex.core.disguise.disguises.DisguisePlayer; import mineplex.core.gadget.event.GadgetEnableEvent; import mineplex.core.gadget.types.GadgetType; @@ -21,8 +21,19 @@ 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.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.WorldSettings.EnumGamemode; +import net.minecraft.server.v1_8_R3.WorldType; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -52,10 +63,9 @@ public class DisguiseCommand extends CommandBase 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,15 +75,17 @@ public class DisguiseCommand extends CommandBase 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; } try { + GameProfile profile = _disguisedPlayers.get(caller); _disguisedPlayers.remove(caller); _disguisedPlayerDisguises.remove(caller); Plugin.GetDisguise().undisguise(caller); String playerName = _disguisedPlayersNames.get(caller); + Plugin.getPluginManager().callEvent(new PlayerUndisguiseEvent(caller)); CoreClient client = Plugin.GetClients().Get(caller); client.setDisguisedRank(null); @@ -81,7 +93,28 @@ public class DisguiseCommand extends CommandBase 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 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 implements Liste } if(args != null && args.length > 1) { - UtilPlayer.message(caller, C.cRed + C.Bold + "/disguise "); + UtilPlayer.message(caller, F.main("Disguise", "/disguise ")); return; } @@ -111,40 +144,41 @@ public class DisguiseCommand extends CommandBase 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 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, Youtubers or Twitchers!")); return; } _disguisedPlayers.put(caller, profile); @@ -172,16 +206,100 @@ public class DisguiseCommand extends CommandBase 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)