-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #181 from Ssmidge/master
Added custom messaging system with replies
- Loading branch information
Showing
86 changed files
with
299 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
.DS_Store | ||
|
||
#.idea/ | ||
.idea/ | ||
.settings/ | ||
.classpath | ||
.project | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/com/hackclub/hccore/commands/messaging/MessageCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/main/java/com/hackclub/hccore/commands/messaging/ReplyCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.