EventHandler: Fishing Help

Discussion in 'Plugin Development' started by WatermellonLOL, Apr 11, 2014.

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

    WatermellonLOL

    I am attempting to make a plugin where when a player catches a fish, it will add a set amount of experience points to the "Fishing Skill" which is in the plugin, too. I have no idea how to make it check whether or not the player has caught a fish, not just an entity.
    This is my code so far:
    Code:java
    1. package me.WatermellonLOL;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.player.PlayerFishEvent;
    8.  
    9. public class PlayerListener implements Listener {
    10.  
    11. public PlayerListener(PluginDevelopmentClass plugin) {
    12. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    13. }
    14.  
    15. // These are the skill status.
    16.  
    17. int fishingLevel = 1;
    18. int fishingExp = 0;
    19.  
    20.  
    21. @EventHandler
    22. public void onFish(PlayerFishEvent event) {
    23.  
    24. Player player = event.getPlayer();
    25.  
    26. fishingExp++;
    27. player.sendMessage(ChatColor.BLUE + "You've gained 1 fishing experience.");
    28.  
    29. if (fishingExp == 50) {
    30.  
    31. fishingLevel++;
    32. player.sendMessage(ChatColor.DARK_BLUE +
    33. "Congratulations! You've achieved level " + fishingLevel + " in the fishing skill!");
    34.  
    35. } // End of the if statement.
    36.  
    37.  
    38. }
    39.  
    40. }

    Code:java
    1. package me.WatermellonLOL;
    2.  
    3. import org.bukkit.plugin.java.JavaPlugin;
    4.  
    5. public class PluginDevelopmentClass extends JavaPlugin {
    6.  
    7. @Override
    8. public void onEnable() {
    9. getLogger().info("wSkills has enabled successfully with no errors.");
    10. new PlayerListener(this);
    11. }
    12.  
    13. @Override
    14. public void onDisable() {
    15. getLogger().info("wSkills has disabled successfully with no errors.");
    16. }
    17.  
    18. }


    Plus, I want to figure out how to add a leveling system which requires more and more experience in the skill every time you've leveled up.

    Thank you so much,
    WatermellonLOL
     
  2. Offline

    Beasty

    You are not defining "fishingLVL" , define it also, Maybe that would work.
     
  3. Offline

    WatermellonLOL

    I rewrote the thread. Sorry, I believe I cleared up some stuff.
     
  4. Offline

    xTigerRebornx

  5. Offline

    WatermellonLOL

    I don't understand the javadocs though. :/ Wait! *lightbulb* Is this correct? I believe so!

    Code:java
    1. package me.WatermellonLOL;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.player.PlayerFishEvent;
    8. import org.bukkit.event.player.PlayerFishEvent.State;
    9.  
    10. public class PlayerListener implements Listener {
    11.  
    12. public PlayerListener(PluginDevelopmentClass plugin) {
    13. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    14. }
    15.  
    16. // These are the skill status.
    17.  
    18. int fishingExp, xpTillLevel, fishingLevel, fishingInc; {
    19.  
    20. fishingLevel = 1;
    21. fishingExp = 0;
    22. xpTillLevel = 50;
    23. fishingInc = 0;
    24. }
    25.  
    26.  
    27. @EventHandler
    28. public void onFish(PlayerFishEvent event) {
    29.  
    30. Player player = event.getPlayer();
    31. event.getState();
    32.  
    33. if (event.getState() == State.CAUGHT_FISH) {
    34.  
    35. fishingExp++;
    36. player.sendMessage(ChatColor.BLUE + "You've gained 1 fishing experience.");
    37.  
    38. if (fishingExp == xpTillLevel) {
    39.  
    40. fishingLevel++;
    41. player.sendMessage(ChatColor.DARK_BLUE +
    42. "Congratulations! You've achieved level " + fishingLevel + " in the fishing skill!");
    43. fishingExp = 0;
    44.  
    45. } // End of the if statement.
    46.  
    47. if (fishingLevel != fishingInc) {
    48.  
    49. fishingInc++;
    50. xpTillLevel = xpTillLevel * fishingInc;
    51.  
    52. }
    53.  
    54. }
    55.  
    56.  
    57. }
    58.  
    59. }
     
Thread Status:
Not open for further replies.

Share This Page