Add command to toggle reply player functionality

This commit is contained in:
AgentTroll 2019-03-09 15:39:45 -08:00
parent 25ddaef423
commit f68fb52af1
7 changed files with 77 additions and 7 deletions

View File

@ -184,5 +184,9 @@ public interface IUser {
void setPromptingClearConfirm(boolean prompt);
boolean isLastMessageReplyRecipient();
void setLastMessageReplyRecipient(boolean enabled);
Map<User, BigDecimal> getConfirmingPayments();
}

View File

@ -93,6 +93,7 @@ public abstract class UserData extends PlayerExtension implements IConf {
acceptingPay = _getAcceptingPay();
confirmPay = _getConfirmPay();
confirmClear = _getConfirmClear();
lastMessageReplyRecipient = _getLastMessageReplyRecipient();
}
private BigDecimal money;
@ -957,6 +958,22 @@ public abstract class UserData extends PlayerExtension implements IConf {
save();
}
private boolean lastMessageReplyRecipient;
private boolean _getLastMessageReplyRecipient() {
return config.getBoolean("last-message-reply-recipient", ess.getSettings().isLastMessageReplyRecipient());
}
public boolean isLastMessageReplyRecipient() {
return this.lastMessageReplyRecipient;
}
public void setLastMessageReplyRecipient(boolean enabled) {
this.lastMessageReplyRecipient = enabled;
config.setProperty("last-message-reply-recipient", enabled);
save();
}
public UUID getConfigUUID() {
return config.uuid;
}

View File

@ -0,0 +1,37 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import org.bukkit.Server;
import static com.earth2me.essentials.I18n.tl;
public class Commandrtoggle extends EssentialsToggleCommand {
public Commandrtoggle() {
super("rtoggle", "essentials.rtoggle.others");
}
@Override
public void run(Server server, User user, String commandLabel, String[] args) throws Exception {
handleToggleWithArgs(server, user, args);
}
@Override
public void run(Server server, CommandSource sender, String commandLabel, String[] args) throws Exception {
toggleOtherPlayers(server, sender, args);
}
@Override
void togglePlayer(CommandSource sender, User user, Boolean enabled) throws NotEnoughArgumentsException {
if (enabled == null) {
enabled = !user.isLastMessageReplyRecipient();
}
user.setLastMessageReplyRecipient(enabled);
user.sendMessage(!enabled ? tl("replyLastRecipientDisabled") : tl("replyLastRecipientEnabled"));
if (!sender.isPlayer() || !user.getBase().equals(sender.getPlayer())) {
sender.sendMessage(!enabled ? tl("replyLastRecipientDisabledFor", user.getDisplayName()) : tl("replyLastRecipientEnabledFor", user.getDisplayName()));
}
}
}

View File

@ -1,13 +1,13 @@
package com.earth2me.essentials.messaging;
import static com.earth2me.essentials.I18n.tl;
import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.IUser;
import com.earth2me.essentials.User;
import java.lang.ref.WeakReference;
import static com.earth2me.essentials.I18n.tl;
/**
* Represents a simple reusable implementation of {@link IMessageRecipient}. This class provides functionality for the following methods:
* <ul>
@ -119,11 +119,13 @@ public class SimpleMessageRecipient implements IMessageRecipient {
User user = getUser(this);
boolean afk = false;
boolean isLastMessageReplyRecipient = ess.getSettings().isLastMessageReplyRecipient();
if (user != null) {
if (user.isIgnoreMsg() && sender instanceof IUser && !((IUser) sender).isAuthorized("essentials.msgtoggle.bypass")) { // Don't ignore console and senders with permission
return MessageResponse.MESSAGES_IGNORED;
if (user.isIgnoreMsg() && sender instanceof IUser && !((IUser) sender).isAuthorized("essentials.msgtoggle.bypass")) { // Don't ignore console and senders with permission
return MessageResponse.MESSAGES_IGNORED;
}
afk = user.isAfk();
isLastMessageReplyRecipient = user.isLastMessageReplyRecipient();
// Check whether this recipient ignores the sender, only if the sender is not the console.
if (sender instanceof IUser && user.isIgnoredPlayer((IUser) sender)) {
return MessageResponse.SENDER_IGNORED;
@ -132,7 +134,7 @@ public class SimpleMessageRecipient implements IMessageRecipient {
// Display the formatted message to this recipient.
sendMessage(tl("msgFormat", sender.getDisplayName(), tl("me"), message));
if (ess.getSettings().isLastMessageReplyRecipient()) {
if (isLastMessageReplyRecipient) {
// If this recipient doesn't have a reply recipient, initiate by setting the first
// message sender to this recipient's replyRecipient.
long timeout = ess.getSettings().getLastMessageReplyRecipientTimeout() * 1000;

View File

@ -480,11 +480,13 @@ mails-per-minute: 1000
# Set to -1 to disable, and essentials.tempban.unlimited can be used to override.
max-tempban-time: -1
# Changes /reply functionality. If true, /r goes to the person you messaged last, otherwise the first person that messaged you.
# Changes the default /reply functionality.
# If true, /r goes to the person you messaged last, otherwise the first person that messaged you.
# If false, /r goes to the last person that messaged you.
last-message-reply-recipient: true
# If last-message-reply-recipient is true, this specifies the duration, in seconds, that would need to elapse for the
# If last-message-reply-recipient is enabled for a particular player,
# this specifies the duration, in seconds, that would need to elapse for the
# reply-recipient to update when receiving a message.
# Default is 180 (3 minutes)
last-message-reply-recipient-timeout: 180

View File

@ -447,6 +447,10 @@ repairAlreadyFixed=\u00a74This item does not need repairing.
repairEnchanted=\u00a74You are not allowed to repair enchanted items.
repairInvalidType=\u00a74This item cannot be repaired.
repairNone=\u00a74There were no items that needed repairing.
replyLastRecipientDisabled=\u00a76Replying to last message recipient \u00a7cdisabled\u00a76.
replyLastRecipientDisabledFor=\u00a76Replying to last message recipient \u00a7cdisabled \u00a76for \u00a7c{0}\u00a76.
replyLastRecipientEnabled=\u00a76Replying to last message recipient \u00a7cenabled\u00a76.
replyLastRecipientEnabledFor=\u00a76Replying to last message recipient \u00a7cenabled \u00a76for \u00a7c{0}\u00a76.
requestAccepted=\u00a76Teleport request accepted.
requestAcceptedFrom=\u00a7c{0} \u00a76accepted your teleport request.
requestDenied=\u00a76Teleport request denied.

View File

@ -324,6 +324,10 @@ commands:
description: Quickly reply to the last player to message you.
usage: /<command> <message>
aliases: [er,reply,ereply]
rtoggle:
description: Change whether the recipient of the reply is last recipient or last sender
usage: /<command> [player] [on|off]
aliases: [ertoggle, replytoggle, ereplytoggle]
realname:
description: Displays the username of a user based on nick.
usage: /<command> <nickname>