Skip to content

Commit

Permalink
Rename ChatManager and fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Pugzy <[email protected]>
  • Loading branch information
Pugzy committed Nov 20, 2024
1 parent f94e4b3 commit 826dc99
Show file tree
Hide file tree
Showing 21 changed files with 107 additions and 129 deletions.
12 changes: 6 additions & 6 deletions core/src/main/java/tc/oc/pgm/PGMPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import tc.oc.pgm.api.match.MatchManager;
import tc.oc.pgm.api.module.Module;
import tc.oc.pgm.api.module.exception.ModuleLoadException;
import tc.oc.pgm.channels.ChannelManager;
import tc.oc.pgm.channels.ChatManager;
import tc.oc.pgm.command.util.PGMCommandGraph;
import tc.oc.pgm.db.CacheDatastore;
import tc.oc.pgm.db.SQLDatastore;
Expand Down Expand Up @@ -99,7 +99,7 @@ public class PGMPlugin extends JavaPlugin implements PGM, Listener {
private NameDecorationRegistry nameDecorationRegistry;
private ScheduledExecutorService executorService;
private ScheduledExecutorService asyncExecutorService;
private ChannelManager channelManager;
private ChatManager chatManager;
private InventoryManager inventoryManager;
private AfkTracker afkTracker;

Expand Down Expand Up @@ -243,7 +243,7 @@ public void onEnable() {
asyncExecutorService.scheduleAtFixedRate(new ShouldRestartTask(), 0, 1, TimeUnit.MINUTES);
}

channelManager = new ChannelManager();
chatManager = new ChatManager();

registerListeners();
registerCommands();
Expand Down Expand Up @@ -352,8 +352,8 @@ public AfkTracker getAfkTracker() {
}

@Override
public ChannelManager getChannelManager() {
return channelManager;
public ChatManager getChatManager() {
return chatManager;
}

private void registerCommands() {
Expand Down Expand Up @@ -392,7 +392,7 @@ private void registerListeners() {
registerEvents(new MotdListener());
registerEvents(new ServerPingDataListener(matchManager, mapOrder, getLogger()));
registerEvents(new JoinLeaveAnnouncer(matchManager));
registerEvents(channelManager);
registerEvents(chatManager);
}

private boolean loadInitialMaps() {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/tc/oc/pgm/api/PGM.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import tc.oc.pgm.api.map.MapLibrary;
import tc.oc.pgm.api.map.MapOrder;
import tc.oc.pgm.api.match.MatchManager;
import tc.oc.pgm.channels.ChannelManager;
import tc.oc.pgm.channels.ChatManager;
import tc.oc.pgm.namedecorations.NameDecorationRegistry;
import tc.oc.pgm.tablist.MatchTabManager;
import tc.oc.pgm.util.listener.AfkTracker;
Expand Down Expand Up @@ -44,7 +44,7 @@ public interface PGM extends Plugin {

AfkTracker getAfkTracker();

ChannelManager getChannelManager();
ChatManager getChatManager();

AtomicReference<PGM> GLOBAL = new AtomicReference<>(null);

Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/tc/oc/pgm/api/channels/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ default void registerCommand(CommandManager<CommandSender> manager) {
context.inject(MatchPlayer.class).orElseThrow(IllegalStateException::new);

if (context.contains(MESSAGE_KEY)) {
PGM.get().getChannelManager().process(this, sender, context);
PGM.get().getChatManager().process(this, sender, context);
} else {
PGM.get().getChannelManager().setChannel(sender, this);
PGM.get().getChatManager().setChannel(sender, this);
}
}));
}
Expand Down Expand Up @@ -190,7 +190,7 @@ default void processChatMessage(
default void processChatShortcut(
MatchPlayer sender, String message, CommandContext<CommandSender> context) {
if (message.length() == 1) {
PGM.get().getChannelManager().setChannel(sender, this);
PGM.get().getChatManager().setChannel(sender, this);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static void setSquadIntegration(SquadIntegration integration) {
public static void registerChannel(Channel<?> channel) {
if (CHANNELS == null)
throw new IllegalStateException(
"New channels cannot be registered after ChannelManager has been initialised!");
"New channels cannot be registered after ChatManager has been initialised!");
CHANNELS.add(assertNotNull(channel));
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/tc/oc/pgm/api/setting/SettingKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public enum SettingKey implements Aliased {
CHAT("chat", Materials.SIGN, CHAT_TEAM, CHAT_GLOBAL, CHAT_ADMIN) {
@Override
public void update(MatchPlayer player) {
PGM.get().getChannelManager().setChannel(player, player.getSettings().getValue(CHAT));
PGM.get().getChatManager().setChannel(player, player.getSettings().getValue(CHAT));
}
}, // Changes the default chat channel
DEATH(
Expand Down
10 changes: 3 additions & 7 deletions core/src/main/java/tc/oc/pgm/channels/AdminChannel.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package tc.oc.pgm.channels;

import static net.kyori.adventure.key.Key.key;
import static net.kyori.adventure.sound.Sound.sound;
import static net.kyori.adventure.text.Component.empty;
import static net.kyori.adventure.text.Component.text;

import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;
Expand All @@ -23,20 +20,19 @@
import tc.oc.pgm.api.player.MatchPlayer;
import tc.oc.pgm.api.setting.SettingKey;
import tc.oc.pgm.api.setting.SettingValue;
import tc.oc.pgm.util.bukkit.Sounds;
import tc.oc.pgm.util.named.NameStyle;

public class AdminChannel implements Channel<Void> {

private static final List<String> ALIASES = List.of("a");

private static final TextComponent PREFIX = text()
public static final TextComponent PREFIX = text()
.append(text("[", NamedTextColor.WHITE))
.append(text("A", NamedTextColor.GOLD))
.append(text("] ", NamedTextColor.WHITE))
.build();

private static final Sound SOUND = sound(key("random.orb"), Sound.Source.MASTER, 1f, 0.7f);

@Override
public String getDisplayName() {
return "admin";
Expand Down Expand Up @@ -88,7 +84,7 @@ public void messageSent(ChannelMessageEvent<Void> event) {
if (viewer.equals(event.getSender())) continue;
SettingValue value = viewer.getSettings().getValue(SettingKey.SOUNDS);
if (value.equals(SettingValue.SOUNDS_ALL) || value.equals(SettingValue.SOUNDS_CHAT))
viewer.playSound(SOUND);
viewer.playSound(Sounds.ADMIN_CHAT);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import tc.oc.pgm.util.bukkit.OnlinePlayerUUIDMapAdapter;
import tc.oc.pgm.util.text.TextException;

public class ChannelManager implements Listener {
public class ChatManager implements Listener {

CloudKey<AsyncPlayerChatEvent> ORIGINAL_EVENT_KEY =
CloudKey.of("event", AsyncPlayerChatEvent.class);
Expand All @@ -66,7 +66,7 @@ public class ChannelManager implements Listener {

private CommandManager<CommandSender> manager;

public ChannelManager() {
public ChatManager() {
this.channels = new HashSet<>();
this.channels.add(globalChannel = new GlobalChannel());
this.channels.add(adminChannel = new AdminChannel());
Expand All @@ -87,7 +87,7 @@ public ChannelManager() {
public void registerCommands(CommandManager<CommandSender> manager) {
this.manager = manager;

for (Channel<?> channel : PGM.get().getChannelManager().getChannels()) {
for (Channel<?> channel : PGM.get().getChatManager().getChannels()) {
channel.registerCommand(manager);
}
}
Expand Down Expand Up @@ -272,8 +272,7 @@ public void setChannel(MatchPlayer player, SettingValue value) {
}

public void setChannel(MatchPlayer player, Channel<?> channel) {
Channel<?> previous = selectedChannel.get(player.getId());
selectedChannel.put(player.getId(), channel);
Channel<?> previous = selectedChannel.put(player.getId(), channel);

if (channel.getSetting() != null) {
Settings setting = player.getSettings();
Expand All @@ -284,15 +283,15 @@ public void setChannel(MatchPlayer player, Channel<?> channel) {
}
}

if (previous != channel) {
if (previous != null && previous != channel) {
player.sendMessage(translatable(
"setting.set",
text("chat"),
text(previous.getDisplayName(), NamedTextColor.GRAY),
text(channel.getDisplayName(), NamedTextColor.GREEN)));
} else {
player.sendMessage(translatable(
"setting.get", text("chat"), text(previous.getDisplayName(), NamedTextColor.GREEN)));
"setting.get", text("chat"), text(channel.getDisplayName(), NamedTextColor.GREEN)));
}
}

Expand All @@ -304,28 +303,36 @@ public Set<Channel<?>> getChannels() {
return channels;
}

public GlobalChannel getGlobalChannel() {
return globalChannel;
}

public AdminChannel getAdminChannel() {
return adminChannel;
}

public TeamChannel getTeamChannel() {
return teamChannel;
}

public static void broadcastMessage(Component message) {
PGM.get().getChannelManager().globalChannel.broadcastMessage(message, null);
PGM.get().getChatManager().globalChannel.broadcastMessage(message, null);
}

public static void broadcastMessage(Component message, Predicate<MatchPlayer> filter) {
PGM.get().getChannelManager().globalChannel.broadcastMessage(message, null, filter);
PGM.get().getChatManager().globalChannel.broadcastMessage(message, null, filter);
}

public static void broadcastAdminMessage(Component message) {
PGM.get().getChannelManager().adminChannel.broadcastMessage(message, null);
PGM.get().getChatManager().adminChannel.broadcastMessage(message, null);
}

public static void broadcastPartyMessage(Component message, Party party) {
PGM.get().getChannelManager().teamChannel.broadcastMessage(message, party);
PGM.get().getChatManager().teamChannel.broadcastMessage(message, party);
}

public static void broadcastPartyMessage(
Component message, Party party, Predicate<MatchPlayer> filter) {
PGM.get().getChannelManager().teamChannel.broadcastMessage(message, party, filter);
PGM.get().getChatManager().teamChannel.broadcastMessage(message, party, filter);
}
}
21 changes: 8 additions & 13 deletions core/src/main/java/tc/oc/pgm/channels/PrivateMessageChannel.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package tc.oc.pgm.channels;

import static net.kyori.adventure.identity.Identity.identity;
import static net.kyori.adventure.key.Key.key;
import static net.kyori.adventure.sound.Sound.sound;
import static net.kyori.adventure.text.Component.space;
import static net.kyori.adventure.text.Component.text;
import static net.kyori.adventure.text.Component.translatable;
Expand All @@ -15,7 +12,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
Expand All @@ -36,6 +32,7 @@
import tc.oc.pgm.util.MessageSenderIdentity;
import tc.oc.pgm.util.Players;
import tc.oc.pgm.util.bukkit.OnlinePlayerUUIDMapAdapter;
import tc.oc.pgm.util.bukkit.Sounds;
import tc.oc.pgm.util.named.NameStyle;

public class PrivateMessageChannel implements Channel<MatchPlayer> {
Expand All @@ -46,8 +43,6 @@ public class PrivateMessageChannel implements Channel<MatchPlayer> {

private final OnlinePlayerUUIDMapAdapter<MessageSenderIdentity> selectedPlayer, lastMessagedBy;

private static final Sound SOUND = sound(key("random.orb"), Sound.Source.MASTER, 1f, 1.2f);

public PrivateMessageChannel() {
this.selectedPlayer = new OnlinePlayerUUIDMapAdapter<>(PGM.get());
this.lastMessagedBy = new OnlinePlayerUUIDMapAdapter<>(PGM.get());
Expand Down Expand Up @@ -97,7 +92,7 @@ public void messageSent(ChannelMessageEvent<MatchPlayer> event) {
SettingValue value = target.getSettings().getValue(SettingKey.SOUNDS);
if (value.equals(SettingValue.SOUNDS_ALL)
|| value.equals(SettingValue.SOUNDS_CHAT)
|| value.equals(SettingValue.SOUNDS_DM)) target.playSound(SOUND);
|| value.equals(SettingValue.SOUNDS_DM)) target.playSound(Sounds.DIRECT_MESSAGE);

setTarget(lastMessagedBy, sender, target);
setTarget(lastMessagedBy, target, sender);
Expand Down Expand Up @@ -135,9 +130,9 @@ public void registerCommand(CommandManager<CommandSender> manager) {

if (!context.contains(MESSAGE_KEY)) {
setTarget(selectedPlayer, sender, context.get(TARGET_KEY));
PGM.get().getChannelManager().setChannel(sender, this);
PGM.get().getChatManager().setChannel(sender, this);
} else {
PGM.get().getChannelManager().process(this, sender, context);
PGM.get().getChatManager().process(this, sender, context);
}
}));

Expand All @@ -155,10 +150,10 @@ public void registerCommand(CommandManager<CommandSender> manager) {

if (!context.contains(MESSAGE_KEY)) {
setTarget(selectedPlayer, sender, target);
PGM.get().getChannelManager().setChannel(sender, this);
PGM.get().getChatManager().setChannel(sender, this);
} else {
context.store(TARGET_KEY, target);
PGM.get().getChannelManager().process(this, sender, context);
PGM.get().getChatManager().process(this, sender, context);
}
}));
}
Expand All @@ -183,11 +178,11 @@ public void processChatShortcut(

if (spaceIndex == -1) {
setTarget(selectedPlayer, sender, target);
PGM.get().getChannelManager().setChannel(sender, this);
PGM.get().getChatManager().setChannel(sender, this);
return;
}

context.store(MESSAGE_KEY, message.substring(spaceIndex + 1));
context.store(MESSAGE_KEY, message.substring(spaceIndex + 1).trim());
context.store(TARGET_KEY, target);
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/tc/oc/pgm/command/CancelCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.incendo.cloud.annotations.Permission;
import tc.oc.pgm.api.Permissions;
import tc.oc.pgm.api.match.Match;
import tc.oc.pgm.channels.ChannelManager;
import tc.oc.pgm.channels.ChatManager;
import tc.oc.pgm.restart.CancelRestartEvent;
import tc.oc.pgm.restart.RestartManager;
import tc.oc.pgm.start.StartMatchModule;
Expand Down Expand Up @@ -39,7 +39,7 @@ public void cancel(CommandSender sender, Audience audience, Match match) {

match.getCountdown().cancelAll();
match.needModule(StartMatchModule.class).setAutoStart(false);
ChannelManager.broadcastAdminMessage(
ChatManager.broadcastAdminMessage(
translatable("admin.cancelCountdowns.announce", player(sender, NameStyle.FANCY)));
}
}
4 changes: 2 additions & 2 deletions core/src/main/java/tc/oc/pgm/command/FreeForAllCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.incendo.cloud.annotations.Permission;
import tc.oc.pgm.api.Permissions;
import tc.oc.pgm.api.match.Match;
import tc.oc.pgm.channels.ChannelManager;
import tc.oc.pgm.channels.ChatManager;
import tc.oc.pgm.ffa.FreeForAllMatchModule;
import tc.oc.pgm.util.named.NameStyle;
import tc.oc.pgm.util.text.TextParser;
Expand Down Expand Up @@ -86,7 +86,7 @@ public void max(Match match, CommandSender sender, FreeForAllMatchModule ffa) {
}

private void sendResizedMessage(Match match, CommandSender sender, String type, int value) {
ChannelManager.broadcastAdminMessage(translatable(
ChatManager.broadcastAdminMessage(translatable(
"match.resize.announce." + type,
player(sender, NameStyle.FANCY),
translatable("match.info.players", NamedTextColor.YELLOW),
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/tc/oc/pgm/command/MapOrderCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import tc.oc.pgm.api.map.MapInfo;
import tc.oc.pgm.api.map.MapOrder;
import tc.oc.pgm.api.match.Match;
import tc.oc.pgm.channels.ChannelManager;
import tc.oc.pgm.channels.ChatManager;
import tc.oc.pgm.restart.RestartManager;
import tc.oc.pgm.util.Audience;
import tc.oc.pgm.util.UsernameFormatUtils;
Expand Down Expand Up @@ -69,7 +69,7 @@ public void setNext(
if (mapOrder.getNextMap() != null) {
Component mapName = mapOrder.getNextMap().getStyledName(MapNameStyle.COLOR);
mapOrder.setNextMap(null);
ChannelManager.broadcastAdminMessage(translatable(
ChatManager.broadcastAdminMessage(translatable(
"map.setNext.revert",
NamedTextColor.GRAY,
UsernameFormatUtils.formatStaffName(sender, match),
Expand All @@ -92,7 +92,7 @@ public void setNext(

public static void sendSetNextMessage(@NotNull MapInfo map, CommandSender sender, Match match) {
Component mapName = text(map.getName(), NamedTextColor.GOLD);
ChannelManager.broadcastAdminMessage(translatable(
ChatManager.broadcastAdminMessage(translatable(
"map.setNext",
NamedTextColor.GRAY,
UsernameFormatUtils.formatStaffName(sender, match),
Expand Down
Loading

0 comments on commit 826dc99

Please sign in to comment.