Config Help

Discussion in 'Plugin Development' started by Brevoort, Oct 21, 2016.

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

    Brevoort

    So I've finally made the plugin I wanted, which gives users rewards when they unlock an achievement.
    However I want to make it so that players will be able to configure their own rewards. I am incredibly new to the coding scene and know little about configuration files. So far in my listener class I've defined one thing completely, (Chance1). However the reward isn't working, why isn't it connecting the the config? (When I export the plugin it also says 'config out of sync')
    My Listener Class:
    Show Spoiler

    Code:
    package me.themedieval;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerAchievementAwardedEvent;
    public class EventListener implements Listener{
    private Medfre1 plugin;
    public EventListener(Medfre1 plugin) {
    plugin.getServer().getPluginManager().registerEvents(this, plugin);
    }
    @EventHandler
    public void aListener(PlayerAchievementAwardedEvent event) {
    Player player = event.getPlayer();
    double number = Math.random();
    if(number <= 0.2) {
    player.sendMessage(ChatColor.GREEN + "You won a prize for completing an achievement!");
    String commandd = plugin.getConfig().getString("Chance1");
    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), commandd);
    } else if(number <= 0.4) {
    player.sendMessage(ChatColor.RED + "You won a prize for completing an achievement!");
    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "give " + player.getName() + " minecraft:diamond 5");
    } else if(number <= 0.6){
    player.sendMessage(ChatColor.BLUE + "You won a prize for completing an achievement!");
    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "give " + player.getName() + " minecraft:diamond 3");
    } else if(number <= 0.8){
    player.sendMessage(ChatColor.YELLOW + "You won a prize for completing an achievement!");
    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "give " + player.getName() + " minecraft:diamond 3");
    } else if(number <= 0.97){
    player.sendMessage(ChatColor.AQUA + "You won a prize for completing an achievement!");
    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "give " + player.getName() + " minecraft:diamond 3");
    } else if(number <= 0.99){
    player.sendMessage(ChatColor.BOLD + "You won a prize for completing an achievement!");
    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "give " + player.getName() + " minecraft:diamond 3");
    }
    }
    }
    


    My main class:
    Show Spoiler
    Code:
    package me.themedieval;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Medfre1 extends JavaPlugin{
    public void onEnable() {
    registerConfig();
    saveConfig();
    new EventListener(this);
    }
    
    
    public void onDisable(){
    saveConfig();
    
    }
    private void registerConfig() {
    getConfig().options().copyDefaults(true);
    saveConfig();
    
    }
    
    
    }
    


    My config.yml
    Show Spoiler

    Code:
    #  TheMedieval's UsefulAchievement Plugin
    #  PM me on Planet Minecraft @ Brevoort43214. I want to see a server use this!
    #  Anyways this is the config soooo..... have a blast and dont break anything....
    #  Version 1.0
    Chance1: 'give player.getName() minecraft:dirt 35'
    Chance2: ''
    Chance3: ''
    Chance4: ''
    Chance5: ''
    Chance6: ''
    ######################################################
    # Put command you want in the '' however do not put the "/"
    # An example of this would be:
    # Chance1: 'give player.getName() minecraft:diamond 1'
    ######################################################
    # Probabilities:
    # Chance1 = common
    # Chance2 = common
    # Chance3 = common
    # Chance4 = common
    # Chance5 = uncommon
    # Chance6 = rare
    ######################################################
    # You can't change the probability now, so you may only have:
    #  4 common rewards
    #  1 uncommon reward
    #  1 rare reward
    ######################################################
    


    Anyone know how to make it so command is the command they put?
     
    Last edited: Oct 21, 2016
  2. Offline

    PumpMelon

    You'd have to use createSection("their name") then inside that section put their possible rewards and use something like Material.matchMaterial("material") or however your defining their reward.
    http://wiki.bukkit.org/Configuration_API_Reference
    If you want each user to define their own rewards, you would do as above.
    Also try using " " instead of ' ' for your configuration strings

    Any console errors? Not really sure what you mean by the config is out of sync.
    What I typically do when generating my config is I check if the file already exists, and if it doesn't I call the saveDefaultConfig which I'd suggest you do instead of getConfig options.
     
  3. Offline

    Brevoort

    Okay so when I export the config.yml is says "out of sync"
    Also, when I edit the config when its loaded on my server it keeps going to its default state, instead of what I changed it too.

    Also I'm not quite sure what you mean above, again, I'm pretty new to this and this is my pioneer plugin.

    The config when I load up my server:
    Code:
    #  TheMedieval's UsefulAchievement Plugin
    #  PM me on Planet Minecraft @ Brevoort43214. I want to see a server use this!
    #  Anyways this is the config soooo..... have a blast and dont break anything....
    #  Version 1.0
    
    Chance1: ''
    Chance2: ''
    Chance3: ''
    Chance4: ''
    Chance5: ''
    Chance6: ''
    
    And the Console errors I receive:
    Code:
    Loading libraries, please wait...
    [06:58:32 INFO]: Starting minecraft server version 1.10.2
    [06:58:32 INFO]: Loading properties
    [06:58:32 INFO]: Default game type: SURVIVAL
    [06:58:32 INFO]: This server is running CraftBukkit version git-Spigot-850da7e-e20928f (MC: 1.10.2) (Implementing API version 1.10.2-R0.1-SNAPSHOT)
    [06:58:32 INFO]: Debug logging is disabled
    [06:58:32 INFO]: Server Ping Player Sample Count: 12
    [06:58:32 INFO]: Using 4 threads for Netty based IO
    [06:58:32 INFO]: Generating keypair
    [06:58:32 INFO]: Starting Minecraft server on *:25565
    [06:58:32 INFO]: Using default channel type
    [06:58:33 WARN]: Plugin `Random_Teleporter v1.0' uses the space-character (0x20) in its name `Random Teleporter' - this is discouraged
    [06:58:33 INFO]: Set PluginClassLoader as parallel capable
    [06:58:33 ERROR]: Could not load 'plugins\HealthPlugin.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.IllegalArgumentException: Plugin already initialized!
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:133) ~[spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) [spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            at org.bukkit.craftbukkit.v1_10_R1.CraftServer.loadPlugins(CraftServer.java:298) [spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            at net.minecraft.server.v1_10_R1.DedicatedServer.init(DedicatedServer.java:203) [spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            at net.minecraft.server.v1_10_R1.MinecraftServer.run(MinecraftServer.java:535) [spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_101]
    Caused by: java.lang.IllegalArgumentException: Plugin already initialized!
            at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:122) ~[spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:67) ~[spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            at me.themedieval.Medfre1.<init>(Medfre1.java:5) ~[?:?]
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_101]
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_101]
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_101]
            at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_101]
            at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_101]
            at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:129) ~[spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            ... 6 more
    Caused by: java.lang.IllegalStateException: Initial initialization
            at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:125) ~[spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:67) ~[spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            at me.themedieval.Medfre1.<init>(Medfre1.java:5) ~[?:?]
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_101]
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_101]
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_101]
            at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_101]
            at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_101]
            at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:129) ~[spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            ... 6 more
    [06:58:33 INFO]: [OnlyBedrock] Loading OnlyBedrock v1.0
    [06:58:33 INFO]: [Random_Teleporter] Loading Random_Teleporter v1.0
    [06:58:33 INFO]: [BCtest] Loading BCtest v1.0
    [06:58:33 INFO]: [UsefulAchievement] Loading UsefulAchievement v0.5
    [06:58:33 INFO]: **** Beginning UUID conversion, this may take A LONG time ****
    [06:58:33 INFO]: Preparing level "world"
    [06:58:33 INFO]: -------- World Settings For [world] --------
    [06:58:33 INFO]: Allow Zombie Pigmen to spawn from portal blocks: true
    [06:58:33 INFO]: Item Despawn Rate: 6000
    [06:58:33 INFO]: Item Merge Radius: 2.5
    [06:58:33 INFO]: Zombie Aggressive Towards Villager: true
    [06:58:33 INFO]: Arrow Despawn Rate: 1200
    [06:58:33 INFO]: Max Entity Collisions: 8
    [06:58:33 INFO]: Custom Map Seeds:  Village: 10387312 Feature: 14357617
    [06:58:33 INFO]: Experience Merge Radius: 3.0
    [06:58:33 INFO]: Nerfing mobs spawned from spawners: false
    [06:58:33 INFO]: Entity Tracking Range: Pl 48 / An 48 / Mo 48 / Mi 32 / Other 64
    [06:58:33 INFO]: Cactus Growth Modifier: 100%
    [06:58:33 INFO]: Cane Growth Modifier: 100%
    [06:58:33 INFO]: Melon Growth Modifier: 100%
    [06:58:33 INFO]: Mushroom Growth Modifier: 100%
    [06:58:33 INFO]: Pumpkin Growth Modifier: 100%
    [06:58:33 INFO]: Sapling Growth Modifier: 100%
    [06:58:33 INFO]: Wheat Growth Modifier: 100%
    [06:58:33 INFO]: NetherWart Growth Modifier: 100%
    [06:58:33 INFO]: Vine Growth Modifier: 100%
    [06:58:33 INFO]: Cocoa Growth Modifier: 100%
    [06:58:33 INFO]: Hopper Transfer: 8 Hopper Check: 8 Hopper Amount: 1
    [06:58:33 INFO]: Entity Activation Range: An 32 / Mo 32 / Mi 16
    [06:58:33 INFO]: Mob Spawn Range: 4
    [06:58:33 INFO]: Max TNT Explosions: 100
    [06:58:33 INFO]: Random Lighting Updates: false
    [06:58:33 INFO]: Structure Info Saving: true
    [06:58:33 INFO]: Tile Max Tick Time: 50ms Entity max Tick Time: 50ms
    [06:58:33 INFO]: View Distance: 10
    [06:58:33 INFO]: -------- World Settings For [world_nether] --------
    [06:58:33 INFO]: Allow Zombie Pigmen to spawn from portal blocks: true
    [06:58:33 INFO]: Item Despawn Rate: 6000
    [06:58:33 INFO]: Item Merge Radius: 2.5
    [06:58:33 INFO]: Zombie Aggressive Towards Villager: true
    [06:58:33 INFO]: Arrow Despawn Rate: 1200
    [06:58:33 INFO]: Max Entity Collisions: 8
    [06:58:33 INFO]: Custom Map Seeds:  Village: 10387312 Feature: 14357617
    [06:58:33 INFO]: Experience Merge Radius: 3.0
    [06:58:33 INFO]: Nerfing mobs spawned from spawners: false
    [06:58:33 INFO]: Entity Tracking Range: Pl 48 / An 48 / Mo 48 / Mi 32 / Other 64
    [06:58:33 INFO]: Cactus Growth Modifier: 100%
    [06:58:33 INFO]: Cane Growth Modifier: 100%
    [06:58:33 INFO]: Melon Growth Modifier: 100%
    [06:58:33 INFO]: Mushroom Growth Modifier: 100%
    [06:58:33 INFO]: Pumpkin Growth Modifier: 100%
    [06:58:33 INFO]: Sapling Growth Modifier: 100%
    [06:58:33 INFO]: Wheat Growth Modifier: 100%
    [06:58:33 INFO]: NetherWart Growth Modifier: 100%
    [06:58:33 INFO]: Vine Growth Modifier: 100%
    [06:58:33 INFO]: Cocoa Growth Modifier: 100%
    [06:58:33 INFO]: Hopper Transfer: 8 Hopper Check: 8 Hopper Amount: 1
    [06:58:33 INFO]: Entity Activation Range: An 32 / Mo 32 / Mi 16
    [06:58:33 INFO]: Mob Spawn Range: 4
    [06:58:33 INFO]: Max TNT Explosions: 100
    [06:58:33 INFO]: Random Lighting Updates: false
    [06:58:33 INFO]: Structure Info Saving: true
    [06:58:33 INFO]: Tile Max Tick Time: 50ms Entity max Tick Time: 50ms
    [06:58:33 INFO]: View Distance: 10
    [06:58:33 INFO]: -------- World Settings For [world_the_end] --------
    [06:58:33 INFO]: Allow Zombie Pigmen to spawn from portal blocks: true
    [06:58:33 INFO]: Item Despawn Rate: 6000
    [06:58:33 INFO]: Item Merge Radius: 2.5
    [06:58:33 INFO]: Zombie Aggressive Towards Villager: true
    [06:58:33 INFO]: Arrow Despawn Rate: 1200
    [06:58:33 INFO]: Max Entity Collisions: 8
    [06:58:33 INFO]: Custom Map Seeds:  Village: 10387312 Feature: 14357617
    [06:58:33 INFO]: Experience Merge Radius: 3.0
    [06:58:33 INFO]: Nerfing mobs spawned from spawners: false
    [06:58:33 INFO]: Entity Tracking Range: Pl 48 / An 48 / Mo 48 / Mi 32 / Other 64
    [06:58:33 INFO]: Cactus Growth Modifier: 100%
    [06:58:33 INFO]: Cane Growth Modifier: 100%
    [06:58:33 INFO]: Melon Growth Modifier: 100%
    [06:58:33 INFO]: Mushroom Growth Modifier: 100%
    [06:58:33 INFO]: Pumpkin Growth Modifier: 100%
    [06:58:33 INFO]: Sapling Growth Modifier: 100%
    [06:58:33 INFO]: Wheat Growth Modifier: 100%
    [06:58:33 INFO]: NetherWart Growth Modifier: 100%
    [06:58:33 INFO]: Vine Growth Modifier: 100%
    [06:58:33 INFO]: Cocoa Growth Modifier: 100%
    [06:58:33 INFO]: Hopper Transfer: 8 Hopper Check: 8 Hopper Amount: 1
    [06:58:33 INFO]: Entity Activation Range: An 32 / Mo 32 / Mi 16
    [06:58:33 INFO]: Mob Spawn Range: 4
    [06:58:33 INFO]: Max TNT Explosions: 100
    [06:58:33 INFO]: Random Lighting Updates: false
    [06:58:33 INFO]: Structure Info Saving: true
    [06:58:33 INFO]: Tile Max Tick Time: 50ms Entity max Tick Time: 50ms
    [06:58:33 INFO]: View Distance: 10
    [06:58:33 INFO]: Preparing start region for level 0 (Seed: -7537255637444697363)
    [06:58:34 INFO]: Preparing spawn area: 0%
    [06:58:35 INFO]: Preparing spawn area: 52%
    [06:58:36 INFO]: Preparing spawn area: 95%
    [06:58:36 INFO]: Preparing start region for level 1 (Seed: -7537255637444697363)
    [06:58:37 INFO]: Preparing spawn area: 55%
    [06:58:38 INFO]: Preparing start region for level 2 (Seed: -7537255637444697363)
    [06:58:38 INFO]: [OnlyBedrock] Enabling OnlyBedrock v1.0
    [06:58:38 INFO]: [Random_Teleporter] Enabling Random_Teleporter v1.0
    [06:58:38 INFO]: [BCtest] Enabling BCtest v1.0
    [06:58:38 INFO]: [UsefulAchievement] Enabling UsefulAchievement v0.5
    [06:58:38 INFO]: Server permissions file permissions.yml is empty, ignoring it
    [06:58:38 INFO]: Done (5.833s)! For help, type "help" or "?"
    >
    
    
     
  4. Offline

    timtower Administrator Administrator Moderator

    @Brevoort Do you have multiple plugins that use the same package? If so: Don't do that, server can't handle that.
    And refresh the files in Eclipse, then they are synced again.
     
  5. Offline

    Brevoort

    I did this and the plugins load with no errors now, however whenever I get the reward from Chance1 it doesn't run the command and gives me back this in the console:
    Code:
    [07:47:58 ERROR]: Could not pass event PlayerAchievementAwardedEvent to UsefulAchievement v0.5
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            at org.bukkit.craftbukkit.v1_10_R1.event.CraftEventFactory.handleStatisticsIncrease(CraftEventFactory.java:986) [spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            at net.minecraft.server.v1_10_R1.StatisticManager.b(StatisticManager.java:23) [spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            at net.minecraft.server.v1_10_R1.EntityPlayer.a(EntityPlayer.java:877) [spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            at net.minecraft.server.v1_10_R1.EntityHuman.b(EntityHuman.java:1415) [spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            at net.minecraft.server.v1_10_R1.PlayerConnection.a(PlayerConnection.java:1627) [spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            at net.minecraft.server.v1_10_R1.PacketPlayInClientCommand.a(SourceFile:31) [spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            at net.minecraft.server.v1_10_R1.PacketPlayInClientCommand.a(SourceFile:8) [spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            at net.minecraft.server.v1_10_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_101]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_101]
            at net.minecraft.server.v1_10_R1.SystemUtils.a(SourceFile:45) [spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            at net.minecraft.server.v1_10_R1.MinecraftServer.D(MinecraftServer.java:732) [spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            at net.minecraft.server.v1_10_R1.DedicatedServer.D(DedicatedServer.java:400) [spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            at net.minecraft.server.v1_10_R1.MinecraftServer.C(MinecraftServer.java:668) [spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            at net.minecraft.server.v1_10_R1.MinecraftServer.run(MinecraftServer.java:567) [spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_101]
    Caused by: java.lang.NullPointerException
            at me.themedieval.EventListener.aListener(EventListener.java:21) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_101]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_101]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_101]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_101]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot-1.10.2.jar:git-Spigot-850da7e-e20928f]
            ... 19 more
    >reload
    [07:48:34 INFO]: CONSOLE: Please note that this command is not supported and may cause issues when using some plugins.
    [07:48:34 INFO]: CONSOLE: If you encounter any issues please use the /stop command to restart your server.
    [07:48:34 INFO]: Debug logging is disabled
    [07:48:34 INFO]: Server Ping Player Sample C
     
  6. Offline

    timtower Administrator Administrator Moderator

    @Brevoort Could you tell what line 21 of your EventListener is?
    And try to follow the package name me.themedieval.<pluginname>
     
  7. Offline

    Brevoort

    Yea the line 21 is extracting the string "Chance1" from my config.
     
  8. Offline

    timtower Administrator Administrator Moderator

  9. Offline

    Brevoort

    How would I do that?
     
  10. Offline

    timtower Administrator Administrator Moderator

    @Brevoort this.plugin = plugin
    It is just setting a variable.
     
  11. Offline

    Brevoort

    I tried doing that however it seemed to give me this error in the console:
    Code:
    [09:29:45 INFO]: [UsefulAchievement] Enabling UsefulAchievement v0.5
    [09:29:45 ERROR]: [UsefulAchievement] UsefulAchievement v0.5 attempted to register an invalid EventHandler method signature "public void me.themedieval.EventListener.aListener(org.bukkit.event.player.PlayerAchievementAwardedEvent,me.themedieval.Medfre1)" in class me.themedieval.EventListener

    My changed listener class:
    Code:
    package me.themedieval;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerAchievementAwardedEvent;
    public class EventListener implements Listener{
     private Medfre1 plugin;
     public EventListener(Medfre1 plugin) {
     plugin.getServer().getPluginManager().registerEvents(this, plugin);
     }
     @EventHandler
     public void aListener(PlayerAchievementAwardedEvent event, Medfre1 plugin) {
     Player player = event.getPlayer();
     double number = Math.random();
     if(number <= 0.2) {
     player.sendMessage(ChatColor.GREEN + "You won a prize for completing an achievement!");
     this.setPlugin(plugin);
     String commandd = plugin.getConfig().getString("Chance1");
     Bukkit.dispatchCommand(Bukkit.getConsoleSender(), commandd);
     } else if(number <= 0.4) {
     player.sendMessage(ChatColor.RED + "You won a prize for completing an achievement!");
     Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "give " + player.getName() + " minecraft:diamond 5");
     } else if(number <= 0.6){
     player.sendMessage(ChatColor.BLUE + "You won a prize for completing an achievement!");
     Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "give " + player.getName() + " minecraft:diamond 3");
     } else if(number <= 0.8){
     player.sendMessage(ChatColor.YELLOW + "You won a prize for completing an achievement!");
     Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "give " + player.getName() + " minecraft:diamond 3");
     } else if(number <= 0.97){
     player.sendMessage(ChatColor.AQUA + "You won a prize for completing an achievement!");
     Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "give " + player.getName() + " minecraft:diamond 3");
     } else if(number <= 0.99){
     player.sendMessage(ChatColor.BOLD + "You won a prize for completing an achievement!");
     Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "give " + player.getName() + " minecraft:diamond 3");
     }
     }
    }
    
     
    Last edited: Oct 22, 2016
  12. Offline

    timtower Administrator Administrator Moderator

    @Brevoort I don't see anything from that there.
     
  13. Offline

    Brevoort

    Oh, it was because when I put it in it produced some errors which must have deleted it.

    I updated the code above, but the error it gives me is at:
    Line 11 saying the value isn't used
    Line 21 saying I need a method made
     
  14. Offline

    timtower Administrator Administrator Moderator

    @Brevoort You put it in the event didn't you?
    Put that line in the constructor.
     
  15. Offline

    Brevoort

    So I put it above @EventHandler but it just gives an error again
    Its a syntax error I believe
     
  16. Offline

    timtower Administrator Administrator Moderator

  17. Offline

    Brevoort

    Ik its probably pretty obvious, but I do not know Java. I'm being self taught so I don't know much atm.

    So I put this.plugin = plugin; in like this?
    Code:
    package me.themedieval;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerAchievementAwardedEvent;
    
    public class EventListener implements Listener{
        private Medfre1 plugin;
        public EventListener(Medfre1 plugin) {
            plugin.getServer().getPluginManager().registerEvents(this, plugin);
        }
        @EventHandler
        public void aListener(PlayerAchievementAwardedEvent event, Medfre1 plugin) {
            Player player = event.getPlayer();
            double number = Math.random();
            this.plugin = plugin;
            if(number <= 0.2) {
                player.sendMessage(ChatColor.GREEN + "You won a prize for completing an achievement!");
                String commandd = plugin.getConfig().getString("Chance1");
                Bukkit.dispatchCommand(Bukkit.getConsoleSender(), commandd);
            }
    I'm not quite sure what the constructor is.
     
  18. Offline

    timtower Administrator Administrator Moderator

    @Brevoort Then read the link. It will help a lot.
     
  19. Offline

    Zombie_Striker

  20. Offline

    Brevoort

    I did but I'm still confused
     
  21. Offline

    timtower Administrator Administrator Moderator

    @Brevoort Then please check the post above by Zombie_Striker
     
Thread Status:
Not open for further replies.

Share This Page