Files
src
build.gradle
Code
41 10,122
src/main/java/com/example/customdialogs/Main.java
package com.example.customdialogs;
import com.example.customdialogs.home.HomeCommand;
import com.example.customdialogs.home.HomeManager;
import com.example.customdialogs.afk.AfkCommand;
import com.example.customdialogs.afk.AfkManager;
import com.example.customdialogs.iplimit.IpLimitManager;
import com.example.customdialogs.item.AutoItemInAction;
import com.example.customdialogs.item.AutoPickupManager;
import com.example.customdialogs.item.ItemCommandManager;
import com.example.customdialogs.onlinetime.OnlineTimeManager;
import com.example.customdialogs.onlinetime.OnlineTimeExpansion;
import com.example.customdialogs.shop.ShopCommandExecutor;
import com.example.customdialogs.shop.ShopCommandListener;
import com.example.customdialogs.shop.ShopManager;
import com.example.customdialogs.spawn.SpawnCommand;
import com.example.customdialogs.spawn.SpawnManager;
import com.example.customdialogs.tpa.TpaCommand;
import com.example.customdialogs.tpa.TpaManager;
import com.example.customdialogs.rtp.RtpCommand;
import com.example.customdialogs.rtp.RtpManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandMap;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.plugin.java.JavaPlugin;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
public final class Main extends JavaPlugin {
private static Main instance;
private HomeManager homeManager;
private ItemCommandManager itemCommandManager;
private ShopManager shopManager;
private ShopCommandListener shopCommandListener;
private SpawnManager spawnManager;
private TpaManager tpaManager;
private RtpManager rtpManager;
private OnlineTimeManager onlineTimeManager;
private OnlineTimeExpansion onlineTimeExpansion;
private AfkManager afkManager;
private AutoItemInAction autoItemInAction;
private AutoPickupManager autoPickupManager;
private IpLimitManager ipLimitManager;
private final Map<String, DynamicDialogCommand> dynamicDialogCommands = new HashMap<>();
@Override
public void onEnable() {
instance = this;
saveDefaultConfig();
afkManager = new AfkManager(this);
getServer().getPluginManager().registerEvents(afkManager, this);
if (getCommand("afk") != null) {
getCommand("afk").setExecutor(new AfkCommand(afkManager));
}
ipLimitManager = new IpLimitManager(this);
getServer().getPluginManager().registerEvents(ipLimitManager, this);
// Home System
homeManager = new HomeManager(this);
// Home Commands & TabCompleter
HomeCommand homeCommandExecutor = new HomeCommand(this);
if (getCommand("sethome") != null) {
getCommand("sethome").setExecutor(homeCommandExecutor);
getCommand("sethome").setTabCompleter(homeCommandExecutor);
}
if (getCommand("delhome") != null) {
getCommand("delhome").setExecutor(homeCommandExecutor);
getCommand("delhome").setTabCompleter(homeCommandExecutor);
}
if (getCommand("home") != null) {
getCommand("home").setExecutor(homeCommandExecutor);
getCommand("home").setTabCompleter(homeCommandExecutor);
}
// Item Command System
itemCommandManager = new ItemCommandManager(this);
getServer().getPluginManager().registerEvents(itemCommandManager, this);
autoItemInAction = new AutoItemInAction(this);
getServer().getPluginManager().registerEvents(autoItemInAction, this);
autoPickupManager = new AutoPickupManager(this);
getServer().getPluginManager().registerEvents(autoPickupManager, this);
if (getCommand("autopickup") != null) {
getCommand("autopickup").setExecutor((sender, command, label, args) -> {
if (!(sender instanceof org.bukkit.entity.Player player)) {
sender.sendMessage("คำสั่งนี้ใช้ได้เฉพาะผู้เล่นเท่านั้น");
return true;
}
if (!autoPickupManager.checkPermission(player)) {
return true;
}
if (args.length == 0 || "toggle".equalsIgnoreCase(args[0])) {
autoPickupManager.toggle(player);
} else if ("on".equalsIgnoreCase(args[0])) {
autoPickupManager.setEnabled(player, true);
} else if ("off".equalsIgnoreCase(args[0])) {
autoPickupManager.setEnabled(player, false);
} else {
player.sendMessage(ChatColor.YELLOW + "ใช้ /autopickup [on|off|toggle]");
}
return true;
});
}
shopManager = new ShopManager(this);
shopCommandListener = new ShopCommandListener(this);
getServer().getPluginManager().registerEvents(shopCommandListener, this);
shopCommandListener.registerCommands();
if (getCommand("symenubuy") != null) {
getCommand("symenubuy").setExecutor(new ShopCommandExecutor(this, true));
}
if (getCommand("symenusell") != null) {
getCommand("symenusell").setExecutor(new ShopCommandExecutor(this, false));
}
spawnManager = new SpawnManager(this);
SpawnCommand spawnCommand = new SpawnCommand(spawnManager);
if (getCommand("setspawn") != null) {
getCommand("setspawn").setExecutor(spawnCommand);
}
if (getCommand("spawn") != null) {
getCommand("spawn").setExecutor(spawnCommand);
}
getServer().getPluginManager().registerEvents(spawnManager, this);
tpaManager = new TpaManager(this);
TpaCommand tpaCommand = new TpaCommand(tpaManager);
for (String commandName : new String[]{"tpa", "tpahere", "tpauto", "tpaccept", "tpdeny", "tpatoggle", "back"}) {
if (getCommand(commandName) != null) {
getCommand(commandName).setExecutor(tpaCommand);
getCommand(commandName).setTabCompleter(tpaCommand);
}
}
getServer().getPluginManager().registerEvents(tpaManager, this);
rtpManager = new RtpManager(this);
RtpCommand rtpCommand = new RtpCommand(rtpManager);
if (getCommand("rp") != null) {
getCommand("rp").setExecutor(rtpCommand);
getCommand("rp").setTabCompleter(rtpCommand);
}
getServer().getPluginManager().registerEvents(rtpManager, this);
onlineTimeManager = new OnlineTimeManager(this);
getServer().getPluginManager().registerEvents(onlineTimeManager, this);
if (getServer().getPluginManager().isPluginEnabled("PlaceholderAPI")) {
onlineTimeExpansion = new OnlineTimeExpansion(this, onlineTimeManager, afkManager);
onlineTimeExpansion.register();
}
// Reload Command
if (getCommand("symenureload") != null) {
getCommand("symenureload").setExecutor(this::handleReloadCommand);
}
registerDialogCommands();
}
private void registerDialogCommands() {
// Custom Dialog Commands config.yml
ConfigurationSection dialogsSection = getConfig().getConfigurationSection("dialogs");
if (dialogsSection != null) {
for (String key : dialogsSection.getKeys(false)) {
ConfigurationSection dialogConfig = dialogsSection.getConfigurationSection(key);
if (dialogConfig != null) {
String commandName = dialogConfig.getString("command");
if ("home".equalsIgnoreCase(commandName)) {
continue;
}
if (commandName == null || commandName.isBlank()) {
getLogger().warning("เมนู '" + key + "' ไม่มีค่า command ใน config.yml");
continue;
}
commandName = commandName.trim();
if (commandName.startsWith("/")) {
commandName = commandName.substring(1);
}
if (getCommand(commandName) != null) {
// Always replace the executor when registering/reloading.
// This also makes existing commands use the latest config.
getCommand(commandName).setExecutor(new DialogCommandExecutor(this, key));
} else {
registerDynamicDialogCommand(commandName, key);
}
}
}
}
}
private void registerDynamicDialogCommand(String commandName, String dialogKey) {
String normalizedName = commandName.toLowerCase(Locale.ROOT);