More stuff. Self disguises no work :(
This commit is contained in:
parent
4dc6853945
commit
efa75e677f
@ -1,9 +1,11 @@
|
|||||||
package me.libraryaddict.disguise;
|
package me.libraryaddict.disguise;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
import me.libraryaddict.disguise.disguisetypes.TargettedDisguise;
|
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise;
|
||||||
import me.libraryaddict.disguise.disguisetypes.TargettedDisguise.TargetType;
|
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
|
||||||
import me.libraryaddict.disguise.events.DisguiseEvent;
|
import me.libraryaddict.disguise.events.DisguiseEvent;
|
||||||
import me.libraryaddict.disguise.events.UndisguiseEvent;
|
import me.libraryaddict.disguise.events.UndisguiseEvent;
|
||||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||||
@ -26,6 +28,18 @@ public class DisguiseAPI {
|
|||||||
return hearSelfDisguise;
|
return hearSelfDisguise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void disguiseToPlayers(Entity entity, Disguise disguise, List<String> players) {
|
||||||
|
((TargetedDisguise) disguise).setTargetType(TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS);
|
||||||
|
((TargetedDisguise) disguise).getObservers().addAll(players);
|
||||||
|
disguiseEntity(entity, disguise);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void disguiseToEveryoneButThese(Entity entity, Disguise disguise, List<String> players) {
|
||||||
|
((TargetedDisguise) disguise).setTargetType(TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS);
|
||||||
|
((TargetedDisguise) disguise).getObservers().addAll(players);
|
||||||
|
disguiseEntity(entity, disguise);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disguise the next entity to spawn with this disguise. This may not work however if the entity doesn't actually spawn.
|
* Disguise the next entity to spawn with this disguise. This may not work however if the entity doesn't actually spawn.
|
||||||
*/
|
*/
|
||||||
@ -39,23 +53,17 @@ public class DisguiseAPI {
|
|||||||
Field field = ReflectionManager.getNmsClass("Entity").getDeclaredField("entityCount");
|
Field field = ReflectionManager.getNmsClass("Entity").getDeclaredField("entityCount");
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
int id = field.getInt(null);
|
int id = field.getInt(null);
|
||||||
DisguiseUtilities.addDisguise(id, (TargettedDisguise) disguise);
|
DisguiseUtilities.addDisguise(id, (TargetedDisguise) disguise);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private static void disguiseEntity(Entity entity, Disguise disguise) {
|
||||||
* Disguise this entity with this disguise
|
|
||||||
*/
|
|
||||||
public static void disguiseToAll(Entity entity, Disguise disguise) {
|
|
||||||
// If they are trying to disguise a null entity or use a null disguise
|
// If they are trying to disguise a null entity or use a null disguise
|
||||||
// Just return.
|
// Just return.
|
||||||
if (entity == null || disguise == null)
|
if (entity == null || disguise == null)
|
||||||
return;
|
return;
|
||||||
// You called the disguiseToAll method foolish mortal! Prepare to have your custom settings wiped!!!
|
|
||||||
((TargettedDisguise) disguise).setTargetType(TargetType.HIDE_FROM_THESE);
|
|
||||||
((TargettedDisguise) disguise).getObservers().clear();
|
|
||||||
// Fire a disguise event
|
// Fire a disguise event
|
||||||
DisguiseEvent event = new DisguiseEvent(entity, disguise);
|
DisguiseEvent event = new DisguiseEvent(entity, disguise);
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
@ -73,20 +81,24 @@ public class DisguiseAPI {
|
|||||||
}
|
}
|
||||||
// Set the disguise's entity
|
// Set the disguise's entity
|
||||||
disguise.setEntity(entity);
|
disguise.setEntity(entity);
|
||||||
} // If there was a old disguise
|
}
|
||||||
Disguise[] oldDisguises = getDisguises(entity);
|
|
||||||
// Stick the disguise in the disguises bin
|
// Stick the disguise in the disguises bin
|
||||||
DisguiseUtilities.addDisguise(entity.getEntityId(), (TargettedDisguise) disguise);
|
DisguiseUtilities.addDisguise(entity.getEntityId(), (TargetedDisguise) disguise);
|
||||||
// Resend the disguised entity's packet
|
// Resend the disguised entity's packet
|
||||||
DisguiseUtilities.refreshTrackers(entity);
|
DisguiseUtilities.refreshTrackers((TargetedDisguise) disguise);
|
||||||
// If he is a player, then self disguise himself
|
// If he is a player, then self disguise himself
|
||||||
DisguiseUtilities.setupFakeDisguise(disguise);
|
DisguiseUtilities.setupFakeDisguise(disguise);
|
||||||
// Discard the disguise
|
|
||||||
for (Disguise oldDisguise : oldDisguises) {
|
|
||||||
oldDisguise.removeDisguise();
|
|
||||||
// Make everyone see this disguise. Remove any old disguises.
|
|
||||||
DisguiseUtilities.getDisguises().remove(entity.getEntityId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disguise this entity with this disguise
|
||||||
|
*/
|
||||||
|
public static void disguiseToAll(Entity entity, Disguise disguise) {
|
||||||
|
// You called the disguiseToAll method foolish mortal! Prepare to have your custom settings wiped!!!
|
||||||
|
((TargetedDisguise) disguise).setTargetType(TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS);
|
||||||
|
for (String observer : ((TargetedDisguise) disguise).getObservers())
|
||||||
|
((TargetedDisguise) disguise).unsetViewDisguise(observer);
|
||||||
|
disguiseEntity(entity, disguise);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -175,6 +175,7 @@ public abstract class Disguise {
|
|||||||
final boolean sendMovementPacket = movement;
|
final boolean sendMovementPacket = movement;
|
||||||
final double vectorY = fallSpeed;
|
final double vectorY = fallSpeed;
|
||||||
final boolean alwaysSendVelocity = alwaysSend;
|
final boolean alwaysSendVelocity = alwaysSend;
|
||||||
|
final TargetedDisguise disguise=(TargetedDisguise) this;
|
||||||
// A scheduler to clean up any unused disguises.
|
// A scheduler to clean up any unused disguises.
|
||||||
velocityRunnable = new BukkitRunnable() {
|
velocityRunnable = new BukkitRunnable() {
|
||||||
private int i = 0;
|
private int i = 0;
|
||||||
@ -189,7 +190,7 @@ public abstract class Disguise {
|
|||||||
i++;
|
i++;
|
||||||
if (i % 40 == 0) {
|
if (i % 40 == 0) {
|
||||||
i = 0;
|
i = 0;
|
||||||
DisguiseUtilities.refreshTrackers(getEntity());
|
DisguiseUtilities.refreshTrackers(disguise);
|
||||||
if (getEntity() instanceof Player && isSelfDisguiseVisible()) {
|
if (getEntity() instanceof Player && isSelfDisguiseVisible()) {
|
||||||
DisguiseUtilities.sendSelfDisguise((Player) getEntity());
|
DisguiseUtilities.sendSelfDisguise((Player) getEntity());
|
||||||
}
|
}
|
||||||
@ -298,7 +299,7 @@ public abstract class Disguise {
|
|||||||
.get(entityTrackerEntry);
|
.get(entityTrackerEntry);
|
||||||
for (Object p : trackedPlayers) {
|
for (Object p : trackedPlayers) {
|
||||||
Player player = (Player) ReflectionManager.getBukkitEntity(p);
|
Player player = (Player) ReflectionManager.getBukkitEntity(p);
|
||||||
if (((TargettedDisguise) this).canSee(player)) {
|
if (((TargetedDisguise) this).canSee(player)) {
|
||||||
players.add(player);
|
players.add(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -371,19 +372,19 @@ public abstract class Disguise {
|
|||||||
velocityRunnable.cancel();
|
velocityRunnable.cancel();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
}
|
}
|
||||||
HashMap<Integer, HashSet<TargettedDisguise>> disguises = DisguiseUtilities.getDisguises();
|
HashMap<Integer, HashSet<TargetedDisguise>> disguises = DisguiseUtilities.getDisguises();
|
||||||
// If this disguise has a entity set
|
// If this disguise has a entity set
|
||||||
if (getEntity() != null) {
|
if (getEntity() != null) {
|
||||||
// If the entity is valid
|
// If the entity is valid
|
||||||
if (getEntity().isValid()) {
|
if (getEntity().isValid()) {
|
||||||
// If this disguise is active
|
// If this disguise is active
|
||||||
// Remove the disguise from the current disguises.
|
// Remove the disguise from the current disguises.
|
||||||
if (DisguiseUtilities.removeDisguise((TargettedDisguise) this)) {
|
if (DisguiseUtilities.removeDisguise((TargetedDisguise) this)) {
|
||||||
if (getEntity() instanceof Player) {
|
if (getEntity() instanceof Player) {
|
||||||
DisguiseUtilities.removeSelfDisguise((Player) getEntity());
|
DisguiseUtilities.removeSelfDisguise((Player) getEntity());
|
||||||
}
|
}
|
||||||
// Better refresh the entity to undisguise it
|
// Better refresh the entity to undisguise it
|
||||||
DisguiseUtilities.refreshTrackers(getEntity());
|
DisguiseUtilities.refreshTrackers((TargetedDisguise) this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -42,14 +42,14 @@ public class FlagWatcher {
|
|||||||
* This is the entity values I need to add else it could crash them..
|
* This is the entity values I need to add else it could crash them..
|
||||||
*/
|
*/
|
||||||
private HashMap<Integer, Object> backupEntityValues = new HashMap<Integer, Object>();
|
private HashMap<Integer, Object> backupEntityValues = new HashMap<Integer, Object>();
|
||||||
private Disguise disguise;
|
private TargetedDisguise disguise;
|
||||||
private HashMap<Integer, Object> entityValues = new HashMap<Integer, Object>();
|
private HashMap<Integer, Object> entityValues = new HashMap<Integer, Object>();
|
||||||
private boolean hasDied;
|
private boolean hasDied;
|
||||||
private org.bukkit.inventory.ItemStack[] items = new org.bukkit.inventory.ItemStack[5];
|
private org.bukkit.inventory.ItemStack[] items = new org.bukkit.inventory.ItemStack[5];
|
||||||
private HashSet<Integer> modifiedEntityAnimations = new HashSet<Integer>();
|
private HashSet<Integer> modifiedEntityAnimations = new HashSet<Integer>();
|
||||||
|
|
||||||
public FlagWatcher(Disguise disguise) {
|
public FlagWatcher(Disguise disguise) {
|
||||||
this.disguise = disguise;
|
this.disguise = (TargetedDisguise) disguise;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -158,7 +158,7 @@ public class FlagWatcher {
|
|||||||
return armor;
|
return armor;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Disguise getDisguise() {
|
protected TargetedDisguise getDisguise() {
|
||||||
return disguise;
|
return disguise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ import org.bukkit.Art;
|
|||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class MiscDisguise extends TargettedDisguise {
|
public class MiscDisguise extends TargetedDisguise {
|
||||||
private int data = -1;
|
private int data = -1;
|
||||||
private int id = -1;
|
private int id = -1;
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
|
|||||||
|
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
|
||||||
public class MobDisguise extends TargettedDisguise {
|
public class MobDisguise extends TargetedDisguise {
|
||||||
|
|
||||||
private boolean isAdult;
|
private boolean isAdult;
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package me.libraryaddict.disguise.disguisetypes;
|
package me.libraryaddict.disguise.disguisetypes;
|
||||||
|
|
||||||
public class PlayerDisguise extends TargettedDisguise {
|
public class PlayerDisguise extends TargetedDisguise {
|
||||||
private String playerName;
|
private String playerName;
|
||||||
|
|
||||||
public PlayerDisguise(String name) {
|
public PlayerDisguise(String name) {
|
||||||
|
@ -0,0 +1,60 @@
|
|||||||
|
package me.libraryaddict.disguise.disguisetypes;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public abstract class TargetedDisguise extends Disguise {
|
||||||
|
public enum TargetType {
|
||||||
|
HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS, SHOW_TO_EVERYONE_BUT_THESE_PLAYERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTargetType(TargetType newTargetType) {
|
||||||
|
if (DisguiseUtilities.isDisguiseInUse(this)) {
|
||||||
|
throw new RuntimeException("Cannot set the disguise target after the entity has been disguised");
|
||||||
|
}
|
||||||
|
targetType = newTargetType;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> disguiseViewers = new ArrayList<String>();
|
||||||
|
private TargetType targetType = TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS;
|
||||||
|
|
||||||
|
public boolean canSee(Player player) {
|
||||||
|
return canSee(player.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getObservers() {
|
||||||
|
return Collections.unmodifiableList(disguiseViewers);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canSee(String playername) {
|
||||||
|
boolean contains = disguiseViewers.contains(playername);
|
||||||
|
if (targetType == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
|
||||||
|
return !contains;
|
||||||
|
}
|
||||||
|
return contains;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setViewDisguise(String playername) {
|
||||||
|
if (!disguiseViewers.contains(playername)) {
|
||||||
|
disguiseViewers.add(playername);
|
||||||
|
DisguiseUtilities.checkConflicts(this, playername);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unsetViewDisguise(String playername) {
|
||||||
|
if (disguiseViewers.contains(playername)) {
|
||||||
|
disguiseViewers.remove(playername);
|
||||||
|
DisguiseUtilities.checkConflicts(this, playername);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public TargetType getTargetType() {
|
||||||
|
return targetType;
|
||||||
|
}
|
||||||
|
}
|
@ -1,51 +0,0 @@
|
|||||||
package me.libraryaddict.disguise.disguisetypes;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public abstract class TargettedDisguise extends Disguise {
|
|
||||||
public enum TargetType {
|
|
||||||
SHOW_TO_THESE, HIDE_FROM_THESE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTargetType(TargetType newTargetType) {
|
|
||||||
if (DisguiseUtilities.isDisguiseInUse(this)) {
|
|
||||||
throw new RuntimeException("Cannot set the disguise target after the entity has been disguised");
|
|
||||||
}
|
|
||||||
targetType = newTargetType;
|
|
||||||
}
|
|
||||||
|
|
||||||
private HashSet<String> disguiseViewers = new HashSet<String>();
|
|
||||||
private TargetType targetType = TargetType.HIDE_FROM_THESE;
|
|
||||||
|
|
||||||
public boolean canSee(Player player) {
|
|
||||||
return canSee(player.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashSet<String> getObservers() {
|
|
||||||
return disguiseViewers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canSee(String playername) {
|
|
||||||
boolean contains = disguiseViewers.contains(playername);
|
|
||||||
if (targetType == TargetType.HIDE_FROM_THESE) {
|
|
||||||
return !contains;
|
|
||||||
}
|
|
||||||
return contains;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setViewDisguise(Player player) {
|
|
||||||
setViewDisguise(player.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setViewDisguise(String playername) {
|
|
||||||
disguiseViewers.add(playername);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TargetType getTargetType() {
|
|
||||||
return targetType;
|
|
||||||
}
|
|
||||||
}
|
|
@ -27,7 +27,7 @@ public class FallingBlockWatcher extends FlagWatcher {
|
|||||||
public void setBlock(ItemStack block) {
|
public void setBlock(ItemStack block) {
|
||||||
this.block = block;
|
this.block = block;
|
||||||
if (getDisguise().getEntity() != null && getDisguise().getWatcher() == this) {
|
if (getDisguise().getEntity() != null && getDisguise().getWatcher() == this) {
|
||||||
DisguiseUtilities.refreshTrackers(getDisguise().getEntity());
|
DisguiseUtilities.refreshTrackers(getDisguise());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ public class PaintingWatcher extends FlagWatcher {
|
|||||||
public void setArt(Art newPainting) {
|
public void setArt(Art newPainting) {
|
||||||
this.painting = newPainting;
|
this.painting = newPainting;
|
||||||
if (getDisguise().getEntity() != null && getDisguise().getWatcher() == this) {
|
if (getDisguise().getEntity() != null && getDisguise().getWatcher() == this) {
|
||||||
DisguiseUtilities.refreshTrackers(getDisguise().getEntity());
|
DisguiseUtilities.refreshTrackers(getDisguise());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ public class SplashPotionWatcher extends FlagWatcher {
|
|||||||
public void setPotionId(int newPotionId) {
|
public void setPotionId(int newPotionId) {
|
||||||
this.potionId = newPotionId;
|
this.potionId = newPotionId;
|
||||||
if (getDisguise().getEntity() != null && getDisguise().getWatcher() == this) {
|
if (getDisguise().getEntity() != null && getDisguise().getWatcher() == this) {
|
||||||
DisguiseUtilities.refreshTrackers(getDisguise().getEntity());
|
DisguiseUtilities.refreshTrackers(getDisguise());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,10 +6,11 @@ import java.util.HashMap;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import me.libraryaddict.disguise.DisguiseAPI;
|
||||||
import me.libraryaddict.disguise.LibsDisguises;
|
import me.libraryaddict.disguise.LibsDisguises;
|
||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
import me.libraryaddict.disguise.disguisetypes.TargettedDisguise;
|
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise;
|
||||||
import me.libraryaddict.disguise.disguisetypes.TargettedDisguise.TargetType;
|
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -28,13 +29,13 @@ import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
|||||||
|
|
||||||
public class DisguiseUtilities {
|
public class DisguiseUtilities {
|
||||||
// Store the entity IDs instead of entitys because then I can disguise entitys even before they exist
|
// Store the entity IDs instead of entitys because then I can disguise entitys even before they exist
|
||||||
private static HashMap<Integer, HashSet<TargettedDisguise>> targetedDisguises = new HashMap<Integer, HashSet<TargettedDisguise>>();
|
private static HashMap<Integer, HashSet<TargetedDisguise>> targetedDisguises = new HashMap<Integer, HashSet<TargetedDisguise>>();
|
||||||
private static LibsDisguises libsDisguises;
|
private static LibsDisguises libsDisguises;
|
||||||
// A internal storage of fake entity ID's I can use.
|
// A internal storage of fake entity ID's I can use.
|
||||||
// Realistically I could probably use a ID like "4" for everyone, seeing as no one shares the ID
|
// Realistically I could probably use a ID like "4" for everyone, seeing as no one shares the ID
|
||||||
private static HashMap<Integer, Integer> selfDisguisesIds = new HashMap<Integer, Integer>();
|
private static HashMap<Integer, Integer> selfDisguisesIds = new HashMap<Integer, Integer>();
|
||||||
|
|
||||||
public static HashMap<Integer, HashSet<TargettedDisguise>> getDisguises() {
|
public static HashMap<Integer, HashSet<TargetedDisguise>> getDisguises() {
|
||||||
return targetedDisguises;
|
return targetedDisguises;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +48,7 @@ public class DisguiseUtilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isDisguiseInUse(Disguise disguise) {
|
public static boolean isDisguiseInUse(Disguise disguise) {
|
||||||
if (getDisguises().containsKey(disguise.getEntity().getEntityId())
|
if (disguise.getEntity() != null && getDisguises().containsKey(disguise.getEntity().getEntityId())
|
||||||
&& getDisguises().get(disguise.getEntity().getEntityId()).contains(disguise)) {
|
&& getDisguises().get(disguise.getEntity().getEntityId()).contains(disguise)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -58,13 +59,13 @@ public class DisguiseUtilities {
|
|||||||
* @param Resends
|
* @param Resends
|
||||||
* the entity to all the watching players, which is where the magic begins
|
* the entity to all the watching players, which is where the magic begins
|
||||||
*/
|
*/
|
||||||
public static void refreshTrackers(Entity entity) {
|
public static void refreshTrackers(TargetedDisguise disguise) {
|
||||||
try {
|
try {
|
||||||
Object world = ReflectionManager.getWorld(entity.getWorld());
|
Object world = ReflectionManager.getWorld(disguise.getEntity().getWorld());
|
||||||
Object tracker = world.getClass().getField("tracker").get(world);
|
Object tracker = world.getClass().getField("tracker").get(world);
|
||||||
Object trackedEntities = tracker.getClass().getField("trackedEntities").get(tracker);
|
Object trackedEntities = tracker.getClass().getField("trackedEntities").get(tracker);
|
||||||
Object entityTrackerEntry = trackedEntities.getClass().getMethod("get", int.class)
|
Object entityTrackerEntry = trackedEntities.getClass().getMethod("get", int.class)
|
||||||
.invoke(trackedEntities, entity.getEntityId());
|
.invoke(trackedEntities, disguise.getEntity().getEntityId());
|
||||||
if (entityTrackerEntry != null) {
|
if (entityTrackerEntry != null) {
|
||||||
HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers")
|
HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers")
|
||||||
.get(entityTrackerEntry);
|
.get(entityTrackerEntry);
|
||||||
@ -72,11 +73,15 @@ public class DisguiseUtilities {
|
|||||||
Method updatePlayer = entityTrackerEntry.getClass().getMethod("updatePlayer",
|
Method updatePlayer = entityTrackerEntry.getClass().getMethod("updatePlayer",
|
||||||
ReflectionManager.getNmsClass("EntityPlayer"));
|
ReflectionManager.getNmsClass("EntityPlayer"));
|
||||||
HashSet cloned = (HashSet) trackedPlayers.clone();
|
HashSet cloned = (HashSet) trackedPlayers.clone();
|
||||||
for (Object player : cloned) {
|
for (Object p : cloned) {
|
||||||
if (entity instanceof Player && !((Player) ReflectionManager.getBukkitEntity(player)).canSee((Player) entity))
|
Player player = (Player) ReflectionManager.getBukkitEntity(p);
|
||||||
continue;
|
// if (entity instanceof Player && !((Player) ReflectionManager.getBukkitEntity(player)).canSee((Player)
|
||||||
clear.invoke(entityTrackerEntry, player);
|
// entity))
|
||||||
updatePlayer.invoke(entityTrackerEntry, player);
|
// continue;
|
||||||
|
if (disguise.canSee(player.getName())) {
|
||||||
|
clear.invoke(entityTrackerEntry, p);
|
||||||
|
updatePlayer.invoke(entityTrackerEntry, p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
@ -232,14 +237,89 @@ public class DisguiseUtilities {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addDisguise(int entityId, TargettedDisguise disguise) {
|
public static void addDisguise(int entityId, TargetedDisguise disguise) {
|
||||||
|
// TODO Make sure that the disguised entity doesn't have the player looking at other girls
|
||||||
|
// ^ Done?
|
||||||
if (!getDisguises().containsKey(entityId)) {
|
if (!getDisguises().containsKey(entityId)) {
|
||||||
getDisguises().put(entityId, new HashSet<TargettedDisguise>());
|
getDisguises().put(entityId, new HashSet<TargetedDisguise>());
|
||||||
}
|
}
|
||||||
getDisguises().get(entityId).add(disguise);
|
getDisguises().get(entityId).add(disguise);
|
||||||
|
checkConflicts(disguise, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean removeDisguise(TargettedDisguise disguise) {
|
/**
|
||||||
|
* If name isn't null. Make sure that the name doesn't see any other disguise. Else if name is null. Make sure that the
|
||||||
|
* observers in the disguise don't see any other disguise.
|
||||||
|
*/
|
||||||
|
public static void checkConflicts(TargetedDisguise disguise, String name) {
|
||||||
|
if (DisguiseAPI.isDisguiseInUse(disguise)) {
|
||||||
|
Iterator<TargetedDisguise> disguiseItel = getDisguises().get(disguise.getEntity().getEntityId()).iterator();
|
||||||
|
while (disguiseItel.hasNext()) {
|
||||||
|
TargetedDisguise d = disguiseItel.next();
|
||||||
|
if (d != disguise) {
|
||||||
|
if (d.getTargetType() == TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS) {
|
||||||
|
// If player is a observer in the loop
|
||||||
|
if (disguise.getTargetType() == TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS) {
|
||||||
|
// If player is a observer in the disguise
|
||||||
|
// Remove them from the loop
|
||||||
|
if (name != null) {
|
||||||
|
d.unsetViewDisguise(name);
|
||||||
|
} else {
|
||||||
|
for (String playername : disguise.getObservers()) {
|
||||||
|
d.unsetViewDisguise(playername);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (disguise.getTargetType() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
|
||||||
|
// If player is not a observer in the loop
|
||||||
|
if (name != null) {
|
||||||
|
if (!disguise.getObservers().contains(name)) {
|
||||||
|
d.unsetViewDisguise(name);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (String playername : d.getObservers()) {
|
||||||
|
if (!disguise.getObservers().contains(playername)) {
|
||||||
|
d.unsetViewDisguise(playername);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (d.getTargetType() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
|
||||||
|
// Here you add it to the loop if they see the disguise
|
||||||
|
if (disguise.getTargetType() == TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS) {
|
||||||
|
// Everyone who is in the disguise needs to be added to the loop
|
||||||
|
if (name != null) {
|
||||||
|
d.setViewDisguise(name);
|
||||||
|
} else {
|
||||||
|
for (String playername : disguise.getObservers()) {
|
||||||
|
d.setViewDisguise(playername);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (disguise.getTargetType() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
|
||||||
|
// This here is a paradox.
|
||||||
|
// If fed a name. I can do this.
|
||||||
|
// But the rest of the time.. Its going to conflict.
|
||||||
|
System.out.print("Cannot set more than one " + TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS
|
||||||
|
+ " on a entity. Removed the old disguise.");
|
||||||
|
disguiseItel.remove();
|
||||||
|
/* if (name != null) {
|
||||||
|
if (!disguise.getObservers().contains(name)) {
|
||||||
|
d.setViewDisguise(name);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (String playername : d.getObservers()) {
|
||||||
|
if (!disguise.getObservers().contains(playername)) {
|
||||||
|
d.setViewDisguise(playername);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean removeDisguise(TargetedDisguise disguise) {
|
||||||
int entityId = disguise.getEntity().getEntityId();
|
int entityId = disguise.getEntity().getEntityId();
|
||||||
if (getDisguises().containsKey(entityId) && getDisguises().get(entityId).remove(disguise)) {
|
if (getDisguises().containsKey(entityId) && getDisguises().get(entityId).remove(disguise)) {
|
||||||
if (getDisguises().get(entityId).isEmpty()) {
|
if (getDisguises().get(entityId).isEmpty()) {
|
||||||
@ -251,11 +331,12 @@ public class DisguiseUtilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static TargettedDisguise getDisguise(int entityId) {
|
public static TargetedDisguise getDisguise(int entityId) {
|
||||||
TargettedDisguise toReturn = null;
|
TargetedDisguise toReturn = null;
|
||||||
if (getDisguises().containsKey(entityId)) {
|
if (getDisguises().containsKey(entityId)) {
|
||||||
for (TargettedDisguise disguise : getDisguises().get(entityId)) {
|
for (TargetedDisguise disguise : getDisguises().get(entityId)) {
|
||||||
if (disguise.getTargetType() == TargetType.HIDE_FROM_THESE && disguise.getObservers().isEmpty()) {
|
if (disguise.getTargetType() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS
|
||||||
|
&& disguise.getObservers().isEmpty()) {
|
||||||
return disguise;
|
return disguise;
|
||||||
}
|
}
|
||||||
if (toReturn == null) {
|
if (toReturn == null) {
|
||||||
@ -266,16 +347,16 @@ public class DisguiseUtilities {
|
|||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TargettedDisguise[] getDisguises(int entityId) {
|
public static TargetedDisguise[] getDisguises(int entityId) {
|
||||||
if (getDisguises().containsKey(entityId)) {
|
if (getDisguises().containsKey(entityId)) {
|
||||||
return getDisguises().get(entityId).toArray(new TargettedDisguise[getDisguises().get(entityId).size()]);
|
return getDisguises().get(entityId).toArray(new TargetedDisguise[getDisguises().get(entityId).size()]);
|
||||||
}
|
}
|
||||||
return new TargettedDisguise[0];
|
return new TargetedDisguise[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TargettedDisguise getDisguise(Player observer, int entityId) {
|
public static TargetedDisguise getDisguise(Player observer, int entityId) {
|
||||||
if (getDisguises().containsKey(entityId)) {
|
if (getDisguises().containsKey(entityId)) {
|
||||||
for (TargettedDisguise disguise : getDisguises().get(entityId)) {
|
for (TargetedDisguise disguise : getDisguises().get(entityId)) {
|
||||||
if (disguise.canSee(observer)) {
|
if (disguise.canSee(observer)) {
|
||||||
return disguise;
|
return disguise;
|
||||||
}
|
}
|
||||||
@ -291,7 +372,7 @@ public class DisguiseUtilities {
|
|||||||
Entity e = disguise.getEntity();
|
Entity e = disguise.getEntity();
|
||||||
// If the disguises entity is null, or the disguised entity isn't a player return
|
// If the disguises entity is null, or the disguised entity isn't a player return
|
||||||
if (e == null || !(e instanceof Player) || !getDisguises().containsKey(e.getEntityId())
|
if (e == null || !(e instanceof Player) || !getDisguises().containsKey(e.getEntityId())
|
||||||
|| !getDisguises().get(e).contains(disguise))
|
|| !getDisguises().get(e.getEntityId()).contains(disguise))
|
||||||
return;
|
return;
|
||||||
Player player = (Player) e;
|
Player player = (Player) e;
|
||||||
// Remove the old disguise, else we have weird disguises around the place
|
// Remove the old disguise, else we have weird disguises around the place
|
||||||
|
Loading…
Reference in New Issue
Block a user