Added savePreferences and config option for it, added command to view notify bar, cleaned up code, action bar and custom names now support hex colors, uses a better hex color system conversion

This commit is contained in:
libraryaddict 2020-07-03 17:08:58 +12:00
parent 13fedc4437
commit 3ced8ae9e4
11 changed files with 392 additions and 130 deletions

@ -442,8 +442,22 @@ public class DisguiseAPI {
return hasSelfDisguisePreference(entity) != DisguiseConfig.isViewDisguises(); return hasSelfDisguisePreference(entity) != DisguiseConfig.isViewDisguises();
} }
/**
* Returns true if the entitiy has /disguiseviewself toggled on.
*
* @param entity
* @return
*/
public static boolean isViewBarToggled(Player entity) {
return hasViewBarPreference(entity) == (DisguiseConfig.getNotifyBar() != DisguiseConfig.NotifyBar.NONE);
}
public static boolean hasSelfDisguisePreference(Entity entity) { public static boolean hasSelfDisguisePreference(Entity entity) {
return Disguise.getViewSelf().contains(entity.getUniqueId()); return DisguiseUtilities.getViewSelf().contains(entity.getUniqueId());
}
public static boolean hasViewBarPreference(Entity entity) {
return DisguiseUtilities.getViewSelf().contains(entity.getUniqueId());
} }
/** /**
@ -478,10 +492,32 @@ public class DisguiseAPI {
if (!canSeeSelfDisguises == DisguiseConfig.isViewDisguises()) { if (!canSeeSelfDisguises == DisguiseConfig.isViewDisguises()) {
if (!hasSelfDisguisePreference(entity)) { if (!hasSelfDisguisePreference(entity)) {
Disguise.getViewSelf().add(entity.getUniqueId()); DisguiseUtilities.getViewSelf().add(entity.getUniqueId());
DisguiseUtilities.addSaveAttempt();
} }
} else { } else {
Disguise.getViewSelf().remove(entity.getUniqueId()); DisguiseUtilities.getViewSelf().remove(entity.getUniqueId());
DisguiseUtilities.addSaveAttempt();
}
}
public static void setViewBarToggled(Player player, boolean canSeeNotifyBar) {
if (isDisguised(player)) {
Disguise[] disguises = getDisguises(player);
for (Disguise disguise : disguises) {
disguise.setNotifyBar(canSeeNotifyBar ? DisguiseConfig.getNotifyBar() : DisguiseConfig.NotifyBar.NONE);
}
}
if (canSeeNotifyBar == (DisguiseConfig.getNotifyBar() != DisguiseConfig.NotifyBar.NONE)) {
if (!hasSelfDisguisePreference(player)) {
DisguiseUtilities.getViewBar().add(player.getUniqueId());
DisguiseUtilities.addSaveAttempt();
}
} else {
DisguiseUtilities.getViewBar().remove(player.getUniqueId());
DisguiseUtilities.addSaveAttempt();
} }
} }

@ -250,6 +250,9 @@ public class DisguiseConfig {
@Getter @Getter
@Setter @Setter
private static boolean loginPayloadPackets; private static boolean loginPayloadPackets;
@Getter
@Setter
private static boolean saveUserPreferences;
public static boolean isArmorstandsName() { public static boolean isArmorstandsName() {
return getPlayerNameType() == PlayerNameType.ARMORSTANDS; return getPlayerNameType() == PlayerNameType.ARMORSTANDS;
@ -668,6 +671,7 @@ public class DisguiseConfig {
setTallSelfDisguises(config.getBoolean("TallSelfDisguises")); setTallSelfDisguises(config.getBoolean("TallSelfDisguises"));
setOverrideCustomNames(config.getBoolean("OverrideCustomNames")); setOverrideCustomNames(config.getBoolean("OverrideCustomNames"));
setRandomDisguises(config.getBoolean("RandomDisguiseOptions")); setRandomDisguises(config.getBoolean("RandomDisguiseOptions"));
setSaveUserPreferences(config.getBoolean("SaveUserPreferences"));
if (!LibsPremium.isPremium() && (isSavePlayerDisguises() || isSaveEntityDisguises())) { if (!LibsPremium.isPremium() && (isSavePlayerDisguises() || isSaveEntityDisguises())) {
DisguiseUtilities.getLogger().warning("You must purchase the plugin to use saved disguises!"); DisguiseUtilities.getLogger().warning("You must purchase the plugin to use saved disguises!");

@ -178,6 +178,7 @@ public class LibsDisguises extends JavaPlugin {
registerCommand("disguisehelp", new DisguiseHelpCommand()); registerCommand("disguisehelp", new DisguiseHelpCommand());
registerCommand("disguiseclone", new DisguiseCloneCommand()); registerCommand("disguiseclone", new DisguiseCloneCommand());
registerCommand("disguiseviewself", new DisguiseViewSelfCommand()); registerCommand("disguiseviewself", new DisguiseViewSelfCommand());
registerCommand("disguiseviewbar", new DisguiseViewBarCommand());
registerCommand("disguisemodify", new DisguiseModifyCommand()); registerCommand("disguisemodify", new DisguiseModifyCommand());
registerCommand("disguisemodifyentity", new DisguiseModifyEntityCommand()); registerCommand("disguisemodifyentity", new DisguiseModifyEntityCommand());
registerCommand("disguisemodifyplayer", new DisguiseModifyPlayerCommand()); registerCommand("disguisemodifyplayer", new DisguiseModifyPlayerCommand());

@ -0,0 +1,34 @@
package me.libraryaddict.disguise.commands.utils;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
* Created by libraryaddict on 2/07/2020.
*/
public class DisguiseViewBarCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) {
DisguiseUtilities.sendMessage(sender, LibsMsg.NO_CONSOLE);
return true;
}
Player player = (Player) sender;
if (DisguiseAPI.isViewBarToggled(player)) {
DisguiseAPI.setViewBarToggled(player, false);
DisguiseUtilities.sendMessage(sender, LibsMsg.VIEW_BAR_OFF);
} else {
DisguiseAPI.setViewBarToggled(player, true);
DisguiseUtilities.sendMessage(sender, LibsMsg.VIEW_BAR_ON);
}
return true;
}
}

