81 lines
No EOL
2.4 KiB
Java
81 lines
No EOL
2.4 KiB
Java
package pl.sloudpl.sloudchat.events;
|
|
|
|
import me.clip.placeholderapi.PlaceholderAPI;
|
|
import net.luckperms.api.model.user.User;
|
|
import net.md_5.bungee.api.ChatColor;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.event.EventHandler;
|
|
import org.bukkit.event.Listener;
|
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
import pl.sloudpl.sloudchat.SloudChat;
|
|
import pl.sloudpl.sloudchat.utils.ColorUtils;
|
|
|
|
public class onPlayerChat1_16 implements Listener {
|
|
|
|
private final SloudChat plugin;
|
|
|
|
public onPlayerChat1_16(SloudChat plugin){
|
|
this.plugin = plugin;
|
|
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
|
}
|
|
|
|
@EventHandler
|
|
public void PlayerChat(AsyncPlayerChatEvent event){
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
if(!plugin.isChatEnabled && !player.hasPermission("sloudpl.chat.bypass")){
|
|
|
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("disabled-chat-msg")));
|
|
event.setCancelled(true);
|
|
return;
|
|
|
|
}
|
|
|
|
String playerName = player.getName();
|
|
|
|
String prefix;
|
|
String suffix;
|
|
|
|
if(plugin.luckpermsAvailable){
|
|
|
|
User user = plugin.luckPerms.getUserManager().getUser(playerName);
|
|
if (user == null) return;
|
|
|
|
prefix = user.getCachedData().getMetaData().getPrefix();
|
|
suffix = user.getCachedData().getMetaData().getSuffix();
|
|
|
|
} else {
|
|
|
|
prefix = null;
|
|
suffix = null;
|
|
|
|
}
|
|
|
|
String message = event.getMessage();
|
|
|
|
String format = plugin.getConfig().getString("chat-format");
|
|
|
|
if (format == null) return;
|
|
|
|
format = format
|
|
.replace("{PREFIX}", prefix != null ? prefix : "")
|
|
.replace("{SUFFIX}", suffix != null ? suffix : "")
|
|
.replace("{PLAYER}", playerName);
|
|
|
|
if (plugin.papiAvailable) {
|
|
format = PlaceholderAPI.setPlaceholders(player, format);
|
|
}
|
|
|
|
if (!plugin.papiAvailable && format.contains("%")) {
|
|
plugin.getLogger().warning("Chat format contains PlaceholderAPI variables but PlaceholderAPI is not installed!");
|
|
}
|
|
|
|
format = format.replace("{MESSAGE}", message);
|
|
|
|
format = ColorUtils.convertHexColors(ChatColor.translateAlternateColorCodes('&', format));
|
|
|
|
event.setFormat(format.replace("%", "%%"));
|
|
}
|
|
|
|
} |