Improve message sending

This commit is contained in:
libraryaddict 2020-07-03 17:36:29 +12:00
parent 3ced8ae9e4
commit e74df537bb
26 changed files with 109 additions and 97 deletions

View File

@ -45,7 +45,7 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter
} }
catch (DisguiseParseException ex) { catch (DisguiseParseException ex) {
if (ex.getMessage() != null) { if (ex.getMessage() != null) {
sender.sendMessage(ex.getMessage()); DisguiseUtilities.sendMessage(sender, ex.getMessage());
} }
return true; return true;

View File

@ -51,7 +51,7 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom
} }
catch (DisguiseParseException ex) { catch (DisguiseParseException ex) {
if (ex.getMessage() != null) { if (ex.getMessage() != null) {
sender.sendMessage(ex.getMessage()); DisguiseUtilities.sendMessage(sender, ex.getMessage());
} }
return true; return true;

View File

@ -61,7 +61,7 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom
} }
if (entityTarget == null) { if (entityTarget == null) {
sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[0])); DisguiseUtilities.sendMessage(sender, LibsMsg.CANNOT_FIND_PLAYER, args[0]);
return true; return true;
} }
@ -81,7 +81,7 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom
} }
catch (DisguiseParseException ex) { catch (DisguiseParseException ex) {
if (ex.getMessage() != null) { if (ex.getMessage() != null) {
sender.sendMessage(ex.getMessage()); DisguiseUtilities.sendMessage(sender, ex.getMessage());
} }
return true; return true;
} }
@ -119,12 +119,13 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom
disguise.startDisguise(); disguise.startDisguise();
if (disguise.isDisguiseInUse()) { if (disguise.isDisguiseInUse()) {
sender.sendMessage(LibsMsg.DISG_PLAYER_AS_DISG.get(entityTarget instanceof Player ? entityTarget.getName() : DisguiseUtilities.sendMessage(sender, LibsMsg.DISG_PLAYER_AS_DISG,
DisguiseType.getType(entityTarget).toReadable(), disguise.getDisguiseName())); entityTarget instanceof Player ? entityTarget.getName() :
DisguiseType.getType(entityTarget).toReadable(), disguise.getDisguiseName());
} else { } else {
sender.sendMessage(LibsMsg.DISG_PLAYER_AS_DISG_FAIL DisguiseUtilities.sendMessage(sender, LibsMsg.DISG_PLAYER_AS_DISG_FAIL,
.get(entityTarget instanceof Player ? entityTarget.getName() : entityTarget instanceof Player ? entityTarget.getName() :
DisguiseType.getType(entityTarget).toReadable(), disguise.getDisguiseName())); DisguiseType.getType(entityTarget).toReadable(), disguise.getDisguiseName());
} }
return true; return true;

View File

