Add new options to disable collisions and see friendly invisibles for scoreboards in config, fixed a minor bug where create scoreboard would override settings

This commit is contained in:
libraryaddict 2018-05-18 15:27:05 +12:00
parent 1c60606131
commit d83cb14606
4 changed files with 58 additions and 30 deletions

View File

@ -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'

View File

@ -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<String, Disguise> getCustomDisguise(String disguise) {
for (Entry<String, Disguise> 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) {

View File

@ -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;

View File

@ -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