Added new config options to keep a disguise

This commit is contained in:
libraryaddict 2014-04-03 02:39:52 +13:00
parent 376f18ef95
commit 25df368e9a
5 changed files with 84 additions and 22 deletions

View File

@ -56,3 +56,11 @@ MonstersIgnoreDisguises: false
# This will blow all disguises he has on him
BlowDisguises: false
BlownDisguiseMessage: '&cYour disguise was blown!'
# This I don't really recommend turning on as it can make a memory leak..
# These disguises, as normal will not persist after a server restart.
# There is also no EntityDeath option as entities do not revive after death.
KeepDisguises:
PlayerDeath: false
PlayerLogout: false
EntityDespawn: false

View File

@ -9,6 +9,9 @@ public class DisguiseConfig {
private static boolean hearSelfDisguise;
private static boolean hidingArmor;
private static boolean hidingHeldItem;
private static boolean keepDisguiseEntityDespawn;
private static boolean keepDisguisePlayerDeath;
private static boolean keepDisguisePlayerLogout;
private static boolean modifyBoundingBox;
private static boolean removeUnseenDisguises;
private static boolean sendVelocity;
@ -47,6 +50,18 @@ public class DisguiseConfig {
return hidingHeldItem;
}
public static boolean isKeepDisguiseOnEntityDespawn() {
return keepDisguiseEntityDespawn;
}
public static boolean isKeepDisguiseOnPlayerDeath() {
return keepDisguisePlayerDeath;
}
public static boolean isKeepDisguiseOnPlayerLogout() {
return keepDisguisePlayerLogout;
}
public static boolean isModifyBoundingBox() {
return modifyBoundingBox;
}
@ -133,6 +148,18 @@ public class DisguiseConfig {
}
}
public static void setKeepDisguiseOnEntityDespawn(boolean keepDisguise) {
keepDisguiseEntityDespawn = keepDisguise;
}
public static void setKeepDisguiseOnPlayerDeath(boolean keepDisguise) {
keepDisguisePlayerDeath = keepDisguise;
}
public static void setKeepDisguiseOnPlayerLogout(boolean keepDisguise) {
keepDisguisePlayerLogout = keepDisguise;
}
public static void setModifyBoundingBox(boolean modifyBounding) {
modifyBoundingBox = modifyBounding;
}

View File