@ -78,8 +78,8 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
Collections.sort(classes); Collections.sort(classes);
sender.sendMessage(LibsMsg.DRADIUS_ENTITIES DisguiseUtilities.sendMessage(sender, LibsMsg.DRADIUS_ENTITIES,
.get(ChatColor.GREEN + StringUtils.join(classes, ChatColor.DARK_GREEN + ", " + ChatColor.GREEN))); ChatColor.GREEN + StringUtils.join(classes, ChatColor.DARK_GREEN + ", " + ChatColor.GREEN));
return true; return true;
} }
@ -104,15 +104,15 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
} }
if (type == null) { if (type == null) {
sender.sendMessage(LibsMsg.DMODRADIUS_UNRECOGNIZED.get(args[0])); DisguiseUtilities.sendMessage(sender, LibsMsg.DMODRADIUS_UNRECOGNIZED, args[0]);
return true; return true;
} }
} }
} }
if (args.length == starting + 1) { if (args.length == starting + 1) {
sender.sendMessage( DisguiseUtilities.sendMessage(sender,
(starting == 0 ? LibsMsg.DRADIUS_NEEDOPTIONS : LibsMsg.DRADIUS_NEEDOPTIONS_ENTITY).get()); starting == 0 ? LibsMsg.DRADIUS_NEEDOPTIONS : LibsMsg.DRADIUS_NEEDOPTIONS_ENTITY);
return true; return true;
} else if (args.length < 2) { } else if (args.length < 2) {
DisguiseUtilities.sendMessage(sender, LibsMsg.DRADIUS_NEEDOPTIONS); DisguiseUtilities.sendMessage(sender, LibsMsg.DRADIUS_NEEDOPTIONS);
@ -120,7 +120,7 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
} }
if (!isInteger(args[starting])) { if (!isInteger(args[starting])) {
sender.sendMessage(LibsMsg.NOT_NUMBER.get(args[starting])); DisguiseUtilities.sendMessage(sender, LibsMsg.NOT_NUMBER, args[starting]);
return true; return true;
} }
@ -213,7 +213,7 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
} }
catch (DisguiseParseException ex) { catch (DisguiseParseException ex) {
if (ex.getMessage() != null) { if (ex.getMessage() != null) {
sender.sendMessage(ex.getMessage()); DisguiseUtilities.sendMessage(sender, ex.getMessage());
} }
} }
catch (Exception ex) { catch (Exception ex) {

View File

@ -41,7 +41,7 @@ public class DisguiseEntityInteraction implements LibsEntityInteract {
} }
catch (DisguiseParseException e) { catch (DisguiseParseException e) {
if (e.getMessage() != null) { if (e.getMessage() != null) {
p.sendMessage(e.getMessage()); DisguiseUtilities.sendMessage(p, e.getMessage());
} }
return; return;

View File

@ -60,7 +60,7 @@ public class DisguiseModifyInteraction implements LibsEntityInteract {
} }
catch (DisguiseParseException ex) { catch (DisguiseParseException ex) {
if (ex.getMessage() != null) { if (ex.getMessage() != null) {
p.sendMessage(ex.getMessage()); DisguiseUtilities.sendMessage(p, ex.getMessage());
} }
} }
catch (Exception ex) { catch (Exception ex) {

View File

@ -3,6 +3,7 @@ package me.libraryaddict.disguise.commands.libsdisguises;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import me.libraryaddict.disguise.commands.LibsDisguisesCommand; import me.libraryaddict.disguise.commands.LibsDisguisesCommand;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.translations.LibsMsg; import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -39,7 +40,7 @@ public class LDHelp implements LDCommand {
continue; continue;
} }
sender.sendMessage(cmd.getHelp().get()); DisguiseUtilities.sendMessage(sender, cmd.getHelp());
} }
} }

View File

@ -88,7 +88,7 @@ public class LDJson implements LDCommand {
private void sendMessage(CommandSender sender, LibsMsg prefix, LibsMsg oldVer, String string) { private void sendMessage(CommandSender sender, LibsMsg prefix, LibsMsg oldVer, String string) {
if (!NmsVersion.v1_13.isSupported()) { if (!NmsVersion.v1_13.isSupported()) {
sender.sendMessage(oldVer.get(string)); DisguiseUtilities.sendMessage(sender, oldVer, string);
return; return;
} }

View File

@ -38,7 +38,7 @@ public class LDMods implements LDCommand {
player = Bukkit.getPlayer(args[1]); player = Bukkit.getPlayer(args[1]);
if (player == null) { if (player == null) {
sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[1])); DisguiseUtilities.sendMessage(sender, LibsMsg.CANNOT_FIND_PLAYER, args[1]);
return; return;
} }
} else if (sender instanceof Player) { } else if (sender instanceof Player) {

View File

@ -41,7 +41,7 @@ public class LDPermTest implements LDCommand {
player = Bukkit.getPlayer(args[1]); player = Bukkit.getPlayer(args[1]);
if (player == null) { if (player == null) {
sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[1])); DisguiseUtilities.sendMessage(sender, LibsMsg.CANNOT_FIND_PLAYER, args[1]);
return; return;
} }
} else { } else {
@ -80,9 +80,9 @@ public class LDPermTest implements LDCommand {
} }
if (!sender.hasPermission("libsdisguises.seecmd.disguise")) { if (!sender.hasPermission("libsdisguises.seecmd.disguise")) {
sender.sendMessage(LibsMsg.LIBS_PERM_COMMAND_FAIL.get("libsdisguises.seecmd.disguise")); DisguiseUtilities.sendMessage(sender, LibsMsg.LIBS_PERM_COMMAND_FAIL, "libsdisguises.seecmd.disguise");
} else { } else {
sender.sendMessage(LibsMsg.LIBS_PERM_COMMAND_SUCCESS.get("libsdisguises.seecmd.disguise")); DisguiseUtilities.sendMessage(sender, LibsMsg.LIBS_PERM_COMMAND_SUCCESS, "libsdisguises.seecmd.disguise");
} }
} }

