Skip to content

Commit

Permalink
Add re-wax wrapper to /sign undo and /sign redo
Browse files Browse the repository at this point in the history
  • Loading branch information
Deltik committed Jul 13, 2023
1 parent a1566a8 commit ac57178
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 12 deletions.
8 changes: 6 additions & 2 deletions src/net/deltik/mc/signedit/SignText.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 4 additions & 4 deletions src/net/deltik/mc/signedit/SignTextHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit ac57178

Please sign in to comment.