Skip to content

Commit

Permalink
Merge pull request #181 from Ssmidge/master
Browse files Browse the repository at this point in the history
Added custom messaging system with replies
  • Loading branch information
polypixeldev authored Sep 23, 2024
2 parents 7fe41ef + 6fc82aa commit fe5fa66
Show file tree
Hide file tree
Showing 86 changed files with 299 additions and 140 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.DS_Store

#.idea/
.idea/
.settings/
.classpath
.project
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/hackclub/hccore/HCCorePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import com.hackclub.hccore.commands.SpawnCommand;
import com.hackclub.hccore.commands.StatsCommand;
import com.hackclub.hccore.commands.WelcomeCommand;
import com.hackclub.hccore.commands.messaging.MessageCommand;
import com.hackclub.hccore.commands.messaging.ReplyCommand;
import com.hackclub.hccore.listeners.AFKListener;
import com.hackclub.hccore.listeners.BeehiveInteractionListener;
import com.hackclub.hccore.listeners.NameChangeListener;
Expand Down Expand Up @@ -94,6 +96,8 @@ public void onEnable() {
registerCommand("stats", new StatsCommand(this));
registerCommand("rules", new RulesCommand());
registerCommand("welcome", new WelcomeCommand());
registerCommand("msg", new MessageCommand(this));
registerCommand("reply", new ReplyCommand(this));

// prepare for new emotes commands:
// downvote "↓"
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/hackclub/hccore/PlayerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Level;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
Expand Down Expand Up @@ -44,6 +45,8 @@ public class PlayerData {
private TextColor messageColor = NamedTextColor.GRAY;
@Expose
private Map<String, Location> savedLocations = new LinkedHashMap<>();
@Expose
private UUID lastPlayerChattingWith = null;

public PlayerData(HCCorePlugin plugin, Player player) {
this.plugin = plugin;
Expand Down Expand Up @@ -182,6 +185,7 @@ public void load() {
this.setSlackId(data.slackId);
this.setNameColor(data.nameColor);
this.setMessageColor(data.messageColor);
this.setLastPlayerChattingWith(data.lastPlayerChattingWith);
this.savedLocations = data.savedLocations;
} catch (IOException e) {
e.printStackTrace();
Expand Down Expand Up @@ -241,4 +245,12 @@ private void refreshNameTag() {
}
}
}

public void setLastPlayerChattingWith(UUID lastPlayerChattingWith) {
this.lastPlayerChattingWith = lastPlayerChattingWith;
}

public UUID getLastPlayerChattingWith() {
return this.lastPlayerChattingWith;
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/hackclub/hccore/commands/AFKCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.hackclub.hccore.HCCorePlugin;
import com.hackclub.hccore.PlayerData;
import com.hackclub.hccore.commands.general.ArgumentlessCommand;
import com.hackclub.hccore.playerMessages.MustBePlayerMessage;
import com.hackclub.hccore.playermessages.MustBePlayerMessage;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/hackclub/hccore/commands/ColorCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import com.hackclub.hccore.HCCorePlugin;
import com.hackclub.hccore.PlayerData;
import com.hackclub.hccore.playerMessages.MustBePlayerMessage;
import com.hackclub.hccore.playerMessages.color.ColorResetMessage;
import com.hackclub.hccore.playerMessages.color.ColorSetMessage;
import com.hackclub.hccore.playerMessages.color.InvalidColorMessage;
import com.hackclub.hccore.playermessages.MustBePlayerMessage;
import com.hackclub.hccore.playermessages.color.ColorResetMessage;
import com.hackclub.hccore.playermessages.color.ColorSetMessage;
import com.hackclub.hccore.playermessages.color.InvalidColorMessage;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/com/hackclub/hccore/commands/LocCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

import com.hackclub.hccore.HCCorePlugin;
import com.hackclub.hccore.PlayerData;
import com.hackclub.hccore.playerMessages.MustBePlayerMessage;
import com.hackclub.hccore.playerMessages.NoOnlinePlayerMessage;
import com.hackclub.hccore.playerMessages.loc.HasLocationMessage;
import com.hackclub.hccore.playerMessages.loc.LocationAddMessage;
import com.hackclub.hccore.playerMessages.loc.LocationExistsMessage;
import com.hackclub.hccore.playerMessages.loc.LocationGetMessage;
import com.hackclub.hccore.playerMessages.loc.LocationListMessage;
import com.hackclub.hccore.playerMessages.loc.LocationNotFoundMessage;
import com.hackclub.hccore.playerMessages.loc.LocationRemovedMessage;
import com.hackclub.hccore.playerMessages.loc.LocationRenamedMessage;
import com.hackclub.hccore.playerMessages.loc.NoLocationsMessage;
import com.hackclub.hccore.playerMessages.loc.RecipSharedMessage;
import com.hackclub.hccore.playerMessages.loc.SelfShareMessage;
import com.hackclub.hccore.playerMessages.loc.SendSharedMessage;
import com.hackclub.hccore.playerMessages.loc.SpecifyLocationMessage;
import com.hackclub.hccore.playerMessages.loc.SpecifyShareMessage;
import com.hackclub.hccore.playermessages.MustBePlayerMessage;
import com.hackclub.hccore.playermessages.NoOnlinePlayerMessage;
import com.hackclub.hccore.playermessages.loc.HasLocationMessage;
import com.hackclub.hccore.playermessages.loc.LocationAddMessage;
import com.hackclub.hccore.playermessages.loc.LocationExistsMessage;
import com.hackclub.hccore.playermessages.loc.LocationGetMessage;
import com.hackclub.hccore.playermessages.loc.LocationListMessage;
import com.hackclub.hccore.playermessages.loc.LocationNotFoundMessage;
import com.hackclub.hccore.playermessages.loc.LocationRemovedMessage;
import com.hackclub.hccore.playermessages.loc.LocationRenamedMessage;
import com.hackclub.hccore.playermessages.loc.NoLocationsMessage;
import com.hackclub.hccore.playermessages.loc.RecipSharedMessage;
import com.hackclub.hccore.playermessages.loc.SelfShareMessage;
import com.hackclub.hccore.playermessages.loc.SendSharedMessage;
import com.hackclub.hccore.playermessages.loc.SpecifyLocationMessage;
import com.hackclub.hccore.playermessages.loc.SpecifyShareMessage;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/hackclub/hccore/commands/NickCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import com.hackclub.hccore.HCCorePlugin;
import com.hackclub.hccore.PlayerData;
import com.hackclub.hccore.playerMessages.MustBePlayerMessage;
import com.hackclub.hccore.playerMessages.nickname.NicknameLengthMessage;
import com.hackclub.hccore.playerMessages.nickname.NicknameResetMessage;
import com.hackclub.hccore.playerMessages.nickname.NicknameSetMessage;
import com.hackclub.hccore.playerMessages.nickname.SaharshMessage;
import com.hackclub.hccore.playermessages.MustBePlayerMessage;
import com.hackclub.hccore.playermessages.nickname.NicknameLengthMessage;
import com.hackclub.hccore.playermessages.nickname.NicknameResetMessage;
import com.hackclub.hccore.playermessages.nickname.NicknameSetMessage;
import com.hackclub.hccore.playermessages.nickname.SaharshMessage;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/hackclub/hccore/commands/PingCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import com.hackclub.hccore.HCCorePlugin;
import com.hackclub.hccore.PlayerData;
import com.hackclub.hccore.playerMessages.MustBePlayerMessage;
import com.hackclub.hccore.playerMessages.NoOnlinePlayerMessage;
import com.hackclub.hccore.playerMessages.ping.PingFailMessage;
import com.hackclub.hccore.playerMessages.ping.PingMessage;
import com.hackclub.hccore.playermessages.MustBePlayerMessage;
import com.hackclub.hccore.playermessages.NoOnlinePlayerMessage;
import com.hackclub.hccore.playermessages.ping.PingFailMessage;
import com.hackclub.hccore.playermessages.ping.PingMessage;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.hackclub.hccore.commands;

import com.hackclub.hccore.commands.general.ArgumentlessCommand;
import com.hackclub.hccore.playerMessages.RulesMessage;
import com.hackclub.hccore.playermessages.RulesMessage;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/com/hackclub/hccore/commands/SlackCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

import com.hackclub.hccore.HCCorePlugin;
import com.hackclub.hccore.PlayerData;
import com.hackclub.hccore.playerMessages.MustBePlayerMessage;
import com.hackclub.hccore.playerMessages.PlayerHasntPlayedMessage;
import com.hackclub.hccore.playerMessages.slack.InvalidSlackMessage;
import com.hackclub.hccore.playerMessages.slack.LinkErrorMessage;
import com.hackclub.hccore.playerMessages.slack.LinkedSlackMessage;
import com.hackclub.hccore.playerMessages.slack.LookupErrorMessage;
import com.hackclub.hccore.playerMessages.slack.PlayerNotLinkedMessage;
import com.hackclub.hccore.playerMessages.slack.SlackDisabledMessage;
import com.hackclub.hccore.playerMessages.slack.SlackUsernameMessage;
import com.hackclub.hccore.playerMessages.slack.UnlinkedSlackMessage;
import com.hackclub.hccore.playerMessages.slack.VerificationErrorMessage;
import com.hackclub.hccore.playerMessages.slack.VerificationSentMessage;
import com.hackclub.hccore.playermessages.MustBePlayerMessage;
import com.hackclub.hccore.playermessages.PlayerHasntPlayedMessage;
import com.hackclub.hccore.playermessages.slack.InvalidSlackMessage;
import com.hackclub.hccore.playermessages.slack.LinkErrorMessage;
import com.hackclub.hccore.playermessages.slack.LinkedSlackMessage;
import com.hackclub.hccore.playermessages.slack.LookupErrorMessage;
import com.hackclub.hccore.playermessages.slack.PlayerNotLinkedMessage;
import com.hackclub.hccore.playermessages.slack.SlackDisabledMessage;
import com.hackclub.hccore.playermessages.slack.SlackUsernameMessage;
import com.hackclub.hccore.playermessages.slack.UnlinkedSlackMessage;
import com.hackclub.hccore.playermessages.slack.VerificationErrorMessage;
import com.hackclub.hccore.playermessages.slack.VerificationSentMessage;
import com.slack.api.model.User;
import java.io.IOException;
import java.util.ArrayList;
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/hackclub/hccore/commands/SpawnCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import com.hackclub.hccore.HCCorePlugin;
import com.hackclub.hccore.PlayerData;
import com.hackclub.hccore.commands.general.ArgumentlessCommand;
import com.hackclub.hccore.playerMessages.MustBePlayerMessage;
import com.hackclub.hccore.playerMessages.spawn.OverworldCommandMessage;
import com.hackclub.hccore.playerMessages.spawn.SpawnGroundMessage;
import com.hackclub.hccore.playerMessages.spawn.SpawnHurtMessage;
import com.hackclub.hccore.playerMessages.spawn.SpawnRadiusMessage;
import com.hackclub.hccore.playerMessages.spawn.SpawnSkyMessage;
import com.hackclub.hccore.playerMessages.spawn.SpawnTeleportMessage;
import com.hackclub.hccore.playermessages.MustBePlayerMessage;
import com.hackclub.hccore.playermessages.spawn.OverworldCommandMessage;
import com.hackclub.hccore.playermessages.spawn.SpawnGroundMessage;
import com.hackclub.hccore.playermessages.spawn.SpawnHurtMessage;
import com.hackclub.hccore.playermessages.spawn.SpawnRadiusMessage;
import com.hackclub.hccore.playermessages.spawn.SpawnSkyMessage;
import com.hackclub.hccore.playermessages.spawn.SpawnTeleportMessage;
import org.bukkit.GameMode;
import org.bukkit.World.Environment;
import org.bukkit.block.Block;
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/hackclub/hccore/commands/StatsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import com.hackclub.hccore.HCCorePlugin;
import com.hackclub.hccore.PlayerData;
import com.hackclub.hccore.playerMessages.MustBePlayerMessage;
import com.hackclub.hccore.playerMessages.NoOnlinePlayerMessage;
import com.hackclub.hccore.playerMessages.stats.IncludePlayerStatMessage;
import com.hackclub.hccore.playerMessages.stats.InvalidStatMessage;
import com.hackclub.hccore.playerMessages.stats.SpecificStatMessage;
import com.hackclub.hccore.playerMessages.stats.StatMessage;
import com.hackclub.hccore.playerMessages.stats.UnsupportedStatMessage;
import com.hackclub.hccore.playerMessages.stats.YourStatsMessage;
import com.hackclub.hccore.playermessages.MustBePlayerMessage;
import com.hackclub.hccore.playermessages.NoOnlinePlayerMessage;
import com.hackclub.hccore.playermessages.stats.IncludePlayerStatMessage;
import com.hackclub.hccore.playermessages.stats.InvalidStatMessage;
import com.hackclub.hccore.playermessages.stats.SpecificStatMessage;
import com.hackclub.hccore.playermessages.stats.StatMessage;
import com.hackclub.hccore.playermessages.stats.UnsupportedStatMessage;
import com.hackclub.hccore.playermessages.stats.YourStatsMessage;
import com.hackclub.hccore.utils.TimeUtil;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.hackclub.hccore.commands;

import com.hackclub.hccore.commands.general.ArgumentlessCommand;
import com.hackclub.hccore.playerMessages.WelcomeMessage;
import com.hackclub.hccore.playermessages.WelcomeMessage;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.hackclub.hccore.commands.messaging;

import com.hackclub.hccore.HCCorePlugin;
import com.hackclub.hccore.playermessages.MustBePlayerMessage;
import com.hackclub.hccore.playermessages.NoOnlinePlayerMessage;
import com.hackclub.hccore.playermessages.messages.PrivateMessage;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

public class MessageCommand implements CommandExecutor {

private HCCorePlugin plugin;

public MessageCommand(HCCorePlugin plugin) {
this.plugin = plugin;
}

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length < 2) return false;

//TODO: Allow console to send messages as "Console" in red.
if (!(sender instanceof Player sendingPlayer)) {
sender.sendMessage(MustBePlayerMessage.get());
return true;
}

final Player recipientPlayer = sender.getServer().getPlayerExact(args[0]);

if (recipientPlayer == null) {
sender.sendMessage(NoOnlinePlayerMessage.get());
return true;
}

final Component senderMessage = PrivateMessage.get("You", recipientPlayer.getName(), String.join(" ", args).substring(args[0].length() + 1), null, this.plugin.getDataManager().getData(recipientPlayer).getNameColor());
final Component receiverMessage = PrivateMessage.get(sendingPlayer.getName(), "You", String.join(" ", args).substring(args[0].length() + 1), this.plugin.getDataManager().getData(sendingPlayer).getNameColor(), null);

this.plugin.getDataManager().getData(recipientPlayer).setLastPlayerChattingWith(sendingPlayer.getUniqueId());
this.plugin.getDataManager().getData(sendingPlayer).setLastPlayerChattingWith(recipientPlayer.getUniqueId());

recipientPlayer.sendMessage(receiverMessage);
sendingPlayer.sendMessage(senderMessage);

return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.hackclub.hccore.commands.messaging;

import com.comphenix.protocol.PacketType.Play;
import com.hackclub.hccore.HCCorePlugin;
import com.hackclub.hccore.playermessages.MustBePlayerMessage;
import com.hackclub.hccore.playermessages.NoOnlinePlayerMessage;
import com.hackclub.hccore.playermessages.messages.PrivateMessage;
import java.util.Arrays;
import net.kyori.adventure.text.Component;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

public class ReplyCommand implements CommandExecutor {

private HCCorePlugin plugin;

public ReplyCommand(HCCorePlugin plugin) {
this.plugin = plugin;
}

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length < 1) return false;

if (!(sender instanceof Player sendingPlayer)) {
sender.sendMessage(MustBePlayerMessage.get());
return true;
}

Player recipientPlayer;
try {
recipientPlayer = sender.getServer().getPlayer(this.plugin.getDataManager().getData(sendingPlayer).getLastPlayerChattingWith());
} catch (Exception e) {
sender.sendMessage(NoOnlinePlayerMessage.get());
return true;
}

if (recipientPlayer == null) {
sender.sendMessage(NoOnlinePlayerMessage.get());
return true;
}

final Component senderMessage = PrivateMessage.get("You", recipientPlayer.getName(), String.join(" ", args), null, this.plugin.getDataManager().getData(recipientPlayer).getNameColor());
final Component receiverMessage = PrivateMessage.get(sendingPlayer.getName(), "You", String.join(" ", args), this.plugin.getDataManager().getData(sendingPlayer).getNameColor(), null);

this.plugin.getDataManager().getData(recipientPlayer).setLastPlayerChattingWith(sendingPlayer.getUniqueId());
this.plugin.getDataManager().getData(sendingPlayer).setLastPlayerChattingWith(recipientPlayer.getUniqueId());

recipientPlayer.sendMessage(receiverMessage);
sendingPlayer.sendMessage(senderMessage);

return true;
}
}
8 changes: 4 additions & 4 deletions src/main/java/com/hackclub/hccore/listeners/AFKListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import com.hackclub.hccore.HCCorePlugin;
import com.hackclub.hccore.PlayerData;
import com.hackclub.hccore.events.player.PlayerAFKStatusChangeEvent;
import com.hackclub.hccore.playerMessages.afk.IsAFKMessage;
import com.hackclub.hccore.playerMessages.afk.NotAFKMessage;
import com.hackclub.hccore.playerMessages.afk.RunAFKMessage;
import com.hackclub.hccore.playerMessages.afk.YouAFKMessage;
import com.hackclub.hccore.playermessages.afk.IsAFKMessage;
import com.hackclub.hccore.playermessages.afk.NotAFKMessage;
import com.hackclub.hccore.playermessages.afk.RunAFKMessage;
import com.hackclub.hccore.playermessages.afk.YouAFKMessage;
import io.papermc.paper.event.player.AsyncChatEvent;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/hackclub/hccore/listeners/PlayerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

import com.hackclub.hccore.HCCorePlugin;
import com.hackclub.hccore.PlayerData;
import com.hackclub.hccore.playerMessages.WelcomeMessage;
import com.hackclub.hccore.playerMessages.player.BanMessage;
import com.hackclub.hccore.playerMessages.player.ChatMessage;
import com.hackclub.hccore.playerMessages.player.JoinMessage;
import com.hackclub.hccore.playerMessages.player.LeaveMessage;
import com.hackclub.hccore.playerMessages.player.MustLinkMessage;
import com.hackclub.hccore.playerMessages.player.ServerFullMessage;
import com.hackclub.hccore.playermessages.WelcomeMessage;
import com.hackclub.hccore.playermessages.player.BanMessage;
import com.hackclub.hccore.playermessages.player.ChatMessage;
import com.hackclub.hccore.playermessages.player.JoinMessage;
import com.hackclub.hccore.playermessages.player.LeaveMessage;
import com.hackclub.hccore.playermessages.player.MustLinkMessage;
import com.hackclub.hccore.playermessages.player.ServerFullMessage;
import java.util.UUID;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor;
Expand Down
Loading

0 comments on commit fe5fa66

Please sign in to comment.