Track Launched TNT

Discussion in 'Spigot Plugin Development' started by Torciv, May 30, 2017.

Thread Status:
Not open for further replies.
  1. So basically I am trying to make a plugin to track TNT launch.

    What I want to achive is when a TNT is primed by dispenser - and a TNT launchs another TNT from Point A to Point B - like a cannon.

    • Check where that launched TNT exploded (Location) - Would be Point B.
    • Check where the launched TNT came from (Location) - Would be Point A.

    I dont have any idea how to start this, I have been checking the API but I dont really find anything really related with this.

    - How do i check if TNT is primed by dispenser?
    - How do I track that TNT to get locations from where it came and where it has exploded?

  2. I would recommend using the "BlockDispenseEvent" basically it would trigger spawning any item also your tnt and as you may know, spawning an tnt out of an dispenser will automatically convert the item to a primed tnt.


    Code (Text):

    public void tntDispense(BlockDispenseEvent e) {
        if(e.getBlock().getType() == Material.DISPENSER) { //Check if your block is a dispenser
            if (e.getItem().getType() == Material.TNT) { // make also sure the item is a tnt ( to create primed tnt )
                //Do your thing
    • Useful Useful x 1
  3. Perhaps adding the dispensed block into a hashmap with the UUID as key, and initial location as data, and then another hashmap and add the TNT when it exploded and its location (again, UUID: location),
    then you can simply get location A or location B using the TNT uuid.
  4. Seems very logic :D thanks will try to work with this
  5. Sorry xD I got lost with the hasmap with UUID and data :S

    As far as I have understood I should use something like this:

    Code (Text):

    Map<Dispenser, Location> disp = new HashMap<Dispenser, Location>(); // with BlockDispenseEvent
    Map <TNT, Location> tnt = new HashMap<TNT, Location>(); // with explodeEvent
    What I dont undestand it is what you mean by UUID and data you mean the value of the hashmap?
  6. I personally wouldn't recommend the method that @iSoda mentioned as it requires some maps that don't even be required for what you try.

    It would be simplier checking the dispenser blockface direction get the primed tnt, add a small metadata that saves the location where it has been spawned, go to the ExplosionPrimedEvent, check if the tnt that exploded has the valid metadata, and there you have point a & b without using any map actions
  7. Could you give me an exemple of how to add metadata. I haven't really worked with that before
  8. Similar to this
    Code (Text):

    entity.setMetadata("firstLocation", new FixedMetadataValue(plugin, location));
  9. I will try it. Really thanks to your help.
    Will add some code once I have something
  10. For now I have tried to do what you have told me and this is so far what I have
    #10 Torciv, May 31, 2017
    Last edited: Jul 10, 2017
  11. I guess you learn something new every day :) didnt know you can set meta data...
  12. I have also thought about maybe use EntityExplodeEvent or EntityDamageEvent and check if the explosion affected another TNT becase i just only want to track the TNT that has been launch by another one.
    Any suggestion?
    #12 Torciv, May 31, 2017
    Last edited: May 31, 2017
  13. Well Finally Ended up doing what I really wanted to :D

    It is working I will leave the post open just in case someone knows another way to do this instead of cancel the spawn of your custom TNT.
    Nevertheless, as far as I have been searching it is not possible.
    #13 Torciv, May 31, 2017
    Last edited: Jul 10, 2017
  14. What plugin are you trying to make? There might be an easier way to go about doing it.
  15. I'm actually interested as to what you're trying to do here? Not that I can provide any assistance but I'm very intrigued... I know a lot about factions and cannoning, and I assume you do as well, so it should be easier to explain to me.
  16. I'm trying to make a plugin to trigger raid points.

    I have edited factions plugin to add a "core claim"

    So I just want that when a TNT launched from a claimed land to another claimed land:
    • if it is not your own faction
    • if the faction hasn't lost raidPoints in the last 12h
    • If the explosion was on the core claim
    Then add a % of points to your faction score and add to the faction banc a % of the total money that all players in that faction have (their players would lose that money).

    Then do an F top system with that -> money stealed and raid points gained.

    If you have any suggestion it would be great :D

    Also if you find a better way to do this I would really appreciate any help.
  17. There is a custom spigot that has a getSource() method for TNT/sand. Can't post the name here but you can PM me for it. You can also add /f raid but that is old school :p.
  18. Sure, thanks! That would really help
Thread Status:
Not open for further replies.