Blow yourself up

Discussion in 'Plugin Development' started by Hazematman, Feb 18, 2011.

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

    Hazematman

    Im trying to write a plugin where if you type /allah you will blow your self up, im pretty new to java and to plugin development. I belive there is a class for creating explosions from reading here http://javadoc.lukegb.com/Bukkit/d1/d3a/classnet_1_1minecraft_1_1server_1_1Explosion.html . From my short knowledge I know I would need to create an if statment in my PlayerListener.java file that says if player says "/Allah" create explosion in player current world, at player current postion, and the rest of the explosion arguments. But my problem is i don't know how to call the explosion class and what some of the arguments are so I was hoping someone here could help me, please?

    if it helps this is my allahPlayerListener.java file so far
    Code:
    package com.bukkit.hazematman.Allah;
    
    import java.io.*;
    import org.bukkit.Location;
    import org.bukkit.entity.*;
    import org.bukkit.event.player.PlayerChatEvent;
    import org.bukkit.event.player.PlayerEvent;
    import org.bukkit.event.player.PlayerListener;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.inventory.*;
    import org.bukkit.material.MaterialData;
    import org.bukkit.*;
    
    
    
    
    
    /**
     * Handle events for all Player related events
     * @author Hazematman
     */
    public class allahPlayerListener extends PlayerListener {
        private final allah plugin;
    
        public allahPlayerListener(allah instance) {
            plugin = instance;
        }
        
        public void onPlayerCommand(PlayerChatEvent event) {
        	String[] split = event.getMessage().split(" ");
        	
        	Player player = event.getPlayer();
        	
        	 if ((split[0].equalsIgnoreCase("/Allah"))) {
        		 
        	 }
        }
    
        
    
    }
    
     
  2. Offline

    Edward Hand

    First off, you might like to read this thread:

    http://forums.bukkit.org/threads/on-namespaces-please-do-not-use-bukkit-in-your-plugins.3732/

    Now, to your question. I looked through the code for an example of the class in use and found this.

    Code:
    //(found in World class)
    
    
    public Explosion a(Entity entity, double d0, double d1, double d2, float f, boolean flag) {
         Explosion explosion = new Explosion(this, entity, d0, d1, d2, f);
    
         explosion.a = flag;
         explosion.a();
         explosion.b();
         return explosion;
    }
    Everything in the game that makes a crater does so by calling this function, so trying to call this function would be a good place to start.

    From what I can tell the parameters for the above function should be
    a(EntityToDestroy, XCoord, YCoord, ZCoord, craterRadius, SetOnFire?).
    EntityToDestroy is passed as null for TNT and Ghast fireballs, but creepers pass a reference to themselves, so I'm not entirely sure what you need to use in this instance.

    I would recommend starting with something like this:

    Code:
    //get a reference to the right world class:
    WorldServer world = ((CraftWorld)plugin.getServer().getWorlds().get(0)).getHandle();
    //call the function:
    world.a((Entity)null, player.getLocation().x,player.getLocation().y,player.getLocation().z,3.0F,false);
    //(3 is the radius for creeper explosions)
    
    and playing with it from there.
     
  3. Offline

    Hazematman

    Thank you so much!!!!
    its work perfectly

    I fixed the namespace thing too here is the new allahPlayerListener.java
    Code:
    package hazematman.allah;
    
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerChatEvent;
    import org.bukkit.event.player.PlayerListener;
    import org.bukkit.craftbukkit.CraftWorld;
    import net.minecraft.server.WorldServer;
    
    public class allahPlayerListener extends PlayerListener{
             public static allah plugin;
              public allahPlayerListener(allah instance) {
                    plugin = instance;
                }
    
              public void onPlayerCommand(PlayerChatEvent event) {
                            String[] split = event.getMessage().split(" ");
    
                            Player player = event.getPlayer();
    
                            if ((split[0].equalsIgnoreCase("/allah"))){
                            	//get a reference to the right world class:
                            	WorldServer world = ((CraftWorld)plugin.getServer().getWorlds().get(0)).getHandle();
                            	//call the function:
                            	world.a(null, player.getLocation().getX(),player.getLocation().getY(),player.getLocation().getZ(),3.0F,false);
                            	//(3 is the radius for creeper explosions)
    
                            }
    
                    }
    }
    
     
Thread Status:
Not open for further replies.

Share This Page