Added Hat layer skin
Added Sneak animation With love from Morten <3
This commit is contained in:
parent
d8041ba582
commit
1680b652db
@ -2,140 +2,152 @@ package mineplex.core.disguise.disguises;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.spigotmc.ProtocolData;
|
||||
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import net.minecraft.server.v1_7_R4.MathHelper;
|
||||
import net.minecraft.server.v1_7_R4.Packet;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayInSettings;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutNamedEntitySpawn;
|
||||
import net.minecraft.server.v1_7_R4.PacketPlayOutPlayerInfo;
|
||||
import net.minecraft.util.com.mojang.authlib.GameProfile;
|
||||
|
||||
public class DisguisePlayer extends DisguiseHuman
|
||||
{
|
||||
private GameProfile _profile;
|
||||
private boolean _sneaking;
|
||||
private BlockFace _sleeping;
|
||||
private GameProfile _profile;
|
||||
private boolean _sneaking;
|
||||
private BlockFace _sleeping;
|
||||
|
||||
public DisguisePlayer(org.bukkit.entity.Entity entity)
|
||||
public DisguisePlayer(org.bukkit.entity.Entity entity)
|
||||
{
|
||||
super(entity);
|
||||
}
|
||||
|
||||
public DisguisePlayer(org.bukkit.entity.Entity entity, GameProfile profile)
|
||||
{
|
||||
this(entity);
|
||||
|
||||
setProfile(profile);
|
||||
}
|
||||
|
||||
public void setProfile(GameProfile profile)
|
||||
{
|
||||
GameProfile newProfile = new GameProfile(UUID.randomUUID(), profile.getName());
|
||||
|
||||
newProfile.getProperties().putAll(profile.getProperties());
|
||||
|
||||
_profile = newProfile;
|
||||
}
|
||||
|
||||
public BlockFace getSleepingDirection()
|
||||
{
|
||||
return _sleeping;
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't use this if the disguise is already on as it will not work the way
|
||||
* you want it to. Contact libraryaddict if you need that added.
|
||||
*/
|
||||
public void setSleeping(BlockFace sleeping)
|
||||
{
|
||||
_sleeping = sleeping;
|
||||
}
|
||||
|
||||
public void setSneaking(boolean sneaking)
|
||||
{
|
||||
_sneaking = sneaking;
|
||||
}
|
||||
|
||||
public boolean getSneaking()
|
||||
{
|
||||
return _sneaking;
|
||||
}
|
||||
|
||||
public Packet getOldInfoPacket(boolean add)
|
||||
{
|
||||
PacketPlayOutPlayerInfo playerInfo = new PacketPlayOutPlayerInfo();
|
||||
|
||||
if(Entity instanceof Player)
|
||||
{
|
||||
super(entity);
|
||||
playerInfo.username = Entity.getName();
|
||||
playerInfo.action = add ? 0 : 4;
|
||||
playerInfo.ping = 90;
|
||||
playerInfo.player = ((CraftPlayer) (Player) Entity).getProfile();
|
||||
playerInfo.gamemode = 0;
|
||||
}
|
||||
|
||||
public DisguisePlayer(org.bukkit.entity.Entity entity, GameProfile profile)
|
||||
{
|
||||
this(entity);
|
||||
return playerInfo;
|
||||
}
|
||||
|
||||
setProfile(profile);
|
||||
}
|
||||
public Packet getNewInfoPacket(boolean add)
|
||||
{
|
||||
PacketPlayOutPlayerInfo newDisguiseInfo = new PacketPlayOutPlayerInfo();
|
||||
newDisguiseInfo.username = _profile.getName();
|
||||
newDisguiseInfo.action = add ? 0 : 4;
|
||||
newDisguiseInfo.ping = 90;
|
||||
newDisguiseInfo.player = _profile;
|
||||
newDisguiseInfo.gamemode = 0;
|
||||
|
||||
public void setProfile(GameProfile profile)
|
||||
{
|
||||
GameProfile newProfile = new GameProfile(UUID.randomUUID(), profile.getName());
|
||||
return newDisguiseInfo;
|
||||
}
|
||||
|
||||
newProfile.getProperties().putAll(profile.getProperties());
|
||||
@SuppressWarnings("static-access")
|
||||
@Override
|
||||
public void UpdateDataWatcher()
|
||||
{
|
||||
super.UpdateDataWatcher();
|
||||
|
||||
_profile = newProfile;
|
||||
}
|
||||
byte b0 = DataWatcher.getByte(0);
|
||||
DataWatcher.watch(10, (Object)(byte)0x40);
|
||||
|
||||
if(_sneaking)
|
||||
DataWatcher.watch(0, Byte.valueOf((byte) (b0 | 1 << 1)));
|
||||
else
|
||||
DataWatcher.watch(0, Byte.valueOf((byte) (b0 & ~(1 << 1))));
|
||||
}
|
||||
|
||||
public BlockFace getSleepingDirection()
|
||||
{
|
||||
return _sleeping;
|
||||
}
|
||||
public PacketPlayOutNamedEntitySpawn spawnBeforePlayer(Location spawnLocation)
|
||||
{
|
||||
Location loc = spawnLocation.add(spawnLocation.getDirection().normalize().multiply(30));
|
||||
loc.setY(Math.max(loc.getY(), 0));
|
||||
|
||||
/**
|
||||
* Don't use this if the disguise is already on as it will not work the way you want it to. Contact libraryaddict if you need
|
||||
* that added.
|
||||
*/
|
||||
public void setSleeping(BlockFace sleeping)
|
||||
{
|
||||
_sleeping = sleeping;
|
||||
}
|
||||
PacketPlayOutNamedEntitySpawn packet = new PacketPlayOutNamedEntitySpawn();
|
||||
packet.a = Entity.getId();
|
||||
packet.b = _profile;
|
||||
packet.c = MathHelper.floor(loc.getX() * 32.0D);
|
||||
packet.d = MathHelper.floor(loc.getY() * 32.0D);
|
||||
packet.e = MathHelper.floor(loc.getZ() * 32.0D);
|
||||
packet.f = (byte) ((int) (loc.getYaw() * 256.0F / 360.0F));
|
||||
packet.g = (byte) ((int) (loc.getPitch() * 256.0F / 360.0F));
|
||||
packet.i = DataWatcher;
|
||||
|
||||
public void setSneaking(boolean sneaking)
|
||||
{
|
||||
_sneaking = sneaking;
|
||||
}
|
||||
return packet;
|
||||
}
|
||||
|
||||
public Packet getOldInfoPacket(boolean add)
|
||||
{
|
||||
PacketPlayOutPlayerInfo playerInfo = new PacketPlayOutPlayerInfo();
|
||||
@Override
|
||||
public PacketPlayOutNamedEntitySpawn GetSpawnPacket()
|
||||
{
|
||||
PacketPlayOutNamedEntitySpawn packet = new PacketPlayOutNamedEntitySpawn();
|
||||
packet.a = Entity.getId();
|
||||
packet.b = _profile;
|
||||
packet.c = MathHelper.floor(Entity.locX * 32.0D);
|
||||
packet.d = MathHelper.floor(Entity.locY * 32.0D);
|
||||
packet.e = MathHelper.floor(Entity.locZ * 32.0D);
|
||||
packet.f = (byte) ((int) (Entity.yaw * 256.0F / 360.0F));
|
||||
packet.g = (byte) ((int) (Entity.pitch * 256.0F / 360.0F));
|
||||
packet.i = DataWatcher;
|
||||
|
||||
if (Entity instanceof Player)
|
||||
{
|
||||
playerInfo.username = Entity.getName();
|
||||
playerInfo.action = add ? 0 : 4;
|
||||
playerInfo.ping = 90;
|
||||
playerInfo.player = ((CraftPlayer) (Player) Entity).getProfile();
|
||||
playerInfo.gamemode = 0;
|
||||
}
|
||||
return packet;
|
||||
}
|
||||
|
||||
return playerInfo;
|
||||
}
|
||||
|
||||
public Packet getNewInfoPacket(boolean add)
|
||||
{
|
||||
PacketPlayOutPlayerInfo newDisguiseInfo = new PacketPlayOutPlayerInfo();
|
||||
newDisguiseInfo.username = _profile.getName();
|
||||
newDisguiseInfo.action = add ? 0 : 4;
|
||||
newDisguiseInfo.ping = 90;
|
||||
newDisguiseInfo.player = _profile;
|
||||
newDisguiseInfo.gamemode = 0;
|
||||
|
||||
return newDisguiseInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void UpdateDataWatcher()
|
||||
{
|
||||
super.UpdateDataWatcher();
|
||||
|
||||
byte b0 = DataWatcher.getByte(0);
|
||||
|
||||
if (_sneaking)
|
||||
DataWatcher.watch(0, Byte.valueOf((byte) (b0 | 1 << 1)));
|
||||
else
|
||||
DataWatcher.watch(0, Byte.valueOf((byte) (b0 & ~(1 << 1))));
|
||||
}
|
||||
|
||||
public PacketPlayOutNamedEntitySpawn spawnBeforePlayer(Location spawnLocation)
|
||||
{
|
||||
Location loc = spawnLocation.add(spawnLocation.getDirection().normalize().multiply(30));
|
||||
loc.setY(Math.max(loc.getY(), 0));
|
||||
|
||||
PacketPlayOutNamedEntitySpawn packet = new PacketPlayOutNamedEntitySpawn();
|
||||
packet.a = Entity.getId();
|
||||
packet.b = _profile;
|
||||
packet.c = MathHelper.floor(loc.getX() * 32.0D);
|
||||
packet.d = MathHelper.floor(loc.getY() * 32.0D);
|
||||
packet.e = MathHelper.floor(loc.getZ() * 32.0D);
|
||||
packet.f = (byte) ((int) (loc.getYaw() * 256.0F / 360.0F));
|
||||
packet.g = (byte) ((int) (loc.getPitch() * 256.0F / 360.0F));
|
||||
packet.i = DataWatcher;
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketPlayOutNamedEntitySpawn GetSpawnPacket()
|
||||
{
|
||||
PacketPlayOutNamedEntitySpawn packet = new PacketPlayOutNamedEntitySpawn();
|
||||
packet.a = Entity.getId();
|
||||
packet.b = _profile;
|
||||
packet.c = MathHelper.floor(Entity.locX * 32.0D);
|
||||
packet.d = MathHelper.floor(Entity.locY * 32.0D);
|
||||
packet.e = MathHelper.floor(Entity.locZ * 32.0D);
|
||||
packet.f = (byte) ((int) (Entity.yaw * 256.0F / 360.0F));
|
||||
packet.g = (byte) ((int) (Entity.pitch * 256.0F / 360.0F));
|
||||
packet.i = DataWatcher;
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return _profile.getName();
|
||||
}
|
||||
public String getName()
|
||||
{
|
||||
return _profile.getName();
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
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;
|
||||
@ -43,263 +44,274 @@ 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<>();
|
||||
|
||||
public DisguiseCommand(HubManager plugin)
|
||||
|
||||
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)
|
||||
{
|
||||
super(plugin, Rank.JNR_DEV, new Rank[]{Rank.YOUTUBE, Rank.TWITCH}, "disguise");
|
||||
plugin.getPluginManager().registerEvents(this, Plugin.getPlugin());
|
||||
new NCPDataManFix();
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Execute(final Player caller, final String[] args)
|
||||
{
|
||||
if (args == null)
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(Plugin.getPlugin(), new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if(Plugin.GetDisguise().isDisguised(caller))
|
||||
{
|
||||
if(!Plugin.GetDisguise().isDisguised(caller))
|
||||
{
|
||||
UtilPlayer.message(caller, C.cRed + C.Bold + "please use /disguise <name> first");
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
_disguisedPlayers.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();
|
||||
}
|
||||
UtilPlayer.message(caller, C.cRed + C.Bold + "please use /disguise first");
|
||||
return;
|
||||
}
|
||||
if (args != null && args.length > 1)
|
||||
for(Player other : UtilServer.getPlayers())
|
||||
{
|
||||
UtilPlayer.message(caller, C.cRed + C.Bold + "/disguise <name>");
|
||||
if(other.getName().equalsIgnoreCase(args[0]))
|
||||
{
|
||||
UtilPlayer.message(caller, C.cRed + C.Bold + "this name is already in use!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(Plugin.getPlugin(), new Runnable()
|
||||
if(_disguisedPlayersNames.containsValue(args[0]))
|
||||
{
|
||||
@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))
|
||||
{
|
||||
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().RemoveItem(caller);
|
||||
|
||||
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())
|
||||
UtilPlayer.message(caller, C.cRed + C.Bold + "this name is already in use!");
|
||||
return;
|
||||
}
|
||||
if(args[0].length() > 16)
|
||||
{
|
||||
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;
|
||||
UtilPlayer.message(caller, C.cRed + C.Bold + "Invalid Disguise Name: " + ChatColor.RESET + args[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
DisguisePlayer playerDisguise = new DisguisePlayer(player, _disguisedPlayers.get(player));
|
||||
Plugin.GetDisguise().disguise(playerDisguise);
|
||||
}
|
||||
}
|
||||
|
||||
public void changeName(Player player , String changedName)
|
||||
{
|
||||
try
|
||||
{
|
||||
Field name = GameProfile.class.getDeclaredField("name");
|
||||
Field declaredProfile = EntityHuman.class.getDeclaredField("i");
|
||||
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);
|
||||
Plugin.GetDisguise().undisguise(player);
|
||||
String playerName = _disguisedPlayersNames.get(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(GadgetActivateEvent event)
|
||||
{
|
||||
if(!event.getGadget().GetName().equalsIgnoreCase("Coin Party Bomb") && event.getGadget().getGadgetType() != GadgetType.Morph)
|
||||
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))
|
||||
{
|
||||
UtilPlayer.message(caller, C.cRed + C.Bold + "You can't disguise as staff!");
|
||||
return;
|
||||
|
||||
if(_disguisedPlayers.containsKey(event.getPlayer()))
|
||||
}
|
||||
_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().RemoveItem(caller);
|
||||
|
||||
UtilPlayer.message(caller, C.cGreen + C.Bold + "Disguise Active: " + ChatColor.RESET + args[0]);
|
||||
} catch(Exception e)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
e.printStackTrace();
|
||||
UtilPlayer.message(caller, C.cRed + C.Bold + "Invalid Disguise Name: " + ChatColor.RESET + args[0]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void chest(TreasureStartEvent event)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void updateDisguises(UpdateEvent event)
|
||||
{
|
||||
if(event.getType() != UpdateType.FASTEST)
|
||||
return;
|
||||
|
||||
for(final Player player : UtilServer.getPlayers())
|
||||
{
|
||||
if(_disguisedPlayers.containsKey(event.getPlayer()))
|
||||
if(!_disguisedPlayers.containsKey(player))
|
||||
continue;
|
||||
|
||||
for(Player other : UtilServer.getPlayers())
|
||||
{
|
||||
try
|
||||
{
|
||||
UtilPlayer.message(event.getPlayer(), F.main("Disguise", "You cant open Treasure Chests while you are disguised!"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
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("i");
|
||||
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);
|
||||
_disguisedPlayersNames.remove(player);
|
||||
Plugin.GetDisguise().undisguise(player);
|
||||
String playerName = _disguisedPlayersNames.get(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(GadgetActivateEvent 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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,11 +1,7 @@
|
||||
package nautilus.game.arcade.command;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Scanner;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import mineplex.core.NCPDataManFix;
|
||||
import mineplex.core.account.CoreClient;
|
||||
@ -25,282 +21,319 @@ import mineplex.core.treasure.event.TreasureStartEvent;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import nautilus.game.arcade.ArcadeManager;
|
||||
import net.minecraft.server.v1_7_R4.EntityHuman;
|
||||
import net.minecraft.util.com.mojang.authlib.GameProfile;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.v1_7_R4.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.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
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 org.jooq.tools.json.JSONArray;
|
||||
import org.jooq.tools.json.JSONObject;
|
||||
import org.jooq.tools.json.JSONParser;
|
||||
|
||||
public class DisguiseCommand extends CommandBase<ArcadeManager> implements Listener
|
||||
{
|
||||
|
||||
private NautHashMap<Player, GameProfile> _disguisedPlayers = new NautHashMap<>();
|
||||
private NautHashMap<Player, String> _disguisedPlayersNames = new NautHashMap<>();
|
||||
|
||||
public DisguiseCommand(ArcadeManager plugin)
|
||||
|
||||
private NautHashMap<Player, GameProfile> _disguisedPlayers = new NautHashMap<>();
|
||||
private NautHashMap<Player, String> _disguisedPlayersNames = new NautHashMap<>();
|
||||
private NautHashMap<Player, DisguisePlayer> _disguisedPlayerDisguises = new NautHashMap<>();
|
||||
|
||||
public DisguiseCommand(ArcadeManager 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)
|
||||
{
|
||||
super(plugin, Rank.JNR_DEV, new Rank[]{Rank.YOUTUBE, Rank.TWITCH}, "disguise");
|
||||
plugin.getPluginManager().registerEvents(this, Plugin.getPlugin());
|
||||
new NCPDataManFix();
|
||||
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, true);
|
||||
|
||||
for(Player other : UtilServer.getPlayers())
|
||||
{
|
||||
for(Team team : other.getScoreboard().getTeams())
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Execute(final Player caller, final String[] args)
|
||||
{
|
||||
if (args == null)
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(Plugin.getPlugin(), new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if(Plugin.GetDisguise().isDisguised(caller))
|
||||
{
|
||||
if(!Plugin.GetDisguise().isDisguised(caller))
|
||||
{
|
||||
UtilPlayer.message(caller, C.cRed + C.Bold + "please use /disguise <name> first");
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
_disguisedPlayers.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, true);
|
||||
|
||||
for(Player other : UtilServer.getPlayers())
|
||||
{
|
||||
for(Team team : other.getScoreboard().getTeams())
|
||||
{
|
||||
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();
|
||||
}
|
||||
UtilPlayer.message(caller, C.cRed + C.Bold + "please use /disguise first");
|
||||
return;
|
||||
}
|
||||
if (args != null && args.length > 1)
|
||||
for(Player other : UtilServer.getPlayers())
|
||||
{
|
||||
UtilPlayer.message(caller, C.cRed + C.Bold + "/disguise <name>");
|
||||
if(other.getName().equalsIgnoreCase(args[0]))
|
||||
{
|
||||
UtilPlayer.message(caller, C.cRed + C.Bold + "this name is already in use!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(Plugin.getPlugin(), new Runnable()
|
||||
if(_disguisedPlayersNames.containsValue(args[0]))
|
||||
{
|
||||
@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))
|
||||
{
|
||||
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], true);
|
||||
|
||||
Plugin.getCosmeticManager().getGadgetManager().RemoveItem(caller);
|
||||
|
||||
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())
|
||||
UtilPlayer.message(caller, C.cRed + C.Bold + "this name is already in use!");
|
||||
return;
|
||||
}
|
||||
if(args[0].length() > 16)
|
||||
{
|
||||
if(!_disguisedPlayers.containsKey(player))
|
||||
continue;
|
||||
|
||||
for(Player other : UtilServer.getPlayers())
|
||||
{
|
||||
try
|
||||
{
|
||||
if(other.getScoreboard().getTeam(Plugin.GetClients().Get(player).GetRank().Name).getPlayers().contains(player))
|
||||
{
|
||||
other.getScoreboard().getTeam(Plugin.GetClients().Get(player).GetRank().Name).removePlayer(player);
|
||||
other.getScoreboard().getTeam(Plugin.GetClients().Get(player).getDisguisedRank().Name).addPlayer(player);
|
||||
}
|
||||
if(other.getScoreboard().getTeam(Plugin.GetClients().Get(player).GetRank().Name + Plugin.GetGame().GetTeam(player).GetName().toUpperCase()) != null)
|
||||
{
|
||||
if(other.getScoreboard().getTeam(Plugin.GetClients().Get(player).GetRank().Name + Plugin.GetGame().GetTeam(player).GetName().toUpperCase()).getPlayers().contains(player))
|
||||
{
|
||||
other.getScoreboard().getTeam(Plugin.GetClients().Get(player).GetRank().Name + Plugin.GetGame().GetTeam(player).GetName().toUpperCase()).removePlayer(player);
|
||||
other.getScoreboard().getTeam(Plugin.GetClients().Get(player).getDisguisedRank().Name + Plugin.GetGame().GetTeam(player).GetName().toUpperCase()).addPlayer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (NullPointerException exp)
|
||||
{}
|
||||
}
|
||||
|
||||
if(Plugin.GetDisguise().isDisguised(player))
|
||||
continue;
|
||||
UtilPlayer.message(caller, C.cRed + C.Bold + "Invalid Disguise Name: " + ChatColor.RESET + args[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
DisguisePlayer playerDisguise = new DisguisePlayer(player, _disguisedPlayers.get(player));
|
||||
Plugin.GetDisguise().disguise(playerDisguise);
|
||||
}
|
||||
}
|
||||
|
||||
public void changeName(final Player player , String changedName, boolean skin)
|
||||
{
|
||||
try
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority=EventPriority.HIGHEST)
|
||||
public void Quit(PlayerQuitEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if(_disguisedPlayers.containsKey(player))
|
||||
{
|
||||
try
|
||||
{
|
||||
_disguisedPlayers.remove(player);
|
||||
Plugin.GetDisguise().undisguise(player);
|
||||
String playerName = _disguisedPlayersNames.get(player);
|
||||
|
||||
CoreClient client = Plugin.GetClients().Get(player);
|
||||
client.setDisguisedRank(null);
|
||||
client.setDisguisedAs(null);
|
||||
client.setDisguised(false);
|
||||
|
||||
changeName(player, playerName, true);
|
||||
}
|
||||
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(GadgetActivateEvent event)
|
||||
{
|
||||
if(!event.getGadget().GetName().equalsIgnoreCase("Coin Party Bomb") && event.getGadget().getGadgetType() != GadgetType.Morph)
|
||||
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))
|
||||
{
|
||||
UtilPlayer.message(caller, C.cRed + C.Bold + "You can't disguise as staff!");
|
||||
return;
|
||||
|
||||
if(_disguisedPlayers.containsKey(event.getPlayer()))
|
||||
}
|
||||
_disguisedPlayers.put(caller, profile);
|
||||
_disguisedPlayersNames.put(caller, caller.getName());
|
||||
client.setDisguisedRank(otherRank);
|
||||
client.setDisguised(true);
|
||||
|
||||
client.setDisguisedAs(args[0]);
|
||||
|
||||
changeName(caller, args[0], true);
|
||||
|
||||
Plugin.getCosmeticManager().getGadgetManager().RemoveItem(caller);
|
||||
|
||||
UtilPlayer.message(caller, C.cGreen + C.Bold + "Disguise Active: " + ChatColor.RESET + args[0]);
|
||||
} catch(Exception e)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
e.printStackTrace();
|
||||
UtilPlayer.message(caller, C.cRed + C.Bold + "Invalid Disguise Name: " + ChatColor.RESET + args[0]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void chest(TreasureStartEvent event)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void updateDisguises(UpdateEvent event)
|
||||
{
|
||||
if(event.getType() != UpdateType.FASTEST)
|
||||
return;
|
||||
|
||||
for(final Player player : UtilServer.getPlayers())
|
||||
{
|
||||
if(_disguisedPlayers.containsKey(event.getPlayer()))
|
||||
if(!_disguisedPlayers.containsKey(player))
|
||||
continue;
|
||||
|
||||
for(Player other : UtilServer.getPlayers())
|
||||
{
|
||||
try
|
||||
{
|
||||
UtilPlayer.message(event.getPlayer(), F.main("Disguise", "You cant open Treasure Chests while you are disguised!"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
if(other.getScoreboard().getTeam(Plugin.GetClients().Get(player).GetRank().Name).getPlayers().contains(player))
|
||||
{
|
||||
other.getScoreboard().getTeam(Plugin.GetClients().Get(player).GetRank().Name).removePlayer(player);
|
||||
other.getScoreboard().getTeam(Plugin.GetClients().Get(player).getDisguisedRank().Name).addPlayer(player);
|
||||
}
|
||||
if(other.getScoreboard().getTeam(
|
||||
Plugin.GetClients().Get(player).GetRank().Name + Plugin.GetGame().GetTeam(player).GetName().toUpperCase()) != null)
|
||||
{
|
||||
if(other.getScoreboard()
|
||||
.getTeam(Plugin.GetClients().Get(player).GetRank().Name + Plugin.GetGame().GetTeam(player).GetName().toUpperCase())
|
||||
.getPlayers().contains(player))
|
||||
{
|
||||
other.getScoreboard()
|
||||
.getTeam(
|
||||
Plugin.GetClients().Get(player).GetRank().Name + Plugin.GetGame().GetTeam(player).GetName().toUpperCase())
|
||||
.removePlayer(player);
|
||||
other.getScoreboard()
|
||||
.getTeam(
|
||||
Plugin.GetClients().Get(player).getDisguisedRank().Name
|
||||
+ Plugin.GetGame().GetTeam(player).GetName().toUpperCase()).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(final Player player, String changedName, boolean skin)
|
||||
{
|
||||
try
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void Quit(PlayerQuitEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if(_disguisedPlayers.containsKey(player))
|
||||
{
|
||||
try
|
||||
{
|
||||
_disguisedPlayers.remove(player);
|
||||
_disguisedPlayerDisguises.remove(player);
|
||||
_disguisedPlayersNames.remove(player);
|
||||
Plugin.GetDisguise().undisguise(player);
|
||||
String playerName = _disguisedPlayersNames.get(player);
|
||||
|
||||
CoreClient client = Plugin.GetClients().Get(player);
|
||||
client.setDisguisedRank(null);
|
||||
client.setDisguisedAs(null);
|
||||
client.setDisguised(false);
|
||||
|
||||
changeName(player, playerName, true);
|
||||
} 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(GadgetActivateEvent 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
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user