No TNT Damage Plugin

Discussion in 'Plugin Development' started by GoldenElixir8971, Jun 8, 2021.

Thread Status:
Not open for further replies.
  1. I made a bedwars server. In the plugin I got, it didnt disable TNT damage. With the help of my friend, I coded a plugin 'NoBlast.jar' to remove the TNT damage. But it also removes all TNT knockback which doesnt allow TNT jumping. I also found another plugin called 'Hypixel TNT' which removed tnt damage but the TNT still knocked people back. But this plugin also adds many unwanted things. I tried copying the code of 'damagehandler.class' from the plugin to make a fresh one but that doesnt work. I hope someone could help me with this.
    Thanks a lot

    Links to files
    NoBlast: https://drive.google.com/file/d/1rlI7ITp91etTvxHpZf-tPDFFX06KowfW/view?usp=sharing
    HypixelTNT: https://drive.google.com/file/d/17EDFKtSeqaI5VIg3tbaAmJ6Aer2iCNGM/view?usp=sharing
     
  2. Offline

    davidclue

    @GoldenElixir8971 In your listener class have a EntityDamageByEntity event that checks for tnt damage. Your plugin is very simple all you need to remove tnt damage is this
    Code:
    @EventHandler
    public void onDamage(EntityDamageByEntity e) {
        if (e.getDamager() instanceof TNTPrimed)
            e.setDamage(0D);
    }
     
    c7dev likes this.
  3. I made these two plugins, V1 doesnt work whereas V2 removes tnt damage as well as knockback. I know I'm not smart but it'd really help if you could tell me the problem.
     

    Attached Files:

  4. Offline

    davidclue

    @GoldenElixir8971 You realize I can't access the jar file right... You have to share the code directly here. I have already supplied you with what you need in my previous post.
     
  5. Im sorry
    I did upload a zip file containing the jar files
    ill send the code
    sorry
    Code:
    package me.Golden.NoTNTDamage;
    
    import EntityDamageByEntity;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin implements Listener {
      public void onEnable() {
        getServer().getPluginManager().registerEvents(this, (Plugin)this);
      }
     
      public void onDisable() {}
     
      @EventHandler
      public void onDamage(EntityDamageByEntity paramEntityDamageByEntity) {
        throw new Error("Unresolved compilation problems: \n\tEntityDamageByEntity cannot be resolved to a type\n\tTNTPrimed cannot be resolved to a type\n");
      }
    }
    Code:
    package me.Golden.NoTNTDamage;
    
    import EntityDamageByEntity;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    
    public class Main implements Listener {
      @EventHandler
      public void onDamage(EntityDamageByEntity paramEntityDamageByEntity) {
        throw new Error("Unresolved compilation problems: \n\tEntityDamageByEntity cannot be resolved to a type\n\tTNTPrimed cannot be resolved to a type\n");
      }
    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2021
  6. Offline

    davidclue

    @GoldenElixir8971 You are throwing an error every time an entity is getting damaged... You need to learn the basics of java, also there is no reason to cast "this" to a plugin.
     
  7. Offline

    c7dev

    The code by davidclue should work. It looks like one of the issues you're having is being unable to import EntityDamageByEntityEvent. Most IDEs have a way to import all of the needed classes, for example on eclipse it's Ctrl+Shift+O. If that doesn't work, the class is org.bukkit.event.entity.EntityDamageByEntityEvent. You can find this in the Bukkit javadocs.
     
  8. I tried this but its still showing throwing an error

    package me.Golden.NoTNTDamage;

    import org.bukkit.entity.TNTPrimed;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;

    public class Main extends JavaPlugin implements Listener {
    public void onEnable() {
    getServer().getPluginManager().registerEvents(this, (Plugin)this);
    }

    public void onDisable() {}

    @EventHandler
    public void onDamage(EntityDamageByEntity e) {
    if (e.getDamager() instanceof TNTPrimed)
    e.setDamage(0D);
    }

    }

    but its just throwing the error throw new Error("Unresolved compilation problem: \n\tEntityDamageByEntity cannot be resolved to a type\n");
     
  9. Offline

    c7dev

    @GoldenElixir8971 "EntityDamageByEntity" is not a class, the event class is "EntityDamageByEntityEvent." If you have errors that say "unresolved compilation problem," it means there's a syntax error. Syntax errors are basic things like forgetting a semicolon, or in your case referencing a class that never existed anywhere in the libraries.

    If you fix it as described above and it still has an error, I would recommend reading the stack trace (the big block of text in the console when the error happens), because it tells you what is causing the error when it says "EntityDamageByEntity cannot be resolved to a type." It will also give you the line number to the code causing the issue, so you can pinpoint where the threads were when the error was generated.
     
    KarimAKL likes this.
  10. Offline

    KarimAKL

    @GoldenElixir8971 "EntityDamageByEntity" is not a thing, it should be "EntityDamageByEntityEvent"

    Edit: @c7dev elaborated above me, but his post was under moderation when I wrote this.
     
    Last edited: Jun 11, 2021
  11. Tried this, didn't work, I know I'm being stupid and annoying you but I'm sorry I need this.

    Code:
    package me.Golden.NoTNTDamage;
    
    import org.bukkit.entity.TNTPrimed;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin implements Listener {
      public void onEnable() {
        getServer().getPluginManager().registerEvents(this, (Plugin)this);
      }
      public void onDisable() {}
      @EventHandler
      public void onDamage(EntityDamageByEntityEvent e) {
          if (e.getDamager() instanceof TNTPrimed)
              e.setDamage(0D);
      }
    }
     
    Last edited by a moderator: Jun 11, 2021
  12. Online

    timtower Administrator Administrator Moderator

    @GoldenElixir8971 What does not work then? Why are you even casting Plugin in the onEnable?
    Do you have errors in the log?
     
  13. Its dealing damage to me when I tested it on the server. The console doesnt give me any errors, I dont understand why this is happening :(

    But anyways thank you everyone for your help
     
  14. Online

    timtower Administrator Administrator Moderator

    @GoldenElixir8971 Can you put a debug line in the method? To see if it even fires?
     
  15. Offline

    davidclue

  16. I did make a plugin.yml file
     
  17. Offline

    KarimAKL

    @GoldenElixir8971 Can you post your server log? It might contain some useful information.
     
Thread Status:
Not open for further replies.

Share This Page