Skip to content

Commit

Permalink
Fix 1.20 hanging signs, attempt to fix most Folia-related issues.
Browse files Browse the repository at this point in the history
* #305 Another attempt at fixing AutoSign with the editing mechanic.
So far, we do not have a specific event for player-editing, so everything has to be manually detected.
Player-editing-speed cannot be monitored due to PlayerInteractEvents not being fired at all when "opening" a sign.

* Hanging WALL signs have a collision box for their post. Hanging signs don't, so they are treated like a normal sign would (fully passable)

* BlockPlaceListener: cleanup, don't use player#getLocation() for Scaffold; use PlayerMoveData instead

* (+ random cleanup in PassengerUtil)

Folia fix is provided by @xymb-endcrystalme
  • Loading branch information
Lysandr0 committed Jul 9, 2023
1 parent eeb55ad commit ebd5bb8
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public MCAccessBukkitModern() {

@Override
public String getMCVersion() {
return "1.13-1.19|?";
return "1.13-1.20|?";
}

@Override
Expand Down Expand Up @@ -224,6 +224,12 @@ public void setupBlockProperties(final WorldConfigProvider<?> worldConfigProvide
"sniffer_egg", "decorated_pot", "pitcher_crop", "calibrated_sculk_sensor")) {
addModel(mat, MODEL_AUTO_FETCH);
}

// Wall hanging signs have a collision box. Hanging signs don't, so they are treated as an ordinary sign.
for (Material mat : MaterialUtil.WALL_HANGING_SIGNS) {
// Only the post has an actual collision box, the rest is all hit box.
addModel(mat, MODEL_AUTO_FETCH);
}

for (Material mat : BridgeMaterial.getAllBlocks(
"stonecutter", "chain")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

public class AutoSign extends Check {

// TODO: Make these configurable. <- No.:)
/** Reference time that is needed to edit the most complicated sign :). */
private static long maxEditTime = 1500;
/** Fastest time "possible" estimate for an empty sign. */
Expand All @@ -58,39 +57,49 @@ public AutoSign() {
* @param block
* @param lines
* @param pData
* @param fakeNews This SignChangeEvent was triggered by player-editing, not by a newly placed sign.
* @return true if the player failed the check.
*/
public boolean check(final Player player, final Block block, final String[] lines, final IPlayerData pData) {
public boolean check(final Player player, final Block block, final String[] lines, final IPlayerData pData, final boolean fakeNews) {
tags.clear();
final long time = System.currentTimeMillis();
final BlockPlaceData data = pData.getGenericInstance(BlockPlaceData.class);
final BlockPlaceConfig cc = pData.getGenericInstance(BlockPlaceConfig.class);
Material mat = block.getType();
String s = mat.toString();
if (s.endsWith("_WALL_SIGN")) {
if (s.endsWith("_WALL_HANGING_SIGN")) {
s = s.replace("WALL_HANGING", "HANGING");
// A "wooden_wall_hanging_sign" block is just an "wooden_hanging_sign" as an item.
mat = Material.getMaterial(s);
}
else if (s.endsWith("_WALL_SIGN")) {
s = s.replace("_WALL_SIGN", "_SIGN");
// a "wooden_wall_sign" block is just a "wooden_sign" as an item.
mat = Material.getMaterial(s);
}
else if (s.endsWith("WALL_SIGN")) {
s = s.replace("WALL_", "");
// A "wall_sign" block is just a "sign" as an item.
mat = Material.getMaterial(s);
}
if (s.equals("SIGN_POST")) {
else if (s.equals("SIGN_POST")) {
mat = Material.getMaterial("SIGN");
}

if (pData.isDebugActive(CheckType.BLOCKPLACE_AUTOSIGN)) {
debug(player, "Block-place hash: " + BlockPlaceListener.getBlockPlaceHash(block, mat) + ", Material type: " + mat + " / " + s);
}

// Check hash match
if (data.autoSignPlacedHash != BlockPlaceListener.getBlockPlaceHash(block, mat)
// If a player triggered a sign event and the hash is 0, that means they edited an already placed sign, no need to check here.
&& data.autoSignPlacedHash != 0) {
if (data.autoSignPlacedHash != BlockPlaceListener.getBlockPlaceHash(block, mat) && !fakeNews) {
tags.add("block_mismatch");
return handleViolation(player, maxEditTime, data, cc);
}

if (time < data.autoSignPlacedTime) {
data.autoSignPlacedTime = 0;
return false;
}

// Check time, mind lag.
final long editTime = time - data.autoSignPlacedTime;
long expected = getExpectedEditTime(lines, cc.autoSignSkipEmpty);
Expand All @@ -114,7 +123,7 @@ private long getExpectedEditTime(final String[] lines, final boolean skipEmpty)
if (!line.isEmpty()){
chars.clear();
n += 1;
for (final char c : line.toCharArray()){
for (final char c : line.toCharArray()) {
chars.add(c);
}
expected += minCharTime * chars.size();
Expand All @@ -124,7 +133,7 @@ private long getExpectedEditTime(final String[] lines, final boolean skipEmpty)
if (skipEmpty && n == 0) {
return 0;
}
if (n > 1){
if (n > 1) {
expected += minLineTime * n;
}
return expected;
Expand Down
Loading

0 comments on commit ebd5bb8

Please sign in to comment.