Lightning on a player when a word is said in chat

Discussion in 'Plugin Development' started by RoundishCrab4, Oct 20, 2012.

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

    RoundishCrab4

    Hi,
    I'm trying to make a plugin where when someone says something, it strikes someone on the server
    with lighting (will be defined either in code or config).
    This is my code so far, All it does is strikes lighting on the person that says the word.
    Code:
    package me.RoundishCrab4.Humiliate;
     
    import org.bukkit.Bukkit;
     
    import org.bukkit.ChatColor;
     
    import org.bukkit.event.EventHandler;
     
    import org.bukkit.event.Listener;
     
    import org.bukkit.event.player.AsyncPlayerChatEvent;
     
    public class PlayerListener implements Listener {
     
    @EventHandler
     
    public void onPlayerChat(AsyncPlayerChatEvent event) {
     
    if (event.getMessage().toLowerCase().contains("pie")) {
     
    event.getPlayer().getWorld().strikeLightning(event.getPlayer().getLocation());
     
    Bukkit.broadcastMessage(ChatColor.RED + "Someone was hit with lighting!");
     
    }
     
    }
     
    }
    Any help would be greatly appreciated
     
  2. Offline

    Tirelessly

    What are you asking for...? The code is right there.
     
  3. Offline

    RoundishCrab4

    Well I want it to hit a certain player when the command is said in chat...IT wont be an actual command like /strike Roundishcrab4. More like it will always strike one player if the word is said in chat...
     
  4. Offline

    bob7

    Wait... You want it to strike the person when they say that word or any word???
     
  5. Offline

    Tirelessly

    So set a variable to their name, see of they're online, and strike the lightning at their location... Not that hard..
     
  6. Offline

    CeramicTitan

    So, you want it to strike a random player but it strikes you instead?
     
  7. Offline

    Hoolean

    RoundishCrab4

    Hi,

    In the future, please use a code tag
    Code:
    like this
    for code. It makes it easier for people to read and also has an independant scroll!

    Thank you!
     
  8. Offline

    Infamous Jeezy

    If I'm understanding him correctly he may be trying to make it check if he said a certain word in chat.
    Not exactly a command but kind of how a profanity filter works, it checks for a certain word in the message.

    If using onCommand, you could collect all the arguments, and set up a for statement to check each one.
    You'd also have to make sure the player wasn't actually typing in a command rather than just typing.

    If using the AsyncPlayerChatEvent, I believe you'd have to parse the message.
    I'm not the best at parsing strings so I won't be as much help there.
     
  9. Offline

    RoundishCrab4

    When they say a certain word. It wouldn't be a random player, but it would be a player that was defined in the code.

    thanks haha i didn't know how to do that.

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

    Infamous Jeezy

    So are you trying to make the word a command like /word
    or are you trying to see if the player said the word in their message?

    Well the code in the OP seems like it'd work..
    Are you initiating the event handler correctly?
    Like this:
    Code:java
    1.  
    2. getServer().getPluginManager().registerEvents(new EventListener(this), this);
    3.  

    In your main class..
     
  11. Offline

    Hoolean

    I think he means chat, although I may be wrong and he was a bit confused...
     
  12. Offline

    RoundishCrab4

    Yeah that's what I mean, for example if i said pie, it would strike me with lightning or whoever was defined in the code. So if my friend said pie, whoever was defined in the code would be struck with lightning
     
  13. Offline

    Hoolean

    Some code coming...
     
  14. Offline

    Infamous Jeezy

    Doesn't his code in the first post have @EventHandler? :eek:
     
  15. Offline

    Hoolean

    Indeed it does...
    [​IMG]
     
  16. Offline

    Infamous Jeezy

    xD
    Can the OP post his main class?
    Did you try to add in a couple debug messages to make sure the event is even being executed?
     
  17. Offline

    Hoolean

    Right, replace:
    with:
    Code:
    Player chosenPlayer = Bukkit.getServer().getPlayer("playerusername");
    if(!chosenPlayer.equals(null) {
        chosenPlayer.getWorld().strikeLightning(chosenPlayer.getLocation();
    }
    ^ Code off the top of my head ^

    I think his problem was doing it to a different player!

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

    Infamous Jeezy

    Oh okay that makes sense. ^_^
     
  19. Offline

    RoundishCrab4

    Yes thanks, god I feel stupid...I really need to learn this stuff, do you guys know of any good resources. I watched the new boston tutorials and went on the wiki for the plugin tutorial but I'm still kinda lost. Like I know about methods, variables, and so on But I don't know how to actually make bukkit do what I want.
     
  20. Offline

    Hoolean

    Search for TheBCBroz on YouTube!
     
  21. Offline

    RoundishCrab4

    Yeah I watched a few of his videos, but I didn't really feel like I was learning anything, more like just copying what he was doing... Maybe if I go back now with the knowledge from the new boston I'll be better off. Thanks again!
     
  22. Offline

    Hoolean

    Yeah... that's what I was doing at first but I like how he always explains what he's doing :D
     
  23. I dont know if its already said, but dont run the bukkit methodes on non bukkit main threads, the ascry event is actually not thread safe, as stated by the Async Event, so you can never thruth the code to never give of errors
     
  24. Offline

    RoundishCrab4

    what do you mean? How would i fix my code...
     
  25. generate al information for your eevent inside onenable, acces it in the chat event and do whatever you want, if you want to stike lighting, schedule an bukkit thread to do so
     
  26. Offline

    RobotA69

    1. Find when the message is said
    2. Find the player
    3. Get the players location
    4. Strike there

    I'm not going to spoonfeed it to you, it's not that hard.
     
  27. Offline

    calebbfmv

    Would you tell your 1 month year old baby that? I sure hope not!
    Sometimes, some people need to be spoon fed in order to grasp the concept.
     
  28. Offline

    RoundishCrab4

    Thanks for sticking up for me, I'm still learning this and it's really frustrating when it doesn't work. I'm sorry for bothering any of you guys with my questions by the way.
     
  29. Offline

    calebbfmv

    Even though most of us don't like to admit it, we all were once in your spot!
     
  30. Offline

    RoundishCrab4

    Haha It's good to know that...Anyways thanks again for the help!
     
Thread Status:
Not open for further replies.

Share This Page