Made wildcard catch only apply to regex aliases
This commit is contained in:
parent
73f7f0da50
commit
d73e15eecd
@ -11,6 +11,7 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||||
@ -25,7 +26,7 @@ import com.redstoner.misc.Utils;
|
|||||||
import com.redstoner.modules.Module;
|
import com.redstoner.modules.Module;
|
||||||
|
|
||||||
@AutoRegisterListener
|
@AutoRegisterListener
|
||||||
@Version(major = 1, minor = 0, revision = 6, compatible = 1)
|
@Version(major = 1, minor = 0, revision = 7, compatible = 1)
|
||||||
public class Chatalias implements Module, Listener
|
public class Chatalias implements Module, Listener
|
||||||
{
|
{
|
||||||
// to export chatalias data to json:
|
// to export chatalias data to json:
|
||||||
@ -33,8 +34,8 @@ public class Chatalias implements Module, Listener
|
|||||||
// HANDLE WITH CARE! This will create an array of null entries the size of len(data)!
|
// HANDLE WITH CARE! This will create an array of null entries the size of len(data)!
|
||||||
private boolean enabled = false;
|
private boolean enabled = false;
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private final String[] commands = new String[] {"e?r", "e?m", "e?t", "e?w", "e?msg", "e?message", "e?whisper",
|
private final String[] commands = new String[] {"e?r", "e?m .+? ", "e?t", "e?w", "e?msg .+? ", "e?message .+? ",
|
||||||
"e?me", "cg say", "ac"};
|
"e?whisper .+? ", "e?me", "cg say", "ac"};
|
||||||
private JSONObject defaults = new JSONObject();
|
private JSONObject defaults = new JSONObject();
|
||||||
private JSONObject aliases = new JSONObject();
|
private JSONObject aliases = new JSONObject();
|
||||||
|
|
||||||
@ -44,7 +45,7 @@ public class Chatalias implements Module, Listener
|
|||||||
{
|
{
|
||||||
defaults.put("dataFormat", "v1");
|
defaults.put("dataFormat", "v1");
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
data.put("R: ^(([^\\w]|_)\\/|\\\\)", "\\/");
|
data.put("N: ./", "/");
|
||||||
defaults.put("data", data);
|
defaults.put("data", data);
|
||||||
for (Player p : Bukkit.getOnlinePlayers())
|
for (Player p : Bukkit.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
@ -130,65 +131,71 @@ public class Chatalias implements Module, Listener
|
|||||||
saveAliases(uuid);
|
saveAliases(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @EventHandler
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
// public void onPlayerCommand(PlayerCommandPreprocessEvent event)
|
public void onPlayerCommand(PlayerCommandPreprocessEvent event)
|
||||||
// {
|
{
|
||||||
// if (event.isCancelled())
|
if (event.isCancelled())
|
||||||
// return;
|
return;
|
||||||
// boolean listening = false;
|
boolean listening = false;
|
||||||
// for (String s : commands)
|
String regex = "";
|
||||||
// {
|
for (String s : commands)
|
||||||
// if (event.getMessage().matches("^/.*:" + s))
|
{
|
||||||
// {
|
regex = "^\\/(.*:)?" + s + ".*";
|
||||||
// listening = true;
|
if (event.getMessage().matches(regex))
|
||||||
// break;
|
{
|
||||||
// }
|
listening = true;
|
||||||
// }
|
break;
|
||||||
// if (!listening)
|
}
|
||||||
// return;
|
}
|
||||||
// Player player = event.getPlayer();
|
if (!listening)
|
||||||
// UUID uuid = player.getUniqueId();
|
return;
|
||||||
// JSONObject playerAliases = (JSONObject) aliases.get(uuid.toString());
|
Player player = event.getPlayer();
|
||||||
// String command = event.getMessage().split(" ")[0];
|
UUID uuid = player.getUniqueId();
|
||||||
// event.setMessage(event.getMessage().replace(command, ""));
|
JSONObject playerAliases = (JSONObject) aliases.get(uuid.toString());
|
||||||
// for (Object key : playerAliases.keySet())
|
String command = event.getMessage().replaceAll(regex.replaceAll("\\.\\*$", ""), "");
|
||||||
// {
|
command = event.getMessage().replace(command, "");
|
||||||
// String keyword = (String) key;
|
event.setMessage(event.getMessage().replace(command, "§§"));
|
||||||
// String replacement = (String) playerAliases.get(key);
|
Utils.log(event.getMessage());
|
||||||
// if (keyword.startsWith("R: "))
|
for (Object key : playerAliases.keySet())
|
||||||
// {
|
{
|
||||||
// keyword = keyword.replace("R: ", "");
|
String keyword = (String) key;
|
||||||
// event.setMessage(event.getMessage().replaceAll(keyword, replacement));
|
String replacement = (String) playerAliases.get(key);
|
||||||
// }
|
if (keyword.startsWith("R: "))
|
||||||
// else
|
{
|
||||||
// {
|
keyword = keyword.replace("R: ", "");
|
||||||
// if (keyword.startsWith("N: "))
|
event.setMessage(event.getMessage().replaceAll(keyword, replacement));
|
||||||
// keyword = keyword.replace("N: ", "");
|
}
|
||||||
// event.setMessage(event.getMessage().replace(keyword, replacement));
|
else
|
||||||
// }
|
{
|
||||||
// int maxLength;
|
if (keyword.startsWith("N: "))
|
||||||
// try
|
keyword = keyword.replace("N: ", "");
|
||||||
// {
|
event.setMessage(event.getMessage().replace(keyword, replacement));
|
||||||
// maxLength = Integer.valueOf(getPermissionContent(player, "utils.alias.length."));
|
}
|
||||||
// }
|
int maxLength;
|
||||||
// catch (NumberFormatException e)
|
try
|
||||||
// {
|
{
|
||||||
// maxLength = 255;
|
maxLength = Integer.valueOf(getPermissionContent(player, "utils.alias.length."));
|
||||||
// }
|
}
|
||||||
// if (event.getMessage().length() > maxLength)
|
catch (NumberFormatException e)
|
||||||
// {
|
{
|
||||||
// Utils.sendErrorMessage(player, null, "The generated message is too long!");
|
maxLength = 255;
|
||||||
// event.setCancelled(true);
|
}
|
||||||
// return;
|
if (event.getMessage().length() > maxLength)
|
||||||
// }
|
{
|
||||||
// }
|
Utils.sendErrorMessage(player, null, "The generated message is too long!");
|
||||||
// event.setMessage(command + event.getMessage());
|
event.setCancelled(true);
|
||||||
// }
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event.setMessage(command + event.getMessage().substring(2));
|
||||||
|
Utils.log(event.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Command(hook = "addalias")
|
@Command(hook = "addalias")
|
||||||
public boolean addAlias(CommandSender sender, boolean regex, String keyword, String replacement)
|
public boolean addAlias(CommandSender sender, boolean regex, String keyword, String replacement)
|
||||||
{
|
{
|
||||||
if (keyword.equals(".*"))
|
if (regex && keyword.equals(".*"))
|
||||||
{
|
{
|
||||||
Utils.sendErrorMessage(sender, null, "You may not define the wildcard regex as an alias.");
|
Utils.sendErrorMessage(sender, null, "You may not define the wildcard regex as an alias.");
|
||||||
return true;
|
return true;
|
||||||
@ -290,7 +297,7 @@ public class Chatalias implements Module, Listener
|
|||||||
{
|
{
|
||||||
for (Object key : playerAliases.keySet())
|
for (Object key : playerAliases.keySet())
|
||||||
{
|
{
|
||||||
tempAliases.put(key, "N: " + playerAliases.get(key));
|
tempAliases.put("N: " + key, playerAliases.get(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
temp.put("data", tempAliases);
|
temp.put("data", tempAliases);
|
||||||
|
Reference in New Issue
Block a user