Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public interface ISettings extends IConf {

char getChatQuestion();

boolean isShoutDefault();

boolean isPersistShout();

boolean isChatQuestionEnabled();

BigDecimal getCommandCost(IEssentialsCommand cmd);

BigDecimal getCommandCost(String label);
Expand Down
15 changes: 15 additions & 0 deletions Essentials/src/main/java/com/earth2me/essentials/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,21 @@ public char getChatQuestion() {
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);
}

public boolean _isTeleportSafetyEnabled() {
return config.getBoolean("teleport-safety", true);
}
Expand Down
10 changes: 8 additions & 2 deletions Essentials/src/main/java/com/earth2me/essentials/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
private long lastNotifiedAboutMailsMs;
private String lastHomeConfirmation;
private long lastHomeConfirmationTimestamp;
private boolean toggleShout = false;
private Boolean toggleShout;
private transient final List<String> signCopy = Lists.newArrayList("", "", "", "");

public User(final Player base, final IEssentials ess) {
Expand Down Expand Up @@ -1202,10 +1202,16 @@ public Block getTargetBlock(int maxDistance) {
@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;
}
}
12 changes: 12 additions & 0 deletions Essentials/src/main/java/com/earth2me/essentials/UserData.java
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,18 @@ public void setBaltopExemptCache(boolean baltopExempt) {
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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,16 @@ public void baltopExempt(final boolean value) {
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() {
Expand Down
9 changes: 9 additions & 0 deletions Essentials/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,15 @@ 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

############################################################
# +------------------------------------------------------+ #
# | EssentialsX Protect | #
Expand Down
9 changes: 5 additions & 4 deletions Essentials/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ cantReadGeoIpDB=Failed to read GeoIP database\!
cantSpawnItem=\u00a74You are not allowed to spawn the item\u00a7c {0}\u00a74.
cartographytableCommandDescription=Opens up a cartography table.
cartographytableCommandUsage=/<command>
chatTypeLocal=[L]
chatTypeLocal=\u00a73[L]
chatTypeSpy=[Spy]
cleaned=Userfiles Cleaned.
cleaning=Cleaning userfiles.
Expand Down Expand Up @@ -669,7 +669,7 @@ listGroupTag=\u00a76{0}\u00a7r\:
listHiddenTag=\u00a77[HIDDEN]\u00a7r
listRealName=({0})
loadWarpError=\u00a74Failed to load warp {0}.
localFormat=[L]<{0}> {1}
localFormat=\u00a73[L] \u00a7r<{0}> {1}
localNoOne=
loomCommandDescription=Opens up a loom.
loomCommandUsage=/<command>
Expand Down Expand Up @@ -833,8 +833,9 @@ noPlacePermission=\u00a74You do not have permission to place a block near that s
noPotionEffectPerm=\u00a74You do not have permission to apply potion effect \u00a7c{0} \u00a74to this potion.
noPowerTools=\u00a76You have no power tools assigned.
notAcceptingPay=\u00a74{0} \u00a74is not accepting payment.
notAllowedToQuestion=\u00a74You are not authorized to use question.
notAllowedToShout=\u00a74You are not authorized to shout.
notAllowedToLocal=\u00a74You don't have permission to speak in local chat.
notAllowedToQuestion=\u00a74You don't have permission to use question.
notAllowedToShout=\u00a74You don't have permission to shout.
notEnoughExperience=\u00a74You do not have enough experience.
notEnoughMoney=\u00a74You do not have sufficient funds.
notFlying=not flying
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,15 @@ String getChatType(final User user, final String message) {
}

final char prefix = message.charAt(0);
if (prefix == ess.getSettings().getChatShout() || user.isToggleShout()) {
if (prefix == ess.getSettings().getChatShout()) {
if (user.isToggleShout()) {
return "";
}
return message.length() > 1 ? "shout" : "";
} else if (prefix == ess.getSettings().getChatQuestion()) {
} else if (ess.getSettings().isChatQuestionEnabled() && prefix == ess.getSettings().getChatQuestion()) {
return message.length() > 1 ? "question" : "";
} else if (user.isToggleShout()) {
return message.length() > 1 ? "shout" : "";
} else {
return "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,35 @@ public void onPlayerChat(final AsyncPlayerChatEvent event) {
final User user = chatStore.getUser();
chatStore.setRadius(radius);

if (event.getMessage().length() > 1 && chatStore.getType().length() > 0) {
final StringBuilder permission = new StringBuilder();
permission.append("essentials.chat.").append(chatStore.getType());
if (event.getMessage().length() > 1) {
if (chatStore.getType().isEmpty()) {
if (!user.isAuthorized("essentials.chat.local")) {
user.sendMessage(tl("notAllowedToLocal"));
event.setCancelled(true);
return;
}

if (user.isAuthorized(permission.toString())) {
if (event.getMessage().charAt(0) == ess.getSettings().getChatShout() || event.getMessage().charAt(0) == ess.getSettings().getChatQuestion()) {
if (user.isToggleShout() && event.getMessage().length() > 1 && event.getMessage().charAt(0) == ess.getSettings().getChatShout()) {
event.setMessage(event.getMessage().substring(1));
}
event.setFormat(tl(chatStore.getType() + "Format", event.getFormat()));

event.getRecipients().removeIf(player -> !ess.getUser(player).isAuthorized("essentials.chat.receive.local"));
} else {
final String permission = "essentials.chat." + chatStore.getType();

if (user.isAuthorized(permission)) {
if (event.getMessage().charAt(0) == ess.getSettings().getChatShout() || (event.getMessage().charAt(0) == ess.getSettings().getChatQuestion() && ess.getSettings().isChatQuestionEnabled())) {
event.setMessage(event.getMessage().substring(1));
}
event.setFormat(tl(chatStore.getType() + "Format", event.getFormat()));
event.getRecipients().removeIf(player -> !ess.getUser(player).isAuthorized("essentials.chat.receive." + chatStore.getType()));
return;
}

user.sendMessage(tl("notAllowedTo" + chatStore.getType().substring(0, 1).toUpperCase(Locale.ENGLISH) + chatStore.getType().substring(1)));
event.setCancelled(true);
return;
}

user.sendMessage(tl("notAllowedTo" + chatStore.getType().substring(0, 1).toUpperCase(Locale.ENGLISH) + chatStore.getType().substring(1)));
event.setCancelled(true);
return;
}

final Location loc = user.getLocation();
Expand Down
9 changes: 9 additions & 0 deletions EssentialsChat/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@ commands:
description: Toggles whether you are talking in shout mode
usage: /<command> [player] [on|off]
aliases: [etoggleshout]
permissions:
essentials.chat.local:
default: true
essentials.chat.receive.local:
default: true
essentials.chat.receive.shout:
default: true
essentials.chat.receive.question:
default: true