Im a begginer and cant figure this out- pumpkin bombs

Discussion in 'Plugin Development' started by ChroniclerBat, Jan 2, 2014.

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

    ChroniclerBat

    Im trying to make a pumpkin bomb plugin but for the life of me cannot get it to work.
    heres my code
    Code:java
    1. package me.zaxdas247.YingYangclass;
    2. import java.io.File;
    3. import java.io.InputStream;
    4. import java.util.List;
    5. import java.util.logging.Logger;
    6.  
    7. import org.bukkit.Bukkit;
    8. import org.bukkit.Material;
    9. import org.bukkit.Server;
    10. import org.bukkit.World;
    11. import org.bukkit.command.Command;
    12. import org.bukkit.command.CommandSender;
    13. import org.bukkit.configuration.file.FileConfiguration;
    14. import org.bukkit.entity.Entity;
    15. import org.bukkit.entity.Item;
    16. import org.bukkit.entity.Player;
    17. import org.bukkit.event.EventHandler;
    18. import org.bukkit.event.Listener;
    19. import org.bukkit.event.block.Action;
    20. import org.bukkit.event.player.PlayerInteractEvent;
    21. import org.bukkit.generator.ChunkGenerator;
    22. import org.bukkit.inventory.ItemStack;
    23. import org.bukkit.plugin.Plugin;
    24. import org.bukkit.plugin.PluginDescriptionFile;
    25. import org.bukkit.plugin.PluginLoader;
    26. import org.bukkit.potion.PotionEffect;
    27. import org.bukkit.potion.PotionEffectType;
    28.  
    29. import com.avaje.ebean.EbeanServer;
    30.  
    31. public class ListenerClass implements Listener, Plugin {
    32. public ListenerClass plugin;
    33.  
    34. @EventHandler
    35. public void onPlayerInteract(PlayerInteractEvent event) {
    36.  
    37. Player player = event.getPlayer();
    38. World world = player.getWorld();
    39.  
    40. if (player.hasPermission("pumpkin.use")){
    41.  
    42. if (player.getItemInHand().getType() == Material.PUMPKIN) {
    43.  
    44. if (event.getAction() == Action.RIGHT_CLICK_AIR) {
    45.  
    46. final Item drop = world.dropItem(player.getEyeLocation(), new ItemStack(Material.PUMPKIN, 0));
    47. drop.setVelocity(player.getEyeLocation().getDirection());
    48.  
    49. player.getItemInHand().setAmount(player.getItemInHand().getAmount() -1);
    50. Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    51. public void run(){
    52. drop.getWorld().createExplosion(drop.getLocation(), 3F);
    53. for(Entity nearbyEntity : drop.getNearbyEntities(5.0D, 5.0D, 5.0D)){
    54. if(nearbyEntity instanceof Player){
    55. Player nearbyPlayer = (Player) nearbyEntity;
    56. nearbyPlayer.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 130, 1));
    57. drop.remove();
    58. }
    59. }}}, 20L);
    60. }
    61. }
    62. }
    63. }
    64. }

    Im getting a IllegalArgumentError Plugin cannot be null. Im just begging, so if anyone could, help, that would be great. thanks so much,
    ~ChroniclerBat
     
  2. Offline

    Bart

    ->Remove this:
    Code:java
    1. public ListenerClass plugin;

    ->Don't implement 'Plugin' from ListenerClass
    ->Add this:
    Code:java
    1. private JavaPlugin plugin;

    -> and this:
    Code:java
    1. public ListenerClass(JavaPlugin plugin){
    2. this.plugin = plugin;
    3. }

    ->Where you register your events (presumably in your main plugin class), change the line:
    Code:java
    1. getServer().getPluginManager().registerEvents(new ListenerClass(), this);

    to
    Code:java
    1. getServer().getPluginManager().registerEvents(new ListenerClass(this), this);

    ->Change this line:
    Code:java
    1. Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){

    to
    Code:java
    1. plugin.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){

    Please learn Java before trying to make plugins.
     
    swampshark19 and jimbo8 like this.
  3. Offline

    ChroniclerBat

    Im sorry, thank you so much. That comment at the end made me feel sort of sad, as i have learned alot of java, but thanks nonetheless.
     
  4. Offline

    ChroniclerBat

    I admit i may not know plenty of java, and i still need to learn, so please help. my codelooks like this and its giving me all kinds of errors. please correct what i have missed. I have very little experience and just want to make this one thing, then ill never bother these forums again. Again, Im probably missing something obvious.
    heres my code:
    main class
    Code:java
    1. package me.zaxdas247.AppleBombs;
    2.  
    3. import org.bukkit.plugin.PluginManager;
    4. import org.bukkit.plugin.java.JavaPlugin;
    5.  
    6. public class AppleBombs extends JavaPlugin {
    7.  
    8. public final ListenerClass Listener = new ListenerClass();
    9.  
    10. public void onEnable() {
    11.  
    12. getServer().getPluginManager().registerEvents(new ListenerClass(this), this);
    13.  
    14. getLogger().info("PLUGIN is now enabled.");
    15.  
    16. }
    17.  
    18. public void onDisable() {
    19.  
    20. getLogger().info("PLUGIN is now disabled.");
    21.  
    22. }
    23.  
    24. }

    Listener Class
    Code:java
    1. package me.zaxdas247.AppleBombs;
    2. import java.io.File;
    3. import java.io.InputStream;
    4. import java.util.List;
    5. import java.util.logging.Logger;
    6.  
    7.  
    8. import org.bukkit.Bukkit;
    9. import org.bukkit.Material;
    10. import org.bukkit.Server;
    11. import org.bukkit.World;
    12. import org.bukkit.command.Command;
    13. import org.bukkit.command.CommandSender;
    14. import org.bukkit.configuration.file.FileConfiguration;
    15. import org.bukkit.entity.Entity;
    16. import org.bukkit.entity.Item;
    17. import org.bukkit.entity.Player;
    18. import org.bukkit.event.EventHandler;
    19. import org.bukkit.event.Listener;
    20. import org.bukkit.event.block.Action;
    21. import org.bukkit.event.player.PlayerInteractEvent;
    22. import org.bukkit.generator.ChunkGenerator;
    23. import org.bukkit.inventory.ItemStack;
    24. import org.bukkit.plugin.Plugin;
    25. import org.bukkit.plugin.PluginDescriptionFile;
    26. import org.bukkit.plugin.PluginLoader;
    27. import org.bukkit.plugin.java.JavaPlugin;
    28. import org.bukkit.potion.PotionEffect;
    29. import org.bukkit.potion.PotionEffectType;
    30. import com.avaje.ebean.EbeanServer;
    31.  
    32. public class ListenerClass implements Listener{
    33. private JavaPlugin plugin;
    34. public ListenerClass(JavaPlugin plugin){
    35. this.plugin = plugin;
    36.  
    37.  
    38. @EventHandler
    39. public void onPlayerInteract(PlayerInteractEvent event) {
    40.  
    41. Player player = event.getPlayer();
    42. World world = player.getWorld();
    43.  
    44. if (player.hasPermission("pumpkin.use")){
    45.  
    46. if (player.getItemInHand().getType() == Material.PUMPKIN) {
    47.  
    48. if (event.getAction() == Action.RIGHT_CLICK_AIR) {
    49.  
    50. final Item drop = world.dropItem(player.getEyeLocation(), new ItemStack(Material.PUMPKIN, 0));
    51. drop.setVelocity(player.getEyeLocation().getDirection());
    52.  
    53. player.getItemInHand().setAmount(player.getItemInHand().getAmount() -1);
    54. plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
    55. public void run(){
    56. drop.getWorld().createExplosion(drop.getLocation(), 3F);
    57. for(Entity nearbyEntity : drop.getNearbyEntities(5.0D, 5.0D, 5.0D)){
    58. if(nearbyEntity instanceof Player){
    59. Player nearbyPlayer = (Player) nearbyEntity;
    60. nearbyPlayer.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 130, 1));
    61. drop.remove();
    62. }
    63. }}}, 20L);
    64. }
    65. }
    66. }
    67. }
    68. }
    69. }
     
  5. Offline

    Codex Arcanum

    I would try helping you, but you need to make sure the indentation is included in your posts - this is extremely hard to read without tabs.
     
    hintss likes this.
  6. Offline

    Desle

    I can't find a mistake you made?

    By the way;
    will only work if the item in the player's hand has 2 or more of that item.
     
  7. Offline

    ChroniclerBat

    New
    @Desle
    that code works fine as i use it for other code and it works wonderfully becuase of my other line of code which removes it when the player has 1 of the item in hand​
    and on my code it gives me the errors on:​

    public final ListenerClass Listener = new ListenerClass(); //"the contructor ListenerClass() is undefined"​

    and on
    public void onPlayerInteract //"void is an invalid type for the variable onPlayerInteract"(PlayerInteractEvent event)
    @Codex_Arcanum​
    what do you mean by indentation?​
    how can i add it?​
    Thanks for the replies​
     
  8. Offline

    Commander9292

    ChroniclerBat

    I hate to spoonfeed, but would you like me to write this plugin real quick so you can take a look at the code?
     
    ChroniclerBat likes this.
  9. Offline

    ChroniclerBat

    I hate to sound like this, but that would be awesome! I bet i could learn a lot from that, and from many others on this forum as many of you seem so knowledgeable. I intend to keep posting to learn as much as i can since the way we learn best is through mistakes.
     
  10. Offline

    nuclearmissile

    Please learn Java before trying to make plugins? Sheesh, that never stopped me! :D
     
  11. Offline

    ChroniclerBat

    thanks for the encouragement! that comment kind of made me feel like i should just give up and die. glad to know not all of you are like that :)
     
  12. Offline

    nuclearmissile

    Yeah don't let snobs or people having a bad day get you down. My Omega Weapons plugin is a fair piece of work, and I made it before I knew even a small fraction of Bukkit's classes and methods and whatnot. I still don't, hence my frequent posts on this forum. XD
     
  13. Offline

    Commander9292

    ChroniclerBat likes this.
  14. Offline

    ChroniclerBat

    Commander9292
    Thanks so much for that, ill study it carefully.
    [diamond][diamond][diamond] Here are some "likes" [diamond] [diamond][diamond]
     
  15. Offline

    Iroh Retired Staff

    Removed offtopic arguement.
     
    Garris0n likes this.
Thread Status:
Not open for further replies.

Share This Page