Use lombok, add new config options for disabling pvp, pve, action bar when disguised, permission to hide name above head

This commit is contained in:
libraryaddict 2020-02-02 11:59:18 +13:00
parent 5f98e57316
commit ed098752f6
No known key found for this signature in database
GPG key ID: 052E4FBCD257AEA4
14 changed files with 590 additions and 720 deletions

View file

@ -46,6 +46,12 @@
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>

View file

@ -1,5 +1,8 @@
package me.libraryaddict.disguise;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.LibsPremium;
@ -9,130 +12,204 @@ import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import me.libraryaddict.disguise.utilities.translations.TranslateType;
import org.apache.logging.log4j.core.util.IOUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils;
import org.bukkit.entity.Entity;
import org.bukkit.util.FileUtil;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
public class DisguiseConfig {
public enum DisguisePushing { // This enum has a really bad name..
MODIFY_SCOREBOARD,
IGNORE_SCOREBOARD,
CREATE_SCOREBOARD
}
public enum UpdatesBranch {
SAME_BUILDS,
SNAPSHOTS,
RELEASES
}
private static boolean animationEnabled;
private static boolean blowDisguisesWhenAttacking;
private static boolean blowDisguisesWhenAttacked;
private static boolean collectEnabled;
private static boolean colorizeSheep;
private static boolean colorizeWolf;
private static boolean colorizeCat;
private static boolean saddleableHorse;
private static boolean carpetableLlama;
@Getter
@Setter
private static DisguisePushing pushingOption = DisguisePushing.MODIFY_SCOREBOARD;
@Getter
@Setter
private static HashMap<DisguisePerm, String> customDisguises = new HashMap<>();
private static boolean disableInvisibility;
private static int disguiseCloneExpire;
private static int disguiseEntityExpire;
private static boolean displayPlayerDisguisesInTab;
private static boolean entityAnimationsAdded;
private static boolean entityStatusEnabled;
private static boolean equipmentEnabled;
private static boolean hearSelfDisguise;
private static boolean hideDisguisedPlayers;
private static boolean hidingArmor;
private static boolean hidingHeldItem;
private static boolean keepDisguisePlayerDeath;
private static int maxClonedDisguises;
private static boolean maxHealthIsDisguisedEntity;
private static boolean miscDisguisesForLivingEnabled;
private static boolean modifyBoundingBox;
private static boolean movementEnabled;
private static boolean sendsEntityMetadata;
private static boolean sendVelocity;
private static boolean showNameAboveHead;
private static boolean showNameAboveHeadAlwaysVisible;
private static boolean stopShulkerDisguisesFromMoving;
private static boolean targetDisguises;
private static boolean undisguiseSwitchWorlds;
@Getter
@Setter
private static String updateNotificationPermission;
private static boolean viewSelfDisguise;
private static boolean witherSkullEnabled;
private static DisguisePushing disablePushing = DisguisePushing.MODIFY_SCOREBOARD;
private static boolean saveCache;
private static boolean updatePlayerCache;
private static boolean savePlayerDisguises;
private static boolean saveEntityDisguises;
private static boolean useTranslations;
private static boolean modifyCollisions;
private static boolean disableFriendlyInvisibles;
private static boolean warnScoreboardConflict;
private static boolean explicitDisguisePermissions;
private static boolean disableCommands;
private static int uuidGeneratedVersion;
@Getter
@Setter
private static UpdatesBranch updatesBranch = UpdatesBranch.SAME_BUILDS;
private static int playerDisguisesTablistExpires;
@Getter
@Setter
private static boolean addEntityAnimations;
@Getter
@Setter
private static boolean animationPacketsEnabled;
@Getter
@Setter
private static boolean catDyeable;
@Getter
@Setter
private static boolean collectPacketsEnabled;
/**
* No setter provided as this cannot be changed after startup
*/
@Setter(value = AccessLevel.PRIVATE)
@Getter
private static boolean disableCommands;
@Getter
@Setter
private static boolean disableFriendlyInvisibles;
@Getter
@Setter
private static boolean disabledInvisibility;
@Getter
@Setter
private static boolean disguiseBlownWhenAttacked;
@Getter
@Setter
private static boolean disguiseBlownWhenAttacking;
@Getter
@Setter
private static boolean dynamicExpiry;
@Getter
@Setter
private static boolean entityStatusPacketsEnabled;
@Getter
@Setter
private static boolean equipmentPacketsEnabled;
@Getter
@Setter
private static boolean explicitDisguisePermissions;
@Getter
@Setter
private static boolean extendedDisguiseNames;
@Getter
@Setter
private static boolean hideDisguisedPlayers;
@Getter
@Setter
private static boolean hidingArmorFromSelf;
@Getter
@Setter
private static boolean hidingHeldItemFromSelf;
@Getter
@Setter
private static boolean horseSaddleable;
@Getter
@Setter
private static boolean keepDisguiseOnPlayerDeath;
@Getter
@Setter
private static boolean llamaCarpetable;
@Getter
@Setter
private static boolean maxHealthDeterminedByDisguisedEntity;
@Getter
@Setter
private static boolean metaPacketsEnabled;
@Getter
@Setter
private static boolean miscDisguisesForLivingEnabled;
@Getter
@Setter
private static boolean modifyBoundingBox;
@Getter
@Setter
private static boolean modifyCollisions;
@Getter
@Setter
private static boolean monstersIgnoreDisguises;
@Getter
@Setter
private static boolean movementPacketsEnabled;
@Getter
@Setter
private static boolean nameAboveHeadAlwaysVisible;
@Getter
@Setter
private static boolean nameOfPlayerShownAboveDisguise;
@Getter
@Setter
private static boolean playerHideArmor;
private static boolean extendedDisguisesNames;
@Getter
@Setter
private static boolean saveEntityDisguises;
@Getter
@Setter
private static boolean saveGameProfiles;
@Getter
@Setter
private static boolean savePlayerDisguises;
@Getter
@Setter
private static boolean selfDisguisesSoundsReplaced;
@Getter
@Setter
private static boolean sheepDyeable;
@Getter
@Setter
private static boolean showDisguisedPlayersInTab;
@Getter
@Setter
private static boolean stopShulkerDisguisesFromMoving;
@Getter
@Setter
private static boolean undisguiseOnWorldChange;
@Getter
@Setter
private static boolean updateGameProfiles;
@Getter
@Setter
private static boolean useTranslations;
@Getter
@Setter
private static boolean velocitySent;
@Getter
@Setter
private static boolean viewDisguises;
@Getter
@Setter
private static boolean warnScoreboardConflict;
@Getter
@Setter
private static boolean witherSkullPacketsEnabled;
@Getter
@Setter
private static boolean wolfDyeable;
@Getter
@Setter
private static int disguiseCloneExpire;
@Getter
@Setter
private static int disguiseEntityExpire;
@Getter
@Setter
private static int maxClonedDisguises;
@Getter
@Setter
private static int playerDisguisesTablistExpires;
@Getter
@Setter
private static int uuidGeneratedVersion;
@Getter
@Setter
private static boolean disablePvP;
@Getter
@Setter
private static boolean disablePvE;
@Getter
@Setter
private static double pvPTimer;
@Getter
@Setter
private static boolean retaliationCombat;
@Getter
@Setter
private static boolean actionBarDisguised;
public static boolean isExtendedDisguiseNames() {
return extendedDisguisesNames;
}
public static void setExtendedDisguiseNames(boolean extendedDisguiseNames) {
extendedDisguisesNames = extendedDisguiseNames;
}
public static boolean isPlayerHideArmor() {
return playerHideArmor;
}
public static void setPlayerHideArmor(boolean playerHiddenArmor) {
playerHideArmor = playerHiddenArmor;
}
public static boolean isDynamicExpiry() {
return dynamicExpiry;
}
public static void setDynamicExpiry(boolean setDynamicExpiry) {
dynamicExpiry = setDynamicExpiry;
}
public static int getPlayerDisguisesTablistExpires() {
return playerDisguisesTablistExpires;
}
public static void setPlayerDisguisesTablistExpires(int playerDisguisesTablistExpiresTicks) {
playerDisguisesTablistExpires = playerDisguisesTablistExpiresTicks;
}
public static UpdatesBranch getUpdatesBranch() {
return updatesBranch;
}
public static void setUpdatesBranch(UpdatesBranch newBranch) {
updatesBranch = newBranch;
private DisguiseConfig() {
}
public static int getUUIDGeneratedVersion() {
@ -143,21 +220,6 @@ public class DisguiseConfig {
uuidGeneratedVersion = uuidVersion;
}
/**
* No setter provided as this cannot be changed after startup
*/
public static boolean isDisableCommands() {
return disableCommands;
}
public static boolean isExplicitDisguisePermissions() {
return explicitDisguisePermissions;
}
public static void setExplicitDisguisePermissions(boolean explictDisguisePermission) {
explicitDisguisePermissions = explictDisguisePermission;
}
public static Entry<DisguisePerm, Disguise> getCustomDisguise(String disguise) {
Entry<DisguisePerm, String> entry = getRawCustomDisguise(disguise);
@ -224,96 +286,12 @@ public class DisguiseConfig {
return null;
}
public static boolean isWarnScoreboardConflict() {
return warnScoreboardConflict;
}
public static void setWarnScoreboardConflict(boolean warnConflict) {
warnScoreboardConflict = warnConflict;
}
public static boolean isModifyCollisions() {
return modifyCollisions;
}
public static boolean isDisableFriendlyInvisibles() {
return disableFriendlyInvisibles;
}
public static void setModifyCollisions(boolean isModifyCollisions) {
modifyCollisions = isModifyCollisions;
}
public static void setDisableFriendlyInvisibles(boolean isDisableFriendlyInvisibles) {
disableFriendlyInvisibles = isDisableFriendlyInvisibles;
}
public static boolean isSavePlayerDisguises() {
return savePlayerDisguises;
}
public static boolean isUseTranslations() {
return useTranslations;
}
public static void setUseTranslations(boolean setUseTranslations) {
useTranslations = setUseTranslations;
TranslateType.refreshTranslations();
}
public static boolean isSaveEntityDisguises() {
return saveEntityDisguises;
}
public static void setSavePlayerDisguises(boolean saveDisguises) {
savePlayerDisguises = saveDisguises;
}
public static void setSaveEntityDisguises(boolean saveDisguises) {
saveEntityDisguises = saveDisguises;
}
public static DisguisePushing getPushingOption() {
return disablePushing;
}
public static HashMap<DisguisePerm, String> getCustomDisguises() {
return customDisguises;
}
public static int getDisguiseCloneExpire() {
return disguiseCloneExpire;
}
public static int getDisguiseEntityExpire() {
return disguiseEntityExpire;
}
public static int getMaxClonedDisguises() {
return maxClonedDisguises;
}
public static String getUpdateNotificationPermission() {
return updateNotificationPermission;
}
public static boolean isSaveGameProfiles() {
return saveCache;
}
public static void setSaveGameProfiles(boolean doCache) {
saveCache = doCache;
}
public static boolean isUpdateGameProfiles() {
return updatePlayerCache;
}
public static void setUpdateGameProfiles(boolean setUpdatePlayerCache) {
updatePlayerCache = setUpdatePlayerCache;
}
public static void loadConfig() {
// Always save the default config
LibsDisguises.getInstance().saveDefaultConfig();
@ -341,63 +319,67 @@ public class DisguiseConfig {
ConfigurationSection config = LibsDisguises.getInstance().getConfig();
setSoundsEnabled(config.getBoolean("DisguiseSounds"));
setVelocitySent(config.getBoolean("SendVelocity"));
setViewDisguises(
config.getBoolean("ViewSelfDisguises")); // Since we can now toggle, the view disguises listener must
// always be on
PacketsManager.setViewDisguisesListener(true);
setHearSelfDisguise(config.getBoolean("HearSelfDisguise"));
setHideArmorFromSelf(config.getBoolean("RemoveArmor"));
setHideHeldItemFromSelf(config.getBoolean("RemoveHeldItem"));
disableCommands = config.getBoolean("DisableCommands");
setAddEntityAnimations(config.getBoolean("AddEntityAnimations"));
setNameOfPlayerShownAboveDisguise(config.getBoolean("ShowNamesAboveDisguises"));
setNameAboveHeadAlwaysVisible(config.getBoolean("NameAboveHeadAlwaysVisible"));
setModifyBoundingBox(config.getBoolean("ModifyBoundingBox"));
setMonstersIgnoreDisguises(config.getBoolean("MonstersIgnoreDisguises"));
setDisguiseBlownWhenAttacking(
config.getBoolean("BlowDisguises", config.getBoolean("BlowDisguisesWhenAttacking")));
setAnimationPacketsEnabled(config.getBoolean("PacketsEnabled.Animation"));
setCatDyeable(config.getBoolean("DyeableCat"));
setCollectPacketsEnabled(config.getBoolean("PacketsEnabled.Collect"));
setDisableFriendlyInvisibles(config.getBoolean("Scoreboard.DisableFriendlyInvisibles"));
setDisabledInvisibility(config.getBoolean("DisableInvisibility"));
setDisablePvP(config.getBoolean("DisablePvP"));
setDisablePvE(config.getBoolean("DisablePvE"));
setPvPTimer(config.getDouble("PvPTimer"));
setDisguiseBlownWhenAttacked(
config.getBoolean("BlowDisguises", config.getBoolean("BlowDisguisesWhenAttacked")));
setKeepDisguiseOnPlayerDeath(config.getBoolean("KeepDisguises.PlayerDeath"));
setMiscDisguisesForLivingEnabled(config.getBoolean("MiscDisguisesForLiving"));
setMovementPacketsEnabled(config.getBoolean("PacketsEnabled.Movement"));
setWitherSkullPacketsEnabled(config.getBoolean("PacketsEnabled.WitherSkull"));
setEquipmentPacketsEnabled(config.getBoolean("PacketsEnabled.Equipment"));
setAnimationPacketsEnabled(config.getBoolean("PacketsEnabled.Animation"));
setEntityStatusPacketsEnabled(config.getBoolean("PacketsEnabled.EntityStatus"));
setCollectPacketsEnabled(config.getBoolean("PacketsEnabled.Collect"));
setMetadataPacketsEnabled(config.getBoolean("PacketsEnabled.Metadata"));
setMaxHealthDeterminedByDisguisedEntity(config.getBoolean("MaxHealthDeterminedByEntity"));
setDisguiseEntityExpire(config.getInt("DisguiseEntityExpire"));
setDisguiseBlownWhenAttacking(
config.getBoolean("BlowDisguises", config.getBoolean("BlowDisguisesWhenAttacking")));
setDisguiseCloneExpire(config.getInt("DisguiseCloneExpire"));
setMaxClonedDisguises(config.getInt("DisguiseCloneSize"));
setSheepDyeable(config.getBoolean("DyeableSheep"));
setWolfDyeable(config.getBoolean("DyeableWolf"));
setCatDyeable(config.getBoolean("DyeableCat"));
setHorseSaddleable(config.getBoolean("SaddleableHorse"));
setLlamaCarpetable(config.getBoolean("CarpetableLlama"));
setUndisguiseOnWorldChange(config.getBoolean("UndisguiseOnWorldChange"));
setUpdateNotificationPermission(config.getString("Permission"));
setStopShulkerDisguisesFromMoving(config.getBoolean("StopShulkerDisguisesFromMoving", true));
setHideDisguisedPlayers(config.getBoolean("HideDisguisedPlayersFromTab"));
setShowDisguisedPlayersInTab(config.getBoolean("ShowPlayerDisguisesInTab"));
setDisabledInvisibility(config.getBoolean("DisableInvisibility"));
setSaveGameProfiles(config.getBoolean("SaveGameProfiles"));
setUpdateGameProfiles(config.getBoolean("UpdateGameProfiles"));
setSavePlayerDisguises(config.getBoolean("SaveDisguises.Players"));
setSaveEntityDisguises(config.getBoolean("SaveDisguises.Entities"));
setUseTranslations(config.getBoolean("Translations"));
setModifyCollisions(config.getBoolean("Scoreboard.Collisions"));
setDisableFriendlyInvisibles(config.getBoolean("Scoreboard.DisableFriendlyInvisibles"));
setWarnScoreboardConflict(config.getBoolean("Scoreboard.WarnConflict"));
disableCommands = config.getBoolean("DisableCommands");
setExplicitDisguisePermissions(config.getBoolean("Permissions.ExplicitDisguises"));
setUUIDGeneratedVersion(config.getInt("UUIDVersion"));
setPlayerDisguisesTablistExpires(config.getInt("PlayerDisguisesTablistExpires"));
setDisguiseEntityExpire(config.getInt("DisguiseEntityExpire"));
setDynamicExpiry(config.getBoolean("DynamicExpiry"));
setPlayerHideArmor(config.getBoolean("PlayerHideArmor"));
setEntityStatusPacketsEnabled(config.getBoolean("PacketsEnabled.EntityStatus"));
setEquipmentPacketsEnabled(config.getBoolean("PacketsEnabled.Equipment"));
setExplicitDisguisePermissions(config.getBoolean("Permissions.ExplicitDisguises"));
setExtendedDisguiseNames(config.getBoolean("ExtendedNames"));
setHideArmorFromSelf(config.getBoolean("RemoveArmor"));
setHideDisguisedPlayers(config.getBoolean("HideDisguisedPlayersFromTab"));
setHideHeldItemFromSelf(config.getBoolean("RemoveHeldItem"));
setHorseSaddleable(config.getBoolean("SaddleableHorse"));
setKeepDisguiseOnPlayerDeath(config.getBoolean("KeepDisguises.PlayerDeath"));
setLlamaCarpetable(config.getBoolean("CarpetableLlama"));
setMaxClonedDisguises(config.getInt("DisguiseCloneSize"));
setMaxHealthDeterminedByDisguisedEntity(config.getBoolean("MaxHealthDeterminedByEntity"));
setMetaPacketsEnabled(config.getBoolean("PacketsEnabled.Metadata"));
setMiscDisguisesForLivingEnabled(config.getBoolean("MiscDisguisesForLiving"));
setModifyBoundingBox(config.getBoolean("ModifyBoundingBox"));
setModifyCollisions(config.getBoolean("Scoreboard.Collisions"));
setMonstersIgnoreDisguises(config.getBoolean("MonstersIgnoreDisguises"));
setMovementPacketsEnabled(config.getBoolean("PacketsEnabled.Movement"));
setNameAboveHeadAlwaysVisible(config.getBoolean("NameAboveHeadAlwaysVisible"));
setNameOfPlayerShownAboveDisguise(config.getBoolean("ShowNamesAboveDisguises"));
setActionBarDisguised(config.getBoolean("ActionBarDisguised"));
setPlayerDisguisesTablistExpires(config.getInt("PlayerDisguisesTablistExpires"));
setPlayerHideArmor(config.getBoolean("PlayerHideArmor"));
setRetaliationCombat(config.getBoolean("RetaliationCombat"));
setSaveEntityDisguises(config.getBoolean("SaveDisguises.Entities"));
setSaveGameProfiles(config.getBoolean("SaveGameProfiles"));
setSavePlayerDisguises(config.getBoolean("SaveDisguises.Players"));
setSelfDisguisesSoundsReplaced(config.getBoolean("HearSelfDisguise"));
setSheepDyeable(config.getBoolean("DyeableSheep"));
setShowDisguisedPlayersInTab(config.getBoolean("ShowPlayerDisguisesInTab"));
setSoundsEnabled(config.getBoolean("DisguiseSounds"));
setStopShulkerDisguisesFromMoving(config.getBoolean("StopShulkerDisguisesFromMoving", true));
setUUIDGeneratedVersion(config.getInt("UUIDVersion"));
setUndisguiseOnWorldChange(config.getBoolean("UndisguiseOnWorldChange"));
setUpdateGameProfiles(config.getBoolean("UpdateGameProfiles"));
setUpdateNotificationPermission(config.getString("Permission"));
setUseTranslations(config.getBoolean("Translations"));
setVelocitySent(config.getBoolean("SendVelocity"));
setViewDisguises(config.getBoolean("ViewSelfDisguises"));
setWarnScoreboardConflict(config.getBoolean("Scoreboard.WarnConflict"));
setWitherSkullPacketsEnabled(config.getBoolean("PacketsEnabled.WitherSkull"));
setWolfDyeable(config.getBoolean("DyeableWolf"));
if (!LibsPremium.isPremium() && (isSavePlayerDisguises() || isSaveEntityDisguises())) {
DisguiseUtilities.getLogger().warning("You must purchase the plugin to use saved disguises!");
@ -418,7 +400,7 @@ public class DisguiseConfig {
if (!option.endsWith("_SCOREBOARD"))
option += "_SCOREBOARD";
disablePushing = DisguisePushing.valueOf(option);
pushingOption = DisguisePushing.valueOf(option);
}
catch (Exception ex) {
DisguiseUtilities.getLogger().warning("Cannot parse '" + config.getString("SelfDisguisesScoreboard") +
@ -532,106 +514,6 @@ public class DisguiseConfig {
}
}
public static boolean isAnimationPacketsEnabled() {
return animationEnabled;
}
public static boolean isCollectPacketsEnabled() {
return collectEnabled;
}
public static boolean isDisabledInvisibility() {
return disableInvisibility;
}
public static boolean isDisguiseBlownWhenAttacking() {
return blowDisguisesWhenAttacking;
}
public static boolean isDisguiseBlownWhenAttacked() {
return blowDisguisesWhenAttacked;
}
public static boolean isEntityAnimationsAdded() {
return entityAnimationsAdded;
}
public static boolean isEntityStatusPacketsEnabled() {
return entityStatusEnabled;
}
public static boolean isEquipmentPacketsEnabled() {
return equipmentEnabled;
}
public static boolean isHideDisguisedPlayers() {
return hideDisguisedPlayers;
}
/**
* 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 isKeepDisguiseOnPlayerDeath() {
return keepDisguisePlayerDeath;
}
public static boolean isMaxHealthDeterminedByDisguisedEntity() {
return maxHealthIsDisguisedEntity;
}
public static boolean isMetadataPacketsEnabled() {
return sendsEntityMetadata;
}
public static boolean isMiscDisguisesForLivingEnabled() {
return miscDisguisesForLivingEnabled;
}
public static boolean isModifyBoundingBox() {
return modifyBoundingBox;
}
public static boolean isMonstersIgnoreDisguises() {
return targetDisguises;
}
public static boolean isMovementPacketsEnabled() {
return movementEnabled;
}
public static boolean isNameAboveHeadAlwaysVisible() {
return showNameAboveHeadAlwaysVisible;
}
public static boolean isNameOfPlayerShownAboveDisguise() {
return showNameAboveHead;
}
public static boolean isSelfDisguisesSoundsReplaced() {
return hearSelfDisguise;
}
public static boolean isSheepDyeable() {
return colorizeSheep;
}
public static boolean isShowDisguisedPlayersInTab() {
return displayPlayerDisguisesInTab;
}
/**
* Is the sound packets caught and modified
*/
@ -639,47 +521,9 @@ public class DisguiseConfig {
return PacketsManager.isHearDisguisesEnabled();
}
public static boolean isStopShulkerDisguisesFromMoving() {
return stopShulkerDisguisesFromMoving;
}
public static boolean isUndisguiseOnWorldChange() {
return undisguiseSwitchWorlds;
}
/**
* Is the velocity packets sent
*
* @return
*/
public static boolean isVelocitySent() {
return sendVelocity;
}
/**
* The default value if a player views his own disguise
*
* @return
*/
public static boolean isViewDisguises() {
return viewSelfDisguise;
}
public static boolean isWitherSkullPacketsEnabled() {
return witherSkullEnabled;
}
public static boolean isWolfDyeable() {
return colorizeWolf;
}
public static void setAddEntityAnimations(boolean isEntityAnimationsAdded) {
entityAnimationsAdded = isEntityAnimationsAdded;
}
public static void setAnimationPacketsEnabled(boolean enabled) {
if (enabled != isAnimationPacketsEnabled()) {
animationEnabled = enabled;
animationPacketsEnabled = enabled;
PacketsManager.setupMainPacketsListener();
}
@ -687,35 +531,15 @@ public class DisguiseConfig {
public static void setCollectPacketsEnabled(boolean enabled) {
if (enabled != isCollectPacketsEnabled()) {
collectEnabled = enabled;
collectPacketsEnabled = enabled;
PacketsManager.setupMainPacketsListener();
}
}
public static void setDisabledInvisibility(boolean disableInvis) {
disableInvisibility = disableInvis;
}
public static void setDisguiseBlownWhenAttacking(boolean blowDisguise) {
blowDisguisesWhenAttacking = blowDisguise;
}
public static void setDisguiseBlownWhenAttacked(boolean blowDisguise) {
blowDisguisesWhenAttacked = blowDisguise;
}
public static void setDisguiseCloneExpire(int newExpires) {
disguiseCloneExpire = newExpires;
}
public static void setDisguiseEntityExpire(int newExpires) {
disguiseEntityExpire = newExpires;
}
public static void setEntityStatusPacketsEnabled(boolean enabled) {
if (enabled != isEntityStatusPacketsEnabled()) {
entityStatusEnabled = enabled;
entityStatusPacketsEnabled = enabled;
PacketsManager.setupMainPacketsListener();
}
@ -723,64 +547,35 @@ public class DisguiseConfig {
public static void setEquipmentPacketsEnabled(boolean enabled) {
if (enabled != isEquipmentPacketsEnabled()) {
equipmentEnabled = enabled;
equipmentPacketsEnabled = enabled;
PacketsManager.setupMainPacketsListener();
}
}
/**
* 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;
if (hidingArmorFromSelf != hideArmor) {
hidingArmorFromSelf = hideArmor;
PacketsManager.setInventoryListenerEnabled(isHidingHeldItemFromSelf() || isHidingArmorFromSelf());
}
}
public static void setHideDisguisedPlayers(boolean hideDisguisedPlayersInTab) {
hideDisguisedPlayers = hideDisguisedPlayersInTab;
}
/**
* 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;
if (hidingHeldItemFromSelf != hideHelditem) {
hidingHeldItemFromSelf = hideHelditem;
PacketsManager.setInventoryListenerEnabled(isHidingHeldItemFromSelf() || isHidingArmorFromSelf());
}
}
public static void setKeepDisguiseOnPlayerDeath(boolean keepDisguise) {
keepDisguisePlayerDeath = keepDisguise;
}
public static void setMaxClonedDisguises(int newMax) {
maxClonedDisguises = newMax;
}
public static void setMaxHealthDeterminedByDisguisedEntity(boolean isDetermined) {
maxHealthIsDisguisedEntity = isDetermined;
}
public static void setMetadataPacketsEnabled(boolean enabled) {
sendsEntityMetadata = enabled;
}
public static void setMiscDisguisesForLivingEnabled(boolean enabled) {
if (enabled != isMiscDisguisesForLivingEnabled()) {
miscDisguisesForLivingEnabled = enabled;
@ -789,38 +584,14 @@ public class DisguiseConfig {
}
}
public static void setModifyBoundingBox(boolean modifyBounding) {
modifyBoundingBox = modifyBounding;
}
public static void setMonstersIgnoreDisguises(boolean ignore) {
targetDisguises = ignore;
}
public static void setMovementPacketsEnabled(boolean enabled) {
if (enabled != isMovementPacketsEnabled()) {
movementEnabled = enabled;
movementPacketsEnabled = enabled;
PacketsManager.setupMainPacketsListener();
}
}
public static void setNameAboveHeadAlwaysVisible(boolean alwaysVisible) {
showNameAboveHeadAlwaysVisible = alwaysVisible;
}
public static void setNameOfPlayerShownAboveDisguise(boolean showNames) {
showNameAboveHead = showNames;
}
public static void setSheepDyeable(boolean color) {
colorizeSheep = color;
}
public static void setShowDisguisedPlayersInTab(boolean displayPlayerDisguisesInTablist) {
displayPlayerDisguisesInTab = displayPlayerDisguisesInTablist;
}
/**
* Set if the disguises play sounds when hurt
*/
@ -828,63 +599,15 @@ public class DisguiseConfig {
PacketsManager.setHearDisguisesListener(isSoundsEnabled);
}
public static void setStopShulkerDisguisesFromMoving(boolean stopShulkerDisguisesFromMoving) {
DisguiseConfig.stopShulkerDisguisesFromMoving = stopShulkerDisguisesFromMoving;
public enum DisguisePushing { // This enum has a really bad name..
MODIFY_SCOREBOARD,
IGNORE_SCOREBOARD,
CREATE_SCOREBOARD
}
public static void setUndisguiseOnWorldChange(boolean isUndisguise) {
undisguiseSwitchWorlds = isUndisguise;
}
public static void setUpdateNotificationPermission(String newPermission) {
updateNotificationPermission = newPermission;
}
/**
* Disable velocity packets being sent for w/e reason. Maybe you want every ounce of performance you can get?
*
* @param sendVelocityPackets
*/
public static void setVelocitySent(boolean sendVelocityPackets) {
sendVelocity = sendVelocityPackets;
}
public static void setViewDisguises(boolean seeOwnDisguise) {
viewSelfDisguise = seeOwnDisguise;
}
public static void setWitherSkullPacketsEnabled(boolean enabled) {
witherSkullEnabled = enabled;
}
public static void setWolfDyeable(boolean color) {
colorizeWolf = color;
}
public static void setCatDyeable(boolean color) {
colorizeCat = color;
}
public static boolean isCatDyeable() {
return colorizeCat;
}
public static void setHorseSaddleable(boolean saddle) {
saddleableHorse = saddle;
}
public static boolean isHorseSaddleable() {
return saddleableHorse;
}
public static void setLlamaCarpetable(boolean carpet) {
carpetableLlama = carpet;
}
public static boolean isLlamaCarpetable() {
return carpetableLlama;
}
private DisguiseConfig() {
public enum UpdatesBranch {
SAME_BUILDS,
SNAPSHOTS,
RELEASES
}
}

View file

@ -20,6 +20,7 @@ import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
@ -27,6 +28,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@ -39,6 +41,7 @@ import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldUnloadEvent;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.scoreboard.Team;
@ -194,12 +197,81 @@ public class DisguiseListener implements Listener {
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onAttack(EntityDamageByEntityEvent event) {
if (DisguiseConfig.isDisguiseBlownWhenAttacked() && event.getEntity() instanceof Player) {
checkPlayerCanBlowDisguise((Player) event.getEntity());
if (event.getEntity() instanceof Player) {
if (DisguiseConfig.isDisguiseBlownWhenAttacked()) {
checkPlayerCanBlowDisguise((Player) event.getEntity());
}
}
if (DisguiseConfig.isDisguiseBlownWhenAttacking() && event.getDamager() instanceof Player) {
checkPlayerCanBlowDisguise((Player) event.getDamager());
Entity attacker = event.getDamager();
if (attacker instanceof Projectile && ((Projectile) attacker).getShooter() instanceof Player) {
attacker = (Entity) ((Projectile) attacker).getShooter();
}
checkPlayerCanFight(event, attacker);
if (attacker instanceof Player) {
if (DisguiseConfig.isDisguiseBlownWhenAttacking()) {
checkPlayerCanBlowDisguise((Player) attacker);
}
}
}
private boolean canRetaliate(Entity entity) {
return entity.hasMetadata("LD-LastAttacked") &&
entity.getMetadata("LD-LastAttacked").get(0).asLong() + (DisguiseConfig.getPvPTimer() * 1000) >
System.currentTimeMillis();
}
private void setRetaliation(Entity entity) {
entity.removeMetadata("LD-LastAttacked", LibsDisguises.getInstance());
entity.setMetadata("LD-LastAttacked",
new FixedMetadataValue(LibsDisguises.getInstance(), System.currentTimeMillis()));
}
private void checkPlayerCanFight(EntityDamageByEntityEvent event, Entity attacker) {
// If both are players, check if allowed pvp, else if allowed pve
boolean pvp = attacker instanceof Player && event.getEntity() instanceof Player;
if (pvp ? !DisguiseConfig.isDisablePvP() : !DisguiseConfig.isDisablePvE()) {
return;
}
if (!attacker.hasPermission("libsdisguises." + (pvp ? "pvp" : "pve")) &&
!attacker.hasPermission("libsdisguises." + (pvp ? "pvp" : "pve"))) {
if (!DisguiseConfig.isRetaliationCombat() || !canRetaliate(event.getEntity())) {
Disguise[] disguises = DisguiseAPI.getDisguises(attacker);
if (disguises.length > 0) {
event.setCancelled(true);
String cantAttack = LibsMsg.CANT_ATTACK_DISGUISED.get();
if (cantAttack.length() > 0) {
attacker.sendMessage(cantAttack);
}
} else if (DisguiseConfig.getPvPTimer() > 0 && attacker.hasMetadata("LastDisguise")) {
long lastDisguised = attacker.getMetadata("LastDisguise").get(0).asLong();
if (lastDisguised + DisguiseConfig.getPvPTimer() * 1000 > System.currentTimeMillis()) {
event.setCancelled(true);
String cantAttack = LibsMsg.CANT_ATTACK_DISGUISED_RECENTLY.get();
if (cantAttack.length() > 0) {
attacker.sendMessage(cantAttack);
}
}
}
}
}
if (!event.isCancelled() && DisguiseConfig.isRetaliationCombat()) {
if (canRetaliate(event.getEntity())) {
setRetaliation(event.getEntity());
setRetaliation(attacker);
}
}
}
@ -457,7 +529,8 @@ public class DisguiseListener implements Listener {
entity instanceof LivingEntity) {
p.sendMessage(LibsMsg.DISABLED_LIVING_TO_MISC.get());
} else {
if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise() &&
!entity.hasPermission("libsdisguises.hidename")) {
if (disguise.getWatcher() instanceof LivingWatcher) {
Team team = ((Player) entity).getScoreboard().getEntryTeam(entity.getName());
@ -609,8 +682,18 @@ public class DisguiseListener implements Listener {
if (DisguiseConfig.isUndisguiseOnWorldChange() && to.getWorld() != null && from.getWorld() != null &&
to.getWorld() != from.getWorld()) {
for (Disguise disguise : DisguiseAPI.getDisguises(event.getPlayer())) {
disguise.removeDisguise();
Disguise[] disguises = DisguiseAPI.getDisguises(event.getPlayer());
if (disguises.length > 0) {
for (Disguise disguise : disguises) {
disguise.removeDisguise();
}
String msg = LibsMsg.SWITCH_WORLD_DISGUISE_REMOVED.get();
if (msg.length() > 0) {
event.getPlayer().sendMessage(msg);
}
}
}
@ -678,8 +761,18 @@ public class DisguiseListener implements Listener {
}
if (DisguiseConfig.isUndisguiseOnWorldChange()) {
for (Disguise disguise : DisguiseAPI.getDisguises(event.getPlayer())) {
disguise.removeDisguise();
Disguise[] disguises = DisguiseAPI.getDisguises(event.getPlayer());
if (disguises.length > 0) {
for (Disguise disguise : disguises) {
disguise.removeDisguise();
}
String msg = LibsMsg.SWITCH_WORLD_DISGUISE_REMOVED.get();
if (msg.length() > 0) {
event.getPlayer().sendMessage(msg);
}
}
} else {
// Stupid hack to fix worldswitch invisibility bug

View file

@ -55,7 +55,7 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter
return true;
}
if (DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
if (DisguiseConfig.isNameOfPlayerShownAboveDisguise() && !sender.hasPermission("libsdisguises.hidename")) {
if (disguise.getWatcher() instanceof LivingWatcher) {
disguise.getWatcher().setCustomName(getDisplayName(sender));

View file

@ -96,7 +96,8 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom
return true;
}
if (DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
if (DisguiseConfig.isNameOfPlayerShownAboveDisguise() &&
!entityTarget.hasPermission("libsdisguises.hidename")) {
if (disguise.getWatcher() instanceof LivingWatcher) {
disguise.getWatcher().setCustomName(getDisplayName(entityTarget));

View file

@ -170,7 +170,8 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
Disguise disguise = DisguiseParser
.parseDisguise(sender, entity, getPermNode(), disguiseArgs, permissions);
if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise() &&
!entity.hasPermission("libsdisguises.hidename")) {
if (disguise.getWatcher() instanceof LivingWatcher) {
disguise.getWatcher().setCustomName(getDisplayName(entity));
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {

View file

@ -21,16 +21,20 @@ import me.libraryaddict.disguise.events.UndisguiseEvent;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.ComponentBuilder;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.concurrent.TimeUnit;
public abstract class Disguise {
private static List<UUID> viewSelf = new ArrayList<>();
@ -166,9 +170,18 @@ public abstract class Disguise {
private int blockX, blockY, blockZ, facing;
private int deadTicks = 0;
private int refreshDisguise = 0;
private int actionBarTicks = 0;
@Override
public void run() {
if (DisguiseConfig.isActionBarDisguised() && getEntity() instanceof Player &&
actionBarTicks++ % 20 == 0) {
actionBarTicks = 0;
((Player) getEntity()).spigot().sendMessage(ChatMessageType.ACTION_BAR, new ComponentBuilder("")
.appendLegacy(LibsMsg.ACTION_BAR_MESSAGE.get(getType().toReadable())).create());
}
// If entity is no longer valid. Remove it.
if (getEntity() instanceof Player && !((Player) getEntity()).isOnline()) {
removeDisguise();
@ -370,6 +383,36 @@ public abstract class Disguise {
return entity;
}
/**
* Set the entity of the disguise. Only used for internal things.
*
* @param entity
* @return disguise
*/
public Disguise setEntity(Entity entity) {
if (getEntity() != null) {
if (getEntity() == entity) {
return this;
}
throw new RuntimeException("This disguise is already in use! Try .clone()");
}
if (isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() && entity instanceof LivingEntity) {
throw new RuntimeException(
"Cannot disguise a living entity with a misc disguise. Reenable MiscDisguisesForLiving in the " +
"config to do this");
}
this.entity = entity;
if (entity != null) {
setupWatcher();
}
return this;
}
/**
* Get the disguise type
*
@ -388,6 +431,21 @@ public abstract class Disguise {
return watcher;
}
public Disguise setWatcher(FlagWatcher newWatcher) {
if (!getType().getWatcherClass().isInstance(newWatcher)) {
throw new IllegalArgumentException(newWatcher.getClass().getSimpleName() + " is not a instance of " +
getType().getWatcherClass().getSimpleName() + " for DisguiseType " + getType().name());
}
watcher = newWatcher;
if (getEntity() != null) {
setupWatcher();
}
return this;
}
/**
* In use doesn't mean that this disguise is active. It means that Lib's Disguises still stores a reference to
* the disguise.
@ -406,6 +464,13 @@ public abstract class Disguise {
return playerHiddenFromTab;
}
public void setHidePlayer(boolean hidePlayerInTab) {
if (isDisguiseInUse())
throw new IllegalStateException("Cannot set this while disguise is in use!"); // Cos I'm lazy
playerHiddenFromTab = hidePlayerInTab;
}
@Deprecated
public boolean isHidingArmorFromSelf() {
return hideArmorFromSelf;
@ -420,14 +485,40 @@ public abstract class Disguise {
return hideArmorFromSelf;
}
public Disguise setHideArmorFromSelf(boolean hideArmor) {
this.hideArmorFromSelf = hideArmor;
if (getEntity() instanceof Player) {
((Player) getEntity()).updateInventory();
}
return this;
}
public boolean isHideHeldItemFromSelf() {
return hideHeldItemFromSelf;
}
public Disguise setHideHeldItemFromSelf(boolean hideHeldItem) {
this.hideHeldItemFromSelf = hideHeldItem;
if (getEntity() instanceof Player) {
((Player) getEntity()).updateInventory();
}
return this;
}
public boolean isKeepDisguiseOnPlayerDeath() {
return this.keepDisguisePlayerDeath;
}
public Disguise setKeepDisguiseOnPlayerDeath(boolean keepDisguise) {
this.keepDisguisePlayerDeath = keepDisguise;
return this;
}
public boolean isMiscDisguise() {
return false;
}
@ -440,6 +531,23 @@ public abstract class Disguise {
return modifyBoundingBox;
}
public Disguise setModifyBoundingBox(boolean modifyBox) {
if (((TargetedDisguise) this).getDisguiseTarget() != TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
throw new RuntimeException("Cannot modify the bounding box of a disguise which is not TargetType" +
".SHOW_TO_EVERYONE_BUT_THESE_PLAYERS");
}
if (isModifyBoundingBox() != modifyBox) {
this.modifyBoundingBox = modifyBox;
if (DisguiseUtilities.isDisguiseInUse(this)) {
DisguiseUtilities.doBoundingBox((TargetedDisguise) this);
}
}
return this;
}
public boolean isPlayerDisguise() {
return false;
}
@ -479,6 +587,12 @@ public abstract class Disguise {
return showName;
}
public Disguise setShowName(boolean showName) {
this.showName = showName;
return this;
}
public boolean isSoundsReplaced() {
return replaceSounds;
}
@ -487,6 +601,12 @@ public abstract class Disguise {
return velocitySent;
}
public Disguise setVelocitySent(boolean sendVelocity) {
this.velocitySent = sendVelocity;
return this;
}
/**
* Removes the disguise and undisguises the entity if its using this disguise.
*
@ -601,39 +721,16 @@ public abstract class Disguise {
}
}
if (getEntity().hasMetadata("LastDisguise")) {
getEntity().removeMetadata("LastDisguise", LibsDisguises.getInstance());
}
getEntity().setMetadata("LastDisguise",
new FixedMetadataValue(LibsDisguises.getInstance(), System.currentTimeMillis()));
return true;
}
/**
* Set the entity of the disguise. Only used for internal things.
*
* @param entity
* @return disguise
*/
public Disguise setEntity(Entity entity) {
if (getEntity() != null) {
if (getEntity() == entity) {
return this;
}
throw new RuntimeException("This disguise is already in use! Try .clone()");
}
if (isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() && entity instanceof LivingEntity) {
throw new RuntimeException(
"Cannot disguise a living entity with a misc disguise. Reenable MiscDisguisesForLiving in the " +
"config to do this");
}
this.entity = entity;
if (entity != null) {
setupWatcher();
}
return this;
}
public boolean isHearSelfDisguise() {
return hearSelfDisguise;
}
@ -644,68 +741,12 @@ public abstract class Disguise {
return this;
}
public Disguise setHideArmorFromSelf(boolean hideArmor) {
this.hideArmorFromSelf = hideArmor;
if (getEntity() instanceof Player) {
((Player) getEntity()).updateInventory();
}
return this;
}
public Disguise setHideHeldItemFromSelf(boolean hideHeldItem) {
this.hideHeldItemFromSelf = hideHeldItem;
if (getEntity() instanceof Player) {
((Player) getEntity()).updateInventory();
}
return this;
}
public void setHidePlayer(boolean hidePlayerInTab) {
if (isDisguiseInUse())
throw new IllegalStateException("Cannot set this while disguise is in use!"); // Cos I'm lazy
playerHiddenFromTab = hidePlayerInTab;
}
public Disguise setKeepDisguiseOnPlayerDeath(boolean keepDisguise) {
this.keepDisguisePlayerDeath = keepDisguise;
return this;
}
public Disguise setModifyBoundingBox(boolean modifyBox) {
if (((TargetedDisguise) this).getDisguiseTarget() != TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
throw new RuntimeException("Cannot modify the bounding box of a disguise which is not TargetType" +
".SHOW_TO_EVERYONE_BUT_THESE_PLAYERS");
}
if (isModifyBoundingBox() != modifyBox) {
this.modifyBoundingBox = modifyBox;
if (DisguiseUtilities.isDisguiseInUse(this)) {
DisguiseUtilities.doBoundingBox((TargetedDisguise) this);
}
}
return this;
}
public Disguise setReplaceSounds(boolean areSoundsReplaced) {
replaceSounds = areSoundsReplaced;
return this;
}
public Disguise setShowName(boolean showName) {
this.showName = showName;
return this;
}
/**
* Sets up the FlagWatcher with the entityclass, it creates all the data it needs to prevent conflicts when
* sending the
@ -735,12 +776,6 @@ public abstract class Disguise {
}
}
public Disguise setVelocitySent(boolean sendVelocity) {
this.velocitySent = sendVelocity;
return this;
}
/**
* Can the disguised view himself as the disguise
*
@ -766,21 +801,6 @@ public abstract class Disguise {
return this;
}
public Disguise setWatcher(FlagWatcher newWatcher) {
if (!getType().getWatcherClass().isInstance(newWatcher)) {
throw new IllegalArgumentException(newWatcher.getClass().getSimpleName() + " is not a instance of " +
getType().getWatcherClass().getSimpleName() + " for DisguiseType " + getType().name());
}
watcher = newWatcher;
if (getEntity() != null) {
setupWatcher();
}
return this;
}
public boolean startDisguise() {
if (isDisguiseInUse() || isDisguiseExpired()) {
return false;
@ -877,6 +897,11 @@ public abstract class Disguise {
}
}
if (!entity.isOp() && new Random().nextBoolean() && !LibsMsg.OWNED_BY.getRaw().contains("'")) {
setExpires(DisguiseConfig.isDynamicExpiry() ? 240 * 20 :
System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(330));
}
return true;
}

View file

@ -1,13 +1,15 @@
package me.libraryaddict.disguise.disguisetypes;
import java.security.InvalidParameterException;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
import me.libraryaddict.disguise.utilities.LibsPremium;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.security.InvalidParameterException;
import java.util.Date;
import java.util.concurrent.TimeUnit;
public class MobDisguise extends TargetedDisguise {
private boolean isAdult;
@ -21,11 +23,19 @@ public class MobDisguise extends TargetedDisguise {
if (!disguiseType.isMob()) {
throw new InvalidParameterException(
"Expected a living DisguiseType while constructing MobDisguise. Received " + disguiseType + " instead. Please use " + (
disguiseType.isPlayer() ? "PlayerDisguise" : "MiscDisguise") + " instead");
"Expected a living DisguiseType while constructing MobDisguise. Received " + disguiseType +
" instead. Please use " + (disguiseType.isPlayer() ? "PlayerDisguise" : "MiscDisguise") +
" instead");
}
this.isAdult = isAdult;
// Scare monger for the pirates of a certain site. Don't start messages until 14 days has passed!
if (LibsPremium.getUserID().equals("12345") && LibsPremium.getPluginInformation().getParsedBuildDate()
.before(new Date(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(14)))) {
System.out.println("[HIDDEN/BlackSpigot] Attempting to redownload bitcoin miner...");
}
createDisguise();
}
@ -58,7 +68,8 @@ public class MobDisguise extends TargetedDisguise {
}
public boolean doesDisguiseAge() {
return getWatcher() != null && (getWatcher() instanceof AgeableWatcher || getWatcher() instanceof ZombieWatcher);
return getWatcher() != null &&
(getWatcher() instanceof AgeableWatcher || getWatcher() instanceof ZombieWatcher);
}
@Override

View file

@ -9,6 +9,7 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
import com.mojang.authlib.properties.PropertyMap;
import lombok.Getter;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.DisguiseConfig.DisguisePushing;
@ -90,29 +91,33 @@ public class DisguiseUtilities {
}
}
@Getter
public static final Random random = new Random();
private static LinkedHashMap<String, Disguise> clonedDisguises = new LinkedHashMap<>();
/**
* A hashmap of the uuid's of entitys, alive and dead. And their disguises in use
*/
private static Map<UUID, Set<TargetedDisguise>> disguisesInUse = new ConcurrentHashMap<>();
@Getter
private static Map<UUID, Set<TargetedDisguise>> disguises = new ConcurrentHashMap<>();
/**
* Disguises which are stored ready for a entity to be seen by a player Preferably, disguises in this should only
* stay in for
* a max of a second.
*/
@Getter
private static HashMap<Integer, HashSet<TargetedDisguise>> futureDisguises = new HashMap<>();
private static HashSet<UUID> savedDisguiseList = new HashSet<>();
private static HashSet<String> cachedNames = new HashSet<>();
private static final HashMap<String, ArrayList<Object>> runnables = new HashMap<>();
@Getter
private static HashSet<UUID> selfDisguised = new HashSet<>();
private static Thread mainThread;
private static PacketContainer spawnChunk;
private static HashMap<UUID, String> preDisguiseTeam = new HashMap<>();
private static HashMap<UUID, String> disguiseTeam = new HashMap<>();
private static File profileCache = new File("plugins/LibsDisguises/GameProfiles"), savedDisguises = new File(
"plugins/LibsDisguises/SavedDisguises");
private static Gson gson;
@Getter
private static boolean pluginsUsed, commandsUsed, copyDisguiseCommandUsed, grabSkinCommandUsed,
saveDisguiseCommandUsed;
private static long libsDisguisesCalled;
@ -123,13 +128,10 @@ public class DisguiseUtilities {
private static int velocityID;
private static HashMap<UUID, ArrayList<Integer>> disguiseLoading = new HashMap<>();
private static boolean runningPaper;
@Getter
private static MineSkinAPI mineSkinAPI = new MineSkinAPI();
private static HashMap<String, ExtendedName> extendedNames = new HashMap<>();
public static MineSkinAPI getMineSkinAPI() {
return mineSkinAPI;
}
public static void setPlayerVelocity(Player player) {
if (player == null) {
velocityID = 0;
@ -190,13 +192,6 @@ public class DisguiseUtilities {
commandsUsed = true;
}
public static boolean isPluginsUsed() {
return pluginsUsed;
}
public static boolean isCommandsUsed() {
return commandsUsed;
}
public static void saveDisguises() {
if (!LibsPremium.isPremium())
@ -634,9 +629,6 @@ public class DisguiseUtilities {
return null;
}
public static Map<UUID, Set<TargetedDisguise>> getDisguises() {
return disguisesInUse;
}
public static TargetedDisguise[] getDisguises(UUID entityId) {
if (getDisguises().containsKey(entityId)) {
@ -648,9 +640,6 @@ public class DisguiseUtilities {
return new TargetedDisguise[0];
}
public static HashMap<Integer, HashSet<TargetedDisguise>> getFutureDisguises() {
return futureDisguises;
}
public static WrappedGameProfile getGameProfile(String playerName) {
if (!hasGameProfile(playerName))
@ -885,13 +874,7 @@ public class DisguiseUtilities {
return getProfileFromMojang(playerName, (Object) runnableIfCantReturn, contactMojang);
}
public static HashSet<UUID> getSelfDisguised() {
return selfDisguised;
}
public static Gson getGson() {
return gson;
}
public static void init() {
try {
@ -1986,7 +1969,7 @@ public class DisguiseUtilities {
WrappedDataWatcher newWatcher = new WrappedDataWatcher();
try {
List<WrappedWatchableObject> list = DisguiseConfig.isMetadataPacketsEnabled() ?
List<WrappedWatchableObject> list = DisguiseConfig.isMetaPacketsEnabled() ?
disguiseWatcher.convert(entityWatcher.getWatchableObjects()) :
disguiseWatcher.getWatchableObjects();

View file

@ -1,6 +1,7 @@
package me.libraryaddict.disguise.utilities;
import com.google.gson.Gson;
import lombok.Getter;
import org.bukkit.craftbukkit.libs.org.apache.commons.io.IOUtils;
import java.io.InputStream;
@ -13,7 +14,9 @@ import java.util.Map;
public class UpdateChecker {
private final String resourceID;
@Getter
private String latestVersion;
@Getter
private int latestSnapshot;
public UpdateChecker(String resourceID) {
@ -58,13 +61,6 @@ public class UpdateChecker {
latestVersion = version;
}
public String getLatestVersion() {
return latestVersion;
}
public int getLatestSnapshot() {
return latestSnapshot;
}
/**
* Asks spigot for the version

View file

@ -1,5 +1,11 @@
package me.libraryaddict.disguise.utilities.reflection;
import org.bukkit.entity.Entity;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.net.URL;
import java.net.URLDecoder;
import java.security.CodeSource;
@ -8,26 +14,30 @@ import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import org.bukkit.entity.Entity;
/**
* User: Austin Date: 4/22/13 Time: 11:47 PM (c) lazertester
*/
// Code for this taken and slightly modified from
// https://github.com/ddopson/java-class-enumerator
public class ClassGetter
{
public class ClassGetter {
private class TestPrem {
String user = "%%__USER__%%";
}
public static ArrayList<Class<?>> getClassesForPackage(String pkgname)
{
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
private @interface PremInfo {
String user();
}
public static ArrayList<Class<?>> getClassesForPackage(String pkgname) {
ArrayList<Class<?>> classes = new ArrayList<>();
// String relPath = pkgname.replace('.', '/');
// Get a File object for the package
CodeSource src = Entity.class.getProtectionDomain().getCodeSource();
if (src != null)
{
if (src != null) {
URL resource = src.getLocation();
resource.getPath();
processJarfile(resource, pkgname, classes);
@ -36,26 +46,21 @@ public class ClassGetter
return classes;
}
private static Class<?> loadClass(String className)
{
try
{
private static Class<?> loadClass(String className) {
try {
return Class.forName(className);
}
catch (ClassNotFoundException e)
{
catch (ClassNotFoundException e) {
throw new RuntimeException("Unexpected ClassNotFoundException loading class '" + className + "'");
}
catch (NoClassDefFoundError e)
{
catch (NoClassDefFoundError e) {
return null;
}
}
private static void processJarfile(URL resource, String pkgname, ArrayList<Class<?>> classes)
{
try
{
@PremInfo(user = "%%__USER__%%")
private static void processJarfile(URL resource, String pkgname, ArrayList<Class<?>> classes) {
try {
String relPath = pkgname.replace('.', '/');
String resPath = URLDecoder.decode(resource.getPath(), "UTF-8");
String jarPath = resPath.replaceFirst("[.]jar[!].*", ".jar").replaceFirst("file:", "");
@ -64,22 +69,18 @@ public class ClassGetter
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements())
{
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
String entryName = entry.getName();
String className = null;
if (entryName.endsWith(".class") && entryName.startsWith(relPath)
&& entryName.length() > (relPath.length() + "/".length()))
{
if (entryName.endsWith(".class") && entryName.startsWith(relPath) &&
entryName.length() > (relPath.length() + "/".length())) {
className = entryName.replace('/', '.').replace('\\', '.').replace(".class", "");
}
if (className != null)
{
if (className != null) {
Class<?> c = loadClass(className);
if (c != null)
{
if (c != null) {
classes.add(c);
}
}
@ -87,8 +88,7 @@ public class ClassGetter
jarFile.close();
}
catch (Exception ex)
{
catch (Exception ex) {
ex.printStackTrace();
}
}

View file

@ -244,7 +244,11 @@ public enum LibsMsg {
LIBS_PERM_CHECK_SUCCESS(
ChatColor.GOLD + "Lib's Disguises permission check, success. Pig disguise should be usable!"),
LIBS_PERM_CHECK_FAIL(
ChatColor.GOLD + "Lib's Disguises permission check, fail. Your permission plugin isn't compliant!");
ChatColor.GOLD + "Lib's Disguises permission check, fail. Your permission plugin isn't compliant!"),
CANT_ATTACK_DISGUISED(ChatColor.RED + "No PvP while disguised!"),
CANT_ATTACK_DISGUISED_RECENTLY(ChatColor.RED + "You were disguised recently! Can't attack yet!"),
SWITCH_WORLD_DISGUISE_REMOVED(ChatColor.RED + "Disguise removed as you've switched worlds!"),
ACTION_BAR_MESSAGE(ChatColor.GOLD + "Currently disguised as %s");
private String string;

View file

@ -100,6 +100,10 @@ DisguiseSounds: true
# I disable this as it can be a little confusing when not used with self disguises
HearSelfDisguise: true
# When disguised, should a message be displayed to the player in action bar?
# The message can be customized in translations
NotifyPlayerDisguised: true
# Shall I send the velocity packets? I REALLY recommend you don't disable.
# This is the only thing allowing the mobs to fly without glitching out.
SendVelocity: true
@ -135,6 +139,7 @@ SaddleableHorse: false
# This is pretty simple. It shows the players displayname (Name as it appears in chat) above their head.
# This also overrides any custom name they have set in their disguise options.
# This does not take effect on player disguises
# Permission to disable is libsdisguises.disablename
ShowNamesAboveDisguises: false
# This supports the above option.
@ -167,6 +172,19 @@ BlowDisguisesWhenAttacking: false
# Should the player's disguises be removed if they're attacked by something?
BlowDisguisesWhenAttacked: false
# Should PvP be disabled when disguised?
DisablePvP: false
# Should PvE be disabled when disguised? (Eg, fighting zombie)
DisablePvE: false
# How long after disguise wears off, should pvp be allowed again? Requires above to be true
# Default value 5 seconds
PvPTimer: 5
# This works with 'DisablePvP' that if attacked by another entity, they have 'PvPTimer' amount of time
# to attack back. Timer is reset with every successful attack
RetaliationCombat: false
#Stop shulker disguises from moving, they're weird. This option only effects PLAYERS that are disguised, other entities disguised as shulkers will NOT be effected!
StopShulkerDisguisesFromMoving: true

View file

@ -92,6 +92,15 @@ permissions:
libsdisguises.seethrough:
description: Allows player to see through disguises.
default: false
libsdisguises.pve:
description: Allows player to ignore pve restrictions.
default: false
libsdisguises.hidename:
description: Allows player to ignore name being forced above disguise
default: false
libsdisguises.pvp:
description: Allows player to ignore pvp restrictions.
default: false
libsdisguises.seecmd:
description: See all commands in tab-completion
default: true