2017-01-20 19:58:51 +01:00
|
|
|
package me.libraryaddict.disguise;
|
|
|
|
|
2021-04-21 00:56:50 +02:00
|
|
|
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
2020-01-02 05:10:36 +01:00
|
|
|
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
2021-04-21 00:56:50 +02:00
|
|
|
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
2021-12-25 06:12:18 +01:00
|
|
|
import java.util.ArrayList;
|
2017-12-05 20:08:24 +01:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.*;
|
|
|
|
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
|
2021-09-10 15:28:01 +02:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
2017-12-05 20:08:24 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
2020-01-02 05:10:36 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
|
|
|
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
2019-03-05 05:46:47 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
|
2021-09-10 15:28:01 +02:00
|
|
|
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
2019-01-03 03:13:03 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
2017-01-20 19:58:51 +01:00
|
|
|
import org.bukkit.Material;
|
2021-03-29 10:42:41 +02:00
|
|
|
import org.bukkit.command.CommandSender;
|
2020-01-02 05:10:36 +01:00
|
|
|
import org.bukkit.configuration.ConfigurationSection;
|
|
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
2021-05-20 20:23:01 +02:00
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.LivingEntity;
|
|
|
|
import org.bukkit.entity.Player;
|
2017-01-20 19:58:51 +01:00
|
|
|
import org.bukkit.inventory.EntityEquipment;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
2020-01-02 05:10:36 +01:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2020-04-15 14:55:35 +02:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2017-01-20 19:58:51 +01:00
|
|
|
|
|
|
|
public class DisguiseAPI {
|
2021-11-22 08:28:33 +01:00
|
|
|
private static int selfDisguiseId;
|
|
|
|
private static int entityAttachmentId;
|
2021-11-09 04:57:58 +01:00
|
|
|
|
2021-11-22 08:28:33 +01:00
|
|
|
public static int getEntityAttachmentId() {
|
|
|
|
if (entityAttachmentId == 0) {
|
|
|
|
entityAttachmentId = ReflectionManager.getNewEntityId();
|
|
|
|
}
|
|
|
|
|
|
|
|
return entityAttachmentId;
|
2021-11-09 04:57:58 +01:00
|
|
|
}
|
2017-12-05 20:08:24 +01:00
|
|
|
|
2020-01-02 05:10:36 +01:00
|
|
|
public static void addCustomDisguise(String disguiseName, String disguiseInfo) throws DisguiseParseException {
|
|
|
|
// Dirty fix for anyone that somehow got this far with a . in the name, invalid yaml!
|
|
|
|
disguiseName = disguiseName.replace(".", "");
|
|
|
|
|
|
|
|
try {
|
2020-01-11 01:37:45 +01:00
|
|
|
DisguiseConfig.removeCustomDisguise(disguiseName);
|
2020-01-02 05:10:36 +01:00
|
|
|
DisguiseConfig.addCustomDisguise(disguiseName, disguiseInfo);
|
|
|
|
|
2021-01-31 09:28:07 +01:00
|
|
|
File disguisesFile = new File(LibsDisguises.getInstance().getDataFolder(), "configs/disguises.yml");
|
2020-01-02 05:10:36 +01:00
|
|
|
|
|
|
|
if (!disguisesFile.exists()) {
|
2021-01-31 09:28:07 +01:00
|
|
|
disguisesFile.getParentFile().mkdirs();
|
2020-01-02 05:10:36 +01:00
|
|
|
disguisesFile.createNewFile();
|
|
|
|
}
|
|
|
|
|
|
|
|
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(disguisesFile);
|
|
|
|
|
|
|
|
if (!configuration.isConfigurationSection("Disguises")) {
|
|
|
|
configuration.createSection("Disguises");
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfigurationSection section = configuration.getConfigurationSection("Disguises");
|
2020-10-09 20:08:37 +02:00
|
|
|
section.set(disguiseName, disguiseInfo.replace("\n", "\\n").replace("\r", "\\r"));
|
2020-01-02 05:10:36 +01:00
|
|
|
|
|
|
|
configuration.save(disguisesFile);
|
|
|
|
|
|
|
|
DisguiseUtilities.getLogger().info("Added new Custom Disguise " + disguiseName);
|
2020-09-18 20:08:20 +02:00
|
|
|
} catch (IOException e) {
|
2020-01-02 05:10:36 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void addGameProfile(String profileName, WrappedGameProfile gameProfile) {
|
|
|
|
DisguiseUtilities.addGameProfile(profileName, gameProfile);
|
|
|
|
}
|
|
|
|
|
2019-05-18 08:07:54 +02:00
|
|
|
public static String getRawCustomDisguise(String disguiseName) {
|
2019-05-16 08:07:53 +02:00
|
|
|
Map.Entry<DisguisePerm, String> entry = DisguiseConfig.getRawCustomDisguise(disguiseName);
|
2017-07-20 09:23:43 +02:00
|
|
|
|
2020-09-18 20:08:20 +02:00
|
|
|
if (entry == null) {
|
2017-07-20 09:23:43 +02:00
|
|
|
return null;
|
2020-09-18 20:08:20 +02:00
|
|
|
}
|
2017-07-20 09:23:43 +02:00
|
|
|
|
|
|
|
return entry.getValue();
|
|
|
|
}
|
|
|
|
|
2019-05-18 08:07:54 +02:00
|
|
|
public static Disguise getCustomDisguise(String disguiseName) {
|
|
|
|
Map.Entry<DisguisePerm, Disguise> disguise = DisguiseConfig.getCustomDisguise(disguiseName);
|
|
|
|
|
|
|
|
if (disguise == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return disguise.getValue();
|
|
|
|
}
|
|
|
|
|
2017-01-20 19:58:51 +01:00
|
|
|
public static Disguise constructDisguise(Entity entity) {
|
2021-04-21 00:56:50 +02:00
|
|
|
return constructDisguise(entity, true, false);
|
2017-01-20 19:58:51 +01:00
|
|
|
}
|
|
|
|
|
2021-04-21 15:33:23 +02:00
|
|
|
public static Disguise constructDisguise(Entity entity, boolean doEquipment, boolean displayExtraAnimations) {
|
2017-01-20 19:58:51 +01:00
|
|
|
DisguiseType disguiseType = DisguiseType.getType(entity);
|
|
|
|
Disguise disguise;
|
|
|
|
|
|
|
|
if (disguiseType.isMisc()) {
|
|
|
|
disguise = new MiscDisguise(disguiseType);
|
2017-06-21 21:20:12 +02:00
|
|
|
} else if (disguiseType.isMob()) {
|
2017-01-20 19:58:51 +01:00
|
|
|
disguise = new MobDisguise(disguiseType);
|
2017-06-21 21:20:12 +02:00
|
|
|
} else {
|
2017-01-20 19:58:51 +01:00
|
|
|
disguise = new PlayerDisguise(entity.getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
FlagWatcher watcher = disguise.getWatcher();
|
|
|
|
|
|
|
|
if (doEquipment && entity instanceof LivingEntity) {
|
|
|
|
EntityEquipment equip = ((LivingEntity) entity).getEquipment();
|
|
|
|
|
|
|
|
watcher.setArmor(equip.getArmorContents());
|
|
|
|
|
2021-04-21 00:56:50 +02:00
|
|
|
ItemStack mainItem = equip.getItemInMainHand();
|
2017-01-20 19:58:51 +01:00
|
|
|
|
2021-04-21 00:56:50 +02:00
|
|
|
if (mainItem != null && mainItem.getType() != Material.AIR) {
|
|
|
|
watcher.setItemInMainHand(mainItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemStack offItem = equip.getItemInMainHand();
|
|
|
|
|
|
|
|
if (offItem != null && offItem.getType() != Material.AIR) {
|
|
|
|
watcher.setItemInOffHand(offItem);
|
2017-01-20 19:58:51 +01:00
|
|
|
}
|
|
|
|
}
|
2021-04-21 00:56:50 +02:00
|
|
|
|
|
|
|
WrappedDataWatcher dataWatcher = WrappedDataWatcher.getEntityWatcher(entity);
|
|
|
|
|
|
|
|
for (WrappedWatchableObject obj : dataWatcher.getWatchableObjects()) {
|
|
|
|
MetaIndex index = MetaIndex.getMetaIndex(watcher.getClass(), obj.getIndex());
|
|
|
|
|
|
|
|
if (index == null) {
|
|
|
|
continue;
|
2017-01-20 19:58:51 +01:00
|
|
|
}
|
2021-04-21 00:56:50 +02:00
|
|
|
|
|
|
|
if (index.getDefault() == obj.getValue() || index.getDefault() == obj.getRawValue()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-09-10 15:28:01 +02:00
|
|
|
watcher.setUnsafeData(index, obj.getRawValue());
|
2021-04-21 15:33:23 +02:00
|
|
|
|
|
|
|
// Update the meta for 0, otherwise boolean be weird
|
|
|
|
if (index == MetaIndex.ENTITY_META) {
|
|
|
|
watcher.setSprinting(watcher.isSprinting() && displayExtraAnimations);
|
|
|
|
watcher.setFlyingWithElytra(watcher.isFlyingWithElytra() && displayExtraAnimations);
|
|
|
|
watcher.setSneaking(watcher.isSneaking() && displayExtraAnimations);
|
|
|
|
watcher.setSwimming(watcher.isSwimming() && displayExtraAnimations);
|
|
|
|
|
2021-09-10 15:28:01 +02:00
|
|
|
if (!NmsVersion.v1_13.isSupported()) {
|
2021-09-10 16:43:42 +02:00
|
|
|
watcher.setMainHandRaised(watcher.isMainHandRaised() && displayExtraAnimations);
|
2021-09-10 15:28:01 +02:00
|
|
|
}
|
|
|
|
|
2021-04-21 15:33:23 +02:00
|
|
|
if (!displayExtraAnimations) {
|
|
|
|
Arrays.fill(watcher.getModifiedEntityAnimations(), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
watcher.setGlowing(watcher.isGlowing());
|
|
|
|
watcher.setInvisible(watcher.isInvisible());
|
2021-09-10 15:28:01 +02:00
|
|
|
} else if (index == MetaIndex.LIVING_META && NmsVersion.v1_13.isSupported()) {
|
|
|
|
LivingWatcher livingWatcher = (LivingWatcher) watcher;
|
|
|
|
|
2021-09-10 16:43:42 +02:00
|
|
|
livingWatcher.setMainHandRaised(livingWatcher.isMainHandRaised() && displayExtraAnimations);
|
|
|
|
livingWatcher.setOffhandRaised(livingWatcher.isOffhandRaised() && displayExtraAnimations);
|
2021-09-10 15:28:01 +02:00
|
|
|
livingWatcher.setSpinning(livingWatcher.isSpinning() && displayExtraAnimations);
|
|
|
|
|
|
|
|
if (!displayExtraAnimations) {
|
|
|
|
Arrays.fill(livingWatcher.getModifiedLivingAnimations(), false);
|
|
|
|
}
|
2021-04-21 15:33:23 +02:00
|
|
|
}
|
2017-01-20 19:58:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return disguise;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void disguiseEntity(Entity entity, Disguise disguise) {
|
2021-03-29 10:42:41 +02:00
|
|
|
disguiseEntity(null, entity, disguise);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void disguiseEntity(CommandSender commandSender, Entity entity, Disguise disguise) {
|
2017-01-20 19:58:51 +01:00
|
|
|
// If they are trying to disguise a null entity or use a null disguise
|
|
|
|
// Just return.
|
|
|
|
if (entity == null || disguise == null) {
|
|
|
|
return;
|
|
|
|
}
|
2017-07-11 07:38:27 +02:00
|
|
|
|
2017-01-20 19:58:51 +01:00
|
|
|
// The event wasn't cancelled.
|
|
|
|
// If the disguise entity isn't the same as the one we are disguising
|
|
|
|
if (disguise.getEntity() != entity) {
|
|
|
|
// If the disguise entity actually exists
|
|
|
|
if (disguise.getEntity() != null) {
|
|
|
|
// Clone the disguise
|
|
|
|
disguise = disguise.clone();
|
|
|
|
}
|
|
|
|
// Set the disguise's entity
|
|
|
|
disguise.setEntity(entity);
|
|
|
|
}
|
|
|
|
|
2018-02-14 06:49:10 +01:00
|
|
|
// They prefer to have the opposite of whatever the view disguises option is
|
2021-06-04 17:03:19 +02:00
|
|
|
if (hasSelfDisguisePreference(entity) && disguise.isSelfDisguiseVisible() == DisguiseConfig.isViewSelfDisguisesDefault()) {
|
2018-02-14 06:49:10 +01:00
|
|
|
disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible());
|
2020-09-18 20:08:20 +02:00
|
|
|
}
|
2017-01-20 19:58:51 +01:00
|
|
|
|
2021-10-23 13:49:21 +02:00
|
|
|
if (hasActionBarPreference(entity) && !isNotifyBarShown(entity)) {
|
2020-07-03 13:45:48 +02:00
|
|
|
disguise.setNotifyBar(DisguiseConfig.NotifyBar.NONE);
|
|
|
|
}
|
|
|
|
|
2021-03-29 10:42:41 +02:00
|
|
|
disguise.startDisguise(commandSender);
|
2017-01-20 19:58:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, Collection playersToNotSeeDisguise) {
|
|
|
|
if (disguise.getEntity() != null) {
|
|
|
|
disguise = disguise.clone();
|
|
|
|
}
|
|
|
|
|
|
|
|
((TargetedDisguise) disguise).setDisguiseTarget(TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS);
|
|
|
|
|
|
|
|
for (Object obj : playersToNotSeeDisguise) {
|
|
|
|
if (obj instanceof String) {
|
|
|
|
((TargetedDisguise) disguise).addPlayer((String) obj);
|
2017-06-21 21:20:12 +02:00
|
|
|
} else if (obj instanceof Player) {
|
2017-01-20 19:58:51 +01:00
|
|
|
((TargetedDisguise) disguise).addPlayer(((Player) obj).getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
disguiseEntity(entity, disguise);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, List<String> playersToNotSeeDisguise) {
|
|
|
|
disguiseIgnorePlayers(entity, disguise, (Collection) playersToNotSeeDisguise);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, Player... playersToNotSeeDisguise) {
|
2019-05-18 08:54:51 +02:00
|
|
|
disguiseIgnorePlayers(entity, disguise, Arrays.asList(playersToNotSeeDisguise));
|
2017-01-20 19:58:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, String... playersToNotSeeDisguise) {
|
|
|
|
disguiseIgnorePlayers(entity, disguise, (Collection) Arrays.asList(playersToNotSeeDisguise));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disguise the next entity to spawn, this means you need to spawn an entity immediately after calling this.
|
|
|
|
*
|
|
|
|
* @param disguise
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public static int disguiseNextEntity(Disguise disguise) {
|
|
|
|
if (disguise == null) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (disguise.getEntity() != null || DisguiseUtilities.getDisguises().containsValue(disguise)) {
|
|
|
|
disguise = disguise.clone();
|
|
|
|
}
|
|
|
|
|
2017-12-05 20:08:24 +01:00
|
|
|
int id = ReflectionManager.getNewEntityId(false);
|
|
|
|
DisguiseUtilities.addFutureDisguise(id, (TargetedDisguise) disguise);
|
2017-01-20 19:58:51 +01:00
|
|
|
|
2017-12-05 20:08:24 +01:00
|
|
|
return id;
|
2017-01-20 19:58:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disguise this entity with this disguise
|
|
|
|
*
|
|
|
|
* @param entity
|
|
|
|
* @param disguise
|
|
|
|
*/
|
|
|
|
public static void disguiseToAll(Entity entity, Disguise disguise) {
|
|
|
|
if (disguise.getEntity() != null) {
|
|
|
|
disguise = disguise.clone();
|
|
|
|
}
|
|
|
|
|
|
|
|
// You called the disguiseToAll method foolish mortal! Prepare to have your custom settings wiped!!!
|
|
|
|
((TargetedDisguise) disguise).setDisguiseTarget(TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS);
|
|
|
|
|
2021-12-25 06:12:18 +01:00
|
|
|
for (String observer : new ArrayList<>(((TargetedDisguise) disguise).getObservers())) {
|
2017-01-20 19:58:51 +01:00
|
|
|
((TargetedDisguise) disguise).removePlayer(observer);
|
|
|
|
}
|
2017-06-22 18:14:19 +02:00
|
|
|
|
2017-01-20 19:58:51 +01:00
|
|
|
disguiseEntity(entity, disguise);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void disguiseToPlayers(Entity entity, Disguise disguise, Collection playersToViewDisguise) {
|
|
|
|
if (disguise.getEntity() != null) {
|
|
|
|
disguise = disguise.clone();
|
|
|
|
}
|
|
|
|
|
|
|
|
((TargetedDisguise) disguise).setDisguiseTarget(TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS);
|
|
|
|
|
|
|
|
for (Object obj : playersToViewDisguise) {
|
|
|
|
if (obj instanceof String) {
|
|
|
|
((TargetedDisguise) disguise).addPlayer((String) obj);
|
2017-06-21 21:20:12 +02:00
|
|
|
} else if (obj instanceof Player) {
|
2017-01-20 19:58:51 +01:00
|
|
|
((TargetedDisguise) disguise).addPlayer(((Player) obj).getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
disguiseEntity(entity, disguise);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
public static void disguiseToPlayers(Entity entity, Disguise disguise, List<String> playersToViewDisguise) {
|
|
|
|
disguiseToPlayers(entity, disguise, (Collection) playersToViewDisguise);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void disguiseToPlayers(Entity entity, Disguise disguise, Player... playersToViewDisguise) {
|
2019-05-18 08:54:51 +02:00
|
|
|
disguiseToPlayers(entity, disguise, Arrays.asList(playersToViewDisguise));
|
2017-01-20 19:58:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void disguiseToPlayers(Entity entity, Disguise disguise, String... playersToViewDisguise) {
|
|
|
|
disguiseToPlayers(entity, disguise, (Collection) Arrays.asList(playersToViewDisguise));
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int firstCapital(String str) {
|
|
|
|
for (int i = 0; i < str.length(); i++) {
|
|
|
|
if (Character.isUpperCase(str.charAt(i))) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the disguise of a entity
|
|
|
|
*
|
|
|
|
* @param disguised
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public static Disguise getDisguise(Entity disguised) {
|
|
|
|
if (disguised == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-08-12 09:28:41 +02:00
|
|
|
return DisguiseUtilities.getMainDisguise(disguised.getEntityId());
|
2017-01-20 19:58:51 +01:00
|
|
|
}
|
|
|
|
|
2020-01-02 05:10:36 +01:00
|
|
|
public static String parseToString(Disguise disguise, boolean outputSkin) {
|
|
|
|
return DisguiseParser.parseToString(disguise, outputSkin);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String parseToString(Disguise disguise) {
|
|
|
|
return parseToString(disguise, true);
|
|
|
|
}
|
|
|
|
|
2017-01-20 19:58:51 +01:00
|
|
|
/**
|
|
|
|
* Get the disguise of a entity
|
|
|
|
*
|
|
|
|
* @param observer
|
|
|
|
* @param disguised
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public static Disguise getDisguise(Player observer, Entity disguised) {
|
|
|
|
if (disguised == null || observer == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DisguiseUtilities.getDisguise(observer, disguised);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the disguises of a entity
|
|
|
|
*
|
|
|
|
* @param disguised
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public static Disguise[] getDisguises(Entity disguised) {
|
|
|
|
if (disguised == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-08-12 09:28:41 +02:00
|
|
|
return DisguiseUtilities.getDisguises(disguised.getEntityId());
|
2017-01-20 19:58:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static int getSelfDisguiseId() {
|
2021-11-22 08:28:33 +01:00
|
|
|
if (selfDisguiseId == 0) {
|
|
|
|
selfDisguiseId = ReflectionManager.getNewEntityId();
|
|
|
|
}
|
|
|
|
|
2017-12-05 20:08:24 +01:00
|
|
|
return selfDisguiseId;
|
2017-01-20 19:58:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is this entity disguised
|
|
|
|
*
|
|
|
|
* @param disguised
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public static boolean isDisguised(Entity disguised) {
|
|
|
|
return getDisguise(disguised) != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is this entity disguised
|
|
|
|
*
|
|
|
|
* @param observer
|
|
|
|
* @param disguised
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public static boolean isDisguised(Player observer, Entity disguised) {
|
|
|
|
return getDisguise(observer, disguised) != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isDisguiseInUse(Disguise disguise) {
|
|
|
|
return disguise.isDisguiseInUse();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isSelfDisguised(Player player) {
|
|
|
|
return DisguiseUtilities.getSelfDisguised().contains(player.getUniqueId());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the entitiy has /disguiseviewself toggled on.
|
|
|
|
*
|
|
|
|
* @param entity
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public static boolean isViewSelfToggled(Entity entity) {
|
2021-06-04 17:03:19 +02:00
|
|
|
return hasSelfDisguisePreference(entity) != DisguiseConfig.isViewSelfDisguisesDefault();
|
2018-02-14 06:49:10 +01:00
|
|
|
}
|
|
|
|
|
2021-10-23 13:49:21 +02:00
|
|
|
@Deprecated
|
|
|
|
public static boolean isActionBarShown(Entity entity) {
|
|
|
|
return isNotifyBarShown(entity);
|
|
|
|
}
|
|
|
|
|
2020-07-03 07:08:58 +02:00
|
|
|
/**
|
2021-10-23 13:49:21 +02:00
|
|
|
* Returns true if the entity wants to see the action bar / boss bar
|
2020-07-03 07:08:58 +02:00
|
|
|
*
|
|
|
|
* @param entity
|
|
|
|
* @return
|
|
|
|
*/
|
2021-10-23 13:49:21 +02:00
|
|
|
public static boolean isNotifyBarShown(Entity entity) {
|
|
|
|
// If default is no notify bar, but they toggled it. Then we want to show it.
|
|
|
|
// If default is a notify bar, but they toggled it. Then we want to hide it.
|
|
|
|
|
|
|
|
return (DisguiseConfig.getNotifyBar() == DisguiseConfig.NotifyBar.NONE) == hasActionBarPreference(entity);
|
2020-07-03 07:08:58 +02:00
|
|
|
}
|
|
|
|
|
2018-02-14 06:49:10 +01:00
|
|
|
public static boolean hasSelfDisguisePreference(Entity entity) {
|
2020-07-03 07:08:58 +02:00
|
|
|
return DisguiseUtilities.getViewSelf().contains(entity.getUniqueId());
|
|
|
|
}
|
|
|
|
|
2020-07-03 13:45:48 +02:00
|
|
|
public static boolean hasActionBarPreference(Entity entity) {
|
2020-07-03 14:59:33 +02:00
|
|
|
return DisguiseUtilities.getViewBar().contains(entity.getUniqueId());
|
2017-01-20 19:58:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-05 20:08:24 +01:00
|
|
|
* Undisguise the entity. This doesn't let you cancel the UndisguiseEvent if the entity is no longer valid. Aka
|
|
|
|
* removed from
|
2017-01-20 19:58:51 +01:00
|
|
|
* the world.
|
|
|
|
*
|
|
|
|
* @param entity
|
|
|
|
*/
|
|
|
|
public static void undisguiseToAll(Entity entity) {
|
2021-03-29 10:42:41 +02:00
|
|
|
undisguiseToAll(null, entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Undisguise the entity. This doesn't let you cancel the UndisguiseEvent if the entity is no longer valid. Aka
|
|
|
|
* removed from
|
|
|
|
* the world.
|
|
|
|
*
|
|
|
|
* @param entity
|
|
|
|
*/
|
|
|
|
public static void undisguiseToAll(CommandSender sender, Entity entity) {
|
2017-01-20 19:58:51 +01:00
|
|
|
Disguise[] disguises = getDisguises(entity);
|
|
|
|
|
|
|
|
for (Disguise disguise : disguises) {
|
2021-03-29 10:42:41 +02:00
|
|
|
disguise.removeDisguise(sender);
|
2017-01-20 19:58:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set whether this player can see his own disguise or not.
|
|
|
|
*
|
|
|
|
* @param entity
|
2017-07-23 13:47:00 +02:00
|
|
|
* @param canSeeSelfDisguises
|
2017-01-20 19:58:51 +01:00
|
|
|
*/
|
2017-07-23 13:47:00 +02:00
|
|
|
public static void setViewDisguiseToggled(Entity entity, boolean canSeeSelfDisguises) {
|
2017-01-20 19:58:51 +01:00
|
|
|
if (isDisguised(entity)) {
|
2017-06-21 21:20:12 +02:00
|
|
|
Disguise[] disguises = getDisguises(entity);
|
|
|
|
|
|
|
|
for (Disguise disguise : disguises) {
|
2017-07-23 13:47:00 +02:00
|
|
|
disguise.setViewSelfDisguise(canSeeSelfDisguises);
|
2017-06-21 21:20:12 +02:00
|
|
|
}
|
2017-01-20 19:58:51 +01:00
|
|
|
}
|
|
|
|
|
2021-06-04 17:03:19 +02:00
|
|
|
if (!canSeeSelfDisguises == DisguiseConfig.isViewSelfDisguisesDefault()) {
|
2018-02-14 06:49:10 +01:00
|
|
|
if (!hasSelfDisguisePreference(entity)) {
|
2020-07-03 07:08:58 +02:00
|
|
|
DisguiseUtilities.getViewSelf().add(entity.getUniqueId());
|
|
|
|
DisguiseUtilities.addSaveAttempt();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
DisguiseUtilities.getViewSelf().remove(entity.getUniqueId());
|
|
|
|
DisguiseUtilities.addSaveAttempt();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-03 13:45:48 +02:00
|
|
|
public static void setActionBarShown(Player player, boolean isShown) {
|
2020-07-03 07:08:58 +02:00
|
|
|
if (isDisguised(player)) {
|
|
|
|
Disguise[] disguises = getDisguises(player);
|
|
|
|
|
|
|
|
for (Disguise disguise : disguises) {
|
2020-07-03 13:45:48 +02:00
|
|
|
disguise.setNotifyBar(isShown ? DisguiseConfig.getNotifyBar() : DisguiseConfig.NotifyBar.NONE);
|
2020-07-03 07:08:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-03 13:45:48 +02:00
|
|
|
// If default is view and we want the opposite
|
|
|
|
if (!isShown) {
|
2020-07-03 14:59:33 +02:00
|
|
|
if (!hasActionBarPreference(player)) {
|
2020-07-03 07:08:58 +02:00
|
|
|
DisguiseUtilities.getViewBar().add(player.getUniqueId());
|
|
|
|
DisguiseUtilities.addSaveAttempt();
|
2017-01-20 19:58:51 +01:00
|
|
|
}
|
2017-06-21 21:20:12 +02:00
|
|
|
} else {
|
2020-07-03 07:08:58 +02:00
|
|
|
DisguiseUtilities.getViewBar().remove(player.getUniqueId());
|
|
|
|
DisguiseUtilities.addSaveAttempt();
|
2017-01-20 19:58:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private DisguiseAPI() {
|
|
|
|
}
|
|
|
|
}
|