Plugin enables... but does nothing. No errors though!

Discussion in 'Plugin Development' started by WatermellonLOL, Jul 14, 2014.

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

    WatermellonLOL

    It is a fishing plugin for 1.7.9. When I fish, nothing happens.

    Code:java
    1. package me.WatermellonLOL;
    2.  
    3. import java.util.Arrays;
    4. import java.util.Random;
    5. import java.util.logging.Logger;
    6.  
    7. import org.bukkit.Location;
    8. import org.bukkit.Material;
    9. import org.bukkit.Sound;
    10. import org.bukkit.World;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.event.Listener;
    13. import org.bukkit.event.player.PlayerFishEvent;
    14. import org.bukkit.event.player.PlayerJoinEvent;
    15. import org.bukkit.event.player.PlayerFishEvent.State;
    16. import org.bukkit.inventory.ItemStack;
    17. import org.bukkit.inventory.meta.ItemMeta;
    18. import org.bukkit.plugin.PluginDescriptionFile;
    19. import org.bukkit.plugin.java.JavaPlugin;
    20.  
    21. public class Fishing extends JavaPlugin implements Listener {
    22. public final Logger logger = Logger.getLogger("Minecraft");
    23.  
    24. public void onEnable() {
    25. getServer().getPluginManager().registerEvents(this, this);
    26. PluginDescriptionFile pdfFile = this.getDescription();
    27. this.logger.info(pdfFile.getName() + " " + pdfFile.getVersion() + " has successfully been enabled.");
    28. }
    29.  
    30. public void onFish (PlayerFishEvent event, Player player, World world) {
    31. player.sendMessage("§eyou got fish");
    32. Random random = new Random();
    33.  
    34. /*
    35.   * Fish Sizes:
    36.   * 7 different sizes.
    37.   *
    38.   * Elder
    39.   * Giant
    40.   * Large
    41.   * Medium
    42.   * Small
    43.   * Tiny
    44.   * Baby
    45.   */
    46.  
    47. int fish = 1 + random.nextInt(100);
    48.  
    49. /*
    50.   * Variety:
    51.   * 8 different 'kinds' of fish.
    52.   *
    53.   * Rarest to most common:
    54.   * Kingly
    55.   * Crystal
    56.   * Unique
    57.   * Glowing
    58.   * Shiny
    59.   * Sparkling
    60.   * Quick
    61.   * Standard
    62.   */
    63.  
    64. int variety = 1 + random.nextInt(1024);
    65. int randomXP = 1 + random.nextInt(10);
    66. int nextLevelXPmultiplier = 1 + random.nextInt(3);
    67. Location pl = player.getLocation();
    68.  
    69. if (event.getState() == State.FAILED_ATTEMPT) {
    70. player.playSound(pl, Sound.ITEM_BREAK, 1f, 0.4f);
    71. player.sendMessage("§cYou've failed to catch a fish.");
    72. }else if (event.getState() == State.CAUGHT_FISH) {
    73. getConfig().set(player.getName() + ".fishing", getConfig().getInt(player.getName() + ".fishing") + randomXP);
    74. if (fish == 100) {
    75. if (variety == 1024) {
    76. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§6Elder Kingly Fish")));
    77. }else if (variety < 1024 && variety >= 1000) {
    78. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§6Elder Crystal Fish")));
    79. }else if (variety < 1000 && variety >= 950) {
    80. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§6Elder Unique Fish")));
    81. }else if (variety < 950 && variety >= 850) {
    82. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§6Elder Glowing Fish")));
    83. }else if (variety < 850 && variety >= 650) {
    84. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§6Elder Shiny Fish")));
    85. }else if (variety < 650 && variety >= 375) {
    86. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§6Elder Quick Fish")));
    87. }else if (variety < 375) {
    88. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§6Elder Standard Fish")));
    89. }
    90. }else if (fish <= 99 && fish >= 75) {
    91. if (variety == 1024) {
    92. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§5Giant Kingly Fish")));
    93. }else if (variety < 1024 && variety >= 1000) {
    94. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§5Giant Crystal Fish")));
    95. }else if (variety < 1000 && variety >= 950) {
    96. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§5Giant Unique Fish")));
    97. }else if (variety < 950 && variety >= 850) {
    98. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§5Giant Glowing Fish")));
    99. }else if (variety < 850 && variety >= 650) {
    100. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§5Giant Shiny Fish")));
    101. }else if (variety < 650 && variety >= 375) {
    102. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§5Giant Quick Fish")));
    103. }else if (variety < 375) {
    104. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§5Giant Standard Fish")));
    105. }
    106. }else if (fish <= 74 && fish >= 50) {
    107. if (variety == 1024) {
    108. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§aLarge Kingly Fish")));
    109. }else if (variety < 1024 && variety >= 1000) {
    110. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§aLarge Crystal Fish")));
    111. }else if (variety < 1000 && variety >= 950) {
    112. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§aLarge Unique Fish")));
    113. }else if (variety < 950 && variety >= 850) {
    114. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§aLarge Glowing Fish")));
    115. }else if (variety < 850 && variety >= 650) {
    116. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§aLarge Shiny Fish")));
    117. }else if (variety < 650 && variety >= 375) {
    118. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§aLarge Quick Fish")));
    119. }else if (variety < 375) {
    120. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§aLarge Standard Fish")));
    121. }
    122. }else if (fish <= 49 && fish >= 25) {
    123. if (variety == 1024) {
    124. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§eMedium Kingly Fish")));
    125. }else if (variety < 1024 && variety >= 1000) {
    126. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§eMedium Crystal Fish")));
    127. }else if (variety < 1000 && variety >= 950) {
    128. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§eMedium Unique Fish")));
    129. }else if (variety < 950 && variety >= 850) {
    130. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§eMedium Glowing Fish")));
    131. }else if (variety < 850 && variety >= 650) {
    132. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§eMedium Shiny Fish")));
    133. }else if (variety < 650 && variety >= 375) {
    134. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§eMedium Quick Fish")));
    135. }else if (variety < 375) {
    136. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§eMedium Standard Fish")));
    137. }
    138. }else if (fish <= 24 && fish >= 3) {
    139. if (variety == 1024) {
    140. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§bSmall Kingly Fish")));
    141. }else if (variety < 1024 && variety >= 1000) {
    142. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§bSmall Crystal Fish")));
    143. }else if (variety < 1000 && variety >= 950) {
    144. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§bSmall Unique Fish")));
    145. }else if (variety < 950 && variety >= 850) {
    146. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§bSmall Glowing Fish")));
    147. }else if (variety < 850 && variety >= 650) {
    148. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§bSmall Shiny Fish")));
    149. }else if (variety < 650 && variety >= 375) {
    150. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§bSmall Quick Fish")));
    151. }else if (variety < 375) {
    152. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§bSmall Standard Fish")));
    153. }
    154. }else if (fish == 2) {
    155. if (variety == 1024) {
    156. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§dTiny Kingly Fish")));
    157. }else if (variety < 1024 && variety >= 1000) {
    158. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§dTiny Crystal Fish")));
    159. }else if (variety < 1000 && variety >= 950) {
    160. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§dTiny Unique Fish")));
    161. }else if (variety < 950 && variety >= 850) {
    162. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§dTiny Glowing Fish")));
    163. }else if (variety < 850 && variety >= 650) {
    164. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§dTiny Shiny Fish")));
    165. }else if (variety < 650 && variety >= 375) {
    166. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§dTiny Quick Fish")));
    167. }else if (variety < 375) {
    168. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§dTiny Standard Fish")));
    169. }
    170. }else if (fish == 1) {
    171. if (variety == 1024) {
    172. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§2Baby Kingly Fish")));
    173. }else if (variety < 1024 && variety >= 1000) {
    174. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§2Baby Crystal Fish")));
    175. }else if (variety < 1000 && variety >= 950) {
    176. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§2Baby Unique Fish")));
    177. }else if (variety < 950 && variety >= 850) {
    178. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§2Baby Glowing Fish")));
    179. }else if (variety < 850 && variety >= 650) {
    180. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§2Baby Shiny Fish")));
    181. }else if (variety < 650 && variety >= 375) {
    182. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§2Baby Quick Fish")));
    183. }else if (variety < 375) {
    184. world.dropItem(player.getLocation(), (makeNoLore(Material.RAW_FISH, 1, (short) 0, "§2Baby Standard Fish")));
    185. }
    186. }
    187. }
    188.  
    189. if (getConfig().getInt(player.getName() + ".fishing") == getConfig().getInt(player.getName() + ".xpTillFishingLevel")) {
    190. getConfig().set(player.getName() + ".fishingLevel", getConfig().getInt(player.getName() + ".fishingLevel") + 1);
    191. player.sendMessage("§eCongratulations! You've achieved level " + getConfig().getInt(player.getName() + ".fishingLevel") + " in the Fishing skill!");
    192. getConfig().set(player.getName() + ".fishing", 0);
    193. getConfig().set(player.getName() + ".xpTillFishingLevel", getConfig().getInt(player.getName() + ".xpTillFishingLevel") * nextLevelXPmultiplier);
    194. player.sendMessage("§aYou need " + getConfig().getInt(player.getName() + ".xpTillFishingLevel") + " XP till the next Fishing level.");
    195. }
    196.  
    197. }
    198.  
    199. public void onPlayerJoin(PlayerJoinEvent event, Player player) {
    200. if (!getConfig().contains(player.getName())) {
    201. getConfig().set(player.getName() + ".fishing", 0);
    202. getConfig().set(player.getName() + ".fishingLevel", 1);
    203. getConfig().set(player.getName() + ".xpTillFishingLevel", 10);
    204. }
    205. }
    206.  
    207. public ItemStack make(Material material, int amount, int shrt, String displayname, String lore) {
    208. ItemStack item = new ItemStack(material, amount, (short) shrt);
    209. ItemMeta meta = item.getItemMeta();
    210. meta.setDisplayName(displayname);
    211. meta.setLore(Arrays.asList(lore));
    212. item.setItemMeta(meta);
    213. return item;
    214. }
    215.  
    216. public ItemStack makeNoLore(Material material, int amount, int shrt, String displayname) {
    217. ItemStack item = new ItemStack(material, amount, (short) shrt);
    218. ItemMeta meta = item.getItemMeta();
    219. meta.setDisplayName(displayname);
    220. item.setItemMeta(meta);
    221. return item;
    222. }
    223.  
    224. }


    Thanks so much; if you need more information, ask me.
     
  2. Offline

    malandrix_bunny

    @eventhandler?
     
  3. Offline

    DevRosemberg

    WatermellonLOL Of course it does nothing as:

    Code:java
    1. public void onPlayerJoin(PlayerJoinEvent event, Player player) {


    Code:java
    1. public void onFish (PlayerFishEvent event, Player player, World world) {


    Are not valid Events.
     
  4. Offline

    malandrix_bunny

    DevRosemberg Talk about missing something big, I feel like an idiot.
     
  5. Offline

    WatermellonLOL

    @DevRosemberg
    What would I make them then? If I wanted to use player.whatever or world.whatever? Sorry if this is considered "spoonfeeding".

    Any help?

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

    Gater12

    WatermellonLOL
    Check JavaDocs on events. All PlayerEvent subclasses have a getPlayer method.
     
  7. Offline

    maved145

    WatermellonLOL
    Instead of
    Code:java
    1. public void onFish (PlayerFishEvent event, Player player, World world){
    2. and
    3. public void onPlayerJoin(PlayerJoinEvent event, Player player) {


    Use

    Code:java
    1. @EventHandler
    2. public void onFish (PlayerFishEvent event) {
    3. Player player = event.getPlayer();
    4. World world = player.getWorld();
    5. }
    6. and
    7. @EventHandler
    8. public void onPlayerJoin(PlayerJoinEvent event) {
    9. Player player = event.getPlayer();
    10. }


    Maybe watch some basic tutorials on bukkit coding before trying to make your own.
     
Thread Status:
Not open for further replies.

Share This Page