diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index de6ccccf..5571f7b5 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -4,7 +4,7 @@ paper = "1.19-R0.1-SNAPSHOT" # Plugins worldedit = "7.2.12" -protocollib = "4.8.0" +protocollib = "5.0.0-SNAPSHOT" # Third party bstats = "3.0.0" diff --git a/src/main/java/com/plotsquared/plothider/PacketHandler.java b/src/main/java/com/plotsquared/plothider/PacketHandler.java index 46474950..1505db73 100644 --- a/src/main/java/com/plotsquared/plothider/PacketHandler.java +++ b/src/main/java/com/plotsquared/plothider/PacketHandler.java @@ -380,7 +380,7 @@ private static BitSet intToBitSet(int n) { } /** - * Worldaround method to dynamically inject fields into a custom non-implemented structure modifier. + * Workaround method to dynamically inject fields into a custom non-implemented structure modifier. * * @param structureModifier the custom structureModifier where to inject the fields * @param type the structure modifier hold class type @@ -389,10 +389,25 @@ private static void loadInternalFields(StructureModifier structureModifier, C List fields = getFields(type); try { - Field data = StructureModifier.class.getDeclaredField("data"); - data.setAccessible(true); - data.set(structureModifier, fields); - } catch (NoSuchFieldException | IllegalAccessException e) { + // New v5 management, "data" field has been removed since c5f05509531eb22e9a0580f07bc0bf17a901b729. + List fieldAccessors = new ArrayList<>(fields.size()); + for (Field field : fields) { + fieldAccessors.add(com.comphenix.protocol.reflect.accessors.Accessors.getFieldAccessor(field)); + } + + Field accessors = StructureModifier.class.getDeclaredField("accessors"); + accessors.setAccessible(true); + accessors.set(structureModifier, fieldAccessors); + } catch (NoSuchFieldException e) { + // Former v5 management. + try { + Field data = StructureModifier.class.getDeclaredField("data"); + data.setAccessible(true); + data.set(structureModifier, fields); + } catch (NoSuchFieldException | IllegalAccessException ex) { + throw new RuntimeException(ex); + } + } catch (IllegalAccessException e) { throw new RuntimeException(e); } }