mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-03 06:57:39 +01:00
New Permission: essentials.chat.url
Without this perm, URLs will be modified not to be links.
This commit is contained in:
parent
0dc1270aed
commit
d20519ef8b
@ -495,6 +495,7 @@ public class Util
|
|||||||
}
|
}
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
private static transient final Pattern URL_PATTERN = Pattern.compile("^((?:(?:https?)://)?[\\w-_\\.]{2,})\\.([a-z]{2,3}(?:/\\S+)?)$");
|
||||||
private static transient final Pattern VANILLA_PATTERN = Pattern.compile("\u00A7+[0-9A-FK-ORa-fk-or]");
|
private static transient final Pattern VANILLA_PATTERN = Pattern.compile("\u00A7+[0-9A-FK-ORa-fk-or]");
|
||||||
private static transient final Pattern REPLACE_PATTERN = Pattern.compile("&([0-9a-fk-or])");
|
private static transient final Pattern REPLACE_PATTERN = Pattern.compile("&([0-9a-fk-or])");
|
||||||
private static transient final Pattern VANILLA_COLOR_PATTERN = Pattern.compile("\u00A7+[0-9A-Fa-f]");
|
private static transient final Pattern VANILLA_COLOR_PATTERN = Pattern.compile("\u00A7+[0-9A-Fa-f]");
|
||||||
@ -528,7 +529,7 @@ public class Util
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return input.replace(".", ". ").replace(". ", ". ");
|
return URL_PATTERN.matcher(input).replaceAll("$1 $2");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String formatString(final IUser user, final String permBase, final String input)
|
public static String formatString(final IUser user, final String permBase, final String input)
|
||||||
@ -546,6 +547,24 @@ public class Util
|
|||||||
{
|
{
|
||||||
message = Util.stripColor(input, VANILLA_COLOR_PATTERN);
|
message = Util.stripColor(input, VANILLA_COLOR_PATTERN);
|
||||||
}
|
}
|
||||||
|
if (user.isAuthorized(permBase + ".format"))
|
||||||
|
{
|
||||||
|
message = Util.replaceColor(message, REPLACE_FORMAT_PATTERN);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
message = Util.stripColor(message, VANILLA_FORMAT_PATTERN);
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String formatMessage(final IUser user, final String permBase, final String input)
|
||||||
|
{
|
||||||
|
if (input == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String message = formatString(user, permBase, input);
|
||||||
if (user.isAuthorized(permBase + ".magic"))
|
if (user.isAuthorized(permBase + ".magic"))
|
||||||
{
|
{
|
||||||
message = Util.replaceColor(message, REPLACE_MAGIC_PATTERN);
|
message = Util.replaceColor(message, REPLACE_MAGIC_PATTERN);
|
||||||
@ -554,13 +573,9 @@ public class Util
|
|||||||
{
|
{
|
||||||
message = Util.stripColor(message, VANILLA_MAGIC_PATTERN);
|
message = Util.stripColor(message, VANILLA_MAGIC_PATTERN);
|
||||||
}
|
}
|
||||||
if (user.isAuthorized(permBase + ".format"))
|
if (!user.isAuthorized(permBase + ".url"))
|
||||||
{
|
{
|
||||||
message = Util.replaceColor(message, REPLACE_FORMAT_PATTERN);
|
message = Util.blockURL(message);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
message = Util.stripColor(message, VANILLA_FORMAT_PATTERN);
|
|
||||||
}
|
}
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ public class Commandme extends EssentialsCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
String message = getFinalArg(args, 0);
|
String message = getFinalArg(args, 0);
|
||||||
message = Util.formatString(user, "essentials.chat", message);
|
message = Util.formatMessage(user, "essentials.chat", message);
|
||||||
|
|
||||||
user.setDisplayNick();
|
user.setDisplayNick();
|
||||||
ess.broadcastMessage(user, _("action", user.getDisplayName(), message));
|
ess.broadcastMessage(user, _("action", user.getDisplayName(), message));
|
||||||
|
@ -34,7 +34,7 @@ public class Commandmsg extends EssentialsCommand
|
|||||||
{
|
{
|
||||||
throw new Exception(_("voiceSilenced"));
|
throw new Exception(_("voiceSilenced"));
|
||||||
}
|
}
|
||||||
message = Util.formatString(user, "essentials.msg", message);
|
message = Util.formatMessage(user, "essentials.msg", message);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -32,7 +32,7 @@ public class Commandr extends EssentialsCommand
|
|||||||
if (sender instanceof Player)
|
if (sender instanceof Player)
|
||||||
{
|
{
|
||||||
User user = ess.getUser(sender);
|
User user = ess.getUser(sender);
|
||||||
message = Util.formatString(user, "essentials.msg", message);
|
message = Util.formatMessage(user, "essentials.msg", message);
|
||||||
replyTo = user;
|
replyTo = user;
|
||||||
senderName = user.getDisplayName();
|
senderName = user.getDisplayName();
|
||||||
}
|
}
|
||||||
|
@ -37,9 +37,12 @@ public class EssentialsChatPlayerListenerLowest extends EssentialsChatPlayer
|
|||||||
/**
|
/**
|
||||||
* This listener should apply the general chat formatting only...then return control back the event handler
|
* This listener should apply the general chat formatting only...then return control back the event handler
|
||||||
*/
|
*/
|
||||||
event.setMessage(Util.formatString(user, "essentials.chat", event.getMessage()));
|
event.setMessage(Util.formatMessage(user, "essentials.chat", event.getMessage()));
|
||||||
String group = user.getGroup();
|
String group = user.getGroup();
|
||||||
String world = user.getWorld().getName();
|
String world = user.getWorld().getName();
|
||||||
event.setFormat(ess.getSettings().getChatFormat(group).format(new Object[] {group, world, world.substring(0, 1).toUpperCase(Locale.ENGLISH)}));
|
event.setFormat(ess.getSettings().getChatFormat(group).format(new Object[]
|
||||||
|
{
|
||||||
|
group, world, world.substring(0, 1).toUpperCase(Locale.ENGLISH)
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user