Fixes some bugs preventing placeholders on the back of signs from working
All checks were successful
KnarCraft/PlaceholderSigns/pipeline/head This commit looks good
All checks were successful
KnarCraft/PlaceholderSigns/pipeline/head This commit looks good
This commit is contained in:
parent
51564570ad
commit
66bb96631a
@ -154,13 +154,21 @@ public final class PlaceholderSigns extends JavaPlugin {
|
||||
}
|
||||
|
||||
// Update placeholders
|
||||
SignSide front = sign.getSide(Side.FRONT);
|
||||
SignSide back = sign.getSide(Side.BACK);
|
||||
Map<Side, Map<Integer, String>> placeholders = placeholderSign.placeholders();
|
||||
String[] frontLines = sign.getSide(Side.FRONT).getLines();
|
||||
String[] backLines = sign.getSide(Side.BACK).getLines();
|
||||
String[] frontLines = front.getLines();
|
||||
String[] backLines = back.getLines();
|
||||
|
||||
// Only update the sign if the text has changed
|
||||
if (updatePlaceholders(frontLines, placeholders.get(Side.FRONT), sign.getSide(Side.FRONT)) ||
|
||||
updatePlaceholders(backLines, placeholders.get(Side.BACK), sign.getSide(Side.BACK))) {
|
||||
boolean updateNecessary = false;
|
||||
if (placeholders.get(Side.FRONT) != null) {
|
||||
updateNecessary |= updatePlaceholders(frontLines, placeholders.get(Side.FRONT), front);
|
||||
}
|
||||
if (placeholders.get(Side.BACK) != null) {
|
||||
updateNecessary |= updatePlaceholders(backLines, placeholders.get(Side.BACK), back);
|
||||
}
|
||||
if (updateNecessary) {
|
||||
sign.update();
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,9 @@ public class SignClickListener implements Listener {
|
||||
// Check if the player has run the /editSign command
|
||||
SignLineChangeRequest request = PlaceholderSigns.getInstance().getSignChangeRequest(player);
|
||||
if (request != null) {
|
||||
doSignChange(sign, request, event, player);
|
||||
SignSide standingOn = sign.getTargetSide(player);
|
||||
Side side = sign.getSide(Side.FRONT).equals(standingOn) ? Side.FRONT : Side.BACK;
|
||||
doSignChange(sign, request, event, player, side);
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,17 +87,18 @@ public class SignClickListener implements Listener {
|
||||
* @param player <p>The player triggering the sign change</p>
|
||||
*/
|
||||
private void doSignChange(@NotNull Sign sign, @NotNull SignLineChangeRequest request,
|
||||
@NotNull PlayerInteractEvent event, @NotNull Player player) {
|
||||
@NotNull PlayerInteractEvent event, @NotNull Player player, @NotNull Side side) {
|
||||
// Cancel the event to prevent vanilla behavior
|
||||
event.setCancelled(true);
|
||||
|
||||
String[] lines = sign.getSide(Side.FRONT).getLines();
|
||||
SignSide signSide = sign.getSide(side);
|
||||
String[] lines = signSide.getLines();
|
||||
|
||||
lines[request.line()] = request.text();
|
||||
|
||||
// Run the sign change event to allow protection plugins to cancel, and allow the sign text listener to trigger
|
||||
SignChangeEvent changeEvent = new SignChangeEvent(Objects.requireNonNull(event.getClickedBlock()),
|
||||
player, lines, Side.FRONT);
|
||||
player, lines, side);
|
||||
Bukkit.getPluginManager().callEvent(changeEvent);
|
||||
if (changeEvent.isCancelled()) {
|
||||
return;
|
||||
@ -104,7 +107,7 @@ public class SignClickListener implements Listener {
|
||||
// Update the sign with the new text
|
||||
String[] finalLines = changeEvent.getLines();
|
||||
for (int i = 0; i < finalLines.length; i++) {
|
||||
sign.getSide(Side.FRONT).setLine(i, ColorHelper.translateAllColorCodes(finalLines[i]));
|
||||
signSide.setLine(i, ColorHelper.translateAllColorCodes(finalLines[i]));
|
||||
}
|
||||
sign.update();
|
||||
|
||||
|
@ -53,7 +53,7 @@ public class SignTextListener implements Listener {
|
||||
signHandler.registerSign(placeholderSign);
|
||||
} else if (!placeholders.isEmpty()) {
|
||||
// Overwrite the placeholders of the existing placeholder sign
|
||||
Map<Integer, String> existing = existingSign.placeholders().get(event.getSide());
|
||||
Map<Integer, String> existing = existingSign.placeholders().computeIfAbsent(event.getSide(), k -> new HashMap<>());
|
||||
existing.putAll(placeholders);
|
||||
signHandler.save();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user