Delay

Discussion in 'Plugin Development' started by Epixel, Oct 21, 2016.

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

    Epixel

    Hello.
    I'm making a warp plugin, where you should have a 10 second delay between the /warp command, and the actual teleport. However, the delay is VERY inconsistent. Sometimes it only takes a second to warp. Haven't experienced any situations where it counts too slow. Only where it warps you way faster than 10 seconds. Am I doing anything wrong, or is the problem in bukkit itself?
    @Override
    public void run() {
    if(AntiWarpMove.warping.contains(playerid)){
    int X = (int) plugin.warpsConfig.getConfig().get(playerid + "." + args[0].toLowerCase() + ".X");
    int Y = (int) plugin.warpsConfig.getConfig().get(playerid + "." + args[0].toLowerCase() + ".Y");
    int Z = (int) plugin.warpsConfig.getConfig().get(playerid + "." + args[0].toLowerCase() + ".Z");
    Location Warp = new Location(player.getWorld(), X, Y, Z);
    player.teleport(Warp);
    AntiWarpMove.warping.remove(playerid);
    }
    }
    }, 200);
     
  2. Offline

    Zombie_Striker

    This will never be the case unless you work with scoreboards.Scoreboards are a mess.

    1. Stop abusing static. If you want to access something from AntiWarpMove, then pass the instance through your class's constructor.
    2. Instead of casting, why not specify that you are getting an int by using "getInt()"
    3. Follow Java NamingConventions. Beginning with an Uppercase letter means it is a class and should not be used for Variables. All variables should start with a lower case letter.
    To fully understand why it is "VERY inconsistent", we will have to know about how you set up your move system. Please post your AntiWarpClass.
     
  3. Offline

    Epixel

    Ik it's late but:
    Code:
    public class AntiWarpMove implements Listener{
      
        public static ArrayList<String> warping = new ArrayList<String>();
      
        @EventHandler
        public void onPlayerMove(PlayerMoveEvent event){
            Player player = event.getPlayer();
            String playerid = player.getUniqueId().toString();
            if(event.getFrom().getBlockX() != event.getTo().getBloxkX || event.getFrom().getBlockZ() != event.getTo().getBloxkZ){
                if(warping.contains(playerid)){
                    player.sendMessage(ChatColor.GRAY + "You moved! Warping cancelled!");
                    warping.remove(playerid);
                    return;
                }
            }
        }
    
    }
     
  4. Offline

    Zombie_Striker

    These methods do not exists. If you're using an IDE, this should be underlined/ throwing errors. Change "Bloxk" to "Block".
    Why not compare UUIDs instead of Strings of UUIDs? This may be your issue. Replace all Strings with UUIDs.
     
Thread Status:
Not open for further replies.

Share This Page