0

Disabled chatalias cmd interaction

This commit is contained in:
Pepich 2017-02-07 04:03:17 +01:00
parent 7966b91954
commit c7da1647ea

View File

@ -8,9 +8,7 @@ import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
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.PlayerCommandPreprocessEvent; 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;
@ -26,7 +24,7 @@ import com.redstoner.misc.Utils;
import com.redstoner.modules.Module; import com.redstoner.modules.Module;
@AutoRegisterListener @AutoRegisterListener
@Version(major = 1, minor = 0, revision = 1, compatible = 1) @Version(major = 1, minor = 0, revision = 2, 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:
@ -82,45 +80,44 @@ public class Chatalias implements Module, Listener
aliases.remove(event.getPlayer().getUniqueId().toString()); aliases.remove(event.getPlayer().getUniqueId().toString());
} }
@EventHandler(priority = EventPriority.LOWEST) // @EventHandler(priority = EventPriority.LOWEST)
public void onPlayerChat(AsyncPlayerChatEvent event) // public void onPlayerChat(AsyncPlayerChatEvent event)
{ // {
Player player = event.getPlayer(); // Player player = event.getPlayer();
UUID uuid = player.getUniqueId(); // UUID uuid = player.getUniqueId();
JSONObject playerAliases = (JSONObject) aliases.get(uuid.toString()); // JSONObject playerAliases = (JSONObject) aliases.get(uuid.toString());
for (Object key : playerAliases.keySet()) // for (Object key : playerAliases.keySet())
{ // {
String keyword = (String) key; // String keyword = (String) key;
String replacement = (String) playerAliases.get(key); // String replacement = (String) playerAliases.get(key);
if (keyword.startsWith("R: ")) // if (keyword.startsWith("R: "))
{ // {
keyword = keyword.replace("R: ", ""); // keyword = keyword.replace("R: ", "");
event.setMessage(event.getMessage().replaceAll(keyword, replacement)); // event.setMessage(event.getMessage().replaceAll(keyword, replacement));
} // }
else // else
{ // {
if (keyword.startsWith("N: ")) // if (keyword.startsWith("N: "))
keyword = keyword.replace("N: ", ""); // keyword = keyword.replace("N: ", "");
event.setMessage(event.getMessage().replace(keyword, replacement)); // event.setMessage(event.getMessage().replace(keyword, replacement));
} // }
int maxLength; // int maxLength;
try // try
{ // {
maxLength = Integer.valueOf(getPermissionContent(player, "utils.alias.length.")); // maxLength = Integer.valueOf(getPermissionContent(player, "utils.alias.length."));
} // }
catch (NumberFormatException e) // catch (NumberFormatException e)
{ // {
maxLength = 255; // maxLength = 255;
} // }
if (event.getMessage().length() > maxLength) // if (event.getMessage().length() > maxLength)
{ // {
Utils.sendErrorMessage(player, null, "The generated message is too long!"); // Utils.sendErrorMessage(player, null, "The generated message is too long!");
event.setCancelled(true); // event.setCancelled(true);
return; // return;
} // }
} // }
} // }
@EventHandler @EventHandler
public void onPlayerCommand(PlayerCommandPreprocessEvent event) public void onPlayerCommand(PlayerCommandPreprocessEvent event)
{ {