Read desc

Changed config methods to DisguiseConfig
Added a new config option to blow a disguise
This commit is contained in:
libraryaddict 2014-01-21 06:01:49 +13:00
parent ff6567ba23
commit 38ee3dc983
11 changed files with 241 additions and 191 deletions

View File

@ -50,3 +50,9 @@ ModifyBoundingBox: false
# This doesn't prevent their targeting you if already targeting when disguised
# They will just ignore you unless provoked.
MonstersIgnoreDisguises: false
# Sigh. People are going to want this.
# So lets make your disguise blown if you are attacked..
# Works only for disguised players when attacked by a entity (arrow, monster. etc)
# This will blow all disguises he has on him
BlowDisguises: false
BlownDisguiseMessage: '&cYour disguise was blown!'

View File

@ -10,7 +10,6 @@ import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
import me.libraryaddict.disguise.events.DisguiseEvent;
import me.libraryaddict.disguise.events.UndisguiseEvent;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.PacketsManager;
import me.libraryaddict.disguise.utilities.ReflectionManager;
import org.bukkit.Bukkit;
@ -18,21 +17,6 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
public class DisguiseAPI {
private static boolean hearSelfDisguise;
private static boolean hidingArmor;
private static boolean hidingHeldItem;
private static boolean isEntityAnimationsAdded;
private static boolean modifyBoundingBox;
private static boolean removeUnseenDisguises;
private static boolean sendVelocity;
private static boolean showNameAboveHead;
private static boolean showNameAboveHeadAlwaysVisible;
private static boolean targetDisguises;
@Deprecated
public static boolean canHearSelfDisguise() {
return hearSelfDisguise;
}
public static void disguiseEntity(Entity entity, Disguise disguise) {
// If they are trying to disguise a null entity or use a null disguise
@ -184,140 +168,6 @@ public class DisguiseAPI {
return DisguiseUtilities.isDisguiseInUse(disguise);
}
public static boolean isEntityAnimationsAdded() {
return isEntityAnimationsAdded;
}
/**
* Is the plugin modifying the inventory packets so that players when self disguised, do not see their armor floating around
*/
public static boolean isHidingArmorFromSelf() {
return hidingArmor;
}
/**
* Does the plugin appear to remove the item they are holding, to prevent a floating sword when they are viewing self disguise
*/
public static boolean isHidingHeldItemFromSelf() {
return hidingHeldItem;
}
public static boolean isModifyBoundingBox() {
return modifyBoundingBox;
}
public static boolean isMonstersIgnoreDisguises() {
return targetDisguises;
}
public static boolean isNameAboveHeadAlwaysVisible() {
return showNameAboveHeadAlwaysVisible;
}
public static boolean isNameOfPlayerShownAboveDisguise() {
return showNameAboveHead;
}
public static boolean isSelfDisguisesSoundsReplaced() {
return hearSelfDisguise;
}
/**
* Is the sound packets caught and modified
*/
public static boolean isSoundEnabled() {
return PacketsManager.isHearDisguisesEnabled();
}
public static boolean isUnusedDisguisesRemoved() {
return removeUnseenDisguises;
}
/**
* Is the velocity packets sent
*/
public static boolean isVelocitySent() {
return sendVelocity;
}
/**
* The default value if a player views his own disguise
*/
public static boolean isViewDisguises() {
return PacketsManager.isViewDisguisesListenerEnabled();
}
public static void setAddEntityAnimations(boolean isEntityAnimationsAdded) {
DisguiseAPI.isEntityAnimationsAdded = isEntityAnimationsAdded;
}
/**
* Can players hear their own disguises
*/
public static void setHearSelfDisguise(boolean replaceSound) {
if (hearSelfDisguise != replaceSound) {
hearSelfDisguise = replaceSound;
}
}
/**
* Set the plugin to hide self disguises armor from theirselves
*/
public static void setHideArmorFromSelf(boolean hideArmor) {
if (hidingArmor != hideArmor) {
hidingArmor = hideArmor;
PacketsManager.setInventoryListenerEnabled(isHidingHeldItemFromSelf() || isHidingArmorFromSelf());
}
}
/**
* Does the plugin appear to remove the item they are holding, to prevent a floating sword when they are viewing self disguise
*/
public static void setHideHeldItemFromSelf(boolean hideHelditem) {
if (hidingHeldItem != hideHelditem) {
hidingHeldItem = hideHelditem;
PacketsManager.setInventoryListenerEnabled(isHidingHeldItemFromSelf() || isHidingArmorFromSelf());
}
}
public static void setModifyBoundingBox(boolean modifyBounding) {
modifyBoundingBox = modifyBounding;
}
public static void setMonstersIgnoreDisguises(boolean ignore) {
targetDisguises = ignore;
}
public static void setNameAboveHeadAlwaysVisible(boolean alwaysVisible) {
showNameAboveHeadAlwaysVisible = alwaysVisible;
}
public static void setNameOfPlayerShownAboveDisguise(boolean showNames) {
showNameAboveHead = showNames;
}
/**
* Set if the disguises play sounds when hurt
*/
public static void setSoundsEnabled(boolean isSoundsEnabled) {
PacketsManager.setHearDisguisesListener(isSoundsEnabled);
}
public static void setUnusedDisguisesRemoved(boolean remove) {
removeUnseenDisguises = remove;
}
/**
* Disable velocity packets being sent for w/e reason. Maybe you want every ounce of performance you can get?
*/
public static void setVelocitySent(boolean sendVelocityPackets) {
sendVelocity = sendVelocityPackets;
}
public static void setViewDisguises(boolean seeOwnDisguise) {
PacketsManager.setViewDisguisesListener(seeOwnDisguise);
}
/**
* Undisguise the entity. This doesn't let you cancel the UndisguiseEvent if the entity is no longer valid. Aka removed from
* the world.

View File

@ -0,0 +1,168 @@
package me.libraryaddict.disguise;
import me.libraryaddict.disguise.utilities.PacketsManager;
public class DisguiseConfig {
private static boolean blowDisguisesOnAttack;
private static boolean entityAnimationsAdded;
private static boolean hearSelfDisguise;
private static boolean hidingArmor;
private static boolean hidingHeldItem;
private static boolean modifyBoundingBox;
private static boolean removeUnseenDisguises;
private static boolean sendVelocity;
private static boolean showNameAboveHead;
private static boolean showNameAboveHeadAlwaysVisible;
private static boolean targetDisguises;
@Deprecated
public static boolean canHearSelfDisguise() {
return hearSelfDisguise;
}
public static boolean isDisguiseBlownOnAttack() {
return blowDisguisesOnAttack;
}
public static boolean isEntityAnimationsAdded() {
return entityAnimationsAdded;
}
/**
* Is the plugin modifying the inventory packets so that players when self disguised, do not see their armor floating around
*/
public static boolean isHidingArmorFromSelf() {
return hidingArmor;
}
/**
* Does the plugin appear to remove the item they are holding, to prevent a floating sword when they are viewing self disguise
*/
public static boolean isHidingHeldItemFromSelf() {
return hidingHeldItem;
}
public static boolean isModifyBoundingBox() {
return modifyBoundingBox;
}
public static boolean isMonstersIgnoreDisguises() {
return targetDisguises;
}
public static boolean isNameAboveHeadAlwaysVisible() {
return showNameAboveHeadAlwaysVisible;
}
public static boolean isNameOfPlayerShownAboveDisguise() {
return showNameAboveHead;
}
public static boolean isSelfDisguisesSoundsReplaced() {
return hearSelfDisguise;
}
/**
* Is the sound packets caught and modified
*/
public static boolean isSoundEnabled() {
return PacketsManager.isHearDisguisesEnabled();
}
public static boolean isUnusedDisguisesRemoved() {
return removeUnseenDisguises;
}
/**
* Is the velocity packets sent
*/
public static boolean isVelocitySent() {
return sendVelocity;
}
/**
* The default value if a player views his own disguise
*/
public static boolean isViewDisguises() {
return PacketsManager.isViewDisguisesListenerEnabled();
}
public static void setAddEntityAnimations(boolean isEntityAnimationsAdded) {
entityAnimationsAdded = isEntityAnimationsAdded;
}
public static void setDisguiseBlownOnAttack(boolean blowDisguise) {
blowDisguisesOnAttack = blowDisguise;
}
/**
* Can players hear their own disguises
*/
public static void setHearSelfDisguise(boolean replaceSound) {
if (hearSelfDisguise != replaceSound) {
hearSelfDisguise = replaceSound;
}
}
/**
* Set the plugin to hide self disguises armor from theirselves
*/
public static void setHideArmorFromSelf(boolean hideArmor) {
if (hidingArmor != hideArmor) {
hidingArmor = hideArmor;
PacketsManager.setInventoryListenerEnabled(isHidingHeldItemFromSelf() || isHidingArmorFromSelf());
}
}
/**
* Does the plugin appear to remove the item they are holding, to prevent a floating sword when they are viewing self disguise
*/
public static void setHideHeldItemFromSelf(boolean hideHelditem) {
if (hidingHeldItem != hideHelditem) {
hidingHeldItem = hideHelditem;
PacketsManager.setInventoryListenerEnabled(isHidingHeldItemFromSelf() || isHidingArmorFromSelf());
}
}
public static void setModifyBoundingBox(boolean modifyBounding) {
modifyBoundingBox = modifyBounding;
}
public static void setMonstersIgnoreDisguises(boolean ignore) {
targetDisguises = ignore;
}
public static void setNameAboveHeadAlwaysVisible(boolean alwaysVisible) {
showNameAboveHeadAlwaysVisible = alwaysVisible;
}
public static void setNameOfPlayerShownAboveDisguise(boolean showNames) {
showNameAboveHead = showNames;
}
/**
* Set if the disguises play sounds when hurt
*/
public static void setSoundsEnabled(boolean isSoundsEnabled) {
PacketsManager.setHearDisguisesListener(isSoundsEnabled);
}
public static void setUnusedDisguisesRemoved(boolean remove) {
removeUnseenDisguises = remove;
}
/**
* Disable velocity packets being sent for w/e reason. Maybe you want every ounce of performance you can get?
*/
public static void setVelocitySent(boolean sendVelocityPackets) {
sendVelocity = sendVelocityPackets;
}
public static void setViewDisguises(boolean seeOwnDisguise) {
PacketsManager.setViewDisguisesListener(seeOwnDisguise);
}
private DisguiseConfig() {
}
}

View File

@ -14,6 +14,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerJoinEvent;
@ -63,6 +64,22 @@ public class DisguiseListener implements Listener {
}
}
@EventHandler
public void onAttack(EntityDamageByEntityEvent event) {
if (DisguiseConfig.isDisguiseBlownOnAttack() && event.getEntity() instanceof Player) {
Disguise[] disguises = DisguiseAPI.getDisguises(event.getEntity());
if (disguises.length > 0) {
DisguiseAPI.undisguiseToAll(event.getEntity());
for (Disguise disguise : disguises) {
if (DisguiseUtilities.isDisguiseInUse(disguise)) {
((Player) event.getEntity()).sendMessage(ChatColor.RED + "Your disguise was blown!");
break;
}
}
}
}
}
@EventHandler
public void onJoin(PlayerJoinEvent event) {
Player p = event.getPlayer();
@ -72,7 +89,7 @@ public class DisguiseListener implements Listener {
@EventHandler
public void onQuit(PlayerQuitEvent event) {
if (DisguiseAPI.isUnusedDisguisesRemoved()) {
if (DisguiseConfig.isUnusedDisguisesRemoved()) {
for (TargetedDisguise disguise : DisguiseUtilities.getSeenDisguises(event.getPlayer().getName())) {
disguise.removeDisguise();
}
@ -87,11 +104,11 @@ public class DisguiseListener implements Listener {
disguiseRunnable.remove(event.getPlayer().getName()).cancel();
String entityName = event.getRightClicked().getType().name().toLowerCase().replace("_", " ");
if (disguise != null) {
if (event.getRightClicked() instanceof Player && DisguiseAPI.isNameOfPlayerShownAboveDisguise()) {
if (event.getRightClicked() instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
if (disguise.getWatcher() instanceof LivingWatcher) {
((LivingWatcher) disguise.getWatcher())
.setCustomName(((Player) event.getRightClicked()).getDisplayName());
if (DisguiseAPI.isNameAboveHeadAlwaysVisible()) {
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
((LivingWatcher) disguise.getWatcher()).setCustomNameVisible(true);
}
}
@ -112,7 +129,7 @@ public class DisguiseListener implements Listener {
@EventHandler
public void onTarget(EntityTargetEvent event) {
if (DisguiseAPI.isMonstersIgnoreDisguises() && event.getTarget() != null && event.getTarget() instanceof Player
if (DisguiseConfig.isMonstersIgnoreDisguises() && event.getTarget() != null && event.getTarget() instanceof Player
&& DisguiseAPI.isDisguised(event.getTarget())) {
switch (event.getReason()) {
case TARGET_ATTACKED_ENTITY:

View File

@ -58,17 +58,18 @@ public class LibsDisguises extends JavaPlugin {
}
PacketsManager.init(this);
DisguiseUtilities.init(this);
DisguiseAPI.setSoundsEnabled(getConfig().getBoolean("DisguiseSounds"));
DisguiseAPI.setVelocitySent(getConfig().getBoolean("SendVelocity"));
DisguiseAPI.setViewDisguises(getConfig().getBoolean("ViewSelfDisguises"));
DisguiseAPI.setHearSelfDisguise(getConfig().getBoolean("HearSelfDisguise"));
DisguiseAPI.setHideArmorFromSelf(getConfig().getBoolean("RemoveArmor"));
DisguiseAPI.setHideHeldItemFromSelf(getConfig().getBoolean("RemoveHeldItem"));
DisguiseAPI.setAddEntityAnimations(getConfig().getBoolean("AddEntityAnimations"));
DisguiseAPI.setNameOfPlayerShownAboveDisguise(getConfig().getBoolean("ShowNamesAboveDisguises"));
DisguiseAPI.setNameAboveHeadAlwaysVisible(getConfig().getBoolean("NameAboveHeadAlwaysVisible"));
DisguiseAPI.setModifyBoundingBox(getConfig().getBoolean("ModifyBoundingBox"));
DisguiseAPI.setMonstersIgnoreDisguises(getConfig().getBoolean("MonstersIgnoreDisguises"));
DisguiseConfig.setSoundsEnabled(getConfig().getBoolean("DisguiseSounds"));
DisguiseConfig.setVelocitySent(getConfig().getBoolean("SendVelocity"));
DisguiseConfig.setViewDisguises(getConfig().getBoolean("ViewSelfDisguises"));
DisguiseConfig.setHearSelfDisguise(getConfig().getBoolean("HearSelfDisguise"));
DisguiseConfig.setHideArmorFromSelf(getConfig().getBoolean("RemoveArmor"));
DisguiseConfig.setHideHeldItemFromSelf(getConfig().getBoolean("RemoveHeldItem"));
DisguiseConfig.setAddEntityAnimations(getConfig().getBoolean("AddEntityAnimations"));
DisguiseConfig.setNameOfPlayerShownAboveDisguise(getConfig().getBoolean("ShowNamesAboveDisguises"));
DisguiseConfig.setNameAboveHeadAlwaysVisible(getConfig().getBoolean("NameAboveHeadAlwaysVisible"));
DisguiseConfig.setModifyBoundingBox(getConfig().getBoolean("ModifyBoundingBox"));
DisguiseConfig.setMonstersIgnoreDisguises(getConfig().getBoolean("MonstersIgnoreDisguises"));
DisguiseConfig.setDisguiseBlownOnAttack(getConfig().getBoolean("BlowDisguises"));
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

@ -1,7 +1,9 @@
package me.libraryaddict.disguise.commands;
import java.util.ArrayList;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.utilities.BaseDisguiseCommand;
@ -31,10 +33,10 @@ public class DisguiseCommand extends BaseDisguiseCommand {
}
return true;
}
if (DisguiseAPI.isNameOfPlayerShownAboveDisguise()) {
if (DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
if (disguise.getWatcher() instanceof LivingWatcher) {
((LivingWatcher) disguise.getWatcher()).setCustomName(((Player) sender).getDisplayName());
if (DisguiseAPI.isNameAboveHeadAlwaysVisible()) {
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
((LivingWatcher) disguise.getWatcher()).setCustomNameVisible(true);
}
}

View File

@ -1,7 +1,9 @@
package me.libraryaddict.disguise.commands;
import java.util.ArrayList;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.utilities.BaseDisguiseCommand;
@ -50,10 +52,10 @@ public class DisguisePlayerCommand extends BaseDisguiseCommand {
}
return true;
}
if (DisguiseAPI.isNameOfPlayerShownAboveDisguise()) {
if (DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
if (disguise.getWatcher() instanceof LivingWatcher) {
((LivingWatcher) disguise.getWatcher()).setCustomName(((Player) player).getDisplayName());
if (DisguiseAPI.isNameAboveHeadAlwaysVisible()) {
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
((LivingWatcher) disguise.getWatcher()).setCustomNameVisible(true);
}
}

View File

@ -1,7 +1,9 @@
package me.libraryaddict.disguise.commands;
import java.util.ArrayList;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.utilities.BaseDisguiseCommand;
@ -68,10 +70,10 @@ public class DisguiseRadiusCommand extends BaseDisguiseCommand {
if (entity == sender)
continue;
disguise = disguise.clone();
if (entity instanceof Player && DisguiseAPI.isNameOfPlayerShownAboveDisguise()) {
if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
if (disguise.getWatcher() instanceof LivingWatcher) {
((LivingWatcher) disguise.getWatcher()).setCustomName(((Player) entity).getDisplayName());
if (DisguiseAPI.isNameAboveHeadAlwaysVisible()) {
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
((LivingWatcher) disguise.getWatcher()).setCustomNameVisible(true);
}
}

View File

@ -6,6 +6,7 @@ import java.util.HashSet;
import java.util.Iterator;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
@ -32,14 +33,14 @@ public abstract class Disguise {
private static JavaPlugin plugin;
private DisguiseType disguiseType;
private Entity entity;
private boolean hearSelfDisguise = DisguiseAPI.isSelfDisguisesSoundsReplaced();
private boolean hideArmorFromSelf = DisguiseAPI.isHidingArmorFromSelf();
private boolean hideHeldItemFromSelf = DisguiseAPI.isHidingHeldItemFromSelf();
private boolean modifyBoundingBox = DisguiseAPI.isModifyBoundingBox();
private boolean replaceSounds = DisguiseAPI.isSoundEnabled();
private boolean hearSelfDisguise = DisguiseConfig.isSelfDisguisesSoundsReplaced();
private boolean hideArmorFromSelf = DisguiseConfig.isHidingArmorFromSelf();
private boolean hideHeldItemFromSelf = DisguiseConfig.isHidingHeldItemFromSelf();
private boolean modifyBoundingBox = DisguiseConfig.isModifyBoundingBox();
private boolean replaceSounds = DisguiseConfig.isSoundEnabled();
private BukkitRunnable velocityRunnable;
private boolean velocitySent = DisguiseAPI.isVelocitySent();
private boolean viewSelfDisguise = DisguiseAPI.isViewDisguises();
private boolean velocitySent = DisguiseConfig.isVelocitySent();
private boolean viewSelfDisguise = DisguiseConfig.isViewDisguises();
private FlagWatcher watcher;
@Deprecated
@ -264,7 +265,7 @@ public abstract class Disguise {
packet.getIntegers().write(0, getEntity().getEntityId());
try {
for (Player player : DisguiseUtilities.getPerverts(disguise)) {
if (DisguiseAPI.isViewDisguises() || getEntity() != player) {
if (DisguiseConfig.isViewDisguises() || getEntity() != player) {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
}
}

View File

@ -19,6 +19,7 @@ import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.ReflectionManager;
@ -37,7 +38,7 @@ public class FlagWatcher {
}
}
private boolean addEntityAnimations = DisguiseAPI.isEntityAnimationsAdded();
private boolean addEntityAnimations = DisguiseConfig.isEntityAnimationsAdded();
/**
* This is the entity values I need to add else it could crash them..
*/
@ -230,7 +231,7 @@ public class FlagWatcher {
mods.write(0, entity.getEntityId());
packet.getWatchableCollectionModifier().write(0, list);
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
if (DisguiseAPI.isViewDisguises() || player != entity) {
if (DisguiseConfig.isViewDisguises() || player != entity) {
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
} catch (InvocationTargetException e) {

View File

@ -55,15 +55,6 @@ public class ReflectionManager {
private static Class itemClass;
private static Field pingField;
public static double getPing(Player player) {
try {
return (double) pingField.getInt(ReflectionManager.getNmsEntity(player));
} catch (Exception ex) {
ex.printStackTrace();
}
return 0D;
}
static {
for (Method method : getNmsClass("EntityLiving").getDeclaredMethods()) {
try {
@ -252,6 +243,15 @@ public class ReflectionManager {
return null;
}
public static double getPing(Player player) {
try {
return (double) pingField.getInt(ReflectionManager.getNmsEntity(player));
} catch (Exception ex) {
ex.printStackTrace();
}
return 0D;
}
public static float[] getSize(Entity entity) {
try {
float length = getNmsClass("Entity").getField("length").getFloat(getNmsEntity(entity));