Skip to content

Commit 37beeb8

Browse files
committed
Code cleanup, added toggles to join and leave messages
1 parent 9e2d8f8 commit 37beeb8

File tree

12 files changed

+70
-56
lines changed

12 files changed

+70
-56
lines changed

catalyst-api/src/main/java/org/anvilpowered/catalyst/api/plugin/PluginMessages.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public interface PluginMessages<TString> {
2929

3030
TString getNoPermission();
3131

32-
TString getNoServerPermission();
32+
TString getNoServerPermission(String serverName);
3333

3434
TString getNoNickColorPermission();
3535

@@ -77,8 +77,6 @@ public interface PluginMessages<TString> {
7777

7878
TString getRemoveException(String exception);
7979

80-
String removeColor(String text);
81-
8280
TString banCommandUsage();
8381

8482
TString tempBanCommandUsage();

catalyst-api/src/main/java/org/anvilpowered/catalyst/api/registry/CatalystKeys.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,21 @@ public final class CatalystKeys {
6161
.name("JOIN_MESSAGE")
6262
.fallback("%player% has joined the proxy")
6363
.build();
64+
public static final Key<Boolean> JOIN_LISTENER_ENABLED =
65+
Key.builder(TypeTokens.BOOLEAN)
66+
.name("JOIN_LISTENER_ENABLED")
67+
.fallback(true)
68+
.build();
6469
public static final Key<String> LEAVE_MESSAGE =
6570
Key.builder(TypeTokens.STRING)
6671
.name("LEAVE_MESSAGE")
6772
.fallback("%player% has left the proxy")
6873
.build();
74+
public static final Key<Boolean> LEAVE_LISTENER_ENABLED =
75+
Key.builder(TypeTokens.BOOLEAN)
76+
.name("LEAVE_LISTENER_ENABLED")
77+
.fallback(true)
78+
.build();
6979
public static final Key<Boolean> PROXY_CHAT_ENABLED =
7080
Key.builder(TypeTokens.BOOLEAN)
7181
.name("PROXY_CHAT_ENABLED")

catalyst-common/src/main/java/org/anvilpowered/catalyst/common/command/NickNameCommand.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
import com.google.inject.Inject;
2121
import com.mojang.brigadier.context.CommandContext;
22+
import org.anvilpowered.anvil.api.Anvil;
23+
import org.anvilpowered.anvil.api.coremember.CoreMemberManager;
24+
import org.anvilpowered.anvil.api.model.coremember.CoreMember;
2225
import org.anvilpowered.anvil.api.registry.Registry;
2326
import org.anvilpowered.anvil.api.util.PermissionService;
2427
import org.anvilpowered.anvil.api.util.TextService;
@@ -66,7 +69,7 @@ public int execute(CommandContext<TCommandSource> context, Class<?> playerClass)
6669
nick = nick.replaceAll("&k", "");
6770
}
6871
} else {
69-
nick = pluginMessages.removeColor(nick);
72+
nick = textService.serializePlain(textService.of(nick));
7073
textService.send(pluginMessages.getNoNickColorPermission(), context.getSource());
7174
}
7275
}

catalyst-common/src/main/java/org/anvilpowered/catalyst/common/command/ServerCommand.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.anvilpowered.anvil.api.util.PermissionService;
2828
import org.anvilpowered.anvil.api.util.TextService;
2929
import org.anvilpowered.anvil.api.util.UserService;
30+
import org.anvilpowered.catalyst.api.plugin.PluginMessages;
3031
import org.anvilpowered.catalyst.api.registry.CatalystKeys;
3132
import org.anvilpowered.catalyst.api.service.AdvancedServerInfoService;
3233

@@ -58,6 +59,9 @@ public class ServerCommand<
5859
@Inject
5960
private PermissionService permissionService;
6061

