Skip to content

Commit

Permalink
/sign ui compatibility with Paper 1.17
Browse files Browse the repository at this point in the history
Now looks for the first public boolean in TileEntitySign. This should be
fine until upstream changes the public modifier of the boolean or makes
more drastic changes to how Minecraft signs are marked as editable.

Fixes: #21
  • Loading branch information
Deltik committed Jun 21, 2021
1 parent b09e9fa commit 5d6f08e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## v1.12.8 (2021-06-21)

### Fixed

* `/sign ui` compatibility with Paper 1.17 (#21)

## v1.12.7 (2021-06-13)

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def name = 'SignEdit'
version '1.12.7'
version '1.12.8'

/*
* Copyright (C) 2017-2021 Deltik <https://www.deltik.org/>
Expand Down
18 changes: 15 additions & 3 deletions src/org/deltik/mc/signedit/CraftBukkitReflector.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,28 @@ public static Method getDeclaredMethodRecursive(Class<?> whateverClass, String n
}

public static Field getFirstFieldOfType(Object source, Class<?> desiredType) throws NoSuchFieldException {
return getFirstFieldOfType(source.getClass(), desiredType);
return getFirstFieldOfType(source, desiredType, ~0x0);
}

public static Field getFirstFieldOfType(Class<?> source, Class<?> desiredType) throws NoSuchFieldException {
public static Field getFirstFieldOfType(
Object source,
Class<?> desiredType,
int modifierMask
) throws NoSuchFieldException {
return getFirstFieldOfType(source.getClass(), desiredType, modifierMask);
}

public static Field getFirstFieldOfType(
Class<?> source,
Class<?> desiredType,
int modifierMask
) throws NoSuchFieldException {
Class<?> ancestor = source;
while (ancestor != null) {
Field[] fields = ancestor.getDeclaredFields();
for (Field field : fields) {
Class<?> candidateType = field.getType();
if (desiredType.isAssignableFrom(candidateType)) {
if (desiredType.isAssignableFrom(candidateType) && (field.getModifiers() & modifierMask) > 0) {
field.setAccessible(true);
return field;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import javax.inject.Inject;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.stream.IntStream;

import static org.deltik.mc.signedit.CraftBukkitReflector.getDeclaredMethodRecursive;
Expand Down Expand Up @@ -144,10 +145,10 @@ private Object toRawTileEntity(BlockState blockState) throws Exception {
}

/**
* FIXME: Find a more reliable way than looking for the first boolean to mark the TileEntitySign as editable
* FIXME: Find a more reliable way than looking for the first public boolean to mark the TileEntitySign as editable
*/
private void makeTileEntitySignEditable(Object tileEntitySign) throws Exception {
Field signIsEditable = getFirstFieldOfType(tileEntitySign, boolean.class);
Field signIsEditable = getFirstFieldOfType(tileEntitySign, boolean.class, Modifier.PUBLIC);
signIsEditable.setAccessible(true);
signIsEditable.set(tileEntitySign, true);
}
Expand Down

0 comments on commit 5d6f08e

Please sign in to comment.