Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GlobalCommand implements CommandExecutor {
- private final LuckPerms luckPerms;
- private final HashMap<UUID, Long> cooldown;
- public GlobalCommand(LuckPerms luckPerms) {
- this.luckPerms = luckPerms;
- this.cooldown = new HashMap<>();
- }
- @Override
- public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
- String serverPrefix = McCityChat.plugin.getConfig().getString("Server Prefix");
- String noPerm = McCityChat.plugin.getConfig().getString("No Permission");
- if (!(sender instanceof Player player)) {
- sender.sendMessage("Must be a player");
- return true;
- }
- if (!(args.length >= 1)) {
- sender.sendMessage("incorrect use msg");
- return true;
- }
- if (!sender.hasPermission("mccitychat.global")) {
- sender.sendMessage(MiniMessage.miniMessage().deserialize(serverPrefix + " " + noPerm));
- return true;
- }
- StringBuilder builder = new StringBuilder();
- for (String string : args) {
- builder.append(string).append(" ");
- }
- String msg = builder.toString().trim();
- User user = luckPerms.getPlayerAdapter(Player.class).getUser(player);
- String prefix = user.getCachedData().getMetaData().getPrefix();
- String suffix = user.getCachedData().getMetaData().getSuffix();
- String chatPrefix = McCityChat.plugin.getConfig().getString("Global Prefix");
- String color = McCityChat.plugin.getConfig().getString("Global Chat Color");
- String chatSep = McCityChat.plugin.getConfig().getString("Chat Separator");
- if (!sender.hasPermission("mccitychat.bypass")) {
- if (!cooldown.containsKey(player.getUniqueId())) {
- cooldown.put(player.getUniqueId(), System.currentTimeMillis());
- String message = chatPrefix + " " + prefix + sender.getName() + suffix + chatSep + color + msg;
- ByteArrayDataOutput out = ByteStreams.newDataOutput();
- out.writeUTF(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize(message)));
- player.sendPluginMessage(McCityChat.plugin, "mccity:chat", out.toByteArray());
- }
- long timeElapsed = System.currentTimeMillis() - cooldown.get(player.getUniqueId());
- if (timeElapsed >= McCityChat.plugin.getConfig().getLong("Global Cooldown") * 1000) {
- String message = chatPrefix + " " + prefix + sender.getName() + suffix + chatSep + color + msg;
- ByteArrayDataOutput out = ByteStreams.newDataOutput();
- out.writeUTF(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize(message)));
- player.sendPluginMessage(McCityChat.plugin, "mccity:chat", out.toByteArray());
- cooldown.put(player.getUniqueId(), System.currentTimeMillis());
- return true;
- } else {
- String cooldownMsgStr = McCityChat.plugin.getConfig().getString("Cooldown Message");
- if (cooldownMsgStr.contains("%c%")) {
- Long timeRemaining = ((McCityChat.plugin.getConfig().getLong("Global Cooldown") * 1000) - timeElapsed) / 1000;
- String timeRemainingStr = timeRemaining.toString();
- String cooldownMsg = cooldownMsgStr.replaceAll("%c%", timeRemainingStr);
- String cooldownMsgSend = serverPrefix + " " + cooldownMsg;
- sender.sendMessage(MiniMessage.miniMessage().deserialize(cooldownMsgSend));
- return true;
- }
- String cooldownMsgSend = serverPrefix + " " + cooldownMsgStr;
- ByteArrayDataOutput out = ByteStreams.newDataOutput();
- out.writeUTF(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize(cooldownMsgSend)));
- player.sendPluginMessage(McCityChat.plugin, "mccity:chat", out.toByteArray());
- return true;
- }
- }
- String message = chatPrefix + " " + prefix + sender.getName() + suffix + chatSep + color + msg;
- ByteArrayDataOutput out = ByteStreams.newDataOutput();
- out.writeUTF(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize(message)));
- player.sendPluginMessage(McCityChat.plugin, "mccity:chat", out.toByteArray());
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment