# Minecraft Coding



## Cookienation (22. Dez 2016)

```
package de.MrSchipkim.listener;

import java.io.File;

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.player.AsyncPlayerChatEvent;

import de.MrSchipkim.data.Data;

public class aSyncPlayerChatListener implements Listener{
  
   File file = new File("plugins/SkyPvP", "Beleidigungen.yml");
   FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  
   @EventHandler
   public void onChat(AsyncPlayerChatEvent e) {
      
       Player p = e.getPlayer();
       String msg = e.getMessage().toLowerCase();

       if (msg.equalsIgnoreCase(cfg.getString(""))) {
             e.setCancelled(true);
             p.sendMessage(Data.prefix + "§cBenimm dich!");
            
         }
        
        }
}
```

Ich und ein Freund coden schon etwas länger an einem Plugin.
Dieses soll jetzt ein Beleidigungs Filter haben.
Und in die Beleidigungs.yml soll man dann nur Beleidigungen reinschreiben können.

Folgender Error in der Konsole:


```
: Cannot load plugins\SkyPvP\Beleidigungen.yml
org.bukkit.configuration.InvalidConfigurationException: Top level is not a Map.
        at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:59) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:226) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:169) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:180) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at de.MrSchipkim.listener.chatlistener.<init>(chatlistener.java:18) [SkyPVP.jar:?]
        at de.MrSchipkim.main.Main.onEnable(Main.java:76) [SkyPVP.jar:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.reload(CraftServer.java:741) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.Bukkit.reload(Bukkit.java:535) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchServerCommand(CraftServer.java:627) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.aO(DedicatedServer.java:412) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:375) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_111]
[14:56:31 ERROR]: Cannot load plugins\SkyPvP\Beleidigungen.yml
org.bukkit.configuration.InvalidConfigurationException: Top level is not a Map.
        at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:59) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:226) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:169) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:180) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at de.MrSchipkim.listener.aSyncPlayerChatListener.<init>(aSyncPlayerChatListener.java:17) [SkyPVP.jar:?]
        at de.MrSchipkim.main.Main.onEnable(Main.java:82) [SkyPVP.jar:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.reload(CraftServer.java:741) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.Bukkit.reload(Bukkit.java:535) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchServerCommand(CraftServer.java:627) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.aO(DedicatedServer.java:412) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:375) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_111]
```

Die Beleidigungen.yml:

```
Spasti
Dummkopf
```

Danke für die Hilfe im Voraus!


----------



## stg (22. Dez 2016)

Deine yml-Datei entspricht offenbar nicht der erwarteten Struktur.

Näheres hier:
http://wiki.bukkit.org/Configuration_API_Reference


----------



## Cookienation (22. Dez 2016)

stg hat gesagt.:


> Deine yml-Datei entspricht offenbar nicht der erwarteten Struktur.
> 
> Näheres hier:
> http://wiki.bukkit.org/Configuration_API_Reference



Bedeutet?
Eigentlich müsste das ja funktionieren....


----------



## Joose (22. Dez 2016)

stg hat es doch schon gesagt: der Inhalt der yml Datei ist falsch formatiert
Den Link den er gepostet hat enthält Beispiele wie es ausschauen sollte.


----------



## Cookienation (22. Dez 2016)

Hab das richtig gemacht, indem ich das Plugin was hinzufügen lassen habe.
Dann kommt folgender Error, wenn ich was schreibe:


```
[15:47:48 ERROR]: Could not pass event PlayerChatEvent to SkyPVP v1.0.1
org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.PlayerConnection$7.evaluate(PlayerConnection.java:1093) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.util.Waitable.run(Waitable.java:24) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:729) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_111]
Caused by: java.lang.IllegalArgumentException: Cannot set to an empty path
        at org.apache.commons.lang.Validate.notEmpty(Validate.java:321) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.configuration.MemorySection.set(MemorySection.java:163) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.configuration.MemorySection.set(MemorySection.java:193) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at de.MrSchipkim.listener.chatlistener.on(chatlistener.java:30) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_111]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_111]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_111]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_111]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        ... 10 more
```

Und der Code vom Plugin

```
package de.MrSchipkim.listener;

import java.io.File;
import java.io.IOException;

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.player.PlayerChatEvent;

import de.MrSchipkim.data.Data;
import ru.tehkode.permissions.bukkit.PermissionsEx;

@SuppressWarnings("deprecation")
public class chatlistener implements Listener {
  
   File file = new File("plugins/SkyPvP", "Beleidigungen.yml");
   FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);

   @EventHandler
    public void on(PlayerChatEvent e) {
     String msg = e.getMessage().toLowerCase();
     String prefix = PermissionsEx.getUser(e.getPlayer()).getGroups()[0].getPrefix();
     Player p = e.getPlayer();
     e.setFormat(prefix.replaceAll("(?i)&([a-f0-9])", "\u00A7$1") + p.getDisplayName() +" §8≫ §7" + msg);
    
    
     cfg.set("Beleidigungen" + ".", "dummkopf");
     try {
         cfg.save(file);
       } catch (IOException k) {
           k.printStackTrace();
       }
     if (msg.equalsIgnoreCase(cfg.getString("Beleidigungen" + "."))) {
         e.setCancelled(true);
         p.sendMessage(Data.prefix + "§cBenimm dich!");
        
     }
    
    }
   }
```


----------



## stg (22. Dez 2016)

Vielleicht liest du dir erstmal die Doku zu der API durch, die du da benutzt, anstatt einfach drauf loszuraten...

Irgendwas stimmt jedenfalls nicht mit den Argumenten, die du an die Methode `set` übergibst.


----------

