mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-22 17:18:37 +01:00
Add /editsign copy + paste (#3989)
Adds `copy` and `paste` subcommands to `/editsign` to allow users to copy and paste the contents of signs without having to use the tab-completion output of `/editsign set`. The `/editsign copy` command will also perform format-permission checks to ensure the user copying the sign has the proper permission to use said formatting. Closes #3973.
This commit is contained in:
parent
158d273dbe
commit
8cbd9b7935
@ -10,6 +10,7 @@ import com.earth2me.essentials.utils.EnumUtil;
|
||||
import com.earth2me.essentials.utils.FormatUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.MaxMoneyException;
|
||||
import net.ess3.api.events.AfkStatusChangeEvent;
|
||||
@ -71,6 +72,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
private long lastNotifiedAboutMailsMs;
|
||||
private String lastHomeConfirmation;
|
||||
private long lastHomeConfirmationTimestamp;
|
||||
private transient final List<String> signCopy = Lists.newArrayList("", "", "", "");
|
||||
|
||||
public User(final Player base, final IEssentials ess) {
|
||||
super(base, ess);
|
||||
@ -1045,6 +1047,10 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
this.lastHomeConfirmationTimestamp = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public List<String> getSignCopy() {
|
||||
return signCopy;
|
||||
}
|
||||
|
||||
public boolean isBaltopExempt() {
|
||||
if (getBase().isOnline()) {
|
||||
final boolean exempt = isAuthorized("essentials.balancetop.exclude");
|
||||
|
@ -53,18 +53,47 @@ public class Commandeditsign extends EssentialsCommand {
|
||||
sign.update();
|
||||
user.sendMessage(tl("editsignCommandClearLine", line + 1));
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("copy") || args[0].equalsIgnoreCase("paste")) {
|
||||
final boolean copy = args[0].equalsIgnoreCase("copy");
|
||||
final String tlPrefix = copy ? "editsignCopy" : "editsignPaste";
|
||||
final int line = args.length == 1 ? -1 : Integer.parseInt(args[1]) - 1;
|
||||
|
||||
if (line == -1) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
processSignCopyPaste(user, sign, i, copy);
|
||||
}
|
||||
user.sendMessage(tl(tlPrefix, commandLabel));
|
||||
} else {
|
||||
processSignCopyPaste(user, sign, line, copy);
|
||||
user.sendMessage(tl(tlPrefix + "Line", line + 1, commandLabel));
|
||||
}
|
||||
|
||||
if (!copy) {
|
||||
sign.update();
|
||||
}
|
||||
} else {
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
} catch (final IndexOutOfBoundsException e) {
|
||||
throw new Exception(tl("editsignCommandNoLine"));
|
||||
throw new Exception(tl("editsignCommandNoLine"), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void processSignCopyPaste(final User user, final Sign sign, final int index, final boolean copy) {
|
||||
if (copy) {
|
||||
// We use unformat here to prevent players from copying signs with colors that they do not have permission to use.
|
||||
user.getSignCopy().set(index, FormatUtil.unformatString(user, "essentials.editsign", sign.getLine(index)));
|
||||
return;
|
||||
}
|
||||
|
||||
final String line = FormatUtil.formatString(user, "essentials.editsign", user.getSignCopy().get(index));
|
||||
sign.setLine(index, line == null ? "" : line);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getTabCompleteOptions(final Server server, final User user, final String commandLabel, final String[] args) {
|
||||
if (args.length == 1) {
|
||||
return Lists.newArrayList("set", "clear");
|
||||
return Lists.newArrayList("set", "clear", "copy", "paste");
|
||||
} else if (args.length == 2) {
|
||||
return Lists.newArrayList("1", "2", "3", "4");
|
||||
} else if (args.length == 3 && args[0].equalsIgnoreCase("set") && NumberUtil.isPositiveInt(args[1])) {
|
||||
|
@ -742,7 +742,11 @@ editsignCommandLimit=\u00a74Your provided text is too big to fit on the target s
|
||||
editsignCommandNoLine=\u00a74You must enter a line number between \u00a7c1-4\u00a74.
|
||||
editsignCommandSetSuccess=\u00a76Set line\u00a7c {0}\u00a76 to "\u00a7c{1}\u00a76".
|
||||
editsignCommandTarget=\u00a74You must be looking at a sign to edit its text.
|
||||
editsignCommandUsage=/<command> <set/clear> [line number] [text]
|
||||
editsignCopy=\u00a76Sign copied! Paste it with \u00a7c/{0} paste\u00a76.
|
||||
editsignCopyLine=\u00a76Copied line \u00a7c{0} \u00a76of sign! Paste it with \u00a7c/{1} paste {0}\u00a76.
|
||||
editsignPaste=\u00a76Sign pasted!
|
||||
editsignPasteLine=\u00a76Pasted line \u00a7c{0} \u00a76of sign!
|
||||
editsignCommandUsage=/<command> <set/clear/copy/paste> [line number] [text]
|
||||
showkitCommandUsage=/<command> <kitname>
|
||||
signFormatFail=\u00a74[{0}]
|
||||
signFormatSuccess=\u00a71[{0}]
|
||||
|
@ -426,7 +426,7 @@ commands:
|
||||
aliases: [kitpreview,preview,kitshow]
|
||||
editsign:
|
||||
description: Edits a sign in the world.
|
||||
usage: /<command> <set/clear> <line number> [text]
|
||||
usage: /<command> <set/clear/copy/paste> [line number] [text]
|
||||
aliases: [sign, esign, eeditsign]
|
||||
skull:
|
||||
description: Set the owner of a player skull
|
||||
|
Loading…
Reference in New Issue
Block a user