mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-22 09:08:01 +01:00
Add /toggleshout command (#3965)
Adds a command to toggle shout mode of a user allowing them not to have to prefix all their messages with `!` if they're shouting a lot. Closes #3958.
This commit is contained in:
parent
f806409d80
commit
81571fc014
@ -212,4 +212,8 @@ public interface IUser {
|
|||||||
Map<User, BigDecimal> getConfirmingPayments();
|
Map<User, BigDecimal> getConfirmingPayments();
|
||||||
|
|
||||||
Block getTargetBlock(int maxDistance);
|
Block getTargetBlock(int maxDistance);
|
||||||
|
|
||||||
|
void setToggleShout(boolean toggleShout);
|
||||||
|
|
||||||
|
boolean isToggleShout();
|
||||||
}
|
}
|
||||||
|
@ -72,6 +72,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
|||||||
private long lastNotifiedAboutMailsMs;
|
private long lastNotifiedAboutMailsMs;
|
||||||
private String lastHomeConfirmation;
|
private String lastHomeConfirmation;
|
||||||
private long lastHomeConfirmationTimestamp;
|
private long lastHomeConfirmationTimestamp;
|
||||||
|
private boolean toggleShout = false;
|
||||||
private transient final List<String> signCopy = Lists.newArrayList("", "", "", "");
|
private transient final List<String> signCopy = Lists.newArrayList("", "", "", "");
|
||||||
|
|
||||||
public User(final Player base, final IEssentials ess) {
|
public User(final Player base, final IEssentials ess) {
|
||||||
@ -1068,4 +1069,14 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
|||||||
}
|
}
|
||||||
return block;
|
return block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setToggleShout(boolean toggleShout) {
|
||||||
|
this.toggleShout = toggleShout;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isToggleShout() {
|
||||||
|
return toggleShout;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ public class Commandfly extends EssentialsToggleCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void togglePlayer(final CommandSource sender, final User user, Boolean enabled) {
|
protected void togglePlayer(final CommandSource sender, final User user, Boolean enabled) {
|
||||||
if (enabled == null) {
|
if (enabled == null) {
|
||||||
enabled = !user.getBase().getAllowFlight();
|
enabled = !user.getBase().getAllowFlight();
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ public class Commandgod extends EssentialsToggleCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void togglePlayer(final CommandSource sender, final User user, Boolean enabled) {
|
protected void togglePlayer(final CommandSource sender, final User user, Boolean enabled) {
|
||||||
if (enabled == null) {
|
if (enabled == null) {
|
||||||
enabled = !user.isGodModeEnabled();
|
enabled = !user.isGodModeEnabled();
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ public class Commandmsgtoggle extends EssentialsToggleCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void togglePlayer(final CommandSource sender, final User user, Boolean enabled) {
|
protected void togglePlayer(final CommandSource sender, final User user, Boolean enabled) {
|
||||||
if (enabled == null) {
|
if (enabled == null) {
|
||||||
enabled = !user.isIgnoreMsg();
|
enabled = !user.isIgnoreMsg();
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ public class Commandpaytoggle extends EssentialsToggleCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void togglePlayer(final CommandSource sender, final User user, Boolean enabled) {
|
protected void togglePlayer(final CommandSource sender, final User user, Boolean enabled) {
|
||||||
if (enabled == null) {
|
if (enabled == null) {
|
||||||
enabled = !user.isAcceptingPay();
|
enabled = !user.isAcceptingPay();
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ public class Commandrtoggle extends EssentialsToggleCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void togglePlayer(final CommandSource sender, final User user, Boolean enabled) {
|
protected void togglePlayer(final CommandSource sender, final User user, Boolean enabled) {
|
||||||
if (enabled == null) {
|
if (enabled == null) {
|
||||||
enabled = !user.isLastMessageReplyRecipient();
|
enabled = !user.isLastMessageReplyRecipient();
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ public class Commandtpauto extends EssentialsToggleCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void togglePlayer(final CommandSource sender, final User user, Boolean enabled) {
|
protected void togglePlayer(final CommandSource sender, final User user, Boolean enabled) {
|
||||||
if (enabled == null) {
|
if (enabled == null) {
|
||||||
enabled = !user.isAutoTeleportEnabled();
|
enabled = !user.isAutoTeleportEnabled();
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ public class Commandtptoggle extends EssentialsToggleCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void togglePlayer(final CommandSource sender, final User user, Boolean enabled) {
|
protected void togglePlayer(final CommandSource sender, final User user, Boolean enabled) {
|
||||||
if (enabled == null) {
|
if (enabled == null) {
|
||||||
enabled = !user.isTeleportEnabled();
|
enabled = !user.isTeleportEnabled();
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ public class Commandvanish extends EssentialsToggleCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void togglePlayer(final CommandSource sender, final User user, Boolean enabled) {
|
protected void togglePlayer(final CommandSource sender, final User user, Boolean enabled) {
|
||||||
if (enabled == null) {
|
if (enabled == null) {
|
||||||
enabled = !user.isVanished();
|
enabled = !user.isVanished();
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ public abstract class EssentialsToggleCommand extends EssentialsCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Make sure when implementing this method that all 3 Boolean states are handled, 'null' should toggle the existing state.
|
// Make sure when implementing this method that all 3 Boolean states are handled, 'null' should toggle the existing state.
|
||||||
abstract void togglePlayer(CommandSource sender, User user, Boolean enabled) throws NotEnoughArgumentsException;
|
protected abstract void togglePlayer(CommandSource sender, User user, Boolean enabled) throws NotEnoughArgumentsException;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<String> getTabCompleteOptions(final Server server, final User user, final String commandLabel, final String[] args) {
|
protected List<String> getTabCompleteOptions(final Server server, final User user, final String commandLabel, final String[] args) {
|
||||||
|
@ -733,6 +733,10 @@ setwarpCommandUsage=/<command> <warp>
|
|||||||
setworthCommandDescription=Set the sell value of an item.
|
setworthCommandDescription=Set the sell value of an item.
|
||||||
setworthCommandUsage=/<command> [itemname|id] <price>
|
setworthCommandUsage=/<command> [itemname|id] <price>
|
||||||
sheepMalformedColor=\u00a74Malformed color.
|
sheepMalformedColor=\u00a74Malformed color.
|
||||||
|
shoutDisabled=\u00a76Shout mode \u00a7cdisabled\u00a76.
|
||||||
|
shoutDisabledFor=\u00a76Shout mode \u00a7cdisabled \u00a76for \u00a7c{0}\u00a76.
|
||||||
|
shoutEnabled=\u00a76Shout mode \u00a7cenabled\u00a76.
|
||||||
|
shoutEnabledFor=\u00a76Shout mode \u00a7cenabled \u00a76for \u00a7c{0}\u00a76.
|
||||||
shoutFormat=\u00a76[Shout]\u00a7r {0}
|
shoutFormat=\u00a76[Shout]\u00a7r {0}
|
||||||
editsignCommandClear=\u00a76Sign cleared.
|
editsignCommandClear=\u00a76Sign cleared.
|
||||||
editsignCommandClearLine=\u00a76Cleared line\u00a7c {0}\u00a76.
|
editsignCommandClearLine=\u00a76Cleared line\u00a7c {0}\u00a76.
|
||||||
@ -839,6 +843,8 @@ timeWorldCurrent=\u00a76The current time in\u00a7c {0} \u00a76is \u00a7c{1}\u00a
|
|||||||
timeWorldSet=\u00a76The time was set to\u00a7c {0} \u00a76in\: \u00a7c{1}\u00a76.
|
timeWorldSet=\u00a76The time was set to\u00a7c {0} \u00a76in\: \u00a7c{1}\u00a76.
|
||||||
togglejailCommandDescription=Jails/Unjails a player, TPs them to the jail specified.
|
togglejailCommandDescription=Jails/Unjails a player, TPs them to the jail specified.
|
||||||
togglejailCommandUsage=/<command> <player> <jailname> [datediff]
|
togglejailCommandUsage=/<command> <player> <jailname> [datediff]
|
||||||
|
toggleshoutCommandDescription=Toggles whether you are talking in shout mode
|
||||||
|
toggleshoutCommandUsage=/<command> [player] [on|off]
|
||||||
topCommandDescription=Teleport to the highest block at your current position.
|
topCommandDescription=Teleport to the highest block at your current position.
|
||||||
topCommandUsage=/<command>
|
topCommandUsage=/<command>
|
||||||
totalSellableAll=\u00a7aThe total worth of all sellable items and blocks is \u00a7c{1}\u00a7a.
|
totalSellableAll=\u00a7aThe total worth of all sellable items and blocks is \u00a7c{1}\u00a7a.
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
package com.earth2me.essentials.chat;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.CommandSource;
|
||||||
|
import com.earth2me.essentials.User;
|
||||||
|
import com.earth2me.essentials.commands.EssentialsToggleCommand;
|
||||||
|
import org.bukkit.Server;
|
||||||
|
|
||||||
|
import static com.earth2me.essentials.I18n.tl;
|
||||||
|
|
||||||
|
public class Commandtoggleshout extends EssentialsToggleCommand {
|
||||||
|
public Commandtoggleshout() {
|
||||||
|
super("toggleshout", "essentials.toggleshout.others");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
|
||||||
|
toggleOtherPlayers(server, sender, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||||
|
handleToggleWithArgs(server, user, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void togglePlayer(final CommandSource sender, final User user, Boolean enabled) {
|
||||||
|
if (enabled == null) {
|
||||||
|
enabled = !user.isToggleShout();
|
||||||
|
}
|
||||||
|
|
||||||
|
user.setToggleShout(enabled);
|
||||||
|
|
||||||
|
user.sendMessage(enabled ? tl("shoutEnabled") : tl("shoutDisabled"));
|
||||||
|
if (!sender.isPlayer() || !user.getBase().equals(sender.getPlayer())) {
|
||||||
|
sender.sendMessage(enabled ? tl("shoutEnabledFor", user.getDisplayName()) : tl("shoutDisabledFor", user.getDisplayName()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,8 @@ package com.earth2me.essentials.chat;
|
|||||||
|
|
||||||
import com.earth2me.essentials.metrics.MetricsWrapper;
|
import com.earth2me.essentials.metrics.MetricsWrapper;
|
||||||
import net.ess3.api.IEssentials;
|
import net.ess3.api.IEssentials;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@ -14,13 +16,13 @@ import java.util.logging.Level;
|
|||||||
import static com.earth2me.essentials.I18n.tl;
|
import static com.earth2me.essentials.I18n.tl;
|
||||||
|
|
||||||
public class EssentialsChat extends JavaPlugin {
|
public class EssentialsChat extends JavaPlugin {
|
||||||
|
private transient IEssentials ess;
|
||||||
private transient MetricsWrapper metrics = null;
|
private transient MetricsWrapper metrics = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
final PluginManager pluginManager = getServer().getPluginManager();
|
final PluginManager pluginManager = getServer().getPluginManager();
|
||||||
final IEssentials ess = (IEssentials) pluginManager.getPlugin("Essentials");
|
ess = (IEssentials) pluginManager.getPlugin("Essentials");
|
||||||
if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) {
|
if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) {
|
||||||
getLogger().log(Level.WARNING, tl("versionMismatchAll"));
|
getLogger().log(Level.WARNING, tl("versionMismatchAll"));
|
||||||
}
|
}
|
||||||
@ -43,4 +45,9 @@ public class EssentialsChat extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(final CommandSender sender, final Command command, final String commandLabel, final String[] args) {
|
||||||
|
metrics.markCommand(command.getName(), true);
|
||||||
|
return ess.onCommandEssentials(sender, command, commandLabel, args, EssentialsChat.class.getClassLoader(), "com.earth2me.essentials.chat.Command", "essentials.", null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,14 +29,14 @@ public abstract class EssentialsChatPlayer implements Listener {
|
|||||||
return event.isCancelled();
|
return event.isCancelled();
|
||||||
}
|
}
|
||||||
|
|
||||||
String getChatType(final String message) {
|
String getChatType(final User user, final String message) {
|
||||||
if (message.length() == 0) {
|
if (message.length() == 0) {
|
||||||
//Ignore empty chat events generated by plugins
|
//Ignore empty chat events generated by plugins
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
final char prefix = message.charAt(0);
|
final char prefix = message.charAt(0);
|
||||||
if (prefix == ess.getSettings().getChatShout()) {
|
if (prefix == ess.getSettings().getChatShout() || user.isToggleShout()) {
|
||||||
return message.length() > 1 ? "shout" : "";
|
return message.length() > 1 ? "shout" : "";
|
||||||
} else if (prefix == ess.getSettings().getChatQuestion()) {
|
} else if (prefix == ess.getSettings().getChatQuestion()) {
|
||||||
return message.length() > 1 ? "question" : "";
|
return message.length() > 1 ? "question" : "";
|
||||||
|
@ -33,7 +33,7 @@ public class EssentialsChatPlayerListenerLowest extends EssentialsChatPlayer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final ChatStore chatStore = new ChatStore(ess, user, getChatType(event.getMessage()));
|
final ChatStore chatStore = new ChatStore(ess, user, getChatType(user, event.getMessage()));
|
||||||
setChatStore(event, chatStore);
|
setChatStore(event, chatStore);
|
||||||
|
|
||||||
// This listener should apply the general chat formatting only...then return control back the event handler
|
// This listener should apply the general chat formatting only...then return control back the event handler
|
||||||
|
@ -48,7 +48,9 @@ public class EssentialsChatPlayerListenerNormal extends EssentialsChatPlayer {
|
|||||||
permission.append("essentials.chat.").append(chatStore.getType());
|
permission.append("essentials.chat.").append(chatStore.getType());
|
||||||
|
|
||||||
if (user.isAuthorized(permission.toString())) {
|
if (user.isAuthorized(permission.toString())) {
|
||||||
event.setMessage(event.getMessage().substring(1));
|
if (event.getMessage().charAt(0) == ess.getSettings().getChatShout() || event.getMessage().charAt(0) == ess.getSettings().getChatQuestion()) {
|
||||||
|
event.setMessage(event.getMessage().substring(1));
|
||||||
|
}
|
||||||
event.setFormat(tl(chatStore.getType() + "Format", event.getFormat()));
|
event.setFormat(tl(chatStore.getType() + "Format", event.getFormat()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -8,3 +8,8 @@ description: Provides chat control features for Essentials. Requires Permission
|
|||||||
authors: [Zenexer, ementalo, Aelux, Brettflan, KimKandor, snowleo, ceulemans, Xeology, KHobbits, md_5, Okamosy, Iaccidentally]
|
authors: [Zenexer, ementalo, Aelux, Brettflan, KimKandor, snowleo, ceulemans, Xeology, KHobbits, md_5, Okamosy, Iaccidentally]
|
||||||
depend: [Essentials]
|
depend: [Essentials]
|
||||||
api-version: 1.13
|
api-version: 1.13
|
||||||
|
commands:
|
||||||
|
toggleshout:
|
||||||
|
description: Toggles whether you are talking in shout mode
|
||||||
|
usage: /<command> [player] [on|off]
|
||||||
|
aliases: [etoggleshout]
|
||||||
|
Loading…
Reference in New Issue
Block a user