Solved Player Commands

Discussion in 'Plugin Development' started by klofno1, Jul 16, 2013.

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

    klofno1

    Could someone tell me how create a plugin that casts a spell when you type in a word? For example, if I say 'lightning' in chat. Lightning will appear and hits my target.
     
  2. Offline

    soulofw0lf

    listen for a chat event, check if the message equals lightning, if it does cancel the event and have your spell effect go off
     
  3. Offline

    xTrollxDudex

    soulofw0lf
    No tahging? klofno1
    Also PlayerChatEvent is deprecated which means you need AsyncPlayerChatEvent
     
  4. Offline

    klofno1

    xTrollxDudex soulofw0lf Thank you, but if I say Lightning, I hit myself and not the thing I am looking at. I tried using eyelocation but it was not what I thought it was.

    Code:
     player.strikeLightning(player.getTargetBlock());  
     
  5. Offline

    xTrollxDudex

    klofno1
    Get target block has arguments.
    PHP:
    player.getTargetBlock(null100)
    *on a side note some servers are limited to a 100 block range, better safe.
     
  6. Offline

    klofno1


    Error:
    The method strikeLightning(Block) is undefined for the type Player

    Code:java
    1. @EventHandler
    2. public void onInteract(PlayerInteractEvent event){
    3. if(event.getAction() == (Action.LEFT_CLICK_BLOCK) || event.getAction() == (Action.LEFT_CLICK_AIR)) {
    4. Player player = event.getPlayer();
    5. if(event.getPlayer().getItemInHand().getType()==Material.STICK) {
    6. player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 70, 2));
    7. player.sendMessage("OMG POOF!");
    8. player.strikeLightning(player.getTargetBlock(null, 100));


    *I'll add the player chat listener later*
     
  7. Offline

    xTrollxDudex

    klofno1
    You need to find the blocks location.... getTargetBlock(null, 100).getLocation()
     
  8. Offline

    klofno1

    I am sorry, I added that after I posted the code in my previous post. Still the same error.

    Complete code :

    Code:java
    1. package me.Magic.JonathanNLD;
    2.  
    3. import org.bukkit.Material;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.block.Action;
    8. import org.bukkit.event.player.AsyncPlayerChatEvent;
    9. import org.bukkit.event.player.PlayerInteractEvent;
    10. import org.bukkit.potion.PotionEffect;
    11. import org.bukkit.potion.PotionEffectType;
    12.  
    13. public class SpellsListener implements Listener {
    14.  
    15. @EventHandler
    16. public void onInteract(AsyncPlayerChatEvent event){
    17. Player player = event.getPlayer();
    18. event.getMessage();
    19. if (event.getMessage().contains("Lightning")){
    20. player.sendMessage("OMG POOF!");
    21. player.strikeLightning(player.getTargetBlock(null, 100).getLocation());
    22. }
    23. }
    24. }
    25.  
    26.  
    27.  


    EDIT : GOT IT I forgot the .getWorld()
     
  9. Offline

    xTrollxDudex

    klofno1
    Please read the javadocs and learn some more java. It's player.getWorld().strikeLightning(....)
     
  10. Offline

    klofno1

    I am learning, I have taken some classes and I have completed the basics. I forgot the .getWorld part while rewriting.
     
Thread Status:
Not open for further replies.

Share This Page