-
-
Notifications
You must be signed in to change notification settings - Fork 658
fix: debounce BlockRedstoneEvent to prevent server lag from high-frequency redstone fluctuations #2297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: version/7.0.x
Are you sure you want to change the base?
fix: debounce BlockRedstoneEvent to prevent server lag from high-frequency redstone fluctuations #2297
Changes from all commits
59ad04f
f3b3bee
4726723
f945ffb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * WorldGuard, a suite of tools for Minecraft | ||
| * Copyright (C) sk89q <http://www.sk89q.com> | ||
| * Copyright (C) WorldGuard team and contributors | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify it | ||
| * under the terms of the GNU Lesser General Public License as published by the | ||
| * Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License | ||
| * for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package com.sk89q.worldguard.bukkit.listener.debounce; | ||
|
|
||
| import org.bukkit.block.Block; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * A key for debouncing BlockRedstoneEvents. | ||
| * | ||
| * Identifies a redstone change by the block location and new power state, so | ||
| * that repeated events for the same transition are coalesced into a single | ||
| * sponge check. | ||
| */ | ||
| public class BlockRedstoneKey { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you able to please swap this to a record?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel we should also be encoding the power levels in here, as otherwise we could be losing information about "turn on / turn off" – and purely seeing it as a "turn on" |
||
|
|
||
| private final String worldName; | ||
| private final int x; | ||
| private final int y; | ||
| private final int z; | ||
| private final boolean powered; | ||
|
|
||
| public BlockRedstoneKey(Block block, boolean powered) { | ||
| this.worldName = block.getWorld().getName(); | ||
| this.x = block.getX(); | ||
| this.y = block.getY(); | ||
| this.z = block.getZ(); | ||
| this.powered = powered; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (!(o instanceof BlockRedstoneKey)) return false; | ||
| BlockRedstoneKey that = (BlockRedstoneKey) o; | ||
| return x == that.x && y == that.y && z == that.z | ||
| && powered == that.powered && worldName.equals(that.worldName); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(worldName, x, y, z, powered); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment change here probably shouldn't be done