Files
src
build.gradle
settings.gradle
Code
6 444
src/main/java/com/kodari/nethercore/NetherCorePlugin.java
package com.kodari.nethercore;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Map;
import java.util.UUID;
public final class NetherCorePlugin extends JavaPlugin implements CommandExecutor {
private NetherCoreManager manager;
@Override
public void onEnable() {
saveDefaultConfig();
manager = new NetherCoreManager(this);
manager.load();
getServer().getPluginManager().registerEvents(manager, this);
getCommand("nethercore").setExecutor(this);
manager.start();
}
@Override
public void onDisable() {
if (manager != null) {
manager.save();
}
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!sender.hasPermission("nethercore.admin")) {
sender.sendMessage(ChatColor.RED + "You do not have permission to use this command.");
return true;
}
if (args.length == 1 && args[0].equalsIgnoreCase("list")) {
Map<UUID, Location> blocks = manager.getLocations();
if (blocks.isEmpty()) {
sender.sendMessage(ChatColor.YELLOW + "There are no active Nether Cores.");
return true;
}
sender.sendMessage(ChatColor.GOLD + "Active Nether Cores:");
for (Map.Entry<UUID, Location> entry : blocks.entrySet()) {
Location location = entry.getValue();
String worldName = location.getWorld() == null ? "unknown" : location.getWorld().getName();
sender.sendMessage(ChatColor.YELLOW + entry.getKey().toString() + ChatColor.GRAY + " — "
+ worldName + " " + location.getBlockX() + ", " + location.getBlockY() + ", "
+ location.getBlockZ());
}
return true;
}
if (args.length == 2 && args[0].equalsIgnoreCase("tp")) {
UUID id;
try {
id = UUID.fromString(args[1]);
} catch (IllegalArgumentException exception) {
sender.sendMessage(ChatColor.RED + "That is not a valid Nether Core ID.");
return true;
}
Location location = manager.getLocation(id);
if (location == null || location.getWorld() == null) {
sender.sendMessage(ChatColor.RED + "No active Nether Core has that ID.");
return true;
}
if (!(sender instanceof Player player)) {
sender.sendMessage(ChatColor.RED + "Only players can teleport to Nether Cores.");
return true;
}
player.teleport(location.clone().add(0.5, 1.0, 0.5));
sender.sendMessage(ChatColor.GREEN + "Teleported to Nether Core " + id + ".");
return true;
}
sender.sendMessage(ChatColor.YELLOW + "Usage: /nethercore list | /nethercore tp <id>");
return true;
}
}