How to get the player that you hit?

Discussion in 'Spigot Plugin Development' started by ZevoGaems, May 6, 2017.

  1. I am making a staff hotbar plugin that you can toggle on and off. I am adding a freeze feature so you can click the player to freeze them. I would like to know how would I detect who stick hits so when that happens I can take it and use the freeze plugin api that I use? Thanks :)
  2. There is a playerDamageEvent (or EntityDamageEvent) and it has a methode you can call to know the player who was attacked and I think you can call who you attacked.
  3. Please use the Spigot docs found here: You keep asking a lot of basic questions that if you just googled or looked up the event, you could solve easily
  4. Code (Text):
    public void onPlayClick(PlayerInteractEntityEvent e){
            if (e.getRightClicked() == instanceof player){
    //Your Code here
    Should work. Sorry for mistakes Im writing on a Smartphone.
  5. Ok thanks that works :D
  6. I actually did look it up and I didn't find anything, I didn't spend much time but this is a very fast way to get the information that I would like to have.
  7. No problem. It's very simple.
  8. Actually it says that RIGHT_CLICK_AIR can't be resolved as a variable. Here is my code.
    Code (Text):
        public void onPlayClick(PlayerInteractEntityEvent e) {
            if(e.getAction(RIGHT_CLICK_AIR) {
                if (e.getRightClicked() instanceof Player) {
                    Player player = (Player) e.getRightClicked();
                    player.sendMessage(ChatColor.GREEN + "Testing Approved");
    • Optimistic Optimistic x 1
  9. Seems odd... That an enum constant isn't a variable... Maybe a bit of Java knowledge could solve this?
    It's called pseudo-code, don't copy and paste other people's code and automatically assume it to work.

    I'll give you a hint though,

    The code also doesn't have a second closing parenthesis, preventing it from working as well, however I'll leave you to solving that, since that is basic Java comprehension.
  10. Adding on to this, you don't even need the check as the method only has right clicks and it will only fire when you right click an entity
    • Agree Agree x 1
  11. Please just tell me I don't know I am not the best with java (obviously)
  12. We're not here to write plugins here for you. We're trying to help you learn. Experiment with stuff, he gave you a hint: ActionType. Experiment with that in eclipse, or do some research on it
    • Winner Winner x 1
  13. Research goes a long way, I promise you.

    give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime

    Get the fundamentals of Java down and then come back to Spigot. I promise you it will help, and from personal experience, changes your perception of problems like these. We're not trying to criticize you in any way, just trying to help you understand the API better and learn how to solve problems like these on your own.
  14. I agree with the others... learn Java before touching Spigot, but considering this is an extremely simple fix, I believe you need to compare using == and ActionType. Also, you should in fact probably use != and continue for that statement, or for cleaner code IMO you could just return if it == RIGHT_CLICK_AIR. I'm not sure if it would even matter though, because I'm sure this event only fires when you click an entity, which means you'll never right click air. :/

    Sent from my iPhone using Tapatalk
    • Agree Agree x 1