#Timer lag

1 messages · Page 1 of 1 (latest)

sturdy violet
#

It's the first block placed. The rest of the block place events gets fired immediately after I turn off NetLimiter

solid rapids
#

e

#

llo

odd ermine
#

hmm, interesting

#
@EventHandler
        public void onPlace(BlockPlaceEvent event) {
            Player player = event.getPlayer();

            if (BridgeSession.this.player != event.getPlayer()) { return; }

            Location location = event.getBlock().getLocation();
            placedBlocks.add(location);

            boolean inRangeX = ((xMax == xMin || location.getBlockX() > xMin + 2) && location.getBlockX() < xMax - 2);
            boolean inRangeY = (location.getBlockY() < yMax);
            boolean inRangeZ = (location.getBlockZ() > zMin + 2 && location.getBlockZ() < zMax - 2);

            if (!inRangeX || !inRangeY || !inRangeZ) {
                event.setCancelled(true);
            } else {
                BridgeSession.this.blockLoc = location;

                if (!count) {
                    BridgeSession.this.time = BigDecimal.ZERO;
                    start = Instant.now();
                    count = true;
                    replayID = player.getUniqueId() + "_" + Instant.now().toEpochMilli();
                    ReplayAPI.getInstance().recordReplay(replayID, player, location, player);
                }
                blocks ++;
                if (player.getItemInHand().getAmount() <= 15) {
                    refill();
                }
            }
        }```
#

posting so i can see

solid rapids
#

oh

#

my

#

god

#

what

#

in the shit

odd ermine
#

haha

solid rapids
#

I want to commit unalive

#

how do you expect BridgeSession.this.player to work

odd ermine
#

I told them to fix that and they have

#

that is a bit outdated

solid rapids
#

ohk

#

so you're not the one that wrote that right

odd ermine
#

But I understand the issue now, you're not starting the timer until the player has already moved across all those blocks, thus the advantage

odd ermine
solid rapids
#

o ohk

odd ermine
#

time to think of a solution to this

solid rapids
#

isn't it really easy?

#
  • On place block
    | - Check if the player is already bridging
    | | - Yes? Do nothing
    | | - No? Set the player as bridging, and store their time

  • On step on pressure plate
    | - Check if the player is already bridging
    | | - Yes? Stop the timer and get the difference from the start from now and teleport them to the start
    | | - No? Do nothing

#

bam

#

its that easy

odd ermine
#

that's already what they do

#

the issue is they have laggy players that can freeze up at the start, placing blocks on their client, then it catches up on server-side, but they're already halfway across the map when the timer starts

solid rapids
#

try to lag them back?

#

or

#

add their ping

#

to the time

odd ermine
#

lagback seems to be the only easy solution tbh

solid rapids
odd ermine
#

I want to say you could use transaction packets

#

but that's getting really hacky for something so simple

sturdy violet
solid rapids
#

lag them back

sturdy violet
#

That might be solution. What I wish I could do, is to somehow get the time the packet was sent. And then use that time instead of when the packet was received

odd ermine
#

yeah if you want an easy solution, lag them back

#

if you want the hard solution, transaction packets (probably?)

sturdy violet
#

Any idea how?

#

Updated code btw (without debug messages):

@EventHandler
        public void onPlace(BlockPlaceEvent event) {
            Player player = event.getPlayer();

            if (this.player == null || !this.player.getUniqueId().equals(player.getUniqueId())) { return; }

            Location location = event.getBlock().getLocation().clone();
            placedBlocks.add(location);

            boolean inRangeX = ((xMax == xMin || location.getBlockX() > xMin + 2) && location.getBlockX() < xMax - 2);
            boolean inRangeY = (location.getBlockY() < yMax);
            boolean inRangeZ = (location.getBlockZ() > zMin + 2 && location.getBlockZ() < zMax - 2);

            if (!inRangeX || !inRangeY || !inRangeZ) {
                event.setCancelled(true);
            } else {
                this.blockLoc = location;

                if (!count) {
                    this.time = BigDecimal.ZERO;
                    start = Instant.now();
                    count = true;
                    replayID = player.getUniqueId() + "_" + Instant.now().toEpochMilli();
                    ReplayAPI.getInstance().recordReplay(replayID, player, location, player);
                }
                blocks ++;
                if (player.getItemInHand().getAmount() <= 15) {
                    refill();
                }
            }
        }
sturdy violet
odd ermine
#

one moment

odd ermine
#

well, you could send a transaction packet every tick and when the player starts a lagspike, you'll be waiting for a response from the client for one, so when that returns you can calculate the time between sending it and receiving it, but that's very hacky and idk if there's a better way