More stuff including a small amount of cleanup
This commit is contained in:
parent
25a6e713af
commit
a969811c64
@ -11,6 +11,7 @@ import me.libraryaddict.disguise.utilities.ReflectionManager;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class DisguiseAPI {
|
||||
private static boolean hearSelfDisguise;
|
||||
@ -47,6 +48,7 @@ public class DisguiseAPI {
|
||||
* Disguise this entity with this disguise
|
||||
*/
|
||||
public static void disguiseToAll(Entity entity, Disguise disguise) {
|
||||
// TODO Make everyone see this disguise. Remove any old disguises.
|
||||
// If they are trying to disguise a null entity or use a null disguise
|
||||
// Just return.
|
||||
if (entity == null || disguise == null)
|
||||
@ -84,12 +86,22 @@ public class DisguiseAPI {
|
||||
/**
|
||||
* Get the disguise of a entity
|
||||
*/
|
||||
@Deprecated
|
||||
public static Disguise getDisguise(Entity disguised) {
|
||||
if (disguised == null)
|
||||
return null;
|
||||
return DisguiseUtilities.getDisguise(disguised.getEntityId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the disguise of a entity
|
||||
*/
|
||||
public static Disguise getDisguise(Player observer, Entity disguised) {
|
||||
if (disguised == null)
|
||||
return null;
|
||||
return DisguiseUtilities.getDisguise(observer, disguised.getEntityId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ID of a fake disguise for a entityplayer
|
||||
*/
|
||||
@ -102,10 +114,22 @@ public class DisguiseAPI {
|
||||
/**
|
||||
* Is this entity disguised
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isDisguised(Entity disguised) {
|
||||
return getDisguise(disguised) != null;
|
||||
}
|
||||
|
||||
public static boolean isDisguiseInUse(Disguise disguise) {
|
||||
return DisguiseUtilities.isDisguiseInUse(disguise);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this entity disguised
|
||||
*/
|
||||
public static boolean isDisguised(Player observer, Entity disguised) {
|
||||
return getDisguise(observer, disguised) != null;
|
||||
}
|
||||
|
||||
public static boolean isEntityAnimationsAdded() {
|
||||
return isEntityAnimationsAdded;
|
||||
}
|
||||
@ -213,6 +237,7 @@ public class DisguiseAPI {
|
||||
* the world.
|
||||
*/
|
||||
public static void undisguiseToAll(Entity entity) {
|
||||
// TODO Make all of these disguises be removed
|
||||
Disguise disguise = getDisguise(entity);
|
||||
if (disguise == null)
|
||||
return;
|
||||
|
@ -92,8 +92,7 @@ public class DisguiseListener implements Listener {
|
||||
public void onVechileEnter(VehicleEnterEvent event) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
Disguise disguise = DisguiseAPI.getDisguise(event.getEntered());
|
||||
if (disguise != null && event.getEntered() instanceof Player) {
|
||||
if (event.getEntered() instanceof Player && DisguiseAPI.isDisguised((Player) event.getEntered(), event.getEntered())) {
|
||||
DisguiseUtilities.removeSelfDisguise((Player) event.getEntered());
|
||||
((Player) event.getEntered()).updateInventory();
|
||||
}
|
||||
@ -103,14 +102,16 @@ public class DisguiseListener implements Listener {
|
||||
public void onVechileLeave(VehicleExitEvent event) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
final Disguise disguise = DisguiseAPI.getDisguise(event.getExited());
|
||||
if (disguise != null && event.getExited() instanceof Player) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
public void run() {
|
||||
DisguiseUtilities.setupFakeDisguise(disguise);
|
||||
((Player) disguise.getEntity()).updateInventory();
|
||||
}
|
||||
});
|
||||
if (event.getExited() instanceof Player) {
|
||||
final Disguise disguise = DisguiseAPI.getDisguise((Player) event.getExited(), event.getExited());
|
||||
if (disguise != null) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
public void run() {
|
||||
DisguiseUtilities.setupFakeDisguise(disguise);
|
||||
((Player) disguise.getEntity()).updateInventory();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -332,15 +332,15 @@ public abstract class Disguise {
|
||||
}
|
||||
|
||||
public boolean isMiscDisguise() {
|
||||
return this instanceof MiscDisguise;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isMobDisguise() {
|
||||
return this instanceof MobDisguise;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isPlayerDisguise() {
|
||||
return this instanceof PlayerDisguise;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isSelfDisguiseSoundsReplaced() {
|
||||
@ -550,7 +550,7 @@ public abstract class Disguise {
|
||||
if (this.viewSelfDisguise != viewSelfDisguise) {
|
||||
this.viewSelfDisguise = viewSelfDisguise;
|
||||
if (getEntity() != null && getEntity() instanceof Player) {
|
||||
if (DisguiseAPI.getDisguise(getEntity()) == this) {
|
||||
if (DisguiseAPI.getDisguise((Player) getEntity(), getEntity()) == this) {
|
||||
if (viewSelfDisguise) {
|
||||
DisguiseUtilities.setupFakeDisguise(this);
|
||||
} else
|
||||
|
@ -29,6 +29,10 @@ public class MiscDisguise extends TargettedDisguise {
|
||||
|| disguiseType == DisguiseType.DROPPED_ITEM ? -1 : addictionalData));
|
||||
}
|
||||
|
||||
public boolean isMiscDisguise() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public MiscDisguise(DisguiseType disguiseType, boolean replaceSounds, int id, int data) {
|
||||
createDisguise(disguiseType, replaceSounds);
|
||||
switch (disguiseType) {
|
||||
|
@ -22,6 +22,12 @@ public class MobDisguise extends TargettedDisguise {
|
||||
createDisguise(disguiseType, replaceSounds);
|
||||
}
|
||||
|
||||
|
||||
public boolean isMobDisguise() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
public MobDisguise(EntityType entityType) {
|
||||
this(entityType, true);
|
||||
|
@ -14,6 +14,11 @@ public class PlayerDisguise extends TargettedDisguise {
|
||||
createDisguise(DisguiseType.PLAYER, replaceSounds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlayerDisguise() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerDisguise clone() {
|
||||
PlayerDisguise disguise = new PlayerDisguise(getName(), isSoundsReplaced());
|
||||
|
@ -2,6 +2,8 @@ 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 {
|
||||
@ -9,6 +11,13 @@ public abstract class TargettedDisguise extends Disguise {
|
||||
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;
|
||||
|
||||
@ -16,6 +25,10 @@ public abstract class TargettedDisguise extends Disguise {
|
||||
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) {
|
||||
|
@ -46,6 +46,14 @@ public class DisguiseUtilities {
|
||||
libsDisguises = disguises;
|
||||
}
|
||||
|
||||
public static boolean isDisguiseInUse(Disguise disguise) {
|
||||
if (getDisguises().containsKey(disguise.getEntity().getEntityId())
|
||||
&& getDisguises().get(disguise.getEntity().getEntityId()).contains(disguise)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Resends
|
||||
* the entity to all the watching players, which is where the magic begins
|
||||
@ -242,11 +250,12 @@ public class DisguiseUtilities {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static TargettedDisguise getDisguise(int entityId) {
|
||||
TargettedDisguise toReturn = null;
|
||||
if (getDisguises().containsKey(entityId)) {
|
||||
for (TargettedDisguise disguise : getDisguises().get(entityId)) {
|
||||
if (disguise.getTargetType() == TargetType.HIDE_FROM_THESE) {
|
||||
if (disguise.getTargetType() == TargetType.HIDE_FROM_THESE && disguise.getObservers().isEmpty()) {
|
||||
return disguise;
|
||||
}
|
||||
if (toReturn == null) {
|
||||
|
@ -467,8 +467,10 @@ public class PacketsManager {
|
||||
((Integer) mods.read(2)) / 8D, ((Integer) mods.read(3)) / 8D);
|
||||
Entity disguisedEntity = null;
|
||||
DisguiseSound entitySound = null;
|
||||
Disguise disguise = null;
|
||||
for (Entity entity : soundLoc.getChunk().getEntities()) {
|
||||
if (DisguiseAPI.isDisguised(entity)) {
|
||||
Disguise entityDisguise = DisguiseAPI.getDisguise(observer, entity);
|
||||
if (entityDisguise != null) {
|
||||
Location loc = entity.getLocation();
|
||||
loc = new Location(observer.getWorld(), ((int) (loc.getX() * 8)) / 8D, ((int) (loc.getY() * 8)) / 8D,
|
||||
((int) (loc.getZ() * 8)) / 8D);
|
||||
@ -506,6 +508,7 @@ public class PacketsManager {
|
||||
soundType = entitySound.getType(soundName, !hasInvun);
|
||||
}
|
||||
if (soundType != null) {
|
||||
disguise = entityDisguise;
|
||||
disguisedEntity = entity;
|
||||
break;
|
||||
}
|
||||
@ -513,7 +516,6 @@ public class PacketsManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
Disguise disguise = DisguiseAPI.getDisguise(disguisedEntity);
|
||||
if (disguise != null) {
|
||||
if (disguise.isSelfDisguiseSoundsReplaced() || disguisedEntity != event.getPlayer()) {
|
||||
if (disguise.isSoundsReplaced()) {
|
||||
@ -599,7 +601,7 @@ public class PacketsManager {
|
||||
if ((Byte) mods.read(1) == 1) {
|
||||
// It made a damage animation
|
||||
Entity entity = event.getPacket().getEntityModifier(observer.getWorld()).read(0);
|
||||
Disguise disguise = DisguiseAPI.getDisguise(entity);
|
||||
Disguise disguise = DisguiseAPI.getDisguise(observer, entity);
|
||||
if (disguise != null && (disguise.isSelfDisguiseSoundsReplaced() || entity != event.getPlayer())) {
|
||||
DisguiseSound disSound = DisguiseSound.getType(entity.getType().name());
|
||||
if (disSound == null)
|
||||
@ -769,7 +771,7 @@ public class PacketsManager {
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
// If the inventory is the players inventory
|
||||
if (event.getPlayer().getVehicle() == null && event.getPacket().getIntegers().read(0) == 0) {
|
||||
Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer());
|
||||
Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer(), event.getPlayer());
|
||||
// If the player is disguised, views self disguises and is hiding a item.
|
||||
if (disguise != null && disguise.isSelfDisguiseVisible()
|
||||
&& (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) {
|
||||
@ -860,7 +862,7 @@ public class PacketsManager {
|
||||
@Override
|
||||
public void onPacketReceiving(final PacketEvent event) {
|
||||
if (event.getPlayer().getVehicle() == null) {
|
||||
Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer());
|
||||
Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer(), event.getPlayer());
|
||||
// If player is disguised, views self disguises and has a inventory modifier
|
||||
if (disguise != null && disguise.isSelfDisguiseVisible()
|
||||
&& (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) {
|
||||
@ -1056,7 +1058,7 @@ public class PacketsManager {
|
||||
ProtocolLibrary.getProtocolManager().removePacketListener(inventoryListenerServer);
|
||||
}
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
Disguise disguise = DisguiseAPI.getDisguise(player);
|
||||
Disguise disguise = DisguiseAPI.getDisguise(player, player);
|
||||
if (disguise != null) {
|
||||
if (viewDisguisesListenerEnabled && disguise.isSelfDisguiseVisible()
|
||||
&& (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) {
|
||||
@ -1076,7 +1078,7 @@ public class PacketsManager {
|
||||
ProtocolLibrary.getProtocolManager().removePacketListener(viewDisguisesListener);
|
||||
}
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
Disguise disguise = DisguiseAPI.getDisguise(player);
|
||||
Disguise disguise = DisguiseAPI.getDisguise(player, player);
|
||||
if (disguise != null) {
|
||||
if (disguise.isSelfDisguiseVisible()) {
|
||||
if (enabled) {
|
||||
@ -1102,7 +1104,7 @@ public class PacketsManager {
|
||||
// First get the entity, the one sending this packet
|
||||
StructureModifier<Entity> entityModifer = sentPacket.getEntityModifier(observer.getWorld());
|
||||
org.bukkit.entity.Entity entity = entityModifer.read((Packets.Server.COLLECT == sentPacket.getID() ? 1 : 0));
|
||||
Disguise disguise = DisguiseAPI.getDisguise(entity);
|
||||
Disguise disguise = DisguiseAPI.getDisguise(observer, entity);
|
||||
// If disguised.
|
||||
if (disguise != null) {
|
||||
// If packet is Packets.Server.UPDATE_ATTRIBUTES
|
||||
@ -1157,8 +1159,9 @@ public class PacketsManager {
|
||||
case Packets.Server.COLLECT:
|
||||
|
||||
{
|
||||
if (disguise.getType().isMisc())
|
||||
if (disguise.getType().isMisc()) {
|
||||
packets = new PacketContainer[0];
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user