leonsky_24

Baue eine EssentialsX altanative, mit allen möglichen commands und fubktionen! Mache das wenn mann ein command eingibt es vorgeschlagen bekommt wir der command lauten könnte!

Kodari AI
KodariJul 22 at 5:23 pm 5

Ich habe mir das gesamte Projekt angesehen. Es gibt noch einige fehlende Commands und vor allem die Command-Suggestion (wenn ein Befehl falsch eingegeben wird, sollen ähnliche vorgeschlagen werden). Hier ist der Plan:

  1. CommandManager — Suggestion-System: bei unbekanntem Command werden ähnliche Befehle vorgeschlagen (Levenshtein)

  2. ItemCommand — rename hinzufügen (in plugin.yml registriert, aber nicht implementiert)

  3. ChatCommand/ModerationCommand — socialspy hinzufügen

  4. PlayerCommand — vanish, nick hinzufügen

  5. plugin.yml — neue Commands registrieren

Los geht’s mit Task 1:

Task 1 done — Command Suggestion ist implementiert. Jetzt Task 2–5 parallel

Now add vanish, nick, and socialspy to plugin.yml:

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
README.md
Code
31 5,148
src/main/java/com/novaessentials/NovaEssentials.java
package com.novaessentials;

import com.novaessentials.command.*;
import com.novaessentials.storage.*;
import com.novaessentials.util.MessageUtil;
import com.novaessentials.util.CooldownManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class NovaEssentials extends JavaPlugin {

    private static NovaEssentials instance;
    private MessageUtil messageUtil;
    private CooldownManager cooldownManager;
    private PlayerDataManager playerDataManager;
    private ServerDataManager serverDataManager;
    private EconomyManager economyManager;
    private CommandManager commandManager;
    private YamlConfiguration messagesConfig;
    private File messagesFile;
    private Map<UUID, UUID> lastMessageSenders;
    private Map<UUID, UUID> teleportRequests;
    private Map<UUID, Long> teleportRequestTimestamps;
    private Map<UUID, Boolean> teleportRequestHere;

    @Override
    public void onEnable() {
        instance = this;
        saveDefaultConfig();
        saveResource("messages.yml", false);

        messagesFile = new File(getDataFolder(), "messages.yml");
        messagesConfig = YamlConfiguration.loadConfiguration(messagesFile);

        messageUtil = new MessageUtil(this);
        cooldownManager = new CooldownManager();
        playerDataManager = new PlayerDataManager(this);
        serverDataManager = new ServerDataManager(this);
        economyManager = new EconomyManager(this);

        lastMessageSenders = new HashMap<>();
        teleportRequests = new HashMap<>();
        teleportRequestTimestamps = new HashMap<>();
        teleportRequestHere = new HashMap<>();

        commandManager = new CommandManager(this);

        getServer().getPluginManager().registerEvents(new NovaEssentialsListener(this), this);

        getLogger().info("NovaEssentials v" + getDescription().getVersion() + " enabled!");
    }

    @Override
    public void onDisable() {
        playerDataManager.saveAll();
        serverDataManager.saveAll();
        economyManager.saveAll();
        getLogger().info("NovaEssentials disabled!");
    }

    public static NovaEssentials getInstance() {
        return instance;
    }

    public MessageUtil getMessageUtil() {
        return messageUtil;
    }

    public CooldownManager getCooldownManager() {
        return cooldownManager;
    }

    public PlayerDataManager getPlayerDataManager() {
        return playerDataManager;
    }

    public ServerDataManager getServerDataManager() {
        return serverDataManager;
    }

    public EconomyManager getEconomyManager() {
        return economyManager;
    }

    public YamlConfiguration getMessagesConfig() {
        return messagesConfig;
    }

    public void reloadMessages() {
        messagesConfig = YamlConfiguration.loadConfiguration(messagesFile);
    }

    public String getMessage(String key) {
        String msg = messagesConfig.getString("messages." + key);
        if (msg == null) {
            msg = getConfig().getString("messages." + key);
        }
        return msg != null ? msg : "&cMessage not found: " + key;
    }

    // Teleport request management
    public void sendTeleportRequest(Player sender, Player target) {
        teleportRequests.put(target.getUniqueId(), sender.getUniqueId());
        teleportRequestTimestamps.put(target.getUniqueId(), System.currentTimeMillis());
        teleportRequestHere.put(target.getUniqueId(), false);
    }

    public void sendTeleportHereRequest(Player sender, Player target) {
        teleportRequests.put(target.getUniqueId(), sender.getUniqueId());
        teleportRequestTimestamps.put(target.getUniqueId(), System.currentTimeMillis());
        teleportRequestHere.put(target.getUniqueId(), true);
    }

    public UUID getTeleportRequester(Player player) {
        return teleportRequests.get(player.getUniqueId());
    }

    public boolean isTeleportHere(Player player) {
        return teleportRequestHere.getOrDefault(player.getUniqueId(), false);
    }

    public void removeTeleportRequest(Player player) {
        teleportRequests.remove(player.getUniqueId());
        teleportRequestTimestamps.remove(player.getUniqueId());
        teleportRequestHere.remove(player.getUniqueId());
    }

    public boolean hasTeleportRequest(Player player) {
        UUID requester = teleportRequests.get(player.getUniqueId());
        if (requester == null) return false;
        long timestamp = teleportRequestTimestamps.getOrDefault(player.getUniqueId(), 0L);
        int timeout = getConfig().getInt("teleport.tpa-timeout", 30);
        if (System.currentTimeMillis() - timestamp > timeout * 1000L) {
            removeTeleportRequest(player);
            return false;
        }
        return true;
    }

    // Last message tracking
    public void setLastMessageSender(Player receiver, Player sender) {
        lastMessageSenders.put(receiver.getUniqueId(), sender.getUniqueId());
    }

    public UUID getLastMessageSender(Player player) {
        return lastMessageSenders.get(player.getUniqueId());
    }

    // Spawn location
    public Location getSpawnLocation() {
        String worldName = getConfig().getString("spawn.world", "world");
        World world = Bukkit.getWorld(worldName);
        if (world == null) return null;
        double x = getConfig().getDouble("spawn.x", 0);
        double y = getConfig().getDouble("spawn.y", 64);
        double z = getConfig().getDouble("spawn.z", 0);
        float yaw = (float) getConfig().getDouble("spawn.yaw", 0);
        float pitch = (float) getConfig().getDouble("spawn.pitch", 0);
        return new Location(world, x, y, z, yaw, pitch);
    }

    public void setSpawnLocation(Location location) {
        getConfig().set("spawn.world", location.getWorld().getName());
        getConfig().set("spawn.x", location.getX());
        getConfig().set("spawn.y", location.getY());
        getConfig().set("spawn.z", location.getZ());
        getConfig().set("spawn.yaw", (double) location.getYaw());
        getConfig().set("spawn.pitch", (double) location.getPitch());
        saveConfig();
    }
}