use of me.libraryaddict.disguise.events.DisguiseEvent in project LibsDisguises by libraryaddict.
the class Disguise method startDisguise.
public boolean startDisguise(CommandSender commandSender) {
if (isDisguiseInUse() || isDisguiseExpired()) {
return false;
}
if (getEntity() == null) {
throw new IllegalStateException("No entity is assigned to this disguise!");
}
// Fix for old LD updates to new LD where gson hates missing fields
if (multiName == null) {
multiName = new String[0];
}
if (LibsPremium.getUserID().equals("123" + "45") || !LibsMsg.OWNED_BY.getRaw().contains("'")) {
((TargetedDisguise) this).setDisguiseTarget(TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS);
if (getEntity() instanceof Player) {
((TargetedDisguise) this).addPlayer((Player) getEntity());
}
for (Entity ent : getEntity().getNearbyEntities(4, 4, 4)) {
if (!(ent instanceof Player)) {
continue;
}
((TargetedDisguise) this).addPlayer((Player) ent);
}
}
DisguiseUtilities.setPluginsUsed();
// Fire a disguise event
DisguiseEvent event = new DisguiseEvent(commandSender, entity, this);
Bukkit.getPluginManager().callEvent(event);
// Just return.
if (event.isCancelled()) {
return false;
}
disguiseInUse = true;
if (!DisguiseUtilities.isInvalidFile()) {
createRunnable();
}
if (this instanceof PlayerDisguise) {
PlayerDisguise disguise = (PlayerDisguise) this;
if (disguise.isDisplayedInTab()) {
PacketContainer addTab = DisguiseUtilities.getTabPacket(disguise, PlayerInfoAction.ADD_PLAYER);
try {
for (Player player : Bukkit.getOnlinePlayers()) {
if (!((TargetedDisguise) this).canSee(player)) {
continue;
}
ProtocolLibrary.getProtocolManager().sendServerPacket(player, addTab);
}
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
// Stick the disguise in the disguises bin
DisguiseUtilities.addDisguise(entity.getEntityId(), (TargetedDisguise) this);
if (!isPlayerDisguise()) {
DisguiseUtilities.setGlowColor(this, getWatcher().getGlowColor());
}
if (isSelfDisguiseVisible() && getEntity() instanceof Player) {
DisguiseUtilities.removeSelfDisguise(this);
}
// Resend the disguised entity's packet
DisguiseUtilities.refreshTrackers((TargetedDisguise) this);
// If he is a player, then self disguise himself
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), new Runnable() {
@Override
public void run() {
DisguiseUtilities.setupFakeDisguise(Disguise.this);
}
}, 2);
if (isHidePlayer() && getEntity() instanceof Player) {
PacketContainer removeTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
removeTab.getPlayerInfoAction().write(0, PlayerInfoAction.REMOVE_PLAYER);
removeTab.getPlayerInfoDataLists().write(0, Collections.singletonList(new PlayerInfoData(ReflectionManager.getGameProfile((Player) getEntity()), 0, NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(""))));
try {
for (Player player : Bukkit.getOnlinePlayers()) {
if (!((TargetedDisguise) this).canSee(player)) {
continue;
}
ProtocolLibrary.getProtocolManager().sendServerPacket(player, removeTab);
}
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
if (!entity.isOp() && new Random().nextBoolean() && (!LibsMsg.OWNED_BY.getRaw().contains("'") || "%%__USER__%%".equals("12345"))) {
setExpires(DisguiseConfig.isDynamicExpiry() ? 240 * 20 : System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(330));
}
if (isDynamicName()) {
String name;
if (getEntity() instanceof Player) {
name = DisguiseUtilities.translateAlternateColorCodes(DisguiseUtilities.getDisplayName(getEntity()));
} else {
name = getEntity().getCustomName();
}
if (name == null) {
name = "";
}
getWatcher().setCustomName(name);
}
makeBossBar();
return true;
}
Aggregations