auto commit
This commit is contained in:
parent
04ac327365
commit
0891e252f9
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -39,3 +39,4 @@ target/
|
|||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
/upload.sh
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ public final class Config {
|
|||
|
||||
public static File CONFIGPATH;
|
||||
public static void init() { // todo setup share for the config
|
||||
CONFIGPATH = new File(System.getProperty("user.home")+File.separator+"ChatPlugin");
|
||||
CONFIGPATH = new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "ChatPlugin");
|
||||
CONFIG_FILE = new File(CONFIGPATH, "config.yml");;
|
||||
configLoader = YAMLConfigurationLoader.builder()
|
||||
.setFile(CONFIG_FILE)
|
||||
|
|
@ -175,8 +175,8 @@ public final class Config {
|
|||
|
||||
public static List<String> MESSAGECOMMANDALIASES = new ArrayList<>();
|
||||
public static List<String> REPLYCOMMANDALIASES = new ArrayList<>();
|
||||
public static String MESSAGESENDER = "<hover:show_text:Click to reply><click:suggest_command:/msg <receiver> ><light_purple>(Me -> <gray><receiver></gray>) <message>";
|
||||
public static String MESSAGERECIEVER = "<hover:show_text:Click to reply><click:suggest_command:/msg <sender> ><light_purple>(<gray><sender></gray> on <server> -> Me) <message>";
|
||||
public static String MESSAGESENDER = "<hover:show_text:Click to reply><click:suggest_command:/msg <receivername> ><light_purple>(Me -> <gray><receiver></gray>)</hover> <message>";
|
||||
public static String MESSAGERECIEVER = "<hover:show_text:Click to reply><click:suggest_command:/msg <sendername> ><light_purple>(<gray><sender></gray> on <server> -> Me)</hover> <message>";
|
||||
private static void messageCommand() {
|
||||
MESSAGECOMMANDALIASES.clear();
|
||||
REPLYCOMMANDALIASES.clear();
|
||||
|
|
@ -185,7 +185,7 @@ public final class Config {
|
|||
MESSAGESENDER = getString("commands.message.sender-message", MESSAGESENDER);
|
||||
MESSAGERECIEVER = getString("commands.message.reciever-message", MESSAGERECIEVER);
|
||||
}
|
||||
///broadcast <white><light_purple><prefix></light_purple> <gray>Momlly</gray> <hover:show_text:on Atoll><yellow>to Global</yellow></hover><gray>: We Love <gold>Teri</gold> and <light_purple>Kappa</light_purple></gray></white>
|
||||
|
||||
public static String GCFORMAT = "<white><light_purple><prefix></light_purple> <gray><sender></gray> <hover:show_text:on <server>><yellow>to Global</yellow></hover><gray>: <message>";
|
||||
public static String GCPERMISSION = "proxy.globalchat";
|
||||
public static List<String> GCALIAS = new ArrayList<>();
|
||||
|
|
@ -193,7 +193,7 @@ public final class Config {
|
|||
public static String GCONCOOLDOWN = "You have to wait <cooldown> seconds before using this feature again."; // todo mini message formatting
|
||||
public static int GCCOOLDOWN = 30;
|
||||
private static void globalChat() {
|
||||
MESSAGERECIEVER = getString("commands.globalchat.format", MESSAGERECIEVER);
|
||||
GCFORMAT = getString("commands.globalchat.format", GCFORMAT);
|
||||
GCPERMISSION = getString("commands.globalchat.view-chat-permission", GCPERMISSION);
|
||||
GCALIAS.clear();
|
||||
GCALIAS = getList("commands.globalchat.alias", Lists.newArrayList("gc", "global"));
|
||||
|
|
@ -202,13 +202,13 @@ public final class Config {
|
|||
}
|
||||
|
||||
// TODO prefixes need hovers, this hasn't been setup yet!
|
||||
public static String CHATFORMAT = "<white><light_purple><prefixall> <gray><sender>: <message>";
|
||||
public static String CHATFORMAT = "<white><light_purple><prefixall> <gray><sender>: <white><message>";
|
||||
private static void Chat() {
|
||||
CHATFORMAT = getString("chat.format", CHATFORMAT);
|
||||
}
|
||||
|
||||
public static List<String> GACECOMMANDALIASES = new ArrayList<>();
|
||||
public static String GACFORMAT = "<hover:show_text:Click to reply><click:suggest_command:/acg ><yellow>(<sender> on <server> -> Team) <message>";
|
||||
public static String GACFORMAT = "<hover:show_text:Click to reply><click:suggest_command:/acg ><yellow>(<sender> on <server> -> Team)</hover> <message>";
|
||||
private static void globalAdminChat() {
|
||||
GACECOMMANDALIASES = getList("commands.globaladminchat.aliases", Lists.newArrayList("acg"));
|
||||
GACFORMAT = getString("commands.globaladminchat.format", GACFORMAT);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.alttd.chat.database;
|
|||
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.objects.Mail;
|
||||
import com.alttd.chat.objects.Party;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
|
@ -19,6 +20,7 @@ public class Queries {
|
|||
tables.add("CREATE TABLE IF NOT EXISTS ignored_users (`uuid` VARCHAR(36) NOT NULL, `ignored_uuid` VARCHAR(36) NOT NULL, PRIMARY KEY (`uuid`, `ignored_uuid`))");
|
||||
tables.add("CREATE TABLE IF NOT EXISTS parties (`id` INT NOT NULL AUTO_INCREMENT, `owner_uuid` VARCHAR(36) NOT NULL, `party_name` VARCHAR(36) NOT NULL, `password` VARCHAR(36), PRIMARY KEY (`id`))");
|
||||
tables.add("CREATE TABLE IF NOT EXISTS chat_users (`uuid` VARCHAR(36) NOT NULL, `party_id` INT NOT NULL, `toggled_chat` BIT(1) DEFAULT b'0', `toggled_gc` BIT(1) DEFAULT b'0', PRIMARY KEY (`uuid`))");
|
||||
tables.add("CREATE TABLE IF NOT EXISTS mails (`id` INT NOT NULL AUTO_INCREMENT, `uuid` VARCHAR(36) NOT NULL, `from` VARCHAR(36) NOT NULL, `message` VARCHAR(256) NOT NULL, `sendtime` BIGINT default 0, `readtime` BIGINT default 0, PRIMARY KEY (`id`))");
|
||||
|
||||
try {
|
||||
Connection connection = DatabaseConnection.getConnection();
|
||||
|
|
@ -295,8 +297,7 @@ public class Queries {
|
|||
int partyId = resultSet.getInt("party_id");
|
||||
boolean toggled_chat = resultSet.getInt("toggled_chat") == 1;
|
||||
boolean toggle_Gc = resultSet.getInt("toggled_gc") == 1;
|
||||
// could do a constructor for chatuser to accept the record?
|
||||
//ChatUserManager.addUser(new ChatUser(uuid, partyId, toggled_chat, toggle_Gc));
|
||||
ChatUserManager.addUser(new ChatUser(uuid, partyId, toggled_chat, toggle_Gc));
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
|
|
@ -304,6 +305,31 @@ public class Queries {
|
|||
}
|
||||
}
|
||||
|
||||
public static ChatUser loadChatUser(UUID uuid) { //TODO Get parties from cache somewhere
|
||||
String query = "SELECT * FROM chat_users WHERE uuid = ?";
|
||||
ChatUser user = null;
|
||||
try {
|
||||
Connection connection = DatabaseConnection.getConnection();
|
||||
|
||||
PreparedStatement statement = connection.prepareStatement(query);
|
||||
|
||||
statement.setString(1, uuid.toString());
|
||||
|
||||
ResultSet resultSet = statement.executeQuery();
|
||||
|
||||
while (resultSet.next()) {
|
||||
int partyId = resultSet.getInt("party_id");
|
||||
boolean toggled_chat = resultSet.getInt("toggled_chat") == 1;
|
||||
boolean toggle_Gc = resultSet.getInt("toggled_gc") == 1;
|
||||
user = new ChatUser(uuid, partyId, toggled_chat, toggle_Gc);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
public static void addUser(ChatUser user) {
|
||||
String query = "INSERT INTO chat_users (uuid, party_id, toggled_chat, toggled_gc) VALUES (?, ?, ?, ?)";
|
||||
|
||||
|
|
@ -326,6 +352,10 @@ public class Queries {
|
|||
setBitWhereId("UPDATE chat_users set toggled_chat = ? WHERE uuid = ?", toggledChat, uuid);
|
||||
}
|
||||
|
||||
public static void setGlobalChatState(boolean globalChat, UUID uuid) {
|
||||
setBitWhereId("UPDATE chat_users set toggled_gc = ? WHERE uuid = ?", globalChat, uuid);
|
||||
}
|
||||
|
||||
private static void setBitWhereId(String query, boolean bool, UUID uuid) {
|
||||
try {
|
||||
Connection connection = DatabaseConnection.getConnection();
|
||||
|
|
@ -356,4 +386,48 @@ public class Queries {
|
|||
}
|
||||
|
||||
//-----------------------------------------
|
||||
|
||||
public static LinkedList<Mail> getMails(UUID uuid) {
|
||||
LinkedList<Mail> mails = new LinkedList<>();
|
||||
String query = "SELECT * FROM mails where uuid = ?";
|
||||
|
||||
try {
|
||||
Connection connection = DatabaseConnection.getConnection();
|
||||
|
||||
PreparedStatement statement = connection.prepareStatement(query);
|
||||
|
||||
statement.setString(1, uuid.toString());
|
||||
|
||||
ResultSet resultSet = statement.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
UUID fromUUID = UUID.fromString(resultSet.getString("from"));
|
||||
String message = resultSet.getString("message");
|
||||
long sendTime = resultSet.getLong("sendtime");
|
||||
long readTime = resultSet.getLong("readtime");
|
||||
mails.add(new Mail(uuid, fromUUID, sendTime, readTime, message));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return mails;
|
||||
}
|
||||
|
||||
public static void saveUser(ChatUser user) {
|
||||
String query = "INSERT INTO chat_users (uuid, party_id, toggled_chat, toggled_gc) VALUES (?, ?, ?, ?)";
|
||||
|
||||
try {
|
||||
Connection connection = DatabaseConnection.getConnection();
|
||||
PreparedStatement statement = connection.prepareStatement(query);
|
||||
|
||||
statement.setString(1, user.getUuid().toString());
|
||||
statement.setInt(2, user.getPartyId());
|
||||
statement.setInt(3, user.toggledPartyChat() ? 1 : 0);
|
||||
statement.setInt(4, user.isGcOn() ? 1 : 0);
|
||||
|
||||
statement.execute();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.alttd.chat.managers;
|
||||
|
||||
import com.alttd.chat.database.Queries;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.objects.Mail;
|
||||
|
||||
|
|
@ -14,12 +15,14 @@ public final class ChatUserManager {
|
|||
|
||||
public static void initialize() {
|
||||
chatUsers = new ArrayList<>();
|
||||
//Queries.loadChatUsers(); // todo fix sql
|
||||
}
|
||||
|
||||
public static void addUser(ChatUser user) {
|
||||
if(getChatUser(user.getUuid()) == null)
|
||||
chatUsers.add(user);
|
||||
chatUsers.add(user);
|
||||
}
|
||||
|
||||
public static void removeUser(ChatUser user) {
|
||||
chatUsers.remove(user);
|
||||
}
|
||||
|
||||
public static ChatUser getChatUser(UUID uuid) {
|
||||
|
|
@ -28,9 +31,11 @@ public final class ChatUserManager {
|
|||
return user;
|
||||
}
|
||||
}
|
||||
ChatUser user = new ChatUser(uuid, -1, false, false);
|
||||
ChatUser user = Queries.loadChatUser(uuid);
|
||||
if(user == null) user = new ChatUser(uuid, -1, false, false);
|
||||
Queries.saveUser(user);
|
||||
chatUsers.add(user);
|
||||
return user; // create a new user?
|
||||
return user;
|
||||
}
|
||||
|
||||
public List<Mail> getUnReadMail(ChatUser user) {
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ public class ChatUser {
|
|||
private boolean toggledPartyChat; // should chat messages instantly go to party chat when added, idk if this should be saved
|
||||
private String name; // the nickname, doesn't need to be saved with the chatuser object, could be saved but we can get it from the nicknamesview
|
||||
private Component displayName; // the nickname, doesn't need to be saved with the chatuser object, could be saved but we can get it from the nicknamesview
|
||||
private Component prefix; // doesn't need saving, we get this from luckperms
|
||||
private Component staffPrefix; // doesn't need saving, we get this from luckperms
|
||||
private Component prefixAll; // doesn't need saving, we get this from luckperms
|
||||
// private Component prefix; // doesn't need saving, we get this from luckperms
|
||||
// private Component staffPrefix; // doesn't need saving, we get this from luckperms
|
||||
// private Component prefixAll; // doesn't need saving, we get this from luckperms
|
||||
private boolean toggleGc; // should be saved, this toggles if the player can see and use global chat
|
||||
private String replyTarget; // reply target for use in /msg i don't mind setting this to null on login, feedback?
|
||||
private long gcCooldown; // the time when they last used gc, is used for the cooldown, i wouldn't save this, but setting this to the login time means they can't use gc for 30 seconds after logging in
|
||||
|
|
@ -35,15 +35,15 @@ public class ChatUser {
|
|||
}
|
||||
setDisplayName(name);
|
||||
|
||||
prefix = Utility.getPrefix(uuid, true);
|
||||
staffPrefix = Utility.getStaffPrefix(uuid);
|
||||
|
||||
prefixAll = Utility.getPrefix(uuid, false);
|
||||
// prefix = Utility.getPrefix(uuid, true); // TODO we need to update this, so cache and update when needed or always request it?
|
||||
// staffPrefix = Utility.getStaffPrefix(uuid);
|
||||
//
|
||||
// prefixAll = Utility.getPrefix(uuid, false);
|
||||
|
||||
this.toggleGc = toggleGc;
|
||||
replyTarget = null;
|
||||
gcCooldown = System.currentTimeMillis(); // players can't use gc for 30 seconds after logging in if we use this?
|
||||
mails = new LinkedList<>(); // todo load mails
|
||||
mails = Queries.getMails(uuid);
|
||||
ignoredPlayers = Queries.getIgnoredUsers(uuid);
|
||||
ignoredBy = new LinkedList<>(); // todo load ignoredPlayers
|
||||
}
|
||||
|
|
@ -74,15 +74,18 @@ public class ChatUser {
|
|||
}
|
||||
|
||||
public Component getPrefix() {
|
||||
return prefix;
|
||||
//return prefix;
|
||||
return Utility.getPrefix(uuid, true); // No longer cache this data
|
||||
}
|
||||
|
||||
public Component getStaffPrefix() {
|
||||
return staffPrefix;
|
||||
//return staffPrefix;
|
||||
return Utility.getStaffPrefix(uuid);
|
||||
}
|
||||
|
||||
public Component getPrefixAll() {
|
||||
return prefixAll;
|
||||
//return prefixAll;
|
||||
return Utility.getPrefix(uuid, false);
|
||||
}
|
||||
|
||||
public void toggleGc() {
|
||||
|
|
@ -117,6 +120,10 @@ public class ChatUser {
|
|||
ignoredPlayers.add(uuid);
|
||||
}
|
||||
|
||||
public void removeIgnoredPlayers(UUID uuid) {
|
||||
ignoredPlayers.remove(uuid);
|
||||
}
|
||||
|
||||
public LinkedList<UUID> getIgnoredBy() {
|
||||
return ignoredBy;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,20 +6,26 @@ public class Mail {
|
|||
|
||||
private final UUID uuid; // the player
|
||||
private final UUID sender; // the sender
|
||||
private boolean read;
|
||||
private final long sendTime; // any other option for this? does the db store recordcreation and edit time?
|
||||
private long readTime; // any other option for this?
|
||||
private final String message; // do we want staff to edit this after being send but being unread?
|
||||
|
||||
public Mail(UUID player, UUID sender, Boolean read, long sendTime, long readTime, String message) {
|
||||
public Mail(UUID player, UUID sender, long sendTime, long readTime, String message) {
|
||||
this.uuid = player;
|
||||
this.sender = sender;
|
||||
this.read = read;
|
||||
this.sendTime = sendTime;
|
||||
this.readTime = readTime;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public Mail(UUID player, UUID sender, String message) {
|
||||
this.uuid = player;
|
||||
this.sender = sender;
|
||||
this.sendTime = System.nanoTime();
|
||||
this.readTime = System.nanoTime();
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
|
@ -29,11 +35,7 @@ public class Mail {
|
|||
}
|
||||
|
||||
public boolean isUnRead() {
|
||||
return read;
|
||||
}
|
||||
|
||||
public void setRead(boolean read) {
|
||||
this.read = read;
|
||||
return getSendTime() != getReadTime();
|
||||
}
|
||||
|
||||
public long getSendTime() {
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ public class Utility {
|
|||
prefix.append(user.getCachedData().getMetaData().getPrefix());
|
||||
}
|
||||
|
||||
return LegacyComponentSerializer.builder().character('&').hexColors().build().deserialize(prefix.toString());
|
||||
return applyColor(prefix.toString());
|
||||
}
|
||||
|
||||
public static Component getStaffPrefix(UUID uuid) {
|
||||
|
|
@ -85,7 +85,7 @@ public class Utility {
|
|||
if(group != null)
|
||||
prefix.append(group.getCachedData().getMetaData().getPrefix());
|
||||
}
|
||||
return LegacyComponentSerializer.builder().character('&').hexColors().build().deserialize(prefix.toString());
|
||||
return applyColor(prefix.toString());
|
||||
}
|
||||
|
||||
public static String getDisplayName(UUID uuid) {
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@
|
|||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>15</source>
|
||||
<target>15</target>
|
||||
<source>16</source>
|
||||
<target>16</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@
|
|||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>15</source>
|
||||
<target>15</target>
|
||||
<source>16</source>
|
||||
<target>16</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
package com.alttd.chat;
|
||||
|
||||
import com.alttd.chat.commands.GlobalChat;
|
||||
import com.alttd.chat.commands.Message;
|
||||
import com.alttd.chat.commands.Reply;
|
||||
import com.alttd.chat.commands.ToggleGlobalChat;
|
||||
import com.alttd.chat.commands.*;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.database.DatabaseConnection;
|
||||
import com.alttd.chat.handler.ChatHandler;
|
||||
|
|
@ -36,6 +33,8 @@ public class ChatPlugin extends JavaPlugin {
|
|||
registerCommand("toggleglobalchat", new ToggleGlobalChat());
|
||||
registerCommand("message", new Message());
|
||||
registerCommand("reply", new Reply());
|
||||
registerCommand("ignore", new Ignore());
|
||||
registerCommand("unignore", new Unignore());
|
||||
|
||||
messageChannel = Config.MESSAGECHANNEL;
|
||||
getServer().getMessenger().registerOutgoingPluginChannel(this, messageChannel);
|
||||
|
|
|
|||
51
galaxy/src/main/java/com/alttd/chat/commands/Ignore.java
Executable file
51
galaxy/src/main/java/com/alttd/chat/commands/Ignore.java
Executable file
|
|
@ -0,0 +1,51 @@
|
|||
package com.alttd.chat.commands;
|
||||
|
||||
import com.alttd.chat.ChatPlugin;
|
||||
import com.alttd.chat.database.Queries;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class Ignore implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player)) { // must be a player
|
||||
return true;
|
||||
}
|
||||
if(args.length > 1) return false; // todo error message or command info
|
||||
String targetName = args[0];
|
||||
Player targetPlayer = Bukkit.getPlayer(targetName);
|
||||
if(targetPlayer == null) { // can't ignore offline players
|
||||
//sender.sendMessage("Target not found..."); // TODO load from config and minimessage
|
||||
return false;
|
||||
}
|
||||
if(targetPlayer.hasPermission("chat.ignorebypass")) {
|
||||
sender.sendMessage("You can't ignore this player"); // TODO load from config and minimessage
|
||||
return false;
|
||||
}
|
||||
UUID target = targetPlayer.getUniqueId();
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(((Player) sender).getUniqueId());
|
||||
if(!chatUser.getIgnoredPlayers().contains(target)) {
|
||||
chatUser.addIgnoredPlayers(target);
|
||||
Queries.ignoreUser(((Player) sender).getUniqueId(), target);
|
||||
sender.sendMessage("You have turned ignored " + targetName + "."); // TODO load from config and minimessage
|
||||
} else {
|
||||
sender.sendMessage("You have already ignored " + targetName + "."); // TODO load from config and minimessage
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
25
galaxy/src/main/java/com/alttd/chat/commands/Mail.java
Normal file
25
galaxy/src/main/java/com/alttd/chat/commands/Mail.java
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package com.alttd.chat.commands;
|
||||
|
||||
import com.alttd.chat.ChatPlugin;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Mail implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player)) { // must be a player, @teri should console be able to /msg?
|
||||
return true;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
if(args.length > 2) return false; // todo error message or command info
|
||||
|
||||
String message = StringUtils.join(args, " ", 1, args.length);
|
||||
ChatPlugin.getInstance().getChatHandler().privateMessage(player, args[0], message);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -11,11 +11,11 @@ public class Message implements CommandExecutor {
|
|||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player)) { // must be a player, @teri should console be able to /msg?
|
||||
if(!(sender instanceof Player)) {
|
||||
return true;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
if(args.length > 2) return false; // todo error message or command info
|
||||
if(args.length < 2) return false; // todo error message or command info
|
||||
|
||||
String message = StringUtils.join(args, " ", 1, args.length);
|
||||
ChatPlugin.getInstance().getChatHandler().privateMessage(player, args[0], message);
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public class Reply implements CommandExecutor {
|
|||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player)) { // must be a player, @teri should console be able to /msg?
|
||||
if(!(sender instanceof Player)) {
|
||||
return true;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
package com.alttd.chat.commands;
|
||||
|
||||
import com.alttd.chat.ChatPlugin;
|
||||
import com.alttd.chat.database.Queries;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
|
|
@ -24,9 +26,10 @@ public class ToggleGlobalChat implements CommandExecutor {
|
|||
public void run() {
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(((Player) sender).getUniqueId());
|
||||
chatUser.toggleGc();
|
||||
sender.sendMessage("You have turned globalchat " + (chatUser.isGcOn() ? "<green>on." : "<red>off.")); // TODO load from config and minimessage
|
||||
Queries.setGlobalChatState(chatUser.isGcOn(), chatUser.getUuid());
|
||||
sender.sendMessage(MiniMessage.get().parse("You have turned globalchat " + (chatUser.isGcOn() ? "<green>on." : "<red>off."))); // TODO load from config and minimessage
|
||||
}
|
||||
}.runTask(ChatPlugin.getInstance());
|
||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
46
galaxy/src/main/java/com/alttd/chat/commands/Unignore.java
Executable file
46
galaxy/src/main/java/com/alttd/chat/commands/Unignore.java
Executable file
|
|
@ -0,0 +1,46 @@
|
|||
package com.alttd.chat.commands;
|
||||
|
||||
import com.alttd.chat.ChatPlugin;
|
||||
import com.alttd.chat.database.Queries;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class Unignore implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player)) { // must be a player
|
||||
return true;
|
||||
}
|
||||
if(args.length > 1) return false; // todo error message or command info
|
||||
String targetName = args[0];
|
||||
UUID target = Bukkit.getOfflinePlayer(targetName).getUniqueId();
|
||||
if(target == null) {
|
||||
//sender.sendMessage("Target not found..."); // TODO load from config and minimessage
|
||||
return false;
|
||||
}
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(((Player) sender).getUniqueId());
|
||||
if(chatUser.getIgnoredPlayers().contains(target)) {
|
||||
chatUser.removeIgnoredPlayers(target);
|
||||
Queries.ignoreUser(((Player) sender).getUniqueId(), target);
|
||||
sender.sendMessage("You no longer ignore " + targetName + "."); // TODO load from config and minimessage
|
||||
} else {
|
||||
sender.sendMessage("You don't have " + targetName + " ignored."); // TODO load from config and minimessage
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@ import com.alttd.chat.util.Utility;
|
|||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
|
|
@ -49,7 +50,7 @@ public class ChatHandler {
|
|||
|
||||
List<Template> templates = new ArrayList<>(List.of(
|
||||
Template.of("message", message),
|
||||
Template.of("[i]", itemComponent(player.getInventory().getItemInMainHand())))); // yes cross server [i];)
|
||||
Template.of("[i]", itemComponent(player.getInventory().getItemInMainHand()))));
|
||||
|
||||
Component component = miniMessage.parse("<message>", templates);
|
||||
|
||||
|
|
@ -65,7 +66,7 @@ public class ChatHandler {
|
|||
}
|
||||
long timeLeft = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - user.getGcCooldown());
|
||||
if(timeLeft <= Config.GCCOOLDOWN) { // player is on cooldown and should wait x seconds
|
||||
player.sendMessage(miniMessage.parse(Config.GCONCOOLDOWN, Template.of("cooldown", timeLeft+"")));
|
||||
player.sendMessage(miniMessage.parse(Config.GCONCOOLDOWN, Template.of("cooldown", Config.GCCOOLDOWN-timeLeft+"")));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -90,7 +91,7 @@ public class ChatHandler {
|
|||
Template.of("[i]", itemComponent(player.getInventory().getItemInMainHand()))));
|
||||
|
||||
Component component = miniMessage.parse(Config.GCFORMAT, templates);
|
||||
|
||||
user.setGcCooldown(System.currentTimeMillis());
|
||||
sendPluginMessage(player, "globalchat", component);
|
||||
}
|
||||
|
||||
|
|
@ -112,15 +113,16 @@ public class ChatHandler {
|
|||
|
||||
// Start - move these to util
|
||||
public static Component itemComponent(ItemStack item) {
|
||||
Component component = Component.text("[i]");
|
||||
if(item.getType().equals(Material.AIR)) // do we want to show the <players hand>?
|
||||
return component;
|
||||
Component component = Component.text("[i]", NamedTextColor.AQUA);
|
||||
if(item.getType().equals(Material.AIR))
|
||||
return component.color(NamedTextColor.WHITE);
|
||||
boolean dname = item.hasItemMeta() && item.getItemMeta().hasDisplayName();
|
||||
if(dname) {
|
||||
component = component.append(item.getItemMeta().displayName());
|
||||
} else {
|
||||
component = Component.text(materialToName(item.getType()));
|
||||
component = component.append(Component.text(materialToName(item.getType()), NamedTextColor.WHITE));
|
||||
}
|
||||
component = component.append(Component.text(" x" + item.getAmount(), NamedTextColor.AQUA));
|
||||
component = component.hoverEvent(item.asHoverEvent());
|
||||
return component;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.alttd.chat.listeners;
|
||||
|
||||
import com.alttd.chat.database.Queries;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.managers.RegexManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
|
|
@ -9,6 +10,7 @@ import org.bukkit.event.EventHandler;
|
|||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
|
@ -23,9 +25,16 @@ public class PlayerListener implements Listener {
|
|||
|
||||
// todo actually load the users from db
|
||||
ChatUserManager.addUser(new ChatUser(uuid, -1, false, false));
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
private void onPlayerLogout(PlayerQuitEvent event) {
|
||||
UUID uuid = event.getPlayer().getUniqueId();
|
||||
ChatUser user = ChatUserManager.getChatUser(uuid);
|
||||
ChatUserManager.removeUser(user);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(ignoreCancelled = true) // untested
|
||||
public void onSignChangeE(SignChangeEvent event) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,19 @@
|
|||
package com.alttd.chat.listeners;
|
||||
|
||||
import com.alttd.chat.ChatPlugin;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class PluginMessage implements PluginMessageListener {
|
||||
|
||||
@Override
|
||||
|
|
@ -16,6 +24,16 @@ public class PluginMessage implements PluginMessageListener {
|
|||
ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
|
||||
String subChannel = in.readUTF();
|
||||
switch (subChannel) {
|
||||
case "privatemessage":
|
||||
UUID uuid = UUID.fromString(in.readUTF());
|
||||
String target = in.readUTF();
|
||||
Player p = Bukkit.getPlayer(uuid);
|
||||
if(p != null) {
|
||||
ChatUser user = ChatUserManager.getChatUser(uuid);
|
||||
user.setReplyTarget(target);
|
||||
p.sendMessage(GsonComponentSerializer.gson().deserialize(in.readUTF()));
|
||||
}
|
||||
break;
|
||||
case "globalchat":
|
||||
break;
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -18,4 +18,8 @@ commands:
|
|||
aliases: msg
|
||||
reply:
|
||||
permission: command.message
|
||||
aliases: r
|
||||
aliases: r
|
||||
ignore:
|
||||
permission: command.ignore
|
||||
unignore:
|
||||
permission: command.ignore
|
||||
|
|
@ -71,12 +71,6 @@
|
|||
<version>4.1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.23</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
|
|
|
|||
|
|
@ -96,7 +96,6 @@
|
|||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.23</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
|
|
|
|||
|
|
@ -96,4 +96,8 @@ public class VelocityChat {
|
|||
public ServerHandler getServerHandler() {
|
||||
return serverHandler;
|
||||
}
|
||||
|
||||
public ChannelIdentifier getChannelIdentifier() {
|
||||
return channelIdentifier;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,14 @@ import com.alttd.chat.config.Config;
|
|||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.managers.RegexManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.objects.Mail;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
|
@ -33,15 +38,50 @@ public class ChatHandler {
|
|||
|
||||
List<Template> templates = new ArrayList<>(List.of(
|
||||
Template.of("sender", senderUser.getDisplayName()),
|
||||
Template.of("sendername", player.getUsername()),
|
||||
Template.of("receiver", targetUser.getDisplayName()),
|
||||
Template.of("message", message),
|
||||
Template.of("receivername", player2.getUsername()),
|
||||
Template.of("message", GsonComponentSerializer.gson().deserialize(message)),
|
||||
Template.of("server", player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName() : "Altitude")));
|
||||
|
||||
Component senderMessage = miniMessage.parse(Config.MESSAGESENDER, templates);
|
||||
Component receiverMessage = miniMessage.parse(Config.MESSAGERECIEVER, templates);
|
||||
ServerConnection serverConnection;
|
||||
if(player.getCurrentServer().isPresent() && player2.getCurrentServer().isPresent()) {
|
||||
// redirect to the sender
|
||||
serverConnection = player.getCurrentServer().get();
|
||||
Component component = miniMessage.parse(Config.MESSAGESENDER, templates);
|
||||
ByteArrayDataOutput buf = ByteStreams.newDataOutput();
|
||||
buf.writeUTF("privatemessage");
|
||||
buf.writeUTF(player.getUniqueId().toString());
|
||||
buf.writeUTF(player2.getUsername());
|
||||
buf.writeUTF(GsonComponentSerializer.gson().serialize(component));
|
||||
serverConnection.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), buf.toByteArray());
|
||||
|
||||
player.sendMessage(senderMessage);
|
||||
player2.sendMessage(receiverMessage);
|
||||
//redirect to the receiver
|
||||
serverConnection = player2.getCurrentServer().get();
|
||||
component = miniMessage.parse(Config.MESSAGERECIEVER, templates);
|
||||
buf = ByteStreams.newDataOutput();
|
||||
buf.writeUTF("privatemessage");
|
||||
buf.writeUTF(player2.getUniqueId().toString());
|
||||
buf.writeUTF(player.getUsername());
|
||||
buf.writeUTF(GsonComponentSerializer.gson().serialize(component));
|
||||
serverConnection.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), buf.toByteArray());
|
||||
}
|
||||
|
||||
// ChatUser targetUser = ChatUserManager.getChatUser(player2.getUniqueId());
|
||||
//
|
||||
// MiniMessage miniMessage = MiniMessage.get();
|
||||
//
|
||||
// List<Template> templates = new ArrayList<>(List.of(
|
||||
// Template.of("sender", senderUser.getDisplayName()),
|
||||
// Template.of("receiver", targetUser.getDisplayName()),
|
||||
// Template.of("message", message),
|
||||
// Template.of("server", player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName() : "Altitude")));
|
||||
//
|
||||
// Component senderMessage = miniMessage.parse(Config.MESSAGESENDER, templates);
|
||||
// Component receiverMessage = miniMessage.parse(Config.MESSAGERECIEVER, templates);
|
||||
//
|
||||
// player.sendMessage(senderMessage);
|
||||
// player2.sendMessage(receiverMessage);
|
||||
}
|
||||
|
||||
public void globalAdminChat(String message) {
|
||||
|
|
@ -82,6 +122,15 @@ public class ChatHandler {
|
|||
* / mail send playerA,playerB,playerC message
|
||||
*/
|
||||
public void sendMail(CommandSource commandSource, String recipient, String message) {
|
||||
UUID uuid;
|
||||
if (commandSource instanceof Player) {
|
||||
uuid = ((Player) commandSource).getUniqueId();
|
||||
} else {
|
||||
uuid = Config.CONSOLEUUID;
|
||||
}
|
||||
Optional<Player> optionalPlayer = VelocityChat.getPlugin().getProxy().getPlayer(recipient);
|
||||
|
||||
//Mail mail = new Mail()
|
||||
// todo construct the mail and notify the player if online?
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ public class PluginMessageListener {
|
|||
case "globaladminchat":
|
||||
VelocityChat.getPlugin().getChatHandler().globalAdminChat(in.readUTF());
|
||||
break;
|
||||
case "privatemessage":
|
||||
case "privatemessage": // TODO redirect this to the server that player is on
|
||||
VelocityChat.getPlugin().getChatHandler().privateMessage(in.readUTF(), in.readUTF(), in.readUTF());
|
||||
break;
|
||||
default:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user