Solved Better way than PlayerMoveEvent

Discussion in 'Plugin Help/Development/Requests' started by Hex_27, Apr 18, 2015.

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

    Hex_27

    I'm making a plugin similar to factions, but I need to check when a player goes to a different chunk. I use PlayerMoveEvent now, it works but it makes things kinda laggy. Is there a better way to check if a player enters a different chunk?
     
  2. Offline

    SpongyBacon

    Maybe use a Scheduler and check each player's location?
    Try to reduce what it happening inside your playermove event?
    Let them be inside a chunk but don't let them do anything inside it? e.g. breaking blocks.
     
  3. Offline

    Hex_27

    @SpongyBacon it needs to detect the chunks the player is on to send Messages "Your leaving bla bla bla" and also for map
     
  4. Offline

    Zombie_Striker

    • Make a scheduler
    • If after ____ amount of time, check if the player has left/entered the chunk
    This will have a delayed effect, but not a lot of memory needs to be used.
     
  5. Offline

    Hex_27

    @Zombie_Striker then the map/ ground notifications would seem laggy and inaccurate. The scheduler may be slower than player move event, but it is much less accurate.
     
  6. Offline

    dsouzamatt

    @Hex_27 Can we see your code? You only need to update maps and send notifications when a player moves between chunks, so unless you have a lot of other stuff in your method it shouldn't be causing that much lag.
     
  7. Offline

    Hex_27

    @dsouzamatt So are you saying it isn't supposed to lag here? Maybe its just the 1.8 laggyness...
    Code:
        @EventHandler
        public void onPlayerMove(PlayerMoveEvent event){
            Player p = event.getPlayer();
            if(event.getTo().getChunk() != event.getFrom().getChunk()){
                if(!getChunkKingdom(event.getTo().getChunk()).equals(getChunkKingdom(event.getFrom().getChunk()))){
                if(!getChunkKingdom(event.getTo().getChunk()).equals("")){
                    p.sendMessage(ChatColor.AQUA + "Entering " + ChatColor.YELLOW + getChunkKingdom(event.getTo().getChunk()));
                }else{
                    p.sendMessage(ChatColor.AQUA + "Entering unoccupied land");
                }
            }
            }
        }
     
  8. Offline

    dsouzamatt

    Yeah, that's how I would do it. I don't know why it would be lagging as much as you say it is though :eek: ...

    Maybe have a look at the source for Factions and see if they do it differently.
     
  9. Offline

    Hex_27

    @dsouzamatt Ugh factions. Its full of crap now. The code is weird now. I'll just mark this as solved then
     
Thread Status:
Not open for further replies.

Share This Page