62+
@Inject
63+
private PluginMessages<TString> pluginMessages;
64+
6165
public int execute(CommandContext<TCommandSource> context) {
6266
TPlayer player = (TPlayer) context.getSource();
6367
String userName = userService.getUserName(player);
@@ -68,12 +72,7 @@ public int execute(CommandContext<TCommandSource> context) {
6872

6973
if (registry.getOrDefault(CatalystKeys.ENABLE_PER_SERVER_PERMS)
7074
&& !permissionService.hasPermission(player, "catalyst.server." + targetServer)) {
71-
textService.builder()
72-
.append(pluginInfo.getPrefix())
73-
.red().append("You do not have permission to enter ")
74-
.gold().append(targetServer)
75-
.red().append("!")
76-
.sendTo(player);
75+
textService.send(pluginMessages.getNoServerPermission(targetServer), player);
7776
return 0;
7877
}
7978

catalyst-common/src/main/java/org/anvilpowered/catalyst/common/listener/CommonJoinListener.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
import org.anvilpowered.anvil.api.util.PermissionService;
2525
import org.anvilpowered.anvil.api.util.TextService;
2626
import org.anvilpowered.anvil.api.util.UserService;
27-
import org.anvilpowered.catalyst.api.registry.CatalystKeys;
2827
import org.anvilpowered.catalyst.api.event.JoinEvent;
2928
import org.anvilpowered.catalyst.api.listener.JoinListener;
29+
import org.anvilpowered.catalyst.api.registry.CatalystKeys;
3030
import org.anvilpowered.catalyst.api.service.AdvancedServerInfoService;
3131
import org.anvilpowered.catalyst.api.service.BroadcastService;
3232
import org.anvilpowered.catalyst.api.service.EmojiService;
@@ -117,21 +117,23 @@ public void onPlayerJoin(JoinEvent<TPlayer> event) {
117117
? emojiService.toEmoji(registry.getOrDefault(CatalystKeys.JOIN_MESSAGE), "&f")
118118
: registry.getOrDefault(CatalystKeys.JOIN_MESSAGE);
119119

120-
broadcastService.broadcast(
121-
textService.deserialize(
122-
joinMessage
123-
.replace("%player%", userName)
124-
.replace("%server%", server)
125-
)
126-
);
127-
logger.info(
128-
textService.serializePlain(
129-
textService.of(
130-
registry.getOrDefault(CatalystKeys.JOIN_MESSAGE)
120+
if (registry.getOrDefault(CatalystKeys.JOIN_LISTENER_ENABLED)) {
121+
broadcastService.broadcast(
122+
textService.deserialize(
123+
joinMessage
131124
.replace("%player%", userName)
132125
.replace("%server%", server)
133126
)
134-
)
135-
);
127+
);
128+
logger.info(
129+
textService.serializePlain(
130+
textService.of(
131+
registry.getOrDefault(CatalystKeys.JOIN_MESSAGE)
132+
.replace("%player%", userName)
133+
.replace("%server%", server)
134+
)
135+
)
136+
);
137+
}
136138
}
137139
}

catalyst-common/src/main/java/org/anvilpowered/catalyst/common/listener/CommonLeaveListener.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
import org.anvilpowered.anvil.api.registry.Registry;
2222
import org.anvilpowered.anvil.api.util.TextService;
2323
import org.anvilpowered.anvil.api.util.UserService;
24-
import org.anvilpowered.catalyst.api.registry.CatalystKeys;
2524
import org.anvilpowered.catalyst.api.event.LeaveEvent;
2625
import org.anvilpowered.catalyst.api.listener.LeaveListener;
26+
import org.anvilpowered.catalyst.api.registry.CatalystKeys;
2727
import org.anvilpowered.catalyst.api.service.BroadcastService;
2828
import org.anvilpowered.catalyst.api.service.EmojiService;
2929
import org.anvilpowered.catalyst.api.service.StaffListService;
@@ -67,19 +67,21 @@ public void onPlayerLeave(LeaveEvent<TPlayer> event) {
6767
? emojiService.toEmoji(registry.getOrDefault(CatalystKeys.LEAVE_MESSAGE), "&f")
6868
: registry.getOrDefault(CatalystKeys.LEAVE_MESSAGE);
6969

70-
broadcastService.broadcast(
71-
textService.deserialize(
72-
message
73-
.replace("%player%", userService.getUserName((TUser) player))
74-
));
75-
76-
logger.info(
77-
textService.serializePlain(
78-
textService.of(
79-
registry.getOrDefault(CatalystKeys.LEAVE_MESSAGE)
70+
if (registry.getOrDefault(CatalystKeys.LEAVE_LISTENER_ENABLED)) {
71+
broadcastService.broadcast(
72+
textService.deserialize(
73+
message
8074
.replace("%player%", userService.getUserName((TUser) player))
75+
));
76+
77+
logger.info(
78+
textService.serializePlain(
79+
textService.of(
80+
registry.getOrDefault(CatalystKeys.LEAVE_MESSAGE)
81+
.replace("%player%", userService.getUserName((TUser) player))
82+
)
8183
)
82-
)
83-
);
84+
);
85+
}
8486
}
8587
}

catalyst-common/src/main/java/org/anvilpowered/catalyst/common/listener/CommonStaffChatListener.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
import org.anvilpowered.anvil.api.util.PermissionService;
2323
import org.anvilpowered.anvil.api.util.TextService;
2424
import org.anvilpowered.anvil.api.util.UserService;
25-
import org.anvilpowered.catalyst.api.registry.CatalystKeys;
2625
import org.anvilpowered.catalyst.api.event.StaffChatEvent;
2726
import org.anvilpowered.catalyst.api.listener.StaffChatListener;
2827
import org.anvilpowered.catalyst.api.plugin.PluginMessages;
28+
import org.anvilpowered.catalyst.api.registry.CatalystKeys;
2929
import org.anvilpowered.catalyst.api.service.EmojiService;
3030
import org.slf4j.Logger;
3131

@@ -67,8 +67,10 @@ public void onStaffChatEvent(StaffChatEvent<TString, TPlayer> event) {
6767
String finalMessage = message;
6868
userService.getOnlinePlayers().forEach(p -> {
6969
if (permissionService.hasPermission(p, registry.getOrDefault(CatalystKeys.STAFFCHAT_PERMISSION))) {
70-
textService.send(pluginMessages.getStaffChatMessageFormatted("Console",
71-
textService.deserialize(finalMessage)), (TCommandSource) p);
70+
textService.send(
71+
pluginMessages.getStaffChatMessageFormattedConsole(textService.deserialize(finalMessage)),
72+
(TCommandSource) p
73+
);
7274
}
7375
});
7476
logger.info("[STAFF] Console: " + message);

catalyst-common/src/main/java/org/anvilpowered/catalyst/common/plugin/CatalystPluginMessages.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ public TString getNoPermission() {
6868
}
6969

7070
@Override
71-
public TString getNoServerPermission() {
71+
public TString getNoServerPermission(String serverName) {
7272
return textService.builder()
7373
.append(pluginInfo.getPrefix())
74-
.red().append("You do not have permission to join this server!")
74+
.red().append("You do not have permission to enter ")
75+
.gold().append(serverName)
76+
.red().append("!")
7577
.build();
7678
}
7779

@@ -258,17 +260,6 @@ public TString getRemoveException(String exception) {
258260
return getForList(false, false, false, exception);
259261
}
260262

261-
public String removeColor(String in) {
262-
return in.replace("&0", "").replaceAll("&1", "").replaceAll("&2", "")
263-
.replaceAll("&3", "").replaceAll("&4", "").replaceAll("&5", "")
264-
.replaceAll("&6", "").replaceAll("&7", "").replaceAll("&8", "")
265-
.replaceAll("&a", "").replaceAll("&b", "").replaceAll("&c", "")
266-
.replaceAll("&d", "").replaceAll("&e", "").replaceAll("&f", "")
267-
.replaceAll("&k", "").replaceAll("&l", "").replaceAll("&m", "")
268-
.replaceAll("&n", "").replaceAll("&o", "").replaceAll("&r", "")
269-
.replaceAll("&k", "").replaceAll("&9", "");
270-
}
271-
272263
@Override
273264
public TString banCommandUsage() {
274265
return textService.builder()

catalyst-common/src/main/java/org/anvilpowered/catalyst/common/registry/ProxyConfigurationService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ public ProxyConfigurationService(ConfigurationLoader<CommentedConfigurationNode>
4545
setName(CatalystKeys.CHAT_FILTER_ENABLED, "chat.filter.enabled");
4646
setName(CatalystKeys.FIRST_JOIN, "join.firstJoin");
4747
setName(CatalystKeys.JOIN_MESSAGE, "join.message");
48+
setName(CatalystKeys.JOIN_LISTENER_ENABLED, "modules.listener.join");
4849
setName(CatalystKeys.LEAVE_MESSAGE, "leave.message");
50+
setName(CatalystKeys.LEAVE_LISTENER_ENABLED, "modules.listener.leave");
4951
setName(CatalystKeys.PROXY_CHAT_FORMAT_MESSAGE, "chat.format.message");
5052
setName(CatalystKeys.PROXY_CHAT_FORMAT_HOVER, "chat.format.hover");
5153
setName(CatalystKeys.PROXY_CHAT_FORMAT_CLICK_COMMAND, "chat.format.click");
@@ -125,8 +127,12 @@ public ProxyConfigurationService(ConfigurationLoader<CommentedConfigurationNode>
125127
"\nFormat for the message that is displayed when a player joins the proxy for the first time");
126128
setDescription(CatalystKeys.JOIN_MESSAGE,
127129
"\nFormat for the message that is displayed when a player joins the proxy");
130+
setDescription(CatalystKeys.JOIN_LISTENER_ENABLED,
131+
"\nToggle join messages");
128132
setDescription(CatalystKeys.LEAVE_MESSAGE,
129133
"\nFormat for the message that is displayed when a player leaves the proxy");
134+
setDescription(CatalystKeys.LEAVE_LISTENER_ENABLED,
135+
"\nToggle leave messages");
130136
setDescription(CatalystKeys.PROXY_CHAT_FORMAT_MESSAGE,
131137
"\nFormat for the proxy-wide chat");
132138
setDescription(CatalystKeys.PROXY_CHAT_FORMAT_HOVER,

catalyst-common/src/main/java/org/anvilpowered/catalyst/common/service/CommonChatService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ public void sendChatMessage(ChatEvent<TString, TPlayer> event) {
386386
String chatColor = luckpermsService.getChatColor(event.getPlayer());
387387
String nameColor = luckpermsService.getNameColor(event.getPlayer());
388388
String suffix = luckpermsService.getSuffix(event.getPlayer());
389-
String userName = pluginMessages.removeColor(userService.getUserName((TUser) event.getPlayer()));
389+
String userName = textService.serializePlain(textService.of(userService.getUserName((TUser) event.getPlayer())));
390390
String server = locationService.getServer(userName).map(Named::getName).orElseThrow(() ->
391391
new IllegalStateException(userName + " is not in a valid server!"));
392392
UUID playerUUID = userService.getUUID((TUser) event.getPlayer());

catalyst-velocity/src/main/java/org/anvilpowered/catalyst/velocity/listener/VelocityListener.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
4343
import org.anvilpowered.anvil.api.Anvil;
4444
import org.anvilpowered.anvil.api.coremember.CoreMemberManager;
45+
import org.anvilpowered.anvil.api.datastore.Manager;
4546
import org.anvilpowered.anvil.api.model.coremember.CoreMember;
4647
import org.anvilpowered.anvil.api.registry.Registry;
4748
import org.anvilpowered.anvil.api.util.TextService;
@@ -156,7 +157,7 @@ public void onPlayerJoin(LoginEvent event) {
156157
if (!optionalMember.isPresent()) {
157158
return;
158159
}
159-
if (flags[0]) {
160+
if (flags[0] && registry.getOrDefault(CatalystKeys.JOIN_LISTENER_ENABLED)) {
160161
broadcastService.broadcast(
161162
textService.deserialize(
162163
registry.getOrDefault(CatalystKeys.FIRST_JOIN)

catalyst-velocity/src/main/java/org/anvilpowered/catalyst/velocity/module/VelocityModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
import org.anvilpowered.anvil.api.registry.ConfigurationService;
3030
import org.anvilpowered.catalyst.api.service.BroadcastService;
3131
import org.anvilpowered.catalyst.api.service.DiscordCommandService;
32-
import org.anvilpowered.catalyst.common.registry.ProxyConfigurationService;
3332
import org.anvilpowered.catalyst.common.module.CommonModule;
3433
import org.anvilpowered.catalyst.common.plugin.CatalystPluginInfo;
34+
import org.anvilpowered.catalyst.common.registry.ProxyConfigurationService;
3535
import org.anvilpowered.catalyst.velocity.command.VelocityCommandNode;
3636
import org.anvilpowered.catalyst.velocity.service.VelocityBroadcastService;
3737
import org.anvilpowered.catalyst.velocity.service.VelocityDiscordCommandService;

0 commit comments

Comments
 (0)