I'm making a plugin but when a start the server it gives this error massage
Error:
[16:43:41] [Server thread/ERROR]: Error occurred while enabling CustomServer v1.0-SNAPSHOT (Is it up to date?)
java.lang.IllegalArgumentException: Invalid key. Must be [a-z0-9/._-]: Custom
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:220) ~[guava-31.1-jre.jar:?]
at org.bukkit.NamespacedKey.<init>(NamespacedKey.java:84) ~[spigot-api-1.20-R0.1-SNAPSHOT.jar:?]
at org.bukkit.NamespacedKey.minecraft(NamespacedKey.java:175) ~[spigot-api-1.20-R0.1-SNAPSHOT.jar:?]
at me.entropire.customserver.CustomServer.onEnable(CustomEntropireServer.java:30) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:266) ~[spigot-api-1.20-R0.1-SNAPSHOT.jar:?]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:342) ~[spigot-api-1.20-R0.1-SNAPSHOT.jar:?]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:480) ~[spigot-api-1.20-R0.1-SNAPSHOT.jar:?]
at org.bukkit.craftbukkit.v1_20_R1.CraftServer.enablePlugin(CraftServer.java:540) ~[spigot-1.20-R0.1-SNAPSHOT.jar:3797-Spigot-7e2af8b-091027a]
at org.bukkit.craftbukkit.v1_20_R1.CraftServer.enablePlugins(CraftServer.java:454) ~[spigot-1.20-R0.1-SNAPSHOT.jar:3797-Spigot-7e2af8b-091027a]
at org.bukkit.craftbukkit.v1_20_R1.CraftServer.reload(CraftServer.java:962) ~[spigot-1.20-R0.1-SNAPSHOT.jar:3797-Spigot-7e2af8b-091027a]
at org.bukkit.Bukkit.reload(Bukkit.java:832) ~[spigot-api-1.20-R0.1-SNAPSHOT.jar:?]
at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:27) ~[spigot-api-1.20-R0.1-SNAPSHOT.jar:?]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) ~[spigot-api-1.20-R0.1-SNAPSHOT.jar:?]
at org.bukkit.craftbukkit.v1_20_R1.CraftServer.dispatchCommand(CraftServer.java:871) ~[spigot-1.20-R0.1-SNAPSHOT.jar:3797-Spigot-7e2af8b-091027a]
at org.bukkit.craftbukkit.v1_20_R1.command.BukkitCommandWrapper.run(BukkitCommandWrapper.java:50) ~[spigot-1.20-R0.1-SNAPSHOT.jar:3797-Spigot-7e2af8b-091027a]
at com.mojang.brigadier.CommandDispatcher.execute(CommandDispatcher.java:265) ~[spigot-1.20-R0.1-SNAPSHOT.jar:?]
at net.minecraft.commands.CommandDispatcher.performCommand(CommandDispatcher.java:314) ~[spigot-1.20-R0.1-SNAPSHOT.jar:3797-Spigot-7e2af8b-091027a]
at net.minecraft.commands.CommandDispatcher.a(CommandDispatcher.java:298) ~[spigot-1.20-R0.1-SNAPSHOT.jar:3797-Spigot-7e2af8b-091027a]
at net.minecraft.server.network.PlayerConnection.a(PlayerConnection.java:1960) ~[spigot-1.20-R0.1-SNAPSHOT.jar:3797-Spigot-7e2af8b-091027a]
at net.minecraft.server.network.PlayerConnection.lambda$18(PlayerConnection.java:1922) ~[spigot-1.20-R0.1-SNAPSHOT.jar:3797-Spigot-7e2af8b-091027a]
at net.minecraft.util.thread.IAsyncTaskHandler.b(SourceFile:67) ~[spigot-1.20-R0.1-SNAPSHOT.jar:3797-Spigot-7e2af8b-091027a]
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768) ~[?:?]
at net.minecraft.server.TickTask.run(SourceFile:18) ~[spigot-1.20-R0.1-SNAPSHOT.jar:3797-Spigot-7e2af8b-091027a]
at net.minecraft.util.thread.IAsyncTaskHandler.d(SourceFile:156) ~[spigot-1.20-R0.1-SNAPSHOT.jar:3797-Spigot-7e2af8b-091027a]
at net.minecraft.util.thread.IAsyncTaskHandlerReentrant.d(SourceFile:23) ~[spigot-1.20-R0.1-SNAPSHOT.jar:3797-Spigot-7e2af8b-091027a]
at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:1152) ~[spigot-1.20-R0.1-SNAPSHOT.jar:3797-Spigot-7e2af8b-091027a]
at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:1) ~[spigot-1.20-R0.1-SNAPSHOT.jar:3797-Spigot-7e2af8b-091027a]
at net.minecraft.util.thread.IAsyncTaskHandler.x(SourceFile:130) ~[spigot-1.20-R0.1-SNAPSHOT.jar:3797-Spigot-7e2af8b-091027a]
at net.minecraft.server.MinecraftServer.bg(MinecraftServer.java:1131) ~[spigot-1.20-R0.1-SNAPSHOT.jar:3797-Spigot-7e2af8b-091027a]
at net.minecraft.server.MinecraftServer.x(MinecraftServer.java:1124) ~[spigot-1.20-R0.1-SNAPSHOT.jar:3797-Spigot-7e2af8b-091027a]
at net.minecraft.util.thread.IAsyncTaskHandler.c(SourceFile:139) ~[spigot-1.20-R0.1-SNAPSHOT.jar:3797-Spigot-7e2af8b-091027a]
at net.minecraft.server.MinecraftServer.p_(MinecraftServer.java:1108) ~[spigot-1.20-R0.1-SNAPSHOT.jar:3797-Spigot-7e2af8b-091027a]
at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:1019) ~[spigot-1.20-R0.1-SNAPSHOT.jar:3797-Spigot-7e2af8b-091027a]
at net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:304) ~[spigot-1.20-R0.1-SNAPSHOT.jar:3797-Spigot-7e2af8b-091027a]
at java.lang.Thread.run(Thread.java:833) ~[?:?]
Code:
package me.user.customserver;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.io.*;
import java.util.Arrays;
import java.util.List;
public class CoinBag implements Listener {
@EventHandler
public void OnPlayerInterect(PlayerInteractEvent event) {
Player player = event.getPlayer();
if (player.getInventory().getItemInMainHand().getType() == Material.LEATHER_HORSE_ARMOR){
if (player.getInventory().getItemInMainHand().getItemMeta().getCustomModelData() == 1015) {
ItemMeta meta = player.getInventory().getItemInMainHand().getItemMeta();
if (player.getInventory().getItemInMainHand().getItemMeta().hasLore()) {
String id = meta.getLore().toString();
id = id.replaceAll("C", "");
id = id.replaceAll("i", "");
id = id.replaceAll("o", "");
id = id.replaceAll("n", "");
id = id.replaceAll("b", "");
id = id.replaceAll("a", "");
id = id.replaceAll("g", "");
id = id.replaceAll(" ", "");
String fileName = id + ".yml";
Inventory inv = Bukkit.createInventory(player, 18, "CoinBag " + id);
File file = new File("plugins/CustomServer/" + fileName);
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
if (file.exists()){
ItemStack[] contents = ((List<ItemStack>) config.get("CoinBag.contents")).toArray(new ItemStack[0]);
inv.setContents(contents);
}
player.openInventory(inv);
}
}
}
}
@EventHandler
private void onPlayerExitInv(InventoryCloseEvent e) throws IOException {
if (e.getView().getTitle().contains("CoinBag")){
String name_inv = e.getView().getTitle();
name_inv = name_inv.replaceAll("C", "");
name_inv = name_inv.replaceAll("i", "");
name_inv = name_inv.replaceAll("o", "");
name_inv = name_inv.replaceAll("n", "");
name_inv = name_inv.replaceAll("B", "");
name_inv = name_inv.replaceAll("a", "");
name_inv = name_inv.replaceAll("g", "");
name_inv = name_inv.replaceAll(" ", "");
ItemStack[] contants = e.getInventory().getContents();
String fileName = name_inv + ".yml";
File file = new File("plugins/CustomServer/" + fileName);
FileConfiguration c = YamlConfiguration.loadConfiguration(file);
c.set("CoinBag.contents", contants);
c.save(file);
}
}
}
the Error is because of this part of the code:
id = id.replaceAll(" ", "");
name_inv = name_inv.replaceAll(" ", "");
I have tried several ways to change special characters to nothing but the error does not go away. and if i remove this part of code and then the error goas away but my code breaks. can anyone tell me why this Error comes.