Error when I summon primed-tnt

Discussion in 'Plugin Development' started by Dragonhuntrrr, Feb 10, 2021.

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

    Dragonhuntrrr

    Hello, i'm developing a custom TNT plugin that "currently" lets you choose the TNT priming time
    But it seems like it activates the event multiple times or something...
    To be honest, I don't know whats wrong here :(

    Code:
    @EventHandler
        public void onPrime(EntitySpawnEvent event) {
                if (!getConfig().getBoolean("Insta prime")) {
                    if (event.getEntity().getType() == EntityType.PRIMED_TNT && event.getEntity().getCustomName() == null) {
                        var pL = event.getEntity().getLocation();
                        var pW = event.getEntity().getWorld();
                        TNTPrimed tnt = (TNTPrimed) pW.spawnEntity(pL, EntityType.PRIMED_TNT);
                        tnt.setFuseTicks(config.getInt("Priming time"));
                        tnt.setCustomName("TNT");
                        tnt.setCustomNameVisible(true);
                        event.setCancelled(true);
                    }
            }
        }
    }
    Error message from config: https://pastebin.com/j1JELPAz
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    Dragonhuntrrr

    How do i fix it? I've tried naming the tnt's
     
  4. Offline

    timtower Administrator Administrator Moderator

    @Dragonhuntrrr Custom name is done after the event gets called.
    Why are you even spawning a new one? One not modify the one that gets spawned instead?
     
  5. Offline

    Dragonhuntrrr

    @timtower I did not know that was possible...

    I got it working!
    Here is the code, if anyone is curious
    Code:
    @EventHandler
        public void onPrime(EntitySpawnEvent event) {
            if (event.getEntity() instanceof TNTPrimed) {
                if (!getConfig().getBoolean("Insta prime")) {
                            ((TNTPrimed)event.getEntity()).setFuseTicks(getConfig().getInt("Priming time"));
                    }
            }
        }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Feb 12, 2021
Thread Status:
Not open for further replies.

Share This Page