Solved Could not pas event PlayerJoinEvent

Discussion in 'Plugin Development' started by niels1k, Dec 4, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    niels1k

    Code:
    18:02:02 [INFO] [Niels1K] Enabling Niels1K v0.1
    18:02:02 [INFO] [Niels1K] Niels1K Plugin Has Been Enabled!
    18:02:02 [INFO] Server permissions file permissions.yml is empty, ignoring it
    18:02:02 [INFO] Done (4,243s)! For help, type "help" or "?"
    18:02:20 [WARNING] Could not get latest artifact information: SocketTimeoutExcep
    tion
    18:02:41 [WARNING] Could not get preferred channel details: ConnectException
    18:04:18 [INFO] niels1k[/83.84.194.142:52505] logged in with entity id 361 at ([
    world] 163.35238741254847, 68.0, 331.6656405084921)
    18:04:18 [SEVERE] Cannot load plugins\Niels1K\config.yml
    org.bukkit.configuration.InvalidConfigurationException: while scanning an anchor
     
     in "<string>", line 10, column 17:
        onjoin: &bHello &player&! Welcome to a Niels1K s ...
                        ^
    expected alphabetic or numeric character, but found &(38)
     in "<string>", line 10, column 24:
        onjoin: &bHello &player&! Welcome to a Niels1K server!
                               ^
     
            at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlCo
    nfiguration.java:55)
            at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguratio
    n.java:138)
            at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguratio
    n.java:105)
            at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(Yam
    lConfiguration.java:175)
            at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:117)
            at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:111)
            at com.niels1k.plugin.Niels1kPlayerListener.onPlayerJoin(Niels1kPlayerLi
    stener.java:21)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:339)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62)
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:477)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:462)
            at net.minecraft.server.ServerConfigurationManagerAbstract.c(ServerConfi
    gurationManagerAbstract.java:153)
            at net.minecraft.server.ServerConfigurationManagerAbstract.a(ServerConfi
    gurationManagerAbstract.java:93)
            at net.minecraft.server.NetLoginHandler.d(NetLoginHandler.java:132)
            at net.minecraft.server.NetLoginHandler.c(NetLoginHandler.java:45)
            at net.minecraft.server.DedicatedServerConnectionThread.a(DedicatedServe
    rConnectionThread.java:44)
            at net.minecraft.server.DedicatedServerConnection.b(SourceFile:29)
            at net.minecraft.server.MinecraftServer.r(MinecraftServer.java:595)
            at net.minecraft.server.DedicatedServer.r(DedicatedServer.java:222)
            at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:493)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:426)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:856)
    Caused by: while scanning an anchor
     in "<string>", line 10, column 17:
        onjoin: &bHello &player&! Welcome to a Niels1K s ...
                        ^
    expected alphabetic or numeric character, but found &(38)
     in "<string>", line 10, column 24:
        onjoin: &bHello &player&! Welcome to a Niels1K server!
                               ^
     
            at org.yaml.snakeyaml.scanner.ScannerImpl.scanAnchor(ScannerImpl.java:11
    69)
            at org.yaml.snakeyaml.scanner.ScannerImpl.fetchAnchor(ScannerImpl.java:7
    82)
            at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.ja
    va:315)
            at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:17
    9)
            at org.yaml.snakeyaml.parser.ParserImpl.parseNode(ParserImpl.java:393)
            at org.yaml.snakeyaml.parser.ParserImpl.parseBlockNodeOrIndentlessSequen
    ce(ParserImpl.java:373)
            at org.yaml.snakeyaml.parser.ParserImpl.access$2300(ParserImpl.java:117)
     
            at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingValue.produce(P
    arserImpl.java:593)
            at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:161)
            at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:146)
            at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:133)
            at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java
    :237)
            at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:160)
            at org.yaml.snakeyaml.composer.Composer.composeDocument(Composer.java:12
    3)
            at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:106)
     
            at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseCons
    tructor.java:121)
            at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:480)
            at org.yaml.snakeyaml.Yaml.load(Yaml.java:399)
            at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlCo
    nfiguration.java:53)
            ... 25 more
    18:04:18 [SEVERE] Cannot load configuration from stream
    org.bukkit.configuration.InvalidConfigurationException: while scanning an anchor
     
     in "<string>", line 10, column 17:
        onjoin: &bHello &player&! Welcome to a Niels1K s ...
                        ^
    expected alphabetic or numeric character, but found &(38)
     in "<string>", line 10, column 24:
        onjoin: &bHello &player&! Welcome to a Niels1K server!
                               ^
     
            at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlCo
    nfiguration.java:55)
            at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguratio
    n.java:138)
            at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(Yam
    lConfiguration.java:202)
            at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:121)
            at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:111)
            at com.niels1k.plugin.Niels1kPlayerListener.onPlayerJoin(Niels1kPlayerLi
    stener.java:21)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:339)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62)
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:477)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:462)
            at net.minecraft.server.ServerConfigurationManagerAbstract.c(ServerConfi
    gurationManagerAbstract.java:153)
            at net.minecraft.server.ServerConfigurationManagerAbstract.a(ServerConfi
    gurationManagerAbstract.java:93)
            at net.minecraft.server.NetLoginHandler.d(NetLoginHandler.java:132)
            at net.minecraft.server.NetLoginHandler.c(NetLoginHandler.java:45)
            at net.minecraft.server.DedicatedServerConnectionThread.a(DedicatedServe
    rConnectionThread.java:44)
            at net.minecraft.server.DedicatedServerConnection.b(SourceFile:29)
            at net.minecraft.server.MinecraftServer.r(MinecraftServer.java:595)
            at net.minecraft.server.DedicatedServer.r(DedicatedServer.java:222)
            at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:493)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:426)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:856)
    Caused by: while scanning an anchor
     in "<string>", line 10, column 17:
        onjoin: &bHello &player&! Welcome to a Niels1K s ...
                        ^
    expected alphabetic or numeric character, but found &(38)
     in "<string>", line 10, column 24:
        onjoin: &bHello &player&! Welcome to a Niels1K server!
                               ^
     
            at org.yaml.snakeyaml.scanner.ScannerImpl.scanAnchor(ScannerImpl.java:11
    69)
            at org.yaml.snakeyaml.scanner.ScannerImpl.fetchAnchor(ScannerImpl.java:7
    82)
            at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.ja
    va:315)
            at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:17
    9)
            at org.yaml.snakeyaml.parser.ParserImpl.parseNode(ParserImpl.java:393)
            at org.yaml.snakeyaml.parser.ParserImpl.parseBlockNodeOrIndentlessSequen
    ce(ParserImpl.java:373)
            at org.yaml.snakeyaml.parser.ParserImpl.access$2300(ParserImpl.java:117)
     
            at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingValue.produce(P
    arserImpl.java:593)
            at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:161)
            at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:146)
            at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:133)
            at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java
    :237)
            at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:160)
            at org.yaml.snakeyaml.composer.Composer.composeDocument(Composer.java:12
    3)
            at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:106)
     
            at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseCons
    tructor.java:121)
            at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:480)
            at org.yaml.snakeyaml.Yaml.load(Yaml.java:399)
            at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlCo
    nfiguration.java:53)
            ... 24 more
    18:04:18 [SEVERE] Could not pass event PlayerJoinEvent to Niels1K v0.1
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:341)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62)
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:477)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:462)
            at net.minecraft.server.ServerConfigurationManagerAbstract.c(ServerConfi
    gurationManagerAbstract.java:153)
            at net.minecraft.server.ServerConfigurationManagerAbstract.a(ServerConfi
    gurationManagerAbstract.java:93)
            at net.minecraft.server.NetLoginHandler.d(NetLoginHandler.java:132)
            at net.minecraft.server.NetLoginHandler.c(NetLoginHandler.java:45)
            at net.minecraft.server.DedicatedServerConnectionThread.a(DedicatedServe
    rConnectionThread.java:44)
            at net.minecraft.server.DedicatedServerConnection.b(SourceFile:29)
            at net.minecraft.server.MinecraftServer.r(MinecraftServer.java:595)
            at net.minecraft.server.DedicatedServer.r(DedicatedServer.java:222)
            at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:493)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:426)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:856)
    Caused by: java.lang.NullPointerException
            at com.niels1k.plugin.Niels1kPlayerListener.onPlayerJoin(Niels1kPlayerLi
    stener.java:21)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:339)
            ... 14 more
    18:04:33 [INFO] Connection reset
    18:04:33 [INFO] niels1k lost connection: disconnect.quitting
    This is my Main class Main.java:
    Code:
    package com.niels1k.plugin;
     
    import java.util.logging.Logger;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Main extends JavaPlugin{
    public static Main plugin;
    Logger logger = Logger.getLogger("Minecraft");
    public final Niels1kPlayerListener pl = new Niels1kPlayerListener(this);
     
     
    @Override
    public void onEnable() {
    getLogger().info("Niels1K Plugin Has Been Enabled!");
    PluginManager pm = getServer().getPluginManager();
    getCommand("niels1k").setExecutor(new Niels1kCommandExecutor(this));
    this.saveDefaultConfig();
    //Events
    pm.registerEvents(pl, this);
    }
     
    @Override
    public void onDisable() {
    getLogger().info("Niels1K Plugin Has Been Disabled!");
    }
    }
    
    And my Player listener Niels1kPlayerListener.java:
    Code:
    package com.niels1k.plugin;
     
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
     
    @SuppressWarnings("deprecation")
    public class Niels1kPlayerListener implements Listener{
     
    private Main plugin;
     
    public Niels1kPlayerListener(Main plugin) {
    this.plugin = plugin;
    }
     
    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event){
    Player player = event.getPlayer();
    event.setJoinMessage(plugin.getConfig().getString("onjoin").replace("&player&", player.getName()).replaceAll("&1", ChatColor.DARK_BLUE+"").replaceAll("&0", ChatColor.BLACK+"").replaceAll("&2", ChatColor.DARK_GREEN+"").replaceAll("&3", ChatColor.DARK_AQUA+"").replaceAll("&4", ChatColor.DARK_RED+"").replaceAll("&5", ChatColor.DARK_PURPLE+"").replaceAll("&6", ChatColor.GOLD+"").replaceAll("&7", ChatColor.GRAY+"").replaceAll("&8", ChatColor.DARK_GRAY+"").replaceAll("&9", ChatColor.LIGHT_PURPLE+"").replaceAll("&a", ChatColor.GREEN+"").replaceAll("&b", ChatColor.AQUA+"").replaceAll("&c", ChatColor.RED+"").replaceAll("&e", ChatColor.YELLOW+"").replaceAll("&f", ChatColor.WHITE+"").replaceAll("&m", ChatColor.STRIKETHROUGH+"").replaceAll("&n", ChatColor.UNDERLINE+"").replaceAll("&l", ChatColor.BOLD+"").replaceAll("&k", ChatColor.MAGIC+"").replaceAll("&o", ChatColor.ITALIC+""));
    }
    }
    And my config.yml:
    Code:
    ##########################
    # Default Niels1K Config #
    ##########################
    # www.niels1k.comoj.com  #
    ##########################
     
    #Set the player join message
    #onjoin: <message>
    #Color Codes can be use. Notice that the color pink (&d) doesn't work
    onjoin: &bHello &player&! Welcome to a Niels1K server!
    Please help
     
  2. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    The plugin field in your listener is null.

    Also why are you individually replacing chat colors when you could use the translate alternate color codes method?
     
  3. Offline

    gomeow

    What is line 17 of the player listener?
     
  4. Offline

    niels1k

    I'm sorry, what?!
    I am really new to making plugins, watched a few tuts but i tought i understood it. Can you explain what you mean by "The plugin field in your listener is null"?
     
  5. Offline

    fireblast709

    It is something very basic. You never initialize plugin, and so it is null. Just add a constructor to the class that implements Listener and let it use one parameter of the type Main (the main class of your plugin).
    Code:java
    1. public Main plugin;
    2.  
    3. Niels1kPlayerListener(Main p)
    4. {
    5. this.plugin = p;
    6. }

    Also, please try to avoid static as it can cause memory leaks (and it is unneccesary in this case). Next initialize your listener class like this:
    Code:java
    1. new Niels1kPlayerListener(this);

    is your main class
     
  6. In your class Niels1kPlayerListener you have a variable called plugin:
    Code:
    public static Main plugin;
    that variable is null because you didn't assign a value to it.
    Just do it this way:
    Code:
    public Main plugin;
     
    public Niels1kPlayerListener(Main plugin) {
        this.plugin = plugin;
    }
    that works.

    Than you also have to edit your Main class:
    Code:
    public final Niels1kPlayerListener pl = new Niels1kPlayerListener(this); // added "this"
    Greetz blackwolf12333

    EDIT: got ninja'd:p
     
  7. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    This sounds like you aren't new to Bukkit so much as new to Java in general. My suggestion is taking a few weeks to learn Java first, then come back and play with Bukkit with a firmer grasp on the language.
     
  8. Offline

    niels1k

    Updated thread, still doesnt work.
     
  9. In your config you have this line:
    Code:
    onjoin: &bHello &player&! Welcome to a Niels1K server!
    But you can't have '&' as the first character of that sentence.
     
  10. Offline

    niels1k

    Ok. I now made that you dont need to do
    Code:
    &bHello &player&
    But instead
    Code:
    b&Hello player&
    And it works.

    THANKS to everyone who replied to this thread for your help and support!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
Thread Status:
Not open for further replies.

Share This Page