@ -28,7 +28,6 @@ import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg; import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.ComponentBuilder;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
@ -45,17 +44,6 @@ import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
public abstract class Disguise { public abstract class Disguise {
private static List<UUID> viewSelf = new ArrayList<>();
/**
* Returns the list of people who have /disguiseViewSelf toggled on
*
* @return
*/
public static List<UUID> getViewSelf() {
return viewSelf;
}
private transient boolean disguiseInUse; private transient boolean disguiseInUse;
private DisguiseType disguiseType; private DisguiseType disguiseType;
private transient BukkitRunnable runnable; private transient BukkitRunnable runnable;
@ -358,8 +346,8 @@ public abstract class Disguise {
if (getNotifyBar() == DisguiseConfig.NotifyBar.ACTION_BAR && getEntity() instanceof Player && if (getNotifyBar() == DisguiseConfig.NotifyBar.ACTION_BAR && getEntity() instanceof Player &&
!getEntity().hasPermission("libsdisguises.noactionbar") && !getEntity().hasPermission("libsdisguises.noactionbar") &&
DisguiseAPI.getDisguise(getEntity()) == Disguise.this) { DisguiseAPI.getDisguise(getEntity()) == Disguise.this) {
((Player) getEntity()).spigot().sendMessage(ChatMessageType.ACTION_BAR, ((Player) getEntity()).spigot()
new ComponentBuilder(LibsMsg.ACTION_BAR_MESSAGE.get(getDisguiseName())).create()); .sendMessage(ChatMessageType.ACTION_BAR, LibsMsg.ACTION_BAR_MESSAGE.getChat(getDisguiseName()));
} }
if (isDynamicName()) { if (isDynamicName()) {

@ -21,7 +21,7 @@ import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.chat.ComponentSerializer;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
@ -373,7 +373,7 @@ public class FlagWatcher {
if (optional.isPresent()) { if (optional.isPresent()) {
BaseComponent[] base = ComponentConverter.fromWrapper(optional.get()); BaseComponent[] base = ComponentConverter.fromWrapper(optional.get());
return TextComponent.toLegacyText(base); return DisguiseUtilities.getSimpleChat(base);
} }
return null; return null;
@ -416,7 +416,8 @@ public class FlagWatcher {
} }
if (NmsVersion.v1_13.isSupported()) { if (NmsVersion.v1_13.isSupported()) {
setData(MetaIndex.ENTITY_CUSTOM_NAME, Optional.of(WrappedChatComponent.fromText(name))); setData(MetaIndex.ENTITY_CUSTOM_NAME, Optional.of(WrappedChatComponent
.fromJson(ComponentSerializer.toString(DisguiseUtilities.getColoredChat(name)))));
} else { } else {
setData(MetaIndex.ENTITY_CUSTOM_NAME_OLD, name); setData(MetaIndex.ENTITY_CUSTOM_NAME_OLD, name);
} }

@ -36,7 +36,9 @@ import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg; import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import me.libraryaddict.disguise.utilities.watchers.CompileMethods; import me.libraryaddict.disguise.utilities.watchers.CompileMethods;
import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.chat.ComponentSerializer;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.RandomUtils; import org.apache.commons.lang.math.RandomUtils;
import org.apache.logging.log4j.util.Strings; import org.apache.logging.log4j.util.Strings;
@ -58,7 +60,10 @@ import org.bukkit.util.Vector;
import java.io.*; import java.io.*;
import java.lang.reflect.*; import java.lang.reflect.*;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -111,29 +116,29 @@ public class DisguiseUtilities {
@Getter @Getter
public static final Random random = new Random(); public static final Random random = new Random();
private static LinkedHashMap<String, Disguise> clonedDisguises = new LinkedHashMap<>(); private static final LinkedHashMap<String, Disguise> clonedDisguises = new LinkedHashMap<>();
private static final List<Integer> isNoInteract = new ArrayList<>(); private static final List<Integer> isNoInteract = new ArrayList<>();
/** /**
* A hashmap of the uuid's of entitys, alive and dead. And their disguises in use * A hashmap of the uuid's of entitys, alive and dead. And their disguises in use
*/ */
@Getter @Getter
private static Map<UUID, Set<TargetedDisguise>> disguises = new HashMap<>(); private static final Map<UUID, Set<TargetedDisguise>> disguises = new HashMap<>();
/** /**
* Disguises which are stored ready for a entity to be seen by a player Preferably, disguises in this should only * Disguises which are stored ready for a entity to be seen by a player Preferably, disguises in this should only
* stay in for * stay in for
* a max of a second. * a max of a second.
*/ */
@Getter @Getter
private static HashMap<Integer, HashSet<TargetedDisguise>> futureDisguises = new HashMap<>(); private static final HashMap<Integer, HashSet<TargetedDisguise>> futureDisguises = new HashMap<>();
private static HashSet<UUID> savedDisguiseList = new HashSet<>(); private static final HashSet<UUID> savedDisguiseList = new HashSet<>();
private static HashSet<String> cachedNames = new HashSet<>(); private static final HashSet<String> cachedNames = new HashSet<>();
private static final HashMap<String, ArrayList<Object>> runnables = new HashMap<>(); private static final HashMap<String, ArrayList<Object>> runnables = new HashMap<>();
@Getter @Getter
private static HashSet<UUID> selfDisguised = new HashSet<>(); private static final HashSet<UUID> selfDisguised = new HashSet<>();
private static HashMap<UUID, String> preDisguiseTeam = new HashMap<>(); private static final HashMap<UUID, String> preDisguiseTeam = new HashMap<>();
private static HashMap<UUID, String> disguiseTeam = new HashMap<>(); private static final HashMap<UUID, String> disguiseTeam = new HashMap<>();
private static File profileCache = new File("plugins/LibsDisguises/GameProfiles"), savedDisguises = new File( private static final File profileCache = new File("plugins/LibsDisguises/GameProfiles");
"plugins/LibsDisguises/SavedDisguises"); private static final File savedDisguises = new File("plugins/LibsDisguises/SavedDisguises");
@Getter @Getter
private static Gson gson; private static Gson gson;
@Getter @Getter
@ -145,16 +150,104 @@ public class DisguiseUtilities {
*/ */
private static long velocityTime; private static long velocityTime;
private static int velocityID; private static int velocityID;
private static HashMap<UUID, ArrayList<Integer>> disguiseLoading = new HashMap<>(); private static final HashMap<UUID, ArrayList<Integer>> disguiseLoading = new HashMap<>();
@Getter @Getter
private static boolean runningPaper; private static boolean runningPaper;
@Getter @Getter
private static MineSkinAPI mineSkinAPI = new MineSkinAPI(); private static final MineSkinAPI mineSkinAPI = new MineSkinAPI();
@Getter @Getter
private static boolean invalidFile; private static boolean invalidFile;
@Getter @Getter
private static char[] alphabet = "0123456789abcdefghijklmnopqrstuvwxyz".toCharArray(); private static final char[] alphabet = "0123456789abcdefghijklmnopqrstuvwxyz".toCharArray();
private static Pattern hexColor; private static final Pattern urlMatcher = Pattern.compile("^(?:(https?)://)?([-\\w_.]{2,}\\.[a-z]{2,4})(/\\S*)?$");
private final static List<UUID> viewSelf = new ArrayList<>();
private final static List<UUID> viewBar = new ArrayList<>();
private static long lastSavedPreferences;
/**
* Only allow saves every 2 minutes
*/
public static void addSaveAttempt() {
if (lastSavedPreferences + TimeUnit.SECONDS.toMillis(120) > System.currentTimeMillis()) {
return;
}
lastSavedPreferences = System.currentTimeMillis();
new BukkitRunnable() {
@Override
public void run() {
saveViewPreferances();
}
}.runTaskLater(LibsDisguises.getInstance(), 20 * TimeUnit.SECONDS.toMillis(120));
}
/**
* Returns the list of people who have /disguiseViewSelf toggled
*
* @return
*/
public static List<UUID> getViewSelf() {
return viewSelf;
}
public static void saveViewPreferances() {
if (!DisguiseConfig.isSaveUserPreferences()) {
return;
}
File viewPreferences = new File(LibsDisguises.getInstance().getDataFolder(), "preferences.json");
HashMap<String, List<UUID>> map = new HashMap<>();
map.put("selfdisguise", getViewSelf());
map.put("notifybar", getViewBar());
String json = getGson().toJson(map);
try {
Files.write(viewPreferences.toPath(), json.getBytes(), StandardOpenOption.CREATE);
}
catch (IOException e) {
e.printStackTrace();
}
}
public static void loadViewPreferences() {
File viewPreferences = new File(LibsDisguises.getInstance().getDataFolder(), "preferences.json");
if (!viewPreferences.exists()) {
return;
}
HashMap<String, Collection<String>> map;
try {
String disguiseText = new String(Files.readAllBytes(viewPreferences.toPath()));
map = getGson().fromJson(disguiseText, HashMap.class);
if (map.containsKey("selfdisguise")) {
getViewSelf().clear();
map.get("selfdisguise").forEach(uuid -> getViewSelf().add(UUID.fromString(uuid)));
}
if (map.containsKey("notifybar")) {
getViewBar().clear();
map.get("notifybar").forEach(uuid -> getViewBar().add(UUID.fromString(uuid)));
}
}
catch (IOException e) {
e.printStackTrace();
}
}
/**
* Returns the list of people who have /disguiseviewbar toggled
*
* @return
*/
public static List<UUID> getViewBar() {
return viewBar;
}
public static void setPlayerVelocity(Player player) { public static void setPlayerVelocity(Player player) {
if (player == null) { if (player == null) {
@ -231,6 +324,8 @@ public class DisguiseUtilities {
} }
public static void saveDisguises() { public static void saveDisguises() {
saveViewPreferances();
if (!LibsPremium.isPremium()) if (!LibsPremium.isPremium())
return; return;
@ -308,8 +403,6 @@ public class DisguiseUtilities {
if (disguise == null || disguise.length == 0) { if (disguise == null || disguise.length == 0) {
if (savedDisguiseList.contains(owningEntity)) { if (savedDisguiseList.contains(owningEntity)) {
disguiseFile.delete(); disguiseFile.delete();
} else {
return;
} }
} else { } else {
Disguise[] disguises = new Disguise[disguise.length]; Disguise[] disguises = new Disguise[disguise.length];
@ -356,7 +449,7 @@ public class DisguiseUtilities {
} }
try { try {
String cached = null; String cached;
try (FileInputStream input = new FileInputStream( try (FileInputStream input = new FileInputStream(
disguiseFile); InputStreamReader inputReader = new InputStreamReader(input, disguiseFile); InputStreamReader inputReader = new InputStreamReader(input,
@ -829,10 +922,7 @@ public class DisguiseUtilities {
public static WrappedGameProfile getProfileFromMojang(final PlayerDisguise disguise) { public static WrappedGameProfile getProfileFromMojang(final PlayerDisguise disguise) {
final String nameToFetch = disguise.getSkin() != null ? disguise.getSkin() : disguise.getName(); final String nameToFetch = disguise.getSkin() != null ? disguise.getSkin() : disguise.getName();
return getProfileFromMojang(nameToFetch, new LibsProfileLookup() { return getProfileFromMojang(nameToFetch, gameProfile -> {
@Override
public void onLookup(WrappedGameProfile gameProfile) {
if (gameProfile == null || gameProfile.getProperties().isEmpty()) { if (gameProfile == null || gameProfile.getProperties().isEmpty()) {
return; return;
} }
@ -844,7 +934,6 @@ public class DisguiseUtilities {
DisguiseUtilities.refreshTrackers(disguise); DisguiseUtilities.refreshTrackers(disguise);
} }
}
}, LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true)); }, LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true));
} }
@ -902,15 +991,11 @@ public class DisguiseUtilities {
runnables.get(playerName).add(runnable); runnables.get(playerName).add(runnable);
} }
Bukkit.getScheduler().runTaskAsynchronously(LibsDisguises.getInstance(), new Runnable() { Bukkit.getScheduler().runTaskAsynchronously(LibsDisguises.getInstance(), () -> {
@Override
public void run() {
try { try {
final WrappedGameProfile gameProfile = lookupGameProfile(origName); final WrappedGameProfile gameProfile = lookupGameProfile(origName);
Bukkit.getScheduler().runTask(LibsDisguises.getInstance(), new Runnable() { Bukkit.getScheduler().runTask(LibsDisguises.getInstance(), () -> {
@Override
public void run() {
if (DisguiseConfig.isSaveGameProfiles()) { if (DisguiseConfig.isSaveGameProfiles()) {
addGameProfile(playerName, gameProfile); addGameProfile(playerName, gameProfile);
} }
@ -926,7 +1011,6 @@ public class DisguiseUtilities {
} }
} }
} }
}
}); });
} }
catch (Exception e) { catch (Exception e) {
@ -937,7 +1021,6 @@ public class DisguiseUtilities {
getLogger().severe("Error when fetching " + playerName + "'s uuid from mojang: " + getLogger().severe("Error when fetching " + playerName + "'s uuid from mojang: " +
e.getMessage()); e.getMessage());
} }
}
}); });
} else if (runnable != null && contactMojang) { } else if (runnable != null && contactMojang) {
runnables.get(playerName).add(runnable); runnables.get(playerName).add(runnable);
@ -978,11 +1061,7 @@ public class DisguiseUtilities {
// Don't really need this here, but it's insurance! // Don't really need this here, but it's insurance!
runningPaper = Class.forName("com.destroystokyo.paper.VersionHistoryManager$VersionData") != null; runningPaper = Class.forName("com.destroystokyo.paper.VersionHistoryManager$VersionData") != null;
} }
catch (Exception ex) { catch (Exception ignored) {
}
if (NmsVersion.v1_16.isSupported()) {
hexColor = Pattern.compile("<#[0-9a-fA-F]{6}>");
} }
GsonBuilder gsonBuilder = new GsonBuilder(); GsonBuilder gsonBuilder = new GsonBuilder();
@ -1049,7 +1128,7 @@ public class DisguiseUtilities {
bar.removeAll(); bar.removeAll();
Bukkit.removeBossBar(bar.getKey()); Bukkit.removeBossBar(bar.getKey());
} }
catch (IllegalArgumentException ex) { catch (IllegalArgumentException ignored) {
} }
} }
} }
@ -1071,6 +1150,8 @@ public class DisguiseUtilities {
catch (NoSuchMethodException e) { catch (NoSuchMethodException e) {
e.printStackTrace(); e.printStackTrace();
} }
loadViewPreferences();
} }
public static boolean isDisguiseInUse(Disguise disguise) { public static boolean isDisguiseInUse(Disguise disguise) {
@ -2077,7 +2158,7 @@ public class DisguiseUtilities {
public static int[] getNumericVersion(String version) { public static int[] getNumericVersion(String version) {
int[] v = new int[0]; int[] v = new int[0];
for (String split : version.split("\\.|-")) { for (String split : version.split("[.\\-]")) {
if (!split.matches("[0-9]+")) { if (!split.matches("[0-9]+")) {
return v; return v;
} }
@ -2089,31 +2170,151 @@ public class DisguiseUtilities {
return v; return v;
} }
public static BaseComponent[] getColoredChat(String string) { public static String getSimpleChat(BaseComponent[] components) {
if (hexColor == null) { StringBuilder builder = new StringBuilder();
return new ComponentBuilder().appendLegacy(string).create();
for (BaseComponent component : components) {
net.md_5.bungee.api.ChatColor color = component.getColor();
String string = color.toString();
if (string.length() > 2) {
builder.append("<#")
.append(string.substring(2).replace(net.md_5.bungee.api.ChatColor.COLOR_CHAR + "", ""))
.append(">");
} else {
builder.append(string);
} }
Matcher match = hexColor.matcher(string); if (component.isBold()) {
builder.append(net.md_5.bungee.api.ChatColor.BOLD);
ComponentBuilder builder = new ComponentBuilder();
int lastMatch = 0;
while (match.find()) {
if (match.start() > lastMatch) {
builder.appendLegacy(string.substring(lastMatch, match.start()));
} }
lastMatch = match.end(); if (component.isItalic()) {
builder.append(net.md_5.bungee.api.ChatColor.ITALIC);
builder.color(net.md_5.bungee.api.ChatColor.of(match.group().substring(1, 8)));
} }
if (lastMatch < string.length()) { if (component.isUnderlined()) {
builder.appendLegacy(string.substring(lastMatch)); builder.append(net.md_5.bungee.api.ChatColor.UNDERLINE);
} }
return builder.create(); if (component.isStrikethrough()) {
builder.append(net.md_5.bungee.api.ChatColor.STRIKETHROUGH);
}
if (component.isObfuscated()) {
builder.append(net.md_5.bungee.api.ChatColor.MAGIC);
}
if (!(component instanceof TextComponent)) {
continue;
}
builder.append(((TextComponent) component).getText());
}
return builder.toString();
}
/**
* Modification of TextComponent.fromLegacyText
*/
public static BaseComponent[] getColoredChat(String message) {
ArrayList<BaseComponent> components = new ArrayList();
StringBuilder builder = new StringBuilder();
TextComponent component = new TextComponent();
Matcher matcher = urlMatcher.matcher(message);
for (int i = 0; i < message.length(); ++i) {
char c = message.charAt(i);
TextComponent old;
if (c == ChatColor.COLOR_CHAR || (c == '<' && i + 9 < message.length() && NmsVersion.v1_16.isSupported() &&
Pattern.matches("<#[0-9a-fA-F]{6}>", message.substring(i, i + 9)))) {
// If normal color char
if (c == ChatColor.COLOR_CHAR) {
++i;
if (i >= message.length()) {
break;
}
}
net.md_5.bungee.api.ChatColor format;
if (c != ChatColor.COLOR_CHAR) {
format = net.md_5.bungee.api.ChatColor.of(message.substring(i + 1, i + 8));
i += 8;
} else {
c = message.charAt(i);
if (c >= 'A' && c <= 'Z') {
c = (char) (c + 32);
}
format = net.md_5.bungee.api.ChatColor.getByChar(c);
}
if (format != null) {
if (builder.length() > 0) {
old = component;
component = new TextComponent(component);
old.setText(builder.toString());
builder = new StringBuilder();
components.add(old);
}
if (format == net.md_5.bungee.api.ChatColor.BOLD) {
component.setBold(true);
} else if (format == net.md_5.bungee.api.ChatColor.ITALIC) {
component.setItalic(true);
} else if (format == net.md_5.bungee.api.ChatColor.UNDERLINE) {
component.setUnderlined(true);
} else if (format == net.md_5.bungee.api.ChatColor.STRIKETHROUGH) {
component.setStrikethrough(true);
} else if (format == net.md_5.bungee.api.ChatColor.MAGIC) {
component.setObfuscated(true);
} else if (format == net.md_5.bungee.api.ChatColor.RESET) {
component = new TextComponent();
component.setColor(net.md_5.bungee.api.ChatColor.WHITE);
} else {
component = new TextComponent();
component.setColor(format);
}
}
} else {
int pos = message.indexOf(32, i);
if (pos == -1) {
pos = message.length();
}
if (matcher.region(i, pos).find()) {
if (builder.length() > 0) {
old = component;
component = new TextComponent(component);
old.setText(builder.toString());
builder = new StringBuilder();
components.add(old);
}
old = component;
component = new TextComponent(component);
String urlString = message.substring(i, pos);
component.setText(urlString);
component.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL,
urlString.startsWith("http") ? urlString : "http://" + urlString));
components.add(component);
i += pos - i - 1;
component = old;
} else {
builder.append(c);
}
}
}
component.setText(builder.toString());
components.add(component);
return components.toArray(new BaseComponent[components.size()]);
} }
public static boolean isOlderThan(String requiredVersion, String theirVersion) { public static boolean isOlderThan(String requiredVersion, String theirVersion) {
@ -2367,12 +2568,11 @@ public class DisguiseUtilities {
return (byte) -value; return (byte) -value;
} }
switch (disguiseType) { if (disguiseType == DisguiseType.PHANTOM) {
case PHANTOM:
return (byte) -value; return (byte) -value;
default:
return value;
} }
return value;
} }
public static byte getYaw(DisguiseType disguiseType, EntityType entityType, byte value) { public static byte getYaw(DisguiseType disguiseType, EntityType entityType, byte value) {
@ -2441,7 +2641,8 @@ public class DisguiseUtilities {
Object name; Object name;
if (NmsVersion.v1_13.isSupported()) { if (NmsVersion.v1_13.isSupported()) {
name = Optional.of(WrappedChatComponent.fromText(newNames[i])); name = Optional.of(WrappedChatComponent
.fromJson(ComponentSerializer.toString(DisguiseUtilities.getColoredChat(newNames[i]))));
} else { } else {
name = newNames[i]; name = newNames[i];
} }

@ -208,6 +208,8 @@ public enum LibsMsg {
" to download the update!"), " to download the update!"),
VIEW_SELF_ON(ChatColor.GREEN + "Toggled viewing own disguise on!"), VIEW_SELF_ON(ChatColor.GREEN + "Toggled viewing own disguise on!"),
VIEW_SELF_OFF(ChatColor.GREEN + "Toggled viewing own disguise off!"), VIEW_SELF_OFF(ChatColor.GREEN + "Toggled viewing own disguise off!"),
VIEW_BAR_ON(ChatColor.GREEN + "Toggled disguised notify bar on!"),
VIEW_BAR_OFF(ChatColor.GREEN + "Toggled disguised notify bar off!"),
CLICK_TO_COPY(ChatColor.GREEN + "Click to Copy:"), CLICK_TO_COPY(ChatColor.GREEN + "Click to Copy:"),
SKIN_DATA(ChatColor.GREEN + "Skin Data: " + ChatColor.YELLOW + "%s"), SKIN_DATA(ChatColor.GREEN + "Skin Data: " + ChatColor.YELLOW + "%s"),
CLICK_TO_COPY_DATA(ChatColor.YELLOW + "Data"), CLICK_TO_COPY_DATA(ChatColor.YELLOW + "Data"),

@ -96,10 +96,12 @@ public class LDGithub {
for (String s : users) { for (String s : users) {
if (LibsPremium.getPaidInformation() != null && if (LibsPremium.getPaidInformation() != null &&
LibsPremium.getPaidInformation().getUserID().equals(s)) { (s.equals(LibsPremium.getPaidInformation().getDownloadID()) ||
s.equals(LibsPremium.getPaidInformation().getUserID()))) {
LibsDisguises.getInstance().unregisterCommands(true); LibsDisguises.getInstance().unregisterCommands(true);
} else { } else {
if (LibsPremium.getUserID() == null || !LibsPremium.getUserID().equals(s)) { if (LibsPremium.getUserID() == null ||
(!s.equals(LibsPremium.getUserID()) && !s.equals(LibsPremium.getDownloadID()))) {
continue; continue;
} }

@ -156,6 +156,10 @@ BossBarColor: GREEN
# https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/boss/BarStyle.html # https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/boss/BarStyle.html
BossBarStyle: SOLID BossBarStyle: SOLID
# By the default the plugin saves the users of the /viewdisguisebar and /viewselfdisguises to a file
# So that it persists after restart
SaveUserPreferences: true
# Shall I send the velocity packets? I REALLY recommend you don't disable. # 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. # This is the only thing allowing the mobs to fly without glitching out.
SendVelocity: true SendVelocity: true

@ -56,6 +56,11 @@ commands:
aliases: [dviewself, dvs, disguisevs, disvs, vsd, viewselfdisguise, viewselfd, selfdisguise, selfdisg, selfd] aliases: [dviewself, dvs, disguisevs, disvs, vsd, viewselfdisguise, viewselfd, selfdisguise, selfdisg, selfd]
permission: libsdisguises.seecmd.viewself permission: libsdisguises.seecmd.viewself
description: Toggle seeing your own disguise on or off. description: Toggle seeing your own disguise on or off.
disguiseviewbar:
aliases: [dviewbar, dvb, disguisevb, disvb, vsd, viewdisguisebar, viewbardisguise, bardisguise, bardisg, bard,
notifybar, viewnotifybar, disguisenotifybar, disgnotifybar, dnotifybar]
permission: libsdisguises.seecmd.viewself
description: Toggle seeing your own disguise on or off.
disguisemodify: disguisemodify:
aliases: [dmodify, dmod, disgmodify] aliases: [dmodify, dmod, disgmodify]
permission: libsdisguises.seecmd.disguisemodify permission: libsdisguises.seecmd.disguisemodify
@ -144,6 +149,7 @@ permissions:
libsdisguises.seecmd.undisguiseradius: true libsdisguises.seecmd.undisguiseradius: true
libsdisguises.seecmd.disguiseclone: true libsdisguises.seecmd.disguiseclone: true
libsdisguises.seecmd.disguiseviewself: true libsdisguises.seecmd.disguiseviewself: true
libsdisguises.seecmd.disguiseviewbar: true
libsdisguises.seecmd.disguisemodify: true libsdisguises.seecmd.disguisemodify: true
libsdisguises.seecmd.disguisemodifyplayer: true libsdisguises.seecmd.disguisemodifyplayer: true
libsdisguises.seecmd.disguisemodifyradius: true libsdisguises.seecmd.disguisemodifyradius: true
@ -154,58 +160,41 @@ permissions:
libsdisguises.seecmd.grabhead: true libsdisguises.seecmd.grabhead: true
libsdisguises.seecmd.disguiseviewself: libsdisguises.seecmd.disguiseviewself:
description: See the /disguiseviewself command in tab-completion description: See the /disguiseviewself command in tab-completion
default: true libsdisguises.seecmd.disguiseviewbar:
description: See the /disguiseviewbar command in tab-completion
libsdisguises.seecmd.disguise: libsdisguises.seecmd.disguise:
description: See the /disguise command in tab-completion description: See the /disguise command in tab-completion
default: true
libsdisguises.seecmd.disguiseentity: libsdisguises.seecmd.disguiseentity:
description: See the /disguiseentity command in tab-completion description: See the /disguiseentity command in tab-completion
default: true
libsdisguises.seecmd.disguisehelp: libsdisguises.seecmd.disguisehelp:
description: See the /disguisehelp command in tab-completion description: See the /disguisehelp command in tab-completion
default: true
libsdisguises.seecmd.disguiseplayer: libsdisguises.seecmd.disguiseplayer:
description: See the /disguiseplayer command in tab-completion description: See the /disguiseplayer command in tab-completion
default: true
libsdisguises.seecmd.disguiseradius: libsdisguises.seecmd.disguiseradius:
description: See the /disguiseradius command in tab-completion description: See the /disguiseradius command in tab-completion
default: true
libsdisguises.seecmd.undisguise: libsdisguises.seecmd.undisguise:
description: See the /undisguise command in tab-completion description: See the /undisguise command in tab-completion
default: true
libsdisguises.seecmd.undisguiseentity: libsdisguises.seecmd.undisguiseentity:
description: See the /undisguiseentity command in tab-completion description: See the /undisguiseentity command in tab-completion
default: true
libsdisguises.seecmd.undisguiseplayer: libsdisguises.seecmd.undisguiseplayer:
description: See the /undisguiseplayer command in tab-completion description: See the /undisguiseplayer command in tab-completion
default: true
libsdisguises.seecmd.undisguiseradius: libsdisguises.seecmd.undisguiseradius:
description: See the /undisguiseradius command in tab-completion description: See the /undisguiseradius command in tab-completion
default: true
libsdisguises.seecmd.disguiseclone: libsdisguises.seecmd.disguiseclone:
description: See the /disguiseclone command in tab-completion description: See the /disguiseclone command in tab-completion
default: true
libsdisguises.seecmd.disguisemodify: libsdisguises.seecmd.disguisemodify:
description: See the /disguisemodify command in tab-completion description: See the /disguisemodify command in tab-completion
default: true
libsdisguises.seecmd.disguisemodifyplayer: libsdisguises.seecmd.disguisemodifyplayer:
description: See the /disguisemodifyplayer command in tab-completion description: See the /disguisemodifyplayer command in tab-completion
default: true
libsdisguises.seecmd.disguisemodifyradius: libsdisguises.seecmd.disguisemodifyradius:
description: See the /disguisemodifyradius command in tab-completion description: See the /disguisemodifyradius command in tab-completion
default: true
libsdisguises.seecmd.disguisemodifyentity: libsdisguises.seecmd.disguisemodifyentity:
description: See the /disguisemodifyentity command in tab-completion description: See the /disguisemodifyentity command in tab-completion
default: true
libsdisguises.seecmd.copydisguise: libsdisguises.seecmd.copydisguise:
description: See the /copydisguise command in tab-completion description: See the /copydisguise command in tab-completion
default: true
libsdisguises.seecmd.grabskin: libsdisguises.seecmd.grabskin:
description: See the /grabskin command in tab-completion description: See the /grabskin command in tab-completion
default: true
libsdisguises.seecmd.savedisguise: libsdisguises.seecmd.savedisguise:
description: See the /savedisguise command in tab-completion description: See the /savedisguise command in tab-completion
default: true
libsdisguises.seecmd.grabhead: libsdisguises.seecmd.grabhead:
description: See the /grabhead command in tab-completion description: See the /grabhead command in tab-completion
default: true