Solved HashMap error?

Discussion in 'Spigot Plugin Development' started by sandeep, Aug 13, 2017 at 11:18 AM.

Thread Status:
Not open for further replies.
  1. Ok so I have a map:
    Code (Text):

        private Map<UUID, Map.Entry<Long, Double>> fly = new HashMap<UUID, Map.Entry<Long, Double>>();
     
    Whenever I put something inside of it:
    Code (Text):

            this.fly.put(player.getUniqueId(), new AbstractMap.SimpleEntry<Long, Double>(b, a));
     
    And I put debug code to check if the map contains the key it prints true, but when the event (PlayerMove) is again called the map looses the key? So like:
    Code (Text):

            if (this.fly.containsKey(player.getUniqueId())) {
     
    will never be called because the map looses the key afterwards and the put code is at the end of the method


    So what should I do? I have noticed this with a few projects now, it may be java version, I do not know.
     
  2. Please post you your full class.
     
  3. Code (Text):

       
    package me.sunny.dragoanticheat.checks.movement;

    import java.util.AbstractMap;
    import java.util.HashMap;
    import java.util.Map;
    import java.util.UUID;

    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockFace;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;

    import me.sunny.dragoanticheat.anticheat.AlphaDragon;
    import me.sunny.dragoanticheat.checks.utils.Distance;
    import me.sunny.dragoanticheat.util.CheckResult;

    public class FlyDragon {

        private Map<UUID, Map.Entry<Long, Double>> fly = new HashMap<UUID, Map.Entry<Long, Double>>();
       
        public CheckResult CheckFly(PlayerMoveEvent event, Player player) {

            if (!player.getAllowFlight() && player.isFlying()) {
                event.setFrom(event.getTo());
                event.setTo(event.getFrom());
                return new CheckResult(player, "&d&lDAC &8» &f" + player.getName() + " has failed &fFly Type A (isFlying but is not allowed to Fly)", CheckResult.Result.FAIL);
            }
            if (event.getFrom().getY() >= event.getTo().getY()) {
                return new CheckResult(player, "", CheckResult.Result.PASS);
            }
            if (!AlphaDragon.getInstance().isEnabled()) {
                return new CheckResult(player, "", CheckResult.Result.PASS);
            }
            if (player.getAllowFlight()) {
                return new CheckResult(player, "", CheckResult.Result.PASS);
            }
            if (player.getVehicle() != null) {
                return new CheckResult(player, "", CheckResult.Result.PASS);
            }
            if (AlphaDragon.getInstance().LastVelocity.containsKey(player.getUniqueId())) {
                return new CheckResult(player, "", CheckResult.Result.PASS);
            }

            long Time = System.currentTimeMillis();
            double TotalBlocks = 0.0;
           
            if (this.fly.containsKey(player.getUniqueId())) {
                Time = this.fly.get(player.getUniqueId()).getKey();
                TotalBlocks = this.fly.get(player.getUniqueId()).getValue();
            }
            long MS = System.currentTimeMillis() - Time;
            double OffsetY = new Distance(event).getyDiff();
            if (OffsetY > 0.0) {
                TotalBlocks += OffsetY;
            }
           
            double Limit = 0.5;
            if (player.hasPotionEffect(PotionEffectType.JUMP)) {
                for (PotionEffect effect : player.getActivePotionEffects()) {
                    if (!(effect.getType() == PotionEffectType.JUMP)) continue;
                    int level = effect.getAmplifier() + 1;
                    Limit += Math.pow(level + 4.2, 2.0) / 16.0;
                    break;
                }
            }
            if (TotalBlocks > Limit) {
                if (MS > 100) {
                    Time = System.currentTimeMillis();
                    event.setFrom(event.getTo());
                    event.setTo(event.getFrom());
                    return new CheckResult(player, "&d&lDAC &8» &f" + player.getName() + " has failed &fFly Type B (Flying up " + TotalBlocks + " blocks)", CheckResult.Result.FAIL);
                }
            } else {
                Time = System.currentTimeMillis();
            }
           
            double a = TotalBlocks;
            long b = Time;
            this.fly.put(player.getUniqueId(), new AbstractMap.SimpleEntry<Long, Double>(b, a));
                   
            return new CheckResult(player, "", CheckResult.Result.PASS);

        }
    }
     
     
  4. md_5

    Administrator Developer

    Are you making a new class every event call perhaps
     
  5. Code (Text):

        public CheckResult CheckFly(PlayerMoveEvent event, Player player) {
     
    and it is registered in a backend class so it is not all separated:
    Code (Text):

    @EventHandler
        public void move(PlayerMoveEvent event) {
           
            CheckResult result;
            SprintDragon sprintCheck = new SprintDragon();
            result = sprintCheck.Check(event, event.getPlayer());
            if (result.getResult() != CheckResult.Result.PASS) {
                AlphaDragon.getInstance().logCheat(event.getPlayer(), result.getText());
            }
           
            SpeedDragon speedCheck = new SpeedDragon();
            result = speedCheck.Check(event, event.getPlayer());
            if (result.getResult() != CheckResult.Result.PASS) {
                AlphaDragon.getInstance().logCheat(event.getPlayer(), result.getText());
            }
           
            FlyDragon flyCheck = new FlyDragon();
            result = flyCheck.CheckFly(event, event.getPlayer());
            if (result.getResult() != CheckResult.Result.PASS) {
                AlphaDragon.getInstance().logCheat(event.getPlayer(), result.getText());
            }
           
        }
     
  6. Also I am not using maps of any kind for any other checks not even violations because it wouldn't work due to this bug (call it what you want) and whenever I use a cheat it just says
    Code (Text):

    DAC > LavaOG has failed Speed (Walking speed of 7.85) x1
     
    So that just means the map keeps reseting idk why
     
Thread Status:
Not open for further replies.

Share This Page