@ -74,6 +74,9 @@ public class LibsDisguises extends JavaPlugin {
DisguiseConfig.setDisguiseBlownOnAttack(getConfig().getBoolean("BlowDisguises"));
DisguiseConfig.setDisguiseBlownMessage(ChatColor.translateAlternateColorCodes('&',
getConfig().getString("BlownDisguiseMessage")));
DisguiseConfig.setKeepDisguiseOnPlayerDeath(getConfig().getBoolean("KeepDisguises.PlayerDeath"));
DisguiseConfig.setKeepDisguiseOnPlayerLogout(getConfig().getBoolean("KeepDisguises.PlayerLogout"));
DisguiseConfig.setKeepDisguiseOnEntityDespawn(getConfig().getBoolean("KeepDisguises.EntityDespawn"));
try {
// Here I use reflection to set the plugin for Disguise..
// Kind of stupid but I don't want open API calls for a commonly used object.

View File

@ -17,6 +17,7 @@ import me.libraryaddict.disguise.utilities.PacketsManager;
import me.libraryaddict.disguise.utilities.ReflectionManager;
import me.libraryaddict.disguise.utilities.DisguiseValues;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Horse.Variant;
@ -37,8 +38,10 @@ public abstract class Disguise {
private boolean hearSelfDisguise = DisguiseConfig.isSelfDisguisesSoundsReplaced();
private boolean hideArmorFromSelf = DisguiseConfig.isHidingArmorFromSelf();
private boolean hideHeldItemFromSelf = DisguiseConfig.isHidingHeldItemFromSelf();
private boolean keepDisguiseEntityDespawn = DisguiseConfig.isKeepDisguiseOnEntityDespawn();
private boolean keepDisguisePlayerDeath = DisguiseConfig.isKeepDisguiseOnPlayerDeath();
private boolean keepDisguisePlayerLogout = DisguiseConfig.isKeepDisguiseOnPlayerLogout();
private boolean modifyBoundingBox = DisguiseConfig.isModifyBoundingBox();
private boolean removeWhenInvalid = true;
private boolean replaceSounds = DisguiseConfig.isSoundEnabled();
private BukkitRunnable velocityRunnable;
private boolean velocitySent = DisguiseConfig.isVelocitySent();
@ -186,7 +189,15 @@ public abstract class Disguise {
public void run() {
// If entity is no longer valid. Remove it.
if (!getEntity().isValid()) {
if (isRemoveWhenInvalid()) {
if (getEntity() instanceof Player ?
(Bukkit.getPlayerExact(((Player) getEntity()).getName()) == null ? !isKeepDisguiseOnPlayerLogout()
: !isKeepDisguiseOnPlayerDeath())
:
(!isKeepDisguiseOnEntityDespawn() || getEntity().isDead())) {
removeDisguise();
} else {
entity = null;
@ -327,6 +338,18 @@ public abstract class Disguise {
return hideHeldItemFromSelf;
}
public boolean isKeepDisguiseOnEntityDespawn() {
return this.keepDisguiseEntityDespawn;
}
public boolean isKeepDisguiseOnPlayerDeath() {
return this.keepDisguisePlayerDeath;
}
public boolean isKeepDisguiseOnPlayerLogout() {
return this.keepDisguisePlayerLogout;
}
public boolean isMiscDisguise() {
return false;
}
@ -343,13 +366,6 @@ public abstract class Disguise {
return false;
}
/**
* Is the disguise removed when the disguised entity is invalid?
*/
public boolean isRemoveWhenInvalid() {
return removeWhenInvalid;
}
public boolean isSelfDisguiseSoundsReplaced() {
return hearSelfDisguise;
}
@ -443,6 +459,18 @@ public abstract class Disguise {
}
}
public void setKeepDisguiseOnEntityDespawn(boolean keepDisguise) {
this.keepDisguiseEntityDespawn = keepDisguise;
}
public void setKeepDisguiseOnPlayerDeath(boolean keepDisguise) {
this.keepDisguisePlayerDeath = keepDisguise;
}
public void setKeepDisguiseOnPlayerLogout(boolean keepDisguise) {
this.keepDisguisePlayerLogout = keepDisguise;
}
public void setModifyBoundingBox(boolean modifyBox) {
if (((TargetedDisguise) this).getDisguiseTarget() != TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
throw new RuntimeException(
@ -456,10 +484,6 @@ public abstract class Disguise {
}
}
public void setRemoveDisguiseWhenInvalid(boolean removeWhenInvalid) {
this.removeWhenInvalid = removeWhenInvalid;
}
public void setReplaceSounds(boolean areSoundsReplaced) {
replaceSounds = areSoundsReplaced;
}

View File

@ -37,20 +37,13 @@ import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
public class DisguiseUtilities {
private static HashMap<Integer, HashSet<TargetedDisguise>> futureDisguises = new HashMap<Integer, HashSet<TargetedDisguise>>();
private static LibsDisguises libsDisguises;
// 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
private static HashMap<UUID, Integer> selfDisguisesIds = new HashMap<UUID, Integer>();
// Store the entity IDs instead of entitys because then I can disguise entitys even before they exist
private static HashMap<UUID, HashSet<TargetedDisguise>> targetedDisguises = new HashMap<UUID, HashSet<TargetedDisguise>>();
private static HashMap<Integer, HashSet<TargetedDisguise>> futureDisguises = new HashMap<Integer, HashSet<TargetedDisguise>>();
public static void addFutureDisguise(int entityId, TargetedDisguise disguise) {
if (!futureDisguises.containsKey(entityId)) {
futureDisguises.put(entityId, new HashSet<TargetedDisguise>());
}
futureDisguises.get(entityId).add(disguise);
}
public static void addDisguise(UUID entityId, TargetedDisguise disguise) {
if (!getDisguises().containsKey(entityId)) {
@ -63,6 +56,13 @@ public class DisguiseUtilities {
}
}
public static void addFutureDisguise(int entityId, TargetedDisguise disguise) {
if (!futureDisguises.containsKey(entityId)) {
futureDisguises.put(entityId, new HashSet<TargetedDisguise>());
}
futureDisguises.get(entityId).add(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.