Lightning Strike by Sword Hit Air/Player

Discussion in 'Plugin Development' started by thekiller2552, Nov 26, 2012.

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

    thekiller2552

    I cant find in the internet a code for this can you pls give me an example i want to write it allone so dont give me that much help i will learn it!

    thank you thekiller2552
     
  2. Offline

    andf54

    location.getWorld().strikeLightning(location);
     
  3. Offline

    thekiller2552

    Thank you and what is the code for Diamondsword leftclick ?
     
  4. Offline

    andf54

    listen to PlayerInteractEvent and you might also need to listen to EntityDamageByEntity event.
     
  5. Offline

    thekiller2552

    ähhh what ?!
     
  6. Offline

    andf54

    You can start by googling: bukkit tutorial
     
  7. Offline

    thekiller2552

    did i need a listener ? At the moment i have this :
    Code:
    package de.thekiller2552.Blitzschwert;
     
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Blitzschwert extends JavaPlugin implements Listener {
       
        public void onEnable(){getServer().getPluginManager().registerEvents(this, this);}
        public void onDisable(){};
        public interface ServerOperator {
            public boolean isOp();
           
            public void setOP(boolean value);
        }
       
        @EventHandler
        if ((event.getItem()  !=  Null) &&  (event.getItem().getType() == Material.DIAMOND_SWORD){
           
            }
     
    }
    
     
  8. Offline

    repsor

    Well: maybe it's better to actually learn how to make a plugin before posting questions on the forum. I know you said you're learning, but try the bukkit tutorial on the bukkit wiki or the youtube tutorials to learn the basics (for youtube: I recommend the BCBroz). It's really better to start from the beginning instead of beginning on a specific subject, believe me.

    links:
    wiki:http://wiki.bukkit.org/Plugin_Tutorial
    BCBroz (only nummer 1: you have to watch more :)):
     
  9. Offline

    thekiller2552

    ok thank you for the link i just wrote a plugin before posting this thread and the plugin works fine :)
     
  10. Offline

    repsor

    I believe you but if you've never heard of playerinteractevent, have (looking to your current code) no idea what the context is of an eventhandler and your question is pretty basic than I'm pretty sure your plugin isn't really, well how do you say that? big? Anyway: if I'm not right, please tell me!

    for the playerinteractevent try this:


    Code:
    public void rightclick(PlayerInteractEvent event){
            if((event.getAction() == Action.RIGHT_CLICK_AIR) || (event.getAction() == Action.RIGHT_CLICK_BLOCK)){
    //stuf to do here
    }
    }
    in this you will: 1. have to check if the item that the player clicked with is a diamond sword
    2. strike lightning at the location the player is looking at

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  11. Offline

    thekiller2552

    like this ?

    Code:
    package de.thekiller2552.Blitzschwert;
     
    import java.util.logging.Logger;
     
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Blitzschwert extends JavaPlugin implements Listener {
        public final Logger logger = Logger.getLogger("Minecraft");
        public static Blitzschwert plugin;
       
        @Override
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + "Wurde Deaktiviert!");
        }
       
        @Override
        public void onEnable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + "Wurde Aktiviert!");
        }
       
        public void rightclick(PlayerInteractEvent event){
            if((event.getAction() == Action.LEFT_CLICK_BLOCK) || (event.getAction() == Action.RIGHT_CLICK_BLOCK)){
                location.getWorld().strikeLightning(location);
            }
        }
    }
     
  12. Offline

    andf54

    You can't just type a bunch of code together without understanding and hope it works.

    1)You need to register your listener (rightclick), see tutorials on how to do it.
    2)Listener method must have an annotation @EventHandler(priority = 3)EventPriority.NORMAL).
    Location location = event.getBlock().getLocation() (or something like that)
     
  13. Offline

    repsor

    haha no: the location.getWorld().strikeLightning(location); is just an example: with location is ment the location the player is looking at. so you get:

    Code:
    Player player = event.getPlayer();
    Location location = player.getTargetBlock(null, 100).getLocation();
    player.getWorld().strikeLightning(location);
    
    If this is you're only plugin, this way of "learning" is fine. If you want to go "further" with it, I really recommend using tutorials for the basics.
     
Thread Status:
Not open for further replies.

Share This Page