Modifications on Spectator Menu

Discussion in 'Spigot Plugin Development' started by fifoudesbois69, Apr 21, 2017.

  1. Hey guys ! I've been developping spigot plugins for a few months now. Working on my Rush plugin, I need your help on a problem that I don't know how to solve (I'm french, so PLEASE, don't mind my errors).

    This Rush plugin is made for BungeeCord and for single servers, so the thing is that when it is being run on a single server, the players in spectator mode can teleport to ANY players in the server. Please don't tell me "Why don't you just disable teleportation for them ?" because I've already done that, just that I would like a better way to do this.

    I have some ideas that would work, I just don't know where to find the methods I need to override:

    First idea : the spectator mode gets every players in the server, so it must use a list, and if I could override it and replace it by the players in the player's world , maybe it would work.

    Second idea : if the first is impossible (logically), maybe it is possible to create a new Spectator Mode to code it myself, but then I would need some explanations.

    Third idea : if none of the others can work, just prevent menu from being opened (by packet I think).

    In the waiting of an answer, thank you !
     
  2. Instead of just putting them in Spectator mode, try to make them invisible and do some stuff so they can't interact with players who are alive
     
  3. Second idea I think ? Ok yeah I can give it a shot.

    EDIT: Do you know if it's possible to make players invisible for only certain players, not every (so spectator players could see each other but not the others) ?

    Ok, nevermind, I just asked Google.
     
    #3 fifoudesbois69, Apr 21, 2017
    Last edited: Apr 22, 2017
  4. Player.hidePlayer(OtherPlayer) maybe?
     
  5. Yeah, thank you, I should have checked on the Internet before answering, I'm gonna try things out, but do you really know no ways to only hide the menu from the Spectator Player, because the spectator mode is great (there's no health and experience bars...) ?
     
  6. Before writing my suggestion, I should maybe say, that I had to google to actually know what menu you are talking about. I have never been in spectator mode.

    If I understood it correctly you can open a menu in the hotbar by pressing a key (5?). To start an action you have to select one of the items in the hotbar and then select it again. Thus my suggestion would be to listen for PlayerItemHeldEvent which gets fired when "a player changes their currently held item". Then you can check whether the player is in spectator mode and if so, cancel the event. This should lead to the player not being able to use the menu.

    Hopefully that works in spectator mode. I have only my notebook at the moment and can't test it. Please try and tell me what happened, I am interested in it.
     
    • Like Like x 1
  7. Hey ! Thank you for your answer ! This is an interesting solution. I'll tell you this aternoon if it works ;)
     
    • Like Like x 1
  8. Ok, I just tested your solution Nikl, and it doesn't work, the PlayerItemHeldEvent doesn't trigger for a player in spectator gamemode. Anyway, thank you ;)
     
    • Informative Informative x 1