I have this plugin, and it basically players are able to create parties. The data for them are stored in a YAML File.
parties:
mynewparteh:
name: MyNewParteh
leader: Dr_Derek
balance: 0
policies:
- Default policy
members:
- Dr_Derek
I want to make it so when the party leader runs '/party delete', for an example, it would check what party they are a member of, first of all, and if they are leader.
The problem is, I do not know how to check if a player's name belongs to a list of members in a party without specifying the party itself?
int partyListLength = config.getConfigurationSection("parties").getKeys(false).size();
String[] partyList = config.getConfigurationSection("parties").getKeys(false).toArray(new String[partyListLength]);
for (int i = 0; i < partyListLength; i++)
{
if (config.getString("parties."+partyList[i]+".leader") == player.getName())
{
player.sendMessage(ChatColor.GREEN + "Party deleted!");
config.set("parties."+partyList[i], null);
saveConfig();
}
}
In esscense, I've been suggested to use getConfigurationSection(), and I attempt to convert the set to an array, I then use a for loop to go through all of the data and check for the player's name. The problem is in the console, I get ArrayIndexOutOfBoundsException, so obviously there is an issue converting the set to an array, and I need an array in order to work with indexes. How can I get around this?
From console:
[20:50:03] [Server thread/ERROR]: null
org.bukkit.command.CommandException: Unhandled exception executing command 'party' in plugin Parties v1.0
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit.jar:git-Spigot-b8f6402-a646500]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:181) ~[craftbukkit.jar:git-Spigot-b8f6402-a646500]
at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServer.java:642) ~[craftbukkit.jar:git-Spigot-b8f6402-a646500]
at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand(PlayerConnection.java:1105) [craftbukkit.jar:git-Spigot-b8f6402-a646500]
at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:940) [craftbukkit.jar:git-Spigot-b8f6402-a646500]
at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java:26) [craftbukkit.jar:git-Spigot-b8f6402-a646500]
at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java:53) [craftbukkit.jar:git-Spigot-b8f6402-a646500]
at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [craftbukkit.jar:git-Spigot-b8f6402-a646500]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_40]
at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_40]
at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:683) [craftbukkit.jar:git-Spigot-b8f6402-a646500]
at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:316) [craftbukkit.jar:git-Spigot-b8f6402-a646500]
at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:623) [craftbukkit.jar:git-Spigot-b8f6402-a646500]
at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:526) [craftbukkit.jar:git-Spigot-b8f6402-a646500]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_40]
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
at me.penghst.Parties.Main.onCommand(Main.java:212) ~[?:?]
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)