update /Disguise for Hub as well

This commit is contained in:
Sarah 2016-01-02 00:53:56 +01:00
parent 8ef1a524c1
commit a30c2b0d75

View File

@ -1,357 +0,0 @@
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;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap;
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.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.EntityHuman;
import net.minecraft.server.v1_8_R3.PacketPlayOutAnimation;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
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.scoreboard.Team;
import com.mojang.authlib.GameProfile;
import com.mysql.jdbc.BalanceStrategy;
public class DisguiseCommand extends CommandBase<HubManager> implements Listener
{
private NautHashMap<Player, GameProfile> _disguisedPlayers = new NautHashMap<>();
private NautHashMap<Player, String> _disguisedPlayersNames = new NautHashMap<>();
private NautHashMap<Player, DisguisePlayer> _disguisedPlayerDisguises = new NautHashMap<>();
public DisguiseCommand(HubManager plugin)
{
super(plugin, Rank.JNR_DEV, new Rank[]
{
Rank.YOUTUBE, Rank.TWITCH }, "disguise");
plugin.getPluginManager().registerEvents(this, Plugin.getPlugin());
new NCPDataManFix();
}
@Override
public void Execute(final Player caller, final String[] args)
{
if(args == null || args.length == 0)
{
if(!Plugin.GetDisguise().isDisguised(caller))
{
UtilPlayer.message(caller, C.cRed + C.Bold + "please use /disguise <name> first");
return;
}
try
{
_disguisedPlayers.remove(caller);
_disguisedPlayerDisguises.remove(caller);
Plugin.GetDisguise().undisguise(caller);
String playerName = _disguisedPlayersNames.get(caller);
CoreClient client = Plugin.GetClients().Get(caller);
client.setDisguisedRank(null);
client.setDisguisedAs(null);
client.setDisguised(false);
changeName(caller, playerName);
for(Player other : UtilServer.getPlayers())
{
for(Team team : other.getScoreboard().getTeams())
{
if(team.hasPlayer(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!");
return;
} catch(Exception ex)
{
ex.printStackTrace();
}
}
if(args != null && args.length > 1)
{
UtilPlayer.message(caller, C.cRed + C.Bold + "/disguise <name>");
return;
}
final Rank rank = Plugin.GetClients().Get(caller).GetRank();
Bukkit.getServer().getScheduler().runTaskAsynchronously(Plugin.getPlugin(), new Runnable()
{
@Override
public void run()
{
if(Plugin.GetDisguise().isDisguised(caller))
{
UtilPlayer.message(caller, C.cRed + C.Bold + "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!");
return;
}
}
if(_disguisedPlayersNames.containsValue(args[0]))
{
UtilPlayer.message(caller, C.cRed + C.Bold + "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]);
return;
}
try
{
CoreClient client = Plugin.GetClients().Get(caller);
UUID uuid = UUIDFetcher.getUUIDOf(args[0]);
GameProfile profile = null;
try
{
profile = new ProfileLoader(uuid.toString(), args[0]).loadProfile();
} catch(Exception e)
{
uuid = UUIDFetcher.getUUIDOf("Alex");
profile = new ProfileLoader(uuid.toString(), args[0]).loadProfile();
}
Rank otherRank = Rank.ALL;
try
{
CoreClient other = new CoreClient(args[0]);
Plugin.GetClients().LoadClient(other, uuid, caller.getAddress().getAddress().getAddress().toString());
otherRank = other.GetRank();
} catch(NullPointerException exception)
{}
if(otherRank.has(Rank.TWITCH) && !rank.has(Rank.OWNER))
{
UtilPlayer.message(caller, C.cRed + C.Bold + "You can't disguise as staff!");
return;
}
_disguisedPlayers.put(caller, profile);
_disguisedPlayersNames.put(caller, caller.getName());
client.setDisguisedRank(otherRank);
client.setDisguised(true);
client.setDisguisedAs(args[0]);
changeName(caller, args[0]);
Plugin.GetGadget().removeGadgetType(caller, GadgetType.Item);
UtilPlayer.message(caller, C.cGreen + C.Bold + "Disguise Active: " + ChatColor.RESET + args[0]);
} catch(Exception e)
{
e.printStackTrace();
UtilPlayer.message(caller, C.cRed + C.Bold + "Invalid Disguise Name: " + ChatColor.RESET + args[0]);
return;
}
}
});
}
@EventHandler
public void updateDisguises(UpdateEvent event)
{
if(event.getType() != UpdateType.FASTEST)
return;
for(final Player player : UtilServer.getPlayers())
{
if(!_disguisedPlayers.containsKey(player))
continue;
for(Player other : UtilServer.getPlayers())
{
try
{
for(Team team : other.getScoreboard().getTeams())
{
if(team.hasPlayer(player))
{
team.removePlayer(player);
}
}
other.getScoreboard().getTeam(Plugin.GetClients().Get(player).getDisguisedRank().Name).addPlayer(player);
} catch(NullPointerException exp)
{}
}
if(Plugin.GetDisguise().isDisguised(player))
continue;
DisguisePlayer playerDisguise = new DisguisePlayer(player, _disguisedPlayers.get(player));
_disguisedPlayerDisguises.put(player, playerDisguise);
Plugin.GetDisguise().disguise(playerDisguise);
}
}
public void changeName(Player player, String changedName)
{
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());
name.setAccessible(true);
name.set(gameProfile, changedName);
name.setAccessible(false);
} catch(Exception ex)
{
ex.printStackTrace();
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void Quit(PlayerQuitEvent event)
{
Player player = event.getPlayer();
if(_disguisedPlayers.containsKey(player))
{
try
{
_disguisedPlayers.remove(player);
_disguisedPlayerDisguises.remove(player);
Plugin.GetDisguise().undisguise(player);
String playerName = _disguisedPlayersNames.get(player);
_disguisedPlayersNames.remove(player);
CoreClient client = Plugin.GetClients().Get(player);
client.setDisguisedRank(null);
client.setDisguisedAs(null);
client.setDisguised(false);
changeName(player, playerName);
} catch(Exception ex)
{
ex.printStackTrace();
}
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void Join(PlayerLoginEvent event)
{
for(Player player : _disguisedPlayers.keySet())
{
if(player.getName().equalsIgnoreCase(event.getPlayer().getName()))
{
event.disallow(Result.KICK_OTHER, "There is already the same account playing. this probably happened because of /disguise");
}
}
}
@EventHandler
public void gadget(GadgetEnableEvent event)
{
if(!event.getGadget().GetName().equalsIgnoreCase("Coin Party Bomb") && event.getGadget().getGadgetType() != GadgetType.Morph)
return;
if(_disguisedPlayers.containsKey(event.getPlayer()))
{
event.setCancelled(true);
}
}
@EventHandler
public void chest(TreasureStartEvent event)
{
if(_disguisedPlayers.containsKey(event.getPlayer()))
{
UtilPlayer.message(event.getPlayer(), F.main("Disguise", "You cant open Treasure Chests while you are disguised!"));
event.setCancelled(true);
}
}
@EventHandler
public void onPlayerSneak(PlayerToggleSneakEvent event)
{
Player player = event.getPlayer();
if(_disguisedPlayers.containsKey(player))
{
DisguisePlayer dp = _disguisedPlayerDisguises.get(player);
dp.setSneaking(!dp.getSneaking());
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void onDPlayerChat(AsyncPlayerChatEvent event)
{
if(_disguisedPlayers.containsKey(event.getPlayer()))
{
event.setFormat(" *" + event.getMessage());
}
}
@EventHandler
public void on(PlayerInteractEvent event)
{
if(event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK)
{
if(_disguisedPlayers.containsKey(event.getPlayer()))
{
Player player = event.getPlayer();
PacketPlayOutAnimation packet = new PacketPlayOutAnimation();
packet.a = player.getEntityId();
for(Player p : Bukkit.getOnlinePlayers())
{
if(p != player)
{
Plugin.getPacketHandler().getPacketVerifier((Player) p).bypassProcess(packet);
}
}
}
}
}
}