2016-05-12 13:30:22 +02:00
|
|
|
package me.libraryaddict.disguise;
|
|
|
|
|
2020-02-01 23:59:18 +01:00
|
|
|
import lombok.AccessLevel;
|
|
|
|
import lombok.Getter;
|
|
|
|
import lombok.Setter;
|
2018-05-18 05:27:05 +02:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
2018-09-07 04:35:38 +02:00
|
|
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
|
|
|
import me.libraryaddict.disguise.utilities.LibsPremium;
|
2019-01-03 03:13:03 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.packets.PacketsManager;
|
2018-09-07 04:35:38 +02:00
|
|
|
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
|
|
|
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
|
2019-03-05 05:46:47 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
|
2020-01-02 05:10:36 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
2019-02-03 02:02:59 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.translations.TranslateType;
|
2016-11-30 18:38:43 +01:00
|
|
|
import org.bukkit.Bukkit;
|
2019-04-16 22:10:15 +02:00
|
|
|
import org.bukkit.command.CommandSender;
|
2016-05-12 13:30:22 +02:00
|
|
|
import org.bukkit.configuration.ConfigurationSection;
|
2016-11-30 18:38:43 +01:00
|
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
2020-01-02 05:10:36 +01:00
|
|
|
import org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils;
|
2019-04-16 22:10:15 +02:00
|
|
|
import org.bukkit.entity.Entity;
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2018-05-18 05:27:05 +02:00
|
|
|
import java.io.File;
|
2020-01-02 05:10:36 +01:00
|
|
|
import java.io.IOException;
|
2019-04-16 22:10:15 +02:00
|
|
|
import java.lang.reflect.InvocationTargetException;
|
2018-05-18 05:27:05 +02:00
|
|
|
import java.util.HashMap;
|
2019-12-28 01:10:52 +01:00
|
|
|
import java.util.Iterator;
|
2018-05-18 05:27:05 +02:00
|
|
|
import java.util.Map.Entry;
|
2019-12-28 01:10:52 +01:00
|
|
|
import java.util.Random;
|
2016-05-12 13:30:22 +02:00
|
|
|
|
2016-11-30 05:08:12 +01:00
|
|
|
public class DisguiseConfig {
|
2020-02-01 23:59:18 +01:00
|
|
|
@Getter
|
|
|
|
@Setter
|
|
|
|
private static DisguisePushing pushingOption = DisguisePushing.MODIFY_SCOREBOARD;
|
|
|
|
@Getter
|
|
|
|
@Setter
|
2019-03-05 05:46:47 +01:00
|
|
|
private static HashMap<DisguisePerm, String> customDisguises = new HashMap<>();
|
2020-02-01 23:59:18 +01:00
|
|
|
@Getter
|
|
|
|
@Setter
|
|
|
|
private static String updateNotificationPermission;
|
|
|
|
@Getter
|
|
|
|
@Setter
|
|
|
|
private static UpdatesBranch updatesBranch = UpdatesBranch.SAME_BUILDS;
|
|
|
|
@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
|
2016-11-30 05:08:37 +01:00
|
|
|
private static boolean hideDisguisedPlayers;
|
2020-02-01 23:59:18 +01:00
|
|
|
@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
|
2016-05-12 13:30:22 +02:00
|
|
|
private static boolean miscDisguisesForLivingEnabled;
|
2020-02-01 23:59:18 +01:00
|
|
|
@Getter
|
|
|
|
@Setter
|
2016-05-12 13:30:22 +02:00
|
|
|
private static boolean modifyBoundingBox;
|
2020-02-01 23:59:18 +01:00
|
|
|
@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;
|
|
|
|
@Getter
|
|
|
|
@Setter
|
2017-05-28 00:23:15 +02:00
|
|
|
private static boolean saveEntityDisguises;
|
2020-02-01 23:59:18 +01:00
|
|
|
@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
|
2017-06-19 11:23:02 +02:00
|
|
|
private static boolean useTranslations;
|
2020-02-01 23:59:18 +01:00
|
|
|
@Getter
|
|
|
|
@Setter
|
|
|
|
private static boolean velocitySent;
|
|
|
|
@Getter
|
|
|
|
@Setter
|
|
|
|
private static boolean viewDisguises;
|
|
|
|
@Getter
|
|
|
|
@Setter
|
2018-08-24 00:01:01 +02:00
|
|
|
private static boolean warnScoreboardConflict;
|
2020-02-01 23:59:18 +01:00
|
|
|
@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
|
2019-02-03 02:02:59 +01:00
|
|
|
private static int playerDisguisesTablistExpires;
|
2020-02-01 23:59:18 +01:00
|
|
|
@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;
|
2018-12-16 02:47:42 +01:00
|
|
|
|
2020-02-01 23:59:18 +01:00
|
|
|
private DisguiseConfig() {
|
2018-12-16 02:47:42 +01:00
|
|
|
}
|
2018-11-08 09:09:47 +01:00
|
|
|
|
|
|
|
public static int getUUIDGeneratedVersion() {
|
|
|
|
return uuidGeneratedVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setUUIDGeneratedVersion(int uuidVersion) {
|
|
|
|
uuidGeneratedVersion = uuidVersion;
|
|
|
|
}
|
2018-11-08 09:04:18 +01:00
|
|
|
|
2019-05-16 08:07:53 +02:00
|
|
|
public static Entry<DisguisePerm, Disguise> getCustomDisguise(String disguise) {
|
|
|
|
Entry<DisguisePerm, String> entry = getRawCustomDisguise(disguise);
|
|
|
|
|
|
|
|
if (entry == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
return new HashMap.SimpleEntry(entry.getKey(), DisguiseParser.parseDisguise(entry.getValue()));
|
|
|
|
}
|
|
|
|
catch (IllegalAccessException | InvocationTargetException | DisguiseParseException e) {
|
|
|
|
DisguiseUtilities.getLogger().warning("Error when attempting to grab the custom disguise " + disguise);
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2019-04-16 22:10:15 +02:00
|
|
|
|
2019-05-16 08:07:53 +02:00
|
|
|
return null;
|
2019-04-16 22:10:15 +02:00
|
|
|
}
|
|
|
|
|
2019-05-16 08:07:53 +02:00
|
|
|
public static Entry<DisguisePerm, Disguise> getCustomDisguise(Entity target,
|
2019-04-16 22:10:15 +02:00
|
|
|
String disguise) throws IllegalAccessException, DisguiseParseException, InvocationTargetException {
|
2019-05-16 08:07:53 +02:00
|
|
|
Entry<DisguisePerm, String> entry = getRawCustomDisguise(disguise);
|
|
|
|
|
|
|
|
if (entry == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2019-04-16 22:10:15 +02:00
|
|
|
|
|
|
|
return new HashMap.SimpleEntry(entry.getKey(),
|
|
|
|
DisguiseParser.parseDisguise(Bukkit.getConsoleSender(), target, entry.getValue()));
|
|
|
|
}
|
|
|
|
|
2019-05-16 08:07:53 +02:00
|
|
|
public static Entry<DisguisePerm, Disguise> getCustomDisguise(CommandSender invoker, Entity target,
|
2019-04-16 22:10:15 +02:00
|
|
|
String disguise) throws IllegalAccessException, DisguiseParseException, InvocationTargetException {
|
2019-05-16 08:07:53 +02:00
|
|
|
Entry<DisguisePerm, String> entry = getRawCustomDisguise(disguise);
|
|
|
|
|
|
|
|
if (entry == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2019-04-16 22:10:15 +02:00
|
|
|
|
|
|
|
return new HashMap.SimpleEntry(entry.getKey(), DisguiseParser.parseDisguise(invoker, target, entry.getValue()));
|
|
|
|
}
|
|
|
|
|
2020-01-02 05:10:36 +01:00
|
|
|
public static void removeCustomDisguise(String disguise) {
|
|
|
|
for (DisguisePerm entry : customDisguises.keySet()) {
|
|
|
|
String name = entry.toReadable();
|
|
|
|
|
|
|
|
if (!name.equalsIgnoreCase(disguise) && !name.replaceAll("_", "").equalsIgnoreCase(disguise))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
customDisguises.remove(entry);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-16 08:07:53 +02:00
|
|
|
public static Entry<DisguisePerm, String> getRawCustomDisguise(String disguise) {
|
2019-03-05 05:46:47 +01:00
|
|
|
for (Entry<DisguisePerm, String> entry : customDisguises.entrySet()) {
|
|
|
|
String name = entry.getKey().toReadable();
|
|
|
|
|
|
|
|
if (!name.equalsIgnoreCase(disguise) && !name.replaceAll("_", "").equalsIgnoreCase(disguise))
|
2016-11-30 18:56:11 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-06-19 11:23:02 +02:00
|
|
|
public static void setUseTranslations(boolean setUseTranslations) {
|
|
|
|
useTranslations = setUseTranslations;
|
|
|
|
|
2018-07-11 20:05:36 +02:00
|
|
|
TranslateType.refreshTranslations();
|
2017-06-19 11:23:02 +02:00
|
|
|
}
|
|
|
|
|
2018-08-24 00:01:01 +02:00
|
|
|
public static void loadConfig() {
|
|
|
|
// Always save the default config
|
|
|
|
LibsDisguises.getInstance().saveDefaultConfig();
|
|
|
|
// Redundant for the first load, however other plugins may call loadConfig() at a later stage where we
|
|
|
|
// definitely want to reload it.
|
|
|
|
LibsDisguises.getInstance().reloadConfig();
|
|
|
|
|
2020-01-02 05:10:36 +01:00
|
|
|
File skinsFolder = new File(LibsDisguises.getInstance().getDataFolder(), "Skins");
|
|
|
|
|
|
|
|
if (!skinsFolder.exists()) {
|
|
|
|
skinsFolder.mkdir();
|
|
|
|
|
|
|
|
File explain = new File(skinsFolder, "README");
|
|
|
|
|
|
|
|
try {
|
|
|
|
explain.createNewFile();
|
|
|
|
FileUtils.write(explain,
|
|
|
|
"This folder is used to store .png files for uploading with the /savedisguise or /grabskin " +
|
|
|
|
"commands");
|
|
|
|
}
|
|
|
|
catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-24 00:01:01 +02:00
|
|
|
ConfigurationSection config = LibsDisguises.getInstance().getConfig();
|
|
|
|
|
2016-05-12 13:30:22 +02:00
|
|
|
PacketsManager.setViewDisguisesListener(true);
|
2020-02-01 23:59:18 +01:00
|
|
|
disableCommands = config.getBoolean("DisableCommands");
|
|
|
|
|
2016-05-12 13:30:22 +02:00
|
|
|
setAddEntityAnimations(config.getBoolean("AddEntityAnimations"));
|
2020-02-01 23:59:18 +01:00
|
|
|
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"));
|
2017-06-22 18:21:52 +02:00
|
|
|
setDisguiseBlownWhenAttacked(
|
|
|
|
config.getBoolean("BlowDisguises", config.getBoolean("BlowDisguisesWhenAttacked")));
|
2020-02-01 23:59:18 +01:00
|
|
|
setDisguiseBlownWhenAttacking(
|
|
|
|
config.getBoolean("BlowDisguises", config.getBoolean("BlowDisguisesWhenAttacking")));
|
|
|
|
setDisguiseCloneExpire(config.getInt("DisguiseCloneExpire"));
|
|
|
|
setDisguiseEntityExpire(config.getInt("DisguiseEntityExpire"));
|
|
|
|
setDynamicExpiry(config.getBoolean("DynamicExpiry"));
|
|
|
|
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"));
|
2016-05-12 13:30:22 +02:00
|
|
|
setKeepDisguiseOnPlayerDeath(config.getBoolean("KeepDisguises.PlayerDeath"));
|
2020-02-01 23:59:18 +01:00
|
|
|
setLlamaCarpetable(config.getBoolean("CarpetableLlama"));
|
|
|
|
setMaxClonedDisguises(config.getInt("DisguiseCloneSize"));
|
|
|
|
setMaxHealthDeterminedByDisguisedEntity(config.getBoolean("MaxHealthDeterminedByEntity"));
|
|
|
|
setMetaPacketsEnabled(config.getBoolean("PacketsEnabled.Metadata"));
|
2016-05-12 13:30:22 +02:00
|
|
|
setMiscDisguisesForLivingEnabled(config.getBoolean("MiscDisguisesForLiving"));
|
2020-02-01 23:59:18 +01:00
|
|
|
setModifyBoundingBox(config.getBoolean("ModifyBoundingBox"));
|
|
|
|
setModifyCollisions(config.getBoolean("Scoreboard.Collisions"));
|
|
|
|
setMonstersIgnoreDisguises(config.getBoolean("MonstersIgnoreDisguises"));
|
2016-05-12 13:30:22 +02:00
|
|
|
setMovementPacketsEnabled(config.getBoolean("PacketsEnabled.Movement"));
|
2020-02-01 23:59:18 +01:00
|
|
|
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"));
|
2016-05-12 13:30:22 +02:00
|
|
|
setSheepDyeable(config.getBoolean("DyeableSheep"));
|
2016-11-30 05:08:12 +01:00
|
|
|
setShowDisguisedPlayersInTab(config.getBoolean("ShowPlayerDisguisesInTab"));
|
2020-02-01 23:59:18 +01:00
|
|
|
setSoundsEnabled(config.getBoolean("DisguiseSounds"));
|
|
|
|
setStopShulkerDisguisesFromMoving(config.getBoolean("StopShulkerDisguisesFromMoving", true));
|
|
|
|
setUUIDGeneratedVersion(config.getInt("UUIDVersion"));
|
|
|
|
setUndisguiseOnWorldChange(config.getBoolean("UndisguiseOnWorldChange"));
|
2017-06-02 15:51:03 +02:00
|
|
|
setUpdateGameProfiles(config.getBoolean("UpdateGameProfiles"));
|
2020-02-01 23:59:18 +01:00
|
|
|
setUpdateNotificationPermission(config.getString("Permission"));
|
2017-06-19 11:23:02 +02:00
|
|
|
setUseTranslations(config.getBoolean("Translations"));
|
2020-02-01 23:59:18 +01:00
|
|
|
setVelocitySent(config.getBoolean("SendVelocity"));
|
|
|
|
setViewDisguises(config.getBoolean("ViewSelfDisguises"));
|
2018-08-24 00:01:01 +02:00
|
|
|
setWarnScoreboardConflict(config.getBoolean("Scoreboard.WarnConflict"));
|
2020-02-01 23:59:18 +01:00
|
|
|
setWitherSkullPacketsEnabled(config.getBoolean("PacketsEnabled.WitherSkull"));
|
|
|
|
setWolfDyeable(config.getBoolean("DyeableWolf"));
|
2016-12-21 04:25:28 +01:00
|
|
|
|
2017-06-22 18:14:19 +02:00
|
|
|
if (!LibsPremium.isPremium() && (isSavePlayerDisguises() || isSaveEntityDisguises())) {
|
2018-08-14 02:42:35 +02:00
|
|
|
DisguiseUtilities.getLogger().warning("You must purchase the plugin to use saved disguises!");
|
2017-06-22 18:14:19 +02:00
|
|
|
}
|
|
|
|
|
2018-12-16 02:47:42 +01:00
|
|
|
try {
|
|
|
|
setUpdatesBranch(UpdatesBranch.valueOf(config.getString("UpdatesBranch").toUpperCase()));
|
|
|
|
}
|
|
|
|
catch (Exception ex) {
|
2019-02-03 02:02:59 +01:00
|
|
|
DisguiseUtilities.getLogger().warning(
|
|
|
|
"Cannot parse '" + config.getString("UpdatesBranch") + "' to a valid option for UpdatesBranch");
|
2018-12-16 02:47:42 +01:00
|
|
|
}
|
|
|
|
|
2016-12-21 04:25:28 +01:00
|
|
|
try {
|
2017-06-19 19:06:35 +02:00
|
|
|
String option = config.getString("SelfDisguisesScoreboard", DisguisePushing.MODIFY_SCOREBOARD.name())
|
|
|
|
.toUpperCase();
|
2017-02-23 13:28:37 +01:00
|
|
|
|
|
|
|
if (!option.endsWith("_SCOREBOARD"))
|
|
|
|
option += "_SCOREBOARD";
|
|
|
|
|
2020-02-01 23:59:18 +01:00
|
|
|
pushingOption = DisguisePushing.valueOf(option);
|
2016-12-21 04:25:28 +01:00
|
|
|
}
|
|
|
|
catch (Exception ex) {
|
2018-12-16 02:47:42 +01:00
|
|
|
DisguiseUtilities.getLogger().warning("Cannot parse '" + config.getString("SelfDisguisesScoreboard") +
|
2019-03-12 06:29:39 +01:00
|
|
|
"' to a valid option for SelfDisguisesScoreboard");
|
2016-12-21 04:25:28 +01:00
|
|
|
}
|
2016-11-30 18:38:43 +01:00
|
|
|
|
2018-08-14 02:42:35 +02:00
|
|
|
loadCustomDisguises();
|
|
|
|
|
2019-12-28 01:10:52 +01:00
|
|
|
// Another wee trap for the non-legit
|
2020-01-22 06:46:57 +01:00
|
|
|
if ("%%__USER__%%".equals("12345") && getCustomDisguises().size() > 10) {
|
2019-12-28 01:10:52 +01:00
|
|
|
setSoundsEnabled(false);
|
|
|
|
|
|
|
|
// Lets remove randomly half the custom disguises hey
|
|
|
|
Iterator<Entry<DisguisePerm, String>> itel = getCustomDisguises().entrySet().iterator();
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
while (itel.hasNext()) {
|
|
|
|
itel.next();
|
|
|
|
|
|
|
|
if (new Random().nextBoolean()) {
|
|
|
|
itel.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-14 02:42:35 +02:00
|
|
|
int missingConfigs = 0;
|
|
|
|
|
|
|
|
for (String key : config.getDefaultSection().getKeys(true)) {
|
|
|
|
if (config.contains(key, true)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
missingConfigs++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (missingConfigs > 0) {
|
|
|
|
DisguiseUtilities.getLogger().warning(
|
|
|
|
"Your config is missing " + missingConfigs + " options! Please consider regenerating your config!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void loadCustomDisguises() {
|
2016-11-30 18:38:43 +01:00
|
|
|
customDisguises.clear();
|
|
|
|
|
|
|
|
File disguisesFile = new File("plugins/LibsDisguises/disguises.yml");
|
|
|
|
|
|
|
|
if (!disguisesFile.exists())
|
|
|
|
return;
|
|
|
|
|
|
|
|
YamlConfiguration disguisesConfig = YamlConfiguration.loadConfiguration(disguisesFile);
|
|
|
|
|
|
|
|
ConfigurationSection section = disguisesConfig.getConfigurationSection("Disguises");
|
|
|
|
|
|
|
|
if (section == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-14 02:42:35 +02:00
|
|
|
int failedCustomDisguises = 0;
|
|
|
|
|
2016-11-30 18:38:43 +01:00
|
|
|
for (String key : section.getKeys(false)) {
|
|
|
|
String toParse = section.getString(key);
|
|
|
|
|
|
|
|
try {
|
2019-12-28 01:10:52 +01:00
|
|
|
addCustomDisguise(key, toParse);
|
2016-11-30 18:38:43 +01:00
|
|
|
}
|
|
|
|
catch (DisguiseParseException e) {
|
2019-12-28 01:10:52 +01:00
|
|
|
failedCustomDisguises++;
|
2016-11-30 18:38:43 +01:00
|
|
|
|
2019-12-28 01:10:52 +01:00
|
|
|
if (e.getMessage() != null) {
|
|
|
|
DisguiseUtilities.getLogger().severe(e.getMessage());
|
|
|
|
}
|
2018-08-14 02:42:35 +02:00
|
|
|
|
2019-12-28 01:10:52 +01:00
|
|
|
if (e.getCause() != null) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2016-11-30 18:38:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-14 02:42:35 +02:00
|
|
|
if (failedCustomDisguises > 0) {
|
|
|
|
DisguiseUtilities.getLogger().severe("Failed to load " + failedCustomDisguises + " custom disguises");
|
|
|
|
}
|
|
|
|
|
|
|
|
DisguiseUtilities.getLogger().info("Loaded " + customDisguises.size() + " custom disguise" +
|
2018-05-18 05:27:05 +02:00
|
|
|
(customDisguises.size() == 1 ? "" : "s"));
|
2016-11-30 18:38:43 +01:00
|
|
|
}
|
|
|
|
|
2019-12-28 01:10:52 +01:00
|
|
|
public static void addCustomDisguise(String disguiseName, String toParse) throws DisguiseParseException {
|
|
|
|
if (getRawCustomDisguise(toParse) != null) {
|
2020-01-02 05:10:36 +01:00
|
|
|
throw new DisguiseParseException(LibsMsg.CUSTOM_DISGUISE_NAME_CONFLICT, disguiseName);
|
2019-12-28 01:10:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
String[] disguiseArgs = DisguiseUtilities.split(toParse);
|
|
|
|
|
|
|
|
Disguise disguise = DisguiseParser.parseTestDisguise(Bukkit.getConsoleSender(), "disguise", disguiseArgs,
|
|
|
|
DisguiseParser.getPermissions(Bukkit.getConsoleSender(), "disguise"));
|
|
|
|
|
|
|
|
DisguisePerm perm = new DisguisePerm(disguise.getType(), disguiseName);
|
|
|
|
|
|
|
|
customDisguises.put(perm, toParse);
|
|
|
|
|
|
|
|
DisguiseUtilities.getLogger().info("Loaded custom disguise " + disguiseName);
|
|
|
|
}
|
|
|
|
catch (DisguiseParseException e) {
|
2020-01-02 05:10:36 +01:00
|
|
|
throw new DisguiseParseException(LibsMsg.ERROR_LOADING_CUSTOM_DISGUISE, disguiseName,
|
|
|
|
(e.getMessage() == null ? "" : ": " + e.getMessage()));
|
2019-12-28 01:10:52 +01:00
|
|
|
}
|
2020-01-02 05:10:36 +01:00
|
|
|
catch (IllegalAccessException | InvocationTargetException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
throw new DisguiseParseException(LibsMsg.ERROR_LOADING_CUSTOM_DISGUISE, disguiseName, "");
|
2019-12-28 01:10:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-12 13:30:22 +02:00
|
|
|
/**
|
|
|
|
* Is the sound packets caught and modified
|
|
|
|
*/
|
2016-11-30 05:08:12 +01:00
|
|
|
public static boolean isSoundEnabled() {
|
2016-05-12 13:30:22 +02:00
|
|
|
return PacketsManager.isHearDisguisesEnabled();
|
|
|
|
}
|
|
|
|
|
2016-11-30 05:08:12 +01:00
|
|
|
public static void setAnimationPacketsEnabled(boolean enabled) {
|
|
|
|
if (enabled != isAnimationPacketsEnabled()) {
|
2020-02-01 23:59:18 +01:00
|
|
|
animationPacketsEnabled = enabled;
|
2016-05-12 13:30:22 +02:00
|
|
|
|
|
|
|
PacketsManager.setupMainPacketsListener();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-30 05:08:12 +01:00
|
|
|
public static void setCollectPacketsEnabled(boolean enabled) {
|
|
|
|
if (enabled != isCollectPacketsEnabled()) {
|
2020-02-01 23:59:18 +01:00
|
|
|
collectPacketsEnabled = enabled;
|
2016-05-12 13:30:22 +02:00
|
|
|
|
|
|
|
PacketsManager.setupMainPacketsListener();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-30 05:08:12 +01:00
|
|
|
public static void setEntityStatusPacketsEnabled(boolean enabled) {
|
|
|
|
if (enabled != isEntityStatusPacketsEnabled()) {
|
2020-02-01 23:59:18 +01:00
|
|
|
entityStatusPacketsEnabled = enabled;
|
2016-05-12 13:30:22 +02:00
|
|
|
|
|
|
|
PacketsManager.setupMainPacketsListener();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-30 05:08:12 +01:00
|
|
|
public static void setEquipmentPacketsEnabled(boolean enabled) {
|
|
|
|
if (enabled != isEquipmentPacketsEnabled()) {
|
2020-02-01 23:59:18 +01:00
|
|
|
equipmentPacketsEnabled = enabled;
|
2016-05-12 13:30:22 +02:00
|
|
|
|
|
|
|
PacketsManager.setupMainPacketsListener();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the plugin to hide self disguises armor from theirselves
|
|
|
|
*/
|
2016-11-30 05:08:12 +01:00
|
|
|
public static void setHideArmorFromSelf(boolean hideArmor) {
|
2020-02-01 23:59:18 +01:00
|
|
|
if (hidingArmorFromSelf != hideArmor) {
|
|
|
|
hidingArmorFromSelf = hideArmor;
|
2016-05-12 13:30:22 +02:00
|
|
|
|
|
|
|
PacketsManager.setInventoryListenerEnabled(isHidingHeldItemFromSelf() || isHidingArmorFromSelf());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-05-18 05:27:05 +02:00
|
|
|
* Does the plugin appear to remove the item they are holding, to prevent a floating sword when they are viewing
|
|
|
|
* self disguise
|
2016-05-12 13:30:22 +02:00
|
|
|
*/
|
2016-11-30 05:08:12 +01:00
|
|
|
public static void setHideHeldItemFromSelf(boolean hideHelditem) {
|
2020-02-01 23:59:18 +01:00
|
|
|
if (hidingHeldItemFromSelf != hideHelditem) {
|
|
|
|
hidingHeldItemFromSelf = hideHelditem;
|
2016-05-12 13:30:22 +02:00
|
|
|
|
|
|
|
PacketsManager.setInventoryListenerEnabled(isHidingHeldItemFromSelf() || isHidingArmorFromSelf());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-30 05:08:12 +01:00
|
|
|
public static void setMiscDisguisesForLivingEnabled(boolean enabled) {
|
|
|
|
if (enabled != isMiscDisguisesForLivingEnabled()) {
|
2016-05-12 13:30:22 +02:00
|
|
|
miscDisguisesForLivingEnabled = enabled;
|
|
|
|
|
|
|
|
PacketsManager.setupMainPacketsListener();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-30 05:08:12 +01:00
|
|
|
public static void setMovementPacketsEnabled(boolean enabled) {
|
|
|
|
if (enabled != isMovementPacketsEnabled()) {
|
2020-02-01 23:59:18 +01:00
|
|
|
movementPacketsEnabled = enabled;
|
2016-05-12 13:30:22 +02:00
|
|
|
|
|
|
|
PacketsManager.setupMainPacketsListener();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set if the disguises play sounds when hurt
|
|
|
|
*/
|
2016-11-30 05:08:12 +01:00
|
|
|
public static void setSoundsEnabled(boolean isSoundsEnabled) {
|
2016-05-12 13:30:22 +02:00
|
|
|
PacketsManager.setHearDisguisesListener(isSoundsEnabled);
|
|
|
|
}
|
|
|
|
|
2020-02-01 23:59:18 +01:00
|
|
|
public enum DisguisePushing { // This enum has a really bad name..
|
|
|
|
MODIFY_SCOREBOARD,
|
|
|
|
IGNORE_SCOREBOARD,
|
|
|
|
CREATE_SCOREBOARD
|
2019-11-14 03:25:26 +01:00
|
|
|
}
|
|
|
|
|
2020-02-01 23:59:18 +01:00
|
|
|
public enum UpdatesBranch {
|
|
|
|
SAME_BUILDS,
|
|
|
|
SNAPSHOTS,
|
|
|
|
RELEASES
|
2016-05-12 13:30:22 +02:00
|
|
|
}
|
|
|
|
}
|