Read description

Renamed config option 'SeeFriendlyInvisibles' to more accurate 'DisableFriendlyInvisibles'
Added config option 'WarnConflict' in 'Scoreboard'
Improved config loading to always save default config, moved config loading calls into DisguiseConfig
Improved scoreboard handling to properly unregister scoreboard teams on disable, and player quit instead of relying on a scheduler.
Removed redundant casts and imports, switched to lamba in a few calls
Removed DisguiseUtilities.getPlugin() and replaced with LibsDisguises.getInstance()
Now monitoring Self Disguises teams and if config option is enabled, displaying a warning in console about a possible scoreboard conflict
This commit is contained in:
libraryaddict 2018-08-24 10:01:01 +12:00
parent 0b0a9c2704
commit 2b94217aae
7 changed files with 227 additions and 211 deletions

View File

@ -44,7 +44,10 @@ 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
DisableFriendlyInvisibles: true
# Should the scoreboard warn you if it detects a potential conflict?
# If self disguises are disabled, or the scoreboard is using IGNORE_SCOREBOARD then this does nothing.
WarnConflict: true
# Whats the permission to get the notification?
Permission: 'libsdisguises.update'

View File

@ -60,7 +60,8 @@ public class DisguiseConfig {
private static boolean saveEntityDisguises;
private static boolean useTranslations;
private static boolean modifyCollisions;
private static boolean modifySeeFriendlyInvisibles;
private static boolean disableFriendlyInvisibles;
private static boolean warnScoreboardConflict;
public static Entry<String, Disguise> getCustomDisguise(String disguise) {
for (Entry<String, Disguise> entry : customDisguises.entrySet()) {
@ -74,20 +75,28 @@ 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 isModifySeeFriendlyInvisibles() {
return modifySeeFriendlyInvisibles;
public static boolean isDisableFriendlyInvisibles() {
return disableFriendlyInvisibles;
}
public static void setModifyCollisions(boolean isModifyCollisions) {
modifyCollisions = isModifyCollisions;
}
public static void setModifySeeFriendlyInvisibles(boolean isModifySeeFriendlyInvisibles) {
modifySeeFriendlyInvisibles = isModifySeeFriendlyInvisibles;
public static void setDisableFriendlyInvisibles(boolean isDisableFriendlyInvisibles) {
disableFriendlyInvisibles = isDisableFriendlyInvisibles;
}
public static boolean isSavePlayerDisguises() {
@ -156,7 +165,15 @@ public class DisguiseConfig {
updatePlayerCache = setUpdatePlayerCache;
}
public static void initConfig(ConfigurationSection config) {
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();
ConfigurationSection config = LibsDisguises.getInstance().getConfig();
setSoundsEnabled(config.getBoolean("DisguiseSounds"));
setVelocitySent(config.getBoolean("SendVelocity"));
setViewDisguises(
@ -203,7 +220,8 @@ public class DisguiseConfig {
setSaveEntityDisguises(config.getBoolean("SaveDisguises.Entities"));
setUseTranslations(config.getBoolean("Translations"));
setModifyCollisions(config.getBoolean("Scoreboard.Collisions"));
setModifySeeFriendlyInvisibles(config.getBoolean("Scoreboard.SeeFriendlyInvisibles"));
setDisableFriendlyInvisibles(config.getBoolean("Scoreboard.DisableFriendlyInvisibles"));
setWarnScoreboardConflict(config.getBoolean("Scoreboard.WarnConflict"));
if (!LibsPremium.isPremium() && (isSavePlayerDisguises() || isSaveEntityDisguises())) {
DisguiseUtilities.getLogger().warning("You must purchase the plugin to use saved disguises!");

View File

@ -7,7 +7,6 @@ import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode;
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
import com.comphenix.protocol.wrappers.PlayerInfoData;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
@ -94,8 +93,8 @@ public class DisguiseListener implements Listener {
});
}
catch (Exception ex) {
DisguiseUtilities.getLogger().warning(String
.format("Failed to check for update: %s", ex.getMessage()));
DisguiseUtilities.getLogger()
.warning(String.format("Failed to check for update: %s", ex.getMessage()));
}
}
}, 0, (20 * 60 * 60 * 6)); // Check every 6 hours
@ -382,11 +381,13 @@ public class DisguiseListener implements Listener {
@EventHandler
public void onQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
DisguiseUtilities.removeSelfDisguiseScoreboard(player);
if (!DisguiseConfig.isSavePlayerDisguises())
return;
Player player = event.getPlayer();
Disguise[] disguises = DisguiseAPI.getDisguises(player);
if (disguises.length <= 0)
@ -395,7 +396,6 @@ public class DisguiseListener implements Listener {
DisguiseUtilities.saveDisguises(player.getUniqueId(), disguises);
}
@EventHandler
public void onRespawn(PlayerRespawnEvent event) {
if (DisguiseConfig.isBedPacketsEnabled()) {

View File

@ -32,8 +32,6 @@ public class LibsDisguises extends JavaPlugin {
public void onEnable() {
instance = this;
saveDefaultConfig();
getLogger().info("Discovered nms version: " + ReflectionManager.getBukkitVersion());
if (!new File(getDataFolder(), "disguises.yml").exists()) {
@ -63,7 +61,7 @@ public class LibsDisguises extends JavaPlugin {
registerValues();
DisguiseConfig.initConfig(getConfig());
DisguiseConfig.loadConfig();
PacketsManager.addPacketListeners();
@ -256,6 +254,10 @@ public class LibsDisguises extends JavaPlugin {
@Override
public void onDisable() {
DisguiseUtilities.saveDisguises();
for (Player player : Bukkit.getOnlinePlayers()) {
DisguiseUtilities.removeSelfDisguiseScoreboard(player);
}
}
private void registerCommand(String commandName, CommandExecutor executioner) {
@ -271,9 +273,9 @@ public class LibsDisguises extends JavaPlugin {
/**
* Reloads the config with new config options.
*/
@Deprecated
public void reload() {
reloadConfig();
DisguiseConfig.initConfig(getConfig());
DisguiseConfig.loadConfig();
}
/**

View File

@ -1,9 +1,8 @@
package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.utilities.LibsMsg;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.TranslateType;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
@ -53,13 +52,12 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (args.length == 0) {
sender.sendMessage(
ChatColor.DARK_GREEN + "This server is running " + "Lib's Disguises v" + Bukkit.getPluginManager()
.getPlugin("LibsDisguises").getDescription()
.getVersion() + " by libraryaddict, formerly maintained " + "by Byteflux and NavidK0." + (
sender.hasPermission("libsdisguises.reload") ?
"\nUse " + ChatColor.GREEN + "/libsdisguises " + "reload" + ChatColor.DARK_GREEN + " to reload the config. All disguises will be blown by doing this" + "." :
""));
sender.sendMessage(ChatColor.DARK_GREEN + "This server is running " + "Lib's Disguises v" +
Bukkit.getPluginManager().getPlugin("LibsDisguises").getDescription().getVersion() +
" by libraryaddict, formerly maintained " + "by Byteflux and NavidK0." +
(sender.hasPermission("libsdisguises.reload") ?
"\nUse " + ChatColor.GREEN + "/libsdisguises " + "reload" + ChatColor.DARK_GREEN +
" to reload the config. All disguises will be blown by doing this" + "." : ""));
if (LibsPremium.isPremium()) {
sender.sendMessage(ChatColor.DARK_GREEN + "This server supports the plugin developer!");
@ -67,7 +65,7 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter {
} else if (args.length > 0) {
if (sender.hasPermission("libsdisguises.reload")) {
if (args[0].equalsIgnoreCase("reload")) {
LibsDisguises.getInstance().reload();
DisguiseConfig.loadConfig();
sender.sendMessage(LibsMsg.RELOADED_CONFIG.get());
return true;
} else {

View File

@ -11,6 +11,7 @@ import com.comphenix.protocol.wrappers.WrappedWatchableObject;
import com.google.common.base.Strings;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.ReflectionManager;
import net.md_5.bungee.api.chat.BaseComponent;
@ -164,23 +165,20 @@ public class FlagWatcher {
if (watch.getIndex() == 6) {
Object value = watch.getValue();
if (value != null && value instanceof Float) {
if (value instanceof Float) {
float newHealth = (Float) value;
if (newHealth > 0 && hasDied) {
hasDied = false;
Bukkit.getScheduler()
.scheduleSyncDelayedTask(DisguiseUtilities.getPlugin(), new Runnable() {
@Override
public void run() {
try {
DisguiseUtilities.sendSelfDisguise((Player) getDisguise().getEntity(),
getDisguise());
}
catch (Exception ex) {
ex.printStackTrace();
}
.scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
try {
DisguiseUtilities.sendSelfDisguise((Player) getDisguise().getEntity(),
getDisguise());
}
catch (Exception ex) {
ex.printStackTrace();
}
}, 2);
} else if (newHealth <= 0 && !hasDied) {
@ -308,7 +306,7 @@ public class FlagWatcher {
watchableObjects = new ArrayList<>();
for (int i = 0; i <= 31; i++) {
WrappedWatchableObject watchable = null;
WrappedWatchableObject watchable;
if (entityValues.containsKey(i) && entityValues.get(i) != null) {
watchable = ReflectionManager.createWatchable(i, entityValues.get(i));
@ -405,7 +403,7 @@ public class FlagWatcher {
public void setCustomName(String name) {
if (Strings.isNullOrEmpty(name)) {
setData(MetaIndex.ENTITY_CUSTOM_NAME, Optional.<WrappedChatComponent>empty());
setData(MetaIndex.ENTITY_CUSTOM_NAME, Optional.empty());
} else {
if (name.length() > 64) {
name = name.substring(0, 64);
@ -425,7 +423,7 @@ public class FlagWatcher {
private void setEntityFlag(int byteValue, boolean flag) {
modifiedEntityAnimations[byteValue] = true;
byte b0 = (byte) getData(MetaIndex.ENTITY_META);
byte b0 = getData(MetaIndex.ENTITY_META);
if (flag) {
setData(MetaIndex.ENTITY_META, (byte) (b0 | 1 << byteValue));

View File

@ -68,12 +68,12 @@ public class DisguiseUtilities {
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 LibsDisguises libsDisguises;
private static HashMap<String, ArrayList<Object>> runnables = new HashMap<>();
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;
@ -329,7 +329,7 @@ public class DisguiseUtilities {
}
};
runnable.runTaskLater(libsDisguises, 20);
runnable.runTaskLater(LibsDisguises.getInstance(), 20);
}
public static void addGameProfile(String string, WrappedGameProfile gameProfile) {
@ -764,13 +764,13 @@ public class DisguiseUtilities {
}
if (contactMojang && !runnables.containsKey(playerName)) {
Bukkit.getScheduler().runTaskAsynchronously(libsDisguises, new Runnable() {
Bukkit.getScheduler().runTaskAsynchronously(LibsDisguises.getInstance(), new Runnable() {
@Override
public void run() {
try {
final WrappedGameProfile gameProfile = lookupGameProfile(origName);
Bukkit.getScheduler().runTask(libsDisguises, new Runnable() {
Bukkit.getScheduler().runTask(LibsDisguises.getInstance(), new Runnable() {
@Override
public void run() {
if (gameProfile.getProperties().isEmpty()) {
@ -845,8 +845,6 @@ public class DisguiseUtilities {
}
public static void init(LibsDisguises disguises) {
libsDisguises = disguises;
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(MetaIndex.class, new SerializerMetaIndex());
gsonBuilder.registerTypeAdapter(WrappedGameProfile.class, new SerializerGameProfile());
@ -971,7 +969,7 @@ public class DisguiseUtilities {
PacketContainer destroyPacket = getDestroyPacket(disguise.getEntity().getEntityId());
if (disguise.isDisguiseInUse() && disguise.getEntity() instanceof Player &&
((Player) disguise.getEntity()).getName().equalsIgnoreCase(player)) {
disguise.getEntity().getName().equalsIgnoreCase(player)) {
removeSelfDisguise((Player) disguise.getEntity());
if (disguise.isSelfDisguiseVisible()) {
@ -980,15 +978,12 @@ public class DisguiseUtilities {
ProtocolLibrary.getProtocolManager().sendServerPacket((Player) disguise.getEntity(), destroyPacket);
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
@Override
public void run() {
try {
DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), disguise);
}
catch (Exception ex) {
ex.printStackTrace();
}
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
try {
DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), disguise);
}
catch (Exception ex) {
ex.printStackTrace();
}
}, 2);
} else {
@ -1018,16 +1013,12 @@ public class DisguiseUtilities {
ProtocolLibrary.getProtocolManager().sendServerPacket(pl, destroyPacket);
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
@Override
public void run() {
try {
updatePlayer.invoke(entityTrackerEntry, p);
}
catch (Exception ex) {
ex.printStackTrace();
}
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
try {
updatePlayer.invoke(entityTrackerEntry, p);
}
catch (Exception ex) {
ex.printStackTrace();
}
}, 2);
break;
@ -1074,15 +1065,12 @@ public class DisguiseUtilities {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, destroyPacket);
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
@Override
public void run() {
try {
updatePlayer.invoke(entityTrackerEntry, p);
}
catch (Exception ex) {
ex.printStackTrace();
}
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
try {
updatePlayer.invoke(entityTrackerEntry, p);
}
catch (Exception ex) {
ex.printStackTrace();
}
}, 2);
}
@ -1116,15 +1104,12 @@ public class DisguiseUtilities {
ProtocolLibrary.getProtocolManager().sendServerPacket((Player) disguise.getEntity(), destroyPacket);
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
@Override
public void run() {
try {
DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), disguise);
}
catch (Exception ex) {
ex.printStackTrace();
}
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
try {
DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), disguise);
}
catch (Exception ex) {
ex.printStackTrace();
}
}, 2);
}
@ -1151,16 +1136,12 @@ public class DisguiseUtilities {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, destroyPacket);
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
@Override
public void run() {
try {
updatePlayer.invoke(entityTrackerEntry, p);
}
catch (Exception ex) {
ex.printStackTrace();
}
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
try {
updatePlayer.invoke(entityTrackerEntry, p);
}
catch (Exception ex) {
ex.printStackTrace();
}
}, 2);
}
@ -1220,39 +1201,7 @@ public class DisguiseUtilities {
ex.printStackTrace();
}
String originalTeam = preDisguiseTeam.remove(player.getUniqueId());
if (DisguiseConfig.getPushingOption() != DisguisePushing.IGNORE_SCOREBOARD) {
// Code to stop player pushing
Scoreboard scoreboard = player.getScoreboard();
Team team = originalTeam == null ? null : scoreboard.getTeam(originalTeam);
Team ldTeam = null;
for (Team t : scoreboard.getTeams()) {
if (!t.hasEntry(player.getName()))
continue;
ldTeam = t;
break;
}
if (ldTeam != null) {
if (!ldTeam.getName().equals("LD Pushing") && !ldTeam.getName().endsWith("_LDP")) {
// Its not a team assigned by me
ldTeam = null;
}
}
if (team != null) {
team.addEntry(player.getName());
} else if (ldTeam != null) {
ldTeam.removeEntry(player.getName());
}
if (ldTeam != null && ldTeam.getEntries().isEmpty()) {
ldTeam.unregister();
}
}
removeSelfDisguiseScoreboard(player);
// player.spigot().setCollidesWithEntities(true);
// Finish up
@ -1295,6 +1244,129 @@ public class DisguiseUtilities {
player.updateInventory();
}
public static void removeSelfDisguiseScoreboard(Player player) {
String originalTeam = preDisguiseTeam.remove(player.getUniqueId());
String teamDisguise = disguiseTeam.remove(player.getUniqueId());
if (teamDisguise != null && DisguiseConfig.getPushingOption() != DisguisePushing.IGNORE_SCOREBOARD) {
// Code replace them back onto their original scoreboard team
Scoreboard scoreboard = player.getScoreboard();
Team team = originalTeam == null ? null : scoreboard.getTeam(originalTeam);
Team ldTeam = null;
for (Team t : scoreboard.getTeams()) {
if (!t.hasEntry(player.getName()))
continue;
ldTeam = t;
break;
}
if (DisguiseConfig.isWarnScoreboardConflict()) {
if (ldTeam == null || !ldTeam.getName().equals(teamDisguise)) {
getLogger().warning("Scoreboard conflict, the self disguise player was not on the expected team!");
} else {
OptionStatus collisions = ldTeam.getOption(Option.COLLISION_RULE);
if (collisions != OptionStatus.NEVER && collisions != OptionStatus.FOR_OTHER_TEAMS) {
getLogger().warning(
"Scoreboard conflict, the collisions for a self disguise player team has been " +
"unexpectedly modifed!");
}
}
}
if (ldTeam != null) {
if (!ldTeam.getName().equals("LD_Pushing") && !ldTeam.getName().endsWith("_LDP")) {
// Its not a team assigned by Lib's Disguises
ldTeam = null;
}
}
if (team != null) {
team.addEntry(player.getName());
} else if (ldTeam != null) {
ldTeam.removeEntry(player.getName());
}
if (ldTeam != null && ldTeam.getEntries().isEmpty()) {
ldTeam.unregister();
}
}
}
public static void setupSelfDisguiseScoreboard(Player player) {
DisguisePushing pOption = DisguiseConfig.getPushingOption();
if (pOption != DisguisePushing.IGNORE_SCOREBOARD) {
// Code to stop player pushing
Scoreboard scoreboard = player.getScoreboard();
Team prevTeam = null;
Team ldTeam = null;
String ldTeamName = "LD_Pushing";
for (Team t : scoreboard.getTeams()) {
if (!t.hasEntry(player.getName()))
continue;
prevTeam = t;
break;
}
// If the player is in a team already and the team isn't one controlled by Lib's Disguises
if (prevTeam != null && !(prevTeam.getName().equals("LD_Pushing") || prevTeam.getName().endsWith("_LDP"))) {
// If we're creating a scoreboard
if (pOption == DisguisePushing.CREATE_SCOREBOARD) {
// Remember his old team so we can give him it back later
preDisguiseTeam.put(player.getUniqueId(), prevTeam.getName());
} else {
// We're modifying the scoreboard
ldTeam = prevTeam;
}
} else {
prevTeam = null;
}
// If we are creating a new scoreboard because the current one must not be modified
if (pOption == DisguisePushing.CREATE_SCOREBOARD) {
// If they have a team, we'll reuse that name. Otherwise go for another name
ldTeamName = (prevTeam == null ? "No Team" : prevTeam.getName());
// Give the teamname a custom name
ldTeamName = ldTeamName.substring(0, Math.min(12, ldTeamName.length())) + "_LDP";
}
if (ldTeam == null && (ldTeam = scoreboard.getTeam(ldTeamName)) == null) {
ldTeam = scoreboard.registerNewTeam(ldTeamName);
}
disguiseTeam.put(player.getUniqueId(), ldTeam.getName());
if (!ldTeam.hasEntry(player.getName()))
ldTeam.addEntry(player.getName());
if (pOption == DisguisePushing.CREATE_SCOREBOARD && prevTeam != null) {
ldTeam.setAllowFriendlyFire(prevTeam.allowFriendlyFire());
ldTeam.setCanSeeFriendlyInvisibles(prevTeam.canSeeFriendlyInvisibles());
ldTeam.setDisplayName(prevTeam.getDisplayName());
ldTeam.setPrefix(prevTeam.getPrefix());
ldTeam.setSuffix(prevTeam.getSuffix());
for (Option option : Team.Option.values()) {
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.isDisableFriendlyInvisibles()) {
ldTeam.setCanSeeFriendlyInvisibles(false);
}
}
}
/**
* Sends the self disguise to the player
*/
@ -1315,87 +1387,16 @@ public class DisguiseUtilities {
// If it is, then this method will be run again in one tick. Which is when it should be constructed.
// Else its going to run in a infinite loop hue hue hue..
// At least until this disguise is discarded
Bukkit.getScheduler().runTask(libsDisguises, new Runnable() {
@Override
public void run() {
if (DisguiseAPI.getDisguise(player, player) == disguise) {
sendSelfDisguise(player, disguise);
}
Bukkit.getScheduler().runTask(LibsDisguises.getInstance(), () -> {
if (DisguiseAPI.getDisguise(player, player) == disguise) {
sendSelfDisguise(player, disguise);
}
});
return;
}
DisguisePushing pOption = DisguiseConfig.getPushingOption();
if (pOption != DisguisePushing.IGNORE_SCOREBOARD) {
// Code to stop player pushing
Scoreboard scoreboard = player.getScoreboard();
Team prevTeam = null;
Team ldTeam = null;
String ldTeamName = "LD Pushing";
for (Team t : scoreboard.getTeams()) {
if (!t.hasEntry(player.getName()))
continue;
prevTeam = t;
break;
}
// If the player is in a team already and the team isn't one controlled by Lib's Disguises
if (prevTeam != null &&
!(prevTeam.getName().equals("LD Pushing") || prevTeam.getName().endsWith("_LDP"))) {
// If we're creating a scoreboard
if (pOption == DisguisePushing.CREATE_SCOREBOARD) {
// Remember his old team so we can give him it back later
preDisguiseTeam.put(player.getUniqueId(), prevTeam.getName());
} else {
// We're modifying the scoreboard
ldTeam = prevTeam;
}
} else {
prevTeam = null;
}
// If we are creating a new scoreboard because the current one must not be modified
if (pOption == DisguisePushing.CREATE_SCOREBOARD) {
// If they have a team, we'll reuse that name. Otherwise go for another name
ldTeamName = (prevTeam == null ? "No Team" : prevTeam.getName());
// Give the teamname a custom name
ldTeamName = ldTeamName.substring(0, Math.min(12, ldTeamName.length())) + "_LDP";
}
if (ldTeam == null && (ldTeam = scoreboard.getTeam(ldTeamName)) == null) {
ldTeam = scoreboard.registerNewTeam(ldTeamName);
}
if (!ldTeam.hasEntry(player.getName()))
ldTeam.addEntry(player.getName());
if (pOption == DisguisePushing.CREATE_SCOREBOARD && prevTeam != null) {
ldTeam.setAllowFriendlyFire(prevTeam.allowFriendlyFire());
ldTeam.setCanSeeFriendlyInvisibles(prevTeam.canSeeFriendlyInvisibles());
ldTeam.setDisplayName(prevTeam.getDisplayName());
ldTeam.setPrefix(prevTeam.getPrefix());
ldTeam.setSuffix(prevTeam.getSuffix());
for (Option option : Team.Option.values()) {
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);
}
}
setupSelfDisguiseScoreboard(player);
// Add himself to his own entity tracker
Object trackedPlayersObj = ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers")
@ -1510,12 +1511,8 @@ public class DisguiseUtilities {
return Strings.isEmpty(player.getPlayerListName()) ? player.getName() : player.getPlayerListName();
}
public static LibsDisguises getPlugin() {
return libsDisguises;
}
public static Logger getLogger() {
return getPlugin().getLogger();
return LibsDisguises.getInstance().getLogger();
}
/**
@ -1559,7 +1556,7 @@ public class DisguiseUtilities {
Entity e = disguise.getEntity();
// If the disguises entity is null, or the disguised entity isn't a player return
if (e == null || !(e instanceof Player) || !getDisguises().containsKey(e.getUniqueId()) ||
if (!(e instanceof Player) || !getDisguises().containsKey(e.getUniqueId()) ||
!getDisguises().get(e.getUniqueId()).contains(disguise)) {
return;
}