PrimedTnt

Discussion in 'Plugin Development' started by creepers84, May 18, 2013.

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

    GodzOfMadness

    creepers84 What's on line 88 in your onPlayerInteract method?
     
  2. Offline

    creepers84

    This:
    Code:
    Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
    This is all of it:
    Code:
    @EventHandler
    public void onPlayerInteract11111(PlayerInteractEvent event) {
        final Player player = event.getPlayer();
        if (event.getAction().equals(Action.RIGHT_CLICK_AIR)) {
            int blockId = player.getItemInHand().getType().getId();
            int blockSubId = player.getItemInHand().getDurability();
            if (blockId == 397 && blockSubId == 2) {
                if (player.hasPermission("zombie.fire")) {
                    final ItemStack item = new ItemStack(Material.ROTTEN_FLESH, 64);
                    Item item1 = player.getWorld().dropItem(player.getEyeLocation(), item);
                    Bukkit.getScheduler();
                    item1.setPickupDelay(60);
                    item1.setVelocity(player.getEyeLocation().getDirection().multiply(1.5D));
                    final Item thrown = item1;
                    Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
                        public void run() {
                            thrown.getWorld().strikeLightning(thrown.getLocation());
                            thrown.remove();
                        }
                    }, 60L);
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  3. Offline

    GodzOfMadness

    creepers84 If this method is in your main class just replace "plugin" with "this" without the quotes.
    If it's not in the main class then create a constructor and put in the paramaters MAINCLASS instance
    then create the object MAINCLASS plugin;
    and in the constructor just do plugin = instance;
    After that, it should work.
     
  4. Offline

    creepers84

    Dude, You are an amazing person. Thank-you so very much for your help. You have been Extremely cooperative. Thanks, But One last thing on the topic of PrimedTnt. (This whon't take long) How can I make this:
    Code:
    @EventHandler
    public void onPlayerInteract111(PlayerInteractEvent event){
        final Player player = event.getPlayer();
        if(event.getAction().equals(Action.RIGHT_CLICK_AIR)){
              int blockId = player.getItemInHand().getType().getId();
              int blockSubId = player.getItemInHand().getDurability();
              if (blockId == 397 && blockSubId == 4) { 
                  if(player.hasPermission("creeper.fire")){
                      player.getWorld().spawnEntity(player.getLocation(), EntityType.PRIMED_TNT);
    Toggleable so that in the config it can be something like:
    Creeper Head:
    Tnt Block Damage: On/off
    (So Basically Turning Block Damage on and off?) ONLY BLOCK DAMAGE =D
    Same with this:
    Code:
    public void onPlayerInteract1(PlayerInteractEvent event){
        final Player player = event.getPlayer();
        if(event.getAction().equals(Action.RIGHT_CLICK_AIR)){
              int blockId = player.getItemInHand().getType().getId();
              int blockSubId = player.getItemInHand().getDurability();
              if (blockId == 397 && blockSubId == 1) { 
                  if(player.hasPermission("wither.fire")){
                      player.launchProjectile(WitherSkull.class);
    So in the config:
    Wither Head:
    Skull Block Damage: On/off
    ??????????????????????????????????????
     
  5. Offline

    GodzOfMadness

    creepers84
    Create a file named "config.yml" and add it's defaults like
    Creeper-Head:
    Tnt-Block-Damage: true
    in your onEnable method(main class) add
    getConfig().options().copyDefaults(true);
    and saveDefaultConfig();
    using that method it will copy all comments and paths you put in the config.yml you created earlier.
    After that you get the boolean value in the interact method like
    getConfig().getBoolean("path.to.boolean");
    an example would be getConfig().getBoolean("Creeper-Head.Tnt-Block-Damage");
    now you would have to create an explosion rather than spawn the entity PRIMED_TNT to check
    like player.getWorld().createExplosion(x, y, z, power, setFire, breakBlocks);
    now you would do
    player.getWorld().createExplosion(x, y, z, power, setFire, getConfig().getBoolean("Creeper-Head.Tnt-Block-Damage"));
    so it would do the block damage or not depending if it's true or false in the config.
     
  6. Offline

    creepers84

    Like this:
    Code:
    @EventHandler
    public void onPlayerInteract111(PlayerInteractEvent event){
        final Player player = event.getPlayer();
        if(event.getAction().equals(Action.RIGHT_CLICK_AIR)){
              int blockId = player.getItemInHand().getType().getId();
              int blockSubId = player.getItemInHand().getDurability();
              if (blockId == 397 && blockSubId == 4) { 
                  if(player.hasPermission("creeper.fire")){ 
                      getConfig().getBoolean("Creeper-Head.Tnt-Block-Damage");
                      player.getWorld().createExplosion(x, y, z, power, setFire, getConfig().getBoolean("Creeper-Head.Tnt-Block-Damage"));
    ??????
    What do You suggest I change this:
    Code:
    player.getWorld().createExplosion(x, y, z, power, setFire, getConfig().getBoolean("Creeper-Head.Tnt-Block-Damage"));
    to?
     
  7. Offline

    GodzOfMadness

    creepers84 you change the x, y, z to the location value like the target block(Keep in mind that they would then have to click the ground or you can use player.getTargetBlock(null, 5).getLocation()). and then the power you can set that to how strong you want it. The setFire argument would mean if you want it to spawn fire or not. If you want it to spawn fire set that to true, else set it to false.
     
  8. Offline

    creepers84

    So if i wanted to make it similar to how it was would I change it to 1 1 1? for x y z?
     
  9. Offline

    GodzOfMadness

    creepers84 The x, y, z are coordinates. The Location stores the world, the x coordinate, y, z and also pitch/yaw
    So changing it to 1, 1, 1 would mean it would be 1 block above bedrock level and for x and z would be 1.
     
  10. Offline

    creepers84

    This is:
    Code:
    player.getWorld().createExplosion(player.getTargetBlock(null, 5).getLocation() , false,  getConfig().getBoolean("Creeper-Head.Tnt-Block-Damage"));
    Underlined in red
     
  11. Offline

    GodzOfMadness

    creepers84 When you hover over it, what does it say?
     
  12. Offline

    creepers84

    type world is not applicable for this etc........
     
  13. Offline

    GodzOfMadness

    creepers84 Can you show me all of your code you have right now?
     
  14. Offline

    creepers84

    Error: http://postimg.org/image/6y9bdtmij/
    Code:
    Code:
    package me.creepers84.projectilewither;
     
    import java.util.logging.Logger;
     
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Arrow;
    import org.bukkit.entity.Item;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.WitherSkull;
    import org.bukkit.event.EventHandler;
    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.plugin.java.JavaPlugin;
     
    public class ProjectileWither extends JavaPlugin implements Listener {
    public final Logger logger = Logger.getLogger("Minecraft");
    public static ProjectileWither plugin;
     
    @Override
    public void onDisable() {
    this.logger.info("[ProjectileWither] Plugin Disabled");
    }
     
    @Override
    public void onEnable() {
    this.logger.info("[ProjectileWither] Plugin Enabled");
    getServer().getPluginManager().registerEvents(this, this);
    getConfig().options().copyDefaults(true);
    saveDefaultConfig();
    }
     
    @EventHandler
    public void onPlayerInteract1(PlayerInteractEvent event){
        final Player player = event.getPlayer();
        if(event.getAction().equals(Action.RIGHT_CLICK_AIR)){
              int blockId = player.getItemInHand().getType().getId();
              int blockSubId = player.getItemInHand().getDurability();
              if (blockId == 397 && blockSubId == 1) { 
                  if(player.hasPermission("wither.fire")){
                      player.launchProjectile(WitherSkull.class);
                  }
              }
        }
    }
     
    @EventHandler
    public void onPlayerInteract11(PlayerInteractEvent event){
        final Player player = event.getPlayer();
        if(event.getAction().equals(Action.RIGHT_CLICK_AIR)){
              int blockId = player.getItemInHand().getType().getId();
              int blockSubId = player.getItemInHand().getDurability();
              if (blockId == 397 && blockSubId == 0) { 
                  if(player.hasPermission("skeleton.fire")){
                      player.launchProjectile(Arrow.class);
    }
                  }
              }
        }
    @EventHandler
    public void onPlayerInteract111(PlayerInteractEvent event){
        final Player player = event.getPlayer();
        if(event.getAction().equals(Action.RIGHT_CLICK_AIR)){
              int blockId = player.getItemInHand().getType().getId();
              int blockSubId = player.getItemInHand().getDurability();
              if (blockId == 397 && blockSubId == 4) { 
                  if(player.hasPermission("creeper.fire")){ 
                      getConfig().getBoolean("Creeper-Head.Tnt-Block-Damage");
                      player.getWorld().createExplosion(player.getTargetBlock(null, 5).getLocation() , false,  getConfig().getBoolean("Creeper-Head.Tnt-Block-Damage"));
                  }
                  }
              }
        }
    @EventHandler
    public void onPlayerInteract11111(PlayerInteractEvent event) {
        final Player player = event.getPlayer();
        if (event.getAction().equals(Action.RIGHT_CLICK_AIR)) {
            int blockId = player.getItemInHand().getType().getId();
            int blockSubId = player.getItemInHand().getDurability();
            if (blockId == 397 && blockSubId == 2) {
                if (player.hasPermission("zombie.fire")) {
                    final ItemStack item = new ItemStack(Material.ROTTEN_FLESH, 64);
                    Item item1 = player.getWorld().dropItem(player.getEyeLocation(), item);
                    Bukkit.getScheduler();
                    item1.setPickupDelay(60);
                    item1.setVelocity(player.getEyeLocation().getDirection().multiply(1.5D));
                    final Item thrown = item1;
                    Bukkit.getScheduler().runTaskLater(this, new Runnable() {
                        public void run() {
                            thrown.getWorld().strikeLightning(thrown.getLocation());
                            thrown.remove();
                        }
                    }, 60L);
     
                }
            }
        }
    }
    }
    
     
  15. Offline

    GodzOfMadness

    creepers84 The reason why it gave an error is because you replaced x, y, z, power with the location of the targetblock. Here is the updated code
    player.getWorld().createExplosion(player.getTargetBlock(null, 5).getLocation().getX(), player.getTargetBlock(null, 5).getLocation().getY(), player.getTargetBlock(null, 5).getLocation().getZ(), power, false, getConfig().getBoolean("Creeper-Head.Tnt-Block-Damage"));
    just replace "power" with the amount of power it will have when it explodes.
     
  16. Offline

    creepers84

    Thankyou. gtg now. Btw config doesn't work when switching options. there is no block damage either way.
     
  17. Offline

    GodzOfMadness

    creepers84 That means it doesn't read the config file properly. When you have time, could you show me your whole class so i can see if you are setting up the configuration properties correctly? Also could you tell me if you created the config.yml file in your project folder and you are compiling it in to the jar.
     
  18. Offline

    creepers84

    U online?

    I'll grab all the code and the config file....

    Code:
    Code:
    package me.creepers84.projectilewither;
     
    import java.util.logging.Logger;
     
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Arrow;
    import org.bukkit.entity.Item;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.WitherSkull;
    import org.bukkit.event.EventHandler;
    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.plugin.java.JavaPlugin;
     
    public class ProjectileWither extends JavaPlugin implements Listener {
    public final Logger logger = Logger.getLogger("Minecraft");
    public static ProjectileWither plugin;
     
    @Override
    public void onDisable() {
    this.logger.info("[ProjectileWither] Plugin Disabled");
    }
     
    @Override
    public void onEnable() {
    this.logger.info("[ProjectileWither] Plugin Enabled");
    getServer().getPluginManager().registerEvents(this, this);
    getConfig().options().copyDefaults(true);
    saveDefaultConfig();
    }
     
    @EventHandler
    public void onPlayerInteract1(PlayerInteractEvent event){
        final Player player = event.getPlayer();
        if(event.getAction().equals(Action.RIGHT_CLICK_AIR)){
              int blockId = player.getItemInHand().getType().getId();
              int blockSubId = player.getItemInHand().getDurability();
              if (blockId == 397 && blockSubId == 1) { 
                  if(player.hasPermission("wither.fire")){
                      player.launchProjectile(WitherSkull.class);
                  }
              }
        }
    }
     
    @EventHandler
    public void onPlayerInteract11(PlayerInteractEvent event){
        final Player player = event.getPlayer();
        if(event.getAction().equals(Action.RIGHT_CLICK_AIR)){
              int blockId = player.getItemInHand().getType().getId();
              int blockSubId = player.getItemInHand().getDurability();
              if (blockId == 397 && blockSubId == 0) { 
                  if(player.hasPermission("skeleton.fire")){
                      player.launchProjectile(Arrow.class);
    }
                  }
              }
        }
    @EventHandler
    public void onPlayerInteract111(PlayerInteractEvent event){
        final Player player = event.getPlayer();
        if(event.getAction().equals(Action.RIGHT_CLICK_AIR)){
              int blockId = player.getItemInHand().getType().getId();
              int blockSubId = player.getItemInHand().getDurability();
              if (blockId == 397 && blockSubId == 4) { 
                  if(player.hasPermission("creeper.fire")){ 
                      getConfig().getBoolean("Creeper-Head.Tnt-Block-Damage");
                      player.getWorld().createExplosion(player.getTargetBlock(null, 5).getLocation().getX(), player.getTargetBlock(null, 5).getLocation().getY(), player.getTargetBlock(null, 5).getLocation().getZ(), 2, false, getConfig().getBoolean("Creeper-Head.Tnt-Block-Damage"));
                  }
                  }
              }
        }
    @EventHandler
    public void onPlayerInteract11111(PlayerInteractEvent event) {
        final Player player = event.getPlayer();
        if (event.getAction().equals(Action.RIGHT_CLICK_AIR)) {
            int blockId = player.getItemInHand().getType().getId();
            int blockSubId = player.getItemInHand().getDurability();
            if (blockId == 397 && blockSubId == 2) {
                if (player.hasPermission("zombie.fire")) {
                    final ItemStack item = new ItemStack(Material.ROTTEN_FLESH, 64);
                    Item item1 = player.getWorld().dropItem(player.getEyeLocation(), item);
                    Bukkit.getScheduler();
                    item1.setPickupDelay(60);
                    item1.setVelocity(player.getEyeLocation().getDirection().multiply(1.5D));
                    final Item thrown = item1;
                    Bukkit.getScheduler().runTaskLater(this, new Runnable() {
                        public void run() {
                            thrown.getWorld().strikeLightning(thrown.getLocation());
                            thrown.remove();
                        }
                    }, 60L);
     
                }
            }
        }
    }
    }
    
    Config:

    Creeper-Head:
    Tnt-Block-Damage: true

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  19. Offline

    GodzOfMadness

    creepers84 Is it compiling in the jar? Do you see it in your plugins folder?

    EDIT: Do you see a folder named your plugin? if so go into it and tell me if you set a config.yml file
     
  20. Offline

    creepers84

    Yup

    Iv'e done that correctly + I've noticed it doesn't do player damage. =(

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  21. Offline

    GodzOfMadness

    creepers84 The explosion?
    Also make sure the path is exactly like the one in the config.yml or it wouldn't work. Make sure your spacing is correct, but remember to not use TAB.
     
  22. Offline

    creepers84

    is this correct Code:
    Code:
    getConfig().getBoolean("Creeper-Head.Tnt-Block-Damage"));
    Config:
    Creeper-Head:
    Tnt-Block-Damage: true
     
  23. Offline

    GodzOfMadness

    creepers84 Stupid question but is Config: in the config.yml? Can you also send a picture because it seems to not format it well when you post it.
     
  24. Offline

    creepers84

  25. Offline

    GodzOfMadness

    creepers84 Put two spaces before Tnt-Block-Damage: true
     
  26. Offline

    creepers84

    That works =D Yey But How can I make it do Player damage?
     
  27. Offline

    GodzOfMadness

    creepers84 It should. It's either another plugin preventing the player(you) from getting hurt, or it's power is too low.
     
  28. Offline

    creepers84

    The power is 2.

    Yet It still doesn't work + No other plugins are enabled

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  29. Offline

    GodzOfMadness

    creepers84 Then another plugin is denying you from taking damage.
     
  30. Offline

    creepers84

    No other plugins are enabled
     
Thread Status:
Not open for further replies.

Share This Page