.itsmespark

Convert to .jar plugin

Kodari AI
KodariNov 2 at 1:04 pm 1

To get your plugin as a .jar:

  1. On desktop, click Compile in the top bar. On phone, tap ⋮ → Compile Project.

  2. Click Compile in the window.

  3. Once it succeeds, click Download on the build or Download {name}.jar in the chat.

Kodari can make mistakes. Review important code before using.
Files
src
pom.xml
README.md
Code
8 255
src/main/java/com/spark/lxworldguard/LxWorldGuard.java
package com.spark.lxworldguard;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public final class LxWorldGuard extends JavaPlugin {
    private static final Pattern HEX = Pattern.compile("(?i)&#([0-9a-f]{6})");
    private ProtectionListener protectionListener;

    @Override
    public void onEnable() {
        saveResource("settings.yml", false);
        saveResource("messages.yml", false);
        reloadLocalFiles();
        protectionListener = new ProtectionListener(this);
        getServer().getPluginManager().registerEvents(protectionListener, this);
        getLogger().info("LxWorldGuard enabled. Made by Spark.");
    }

    public void reloadLocalFiles() {
        reloadConfig();
        // Keep the requested separate settings.yml and messages.yml files.
        settings = YamlFiles.load(this, "settings.yml");
        messages = YamlFiles.load(this, "messages.yml");
    }

    private org.bukkit.configuration.file.FileConfiguration settings;
    private org.bukkit.configuration.file.FileConfiguration messages;

    public org.bukkit.configuration.file.FileConfiguration settings() { return settings; }
    public org.bukkit.configuration.file.FileConfiguration messages() { return messages; }

    public String message(String key) {
        return color(messages.getString(key, "&cMissing message: " + key));
    }

    public static String color(String input) {
        if (input == null) return "";
        Matcher matcher = HEX.matcher(input);
        StringBuffer output = new StringBuffer();
        while (matcher.find()) {
            String hex = matcher.group(1);
            StringBuilder replacement = new StringBuilder("§x");
            for (char c : hex.toCharArray()) replacement.append('§').append(c);
            matcher.appendReplacement(output, Matcher.quoteReplacement(replacement.toString()));
        }
        matcher.appendTail(output);
        return ChatColor.translateAlternateColorCodes('&', output.toString());
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
            if (!sender.hasPermission("lxworldguard.admin")) {
                sender.sendMessage(message("no-permission"));
                return true;
            }
            reloadLocalFiles();
            sender.sendMessage(message("reloaded"));
            return true;
        }
        sender.sendMessage(color("&#ff0000LxWorldGuard &7by Spark &8| &fUse: &#ff0000/" + label + " reload"));
        return true;
    }
}