Welcome/Auto Messages and ClearChat icon

Welcome/Auto Messages and ClearChat -----

Basic Automatic Messages and ClearChat



Simple please for Automatic Message and Clear Chat. I will add a command to restart the plugin so that the whole server doesn't have to restart after modifying the config.yml and I will add whether you want messages to be sent or not, just whether you want Automatic message to be sent or not. And I'll add so you can have unlimited amount of Custom Automatic Message.

2023-04-14_01.26.42.png


Code (Text):
package me.navaras.automaticmessage;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import me.navaras.automaticmessage.commands.ClearChatCommand;
import me.navaras.automaticmessage.commands.ReloadTabCompleter;

public class AutomaticMessage extends JavaPlugin {
    private boolean isAutomaticMessagesEnabled;
    private int taskId;

    @Override
    public void onEnable() {
        // Pokud je plugin právě nahráván
        if(getConfig().getBoolean("Automatic-Message")) {
            // Schedule automatické posílání zpráv každých 5 sekund
            Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> {
                // Získání zprávy z config.yml
                String message = getConfig().getString("Message");
                // Vypisování zprávy do konzole
                getLogger().info(message);
                // Vypisování zprávy do chatu
                Bukkit.broadcastMessage(message);
            }, 0L, 100L);
        }
        // Registrování příkazu /cc
        getCommand("cc").setExecutor(new ClearChatCommand());
        // Registrování příkazu /cc reload
        getCommand("cc").setTabCompleter(new ReloadTabCompleter());
    }

    @Override
    public void onDisable() {
        // Stop the automatic message sending task
        Bukkit.getScheduler().cancelTask(taskId);

        getLogger().info("ChatClear plugin has been disabled!");
    }

    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if (cmd.getName().equalsIgnoreCase("cc")) {
            if (sender.hasPermission("clear.c")) {
                if (args.length > 0 && args[0].equalsIgnoreCase("reload")) {
                    reloadConfig();
                    loadConfig();
                    sender.sendMessage(ChatColor.GREEN + "ChatClear config has been reloaded.");
                } else {
                    Bukkit.broadcastMessage("");
                    Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("Clear-Message")));
                    Bukkit.broadcastMessage("");
                }
                return true;
            } else {
                sender.sendMessage(ChatColor.RED + "You don't have permission to use this command!");
                return false;
            }
        }
        return false;
    }

    private void loadConfig() {
        FileConfiguration config = getConfig();
        isAutomaticMessagesEnabled = config.getBoolean("Automatic-Messages-Enabled");
        if (isAutomaticMessagesEnabled) {
            long delay = config.getLong("Automatic-Message-Delay");
            String message = config.getString("Automatic-Message");
            Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> {
                Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', message));
            }, delay * 20L, delay * 20L);
        }
    }
}


 
Code (Text):
Config:

delay: 5
message: '&cWelcome to the server!'
Resource Information
Author:
----------
Total Downloads: 65
First Release: Apr 13, 2023
Last Update: Apr 15, 2023
Category: ---------------
All-Time Rating:
0 ratings
Version -----
Released: --------------------
Downloads: ------
Version Rating:
----------------------
-- ratings