View File

@ -129,7 +129,7 @@ public class LDScoreboard implements LDCommand {
player = Bukkit.getPlayer(args[1]); player = Bukkit.getPlayer(args[1]);
if (player == null) { if (player == null) {
sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[1])); DisguiseUtilities.sendMessage(sender, LibsMsg.CANNOT_FIND_PLAYER, args[1]);
return; return;
} }

View File

@ -95,10 +95,10 @@ public class LDUpdate implements LDCommand {
if (!forceUpdate) { if (!forceUpdate) {
if (updateResult != null) { if (updateResult != null) {
sender.sendMessage(updateResult.get()); DisguiseUtilities.sendMessage(sender, updateResult);
} else { } else {
for (String msg : checker.getUpdateMessage()) { for (String msg : checker.getUpdateMessage()) {
sender.sendMessage(msg); DisguiseUtilities.sendMessage(sender, msg);
} }
} }
@ -113,7 +113,7 @@ public class LDUpdate implements LDCommand {
} }
for (String msg : checker.getUpdateMessage()) { for (String msg : checker.getUpdateMessage()) {
sender.sendMessage(msg); DisguiseUtilities.sendMessage(sender, msg);
} }
if (sender instanceof Player) { if (sender instanceof Player) {

View File

@ -63,7 +63,7 @@ public class DisguiseModifyCommand extends DisguiseBaseCommand implements TabCom
} }
catch (DisguiseParseException ex) { catch (DisguiseParseException ex) {
if (ex.getMessage() != null) { if (ex.getMessage() != null) {
sender.sendMessage(ex.getMessage()); DisguiseUtilities.sendMessage(sender, ex.getMessage());
} }
return true; return true;

View File

@ -50,7 +50,7 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements
} }
if (entityTarget == null) { if (entityTarget == null) {
sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[0])); DisguiseUtilities.sendMessage(sender, LibsMsg.CANNOT_FIND_PLAYER, args[0]);
return true; return true;
} }
@ -92,7 +92,7 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements
} }
catch (DisguiseParseException ex) { catch (DisguiseParseException ex) {
if (ex.getMessage() != null) { if (ex.getMessage() != null) {
sender.sendMessage(ex.getMessage()); DisguiseUtilities.sendMessage(sender, ex.getMessage());
} }
return true; return true;
} }

View File

@ -77,8 +77,8 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
Collections.sort(classes); Collections.sort(classes);
sender.sendMessage(LibsMsg.DMODRADIUS_USABLE DisguiseUtilities.sendMessage(sender, LibsMsg.DMODRADIUS_USABLE,
.get(ChatColor.GREEN + StringUtils.join(classes, ChatColor.DARK_GREEN + ", " + ChatColor.GREEN))); ChatColor.GREEN + StringUtils.join(classes, ChatColor.DARK_GREEN + ", " + ChatColor.GREEN));
return true; return true;
} }
@ -99,14 +99,14 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
} }
if (baseType == null) { if (baseType == null) {
sender.sendMessage(LibsMsg.DMODRADIUS_UNRECOGNIZED.get(args[0])); DisguiseUtilities.sendMessage(sender, LibsMsg.DMODRADIUS_UNRECOGNIZED, args[0]);
return true; return true;
} }
} }
if (args.length == starting + 1) { if (args.length == starting + 1) {
sender.sendMessage( DisguiseUtilities.sendMessage(sender,
(starting == 0 ? LibsMsg.DMODRADIUS_NEEDOPTIONS : LibsMsg.DMODRADIUS_NEEDOPTIONS_ENTITY).get()); starting == 0 ? LibsMsg.DMODRADIUS_NEEDOPTIONS : LibsMsg.DMODRADIUS_NEEDOPTIONS_ENTITY);
return true; return true;
} else if (args.length < 2) { } else if (args.length < 2) {
DisguiseUtilities.sendMessage(sender, LibsMsg.DMODRADIUS_NEEDOPTIONS); DisguiseUtilities.sendMessage(sender, LibsMsg.DMODRADIUS_NEEDOPTIONS);
@ -114,7 +114,7 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
} }
if (!isInteger(args[starting])) { if (!isInteger(args[starting])) {
sender.sendMessage(LibsMsg.NOT_NUMBER.get(args[starting])); DisguiseUtilities.sendMessage(sender, LibsMsg.NOT_NUMBER, args[starting]);
return true; return true;
} }
@ -176,7 +176,7 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
} }
catch (DisguiseParseException ex) { catch (DisguiseParseException ex) {
if (ex.getMessage() != null) { if (ex.getMessage() != null) {
sender.sendMessage(ex.getMessage()); DisguiseUtilities.sendMessage(sender, ex.getMessage());
} }
return true; return true;

View File

@ -85,17 +85,19 @@ public class UndisguisePlayerCommand implements CommandExecutor, TabCompleter {
} }
if (entityTarget == null) { if (entityTarget == null) {
sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[0])); DisguiseUtilities.sendMessage(sender, LibsMsg.CANNOT_FIND_PLAYER, args[0]);
return true; return true;
} }
if (DisguiseAPI.isDisguised(entityTarget)) { if (DisguiseAPI.isDisguised(entityTarget)) {
DisguiseAPI.undisguiseToAll(entityTarget); DisguiseAPI.undisguiseToAll(entityTarget);
sender.sendMessage(LibsMsg.UNDISG_PLAYER.get(entityTarget instanceof Player ? entityTarget.getName() : DisguiseUtilities.sendMessage(sender, LibsMsg.UNDISG_PLAYER,
DisguiseType.getType(entityTarget).toReadable())); entityTarget instanceof Player ? entityTarget.getName() :
DisguiseType.getType(entityTarget).toReadable());
} else { } else {
sender.sendMessage(LibsMsg.UNDISG_PLAYER_FAIL.get(entityTarget instanceof Player ? entityTarget.getName() : DisguiseUtilities.sendMessage(sender, LibsMsg.UNDISG_PLAYER_FAIL,
DisguiseType.getType(entityTarget).toReadable())); entityTarget instanceof Player ? entityTarget.getName() :
DisguiseType.getType(entityTarget).toReadable());
} }
return true; return true;

View File

