diff --git a/src/net/deltik/mc/signedit/SignText.java b/src/net/deltik/mc/signedit/SignText.java index 661c009..11fad12 100644 --- a/src/net/deltik/mc/signedit/SignText.java +++ b/src/net/deltik/mc/signedit/SignText.java @@ -98,10 +98,14 @@ public void setTargetSign(@Nullable SignShim targetSign, @Nullable SideShim targ this.targetSignSide = targetSignSide != null ? targetSignSide : SideShim.FRONT; } - public void applySignAutoWax(Player player, ChatComms comms) { + public interface Applicator { + void applySign(Player player); + } + + public void applySignAutoWax(Player player, ChatComms comms, Applicator applicator) { Sign sign = Objects.requireNonNull(getTargetSign()); boolean needRewax = SignHelpers.bypassWaxBefore(sign, player, comms); - applySign(player); + applicator.applySign(player); if (needRewax) { SignHelpers.bypassWaxAfter(sign, player, comms); } diff --git a/src/net/deltik/mc/signedit/SignTextHistory.java b/src/net/deltik/mc/signedit/SignTextHistory.java index aa02f40..a0d48c7 100644 --- a/src/net/deltik/mc/signedit/SignTextHistory.java +++ b/src/net/deltik/mc/signedit/SignTextHistory.java @@ -49,22 +49,22 @@ public int redosRemaining() { return history.size() - tailPosition; } - public SignText undo() { + public SignText undo(ChatComms comms) { if (tailPosition <= 0) { throw new SignTextHistoryStackBoundsException("nothing_to_undo"); } SignText previousSignText = history.get(tailPosition - 1); - previousSignText.revertSign(player); + previousSignText.applySignAutoWax(player, comms, previousSignText::revertSign); tailPosition--; return previousSignText; } - public SignText redo() { + public SignText redo(ChatComms comms) { if (tailPosition == history.size()) { throw new SignTextHistoryStackBoundsException("nothing_to_redo"); } SignText nextSignText = history.get(tailPosition); - nextSignText.applySign(player); + nextSignText.applySignAutoWax(player, comms, nextSignText::applySign); tailPosition++; return nextSignText; } diff --git a/src/net/deltik/mc/signedit/interactions/BookUiSignEditInteraction.java b/src/net/deltik/mc/signedit/interactions/BookUiSignEditInteraction.java index a35bcdb..d9d7370 100644 --- a/src/net/deltik/mc/signedit/interactions/BookUiSignEditInteraction.java +++ b/src/net/deltik/mc/signedit/interactions/BookUiSignEditInteraction.java @@ -146,7 +146,7 @@ public void cleanup(Event event) { } ChatComms comms = commsBuilder.commandSender(player).build().comms(); - signText.applySignAutoWax(player, comms); + signText.applySignAutoWax(player, comms, signText::applySign); if (signText.signTextChanged()) { historyManager.getHistory(player).push(signText); } diff --git a/src/net/deltik/mc/signedit/interactions/CutSignEditInteraction.java b/src/net/deltik/mc/signedit/interactions/CutSignEditInteraction.java index a827de5..2ffec48 100644 --- a/src/net/deltik/mc/signedit/interactions/CutSignEditInteraction.java +++ b/src/net/deltik/mc/signedit/interactions/CutSignEditInteraction.java @@ -74,7 +74,7 @@ public void interact(Player player, SignShim sign, SideShim side) { ChatComms comms = commsBuilder.commandSender(player).build().comms(); - sourceSign.applySignAutoWax(player, comms); + sourceSign.applySignAutoWax(player, comms, sourceSign::applySign); if (sourceSign.signTextChanged()) { historyManager.getHistory(player).push(sourceSign); } diff --git a/src/net/deltik/mc/signedit/interactions/PasteSignEditInteraction.java b/src/net/deltik/mc/signedit/interactions/PasteSignEditInteraction.java index eb95a90..7c2289f 100644 --- a/src/net/deltik/mc/signedit/interactions/PasteSignEditInteraction.java +++ b/src/net/deltik/mc/signedit/interactions/PasteSignEditInteraction.java @@ -58,7 +58,7 @@ public void interact(Player player, SignShim sign, SideShim side) { ChatComms comms = commsBuilder.commandSender(player).build().comms(); - signText.applySignAutoWax(player, comms); + signText.applySignAutoWax(player, comms, signText::applySign); if (signText.signTextChanged()) { historyManager.getHistory(player).push(signText); } diff --git a/src/net/deltik/mc/signedit/interactions/SetSignEditInteraction.java b/src/net/deltik/mc/signedit/interactions/SetSignEditInteraction.java index 6a43667..6fb5b83 100644 --- a/src/net/deltik/mc/signedit/interactions/SetSignEditInteraction.java +++ b/src/net/deltik/mc/signedit/interactions/SetSignEditInteraction.java @@ -56,7 +56,7 @@ public void interact(Player player, SignShim sign, SideShim side) { ChatComms comms = commsBuilder.commandSender(player).build().comms(); - signText.applySignAutoWax(player, comms); + signText.applySignAutoWax(player, comms, signText::applySign); if (signText.signTextChanged()) { historyManager.getHistory(player).push(signText); } diff --git a/src/net/deltik/mc/signedit/subcommands/RedoSignSubcommand.java b/src/net/deltik/mc/signedit/subcommands/RedoSignSubcommand.java index de0daa8..79943c5 100644 --- a/src/net/deltik/mc/signedit/subcommands/RedoSignSubcommand.java +++ b/src/net/deltik/mc/signedit/subcommands/RedoSignSubcommand.java @@ -45,8 +45,8 @@ public RedoSignSubcommand( @Override public SignEditInteraction execute() { SignTextHistory history = historyManager.getHistory(player); - SignText redoneSignText = history.redo(); ChatComms comms = commsBuilder.commandSender(player).build().comms(); + SignText redoneSignText = history.redo(comms); comms.compareSignText(redoneSignText); return null; } diff --git a/src/net/deltik/mc/signedit/subcommands/UndoSignSubcommand.java b/src/net/deltik/mc/signedit/subcommands/UndoSignSubcommand.java index 984202d..f1c14f4 100644 --- a/src/net/deltik/mc/signedit/subcommands/UndoSignSubcommand.java +++ b/src/net/deltik/mc/signedit/subcommands/UndoSignSubcommand.java @@ -45,8 +45,8 @@ public UndoSignSubcommand( @Override public SignEditInteraction execute() { SignTextHistory history = historyManager.getHistory(player); - SignText undoneSignText = history.undo(); ChatComms comms = commsBuilder.commandSender(player).build().comms(); + SignText undoneSignText = history.undo(comms); comms.compareSignText(undoneSignText); return null; }