Stopping players from moving w/o PlayerMoveEvent

Discussion in 'Plugin Development' started by Nachoman44, May 25, 2014.

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

    Nachoman44

    Hey, so i'm creating a SG Plugin for funz but i've come across this pain in the butt problem with stopping players from moving, with this current code I have it works, but the players are still able to sprint jump and move AND they can repeatedly jump and avoid being stopped at all! So here's my code atm:

    CODE:
    Code:java
    1. if (player.isOnGround()){
    2. player.setWalkSpeed(0);
    3. player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 9999999 * 20, 9999999 * 20));
    4. }


    If not for the player.isOnGround check, if the player was jumping when the jump effect was added to him, it would stop and spam the console with "player x moved too quickly!". So, is there a better, more easier way to do this without a PlayerMoveEvent ?
     
    GrandmaJam likes this.
  2. Offline

    Gater12

    Nachoman44
    Why not a PlayerMoveEvent? Seems the logical and easiest way to do this.
     
  3. Offline

    Nachoman44

    Gater12
    The way my class is set up, this piece of code is in a method which starts an arena with the players, this method is in my ArenaManager class. So I would prefer to not have my ArenaManager class be a listener
     
    GrandmaJam likes this.
  4. Offline

    Gater12

    Nachoman44
    So create another class that wil designated to be listeners. Test for if players are in a starting arena and cancel the PlayerMoveEvent.
     
  5. Offline

    CoderMusgrove

    Nachoman44 you don't have to have it be a listener, make an external class that is a listener that will grab the ArenaManager, check if the game is running, and if not cancel movement.

    EDIT:
    Gater12 you little ninja..
     
    Gater12 likes this.
  6. Offline

    Nachoman44

    Gater12
    It's not possible for me to have a method that checks for a starting arena, it's either an in-game arena or it's not :confused:
     
  7. Offline

    Gater12

    Nachoman44
    Then make it. You are in control of what you are making - in programming.
    You can post your ArenaManager class if you don't know a way to implement this.
     
  8. Offline

    Nachoman44

    Gater12
    My ArenaManager class is huge... and I don't see a way of making an arena "starting" without completely changing the whole thing :/
     
  9. Offline

    CoderMusgrove

    Instead of checking for starting, just check for if it's running or not.
     
  10. Offline

    Nachoman44

    CoderMusgrove
    How would that work? if I check if they're in a running arena and stop their movement if they are, they wouldn't be able to move for the entire game?
     
  11. Offline

    CoderMusgrove

    Check it how you want it to. if it's NOT running, then cancel the event.
     
  12. Offline

    Gater12

    Nachoman44
    Here's one way I could think up of: When an arena is starting have it in a global Set (Faster to work with Sets at this scenario). Have a scheduled to task to remove that Arena from the Set and "start the game". Have a PlayerMoveEvent listener to listen if a player is in an arena and that arena is in that Set. Cancel the event. $$PROFIT$$
     
  13. Offline

    Nachoman44

    CoderMusgrove
    This is confusing me, here's the process of what happens:
    - Players join a lobby.
    - Once lobby is full, a 30 second timer will start
    - When the timer is at 0, all players in the lobby are teleported into the map and stopped from moving &
    all chests in that arena are filled randomly
    - A 15 second timer will start
    - After the timer ends, all players will be able to move.
     
  14. Offline

    Gater12

    Nachoman44
    When lobby timer is 0. Designate the arena in some sort of state. Check for when player moves, if the arena is in the state -> Cancel event. When the timer reaches 0 remove the arena from that state.
     
  15. Offline

    Nachoman44

    Gater12
    BOOM, got it working! My only problem is the ugliness of the event being cancelled. Is it possible to enable camera rotation?
     
    GrandmaJam likes this.
  16. Offline

    Gater12

    GrandmaJam likes this.
Thread Status:
Not open for further replies.

Share This Page