From 88c8ccd29b1d2392b1da8d81f3d7a0e8fdb87d14 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Tue, 28 Sep 2021 20:31:44 -0400 Subject: [PATCH] Add config for default shout state and for persisting shout state --- .../main/java/com/earth2me/essentials/ISettings.java | 4 ++++ .../main/java/com/earth2me/essentials/Settings.java | 10 ++++++++++ .../src/main/java/com/earth2me/essentials/User.java | 10 ++++++++-- .../main/java/com/earth2me/essentials/UserData.java | 12 ++++++++++++ .../essentials/config/holders/UserConfigHolder.java | 10 ++++++++++ Essentials/src/main/resources/config.yml | 6 ++++++ 6 files changed, 50 insertions(+), 2 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java index bbef5dc3f..4da7f5254 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java @@ -46,6 +46,10 @@ public interface ISettings extends IConf { char getChatQuestion(); + boolean isShoutDefault(); + + boolean isPersistShout(); + boolean isChatQuestionEnabled(); BigDecimal getCommandCost(IEssentialsCommand cmd); diff --git a/Essentials/src/main/java/com/earth2me/essentials/Settings.java b/Essentials/src/main/java/com/earth2me/essentials/Settings.java index 188dd2bd5..d9aae83fb 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Settings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Settings.java @@ -226,6 +226,16 @@ public class Settings implements net.ess3.api.ISettings { return chatQuestion; } + @Override + public boolean isShoutDefault() { + return config.getBoolean("chat.shout-default", false); + } + + @Override + public boolean isPersistShout() { + return config.getBoolean("chat.persist-shout", false); + } + @Override public boolean isChatQuestionEnabled() { return config.getBoolean("chat.question-enabled", true); diff --git a/Essentials/src/main/java/com/earth2me/essentials/User.java b/Essentials/src/main/java/com/earth2me/essentials/User.java index 12952aff9..d21f91ed4 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/User.java +++ b/Essentials/src/main/java/com/earth2me/essentials/User.java @@ -90,7 +90,7 @@ public class User extends UserData implements Comparable, IMessageRecipien private long lastNotifiedAboutMailsMs; private String lastHomeConfirmation; private long lastHomeConfirmationTimestamp; - private boolean toggleShout = false; + private Boolean toggleShout; private transient final List signCopy = Lists.newArrayList("", "", "", ""); public User(final Player base, final IEssentials ess) { @@ -1202,10 +1202,16 @@ public class User extends UserData implements Comparable, IMessageRecipien @Override public void setToggleShout(boolean toggleShout) { this.toggleShout = toggleShout; + if (ess.getSettings().isPersistShout()) { + setShouting(toggleShout); + } } @Override public boolean isToggleShout() { - return toggleShout; + if (ess.getSettings().isPersistShout()) { + return toggleShout = isShouting(); + } + return toggleShout == null ? toggleShout = ess.getSettings().isShoutDefault() : toggleShout; } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/UserData.java b/Essentials/src/main/java/com/earth2me/essentials/UserData.java index 313b984cc..79126b5b3 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/UserData.java +++ b/Essentials/src/main/java/com/earth2me/essentials/UserData.java @@ -722,6 +722,18 @@ public abstract class UserData extends PlayerExtension implements IConf { config.save(); } + public boolean isShouting() { + if (holder.shouting() == null) { + holder.shouting(ess.getSettings().isShoutDefault()); + } + return holder.shouting(); + } + + public void setShouting(boolean shouting) { + holder.shouting(shouting); + config.save(); + } + public UUID getConfigUUID() { return config.getUuid(); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/config/holders/UserConfigHolder.java b/Essentials/src/main/java/com/earth2me/essentials/config/holders/UserConfigHolder.java index 5f1de20c2..6a468d7a4 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/config/holders/UserConfigHolder.java +++ b/Essentials/src/main/java/com/earth2me/essentials/config/holders/UserConfigHolder.java @@ -322,6 +322,16 @@ public class UserConfigHolder { this.baltopExempt = value; } + private @MonotonicNonNull Boolean shouting; + + public Boolean shouting() { + return shouting; + } + + public void shouting(final Boolean value) { + this.shouting = value; + } + private @NonNull Timestamps timestamps = new Timestamps(); public Timestamps timestamps() { diff --git a/Essentials/src/main/resources/config.yml b/Essentials/src/main/resources/config.yml index 69090a21e..9e1b62135 100644 --- a/Essentials/src/main/resources/config.yml +++ b/Essentials/src/main/resources/config.yml @@ -921,6 +921,12 @@ chat: # plots: "&dP&r" # creative: "&eC&r" + # Whether players should be placed into shout mode by default. + shout-default: false + + # Whether a player's shout mode should persist restarts. + persist-shout: false + # Whether chat questions should be enabled or not. question-enabled: true