Solved NullPointerExeption

Discussion in 'Plugin Development' started by amatokus, Apr 21, 2014.

Thread Status:
Not open for further replies.
  1. Hi all!

    I'm having this Error:(I founded out it's a NullPointerExeption)

    Code:
    [19:57:01 INFO]: Permissions listed in as player-commands will be given to all u
    sers.
    [19:57:01 INFO]: Server permissions file permissions.yml is empty, ignoring it
    [19:57:01 INFO]: Done (1,663s)! For help, type "help" or "?"
    [19:57:02 INFO]: [Vault] Checking for Updates:
    [19:57:02 INFO]: [Vault] No new version available
    >pl
    [19:57:03 INFO]: Plugins (3): Vault, BetterAchievement, Essentials
    [19:57:38 INFO]: UUID of player amatokus is 593e1aca42fb4f8ba68f97fae3a84e08
    [19:57:38 INFO]: amatokus[/127.0.0.1:53903] logged in with entity id 323 at ([wo
    rld] -199.5, 72.0, -78.5)
    [19:57:40 ERROR]: Could not pass event PlayerAchievementAwardedEvent to BetterAc
    hievement v0.0.1
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:320) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:486) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:471) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.handleStatisti
    csIncrease(CraftEventFactory.java:775) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3
    020jnks]
            at net.minecraft.server.v1_7_R1.StatisticManager.b(StatisticManager.java
    :24) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.EntityPlayer.a(EntityPlayer.java:809) [c
    raftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.EntityHuman.a(EntityHuman.java:1230) [cr
    aftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java
    :1147) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.PacketPlayInClientCommand.a(SourceFile:5
    0) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.PacketPlayInClientCommand.handle(SourceF
    ile:8) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craf
    tbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:6
    55) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:2
    50) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:5
    45) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    :457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    17) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    Caused by: java.lang.NullPointerException
            at com.gmail.amatokus8669.plugin.betterachievements.Events.onPlayerAchie
    vementAwarded(Events.java:32) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0
    _45]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0
    _45]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
    .7.0_45]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_45]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:318) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            ... 17 more
    [19:58:00 INFO]: amatokus lost connection: Disconnected
    [19:58:00 INFO]: amatokus left the game.
    >


    This is my Main Class:

    Code:java
    1. package com.gmail.amatokus8669.plugin.betterachievements;
    2.  
    3.  
    4. import java.util.logging.Logger;
    5.  
    6. import net.milkbowl.vault.economy.Economy;
    7.  
    8. import org.bukkit.Bukkit;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.plugin.RegisteredServiceProvider;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13.  
    14.  
    15. public class Main extends JavaPlugin{
    16.  
    17. private static final Logger log = Logger.getLogger("Minecraft");
    18. public static Economy econ = null;
    19. private boolean ecoworks = false;
    20.  
    21.  
    22.  
    23. @Override
    24. public void onEnable(){
    25.  
    26. if (!setupEconomy() ) {
    27. log.severe(String.format("[%s] - Economy Disabled due to no Vault dependency found!", getDescription().getName()));
    28. return;
    29. }else{
    30. ecoworks = true;
    31. }
    32. Listener Events = new Events(null);
    33. new Events(this);
    34. Bukkit.getServer().getPluginManager().registerEvents(Events, this);
    35. getLogger().info("Enabling the BetterAchievement Plugin");
    36. getLogger().info("Check bukkit DevPage for updates!");
    37. }
    38.  
    39.  
    40.  
    41. @Override
    42. public void onDisable(){
    43.  
    44. log.info(String.format("[%s] Disabled Version %s", getDescription().getName(), getDescription().getVersion()));
    45.  
    46. }
    47.  
    48.  
    49. //Vault economy soft-depend
    50. private boolean setupEconomy() {
    51. if (getServer().getPluginManager().getPlugin("Vault") == null) {
    52. return false;
    53. }
    54. RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
    55. if (rsp == null) {
    56. return false;
    57. }
    58. econ = rsp.getProvider();
    59. return econ != null;
    60. }
    61.  
    62. }



    And this is my Events Class:

    Code:java
    1. package com.gmail.amatokus8669.plugin.betterachievements;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.Location;
    5. import org.bukkit.Sound;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.EventPriority;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.player.PlayerAchievementAwardedEvent;
    10. import org.bukkit.potion.PotionEffect;
    11. import org.bukkit.potion.PotionEffectType;
    12.  
    13.  
    14.  
    15. public class Events implements Listener{
    16.  
    17.  
    18. Main plugin;
    19. public Events(Main plugin) {
    20. this.plugin = plugin;
    21. }
    22.  
    23. @EventHandler(priority = EventPriority.NORMAL)
    24. public void onPlayerAchievementAwarded(PlayerAchievementAwardedEvent AwEv){
    25.  
    26. Location location = AwEv.getPlayer().getLocation();
    27. String name = AwEv.getPlayer().getName();
    28.  
    29.  
    30. AwEv.getPlayer().sendMessage(ChatColor.AQUA+""+ChatColor.BOLD+"Congratulations"+ChatColor.GOLD+" "+name+ChatColor.AQUA+"!"+ChatColor.BOLD+" "+"You earned an achievement!"+ChatColor.WHITE);
    31. AwEv.getPlayer().playSound(location, Sound.LEVEL_UP, 10.0F, 0);
    32. AwEv.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.getByName(plugin.getConfig().getString("Config.Firstpot.effect")),plugin.getConfig().getInt("Config.Firstpot.time"),plugin.getConfig().getInt("Config.Firstpoot.level")));
    33. AwEv.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.getByName(plugin.getConfig().getString("Config.Secondpot.effect")),plugin.getConfig().getInt("Config.Secondpot.time"),plugin.getConfig().getInt("Config.Secondpoot.level")));
    34. AwEv.getPlayer().sendMessage(ChatColor.AQUA+"The potion effect"+ChatColor.GOLD+ChatColor.ITALIC+" "+"Speed"+" "+ChatColor.RESET+ChatColor.AQUA+"has been given to you for two minutes!"+ChatColor.WHITE);
    35. AwEv.getPlayer().sendMessage(ChatColor.AQUA+"The potion effect"+ChatColor.GOLD+ChatColor.ITALIC+" "+"Jump"+" "+ChatColor.RESET+ChatColor.AQUA+"has been given to you for two minutes!"+ChatColor.WHITE);
    36. }
    37. }





    What is wrong? :/
     
  2. Offline

    lukewizzy

    Please post your config file, it's most likely an error within that.
     
  3. Offline

    ButterSquidz

    Can you show us the config? I'm guessing one of the values is missing
     
  4. Here's the Config file:

    HTML:
    #Default Configuration File For BetterAchievements
    #_____________________
    #EXAMPLE CONFIGURATION
    #---------------------
    #
    #
    #Config:
    #    Message:Example Message
    #    Firstpot:
    #        effect:JUMP
    #        time:2400  Time is in ticks.  1 tick  =  20 seconds      1200 tick  =  1 Minutes
    #        level:1
    #    Secondpot:
    #        effect:SPEED
    #        time:1200
    #        level:2
    #
     
     
     
    #_____________
    #CONFIGURATION
    #-------------
     
     
    Config:
        Message:
        Firstpot:
            effect:JUMP
            time:2400
            level:1
        Secondpot:
            effect:SPEED
            time:1200
            level:2
    No Idea? :/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  5. Offline

    TigerHix

    message is null, and in ymls u need to leave a space after ':'s.
     
  6. Ok thx!
    Going to try it out!

    EDIT: Not working.

    nobody to help me out?

    BUMP! Please help

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  7. Code:
    Config:
        Message:
            Firstpot:
                effect: JUMP
                time: 2400
                level: 1
    You're trying to access Config.Firstpot.X when you should be accessing Config.Message.Firstpot.X.

    I believe you've got confused because of the commented bit in your config.
     
  8. Not working I enven deleted "Message:"

    Error log:


    HTML:
    [17:11:15] [Server thread/INFO]: Starting minecraft server version 1.7.2
    [17:11:15] [Server thread/INFO]: Loading properties
    [17:11:15] [Server thread/INFO]: Default game type: SURVIVAL
    [17:11:15] [Server thread/INFO]: Generating keypair
    [17:11:15] [Server thread/INFO]: Starting Minecraft server on *:25565
    [17:11:15] [Server thread/INFO]: This server is running CraftBukkit version git-Bukkit-1.7.2-R0.3-b3020jnks (MC: 1.7.2) (Implementing API version 1.7.2-R0.3)
    [17:11:15] [Server thread/INFO]: [Vault] Loading Vault v1.2.31-b411
    [17:11:15] [Server thread/INFO]: [BetterAchievement] Loading BetterAchievement v0.1
    [17:11:15] [Server thread/INFO]: [Essentials] Loading Essentials v2.13.1
    [17:11:15] [Server thread/INFO]: [Vault] Enabling Vault v1.2.31-b411
    [17:11:15] [Server thread/INFO]: [Vault] [Vault][Economy] Essentials Economy found: Waiting
    [17:11:15] [Server thread/INFO]: [Vault] [Vault][Permission] SuperPermissions loaded as backup permission system.
    [17:11:16] [Server thread/INFO]: [Vault] [Vault] Enabled Version 1.2.31-b411
    [17:11:16] [Server thread/INFO]: Preparing level "world"
    [17:11:16] [Server thread/INFO]: Preparing start region for level 0 (Seed: 5159119540391967566)
    [17:11:16] [Thread-7/INFO]: ----- Bukkit Auto Updater -----
    [17:11:16] [Thread-7/INFO]: It appears that you're running a Beta Build, when you've specified in bukkit.yml that you prefer to run Recommended Builds.
    [17:11:16] [Thread-7/INFO]: If you would like to be kept informed about new Beta Build releases, it is recommended that you change 'preferred-channel' in your bukkit.yml to 'beta'.
    [17:11:16] [Thread-7/INFO]: With that set, you will be told whenever a new version is available for download, so that you can always keep up to date and secure with the latest fixes.
    [17:11:16] [Thread-7/INFO]: If you would like to disable this warning, simply set 'suggest-channels' to false in bukkit.yml.
    [17:11:16] [Thread-7/INFO]: ----- ------------------- -----
    [17:11:17] [Server thread/INFO]: Preparing start region for level 1 (Seed: 5159119540391967566)
    [17:11:17] [Server thread/INFO]: Preparing start region for level 2 (Seed: 5159119540391967566)
    [17:11:17] [Server thread/INFO]: [BetterAchievement] Enabling BetterAchievement v0.1
    [17:11:17] [Server thread/INFO]: [BetterAchievement] Enabling the BetterAchievement Plugin
    [17:11:17] [Server thread/INFO]: [BetterAchievement] Check bukkit DevPage for updates!
    [17:11:17] [Server thread/INFO]: [Essentials] Enabling Essentials v2.13.1
    [17:11:18] [Server thread/INFO]: [Vault][Economy] Essentials Economy hooked.
    [17:11:18] [Server thread/INFO]: Essentials: Using config file enhanced permissions.
    [17:11:18] [Server thread/INFO]: Permissions listed in as player-commands will be given to all users.
    [17:11:18] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [17:11:18] [Server thread/INFO]: Done (2,075s)! For help, type "help" or "?"
    [17:11:19] [pool-3-thread-7/INFO]: [Vault] Checking for Updates:
    [17:11:19] [pool-3-thread-7/INFO]: [Vault] No new version available
    [17:12:40] [User Authenticator #1/INFO]: UUID of player amatokus is 593e1aca42fb4f8ba68f97fae3a84e08
    [17:12:41] [Server thread/INFO]: amatokus[/127.0.0.1:65135] logged in with entity id 337 at ([world] -188.8835258778565, 74.0, -102.06612302798911)
    [17:12:54] [Server thread/ERROR]: Could not pass event PlayerAchievementAwardedEvent to BetterAchievement v0.1
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:320) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:471) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.handleStatisticsIncrease(CraftEventFactory.java:775) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.StatisticManager.b(StatisticManager.java:24) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.EntityPlayer.a(EntityPlayer.java:809) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.EntityHuman.a(EntityHuman.java:1230) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.EntityItem.b_(EntityItem.java:264) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.EntityHuman.r(EntityHuman.java:445) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.EntityHuman.e(EntityHuman.java:437) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.EntityLiving.h(EntityLiving.java:1299) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.EntityHuman.h(EntityHuman.java:162) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.EntityPlayer.i(EntityPlayer.java:240) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:342) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInFlying.a(SourceFile:137) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInLook.handle(SourceFile:98) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    Caused by: java.lang.NullPointerException
        at com.gmail.amatokus8669.plugin.betterachievements.Events.onPlayerAchievementAwarded(Events.java:32) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_45]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_45]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_45]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_45]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:318) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        ... 23 more
    [17:13:32] [Server thread/INFO]: amatokus lost connection: Internal Exception: java.io.IOException: Une connexion existante a dû être fermée par l’hôte distant
    [17:13:32] [Server thread/INFO]: amatokus left the game.
    


    BTY this is my new Config.yml:


    HTML:
    #Default Configuration File For BetterAchievements
    #_____________________
    #EXAMPLE CONFIGURATION
    #---------------------
    #
    #
    #Config:
    #    Firstpot:
    #        effect: JUMP
    #        time: 2400  Time is in ticks.  1 tick  =  20 seconds      1200 tick  =  1 Minutes
    #        level: 1
    #    Secondpot:
    #        effect: SPEED
    #        time:1 200
    #        level: 2
     
     
     
    #_____________
    #CONFIGURATION
    #-------------
     
     
    Config:
        Firstpot:
            effect: JUMP
            time: 2400
            level: 1
        Secondpot:
            effect: SPEED
            time: 1200
            level: 2
     
  9. Offline

    Slikey

    Okay found it. You misspelled this:

    Take a look at the double O!

    Edit:
    Path in config:
    Code:
    Config.Firstpot.effect
    Path in code:
    Code:
    Config.Firstpoot.effect
     
  10. thx Trying it!

    Still not working :/

    This is my New Events class:


    Code:java
    1. package com.gmail.amatokus8669.plugin.betterachievements;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.Location;
    5. import org.bukkit.Sound;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.EventPriority;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.player.PlayerAchievementAwardedEvent;
    10. import org.bukkit.potion.PotionEffect;
    11. import org.bukkit.potion.PotionEffectType;
    12.  
    13.  
    14.  
    15. public class Events implements Listener{
    16.  
    17.  
    18. Main plugin;
    19. public Events(Main plugin) {
    20. this.plugin = plugin;
    21. }
    22.  
    23. @EventHandler(priority = EventPriority.NORMAL)
    24. public void onPlayerAchievementAwarded(PlayerAchievementAwardedEvent AwEv){
    25.  
    26. Location location = AwEv.getPlayer().getLocation();
    27. String name = AwEv.getPlayer().getName();
    28.  
    29.  
    30. AwEv.getPlayer().sendMessage(ChatColor.AQUA+""+ChatColor.BOLD+"Congratulations"+ChatColor.GOLD+" "+name+ChatColor.AQUA+"!"+ChatColor.BOLD+" "+"You earned an achievement!"+ChatColor.WHITE);
    31. AwEv.getPlayer().playSound(location, Sound.LEVEL_UP, 10.0F, 0);
    32. AwEv.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.getByName(plugin.getConfig().getString("Config.Firstpot.effect")),plugin.getConfig().getInt("Config.Firstpot.time"),plugin.getConfig().getInt("Config.Firstpot.level")));
    33. AwEv.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.getByName(plugin.getConfig().getString("Config.Secondpot.effect")),plugin.getConfig().getInt("Config.Secondpot.time"),plugin.getConfig().getInt("Config.Secondpot.level")));
    34. AwEv.getPlayer().sendMessage(ChatColor.AQUA+"The potion effect"+ChatColor.GOLD+ChatColor.ITALIC+" "+"Speed"+" "+ChatColor.RESET+ChatColor.AQUA+"has been given to you for two minutes!"+ChatColor.WHITE);
    35. AwEv.getPlayer().sendMessage(ChatColor.AQUA+"The potion effect"+ChatColor.GOLD+ChatColor.ITALIC+" "+"Jump"+" "+ChatColor.RESET+ChatColor.AQUA+"has been given to you for two minutes!"+ChatColor.WHITE);
    36. }
    37. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  11. Offline

    Slikey

    Stacktrace again please?

    And place this in the Eventhandler please.
    Code:java
    1.  
    2. System.out.println(plugin);
    3. System.out.println(plugin.getConfig());
    4. System.out.println(plugin.getConfig().getInt("Config.Firstpot.level"));
    5.  


    And upload a new stacktrace
     
  12. Offline

    Maurdekye

    amatokus No, they're all wrong. On lines 32 and 33, your code looks like this;
    Code:java
    1. Listener Events = new Events(null);
    2. new Events(this);

    I'm not sure what you really mean to accomplish, but you're doing it wrong nonetheless. Replace those lines with this;
    Code:java
    1. Listener Events = new Events(this);

    I'm pretty sure it was just something you missed.
     
  13. Offline

    Slikey


    Yep. Then the plugin causes the NullPointer in the other lines..

    amatokus Please read yourself through the Java-Conventions. Always start variable-name with a lowercase letter!
     
  14. Offline

    Slikey

    Events.java
    Show Spoiler
    Code:java
    1. import org.bukkit.ChatColor;
    2. import org.bukkit.Location;
    3. import org.bukkit.Sound;
    4. import org.bukkit.event.EventHandler;
    5. import org.bukkit.event.EventPriority;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.player.PlayerAchievementAwardedEvent;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9. import org.bukkit.potion.PotionEffect;
    10. import org.bukkit.potion.PotionEffectType;
    11.  
    12. public class Events implements Listener {
    13.  
    14. JavaPlugin plugin;
    15.  
    16. public Events(JavaPlugin plugin) {
    17. this.plugin = plugin;
    18. }
    19.  
    20. @EventHandler(priority = EventPriority.NORMAL)
    21. public void onPlayerAchievementAwarded(PlayerAchievementAwardedEvent event) {
    22. Location location = event.getPlayer().getLocation();
    23. String name = event.getPlayer().getName();
    24.  
    25. event.getPlayer().sendMessage(ChatColor.AQUA + "" + ChatColor.BOLD + "Congratulations" + ChatColor.GOLD + " " + name + ChatColor.AQUA + "!" + ChatColor.BOLD + " " + "You earned an achievement!" + ChatColor.WHITE);
    26. event.getPlayer().playSound(location, Sound.LEVEL_UP, 10.0F, 0);
    27. event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.getByName(plugin.getConfig().getString("config.firstpot.effect")), plugin.getConfig().getInt("config.firstpot.time"), plugin.getConfig().getInt("config.firstpot.level")));
    28. event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.getByName(plugin.getConfig().getString("config.cecondpot.effect")), plugin.getConfig().getInt("config.secondpot.time"), plugin.getConfig().getInt("config.secondpot.level")));
    29. event.getPlayer().sendMessage(ChatColor.AQUA + "The potion effect" + ChatColor.GOLD + ChatColor.ITALIC + " " + "Speed" + " " + ChatColor.RESET + ChatColor.AQUA + "has been given to you for two minutes!" + ChatColor.WHITE);
    30. event.getPlayer().sendMessage(ChatColor.AQUA + "The potion effect" + ChatColor.GOLD + ChatColor.ITALIC + " " + "Jump" + " " + ChatColor.RESET + ChatColor.AQUA + "has been given to you for two minutes!" + ChatColor.WHITE);
    31. }
    32. }


    Main.java
    Show Spoiler
    Code:java
    1. import java.util.logging.Logger;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.event.Listener;
    5. import org.bukkit.plugin.RegisteredServiceProvider;
    6. import org.bukkit.plugin.java.JavaPlugin;
    7.  
    8. public class Main extends JavaPlugin {
    9.  
    10. private static final Logger log = Logger.getLogger("Minecraft");
    11. public static Economy econ = null;
    12. private boolean ecoworks = false;
    13.  
    14. @Override
    15. public void onEnable() {
    16. if (!setupEconomy()) {
    17. log.severe(String.format("[%s] - Economy Disabled due to no Vault dependency found!", getDescription().getName()));
    18. return; // TODO Return wont disable the plugin itself.
    19. } else {
    20. ecoworks = true;
    21. }
    22.  
    23. Listener eventsListener = new Events(this);
    24. Bukkit.getServer().getPluginManager().registerEvents(eventsListener, this);
    25. getLogger().info("Enabling the BetterAchievement Plugin");
    26. getLogger().info("Check bukkit DevPage for updates!");
    27. }
    28.  
    29. @Override
    30. public void onDisable() {
    31. log.info(String.format("[%s] Disabled Version %s", getDescription().getName(), getDescription().getVersion()));
    32. }
    33.  
    34. // Vault economy soft-depend
    35. private boolean setupEconomy() {
    36. if (getServer().getPluginManager().getPlugin("Vault") == null) {
    37. return false;
    38. }
    39. RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
    40. if (rsp == null) {
    41. return false;
    42. }
    43. econ = rsp.getProvider();
    44. return econ != null;
    45. }
    46.  
    47. }


    plugin.yml
    Show Spoiler

    Code:
    config:
        firstpot:
            effect: JUMP
            time: 2400
            level: 1
        secondpot:
            effect: SPEED
            time: 1200
            level: 2


    If you use eclipse please press Ctrl + Shift + F before saving. It is hard to read unclean code.

    Edit:
    For OOP reasons, please make the JavaPlugin in Events.java protected and final.
    Code:java
    1. protected final JavaPlugin plugin;


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  15. This is realy a case...still not working and brand new error:


    HTML:
    [18:38:22] [Server thread/INFO]: Starting minecraft server version 1.7.2
    [18:38:22] [Server thread/INFO]: Loading properties
    [18:38:22] [Server thread/INFO]: Default game type: SURVIVAL
    [18:38:22] [Server thread/INFO]: Generating keypair
    [18:38:23] [Server thread/INFO]: Starting Minecraft server on *:25565
    [18:38:23] [Server thread/INFO]: This server is running CraftBukkit version git-Bukkit-1.7.2-R0.3-b3020jnks (MC: 1.7.2) (Implementing API version 1.7.2-R0.3)
    [18:38:23] [Server thread/INFO]: [Vault] Loading Vault v1.2.31-b411
    [18:38:23] [Server thread/INFO]: [BetterAchievement] Loading BetterAchievement v0.1
    [18:38:23] [Server thread/INFO]: [Essentials] Loading Essentials v2.13.1
    [18:38:23] [Server thread/INFO]: [Vault] Enabling Vault v1.2.31-b411
    [18:38:23] [Server thread/INFO]: [Vault] [Vault][Economy] Essentials Economy found: Waiting
    [18:38:23] [Server thread/INFO]: [Vault] [Vault][Permission] SuperPermissions loaded as backup permission system.
    [18:38:23] [Server thread/INFO]: [Vault] [Vault] Enabled Version 1.2.31-b411
    [18:38:23] [Server thread/INFO]: Preparing level "world"
    [18:38:23] [Thread-7/INFO]: ----- Bukkit Auto Updater -----
    [18:38:23] [Thread-7/INFO]: It appears that you're running a Beta Build, when you've specified in bukkit.yml that you prefer to run Recommended Builds.
    [18:38:23] [Thread-7/INFO]: If you would like to be kept informed about new Beta Build releases, it is recommended that you change 'preferred-channel' in your bukkit.yml to 'beta'.
    [18:38:23] [Thread-7/INFO]: With that set, you will be told whenever a new version is available for download, so that you can always keep up to date and secure with the latest fixes.
    [18:38:23] [Thread-7/INFO]: If you would like to disable this warning, simply set 'suggest-channels' to false in bukkit.yml.
    [18:38:23] [Thread-7/INFO]: ----- ------------------- -----
    [18:38:23] [Server thread/INFO]: Preparing start region for level 0 (Seed: 5159119540391967566)
    [18:38:24] [Server thread/INFO]: Preparing start region for level 1 (Seed: 5159119540391967566)
    [18:38:24] [Server thread/INFO]: Preparing start region for level 2 (Seed: 5159119540391967566)
    [18:38:24] [Server thread/INFO]: [BetterAchievement] Enabling BetterAchievement v0.1
    [18:38:24] [Server thread/INFO]: [BetterAchievement] Enabling the BetterAchievement Plugin
    [18:38:24] [Server thread/INFO]: [BetterAchievement] Check bukkit DevPage for updates!
    [18:38:24] [Server thread/INFO]: [Essentials] Enabling Essentials v2.13.1
    [18:38:25] [Server thread/INFO]: [Vault][Economy] Essentials Economy hooked.
    [18:38:25] [Server thread/INFO]: Essentials: Using config file enhanced permissions.
    [18:38:25] [Server thread/INFO]: Permissions listed in as player-commands will be given to all users.
    [18:38:25] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [18:38:25] [Server thread/INFO]: Done (1,713s)! For help, type "help" or "?"
    [18:38:26] [pool-3-thread-7/INFO]: [Vault] Checking for Updates:
    [18:38:26] [pool-3-thread-7/INFO]: [Vault] No new version available
    [18:38:34] [User Authenticator #1/INFO]: UUID of player amatokus is 593e1aca42fb4f8ba68f97fae3a84e08
    [18:38:34] [Server thread/INFO]: amatokus[/127.0.0.1:53505] logged in with entity id 333 at ([world] -252.55023572316657, 79.0, -127.34808025397629)
    [18:38:36] [Server thread/ERROR]: Could not pass event PlayerAchievementAwardedEvent to BetterAchievement v0.1
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:320) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:471) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.handleStatisticsIncrease(CraftEventFactory.java:775) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.StatisticManager.b(StatisticManager.java:24) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.EntityPlayer.a(EntityPlayer.java:809) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.EntityHuman.a(EntityHuman.java:1230) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:1147) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInClientCommand.a(SourceFile:50) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInClientCommand.handle(SourceFile:8) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    Caused by: java.lang.IllegalArgumentException: name cannot be null
        at org.apache.commons.lang.Validate.notNull(Validate.java:203) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.potion.PotionEffectType.getByName(PotionEffectType.java:231) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at com.gmail.amatokus8669.plugin.betterachievements.Events.onPlayerAchievementAwarded(Events.java:34) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_45]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_45]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_45]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_45]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:318) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        ... 17 more
    still not working and brand new error:
     
  16. Offline

    Slikey

    amatokus Oh. I made a typo..
    Line 28: config.cecondpot.effect
    Should be config.secondpot.effect
     
  17. Still not working:

    HTML:
    [19:36:55] [Server thread/INFO]: Starting minecraft server version 1.7.2
    [19:36:55] [Server thread/INFO]: Loading properties
    [19:36:55] [Server thread/INFO]: Default game type: SURVIVAL
    [19:36:55] [Server thread/INFO]: Generating keypair
    [19:36:55] [Server thread/INFO]: Starting Minecraft server on *:25565
    [19:36:55] [Server thread/INFO]: This server is running CraftBukkit version git-Bukkit-1.7.2-R0.3-b3020jnks (MC: 1.7.2) (Implementing API version 1.7.2-R0.3)
    [19:36:55] [Server thread/INFO]: [Vault] Loading Vault v1.2.31-b411
    [19:36:55] [Server thread/INFO]: [BetterAchievement] Loading BetterAchievement v0.1
    [19:36:55] [Server thread/INFO]: [Essentials] Loading Essentials v2.13.1
    [19:36:55] [Server thread/INFO]: [Vault] Enabling Vault v1.2.31-b411
    [19:36:55] [Server thread/INFO]: [Vault] [Vault][Economy] Essentials Economy found: Waiting
    [19:36:55] [Server thread/INFO]: [Vault] [Vault][Permission] SuperPermissions loaded as backup permission system.
    [19:36:55] [Server thread/INFO]: [Vault] [Vault] Enabled Version 1.2.31-b411
    [19:36:55] [Thread-7/INFO]: ----- Bukkit Auto Updater -----
    [19:36:55] [Thread-7/INFO]: It appears that you're running a Beta Build, when you've specified in bukkit.yml that you prefer to run Recommended Builds.
    [19:36:55] [Thread-7/INFO]: If you would like to be kept informed about new Beta Build releases, it is recommended that you change 'preferred-channel' in your bukkit.yml to 'beta'.
    [19:36:55] [Thread-7/INFO]: With that set, you will be told whenever a new version is available for download, so that you can always keep up to date and secure with the latest fixes.
    [19:36:55] [Thread-7/INFO]: If you would like to disable this warning, simply set 'suggest-channels' to false in bukkit.yml.
    [19:36:55] [Thread-7/INFO]: ----- ------------------- -----
    [19:36:55] [Server thread/INFO]: Preparing level "world"
    [19:36:55] [Server thread/INFO]: Preparing start region for level 0 (Seed: 5159119540391967566)
    [19:36:56] [Server thread/INFO]: Preparing start region for level 1 (Seed: 5159119540391967566)
    [19:36:57] [Server thread/INFO]: Preparing start region for level 2 (Seed: 5159119540391967566)
    [19:36:57] [Server thread/INFO]: [BetterAchievement] Enabling BetterAchievement v0.1
    [19:36:57] [Server thread/INFO]: [BetterAchievement] Enabling the BetterAchievement Plugin
    [19:36:57] [Server thread/INFO]: [BetterAchievement] Check bukkit DevPage for updates!
    [19:36:57] [Server thread/INFO]: [Essentials] Enabling Essentials v2.13.1
    [19:36:57] [Server thread/INFO]: [Vault][Economy] Essentials Economy hooked.
    [19:36:57] [Server thread/INFO]: Essentials: Using config file enhanced permissions.
    [19:36:57] [Server thread/INFO]: Permissions listed in as player-commands will be given to all users.
    [19:36:57] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [19:36:57] [Server thread/INFO]: Done (1,762s)! For help, type "help" or "?"
    [19:36:59] [pool-3-thread-7/INFO]: [Vault] Checking for Updates:
    [19:36:59] [pool-3-thread-7/INFO]: [Vault] No new version available
    [19:37:02] [User Authenticator #1/INFO]: UUID of player amatokus is 593e1aca42fb4f8ba68f97fae3a84e08
    [19:37:02] [Server thread/INFO]: amatokus[/127.0.0.1:55990] logged in with entity id 331 at ([world] -252.55023572316657, 79.0, -127.34808025397629)
    [19:37:24] [Server thread/ERROR]: Could not pass event PlayerAchievementAwardedEvent to BetterAchievement v0.1
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:320) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:471) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.handleStatisticsIncrease(CraftEventFactory.java:775) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.StatisticManager.b(StatisticManager.java:24) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.EntityPlayer.a(EntityPlayer.java:809) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.EntityHuman.a(EntityHuman.java:1230) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:1147) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInClientCommand.a(SourceFile:50) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInClientCommand.handle(SourceFile:8) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    Caused by: java.lang.IllegalArgumentException: name cannot be null
        at org.apache.commons.lang.Validate.notNull(Validate.java:203) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.potion.PotionEffectType.getByName(PotionEffectType.java:231) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at com.gmail.amatokus8669.plugin.betterachievements.Events.onPlayerAchievementAwarded(Events.java:34) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_45]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_45]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_45]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_45]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:318) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        ... 17 more
    


    And Events:

    Code:java
    1. package com.gmail.amatokus8669.plugin.betterachievements;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.Location;
    5. import org.bukkit.Sound;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.EventPriority;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.player.PlayerAchievementAwardedEvent;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11. import org.bukkit.potion.PotionEffect;
    12. import org.bukkit.potion.PotionEffectType;
    13.  
    14. public class Events implements Listener {
    15.  
    16. JavaPlugin plugin;
    17.  
    18. public Events(JavaPlugin plugin) {
    19. this.plugin = plugin;
    20. }
    21.  
    22. @EventHandler(priority = EventPriority.NORMAL)
    23. public void onPlayerAchievementAwarded(PlayerAchievementAwardedEvent event) {
    24. Location location = event.getPlayer().getLocation();
    25. String name = event.getPlayer().getName();
    26.  
    27. event.getPlayer().sendMessage(
    28. ChatColor.AQUA + "" + ChatColor.BOLD + "Congratulations"
    29. + ChatColor.GOLD + " " + name + ChatColor.AQUA + "!"
    30. + ChatColor.BOLD + " " + "You earned an achievement!"
    31. + ChatColor.WHITE);
    32. event.getPlayer().playSound(location, Sound.LEVEL_UP, 10.0F, 0);
    33. event.getPlayer().addPotionEffect(
    34. new PotionEffect(PotionEffectType.getByName(plugin.getConfig()
    35. .getString("config.firstpot.effect")), plugin
    36. .getConfig().getInt("config.firstpot.time"), plugin
    37. .getConfig().getInt("config.firstpot.level")));
    38. event.getPlayer().addPotionEffect(
    39. new PotionEffect(PotionEffectType.getByName(plugin.getConfig()
    40. .getString("config.secondpot.effect")), plugin
    41. .getConfig().getInt("config.secondpot.time"), plugin
    42. .getConfig().getInt("config.secondpot.level")));
    43. event.getPlayer().sendMessage(
    44. ChatColor.AQUA + "The potion effect" + ChatColor.GOLD
    45. + ChatColor.ITALIC + " " + "Speed" + " "
    46. + ChatColor.RESET + ChatColor.AQUA
    47. + "has been given to you for two minutes!"
    48. + ChatColor.WHITE);
    49. event.getPlayer().sendMessage(
    50. ChatColor.AQUA + "The potion effect" + ChatColor.GOLD
    51. + ChatColor.ITALIC + " " + "Jump" + " "
    52. + ChatColor.RESET + ChatColor.AQUA
    53. + "has been given to you for two minutes!"
    54. + ChatColor.WHITE);
    55. }
    56. }




    As the Error says it comes from line 34 the:

    Code:java
    1. new PotionEffect(PotionEffectType.getByName(plugin.getConfig()


    HTML:
    Caused by: java.lang.IllegalArgumentException: name cannot be null
    But I have a potion Name...
     
  18. Offline

    Slikey

    Post your config.yml again please..
     
  19. Slikey

    HTML:
    #Default Configuration File For BetterAchievements
    #_____________________
    #EXAMPLE CONFIGURATION
    #---------------------
    #
    #
    #Config:
    #    Firstpot:
    #        effect: JUMP
    #        time: 2400  Time is in ticks.  1 tick  =  20 seconds      1200 tick  =  1 Minutes
    #        level: 1
    #    Secondpot:
    #        effect: SPEED
    #        time: 1200
    #        level: 2
     
     
     
    #_____________
    #CONFIGURATION
    #-------------
     
     
    config:
        firstpot:
            effect: JUMP
            time: 2400
            level: 1
        secondpot:
            effect: SPEED
            time: 1200
            level: 2
     
  20. Offline

    Slikey

    Please remove everything before "config:"
     
  21. Still not working. I think it's the way I use the new

    PotionEffect(PotionEffectType.getByName(plugin.getConfig()

    It's the only thing that is on line 34... So I'm almost sure it's that but .. how could I do?

    Any Idea?
     
  22. Offline

    Slikey


    Says that you give a String to the PotionEffectType.getByName(), but the String is null, which is validated inside the Method with Validate.notNull(). Ergo: The plugin.getConfig().getString("config.firstpot.effect") returns null.
     
  23. Slikey

    Ok I get it but I don't realy understand how I should get the potion name in the Config then...

    Or how do I give a value to the potion effect name?
     
  24. Offline

    Slikey

    Oh.. You never set up an config file...

    Add this to your Main.onEnable()-Method.
    Code:java
    1. this.getConfig().addDefault("config.firstpot.effect", "JUMP");
    2. this.getConfig().addDefault("config.firstpot.time", 2400);
    3. this.getConfig().addDefault("config.firstpot.level", 1);
    4.  
    5. this.getConfig().addDefault("config.secondpot.effect", "SPEED");
    6. this.getConfig().addDefault("config.secondpot.time", 1200);
    7. this.getConfig().addDefault("config.secondpot.level", 2);
    8.  
    9. this.getConfig().options().copyDefaults(true);
    10. this.saveConfig();
     
  25. Slikey thx for the code! It's working great!


    So If the user sets config for example :

    config:
    firstpot:
    effect: DAMAGE_RESISTANCE
    ..........


    The effect will be Damage_Resistance or still JUMP?

    EDIT: I'm so idiot I.. I can test myself x)
    EDIT2:WORKING THX
     
  26. Offline

    Slikey

    @amatokusGlad it works. Have a nice day and mark this thread as solved so that other may find it better. ;)
     
Thread Status:
Not open for further replies.

Share This Page