Updated to 1.21 by switching to cosmos
This commit is contained in:
@@ -7,7 +7,7 @@ import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.command.SimpleCommand;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -39,12 +39,13 @@ public class PartyCommand implements SimpleCommand {
|
||||
CommandSource source = invocation.source();
|
||||
|
||||
if (args.length < 1) {
|
||||
if (!source.hasPermission("party.use"))
|
||||
if (!source.hasPermission("party.use")) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NO_PERMISSION));
|
||||
else if (source instanceof Player)
|
||||
} else if (source instanceof Player) {
|
||||
source.sendMessage(getHelpMessage(source));
|
||||
else
|
||||
} else {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NO_CONSOLE));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -52,11 +53,12 @@ public class PartyCommand implements SimpleCommand {
|
||||
.filter(subCommand -> subCommand.getName().equalsIgnoreCase(args[0]))
|
||||
.findFirst()
|
||||
.ifPresentOrElse(subCommand -> {
|
||||
if (source.hasPermission(subCommand.getPermission()))
|
||||
if (source.hasPermission(subCommand.getPermission())) {
|
||||
subCommand.execute(args, source);
|
||||
else
|
||||
} else {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NO_PERMISSION));
|
||||
}, () -> source.sendMessage(getHelpMessage(source)));
|
||||
}
|
||||
}, () -> source.sendMessage(getHelpMessage(source)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,9 +66,9 @@ public class PartyCommand implements SimpleCommand {
|
||||
String[] args = invocation.arguments();
|
||||
List<String> suggest = new ArrayList<>();
|
||||
|
||||
if (!invocation.source().hasPermission("party.use"))
|
||||
if (!invocation.source().hasPermission("party.use")) {
|
||||
return suggest;
|
||||
else if (args.length == 0) {
|
||||
} else if (args.length == 0) {
|
||||
subCommands.stream()
|
||||
.filter(subCommand -> invocation.source().hasPermission(subCommand.getPermission()))
|
||||
.forEach(subCommand -> suggest.add(subCommand.getName()));
|
||||
@@ -83,10 +85,11 @@ public class PartyCommand implements SimpleCommand {
|
||||
.ifPresent(subCommand -> suggest.addAll(subCommand.suggest(args, invocation.source())));
|
||||
}
|
||||
|
||||
if (args.length == 0)
|
||||
if (args.length == 0) {
|
||||
return suggest;
|
||||
else
|
||||
} else {
|
||||
return finalizeSuggest(suggest, args[args.length - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> finalizeSuggest(List<String> possibleValues, String remaining) {
|
||||
@@ -101,19 +104,21 @@ public class PartyCommand implements SimpleCommand {
|
||||
return finalValues;
|
||||
}
|
||||
|
||||
public Component getHelpMessage(CommandSource source) {
|
||||
public ComponentLike getHelpMessage(CommandSource source) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
subCommands.stream()
|
||||
.filter(subCommand -> source.hasPermission(subCommand.getPermission()))
|
||||
.forEach(subCommand -> stringBuilder.append(subCommand.getHelpMessage()).append("\n"));
|
||||
if (source.hasPermission("command.chat.p"))
|
||||
if (source.hasPermission("command.chat.p")) {
|
||||
stringBuilder.append(Config.PARTY_HELP_CHAT).append("\n");
|
||||
if (stringBuilder.length() != 0)
|
||||
}
|
||||
if (!stringBuilder.isEmpty()) {
|
||||
stringBuilder.replace(stringBuilder.length() - 1, stringBuilder.length(), "");
|
||||
}
|
||||
|
||||
return Utility.parseMiniMessage(Config.PARTY_HELP_WRAPPER,
|
||||
Placeholder.component("commands", Utility.parseMiniMessage(stringBuilder.toString()))
|
||||
);
|
||||
Placeholder.component("commands", Utility.parseMiniMessage(stringBuilder.toString()))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import jdk.jshell.execution.Util;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
|
||||
import java.time.Duration;
|
||||
@@ -30,7 +30,7 @@ import java.util.stream.IntStream;
|
||||
|
||||
public class VoteToMuteHelper {
|
||||
|
||||
private static final Component prefix = Utility.parseMiniMessage("<gold>[VoteMute]</gold>");
|
||||
private static final Component prefix = Utility.parseMiniMessage("<gold>[VoteMute]</gold>").asComponent();
|
||||
|
||||
public VoteToMuteHelper(ProxyServer proxyServer) {
|
||||
RequiredArgumentBuilder<CommandSource, String> playerNode = RequiredArgumentBuilder
|
||||
@@ -51,8 +51,9 @@ public class VoteToMuteHelper {
|
||||
.map(Player::getUsername)
|
||||
.toList();
|
||||
|
||||
if (possibleValues.isEmpty())
|
||||
if (possibleValues.isEmpty()) {
|
||||
return Suggestions.empty();
|
||||
}
|
||||
|
||||
String remaining = builder.getRemaining().toLowerCase();
|
||||
possibleValues.stream()
|
||||
@@ -82,39 +83,39 @@ public class VoteToMuteHelper {
|
||||
.<CommandSource>literal("page")
|
||||
.requires(commandSource -> commandSource.hasPermission("chat.vote-to-mute"))
|
||||
.then(RequiredArgumentBuilder.<CommandSource, Integer>argument("page number", IntegerArgumentType.integer(1))
|
||||
.suggests(((commandContext, suggestionsBuilder) -> {
|
||||
if (!(commandContext.getSource() instanceof Player player)) {
|
||||
return suggestionsBuilder.buildFuture();
|
||||
}
|
||||
Optional<VoteToMuteStarter> instance = VoteToMuteStarter.getInstance(player.getUniqueId());
|
||||
if (instance.isEmpty()) {
|
||||
return suggestionsBuilder.buildFuture();
|
||||
}
|
||||
VoteToMuteStarter voteToMuteStarter = instance.get();
|
||||
String remaining = suggestionsBuilder.getRemaining().toLowerCase();
|
||||
int totalPages = voteToMuteStarter.getTotalPages();
|
||||
IntStream.range(1, totalPages + 1)
|
||||
.mapToObj(String::valueOf)
|
||||
.filter((String str) -> str.toLowerCase().startsWith(remaining))
|
||||
.map(StringArgumentType::escapeIfRequired)
|
||||
.forEach(suggestionsBuilder::suggest);
|
||||
return suggestionsBuilder.buildFuture();
|
||||
}))
|
||||
.executes(commandContext -> {
|
||||
if (!(commandContext.getSource() instanceof Player player)) {
|
||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage("<red>Only players can use this command.</red>"));
|
||||
return 1;
|
||||
}
|
||||
Optional<VoteToMuteStarter> instance = VoteToMuteStarter.getInstance(player.getUniqueId());
|
||||
if (instance.isEmpty()) {
|
||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage("<red>You don't have an active vote to mute.</red>"));
|
||||
return 1;
|
||||
}
|
||||
int pageNumber = commandContext.getArgument("page number", Integer.class);
|
||||
instance.get().showPage(pageNumber);
|
||||
return 1;
|
||||
})
|
||||
).executes(commandContext -> {
|
||||
.suggests(((commandContext, suggestionsBuilder) -> {
|
||||
if (!(commandContext.getSource() instanceof Player player)) {
|
||||
return suggestionsBuilder.buildFuture();
|
||||
}
|
||||
Optional<VoteToMuteStarter> instance = VoteToMuteStarter.getInstance(player.getUniqueId());
|
||||
if (instance.isEmpty()) {
|
||||
return suggestionsBuilder.buildFuture();
|
||||
}
|
||||
VoteToMuteStarter voteToMuteStarter = instance.get();
|
||||
String remaining = suggestionsBuilder.getRemaining().toLowerCase();
|
||||
int totalPages = voteToMuteStarter.getTotalPages();
|
||||
IntStream.range(1, totalPages + 1)
|
||||
.mapToObj(String::valueOf)
|
||||
.filter((String str) -> str.toLowerCase().startsWith(remaining))
|
||||
.map(StringArgumentType::escapeIfRequired)
|
||||
.forEach(suggestionsBuilder::suggest);
|
||||
return suggestionsBuilder.buildFuture();
|
||||
}))
|
||||
.executes(commandContext -> {
|
||||
if (!(commandContext.getSource() instanceof Player player)) {
|
||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage("<red>Only players can use this command.</red>"));
|
||||
return 1;
|
||||
}
|
||||
Optional<VoteToMuteStarter> instance = VoteToMuteStarter.getInstance(player.getUniqueId());
|
||||
if (instance.isEmpty()) {
|
||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage("<red>You don't have an active vote to mute.</red>"));
|
||||
return 1;
|
||||
}
|
||||
int pageNumber = commandContext.getArgument("page number", Integer.class);
|
||||
instance.get().showPage(pageNumber);
|
||||
return 1;
|
||||
})
|
||||
).executes(commandContext -> {
|
||||
sendHelpMessage(commandContext.getSource());
|
||||
return 1;
|
||||
});
|
||||
@@ -123,53 +124,53 @@ public class VoteToMuteHelper {
|
||||
.<CommandSource>literal("messages")
|
||||
.requires(commandSource -> commandSource.hasPermission("chat.vote-to-mute"))
|
||||
.then(RequiredArgumentBuilder.<CommandSource, String>argument("list of messages", StringArgumentType.greedyString())
|
||||
.executes(commandContext -> {
|
||||
if (!(commandContext.getSource() instanceof Player player)) {
|
||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage("<red>Only players can use this command.</red>"));
|
||||
return 1;
|
||||
}
|
||||
Optional<VoteToMuteStarter> instance = VoteToMuteStarter.getInstance(player.getUniqueId());
|
||||
if (instance.isEmpty()) {
|
||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage("<red>You don't have an active vote to mute.</red>"));
|
||||
return 1;
|
||||
}
|
||||
String listOfPages = commandContext.getArgument("list of messages", String.class);
|
||||
if (!listOfPages.matches("([1-9][0-9]*, )*[1-9][0-9]*")) {
|
||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage("<red>Please make sure to format the command correctly.</red>"));
|
||||
return 1;
|
||||
}
|
||||
VoteToMuteStarter voteToMuteStarter = instance.get();
|
||||
.executes(commandContext -> {
|
||||
if (!(commandContext.getSource() instanceof Player player)) {
|
||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage("<red>Only players can use this command.</red>"));
|
||||
return 1;
|
||||
}
|
||||
Optional<VoteToMuteStarter> instance = VoteToMuteStarter.getInstance(player.getUniqueId());
|
||||
if (instance.isEmpty()) {
|
||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage("<red>You don't have an active vote to mute.</red>"));
|
||||
return 1;
|
||||
}
|
||||
String listOfPages = commandContext.getArgument("list of messages", String.class);
|
||||
if (!listOfPages.matches("([1-9][0-9]*, )*[1-9][0-9]*")) {
|
||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage("<red>Please make sure to format the command correctly.</red>"));
|
||||
return 1;
|
||||
}
|
||||
VoteToMuteStarter voteToMuteStarter = instance.get();
|
||||
|
||||
List<Integer> collect = Arrays.stream(listOfPages.split(", "))
|
||||
.map(Integer::parseInt)
|
||||
.collect(Collectors.toList());
|
||||
Optional<Integer> max = collect.stream().max(Integer::compare);
|
||||
if (max.isEmpty()) {
|
||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage("<red>Some of your selected messages do not exist.</red>"));
|
||||
return 1;
|
||||
}
|
||||
int highestLogEntry = max.get();
|
||||
List<Integer> collect = Arrays.stream(listOfPages.split(", "))
|
||||
.map(Integer::parseInt)
|
||||
.collect(Collectors.toList());
|
||||
Optional<Integer> max = collect.stream().max(Integer::compare);
|
||||
if (max.isEmpty()) {
|
||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage("<red>Some of your selected messages do not exist.</red>"));
|
||||
return 1;
|
||||
}
|
||||
int highestLogEntry = max.get();
|
||||
|
||||
if (voteToMuteStarter.getTotalLogEntries() < highestLogEntry) {
|
||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage("<red>Some of your selected messages do not exist.</red>"));
|
||||
return 1;
|
||||
}
|
||||
if (voteToMuteStarter.getTotalLogEntries() < highestLogEntry) {
|
||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage("<red>Some of your selected messages do not exist.</red>"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
Optional<ServerConnection> currentServer = player.getCurrentServer();
|
||||
if (currentServer.isEmpty()) {
|
||||
sendHelpMessage(commandContext.getSource());
|
||||
return 1;
|
||||
}
|
||||
Optional<ServerConnection> currentServer = player.getCurrentServer();
|
||||
if (currentServer.isEmpty()) {
|
||||
sendHelpMessage(commandContext.getSource());
|
||||
return 1;
|
||||
}
|
||||
|
||||
Component chatLogs = voteToMuteStarter.getChatLogsAndClose(collect);
|
||||
RegisteredServer server = currentServer.get().getServer();
|
||||
long count = getTotalEligiblePlayers(server, voteToMuteStarter.countLowerRanks());
|
||||
new ActiveVoteToMute(voteToMuteStarter.getVotedPlayer(), server, proxyServer, Duration.ofMinutes(5),
|
||||
(int) count, voteToMuteStarter.countLowerRanks(), chatLogs, player)
|
||||
.start();
|
||||
return 1;
|
||||
})
|
||||
).executes(commandContext -> {
|
||||
Component chatLogs = voteToMuteStarter.getChatLogsAndClose(collect);
|
||||
RegisteredServer server = currentServer.get().getServer();
|
||||
long count = getTotalEligiblePlayers(server, voteToMuteStarter.countLowerRanks());
|
||||
new ActiveVoteToMute(voteToMuteStarter.getVotedPlayer(), server, proxyServer, Duration.ofMinutes(5),
|
||||
(int) count, voteToMuteStarter.countLowerRanks(), chatLogs, player)
|
||||
.start();
|
||||
return 1;
|
||||
})
|
||||
).executes(commandContext -> {
|
||||
sendHelpMessage(commandContext.getSource());
|
||||
return 1;
|
||||
});
|
||||
@@ -177,47 +178,48 @@ public class VoteToMuteHelper {
|
||||
LiteralArgumentBuilder<CommandSource> voteNode = LiteralArgumentBuilder
|
||||
.<CommandSource>literal("vote")
|
||||
.then(playerNode
|
||||
.then(yesNoNode
|
||||
.executes(commandContext -> {
|
||||
if (!(commandContext.getSource() instanceof Player player)) {
|
||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage(
|
||||
"<red>Only players are allowed to vote</red>"));
|
||||
return 1;
|
||||
}
|
||||
String playerName = commandContext.getArgument("player", String.class);
|
||||
Optional<ActiveVoteToMute> optionalActiveVoteToMute = ActiveVoteToMute.getInstance(playerName);
|
||||
if (optionalActiveVoteToMute.isEmpty()) {
|
||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage(
|
||||
"<red>This player does not have an active vote to mute them.</red>"));
|
||||
return 1;
|
||||
}
|
||||
ActiveVoteToMute activeVoteToMute = optionalActiveVoteToMute.get();
|
||||
.then(yesNoNode
|
||||
.executes(commandContext -> {
|
||||
if (!(commandContext.getSource() instanceof Player player)) {
|
||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage(
|
||||
"<red>Only players are allowed to vote</red>"));
|
||||
return 1;
|
||||
}
|
||||
String playerName = commandContext.getArgument("player", String.class);
|
||||
Optional<ActiveVoteToMute> optionalActiveVoteToMute = ActiveVoteToMute.getInstance(playerName);
|
||||
if (optionalActiveVoteToMute.isEmpty()) {
|
||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage(
|
||||
"<red>This player does not have an active vote to mute them.</red>"));
|
||||
return 1;
|
||||
}
|
||||
ActiveVoteToMute activeVoteToMute = optionalActiveVoteToMute.get();
|
||||
|
||||
if (!activeVoteToMute.countLowerRanks()) {
|
||||
if (!player.hasPermission("chat.vote-to-mute")) {
|
||||
player.sendMessage(Utility.parseMiniMessage("<red>You are not eligible to vote.</red>"));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (!activeVoteToMute.countLowerRanks()) {
|
||||
if (!player.hasPermission("chat.vote-to-mute")) {
|
||||
player.sendMessage(Utility.parseMiniMessage("<red>You are not eligible to vote.</red>"));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
String vote = commandContext.getArgument("yesNo", String.class);
|
||||
switch (vote.toLowerCase()) {
|
||||
case "yes" -> {
|
||||
activeVoteToMute.vote(player.getUniqueId(), true);
|
||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage(
|
||||
"<green>You voted to mute. Thanks for voting, staff will be online soon to review!</green>"));
|
||||
player.getCurrentServer().ifPresent(serverConnection -> notifyEligiblePlayers(serverConnection.getServer(), activeVoteToMute));
|
||||
}
|
||||
case "no" -> {
|
||||
activeVoteToMute.vote(player.getUniqueId(), false);
|
||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage(
|
||||
"<green>You voted <red>not</red> to mute. Thanks for voting, staff will be online soon to review!</green>"));
|
||||
}
|
||||
default -> commandContext.getSource().sendMessage(Utility.parseMiniMessage(
|
||||
"<red><vote> is not a valid vote option</red>", Placeholder.parsed("vote", vote)));
|
||||
}
|
||||
return 1;
|
||||
})).executes(context -> {
|
||||
String vote = commandContext.getArgument("yesNo", String.class);
|
||||
switch (vote.toLowerCase()) {
|
||||
case "yes" -> {
|
||||
activeVoteToMute.vote(player.getUniqueId(), true);
|
||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage(
|
||||
"<green>You voted to mute. Thanks for voting, staff will be online soon to review!</green>"));
|
||||
player.getCurrentServer().ifPresent(serverConnection -> notifyEligiblePlayers(serverConnection.getServer(), activeVoteToMute));
|
||||
}
|
||||
case "no" -> {
|
||||
activeVoteToMute.vote(player.getUniqueId(), false);
|
||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage(
|
||||
"<green>You voted <red>not</red> to mute. Thanks for voting, staff will be online soon to review!</green>"));
|
||||
}
|
||||
default ->
|
||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage(
|
||||
"<red><vote> is not a valid vote option</red>", Placeholder.parsed("vote", vote)));
|
||||
}
|
||||
return 1;
|
||||
})).executes(context -> {
|
||||
sendHelpMessage(context.getSource());
|
||||
return 1;
|
||||
})).executes(context -> {
|
||||
@@ -254,14 +256,14 @@ public class VoteToMuteHelper {
|
||||
}
|
||||
|
||||
private void notifyEligiblePlayers(RegisteredServer server, ActiveVoteToMute activeVoteToMute) {
|
||||
Component message = Utility.parseMiniMessage("<prefix><green><voted_for> out of <total_votes> players have voted to mute <player></green>",
|
||||
Placeholder.component("prefix", prefix),
|
||||
Placeholder.parsed("voted_for", String.valueOf(activeVoteToMute.getVotedFor())),
|
||||
Placeholder.parsed("total_votes", String.valueOf(activeVoteToMute.getTotalEligibleVoters())),
|
||||
Placeholder.parsed("player", activeVoteToMute.getVotedPlayer().getUsername()));
|
||||
ComponentLike message = Utility.parseMiniMessage("<prefix><green><voted_for> out of <total_votes> players have voted to mute <player></green>",
|
||||
Placeholder.component("prefix", prefix),
|
||||
Placeholder.parsed("voted_for", String.valueOf(activeVoteToMute.getVotedFor())),
|
||||
Placeholder.parsed("total_votes", String.valueOf(activeVoteToMute.getTotalEligibleVoters())),
|
||||
Placeholder.parsed("player", activeVoteToMute.getVotedPlayer().getUsername()));
|
||||
boolean countLowerRanks = activeVoteToMute.countLowerRanks();
|
||||
server.getPlayersConnected().stream()
|
||||
.filter(player -> countLowerRanks ? player.hasPermission("chat.backup-vote-to-mute") : player.hasPermission("chat.vote-to-mute"))
|
||||
.filter(player -> countLowerRanks ? player.hasPermission("chat.backup-vote-to-mute") : player.hasPermission("chat.vote-to-mute"))
|
||||
.forEach(player -> player.sendMessage(message));
|
||||
}
|
||||
|
||||
|
||||
+6
-5
@@ -46,11 +46,12 @@ public class Disband implements SubCommand {
|
||||
source.sendMessage(Utility.parseMiniMessage(getHelpMessage()));
|
||||
return;
|
||||
}
|
||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party,
|
||||
Utility.parseMiniMessage(Config.DISBANDED_PARTY,
|
||||
Placeholder.unparsed("owner", player.getUsername()),
|
||||
Placeholder.unparsed("party", party.getPartyName())
|
||||
), null);
|
||||
VelocityChat.getPlugin().getChatHandler()
|
||||
.sendPartyMessage(party,
|
||||
Utility.parseMiniMessage(Config.DISBANDED_PARTY,
|
||||
Placeholder.unparsed("owner", player.getUsername()),
|
||||
Placeholder.unparsed("party", party.getPartyName())
|
||||
).asComponent(), null);
|
||||
party.delete();
|
||||
}
|
||||
|
||||
|
||||
@@ -40,19 +40,20 @@ public class Info implements SubCommand {
|
||||
List<Component> displayNames = new ArrayList<>();
|
||||
for (PartyUser partyUser : party.getPartyUsers()) {
|
||||
Optional<Player> optionalPlayer = VelocityChat.getPlugin().getProxy().getPlayer(partyUser.getUuid());
|
||||
if (optionalPlayer.isPresent() && optionalPlayer.get().isActive())
|
||||
displayNames.add(Config.ONLINE_PREFIX.append(partyUser.getDisplayName()));
|
||||
else
|
||||
displayNames.add(Config.OFFLINE_PREFIX.append(partyUser.getDisplayName()));
|
||||
if (optionalPlayer.isPresent() && optionalPlayer.get().isActive()) {
|
||||
displayNames.add(Config.ONLINE_PREFIX.asComponent().append(partyUser.getDisplayName()));
|
||||
} else {
|
||||
displayNames.add(Config.OFFLINE_PREFIX.asComponent().append(partyUser.getDisplayName()));
|
||||
}
|
||||
}
|
||||
|
||||
PartyUser owner = party.getPartyUser(party.getOwnerUuid());
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.PARTY_INFO,
|
||||
Placeholder.unparsed("party", party.getPartyName()),
|
||||
Placeholder.unparsed("password", party.getPartyPassword()),
|
||||
Placeholder.component("owner", owner == null ? MiniMessage.miniMessage().deserialize("Unknown Owner") : owner.getDisplayName()),
|
||||
Placeholder.component("members", Component.join(JoinConfiguration.separator(Component.text(", ")), displayNames))
|
||||
));
|
||||
Placeholder.unparsed("party", party.getPartyName()),
|
||||
Placeholder.unparsed("password", party.getPartyPassword()),
|
||||
Placeholder.component("owner", owner == null ? MiniMessage.miniMessage().deserialize("Unknown Owner") : owner.getDisplayName()),
|
||||
Placeholder.component("members", Component.join(JoinConfiguration.separator(Component.text(", ")), displayNames))
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -43,7 +43,7 @@ public class Join implements SubCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
// party.addUser(ChatUserManager.getChatUser(player.getUniqueId())); //Removed until we can get nicknames to translate to colors correctly
|
||||
// party.addUser(ChatUserManager.getChatUser(player.getUniqueId())); //Removed until we can get nicknames to translate to colors correctly
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
|
||||
if (chatUser.getPartyId() == party.getPartyId()) {
|
||||
@@ -52,11 +52,12 @@ public class Join implements SubCommand {
|
||||
}
|
||||
party.addUser(chatUser, player.getUsername());
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.JOINED_PARTY, Placeholder.parsed("party_name", party.getPartyName())));
|
||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party,
|
||||
Utility.parseMiniMessage(Config.PLAYER_JOINED_PARTY,
|
||||
Placeholder.component("player_name", chatUser.getDisplayName()),
|
||||
Placeholder.parsed("party_name", party.getPartyName())
|
||||
), null);
|
||||
VelocityChat.getPlugin().getChatHandler()
|
||||
.sendPartyMessage(party,
|
||||
Utility.parseMiniMessage(Config.PLAYER_JOINED_PARTY,
|
||||
Placeholder.component("player_name", chatUser.getDisplayName()),
|
||||
Placeholder.parsed("party_name", party.getPartyName())
|
||||
).asComponent(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+14
-11
@@ -35,28 +35,31 @@ public class Leave implements SubCommand {
|
||||
return;
|
||||
}
|
||||
Optional<ServerConnection> currentServer = player.getCurrentServer();
|
||||
if (currentServer.isEmpty())
|
||||
if (currentServer.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
party.removeUser(player.getUniqueId());
|
||||
if (party.getOwnerUuid().equals(player.getUniqueId())) {
|
||||
if (party.getPartyUsers().size() > 0) {
|
||||
if (!party.getPartyUsers().isEmpty()) {
|
||||
UUID uuid = party.setNewOwner();
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NOTIFY_FINDING_NEW_OWNER));
|
||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party,
|
||||
Utility.parseMiniMessage(Config.OWNER_LEFT_PARTY,
|
||||
Placeholder.unparsed("old_owner", player.getUsername()),
|
||||
Placeholder.unparsed("new_owner", party.getPartyUser(uuid).getPlayerName())
|
||||
), null);
|
||||
VelocityChat.getPlugin().getChatHandler()
|
||||
.sendPartyMessage(party,
|
||||
Utility.parseMiniMessage(Config.OWNER_LEFT_PARTY,
|
||||
Placeholder.unparsed("old_owner", player.getUsername()),
|
||||
Placeholder.unparsed("new_owner", party.getPartyUser(uuid).getPlayerName())
|
||||
).asComponent(), null);
|
||||
} else {
|
||||
party.delete();
|
||||
}
|
||||
} else {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.LEFT_PARTY));
|
||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party,
|
||||
Utility.parseMiniMessage(Config.PLAYER_LEFT_PARTY,
|
||||
Placeholder.unparsed("player_name", player.getUsername())
|
||||
), null);
|
||||
VelocityChat.getPlugin().getChatHandler()
|
||||
.sendPartyMessage(party,
|
||||
Utility.parseMiniMessage(Config.PLAYER_LEFT_PARTY,
|
||||
Placeholder.unparsed("player_name", player.getUsername())
|
||||
).asComponent(), null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,18 +45,19 @@ public class Name implements SubCommand {
|
||||
}
|
||||
if (PartyManager.getParty(args[1]) != null) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.PARTY_EXISTS,
|
||||
Placeholder.unparsed("party", args[1])
|
||||
));
|
||||
Placeholder.unparsed("party", args[1])
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
String oldName = party.getPartyName();
|
||||
party.setPartyName(args[1]);
|
||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party, Utility.parseMiniMessage(Config.RENAMED_PARTY,
|
||||
Placeholder.component("owner", ChatUserManager.getChatUser(player.getUniqueId()).getDisplayName()),
|
||||
Placeholder.unparsed("old_name", oldName),
|
||||
Placeholder.unparsed("new_name", args[1])
|
||||
), null);
|
||||
VelocityChat.getPlugin().getChatHandler()
|
||||
.sendPartyMessage(party, Utility.parseMiniMessage(Config.RENAMED_PARTY,
|
||||
Placeholder.component("owner", ChatUserManager.getChatUser(player.getUniqueId()).getDisplayName()),
|
||||
Placeholder.unparsed("old_name", oldName),
|
||||
Placeholder.unparsed("new_name", args[1])
|
||||
).asComponent(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+17
-13
@@ -14,7 +14,6 @@ import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Owner implements SubCommand {
|
||||
@Override
|
||||
@@ -44,31 +43,36 @@ public class Owner implements SubCommand {
|
||||
PartyUser partyUser = party.getPartyUser(args[1]);
|
||||
if (partyUser == null) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NOT_A_PARTY_MEMBER,
|
||||
Placeholder.unparsed("player", args[1])
|
||||
));
|
||||
Placeholder.unparsed("player", args[1])
|
||||
));
|
||||
return;
|
||||
}
|
||||
party.setNewOwner(partyUser.getUuid());
|
||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party,
|
||||
Utility.parseMiniMessage(Config.NEW_PARTY_OWNER,
|
||||
Placeholder.unparsed("old_owner", player.getUsername()),
|
||||
Placeholder.unparsed("new_owner", partyUser.getPlayerName())
|
||||
), null);
|
||||
VelocityChat.getPlugin().getChatHandler()
|
||||
.sendPartyMessage(party,
|
||||
Utility.parseMiniMessage(Config.NEW_PARTY_OWNER,
|
||||
Placeholder.unparsed("old_owner", player.getUsername()),
|
||||
Placeholder.unparsed("new_owner", partyUser.getPlayerName())
|
||||
).asComponent(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(String[] args, CommandSource source) {
|
||||
ArrayList<String> suggest = new ArrayList<>();
|
||||
if (!(source instanceof Player player))
|
||||
if (!(source instanceof Player player)) {
|
||||
return suggest;
|
||||
}
|
||||
UUID uuid = player.getUniqueId();
|
||||
Party party = PartyManager.getParty(uuid);
|
||||
if (party == null)
|
||||
if (party == null) {
|
||||
return suggest;
|
||||
if (args.length == 1 || args.length == 2)
|
||||
}
|
||||
if (args.length == 1 || args.length == 2) {
|
||||
suggest.addAll(party.getPartyUsers().stream()
|
||||
.filter(partyUser -> !partyUser.getUuid().equals(uuid))
|
||||
.map(PartyUser::getPlayerName).collect(Collectors.toList()));
|
||||
.filter(partyUser -> !partyUser.getUuid().equals(uuid))
|
||||
.map(PartyUser::getPlayerName)
|
||||
.toList());
|
||||
}
|
||||
return suggest;
|
||||
}
|
||||
|
||||
|
||||
+39
-33
@@ -10,6 +10,7 @@ import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -25,12 +26,12 @@ import java.util.stream.Collectors;
|
||||
public class ActiveVoteToMute {
|
||||
|
||||
private static final HashMap<String, ActiveVoteToMute> instances = new HashMap<>();
|
||||
private static final Component prefix = Utility.parseMiniMessage("<gold>[VoteMute]</gold>");
|
||||
private static final Component prefix = Utility.parseMiniMessage("<gold>[VoteMute]</gold>").asComponent();
|
||||
|
||||
private final Player votedPlayer;
|
||||
private final Player startedByPlayer;
|
||||
private HashSet<UUID> votedFor = new HashSet<>();
|
||||
private HashSet<UUID> votedAgainst = new HashSet<>();
|
||||
private final HashSet<UUID> votedFor = new HashSet<>();
|
||||
private final HashSet<UUID> votedAgainst = new HashSet<>();
|
||||
private int totalEligibleVoters;
|
||||
private final boolean countLowerRanks;
|
||||
private final RegisteredServer server;
|
||||
@@ -39,14 +40,16 @@ public class ActiveVoteToMute {
|
||||
private boolean endedVote = false;
|
||||
|
||||
public static Optional<ActiveVoteToMute> getInstance(String username) {
|
||||
if (!instances.containsKey(username))
|
||||
if (!instances.containsKey(username)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(instances.get(username));
|
||||
}
|
||||
|
||||
public static void removePotentialVoter(Player player, RegisteredServer previousServer) {
|
||||
if (!player.hasPermission("chat.backup-vote-to-mute"))
|
||||
if (!player.hasPermission("chat.backup-vote-to-mute")) {
|
||||
return;
|
||||
}
|
||||
if (player.hasPermission("chat.vote-to-mute")) {
|
||||
instances.values().stream()
|
||||
.filter(activeVoteToMute -> previousServer == null || activeVoteToMute.getServer().getServerInfo().hashCode() == previousServer.getServerInfo().hashCode())
|
||||
@@ -60,8 +63,9 @@ public class ActiveVoteToMute {
|
||||
}
|
||||
|
||||
public static void addPotentialVoter(Player player, ServerConnection server) {
|
||||
if (!player.hasPermission("chat.backup-vote-to-mute"))
|
||||
if (!player.hasPermission("chat.backup-vote-to-mute")) {
|
||||
return;
|
||||
}
|
||||
if (player.hasPermission("chat.vote-to-mute")) {
|
||||
instances.values().stream()
|
||||
.filter(activeVoteToMute -> activeVoteToMute.getServer().getServerInfo().hashCode() == server.getServerInfo().hashCode())
|
||||
@@ -85,7 +89,7 @@ public class ActiveVoteToMute {
|
||||
instances.put(votedPlayer.getUsername(), this);
|
||||
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
|
||||
executorService.schedule(this::endVote,
|
||||
duration.toMinutes(), TimeUnit.MINUTES);
|
||||
duration.toMinutes(), TimeUnit.MINUTES);
|
||||
this.startedByPlayer = startedByPlayer;
|
||||
}
|
||||
|
||||
@@ -94,22 +98,23 @@ public class ActiveVoteToMute {
|
||||
}
|
||||
|
||||
private void endVote() {
|
||||
if (endedVote)
|
||||
if (endedVote) {
|
||||
return;
|
||||
}
|
||||
instances.remove(votedPlayer.getUsername());
|
||||
if (votePassed()) {
|
||||
mutePlayer();
|
||||
return;
|
||||
}
|
||||
Component message = Utility.parseMiniMessage("<prefix> <red>The vote to mute <player> has failed, they will not be muted.</red>",
|
||||
Placeholder.component("prefix", prefix), Placeholder.parsed("player", votedPlayer.getUsername()));
|
||||
ComponentLike message = Utility.parseMiniMessage("<prefix> <red>The vote to mute <player> has failed, they will not be muted.</red>",
|
||||
Placeholder.component("prefix", prefix), Placeholder.parsed("player", votedPlayer.getUsername()));
|
||||
server.getPlayersConnected().stream()
|
||||
.filter(player -> countLowerRanks ? player.hasPermission("chat.backup-vote-to-mute") : player.hasPermission("chat.vote-to-mute"))
|
||||
.forEach(player -> player.sendMessage(message));
|
||||
}
|
||||
|
||||
public void start() {
|
||||
Component message = getVoteStartMessage();
|
||||
ComponentLike message = getVoteStartMessage();
|
||||
server.getPlayersConnected().stream()
|
||||
.filter(player -> countLowerRanks ? player.hasPermission("chat.backup-vote-to-mute") : player.hasPermission("chat.vote-to-mute"))
|
||||
.forEach(player -> player.sendMessage(message));
|
||||
@@ -147,24 +152,23 @@ public class ActiveVoteToMute {
|
||||
}
|
||||
|
||||
private void mutePlayer() {
|
||||
Component message = Utility.parseMiniMessage("<prefix> <green>The vote to mute <player> has passed, they will be muted.</green>",
|
||||
Placeholder.component("prefix", prefix), Placeholder.parsed("player", votedPlayer.getUsername()));
|
||||
ComponentLike message = Utility.parseMiniMessage("<prefix> <green>The vote to mute <player> has passed, they will be muted.</green>",
|
||||
Placeholder.component("prefix", prefix), Placeholder.parsed("player", votedPlayer.getUsername()));
|
||||
server.getPlayersConnected().stream()
|
||||
.filter(player -> countLowerRanks ? player.hasPermission("chat.backup-vote-to-mute") : player.hasPermission("chat.vote-to-mute"))
|
||||
.forEach(player -> player.sendMessage(message));
|
||||
proxyServer.getCommandManager().executeAsync(proxyServer.getConsoleCommandSource(),
|
||||
String.format("tempmute %s 1h Muted by the community - under review. -p", votedPlayer.getUsername()));
|
||||
|
||||
String.format("tempmute %s 1h Muted by the community - under review. -p", votedPlayer.getUsername()));
|
||||
|
||||
String chatLogsString = PlainTextComponentSerializer.plainText().serialize(chatLogs);
|
||||
EmbedBuilder embedBuilder = buildMutedEmbed(chatLogsString);
|
||||
|
||||
ALogger.info(String.format("Player %s muted by vote\nLogs:\n%s\n\nVotes for:\n%s\nVotes against:\n%s\n",
|
||||
votedPlayer.getUsername(),
|
||||
chatLogsString,
|
||||
parseUUIDsToPlayerOrString(votedFor),
|
||||
parseUUIDsToPlayerOrString(votedAgainst)
|
||||
));
|
||||
votedPlayer.getUsername(),
|
||||
chatLogsString,
|
||||
parseUUIDsToPlayerOrString(votedFor),
|
||||
parseUUIDsToPlayerOrString(votedAgainst)
|
||||
));
|
||||
|
||||
long id = Config.serverChannelId.get("general");
|
||||
DiscordLink.getPlugin().getBot().sendEmbedToDiscord(id, embedBuilder, -1);
|
||||
@@ -177,14 +181,14 @@ public class ActiveVoteToMute {
|
||||
embedBuilder.setTitle("Player muted by vote");
|
||||
embedBuilder.setColor(Color.CYAN);
|
||||
embedBuilder.addField("Logs",
|
||||
chatLogsString.substring(0, Math.min(chatLogsString.length(), 1024)),
|
||||
false);
|
||||
chatLogsString.substring(0, Math.min(chatLogsString.length(), 1024)),
|
||||
false);
|
||||
embedBuilder.addField("Server",
|
||||
server.getServerInfo().getName().substring(0, 1).toUpperCase() + server.getServerInfo().getName().substring(1),
|
||||
true);
|
||||
server.getServerInfo().getName().substring(0, 1).toUpperCase() + server.getServerInfo().getName().substring(1),
|
||||
true);
|
||||
embedBuilder.addField("Started by",
|
||||
String.format("Username: %s\nUUID: %s", startedByPlayer.getUsername(), startedByPlayer.getUniqueId().toString()),
|
||||
true);
|
||||
String.format("Username: %s\nUUID: %s", startedByPlayer.getUsername(), startedByPlayer.getUniqueId().toString()),
|
||||
true);
|
||||
return embedBuilder;
|
||||
}
|
||||
|
||||
@@ -200,25 +204,27 @@ public class ActiveVoteToMute {
|
||||
|
||||
public void addEligibleVoter(Player player) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
if (votedAgainst.contains(uuid) || votedFor.contains(uuid))
|
||||
if (votedAgainst.contains(uuid) || votedFor.contains(uuid)) {
|
||||
return;
|
||||
}
|
||||
totalEligibleVoters++;
|
||||
player.sendMessage(getVoteStartMessage());
|
||||
}
|
||||
|
||||
public void removeEligibleVoter(UUID uuid) {
|
||||
if (votedFor.contains(uuid) || votedAgainst.contains(uuid))
|
||||
if (votedFor.contains(uuid) || votedAgainst.contains(uuid)) {
|
||||
return;
|
||||
}
|
||||
totalEligibleVoters--;
|
||||
}
|
||||
|
||||
private Component getVoteStartMessage() {
|
||||
private ComponentLike getVoteStartMessage() {
|
||||
return Utility.parseMiniMessage(
|
||||
String.format("""
|
||||
<prefix> <green>A vote to mute <player> for one hour has been started, please read the logs below before voting.</green>
|
||||
<logs>
|
||||
<prefix> Click: <click:run_command:'/votetomutehelper vote %s yes'><red>Mute</red></click> --- <click:run_command:'/votetomutehelper vote %s no'><yellow>Don't mute</yellow></click>""",
|
||||
votedPlayer.getUsername(), votedPlayer.getUsername()),
|
||||
<prefix> <green>A vote to mute <player> for one hour has been started, please read the logs below before voting.</green>
|
||||
<logs>
|
||||
<prefix> Click: <click:run_command:'/votetomutehelper vote %s yes'><red>Mute</red></click> --- <click:run_command:'/votetomutehelper vote %s no'><yellow>Don't mute</yellow></click>""",
|
||||
votedPlayer.getUsername(), votedPlayer.getUsername()),
|
||||
Placeholder.component("prefix", prefix),
|
||||
Placeholder.parsed("player", votedPlayer.getUsername()),
|
||||
Placeholder.component("logs", chatLogs));
|
||||
|
||||
+20
-17
@@ -18,7 +18,7 @@ public class VoteToMuteStarter {
|
||||
|
||||
private static final HashMap<UUID, VoteToMuteStarter> instanceMap = new HashMap<>();
|
||||
|
||||
private static final Component prefix = Utility.parseMiniMessage("<gold>[VoteMute]</gold>");
|
||||
private static final Component prefix = Utility.parseMiniMessage("<gold>[VoteMute]</gold>").asComponent();
|
||||
private final ChatLogHandler chatLogHandler;
|
||||
private final Player votedPlayer;
|
||||
private final Player commandSource;
|
||||
@@ -27,8 +27,9 @@ public class VoteToMuteStarter {
|
||||
private final boolean countLowerRanks;
|
||||
|
||||
public static Optional<VoteToMuteStarter> getInstance(UUID uuid) {
|
||||
if (!instanceMap.containsKey(uuid))
|
||||
if (!instanceMap.containsKey(uuid)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(instanceMap.get(uuid));
|
||||
}
|
||||
|
||||
@@ -45,14 +46,14 @@ public class VoteToMuteStarter {
|
||||
chatLogHandler.retrieveChatLogs(votedPlayer.getUniqueId(), Duration.ofMinutes(10), serverName).whenCompleteAsync((chatLogs, throwable) -> {
|
||||
if (throwable != null) {
|
||||
commandSource.sendMessage(Utility.parseMiniMessage("<prefix> <red>Unable to retrieve messages</red> for player <player>",
|
||||
Placeholder.component("prefix", prefix),
|
||||
Placeholder.parsed("player", votedPlayer.getUsername())));
|
||||
Placeholder.component("prefix", prefix),
|
||||
Placeholder.parsed("player", votedPlayer.getUsername())));
|
||||
return;
|
||||
}
|
||||
parseChatLogs(chatLogs);
|
||||
commandSource.sendMessage(Utility.parseMiniMessage(
|
||||
"<prefix> <green>Please select up to 10 messages other players should see to decide their vote, seperated by comma's. " +
|
||||
"Example: <gold>/votetomutehelper messages 1, 2, 5, 8</gold></green>", Placeholder.component("prefix", prefix)));
|
||||
"Example: <gold>/votetomutehelper messages 1, 2, 5, 8</gold></green>", Placeholder.component("prefix", prefix)));
|
||||
showPage(1);
|
||||
});
|
||||
}
|
||||
@@ -63,13 +64,14 @@ public class VoteToMuteStarter {
|
||||
chatLogs.sort(Comparator.comparing(ChatLog::getTimestamp).reversed());
|
||||
parsedChatLogs = IntStream.range(0, chatLogs.size())
|
||||
.mapToObj(i -> Utility.parseMiniMessage(
|
||||
"<number>. <prefix> <player>: <message>",
|
||||
TagResolver.resolver(
|
||||
Placeholder.unparsed("message", chatLogs.get(i).getMessage()),
|
||||
Placeholder.parsed("number", String.valueOf(i + 1)),
|
||||
playerTag, prefixTag
|
||||
))
|
||||
)
|
||||
"<number>. <prefix> <player>: <message>",
|
||||
TagResolver.resolver(
|
||||
Placeholder.unparsed("message", chatLogs.get(i).getMessage()),
|
||||
Placeholder.parsed("number", String.valueOf(i + 1)),
|
||||
playerTag,
|
||||
prefixTag
|
||||
)).asComponent()
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@@ -89,16 +91,17 @@ public class VoteToMuteStarter {
|
||||
.append("><hover:show_text:'<gold>Click to go to next page'><gold><next page></gold></hover></click> ");
|
||||
}
|
||||
commandSource.sendMessage(Utility.parseMiniMessage(stringBuilder.toString(),
|
||||
Placeholder.parsed("player", votedPlayer.getUsername()),
|
||||
Placeholder.component("prefix", prefix),
|
||||
Placeholder.component("logs", chatLogsComponent)));
|
||||
Placeholder.parsed("player", votedPlayer.getUsername()),
|
||||
Placeholder.component("prefix", prefix),
|
||||
Placeholder.component("logs", chatLogsComponent)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the chat logs for the given list of IDs. It removes 1 from the IDs before using them
|
||||
* It removes the instance from the hashmap after this function call
|
||||
* Retrieves the chat logs for the given list of IDs. It removes 1 from the IDs before using them It removes the
|
||||
* instance from the hashmap after this function call
|
||||
*
|
||||
* @param ids A list of integers representing the IDs of the chat logs to retrieve.
|
||||
*
|
||||
* @return A Component object containing the selected chat logs joined by newlines.
|
||||
*/
|
||||
public Component getChatLogsAndClose(List<Integer> ids) {
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.alttd.velocitychat.data;
|
||||
import com.alttd.chat.config.ServerConfig;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -31,8 +31,7 @@ public class ServerWrapper {
|
||||
return serverName;
|
||||
}
|
||||
|
||||
public boolean globalChat()
|
||||
{
|
||||
public boolean globalChat() {
|
||||
return globalChat;
|
||||
}
|
||||
|
||||
@@ -40,10 +39,11 @@ public class ServerWrapper {
|
||||
return joinMessages;
|
||||
}
|
||||
|
||||
public void sendJoinLeaveMessage(UUID uuid, Component component) {
|
||||
if(joinMessages())
|
||||
public void sendJoinLeaveMessage(UUID uuid, ComponentLike component) {
|
||||
if (joinMessages()) {
|
||||
getRegisteredServer().getPlayersConnected().stream()
|
||||
.filter(p -> !ChatUserManager.getChatUser(p.getUniqueId()).getIgnoredPlayers().contains(uuid))
|
||||
.forEach(p -> p.sendMessage(component));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.TextReplacementConfig;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
@@ -24,7 +25,10 @@ import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.*;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ChatHandler {
|
||||
|
||||
@@ -32,11 +36,15 @@ public class ChatHandler {
|
||||
UUID uuid = UUID.fromString(sender);
|
||||
ChatUser senderUser = ChatUserManager.getChatUser(uuid);
|
||||
Optional<Player> optionalPlayer = VelocityChat.getPlugin().getProxy().getPlayer(uuid);
|
||||
if(optionalPlayer.isEmpty()) return;
|
||||
if (optionalPlayer.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Player player = optionalPlayer.get();
|
||||
|
||||
Optional<Player> optionalPlayer2 = VelocityChat.getPlugin().getProxy().getPlayer(target);
|
||||
if(optionalPlayer2.isEmpty()) return;
|
||||
if (optionalPlayer2.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Player player2 = optionalPlayer2.get();
|
||||
ChatUser targetUser = ChatUserManager.getChatUser(player2.getUniqueId());
|
||||
|
||||
@@ -49,12 +57,12 @@ public class ChatHandler {
|
||||
Placeholder.unparsed("server", player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName() : "Altitude"));
|
||||
|
||||
ServerConnection serverConnection;
|
||||
if(player.getCurrentServer().isPresent() && player2.getCurrentServer().isPresent()) {
|
||||
if (player.getCurrentServer().isPresent() && player2.getCurrentServer().isPresent()) {
|
||||
// redirect to the sender
|
||||
serverConnection = player.getCurrentServer().get();
|
||||
Component component = Utility.parseMiniMessage(Config.MESSAGESENDER
|
||||
.replaceAll("<sendername>", player.getUsername())
|
||||
.replaceAll("<receivername>", player2.getUsername()), Placeholders);
|
||||
.replaceAll("<sendername>", player.getUsername())
|
||||
.replaceAll("<receivername>", player2.getUsername()), Placeholders).asComponent();
|
||||
ByteArrayDataOutput buf = ByteStreams.newDataOutput();
|
||||
buf.writeUTF("privatemessageout");
|
||||
buf.writeUTF(player.getUniqueId().toString());
|
||||
@@ -66,8 +74,8 @@ public class ChatHandler {
|
||||
//redirect to the receiver
|
||||
serverConnection = player2.getCurrentServer().get();
|
||||
component = Utility.parseMiniMessage(Config.MESSAGERECIEVER
|
||||
.replaceAll("<sendername>", player.getUsername())
|
||||
.replaceAll("<receivername>", player2.getUsername()), Placeholders);
|
||||
.replaceAll("<sendername>", player.getUsername())
|
||||
.replaceAll("<receivername>", player2.getUsername()), Placeholders).asComponent();
|
||||
buf = ByteStreams.newDataOutput();
|
||||
buf.writeUTF("privatemessagein");
|
||||
buf.writeUTF(player2.getUniqueId().toString());
|
||||
@@ -85,25 +93,25 @@ public class ChatHandler {
|
||||
Placeholder.parsed("displayname", Utility.getDisplayName(player.getUniqueId(), player.getUsername())),
|
||||
Placeholder.unparsed("target", (target.isEmpty() ? " tried to say: " : " -> " + target + ": ")),
|
||||
Placeholder.unparsed("input", input)
|
||||
);
|
||||
Component blockedNotification = Utility.parseMiniMessage(Config.NOTIFICATIONFORMAT, Placeholders);
|
||||
);
|
||||
ComponentLike blockedNotification = Utility.parseMiniMessage(Config.NOTIFICATIONFORMAT, Placeholders);
|
||||
|
||||
serverConnection.getServer().getPlayersConnected().forEach(pl ->{
|
||||
serverConnection.getServer().getPlayersConnected().forEach(pl -> {
|
||||
if (pl.hasPermission("chat.alert-blocked")) {
|
||||
pl.sendMessage(blockedNotification);
|
||||
}
|
||||
});
|
||||
player.sendMessage(Utility.parseMiniMessage("<red>The language you used in your message is not allowed, " +
|
||||
"this constitutes as your only warning. Any further attempts at bypassing the filter will result in staff intervention.</red>"));
|
||||
"this constitutes as your only warning. Any further attempts at bypassing the filter will result in staff intervention.</red>"));
|
||||
}
|
||||
|
||||
public void sendPartyMessage(Party party, Component message, @Nullable List<UUID> ignoredPlayers)
|
||||
{
|
||||
public void sendPartyMessage(Party party, Component message, @Nullable List<UUID> ignoredPlayers) {
|
||||
VelocityChat.getPlugin().getProxy().getAllPlayers().stream()
|
||||
.filter(pl -> {
|
||||
UUID uuid = pl.getUniqueId();
|
||||
if (ignoredPlayers != null && ignoredPlayers.contains(uuid))
|
||||
if (ignoredPlayers != null && ignoredPlayers.contains(uuid)) {
|
||||
return false;
|
||||
}
|
||||
return party.getPartyUsers().stream().anyMatch(pu -> pu.getUuid().equals(uuid));
|
||||
}).forEach(pl -> {
|
||||
pl.sendMessage(message);
|
||||
@@ -114,7 +122,9 @@ public class ChatHandler {
|
||||
|
||||
public void sendPartyMessage(UUID uuid, String message, Component item, ServerConnection serverConnection) {
|
||||
Optional<Player> optionalPlayer = VelocityChat.getPlugin().getProxy().getPlayer(uuid);
|
||||
if (optionalPlayer.isEmpty()) return;
|
||||
if (optionalPlayer.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Player player = optionalPlayer.get();
|
||||
ChatUser user = ChatUserManager.getChatUser(uuid);
|
||||
Party party = PartyManager.getParty(user.getPartyId());
|
||||
@@ -122,7 +132,7 @@ public class ChatHandler {
|
||||
player.sendMessage(Utility.parseMiniMessage(Config.NOT_IN_A_PARTY));
|
||||
return;
|
||||
}
|
||||
Component senderName = user.getDisplayName();
|
||||
ComponentLike senderName = user.getDisplayName();
|
||||
|
||||
TagResolver Placeholders = TagResolver.resolver(
|
||||
Placeholder.component("sender", senderName),
|
||||
@@ -130,9 +140,9 @@ public class ChatHandler {
|
||||
Placeholder.unparsed("partyname", party.getPartyName()),
|
||||
Placeholder.component("message", parseMessageContent(player, message)),
|
||||
Placeholder.unparsed("server", serverConnection.getServer().getServerInfo().getName())
|
||||
);
|
||||
);
|
||||
|
||||
Component partyMessage = Utility.parseMiniMessage(Config.PARTY_FORMAT, Placeholders)
|
||||
Component partyMessage = Utility.parseMiniMessage(Config.PARTY_FORMAT, Placeholders).asComponent()
|
||||
.replaceText(TextReplacementConfig.builder().once().matchLiteral("[i]").replacement(item).build());
|
||||
|
||||
ModifiableString modifiableString = new ModifiableString(partyMessage);
|
||||
@@ -145,9 +155,9 @@ public class ChatHandler {
|
||||
|
||||
sendPartyMessage(party, partyMessage, user.getIgnoredBy());
|
||||
|
||||
Component spyMessage = Utility.parseMiniMessage(Config.PARTY_SPY, Placeholders);
|
||||
for(Player pl : serverConnection.getServer().getPlayersConnected()) {
|
||||
if(pl.hasPermission(Config.SPYPERMISSION) && !party.getPartyUsersUuid().contains(pl.getUniqueId())) {
|
||||
ComponentLike spyMessage = Utility.parseMiniMessage(Config.PARTY_SPY, Placeholders);
|
||||
for (Player pl : serverConnection.getServer().getPlayersConnected()) {
|
||||
if (pl.hasPermission(Config.SPYPERMISSION) && !party.getPartyUsersUuid().contains(pl.getUniqueId())) {
|
||||
pl.sendMessage(spyMessage);
|
||||
}
|
||||
}
|
||||
@@ -157,18 +167,20 @@ public class ChatHandler {
|
||||
public void globalAdminChat(String message) {
|
||||
Component component = GsonComponentSerializer.gson().deserialize(message);
|
||||
|
||||
VelocityChat.getPlugin().getProxy().getAllPlayers().stream().filter(target -> target.hasPermission("command.chat.globaladminchat")/*TODO permission*/).forEach(target -> {
|
||||
target.sendMessage(component);
|
||||
});
|
||||
VelocityChat.getPlugin().getProxy().getAllPlayers()
|
||||
.stream()
|
||||
.filter(target -> target.hasPermission("command.chat.globaladminchat"))
|
||||
.forEach(target -> target.sendMessage(component));
|
||||
}
|
||||
|
||||
public void globalAdminChat(CommandSource commandSource, String message) {
|
||||
Component senderName = Component.text(Config.CONSOLENAME);
|
||||
ComponentLike senderName = Component.text(Config.CONSOLENAME);
|
||||
String serverName = "Altitude";
|
||||
if (commandSource instanceof Player) {
|
||||
Player sender = (Player) commandSource;
|
||||
if (commandSource instanceof Player sender) {
|
||||
ChatUser user = ChatUserManager.getChatUser(sender.getUniqueId());
|
||||
if(user == null) return;
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
senderName = user.getDisplayName();
|
||||
serverName = sender.getCurrentServer().isPresent() ? sender.getCurrentServer().get().getServerInfo().getName() : "Altitude";
|
||||
}
|
||||
@@ -178,15 +190,16 @@ public class ChatHandler {
|
||||
Placeholder.component("sender", senderName),
|
||||
Placeholder.unparsed("server", serverName));
|
||||
|
||||
Component component = Utility.parseMiniMessage(Config.GACFORMAT, Placeholders);
|
||||
ComponentLike component = Utility.parseMiniMessage(Config.GACFORMAT, Placeholders);
|
||||
|
||||
VelocityChat.getPlugin().getProxy().getAllPlayers().stream().filter(target -> target.hasPermission("command.chat.globaladminchat")/*TODO permission*/).forEach(target -> {
|
||||
target.sendMessage(component);
|
||||
});
|
||||
VelocityChat.getPlugin().getProxy().getAllPlayers()
|
||||
.stream()
|
||||
.filter(target -> target.hasPermission("command.chat.globaladminchat"))
|
||||
.forEach(target -> target.sendMessage(component));
|
||||
}
|
||||
|
||||
public void sendMail(CommandSource commandSource, String recipient, String message) {
|
||||
UUID uuid = Config.CONSOLEUUID;;
|
||||
UUID uuid = Config.CONSOLEUUID;
|
||||
String senderName = Config.CONSOLENAME;
|
||||
UUID targetUUID;
|
||||
if (commandSource instanceof Player player) {
|
||||
@@ -248,7 +261,7 @@ public class ChatHandler {
|
||||
}
|
||||
|
||||
private Component parseMails(List<Mail> mails, boolean mark) {
|
||||
Component component = Utility.parseMiniMessage(Config.mailHeader);
|
||||
Component component = Utility.parseMiniMessage(Config.mailHeader).asComponent();
|
||||
for (Mail mail : mails) {
|
||||
if (mail.isUnRead() && mark) {
|
||||
mail.setReadTime(System.currentTimeMillis());
|
||||
@@ -262,28 +275,14 @@ public class ChatHandler {
|
||||
Placeholder.component("message", Utility.parseMiniMessage(mail.getMessage())),
|
||||
Placeholder.unparsed("date", date.toString()),
|
||||
Placeholder.unparsed("time_ago", getTimeAgo(Duration.between(date.toInstant(), new Date().toInstant())))
|
||||
);
|
||||
Component mailMessage = Utility.parseMiniMessage(Config.mailBody, Placeholders);
|
||||
);
|
||||
ComponentLike mailMessage = Utility.parseMiniMessage(Config.mailBody, Placeholders);
|
||||
component = component.append(Component.newline()).append(mailMessage);
|
||||
}
|
||||
component = component.append(Component.newline()).append(Utility.parseMiniMessage(Config.mailFooter));
|
||||
return component;
|
||||
}
|
||||
|
||||
public void partyChat(String partyId, UUID uuid, Component message) {
|
||||
Party party = PartyManager.getParty(Integer.parseInt(partyId));
|
||||
if (party == null) {
|
||||
ALogger.warn("Received a non existent party");
|
||||
return;
|
||||
}
|
||||
List<UUID> ignoredPlayers = ChatUserManager.getChatUser(uuid).getIgnoredPlayers();
|
||||
List<UUID> partyUsersUuid = party.getPartyUsersUuid();
|
||||
VelocityChat.getPlugin().getProxy().getAllPlayers().stream()
|
||||
.filter(p -> partyUsersUuid.contains(p.getUniqueId()))
|
||||
.filter(p -> !ignoredPlayers.contains(p.getUniqueId()))
|
||||
.forEach(p -> p.sendMessage(message));
|
||||
}
|
||||
|
||||
public void mutePlayer(String uuid, boolean muted) {
|
||||
ByteArrayDataOutput buf = ByteStreams.newDataOutput();
|
||||
buf.writeUTF("chatpunishments");
|
||||
@@ -293,10 +292,12 @@ public class ChatHandler {
|
||||
|
||||
private String getTimeAgo(Duration duration) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
if (duration.toDays() != 0)
|
||||
if (duration.toDays() != 0) {
|
||||
stringBuilder.append(duration.toDays()).append("d ");
|
||||
if (duration.toHoursPart() != 0 || !stringBuilder.isEmpty())
|
||||
}
|
||||
if (duration.toHoursPart() != 0 || !stringBuilder.isEmpty()) {
|
||||
stringBuilder.append(duration.toHoursPart()).append("h ");
|
||||
}
|
||||
stringBuilder.append(duration.toMinutesPart()).append("m ago");
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
@@ -312,7 +313,7 @@ public class ChatHandler {
|
||||
|
||||
MiniMessage miniMessage = MiniMessage.builder().tags(tagResolver.build()).build();
|
||||
Component component = miniMessage.deserialize(rawMessage);
|
||||
for(ChatFilter chatFilter : RegexManager.getEmoteFilters()) {
|
||||
for (ChatFilter chatFilter : RegexManager.getEmoteFilters()) {
|
||||
component = component.replaceText(
|
||||
TextReplacementConfig.builder()
|
||||
.times(Config.EMOTELIMIT)
|
||||
|
||||
@@ -8,15 +8,12 @@ import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.event.PostOrder;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
// TODO code CLEANUP
|
||||
public class ChatListener {
|
||||
|
||||
private VelocityChat plugin;
|
||||
private final VelocityChat plugin;
|
||||
|
||||
public ChatListener() {
|
||||
plugin = VelocityChat.getPlugin();
|
||||
@@ -30,18 +27,20 @@ public class ChatListener {
|
||||
if (commandSource instanceof Player) {
|
||||
Player sender = (Player) event.getSender();
|
||||
senderName = sender.getUsername();
|
||||
serverName = sender.getCurrentServer().isPresent() ? sender.getCurrentServer().get().getServerInfo().getName() : "Altitude";
|
||||
serverName = sender.getCurrentServer().isPresent()
|
||||
? sender.getCurrentServer().get().getServerInfo().getName() : "Altitude";
|
||||
}
|
||||
|
||||
Component message = Utility.parseMiniMessage(Config.GACFORMAT,
|
||||
Placeholder.parsed("sender", senderName),
|
||||
Placeholder.component("message", Utility.parseMiniMessage(event.getMessage())),
|
||||
Placeholder.parsed("server", serverName)
|
||||
);
|
||||
ComponentLike message = Utility.parseMiniMessage(Config.GACFORMAT,
|
||||
Placeholder.parsed("sender", senderName),
|
||||
Placeholder.component("message", Utility.parseMiniMessage(event.getMessage())),
|
||||
Placeholder.parsed("server", serverName)
|
||||
);
|
||||
|
||||
plugin.getProxy().getAllPlayers().stream().filter(target -> target.hasPermission("command.chat.globaladminchat")).forEach(target -> {
|
||||
target.sendMessage(message);
|
||||
});
|
||||
plugin.getProxy().getAllPlayers()
|
||||
.stream()
|
||||
.filter(target -> target.hasPermission("command.chat.globaladminchat"))
|
||||
.forEach(target -> target.sendMessage(message));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package com.alttd.velocitychat.listeners;
|
||||
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.managers.PartyManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.objects.Mail;
|
||||
import com.alttd.chat.objects.Party;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.alttd.velocitychat.VelocityChat;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.velocitychat.commands.vote_to_mute.ActiveVoteToMute;
|
||||
import com.alttd.velocitychat.data.ServerWrapper;
|
||||
import com.alttd.velocitychat.handlers.ServerHandler;
|
||||
import com.alttd.chat.managers.PartyManager;
|
||||
import com.alttd.chat.objects.Party;
|
||||
import com.velocitypowered.api.event.PostOrder;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
||||
@@ -21,11 +21,15 @@ import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.kyori.adventure.title.Title;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ProxyPlayerListener {
|
||||
@@ -35,15 +39,18 @@ public class ProxyPlayerListener {
|
||||
Player player = event.getPlayer();
|
||||
UUID uuid = player.getUniqueId();
|
||||
Party party = PartyManager.getParty(event.getPlayer().getUniqueId());
|
||||
if (party == null) return;
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
|
||||
if (chatUser == null)
|
||||
if (party == null) {
|
||||
return;
|
||||
}
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
|
||||
if (chatUser == null) {
|
||||
return;
|
||||
}
|
||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party,
|
||||
Utility.parseMiniMessage(Config.PARTY_MEMBER_LOGGED_ON,
|
||||
Placeholder.component("player", chatUser.getDisplayName())
|
||||
),
|
||||
chatUser.getIgnoredPlayers());
|
||||
Utility.parseMiniMessage(Config.PARTY_MEMBER_LOGGED_ON,
|
||||
Placeholder.component("player", chatUser.getDisplayName())
|
||||
).asComponent(),
|
||||
chatUser.getIgnoredPlayers());
|
||||
// TODO setup ChatUser on Proxy
|
||||
//VelocityChat.getPlugin().getChatHandler().addPlayer(new ChatPlayer(event.getPlayer().getUniqueId()));
|
||||
|
||||
@@ -57,28 +64,32 @@ public class ProxyPlayerListener {
|
||||
if (previousServer != null) {
|
||||
ActiveVoteToMute.removePotentialVoter(player, previousServer);
|
||||
Optional<ServerConnection> currentServer = player.getCurrentServer();
|
||||
if (currentServer.isEmpty())
|
||||
if (currentServer.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
ActiveVoteToMute.addPotentialVoter(player, currentServer.get());
|
||||
return;
|
||||
}
|
||||
Optional<ServerConnection> currentServer = player.getCurrentServer();
|
||||
if (currentServer.isEmpty())
|
||||
if (currentServer.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
ActiveVoteToMute.addPotentialVoter(player, currentServer.get());
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
List<Mail> unReadMail = chatUser.getUnReadMail();
|
||||
if (unReadMail.isEmpty())
|
||||
if (unReadMail.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
VelocityChat plugin = VelocityChat.getPlugin();
|
||||
plugin.getProxy().getScheduler().buildTask(plugin, () -> {
|
||||
if (!player.isActive())
|
||||
if (!player.isActive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Component message = Utility.parseMiniMessage(Config.mailUnread,
|
||||
Placeholder.unparsed("amount", String.valueOf(unReadMail.size())));
|
||||
ComponentLike message = Utility.parseMiniMessage(Config.mailUnread,
|
||||
Placeholder.unparsed("amount", String.valueOf(unReadMail.size())));
|
||||
player.sendMessage(message);
|
||||
player.showTitle(Title.title(message, Component.empty()));
|
||||
player.showTitle(Title.title(message.asComponent(), Component.empty()));
|
||||
}).delay(Config.mailDisplayDelay * 50L, TimeUnit.MILLISECONDS).schedule();
|
||||
|
||||
}
|
||||
@@ -88,24 +99,25 @@ public class ProxyPlayerListener {
|
||||
ActiveVoteToMute.removePotentialVoter(event.getPlayer(), null);
|
||||
UUID uuid = event.getPlayer().getUniqueId();
|
||||
Party party = PartyManager.getParty(event.getPlayer().getUniqueId());
|
||||
if (party == null) return;
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
|
||||
if (chatUser == null)
|
||||
if (party == null) {
|
||||
return;
|
||||
}
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
|
||||
if (chatUser == null) {
|
||||
return;
|
||||
}
|
||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party,
|
||||
Utility.parseMiniMessage(Config.PARTY_MEMBER_LOGGED_OFF,
|
||||
Placeholder.component("player", chatUser.getDisplayName())
|
||||
),
|
||||
chatUser.getIgnoredPlayers());
|
||||
Utility.parseMiniMessage(Config.PARTY_MEMBER_LOGGED_OFF,
|
||||
Placeholder.component("player", chatUser.getDisplayName())
|
||||
).asComponent(),
|
||||
chatUser.getIgnoredPlayers());
|
||||
// TODO setup ChatUser on Proxy
|
||||
//VelocityChat.getPlugin().getChatHandler().removePlayer(event.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
|
||||
private static final HashSet<UUID> silentJoin = new HashSet<>();
|
||||
|
||||
public static void addSilentJoin(UUID uuid)
|
||||
{
|
||||
public static void addSilentJoin(UUID uuid) {
|
||||
silentJoin.add(uuid);
|
||||
}
|
||||
|
||||
@@ -122,11 +134,11 @@ public class ProxyPlayerListener {
|
||||
Placeholder.parsed("player", player.getUsername()),
|
||||
Placeholder.parsed("from_server", previousServer.getServerInfo().getName()),
|
||||
Placeholder.parsed("to_server", event.getServer().getServerInfo().getName())
|
||||
);
|
||||
);
|
||||
|
||||
if (silentJoin.remove(uuid)) {
|
||||
Component message = Utility.parseMiniMessage(Config.SILENT_JOIN_JOINED_FROM,
|
||||
placeholders);
|
||||
ComponentLike message = Utility.parseMiniMessage(Config.SILENT_JOIN_JOINED_FROM,
|
||||
placeholders);
|
||||
event.getServer().getPlayersConnected().stream()
|
||||
.filter(player1 -> player1.hasPermission("command.chat.silent-join-notify"))
|
||||
.forEach(player1 -> player1.sendMessage(message));
|
||||
@@ -134,17 +146,17 @@ public class ProxyPlayerListener {
|
||||
}
|
||||
|
||||
ServerWrapper wrapper = serverHandler.getWrapper(previousServer.getServerInfo().getName());
|
||||
if(wrapper != null) {
|
||||
if (wrapper != null) {
|
||||
wrapper.sendJoinLeaveMessage(uuid, Utility.parseMiniMessage(Config.SERVERSWTICHMESSAGETO, placeholders));
|
||||
}
|
||||
wrapper = serverHandler.getWrapper(event.getServer().getServerInfo().getName());
|
||||
if(wrapper != null) {
|
||||
if (wrapper != null) {
|
||||
wrapper.sendJoinLeaveMessage(uuid, Utility.parseMiniMessage(Config.SERVERSWTICHMESSAGEFROM, placeholders));
|
||||
}
|
||||
} else {
|
||||
if (silentJoin.remove(uuid)) {
|
||||
Component message = Utility.parseMiniMessage(Config.SILENT_JOIN_JOINED,
|
||||
Placeholder.unparsed("player", player.getUsername()));
|
||||
ComponentLike message = Utility.parseMiniMessage(Config.SILENT_JOIN_JOINED,
|
||||
Placeholder.unparsed("player", player.getUsername()));
|
||||
event.getServer().getPlayersConnected().stream()
|
||||
.filter(player1 -> player1.hasPermission("command.chat.silent-join-notify"))
|
||||
.forEach(player1 -> player1.sendMessage(message));
|
||||
@@ -152,7 +164,7 @@ public class ProxyPlayerListener {
|
||||
}
|
||||
|
||||
ServerWrapper wrapper = serverHandler.getWrapper(event.getServer().getServerInfo().getName());
|
||||
if(wrapper != null) {
|
||||
if (wrapper != null) {
|
||||
wrapper.sendJoinLeaveMessage(uuid, Utility.parseMiniMessage(Config.SERVERJOINMESSAGE, Placeholder.unparsed("player", player.getUsername())));
|
||||
}
|
||||
}
|
||||
@@ -165,11 +177,11 @@ public class ProxyPlayerListener {
|
||||
RegisteredServer registeredServer = event.getPlayer().getCurrentServer().get().getServer();
|
||||
|
||||
ServerWrapper wrapper = serverHandler.getWrapper(registeredServer.getServerInfo().getName());
|
||||
if(wrapper != null) {
|
||||
if (wrapper != null) {
|
||||
wrapper.sendJoinLeaveMessage(event.getPlayer().getUniqueId(), Utility.parseMiniMessage(Config.SERVERLEAVEMESSAGE,
|
||||
Placeholder.unparsed("player", event.getPlayer().getUsername()),
|
||||
Placeholder.unparsed("from_server", registeredServer.getServerInfo().getName())
|
||||
));
|
||||
Placeholder.unparsed("player", event.getPlayer().getUsername()),
|
||||
Placeholder.unparsed("from_server", registeredServer.getServerInfo().getName())
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user