Help with explosive pickaxe

Discussion in 'Plugin Development' started by andrewginn, Oct 30, 2014.

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

    andrewginn

    Hello i have been working on a plugin for a couple of days and ive got this far without a problem, but of course i stumbled upon one today. The problem is that players are bouncing away when they mine a block since the pickaxe, causes a explosion. Here is my code, if anyone could tell me the code to stop the bouncing away. Since i have no clue how or what way to stop it, also if you could tell me where to put it that would be great. Thanks. Here is the code!
    This is the explosive pickaxe class:
    http://pastebin.com/DcE0WmzS
    This is the Commands class:
    http://pastebin.com/qtTjX8Zw
    This is the EventListener Class:
    http://pastebin.com/D2gVhxjT


    Thanks and have a good day!
     
  2. Offline

    Abs0rbed

    you could try canceling the PlayerVelocityEvent, if that's triggered on explosions. Also, just a tiny thing I noticed: your getInstance() really isn't useful for getting your main class instance because it isn't static. Just a tiny thing.
     
  3. Offline

    Unica

    Abs0rbed
    You can't use a 'this' reference in a static context ;)

    andrewginn
    Code:java
    1. createExplosion (double x, double y, double z, float power)

    Try to set the power to 0
     
  4. Offline

    Abs0rbed

    Unica That doesn't mean that you can't use a variable xD
    What's the point of a getInstance() that you can't use without instantiating the class into another object :p?
     
  5. Offline

    Unica

    Abs0rbed

    You're right about that. I would rather just use an constructor. But I just wanted to point out that he cannot make it static :D
     
  6. Offline

    Abs0rbed

    Unica Just out of curiosity, if the power is 0, won't it nullify damage to blocks? Kinda skimmed the pastebin, can't remember if andrewginn wanted blocks broken or not.
    Edit: Saw that he's breaking the blocks with his code, not the explosion. Setting it to 0 should work fine :)
     
  7. Offline

    andrewginn

    I want the explosions but not to deal player damage or pushing them back Abs0rbed
    Also i have got the java for dummies book and my friend helped me with most of this coding.
    After reading the book will i become experienced in java or not?
    Also can you tell me how you learnt java since i need to learn it quick and how long did it take you to learn? Unica
     
  8. Offline

    Abs0rbed

    andrewginn I'm self taught, using some pretty gigantic books. I used Java: A Beginner's Guide by Herbert Schildt, along with reading oracle docs, then I moved up through higher level stuff. Just out of curiosity, why do you need to learn so quickly?
     
  9. Offline

    Unica

    andrewginn

    Setting the power to 0 will remove the damage (right?). I assume without the damage there is also no knockback.
    Concerning your question, I used the internet. But I started off with alot of bad practise, therefor I think books are probably better.
    thenewboston also makes pretty good tutorials for alot of programming languages. And learning takes time, but if you do your best, it will be worth it :)
     
  10. Offline

    Abs0rbed

    andrewginn Unica thenewboston's tutorials are really good, but I think books are better (mainly because I can read them in class when I'm supposed to be paying attention xD) It should remove the damage, as power 4 is tnt
     
  11. Offline

    fireblast709

    andrewginn
    Regarding your main class
    • You should only register the command explosivepickaxe, and set ep as it's alias (this also means that you only need to check cmd.getName().equals("explosivepickaxe")).
    • Instead of using \ or / in file paths, use File.separator. Even better would be using the second constructor of File, File(directory, filename).
    • Don't use the Minecraft Logger, use the Logger object you get by extending JavaPlugin.
    • Instead of using a List<ItemStack> to check if an ItemStack is a pickaxe, use an EnumSet<Material>:
      • Sets are better for contains() operations since they don't require you to check every element in the List (and yes, that's what it does :p).
      • EnumSets are optimised for enums.
    Regarding EventListener
    • Be aware of null ItemStacks (afaik player.getItemInHand() could return null.
    • Check if the ItemMeta has lore before getting the first element of the lore.
     
Thread Status:
Not open for further replies.

Share This Page