Error when write Location in config.

Discussion in 'Spigot Plugin Development' started by Fede1132, May 26, 2018.

  1. Hi i get this error:

    [17:11:31 ERROR]: Could not pass event PlayerBedEnterEvent to AdvancedSurvival v1.0
    org.bukkit.event.EventException: null
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[server.jar:git-Spigot-2086bb0-d0a3620]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[server.jar:git-Spigot-2086bb0-d0a3620]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:500) [server.jar:git-Spigot-2086bb0-d0a3620]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:485) [server.jar:git-Spigot-2086bb0-d0a3620]
    at net.minecraft.server.v1_12_R1.EntityHuman.a(EntityHuman.java:1236) [server.jar:git-Spigot-2086bb0-d0a3620]
    at net.minecraft.server.v1_12_R1.EntityPlayer.a(EntityPlayer.java:658) [server.jar:git-Spigot-2086bb0-d0a3620]
    at net.minecraft.server.v1_12_R1.BlockBed.interact(SourceFile:98) [server.jar:git-Spigot-2086bb0-d0a3620]
    at net.minecraft.server.v1_12_R1.PlayerInteractManager.a(PlayerInteractManager.java:497) [server.jar:git-Spigot-2086bb0-d0a3620]
    at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:951) [server.jar:git-Spigot-2086bb0-d0a3620]
    at net.minecraft.server.v1_12_R1.PacketPlayInUseItem.a(PacketPlayInUseItem.java:37) [server.jar:git-Spigot-2086bb0-d0a3620]
    at net.minecraft.server.v1_12_R1.PacketPlayInUseItem.a(PacketPlayInUseItem.java:1) [server.jar:git-Spigot-2086bb0-d0a3620]
    at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$1.run(SourceFile:13) [server.jar:git-Spigot-2086bb0-d0a3620]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_171]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_171]
    at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) [server.jar:git-Spigot-2086bb0-d0a3620]
    at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:748) [server.jar:git-Spigot-2086bb0-d0a3620]
    at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) [server.jar:git-Spigot-2086bb0-d0a3620]
    at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [server.jar:git-Spigot-2086bb0-d0a3620]
    at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [server.jar:git-Spigot-2086bb0-d0a3620]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_171]
    Caused by: java.lang.IllegalArgumentException: Plugin already initialized!
    at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:183) ~[server.jar:git-Spigot-2086bb0-d0a3620]
    at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:60) ~[server.jar:git-Spigot-2086bb0-d0a3620]
    at com.gmail.fendt873.advancedsurvival.AdvancedSurvival.<init>(AdvancedSurvival.java:18) ~[?:?]
    at com.gmail.fendt873.advancedsurvival.listener.PlayerSleep.onEnter(PlayerSleep.java:32) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_171]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_171]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_171]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[server.jar:git-Spigot-2086bb0-d0a3620]
    ... 19 more
    Caused by: java.lang.IllegalStateException: Initial initialization
    at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:186) ~[server.jar:git-Spigot-2086bb0-d0a3620]
    at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:60) ~[server.jar:git-Spigot-2086bb0-d0a3620]
    at com.gmail.fendt873.advancedsurvival.AdvancedSurvival.<init>(AdvancedSurvival.java:18) ~[?:?]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_171]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:1.8.0_171]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_171]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_171]
    at java.lang.Class.newInstance(Class.java:442) ~[?:1.8.0_171]
    at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:90) ~[server.jar:git-Spigot-2086bb0-d0a3620]
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:129) ~[server.jar:git-Spigot-2086bb0-d0a3620]
    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:327) ~[server.jar:git-Spigot-2086bb0-d0a3620]
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:248) ~[server.jar:git-Spigot-2086bb0-d0a3620]
    at org.bukkit.craftbukkit.v1_12_R1.CraftServer.loadPlugins(CraftServer.java:305) ~[server.jar:git-Spigot-2086bb0-d0a3620]
    at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:205) ~[server.jar:git-Spigot-2086bb0-d0a3620]
    at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:545) ~[server.jar:git-Spigot-2086bb0-d0a3620]
    ... 1 more

    package com.gmail.fendt873.advancedsurvival.listener;

    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerBedEnterEvent;
    import org.bukkit.event.player.PlayerBedLeaveEvent;
    import org.bukkit.plugin.Plugin;

    import com.gmail.fendt873.advancedsurvival.AdvancedSurvival;

    import net.md_5.bungee.api.ChatColor;

    public class PlayerSleep implements Listener {
    private int bed = 0;
    private boolean send = true;
    @EventHandler
    public void onEnter(PlayerBedEnterEvent event) {
    int online = Bukkit.getOnlinePlayers().size();
    bed = bed + 1;
    int per = (int) (bed / online * 100.0f);
    World world = event.getPlayer().getWorld();
    Bukkit.getOnlinePlayers().forEach(player -> {
    player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8> &6" + event.getPlayer().getName() + " &7sta dormendo."));
    player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8> &7Il &6" + per + "% &7sta dormendo. (Richiesto: &b25%&7)"));
    if (per > 25) {
    world.setTime(6000);
    send = false;
    }
    });
    Plugin cfg = new AdvancedSurvival().getInstance();
    if (cfg.getConfig().contains("Homes." + event.getPlayer().getName().toLowerCase())) {
    if (!event.getPlayer().getLocation().equals((Location) cfg.getConfig().get("Homes." + event.getPlayer().getName().toLowerCase()))) {
    cfg.getConfig().set("Homes." + event.getPlayer().getName().toLowerCase(), event.getPlayer().getLocation());
    cfg.saveConfig();
    event.getPlayer().sendTitle("", ChatColor.translateAlternateColorCodes('&', "&6Home impostata."), 0, 60, 0);
    }
    } else {
    cfg.getConfig().set("Homes." + event.getPlayer().getName().toLowerCase(), event.getPlayer().getLocation());
    cfg.saveConfig();
    event.getPlayer().sendTitle("", ChatColor.translateAlternateColorCodes('&', "&6Home impostata."), 0, 60, 0);
    }
    }

    @EventHandler
    public void onLeave(PlayerBedLeaveEvent event) {
    int online = Bukkit.getOnlinePlayers().size();
    bed = bed - 1;
    int per = (int) (bed / online * 100.0f);
    World world = event.getPlayer().getWorld();
    if (send == true) {
    Bukkit.getOnlinePlayers().forEach(player -> {
    player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8> &6" + event.getPlayer().getName() + " &7non sta piu' dormendo."));
    player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8> &7Il &6" + per + "% &7sta dormendo. (Richiesto: &b25%&7)"));
    if (per > 25) {
    world.setTime(6000);
    }
    });
    send = true;
    }
    }
    }
     
  2. Can anyone help me ? I need that!
     
  3. Use the code tags so your code is more readable