Files
src
build.gradle
settings.gradle
Code
6 322
src/main/java/com/kokoscode/KokosCodePlugin.java
package com.kokoscode;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.NamespacedKey;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.inventory.Inventory;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Objects;
public final class KokosCodePlugin extends JavaPlugin implements CommandExecutor {
private NamespacedKey toolKey;
private String menuTitle;
@Override
public void onEnable() {
this.toolKey = new NamespacedKey(this, "kokoscode-tool");
this.menuTitle = color("&8KokosCode Tools");
PluginCommand command = Objects.requireNonNull(getCommand("guikokoscode"), "guikokoscode is missing from plugin.yml");
command.setExecutor(this);
Listener listener = new ToolListener(this);
Bukkit.getPluginManager().registerEvents(listener, this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player player)) {
sender.sendMessage("Only players can open this menu.");
return true;
}
player.openInventory(createMenu());
return true;
}
private Inventory createMenu() {
Inventory inventory = Bukkit.createInventory(null, 27, menuTitle);
inventory.setItem(11, ToolItems.createMiningPickaxe(toolKey));
inventory.setItem(15, ToolItems.createTreeAxe(toolKey));
return inventory;
}
public NamespacedKey getToolKey() {
return toolKey;
}
public String getMenuTitle() {
return menuTitle;
}
public static String color(String text) {
return ChatColor.translateAlternateColorCodes('&', text);
}
}