Ich möchte mit Java ein Plugin für 1.20.4 programmieren und habe mir ein Code von ChatGPT schreiben lassen.
package de.diamanthoe.plugin;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.CommandExecutor;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.Location;
public class NaviSystem extends JavaPlugin implements CommandExecutor {
@Override
public void onEnable() {
// Register commands
getCommand("navi").setExecutor(this);
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("Dieser Befehl kann nur von Spielern ausgeführt werden.");
return true;
}
Player player = (Player) sender;
if (cmd.getName().equalsIgnoreCase("navi")) {
if (args.length >= 1) {
if (args[0].equalsIgnoreCase("save")) {
if (args.length >= 2) {
savePoint(args[1], player.getLocation());
sender.sendMessage("Punkt gespeichert unter: " + args[1]);
} else {
sender.sendMessage("Verwendung: /navi save [Name]");
}
} else {
if (args.length >= 3) {
try {
double x = Double.parseDouble(args[0]);
double y = Double.parseDouble(args[1]);
double z = Double.parseDouble(args[2]);
Location target = new Location(player.getWorld(), x, y, z);
createParticleTrail(player, target);
} catch (NumberFormatException e) {
sender.sendMessage("Ungültige Koordinaten.");
}
} else {
sender.sendMessage("Verwendung: /navi <x y z>");
}
}
} else {
sender.sendMessage("Verwendung: /navi <x y z>");
}
}
return true;
}
private void createParticleTrail(Player player, Location target) {
Location playerLocation = player.getLocation();
player.spawnParticle(Particle.REDSTONE, playerLocation, 0, target.getX(), target.getY(), target.getZ(), 10);
}
private void savePoint(String name, Location location) {
FileConfiguration config = getConfig();
config.set("points." + name + ".world", location.getWorld().getName());
config.set("points." + name + ".x", location.getX());
config.set("points." + name + ".y", location.getY());
config.set("points." + name + ".z", location.getZ());
saveConfig();
}
private void openPointsGUI(Player player) {
Inventory gui = getServer().createInventory(null, 9, "Gespeicherte Punkte");
ConfigurationSection pointsSection = getConfig().getConfigurationSection("points");
if (pointsSection != null) {
for (String pointName : pointsSection.getKeys(false)) {
ConfigurationSection pointConfig = pointsSection.getConfigurationSection(pointName);
if (pointConfig != null) {
String worldName = pointConfig.getString("world");
double x = pointConfig.getDouble("x");
double y = pointConfig.getDouble("y");
double z = pointConfig.getDouble("z");
ItemStack pointItem = createPointItem(worldName, x, y, z);
gui.addItem(pointItem);
}
}
}
player.openInventory(gui);
}
private ItemStack createPointItem(String worldName, double x, double y, double z) {
ItemStack item = new ItemStack(Material.COMPASS);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(worldName + " - " + x + ", " + y + ", " + z);
item.setItemMeta(meta);
return item;
}
}
Das Problem ist, dass da total viel rot unterstrichen wird, was wahrscheinlich auf die Imports zurückzuführen ist. Die Imports selbst sind teilweise ebenso rot interstrichen (org.bukkit).
Ich benutze das JDK 17 und Java SE 1.8.