forked from LogBlock/LogBlock
MC Version 1.20.1, use waxed sign api (#884)
* bump api version to 1.20.1 * Sign.isWaxed is now API
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -44,7 +44,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
<version>1.20-R0.1-SNAPSHOT</version>
|
<version>1.20.1-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
package de.diddiz.LogBlock.blockstate;
|
package de.diddiz.LogBlock.blockstate;
|
||||||
|
|
||||||
import de.diddiz.LogBlock.util.BukkitUtils;
|
import de.diddiz.LogBlock.util.BukkitUtils;
|
||||||
import de.diddiz.LogBlock.util.Reflections;
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -28,7 +27,7 @@ public class BlockStateCodecSign implements BlockStateCodec {
|
|||||||
public YamlConfiguration serialize(BlockState state) {
|
public YamlConfiguration serialize(BlockState state) {
|
||||||
YamlConfiguration conf = null;
|
YamlConfiguration conf = null;
|
||||||
if (state instanceof Sign sign) {
|
if (state instanceof Sign sign) {
|
||||||
boolean waxed = Reflections.isSignWaxed(sign);
|
boolean waxed = sign.isWaxed();
|
||||||
if (waxed) {
|
if (waxed) {
|
||||||
conf = new YamlConfiguration();
|
conf = new YamlConfiguration();
|
||||||
conf.set("waxed", waxed);
|
conf.set("waxed", waxed);
|
||||||
@@ -92,7 +91,7 @@ public class BlockStateCodecSign implements BlockStateCodec {
|
|||||||
if (state instanceof Sign) {
|
if (state instanceof Sign) {
|
||||||
Sign sign = (Sign) state;
|
Sign sign = (Sign) state;
|
||||||
if (conf != null) {
|
if (conf != null) {
|
||||||
sign.setEditable(!conf.getBoolean("waxed"));
|
sign.setWaxed(conf.getBoolean("waxed"));
|
||||||
for (Side side : Side.values()) {
|
for (Side side : Side.values()) {
|
||||||
ConfigurationSection sideSection = side == Side.FRONT ? conf : conf.getConfigurationSection(side.name().toLowerCase());
|
ConfigurationSection sideSection = side == Side.FRONT ? conf : conf.getConfigurationSection(side.name().toLowerCase());
|
||||||
DyeColor signColor = DyeColor.BLACK;
|
DyeColor signColor = DyeColor.BLACK;
|
||||||
@@ -120,7 +119,7 @@ public class BlockStateCodecSign implements BlockStateCodec {
|
|||||||
signSide.setGlowingText(glowing);
|
signSide.setGlowingText(glowing);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sign.setEditable(true);
|
sign.setWaxed(false);
|
||||||
for (Side side : Side.values()) {
|
for (Side side : Side.values()) {
|
||||||
SignSide signSide = sign.getSide(side);
|
SignSide signSide = sign.getSide(side);
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
|
@@ -5,7 +5,6 @@ import de.diddiz.LogBlock.LogBlock;
|
|||||||
import de.diddiz.LogBlock.Logging;
|
import de.diddiz.LogBlock.Logging;
|
||||||
import de.diddiz.LogBlock.config.WorldConfig;
|
import de.diddiz.LogBlock.config.WorldConfig;
|
||||||
import de.diddiz.LogBlock.util.BukkitUtils;
|
import de.diddiz.LogBlock.util.BukkitUtils;
|
||||||
import de.diddiz.LogBlock.util.Reflections;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import org.bukkit.DyeColor;
|
import org.bukkit.DyeColor;
|
||||||
import org.bukkit.GameEvent;
|
import org.bukkit.GameEvent;
|
||||||
@@ -99,8 +98,7 @@ public class InteractLogging extends LoggingListener {
|
|||||||
if (BukkitUtils.isDye(itemType) || itemType == Material.GLOW_INK_SAC || itemType == Material.INK_SAC || itemType == Material.HONEYCOMB) {
|
if (BukkitUtils.isDye(itemType) || itemType == Material.GLOW_INK_SAC || itemType == Material.INK_SAC || itemType == Material.HONEYCOMB) {
|
||||||
final BlockState before = event.getClickedBlock().getState();
|
final BlockState before = event.getClickedBlock().getState();
|
||||||
if (before instanceof Sign signBefore) {
|
if (before instanceof Sign signBefore) {
|
||||||
boolean waxed = Reflections.isSignWaxed(signBefore);
|
if (!signBefore.isWaxed()) {
|
||||||
if (!waxed) {
|
|
||||||
final Sign signAfter = (Sign) event.getClickedBlock().getState();
|
final Sign signAfter = (Sign) event.getClickedBlock().getState();
|
||||||
Side side = BukkitUtils.getFacingSignSide(player, clicked);
|
Side side = BukkitUtils.getFacingSignSide(player, clicked);
|
||||||
SignSide signSideBefore = signBefore.getSide(side);
|
SignSide signSideBefore = signBefore.getSide(side);
|
||||||
@@ -116,7 +114,7 @@ public class InteractLogging extends LoggingListener {
|
|||||||
consumer.queueBlockReplace(Actor.actorFromEntity(player), signBefore, signAfter);
|
consumer.queueBlockReplace(Actor.actorFromEntity(player), signBefore, signAfter);
|
||||||
}
|
}
|
||||||
} else if (itemType == Material.HONEYCOMB) {
|
} else if (itemType == Material.HONEYCOMB) {
|
||||||
signAfter.setEditable(false);
|
signAfter.setWaxed(true);
|
||||||
consumer.queueBlockReplace(Actor.actorFromEntity(player), signBefore, signAfter);
|
consumer.queueBlockReplace(Actor.actorFromEntity(player), signBefore, signAfter);
|
||||||
} else if (BukkitUtils.isDye(itemType) && hasText(signSideBefore)) {
|
} else if (BukkitUtils.isDye(itemType) && hasText(signSideBefore)) {
|
||||||
DyeColor newColor = BukkitUtils.dyeToDyeColor(itemType);
|
DyeColor newColor = BukkitUtils.dyeToDyeColor(itemType);
|
||||||
|
@@ -1,61 +0,0 @@
|
|||||||
package de.diddiz.LogBlock.util;
|
|
||||||
|
|
||||||
import de.diddiz.LogBlock.LogBlock;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import org.bukkit.block.Sign;
|
|
||||||
|
|
||||||
public class Reflections {
|
|
||||||
private static Field FIELD_CraftBlockEntityState_snapshot;
|
|
||||||
private static Field FIELD_SignBlockEntity_isWaxed;
|
|
||||||
|
|
||||||
public static boolean isSignWaxed(Sign sign) {
|
|
||||||
try {
|
|
||||||
if (FIELD_CraftBlockEntityState_snapshot == null) {
|
|
||||||
Class<?> superClass = sign.getClass().getSuperclass();
|
|
||||||
while (superClass != null) {
|
|
||||||
try {
|
|
||||||
FIELD_CraftBlockEntityState_snapshot = superClass.getDeclaredField("snapshot");
|
|
||||||
FIELD_CraftBlockEntityState_snapshot.setAccessible(true);
|
|
||||||
break;
|
|
||||||
} catch (NoSuchFieldException ignored) {
|
|
||||||
}
|
|
||||||
superClass = superClass.getSuperclass();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (FIELD_CraftBlockEntityState_snapshot == null) {
|
|
||||||
LogBlock.getInstance().getLogger().log(Level.SEVERE, "Reflections: Sign field 'snapshot' not found");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Object snapshot = FIELD_CraftBlockEntityState_snapshot.get(sign);
|
|
||||||
if (snapshot == null) {
|
|
||||||
LogBlock.getInstance().getLogger().log(Level.SEVERE, "Reflections: Sign snapshot is null?");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (FIELD_SignBlockEntity_isWaxed == null) {
|
|
||||||
Class<?> snapshotClass = snapshot.getClass();
|
|
||||||
while (snapshotClass != null) {
|
|
||||||
for (Field f : snapshotClass.getDeclaredFields()) {
|
|
||||||
if (f.getType() == boolean.class) {
|
|
||||||
FIELD_SignBlockEntity_isWaxed = f;
|
|
||||||
FIELD_SignBlockEntity_isWaxed.setAccessible(true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (FIELD_SignBlockEntity_isWaxed != null) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
snapshotClass = snapshotClass.getSuperclass();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (FIELD_SignBlockEntity_isWaxed == null) {
|
|
||||||
LogBlock.getInstance().getLogger().log(Level.SEVERE, "Reflections: Sign field 'isWaxed' not found");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return FIELD_SignBlockEntity_isWaxed.getBoolean(snapshot);
|
|
||||||
} catch (SecurityException | IllegalArgumentException | IllegalAccessException e) {
|
|
||||||
LogBlock.getInstance().getLogger().log(Level.SEVERE, "Reflections: Sign.isWaxed reflection failed", e);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user