From d83cb14606684ec6b1384f7fecec219d07644c6b Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Fri, 18 May 2018 15:27:05 +1200 Subject: [PATCH] Add new options to disable collisions and see friendly invisibles for scoreboards in config, fixed a minor bug where create scoreboard would override settings --- config.yml | 7 +++ .../disguise/DisguiseConfig.java | 62 ++++++++++++------- .../disguise/disguisetypes/Disguise.java | 2 +- .../disguise/utilities/DisguiseUtilities.java | 17 ++--- 4 files changed, 58 insertions(+), 30 deletions(-) diff --git a/config.yml b/config.yml index d2751f01..e926d5de 100644 --- a/config.yml +++ b/config.yml @@ -39,6 +39,13 @@ Translations: false # CREATE_SCOREBOARD - Creates a new team which copies the attributes of their previous scoreboard team which they are then assigned to. This means they keep nametag color and other options. SelfDisguisesScoreboard: MODIFY_SCOREBOARD +# More options incase you want to disable a specific setting of the scoreboard +Scoreboard: + # Should it modify the scoreboard to turn collisions off? + Collisions: true + # Should it modify the scoreboard teams to disable seeing friendly invisibles? + SeeFriendlyInvisibles: true + # Whats the permission to get the notification? Permission: 'libsdisguises.update' diff --git a/src/me/libraryaddict/disguise/DisguiseConfig.java b/src/me/libraryaddict/disguise/DisguiseConfig.java index e5f8e612..918ede88 100644 --- a/src/me/libraryaddict/disguise/DisguiseConfig.java +++ b/src/me/libraryaddict/disguise/DisguiseConfig.java @@ -1,19 +1,18 @@ package me.libraryaddict.disguise; -import java.io.File; -import java.util.HashMap; -import java.util.Map.Entry; - +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.utilities.DisguiseParser; +import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException; import me.libraryaddict.disguise.utilities.LibsPremium; +import me.libraryaddict.disguise.utilities.PacketsManager; import me.libraryaddict.disguise.utilities.TranslateType; import org.bukkit.Bukkit; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; -import me.libraryaddict.disguise.disguisetypes.Disguise; -import me.libraryaddict.disguise.utilities.DisguiseParser; -import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException; -import me.libraryaddict.disguise.utilities.PacketsManager; +import java.io.File; +import java.util.HashMap; +import java.util.Map.Entry; public class DisguiseConfig { public static enum DisguisePushing { // This enum has a really bad name.. @@ -63,11 +62,13 @@ public class DisguiseConfig { private static boolean savePlayerDisguises; private static boolean saveEntityDisguises; private static boolean useTranslations; + private static boolean modifyCollisions; + private static boolean modifySeeFriendlyInvisibles; public static Entry getCustomDisguise(String disguise) { for (Entry entry : customDisguises.entrySet()) { - if (!entry.getKey().equalsIgnoreCase(disguise) && !entry.getKey().replaceAll("_", "") - .equalsIgnoreCase(disguise)) + if (!entry.getKey().equalsIgnoreCase(disguise) && + !entry.getKey().replaceAll("_", "").equalsIgnoreCase(disguise)) continue; return entry; @@ -76,6 +77,22 @@ public class DisguiseConfig { return null; } + public static boolean isModifyCollisions() { + return modifyCollisions; + } + + public static boolean isModifySeeFriendlyInvisibles() { + return modifySeeFriendlyInvisibles; + } + + public static void setModifyCollisions(boolean isModifyCollisions) { + modifyCollisions = isModifyCollisions; + } + + public static void setModifySeeFriendlyInvisibles(boolean isModifySeeFriendlyInvisibles) { + modifySeeFriendlyInvisibles = isModifySeeFriendlyInvisibles; + } + public static boolean isSavePlayerDisguises() { return savePlayerDisguises; } @@ -188,6 +205,8 @@ public class DisguiseConfig { setSavePlayerDisguises(config.getBoolean("SaveDisguises.Players")); setSaveEntityDisguises(config.getBoolean("SaveDisguises.Entities")); setUseTranslations(config.getBoolean("Translations")); + setModifyCollisions(config.getBoolean("Scoreboard.Collisions")); + setModifySeeFriendlyInvisibles(config.getBoolean("Scoreboard.SeeFriendlyInvisibles")); if (!LibsPremium.isPremium() && (isSavePlayerDisguises() || isSaveEntityDisguises())) { System.out.println("[LibsDisguises] You must purchase the plugin to use saved disguises!"); @@ -203,8 +222,8 @@ public class DisguiseConfig { disablePushing = DisguisePushing.valueOf(option); } catch (Exception ex) { - System.out.println("[LibsDisguises] Cannot parse '" + config - .getString("SelfDisguisesScoreboard") + "' to a valid option for SelfDisguisesTeam"); + System.out.println("[LibsDisguises] Cannot parse '" + config.getString("SelfDisguisesScoreboard") + + "' to a valid option for SelfDisguisesTeam"); } customDisguises.clear(); @@ -241,9 +260,8 @@ public class DisguiseConfig { System.out.println("[LibsDisguises] Loaded custom disguise " + key); } catch (DisguiseParseException e) { - System.err.println( - "[LibsDisguises] Error while loading custom disguise '" + key + "'" + (e.getMessage() == null ? - "" : ": " + e.getMessage())); + System.err.println("[LibsDisguises] Error while loading custom disguise '" + key + "'" + + (e.getMessage() == null ? "" : ": " + e.getMessage())); if (e.getMessage() == null) e.printStackTrace(); @@ -253,9 +271,8 @@ public class DisguiseConfig { } } - System.out.println( - "[LibsDisguises] Loaded " + customDisguises.size() + " custom disguise" + (customDisguises.size() == 1 ? - "" : "s")); + System.out.println("[LibsDisguises] Loaded " + customDisguises.size() + " custom disguise" + + (customDisguises.size() == 1 ? "" : "s")); } public static boolean isAnimationPacketsEnabled() { @@ -299,14 +316,16 @@ public class DisguiseConfig { } /** - * Is the plugin modifying the inventory packets so that players when self disguised, do not see their armor floating around + * 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 + * 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; @@ -490,7 +509,8 @@ public class DisguiseConfig { } /** - * Does the plugin appear to remove the item they are holding, to prevent a floating sword when they are viewing self disguise + * 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) { diff --git a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java index 0c5b5cd6..91511e26 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -491,7 +491,7 @@ public abstract class Disguise { Bukkit.getPluginManager().callEvent(event); - // If this disguise is not in use, and the entity isnt a player + // If this disguise is not in use, and the entity isnt a player that's offline if (event.isCancelled() && (!(getEntity() instanceof Player) || ((Player) getEntity()).isOnline())) return false; diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index f3c3a508..ccce1d55 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -1357,14 +1357,6 @@ public class DisguiseUtilities { ldTeam = scoreboard.registerNewTeam(ldTeamName); } - if (ldTeam.getOption(Option.COLLISION_RULE) != OptionStatus.NEVER) { - ldTeam.setOption(Option.COLLISION_RULE, OptionStatus.NEVER); - } - - if (ldTeam.canSeeFriendlyInvisibles()) { - ldTeam.setCanSeeFriendlyInvisibles(false); - } - if (!ldTeam.hasEntry(player.getName())) ldTeam.addEntry(player.getName()); @@ -1379,6 +1371,15 @@ public class DisguiseUtilities { ldTeam.setOption(option, prevTeam.getOption(option)); } } + + if (ldTeam.getOption(Option.COLLISION_RULE) != OptionStatus.NEVER && + DisguiseConfig.isModifyCollisions()) { + ldTeam.setOption(Option.COLLISION_RULE, OptionStatus.NEVER); + } + + if (ldTeam.canSeeFriendlyInvisibles() && DisguiseConfig.isModifySeeFriendlyInvisibles()) { + ldTeam.setCanSeeFriendlyInvisibles(false); + } } // Add himself to his own entity tracker