When open a chest create a explosion

Discussion in 'Plugin Development' started by Iervolino, Jun 23, 2013.

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

    Iervolino

    I tried something like this but I got error o getChest and getDoubleChest..

    Code:
    public float explosionSize = 2.0F;
     
    @EventHandler
    public void onInventoryOpenEvent(InventoryOpenEvent event){
        if (event.getInventory().getHolder() instanceof Chest || event.getInventory().getHolder() instanceof DoubleChest){
            World.createExplosion(getChest(),getDoubleChest(), this.explosionSize);
        }
    }
     
  2. Offline

    Alex5657

    Use:
    Code:java
    1.  
    2. Location chestLoc=event.getInventory().getHolder().getLocation();
    3. chestLoc.getWorld().createExplosion(chestLoc,<power of the explosion>);
    4.  
     
  3. Offline

    peteyandpika

    player.getWorld().createExplosion(Location arg, explosion size put as a float);
     
  4. Offline

    Iervolino


    Getting error on GetLocation(): The method getLocation() is undefined for the type InventoryHolder


    * player cannot be resolved
    * The method getLocation() is undefined

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

    Alex5657

    Code:java
    1.  
    2. Location playerLoc=event.getPlayer().getLocation();
    3. playerLoc.getWorld().createExplosion(playerLoc,<power>);
    4.  
     
  6. Offline

    peteyandpika

    good work dawg
     
  7. Offline

    Iervolino


    Yes, but you are creating a explosion in the player and not in the Chest...

    Also, is there some way to create the explosion only for Trapped Chests?
     
  8. Offline

    Alex5657

    So? The player stand right in front of the chest. There is hardly any difference...
     
  9. Offline

    Iervolino


    Yes, the player can open the chest with 3-4 blocks of distance (will make a very huge difference)

    Also, is there some way to create the explosion only for Trapped Chests?
     
  10. Offline

    peteyandpika

    dude use the chests location not the players
     
  11. Offline

    Pawnguy7

    Perhaps you can use the onIteract event?
     
  12. Offline

    Iervolino


    Make a pseudo please, for when you open a trapped chest it explodes..
     
  13. Offline

    peteyandpika

    Code:java
    1. @EventHandler
    2. public void playerInteract(PlayerInteractEvent event) {
    3. Player player = event.getPlayer();
    4. Location location = event.getClickedBlock().getLocation();
    5. Block block = event.getClickedBlock();
    6. if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    7. if(block.getType() == Material.CHEST) {
    8. block.getWorld().createExplosion(location,<explosion power>);
    9.  


    put that in your Listener class, and yourwelcome if thats works for you

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
    Iervolino likes this.
  14. Offline

    Iervolino

    Oh, thanks, worked pretty well..

    Also is there some way to remove the block damage for explosion but still the player damage?


    LOL! Getting crash error on the console, the chest is exploding but I get error on console "Could not pass PlayerInteractEvent to (Plugin Name)"

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

    peteyandpika

    not sure, ill tell u if i find a way
     
  16. Offline

    xxmobkiller

    I thank you will just put where the <explosion power > is if i am not mistaking you will put a 0 where that is and it should not damage any bock but the player. I am still taking java class so i might not got that right if i did then i guss i am doing good in listening in class but if i did not then i gss i am not listening in class that good!
     
  17. Offline

    peteyandpika

    I just used the same code and it is not crashing

    You are wrong bull head guy, that prevents block damage but makes explosion 1 block small and deos not damage the player

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

    xxmobkiller

    I am going to see what i can do i am going to redo the code and see what happens and i bet that i will get this way faster then you!
     
  19. Offline

    peteyandpika

    wow i wish i saw your message earlier lol
    ill be starting late
     
  20. Offline

    xxmobkiller

    Lol i am testing it out right now, I thank i got it .
     
  21. Offline

    peteyandpika

    Mine works pretty good
     
  22. Offline

    xxmobkiller

    Code:
     @EventHandler
    public void playerInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    Location location = event.getClickedBlock().getLocation();
    Block block = event.getClickedBlock();
    if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    if(block.getType() == Material.CHEST) {
    block.getWorld().createExplosion(location,<explosion power>);
    

    this is error that i get when i use your code 2013-06-23 21:59:41 [SEVERE] Could not pass event PlayerInteractEvent to test v1.0
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
    at org.bukkit.craftbukkit.v1_5_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:190)
    at org.bukkit.craftbukkit.v1_5_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:160)
    at net.minecraft.server.v1_5_R3.PlayerConnection.a(PlayerConnection.java:617)
    at net.minecraft.server.v1_5_R3.Packet15Place.handle(SourceFile:58)
    at net.minecraft.server.v1_5_R3.NetworkManager.b(NetworkManager.java:292)
    at net.minecraft.server.v1_5_R3.PlayerConnection.d(PlayerConnection.java:115)
    at net.minecraft.server.v1_5_R3.ServerConnection.b(SourceFile:35)
    at net.minecraft.server.v1_5_R3.DedicatedServerConnection.b(SourceFile:30)
    at net.minecraft.server.v1_5_R3.MinecraftServer.r(MinecraftServer.java:581)
    at net.minecraft.server.v1_5_R3.DedicatedServer.r(DedicatedServer.java:226)
    at net.minecraft.server.v1_5_R3.MinecraftServer.q(MinecraftServer.java:477)
    at net.minecraft.server.v1_5_R3.MinecraftServer.run(MinecraftServer.java:410)
    at net.minecraft.server.v1_5_R3.ThreadServerApplication.run(SourceFile:573)
    Caused by: java.lang.NullPointerException
    at me.xxmobkiller.com.Main.onPlayerInteract(Main.java:24)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
    ... 16 more
     
  23. Offline

    peteyandpika

    you can't get it can you lol. im kinda busy developing my own plugin so you can handle this bull guy
     
  24. Offline

    xxmobkiller

    But i did find a way to stop the block damage here the code
     
  25. Offline

    peteyandpika

    wow why u get error, i dont get any error lol

    you screw up listener class lol
    no need for the code, i got one that works allready

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

    xxmobkiller

    Code:
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
     
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Main extends JavaPlugin implements Listener {
       
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
         
        }
     
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent e) {
                Player p = e.getPlayer();
                Location location = e.getClickedBlock().getLocation();
                Block block = e.getClickedBlock();
                if(e.getAction() == Action.RIGHT_CLICK_BLOCK || block.getType() == Material.CHEST){
                block.getWorld().createExplosion(location, 0);
                p.setHealth(15);
                }
            }
    }


    THERE IT IS JUST USE THAT AND IT WILL WORK JUST FINE IT DOSE NOT DO BLOCK DAMAGE BUT WILL ONLY THE PLAYER
     
  27. Offline

    Iervolino


    And what you do for stop the crash?
     
Thread Status:
Not open for further replies.

Share This Page