Hello all, if you are reading this, I need help on "throwing tnt". I've tried many things to fix it but it is still not working! If you could just please make a code for me from scratch and take notes off this one? Thanks! My current code: Code: import org.bukkit.*; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; public class Main extends JavaPlugin implements Listener { public Main() { } public void onEnable() { Bukkit.getServer().getPluginManager().registerEvents(this, this); } @EventHandler public void onPlayerInteractEvent(PlayerInteractEvent event) { Player player = event.getPlayer(); if(player.getInventory().getItemInHand().getType() == Material.TNT && event.getAction() == Action.RIGHT_CLICK_AIR) if(player.hasPermission("tnt.use")) { TNTPrimed tnt = (TNTPrimed)player.getWorld().spawn(player.getEyeLocation(), EntityType.PRIMED_TNT); tnt.setVelocity(player.getEyeLocation().getDirection().multiply(2)); tnt.setFuseTicks(40); int amount = player.getInventory().getItemInHand().getAmount(); if(--amount == 0) player.getInventory().removeItem(new ItemStack[] { new ItemStack(Material.TNT) }); else player.getInventory().getItemInHand().setAmount(amount); } else { player.sendMessage((new StringBuilder()).append(ChatColor.RED).append("You are not allowed to throw TNT.").toString()); } } } Hopefully you can help me, thanks.
No, it's org/bukkit/entity/TNTPrimed. It just gives an error, I thought it would work because I saw this bit from other peoples throwing TNT thing. I've tried TNTPrimed.class to but that works but it makes an error somewhere else, sorry, I'm on my ipad I can't check it now, got to go to school! Thanks
Code:java TNTPrimed tnt = (TNTPrimed)player.getWorld().spawn(player.getEyeLocation(), org/bukkit/entity/TNTPrimed); should be Code:java TNTPrimed tnt = player.getWorld().spawn(player.getEyeLocation(), TNTPrimed.class); or Code:java TNTPrimed tnt = (TNTPrimed)player.getWorld().spawnEntity(player.getEyeLocation(), EntityType.PRIMED_TNT); NINJA'D
Awesome, it's all working but I just want to add one more thing, a 3 second cool down to use the tnt. I've seen the Schedular programming page and stuff, but I can't seem to set it up with this so could you please help me?
Don't use schedulers for cooldowns (for goodness sake, this is such a common problem- and now we get to watch a 7 minute long video to tell us the wrong way to do it?) Just store the last time each player used the command in a hashmap. Check the time when using the command to make sure they've used it long enough ago. Pretty simple really, and not broken like it will be if you use a scheduled task.
Hmm, that didn't really work. Can someone else please help me? bump EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Your problem should be solved by now. The only way we could help you is if you give you insight into what your current problem is.
What about it didn't work? I explained how to handle cool downs for this, did you try it? Get an error? Have any code or stack traces to share?
BungeeTheCookie I've tried to implement it but it didn't work. Can you just try to implement it to my code above. thanks
Mr_Squidels This isn't a "code for you" section Go to plugin requests if that is your only intent of coming here.