@ -45,7 +45,7 @@ public class UndisguiseRadiusCommand implements CommandExecutor {
int radius = maxRadius; int radius = maxRadius;
if (args.length > 0) { if (args.length > 0) {
if (!isNumeric(args[0])) { if (!isNumeric(args[0])) {
sender.sendMessage(LibsMsg.NOT_NUMBER.get(args[0])); DisguiseUtilities.sendMessage(sender, LibsMsg.NOT_NUMBER, args[0]);
return true; return true;
} }
radius = Integer.parseInt(args[0]); radius = Integer.parseInt(args[0]);

View File

@ -58,7 +58,7 @@ public class CopyDisguiseCommand implements CommandExecutor {
} }
if (target == null) { if (target == null) {
sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[0])); DisguiseUtilities.sendMessage(sender, LibsMsg.CANNOT_FIND_PLAYER, args[0]);
return true; return true;
} }
} }
@ -91,7 +91,7 @@ public class CopyDisguiseCommand implements CommandExecutor {
public void sendMessage(CommandSender sender, LibsMsg msg, LibsMsg oldVer, String string, boolean forceAbbrev) { public void sendMessage(CommandSender sender, LibsMsg msg, LibsMsg oldVer, String string, boolean forceAbbrev) {
if (!NmsVersion.v1_13.isSupported()) { if (!NmsVersion.v1_13.isSupported()) {
sender.sendMessage(oldVer.get(string)); DisguiseUtilities.sendMessage(sender, oldVer, string);
return; return;
} }

View File

@ -67,7 +67,7 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl
DisguisePerm type = DisguiseParser.getDisguisePerm(args[0]); DisguisePerm type = DisguiseParser.getDisguisePerm(args[0]);
if (type == null) { if (type == null) {
sender.sendMessage(LibsMsg.DHELP_CANTFIND.get(args[0])); DisguiseUtilities.sendMessage(sender, LibsMsg.DHELP_CANTFIND, args[0]);
return true; return true;
} }
@ -114,8 +114,8 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl
methods.add(LibsMsg.DHELP_NO_OPTIONS.get()); methods.add(LibsMsg.DHELP_NO_OPTIONS.get());
} }
sender.sendMessage(LibsMsg.DHELP_OPTIONS.get(ChatColor.DARK_RED + type.toReadable(), DisguiseUtilities.sendMessage(sender, LibsMsg.DHELP_OPTIONS, ChatColor.DARK_RED + type.toReadable(),
StringUtils.join(methods, ChatColor.DARK_RED + ", "))); StringUtils.join(methods, ChatColor.DARK_RED + ", "));
if (ignored > 0) { if (ignored > 0) {
DisguiseUtilities.sendMessage(sender, LibsMsg.NO_PERMS_USE_OPTIONS, ignored); DisguiseUtilities.sendMessage(sender, LibsMsg.NO_PERMS_USE_OPTIONS, ignored);

View File

@ -67,14 +67,14 @@ public class GrabHeadCommand implements CommandExecutor {
@Override @Override
public void onError(LibsMsg msg, Object... args) { public void onError(LibsMsg msg, Object... args) {
sender.sendMessage(msg.get(args)); DisguiseUtilities.sendMessage(sender, msg, args);
runnable.cancel(); runnable.cancel();
} }
@Override @Override
public void onInfo(LibsMsg msg, Object... args) { public void onInfo(LibsMsg msg, Object... args) {
sender.sendMessage(msg.get(args)); DisguiseUtilities.sendMessage(sender, msg, args);
} }
@Override @Override

View File

@ -75,14 +75,14 @@ public class GrabSkinCommand implements CommandExecutor {
@Override @Override
public void onError(LibsMsg msg, Object... args) { public void onError(LibsMsg msg, Object... args) {
sender.sendMessage(msg.get(args)); DisguiseUtilities.sendMessage(sender, msg, args);
runnable.cancel(); runnable.cancel();
} }
@Override @Override
public void onInfo(LibsMsg msg, Object... args) { public void onInfo(LibsMsg msg, Object... args) {
sender.sendMessage(msg.get(args)); DisguiseUtilities.sendMessage(sender, msg, args);
} }
@Override @Override

View File

@ -71,7 +71,7 @@ public class SaveDisguiseCommand implements CommandExecutor {
} }
catch (DisguiseParseException e) { catch (DisguiseParseException e) {
if (e.getMessage() != null) { if (e.getMessage() != null) {
sender.sendMessage(e.getMessage()); DisguiseUtilities.sendMessage(sender, e.getMessage());
} else { } else {
DisguiseUtilities.sendMessage(sender, LibsMsg.PARSE_CANT_LOAD); DisguiseUtilities.sendMessage(sender, LibsMsg.PARSE_CANT_LOAD);
} }
@ -109,7 +109,7 @@ public class SaveDisguiseCommand implements CommandExecutor {
String usable = SkinUtils.getUsableStatus(); String usable = SkinUtils.getUsableStatus();
if (usable != null) { if (usable != null) {
sender.sendMessage(usable); DisguiseUtilities.sendMessage(sender, usable);
return true; return true;
} }
@ -127,12 +127,12 @@ public class SaveDisguiseCommand implements CommandExecutor {
public void onError(LibsMsg msg, Object... args) { public void onError(LibsMsg msg, Object... args) {
runnable.cancel(); runnable.cancel();
sender.sendMessage(msg.get(args)); DisguiseUtilities.sendMessage(sender, msg, args);
} }
@Override @Override
public void onInfo(LibsMsg msg, Object... args) { public void onInfo(LibsMsg msg, Object... args) {
sender.sendMessage(msg.get(args)); DisguiseUtilities.sendMessage(sender, msg, args);
} }
@Override @Override
@ -169,7 +169,7 @@ public class SaveDisguiseCommand implements CommandExecutor {
} }
catch (DisguiseParseException e) { catch (DisguiseParseException e) {
if (e.getMessage() != null) { if (e.getMessage() != null) {
sender.sendMessage(e.getMessage()); DisguiseUtilities.sendMessage(sender, e.getMessage());
} else { } else {
DisguiseUtilities.sendMessage(sender, LibsMsg.PARSE_CANT_LOAD); DisguiseUtilities.sendMessage(sender, LibsMsg.PARSE_CANT_LOAD);
} }

View File

@ -430,10 +430,8 @@ public abstract class Disguise {
disguiseExpires < System.currentTimeMillis())) { // If disguise expired disguiseExpires < System.currentTimeMillis())) { // If disguise expired
removeDisguise(); removeDisguise();
String expired = LibsMsg.EXPIRED_DISGUISE.get(); if (getEntity() instanceof Player) {
DisguiseUtilities.sendMessage(getEntity(), LibsMsg.EXPIRED_DISGUISE);
if (getEntity() instanceof Player && expired.length() > 0) {
getEntity().sendMessage(expired);
} }
return; return;

View File

@ -2148,11 +2148,33 @@ public class DisguiseUtilities {
return Strings.isEmpty(player.getPlayerListName()) ? player.getName() : player.getPlayerListName(); return Strings.isEmpty(player.getPlayerListName()) ? player.getName() : player.getPlayerListName();
} }
public static void sendMessage(CommandSender sender, String message) {
if (!NmsVersion.v1_16.isSupported()) {
if (!message.isEmpty()) {
sender.sendMessage(message);
}
} else {
BaseComponent[] components = getColoredChat(message);
if (components.length > 0) {
sender.spigot().sendMessage(components);
}
}
}
public static void sendMessage(CommandSender sender, LibsMsg msg, Object... args) { public static void sendMessage(CommandSender sender, LibsMsg msg, Object... args) {
if (!NmsVersion.v1_16.isSupported()) { if (!NmsVersion.v1_16.isSupported()) {
sender.sendMessage(msg.get(args)); String message = msg.get(args);
if (!message.isEmpty()) {
sender.sendMessage(message);
}
} else { } else {
sender.spigot().sendMessage(msg.getChat(args)); BaseComponent[] components = msg.getChat(args);
if (components.length > 0) {
sender.spigot().sendMessage(components);
}
} }
} }
@ -2219,6 +2241,10 @@ public class DisguiseUtilities {
* Modification of TextComponent.fromLegacyText * Modification of TextComponent.fromLegacyText
*/ */
public static BaseComponent[] getColoredChat(String message) { public static BaseComponent[] getColoredChat(String message) {
if (message.isEmpty()) {
return new BaseComponent[0];
}
ArrayList<BaseComponent> components = new ArrayList(); ArrayList<BaseComponent> components = new ArrayList();
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
TextComponent component = new TextComponent(); TextComponent component = new TextComponent();

View File

@ -125,11 +125,7 @@ public class DisguiseListener implements Listener {
if (disguises.length > 0) { if (disguises.length > 0) {
DisguiseAPI.undisguiseToAll(player); DisguiseAPI.undisguiseToAll(player);
String blown = LibsMsg.BLOWN_DISGUISE.get(); DisguiseUtilities.sendMessage(player, LibsMsg.BLOWN_DISGUISE);
if (blown.length() > 0) {
player.sendMessage(blown);
}
} }
} }
@ -202,22 +198,14 @@ public class DisguiseListener implements Listener {
if (disguises.length > 0) { if (disguises.length > 0) {
event.setCancelled(true); event.setCancelled(true);
String cantAttack = LibsMsg.CANT_ATTACK_DISGUISED.get(); DisguiseUtilities.sendMessage(attacker, LibsMsg.CANT_ATTACK_DISGUISED);
if (cantAttack.length() > 0) {
attacker.sendMessage(cantAttack);
}
} else if (DisguiseConfig.getPvPTimer() > 0 && attacker.hasMetadata("LastDisguise")) { } else if (DisguiseConfig.getPvPTimer() > 0 && attacker.hasMetadata("LastDisguise")) {
long lastDisguised = attacker.getMetadata("LastDisguise").get(0).asLong(); long lastDisguised = attacker.getMetadata("LastDisguise").get(0).asLong();
if (lastDisguised + DisguiseConfig.getPvPTimer() * 1000 > System.currentTimeMillis()) { if (lastDisguised + DisguiseConfig.getPvPTimer() * 1000 > System.currentTimeMillis()) {
event.setCancelled(true); event.setCancelled(true);
String cantAttack = LibsMsg.CANT_ATTACK_DISGUISED_RECENTLY.get(); DisguiseUtilities.sendMessage(attacker, LibsMsg.CANT_ATTACK_DISGUISED_RECENTLY);
if (cantAttack.length() > 0) {
attacker.sendMessage(cantAttack);
}
} }
} }
} }
@ -331,9 +319,9 @@ public class DisguiseListener implements Listener {
if (DisguiseUtilities.isOlderThan(requiredProtocolLib, version)) { if (DisguiseUtilities.isOlderThan(requiredProtocolLib, version)) {
p.sendMessage(ChatColor.RED + "Update your ProtocolLib! You are running " + version + p.sendMessage(ChatColor.RED + "Update your ProtocolLib! You are running " + version +
" but the minimum version you should be on is " + requiredProtocolLib + "!"); " but the minimum version you should be on is " + requiredProtocolLib + "!");
p.sendMessage(ChatColor.RED + "https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/target" + p.sendMessage(
"/ProtocolLib" + ChatColor.RED + "https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/target" +
".jar"); "/ProtocolLib" + ".jar");
p.sendMessage(ChatColor.RED + "Use /ld updateprotocollib - To update to the latest development build"); p.sendMessage(ChatColor.RED + "Use /ld updateprotocollib - To update to the latest development build");
} }
} }
@ -563,11 +551,7 @@ public class DisguiseListener implements Listener {
disguise.removeDisguise(); disguise.removeDisguise();
} }
String msg = LibsMsg.SWITCH_WORLD_DISGUISE_REMOVED.get(); DisguiseUtilities.sendMessage(event.getPlayer(), LibsMsg.SWITCH_WORLD_DISGUISE_REMOVED);
if (msg.length() > 0) {
event.getPlayer().sendMessage(msg);
}
} }
} }
@ -662,11 +646,7 @@ public class DisguiseListener implements Listener {
disguise.removeDisguise(); disguise.removeDisguise();
} }
String msg = LibsMsg.SWITCH_WORLD_DISGUISE_REMOVED.get(); DisguiseUtilities.sendMessage(event.getPlayer(), LibsMsg.SWITCH_WORLD_DISGUISE_REMOVED);
if (msg.length() > 0) {
event.getPlayer().sendMessage(msg);
}
} }
} else { } else {
// Stupid hack to fix worldswitch invisibility bug & paper packet bug // Stupid hack to fix worldswitch invisibility bug & paper packet bug

View File

@ -372,16 +372,20 @@ public enum LibsMsg {
} }
public String get(Object... strings) { public String get(Object... strings) {
if (StringUtils.countMatches(getRaw(), "%s") != strings.length) { int matches = StringUtils.countMatches(getRaw(), "%s");
if (matches != strings.length) {
DisguiseUtilities.getLogger().severe("Mismatch in messages, incorrect parameters supplied for " + name() + DisguiseUtilities.getLogger().severe("Mismatch in messages, incorrect parameters supplied for " + name() +
". Please inform plugin author."); ". Please inform plugin author if not using translations.");
} }
if (strings.length == 0) { String trans = TranslateType.MESSAGES.get(getRaw());
return TranslateType.MESSAGES.get(getRaw());
if (trans.isEmpty() || strings.length == 0) {
return trans;
} }
return String.format(TranslateType.MESSAGES.get(getRaw()), strings); return String.format(trans, strings);
} }
public String toString() { public String toString() {