Files
src
build.gradle
settings.gradle
Code
14 961
src/main/java/com/kodari/practicebot/PracticeBotPlugin.java
package com.kodari.practicebot;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.util.Collections;
import java.util.List;
public final class PracticeBotPlugin extends JavaPlugin implements CommandExecutor, TabCompleter {
private BotManager botManager;
private BotGui botGui;
@Override
public void onEnable() {
saveResource("gui.yml", false);
GuiConfig guiConfig = new GuiConfig(YamlConfiguration.loadConfiguration(new File(getDataFolder(), "gui.yml")));
botManager = new BotManager(this, guiConfig);
botGui = new BotGui(botManager, guiConfig);
getServer().getPluginManager().registerEvents(new PracticeBotListener(botManager, botGui), this);
getCommand("bot").setExecutor(this);
getCommand("bot").setTabCompleter(this);
botManager.start();
}
@Override
public void onDisable() {
if (botManager != null) {
botManager.shutdown();
}
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player player)) {
sender.sendMessage("Only players can use this command.");
return true;
}
if (args.length == 1) {
if (args[0].equalsIgnoreCase("remove")) {
botManager.remove(player);
player.sendMessage("§cPractice bot removed.");
return true;
}
if (args[0].equalsIgnoreCase("spawn")) {
botManager.spawnOrReset(player);
return true;
}
}
botGui.open(player);
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
if (args.length == 1) {
return List.of("spawn", "remove");
}
return Collections.emptyList();
}
}