Finished party command, and sub commands
This commit is contained in:
parent
0932bf8d51
commit
2cb843b68c
|
|
@ -1,6 +1,6 @@
|
||||||
package com.alttd.chat.config;
|
package com.alttd.chat.config;
|
||||||
|
|
||||||
import com.alttd.chat.objects.Channel;
|
import com.alttd.chat.objects.channels.CustomChannel;
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
|
|
@ -68,7 +68,6 @@ public final class Config {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void readConfig(Class<?> clazz, Object instance) {
|
public static void readConfig(Class<?> clazz, Object instance) {
|
||||||
for (Method method : clazz.getDeclaredMethods()) {
|
for (Method method : clazz.getDeclaredMethods()) {
|
||||||
if (Modifier.isPrivate(method.getModifiers())) {
|
if (Modifier.isPrivate(method.getModifiers())) {
|
||||||
|
|
@ -156,6 +155,7 @@ public final class Config {
|
||||||
return config.getNode(splitPath(path));
|
return config.getNode(splitPath(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** ONLY EDIT ANYTHING BELOW THIS LINE **/
|
/** ONLY EDIT ANYTHING BELOW THIS LINE **/
|
||||||
public static List<String> PREFIXGROUPS = new ArrayList<>();
|
public static List<String> PREFIXGROUPS = new ArrayList<>();
|
||||||
public static List<String> STAFFGROUPS = new ArrayList<>();
|
public static List<String> STAFFGROUPS = new ArrayList<>();
|
||||||
|
|
@ -202,6 +202,11 @@ public final class Config {
|
||||||
GCCOOLDOWN = getInt("commands.globalchat.cooldown", GCCOOLDOWN);
|
GCCOOLDOWN = getInt("commands.globalchat.cooldown", GCCOOLDOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String PARTY_FORMAT = "<dark_aqua>(<gray><sender></gray> <hover:show_text:on <server>> → Party</hover>) <message>";
|
||||||
|
private static void party() {
|
||||||
|
PARTY_FORMAT = getString("party.format", PARTY_FORMAT);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO prefixes need hovers, this hasn't been setup yet!
|
// TODO prefixes need hovers, this hasn't been setup yet!
|
||||||
public static String CHATFORMAT = "<white><light_purple><prefixall> <gray><hover:show_text:Click to message <sendername>><click:suggest_command:/msg <sendername> ><sender></hover>: <white><message>";
|
public static String CHATFORMAT = "<white><light_purple><prefixall> <gray><hover:show_text:Click to message <sendername>><click:suggest_command:/msg <sendername> ><sender></hover>: <white><message>";
|
||||||
private static void Chat() {
|
private static void Chat() {
|
||||||
|
|
@ -249,7 +254,7 @@ public final class Config {
|
||||||
for (ConfigurationNode configurationNode : node.getChildrenMap().values()) {
|
for (ConfigurationNode configurationNode : node.getChildrenMap().values()) {
|
||||||
String channelName = Objects.requireNonNull(configurationNode.getKey()).toString();
|
String channelName = Objects.requireNonNull(configurationNode.getKey()).toString();
|
||||||
String key = "chat-channels." + channelName + ".";
|
String key = "chat-channels." + channelName + ".";
|
||||||
new Channel(channelName,
|
new CustomChannel(channelName,
|
||||||
getString(key + "format", ""),
|
getString(key + "format", ""),
|
||||||
getList(key + "servers", Collections.EMPTY_LIST),
|
getList(key + "servers", Collections.EMPTY_LIST),
|
||||||
getBoolean(key + "proxy", false));
|
getBoolean(key + "proxy", false));
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,16 @@ import com.alttd.chat.managers.PartyManager;
|
||||||
import com.alttd.chat.objects.ChatUser;
|
import com.alttd.chat.objects.ChatUser;
|
||||||
import com.alttd.chat.objects.Mail;
|
import com.alttd.chat.objects.Mail;
|
||||||
import com.alttd.chat.objects.Party;
|
import com.alttd.chat.objects.Party;
|
||||||
|
import com.alttd.chat.util.ALogger;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Queries {
|
public class Queries {
|
||||||
|
|
||||||
|
|
@ -155,6 +159,41 @@ public class Queries {
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
loadPartyUsers();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void loadPartyUsers() {
|
||||||
|
String query = "SELECT chat_users.party_id, chat_users.uuid, nicknames.nickname, utility_users.Username " +
|
||||||
|
"FROM chat_users " +
|
||||||
|
"LEFT OUTER JOIN nicknames ON chat_users.UUID = nicknames.uuid " +
|
||||||
|
"LEFT OUTER JOIN utility_users ON chat_users.uuid = utility_users.UUID " +
|
||||||
|
"WHERE party_id != -1";
|
||||||
|
|
||||||
|
try {
|
||||||
|
Connection connection = DatabaseConnection.getConnection();
|
||||||
|
|
||||||
|
ResultSet resultSet = connection.prepareStatement(query).executeQuery();
|
||||||
|
|
||||||
|
while (resultSet.next()) {
|
||||||
|
int id = resultSet.getInt("party_id");
|
||||||
|
UUID uuid = UUID.fromString(resultSet.getString("uuid"));
|
||||||
|
String displayName = resultSet.getString("nickname");
|
||||||
|
if (displayName == null || displayName.isEmpty()) {
|
||||||
|
displayName = resultSet.getString("Username");
|
||||||
|
}
|
||||||
|
|
||||||
|
Party party = PartyManager.getParty(id);
|
||||||
|
if (party == null) {
|
||||||
|
ALogger.warn("Unable to retrieve party: " + id);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
party.putUser(uuid, displayName);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Party addParty(UUID partyOwner, String partyName, String password) {
|
public static Party addParty(UUID partyOwner, String partyName, String password) {
|
||||||
|
|
@ -228,14 +267,15 @@ public class Queries {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeParty(int id) {
|
public static void addPartyUser(ChatUser user) {
|
||||||
String query = "DELETE FROM parties WHERE id = ?";
|
String query = "UPDATE chat_users SET party_id = ? WHERE uuid = ?";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Connection connection = DatabaseConnection.getConnection();
|
Connection connection = DatabaseConnection.getConnection();
|
||||||
PreparedStatement statement = connection.prepareStatement(query);
|
PreparedStatement statement = connection.prepareStatement(query);
|
||||||
|
|
||||||
statement.setInt(1, id);
|
statement.setInt(1, user.getPartyId());
|
||||||
|
statement.setString(2, user.getUuid().toString());
|
||||||
|
|
||||||
statement.execute();
|
statement.execute();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
|
@ -243,46 +283,45 @@ public class Queries {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void removePartyUser(UUID uuid) {
|
||||||
|
String query = "UPDATE chat_users SET party_id = -1 WHERE uuid = ?";
|
||||||
|
|
||||||
|
try {
|
||||||
|
Connection connection = DatabaseConnection.getConnection();
|
||||||
|
PreparedStatement statement = connection.prepareStatement(query);
|
||||||
|
|
||||||
|
statement.setString(1, uuid.toString());
|
||||||
|
|
||||||
|
statement.execute();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeParty(int id) {
|
||||||
|
String deleteParty = "DELETE FROM parties WHERE id = ?";
|
||||||
|
String updateUsers = "UPDATE chat_users SET party_id = -1 WHERE party_id = ?";
|
||||||
|
|
||||||
|
try {
|
||||||
|
Connection connection = DatabaseConnection.getConnection();
|
||||||
|
PreparedStatement statement = connection.prepareStatement(deleteParty);
|
||||||
|
|
||||||
|
statement.setInt(1, id);
|
||||||
|
statement.execute();
|
||||||
|
|
||||||
|
statement = connection.prepareStatement(updateUsers);
|
||||||
|
|
||||||
|
statement.setInt(1, id);
|
||||||
|
statement.execute();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------
|
//-----------------------------------------
|
||||||
|
|
||||||
private static void getChatUsers(HashMap<Integer, Party> parties) { //TODO Get parties from cache somewhere
|
|
||||||
String query = "SELECT * FROM chat_users WHERE party_id != -1";
|
|
||||||
|
|
||||||
try {
|
|
||||||
Connection connection = DatabaseConnection.getConnection();
|
|
||||||
|
|
||||||
ResultSet resultSet = connection.prepareStatement(query).executeQuery();
|
|
||||||
|
|
||||||
while (resultSet.next()) {
|
|
||||||
|
|
||||||
UUID uuid = UUID.fromString(resultSet.getString("uuid"));
|
|
||||||
int partyId = resultSet.getInt("party_id");
|
|
||||||
boolean toggled_chat = resultSet.getInt("toggled_chat") == 1;
|
|
||||||
boolean toggle_Gc = resultSet.getInt("toggled_gc") == 1;
|
|
||||||
|
|
||||||
if (partyId == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Party party = parties.get(partyId);
|
|
||||||
|
|
||||||
if (party == null) {
|
|
||||||
//TODO log this properly
|
|
||||||
System.out.println("INCORRECT LOGGING: party was empty, the party id stored in the database with user " + uuid + " was invalid.");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
party.addUser(new ChatUser(uuid, partyId, toggled_chat, toggle_Gc));
|
|
||||||
//TODO maybe add to the cache as well?
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void loadChatUsers() { //TODO Get parties from cache somewhere
|
public static void loadChatUsers() { //TODO Get parties from cache somewhere
|
||||||
String query = "SELECT * FROM chat_users";
|
String query = "SELECT * FROM chat_users WHERE party_id > -1";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Connection connection = DatabaseConnection.getConnection();
|
Connection connection = DatabaseConnection.getConnection();
|
||||||
|
|
@ -327,25 +366,6 @@ public class Queries {
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addUser(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, 0);
|
|
||||||
// statement.setInt(5, user.isGcOn() ? 1 : 0);
|
|
||||||
|
|
||||||
statement.execute();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setPartyChatState(boolean toggledChat, UUID uuid) {
|
public static void setPartyChatState(boolean toggledChat, UUID uuid) {
|
||||||
setBitWhereId("UPDATE chat_users set toggled_chat = ? WHERE uuid = ?", toggledChat, uuid);
|
setBitWhereId("UPDATE chat_users set toggled_chat = ? WHERE uuid = ?", toggledChat, uuid);
|
||||||
}
|
}
|
||||||
|
|
@ -368,21 +388,6 @@ public class Queries {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeUser(UUID uuid) {
|
|
||||||
String query = "DELETE FROM chat_users WHERE uuid = ?";
|
|
||||||
|
|
||||||
try {
|
|
||||||
Connection connection = DatabaseConnection.getConnection();
|
|
||||||
PreparedStatement statement = connection.prepareStatement(query);
|
|
||||||
|
|
||||||
statement.setString(1, uuid.toString());
|
|
||||||
|
|
||||||
statement.execute();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------
|
//-----------------------------------------
|
||||||
|
|
||||||
public static List<Mail> getMails(UUID uuid) {
|
public static List<Mail> getMails(UUID uuid) {
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public final class ChatUserManager {
|
public final class ChatUserManager {
|
||||||
|
|
@ -17,7 +16,6 @@ public final class ChatUserManager {
|
||||||
|
|
||||||
public static void initialize() {
|
public static void initialize() {
|
||||||
chatUsers = new ArrayList<>();
|
chatUsers = new ArrayList<>();
|
||||||
loadUsers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addUser(ChatUser user) {
|
public static void addUser(ChatUser user) {
|
||||||
|
|
@ -43,10 +41,6 @@ public final class ChatUserManager {
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void loadUsers() {
|
|
||||||
Queries.loadChatUsers();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static List<ChatUser> getChatUsers() {
|
protected static List<ChatUser> getChatUsers() {
|
||||||
return Collections.unmodifiableList(chatUsers);
|
return Collections.unmodifiableList(chatUsers);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.alttd.chat.managers;
|
||||||
import com.alttd.chat.database.Queries;
|
import com.alttd.chat.database.Queries;
|
||||||
import com.alttd.chat.objects.ChatUser;
|
import com.alttd.chat.objects.ChatUser;
|
||||||
import com.alttd.chat.objects.Party;
|
import com.alttd.chat.objects.Party;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
@ -25,6 +26,7 @@ public class PartyManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Party getParty(int id) {
|
public static Party getParty(int id) {
|
||||||
|
if (id < 0) return null;
|
||||||
for(Party party : parties) {
|
for(Party party : parties) {
|
||||||
if(id == party.getPartyId()) {
|
if(id == party.getPartyId()) {
|
||||||
return party;
|
return party;
|
||||||
|
|
@ -33,6 +35,15 @@ public class PartyManager {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Party getParty(String partyName) {
|
||||||
|
for(Party party : parties) {
|
||||||
|
if(party.getPartyName().equalsIgnoreCase(partyName)) {
|
||||||
|
return party;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static Party getParty(UUID uuid) {
|
public static Party getParty(UUID uuid) {
|
||||||
return getParty(ChatUserManager.getChatUser(uuid).getPartyId());
|
return getParty(ChatUserManager.getChatUser(uuid).getPartyId());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
public class ChatUser {
|
public class ChatUser {
|
||||||
private final UUID uuid; // player uuid
|
private final UUID uuid; // player uuid
|
||||||
private final int partyId; // the party they are in
|
private int partyId; // the party they are in
|
||||||
private boolean toggledPartyChat; // should chat messages instantly go to party chat when added, idk if this should be saved
|
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 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 displayName; // the nickname, doesn't need to be saved with the chatuser object, could be saved but we can get it from the nicknamesview
|
||||||
|
|
@ -57,6 +57,10 @@ public class ChatUser {
|
||||||
return partyId;
|
return partyId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPartyId(int partyId) {
|
||||||
|
this.partyId = partyId;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean toggledPartyChat() {
|
public boolean toggledPartyChat() {
|
||||||
return toggledPartyChat;
|
return toggledPartyChat;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
package com.alttd.chat.objects;
|
package com.alttd.chat.objects;
|
||||||
|
|
||||||
import com.alttd.chat.database.Queries;
|
import com.alttd.chat.database.Queries;
|
||||||
|
import com.alttd.chat.managers.ChatUserManager;
|
||||||
|
import com.alttd.chat.managers.PartyManager;
|
||||||
|
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.UUID;
|
import java.util.List;
|
||||||
|
|
||||||
public class Party {
|
public class Party {
|
||||||
|
|
||||||
|
|
@ -11,7 +14,7 @@ public class Party {
|
||||||
private UUID ownerUuid;
|
private UUID ownerUuid;
|
||||||
private String partyName;
|
private String partyName;
|
||||||
private String partyPassword;
|
private String partyPassword;
|
||||||
private HashMap<UUID, ChatUser> partyUsers; //TODO might need to be a map?
|
private final HashMap<UUID, String> partyUsers; //TODO might need to be a map?
|
||||||
|
|
||||||
public Party(int partyId, UUID ownerUuid, String partyName, String partyPassword) {
|
public Party(int partyId, UUID ownerUuid, String partyName, String partyPassword) {
|
||||||
this.partyId = partyId;
|
this.partyId = partyId;
|
||||||
|
|
@ -21,18 +24,23 @@ public class Party {
|
||||||
partyUsers = new HashMap<>();
|
partyUsers = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addUser(HashMap<UUID, ChatUser> partyUsers) {
|
public void putUser(UUID uuid, String displayName) {
|
||||||
this.partyUsers.putAll(partyUsers);
|
this.partyUsers.put(uuid, displayName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addUser(ChatUser partyUser) {
|
public void addUser(ChatUser partyUser) {
|
||||||
this.partyUsers.put(partyUser.getUuid(), partyUser);
|
this.partyUsers.put(partyUser.getUuid(), PlainComponentSerializer.plain().serialize(partyUser.getDisplayName()));
|
||||||
Queries.addUser(partyUser);
|
partyUser.setPartyId(getPartyId());
|
||||||
|
Queries.addPartyUser(partyUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeUser(UUID uuid) {
|
||||||
|
removeUser(ChatUserManager.getChatUser(uuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeUser(ChatUser partyUser) {
|
public void removeUser(ChatUser partyUser) {
|
||||||
partyUsers.remove(partyUser.getUuid());
|
partyUsers.remove(partyUser.getUuid());
|
||||||
Queries.removeUser(partyUser.getUuid());
|
Queries.removePartyUser(partyUser.getUuid());
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPartyId() {
|
public int getPartyId() {
|
||||||
|
|
@ -43,6 +51,12 @@ public class Party {
|
||||||
return ownerUuid;
|
return ownerUuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UUID newOwner() {
|
||||||
|
UUID uuid = partyUsers.keySet().iterator().next();
|
||||||
|
setOwnerUuid(uuid);
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
public void setOwnerUuid(UUID ownerUuid) {
|
public void setOwnerUuid(UUID ownerUuid) {
|
||||||
this.ownerUuid = ownerUuid;
|
this.ownerUuid = ownerUuid;
|
||||||
Queries.setPartyOwner(ownerUuid, partyId); //TODO: Async pls
|
Queries.setPartyOwner(ownerUuid, partyId); //TODO: Async pls
|
||||||
|
|
@ -70,11 +84,20 @@ public class Party {
|
||||||
return !partyPassword.isEmpty();
|
return !partyPassword.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<UUID, ChatUser> getPartyUsers() {
|
public HashMap<UUID, String> getPartyUsers() {
|
||||||
return partyUsers;
|
return partyUsers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPartyUsers(HashMap<UUID, ChatUser> partyUsers) {
|
public void delete() {
|
||||||
this.partyUsers = partyUsers;
|
Queries.removeParty(partyId);
|
||||||
|
PartyManager.removeParty(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<UUID> getPartyUsersUuid() {
|
||||||
|
return new ArrayList<>(partyUsers.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUserDisplayName(UUID uuid) {
|
||||||
|
return partyUsers.get(uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,20 @@
|
||||||
package com.alttd.chat.objects;
|
package com.alttd.chat.objects.channels;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public abstract class Channel {
|
||||||
|
|
||||||
public class Channel {
|
|
||||||
public static HashMap<String, Channel> channels = new HashMap<>();
|
public static HashMap<String, Channel> channels = new HashMap<>();
|
||||||
private String permission;
|
protected String permission;
|
||||||
private String channelName;
|
protected String channelName;
|
||||||
private String format;
|
protected String format;
|
||||||
private List<String> servers;
|
protected boolean proxy;
|
||||||
private boolean proxy;
|
|
||||||
|
|
||||||
public Channel(String channelName, String format, List<String> servers, boolean proxy) {
|
public Channel(String channelName, String format, boolean proxy) {
|
||||||
this.permission = "chat.channel." + channelName.toLowerCase();
|
this.permission = "chat.channel." + channelName.toLowerCase();
|
||||||
this.channelName = channelName;
|
this.channelName = channelName;
|
||||||
this.format = format;
|
this.format = format;
|
||||||
this.servers = servers;
|
|
||||||
this.proxy = proxy;
|
this.proxy = proxy;
|
||||||
channels.put(channelName.toLowerCase(), this);
|
channels.put(channelName.toLowerCase(), this);
|
||||||
}
|
}
|
||||||
|
|
@ -35,10 +35,6 @@ public class Channel {
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getServers() {
|
|
||||||
return servers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isProxy() {
|
public boolean isProxy() {
|
||||||
return proxy;
|
return proxy;
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.alttd.chat.objects.channels;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class CustomChannel extends Channel {
|
||||||
|
private final List<String> servers;
|
||||||
|
|
||||||
|
public CustomChannel(String channelName, String format, List<String> servers, boolean proxy) {
|
||||||
|
super(channelName, format, proxy);
|
||||||
|
this.permission = "chat.channel." + channelName.toLowerCase();
|
||||||
|
this.channelName = channelName;
|
||||||
|
this.format = format;
|
||||||
|
this.servers = servers;
|
||||||
|
this.proxy = proxy;
|
||||||
|
channels.put(channelName.toLowerCase(), this);
|
||||||
|
}
|
||||||
|
public List<String> getServers() {
|
||||||
|
return servers;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.alttd.chat.objects.channels;
|
||||||
|
|
||||||
|
public class DefaultChannel extends Channel{
|
||||||
|
public DefaultChannel(String channelName, String format, boolean proxy) {
|
||||||
|
super(channelName, format, proxy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,7 +8,8 @@ import com.alttd.chat.handler.ChatHandler;
|
||||||
import com.alttd.chat.listeners.ChatListener;
|
import com.alttd.chat.listeners.ChatListener;
|
||||||
import com.alttd.chat.listeners.PlayerListener;
|
import com.alttd.chat.listeners.PlayerListener;
|
||||||
import com.alttd.chat.listeners.PluginMessage;
|
import com.alttd.chat.listeners.PluginMessage;
|
||||||
import com.alttd.chat.objects.Channel;
|
import com.alttd.chat.objects.channels.Channel;
|
||||||
|
import com.alttd.chat.objects.channels.CustomChannel;
|
||||||
import com.alttd.chat.util.ALogger;
|
import com.alttd.chat.util.ALogger;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
|
@ -47,8 +48,11 @@ public class ChatPlugin extends JavaPlugin {
|
||||||
registerCommand("unignore", new Unignore());
|
registerCommand("unignore", new Unignore());
|
||||||
registerCommand("muteserver", new MuteServer());
|
registerCommand("muteserver", new MuteServer());
|
||||||
registerCommand("spy", new Spy());
|
registerCommand("spy", new Spy());
|
||||||
|
registerCommand("party", new PartyCommand());
|
||||||
|
registerCommand("pc", new PartyChatCommand());
|
||||||
for (Channel channel : Channel.getChannels()) {
|
for (Channel channel : Channel.getChannels()) {
|
||||||
this.getServer().getCommandMap().register(channel.getChannelName().toLowerCase(), new ChatChannel(channel));
|
if (!(channel instanceof CustomChannel customChannel)) continue;
|
||||||
|
this.getServer().getCommandMap().register(channel.getChannelName().toLowerCase(), new ChatChannel(customChannel));
|
||||||
}
|
}
|
||||||
|
|
||||||
messageChannel = Config.MESSAGECHANNEL;
|
messageChannel = Config.MESSAGECHANNEL;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package com.alttd.chat.commands;
|
package com.alttd.chat.commands;
|
||||||
|
|
||||||
import com.alttd.chat.ChatPlugin;
|
import com.alttd.chat.ChatPlugin;
|
||||||
import com.alttd.chat.objects.Channel;
|
import com.alttd.chat.objects.channels.CustomChannel;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.defaults.BukkitCommand;
|
import org.bukkit.command.defaults.BukkitCommand;
|
||||||
|
|
@ -13,10 +13,10 @@ import java.util.Collections;
|
||||||
|
|
||||||
public class ChatChannel extends BukkitCommand {
|
public class ChatChannel extends BukkitCommand {
|
||||||
|
|
||||||
Channel channel;
|
CustomChannel channel;
|
||||||
String command;
|
String command;
|
||||||
|
|
||||||
public ChatChannel(Channel channel) {
|
public ChatChannel(CustomChannel channel) {
|
||||||
super(channel.getChannelName().toLowerCase());
|
super(channel.getChannelName().toLowerCase());
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
this.command = channel.getChannelName().toLowerCase();
|
this.command = channel.getChannelName().toLowerCase();
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
package com.alttd.chat.commands;
|
||||||
|
|
||||||
|
import com.alttd.chat.ChatPlugin;
|
||||||
|
import com.alttd.chat.managers.PartyManager;
|
||||||
|
import com.alttd.chat.objects.Party;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
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;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class PartyChatCommand implements CommandExecutor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
|
if(!(sender instanceof Player player)) { // must be a player
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Party party = PartyManager.getParty(player.getUniqueId());
|
||||||
|
if (party == null) {
|
||||||
|
sender.sendMessage(MiniMessage.get().parse("<red>You are not in a party. For more info do <gold>/party</gold>.</red>"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(args.length == 0) {
|
||||||
|
// TODO: 08/08/2021 lock into party chat
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String message = StringUtils.join(args, " ", 0, args.length);
|
||||||
|
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
ChatPlugin.getInstance().getChatHandler().partyMessage(party, player, message);
|
||||||
|
}
|
||||||
|
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,14 +2,23 @@ package com.alttd.chat.commands;
|
||||||
|
|
||||||
import com.alttd.chat.ChatPlugin;
|
import com.alttd.chat.ChatPlugin;
|
||||||
import com.alttd.chat.database.Queries;
|
import com.alttd.chat.database.Queries;
|
||||||
|
import com.alttd.chat.managers.ChatUserManager;
|
||||||
import com.alttd.chat.managers.PartyManager;
|
import com.alttd.chat.managers.PartyManager;
|
||||||
|
import com.alttd.chat.objects.ChatUser;
|
||||||
import com.alttd.chat.objects.Party;
|
import com.alttd.chat.objects.Party;
|
||||||
|
import com.alttd.chat.util.Utility;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class PartyCommand implements CommandExecutor {
|
public class PartyCommand implements CommandExecutor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -17,34 +26,145 @@ public class PartyCommand implements CommandExecutor {
|
||||||
if(!(sender instanceof Player player)) { // must be a player
|
if(!(sender instanceof Player player)) { // must be a player
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(args.length == 0) return false;
|
if (args.length == 0) {
|
||||||
|
helpMessage(sender);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
switch (args[0].toLowerCase()) {
|
switch (args[0].toLowerCase()) {
|
||||||
case "create" -> {
|
case "create" -> {
|
||||||
// TODO: 06/08/2021 verify args 1, 2 and check args length (3-16 char limit?)
|
if (args.length < 3 || !args[1].matches("[\\w]{3,16}") || !args[2].matches("[\\w]{3,16}")) {
|
||||||
|
invalidMessage(sender, CommandUsage.CREATE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (PartyManager.getParty(args[1]) != null) {
|
||||||
|
sender.sendMessage(MiniMessage.get().parse("<red>A party with this name already exists.</red>"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
Party party = Queries.addParty(player.getUniqueId(), args[1], args[2]);
|
Party party = Queries.addParty(player.getUniqueId(), args[1], args[2]);
|
||||||
|
party.addUser(ChatUserManager.getChatUser(player.getUniqueId()));
|
||||||
PartyManager.addParty(party);
|
PartyManager.addParty(party);
|
||||||
|
sender.sendMessage(MiniMessage.get().parse("<green>You created a party called: '<gold>" +
|
||||||
|
party.getPartyName() + "</gold>' with the password: '<gold>" +
|
||||||
|
party.getPartyPassword() + "</gold>'</green>"));
|
||||||
}
|
}
|
||||||
case "invite" -> {
|
case "invite" -> {
|
||||||
// TODO: 07/08/2021 send invite to user, when they click execute </party join partyname password>
|
if (args.length < 2) {
|
||||||
|
invalidMessage(sender, CommandUsage.INVITE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Party party = PartyManager.getParty(player.getUniqueId());
|
||||||
|
if (party == null) {
|
||||||
|
sender.sendMessage(MiniMessage.get().parse("<red>You're not in a party.</red>"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!party.getOwnerUuid().equals(player.getUniqueId())) {
|
||||||
|
sender.sendMessage("<red>You don't own this party.</red>");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Player target = Bukkit.getPlayer(args[1]);
|
||||||
|
if (target == null || !target.isOnline()) {
|
||||||
|
sender.sendMessage(MiniMessage.get().parse("<red>The player must be on the same server to receive an invite.</red>"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
target.sendMessage(MiniMessage.get().parse("<click:run_command:'/party join " + party.getPartyName() + " " + party.getPartyPassword() +
|
||||||
|
"'><dark_aqua>You received an invite to join " + party.getPartyName() + " click this message to accept.</dark_aqua></click>"));
|
||||||
|
sender.sendMessage(MiniMessage.get().parse("<green>You send a party invite to " + target.getName() + "!</green>"));
|
||||||
}
|
}
|
||||||
case "join" -> {
|
case "join" -> {
|
||||||
// TODO: 07/08/2021 verify password and join party
|
if (args.length < 3 || !args[1].matches("[\\w]{3,16}") || !args[2].matches("[\\w]{3,16}")) {
|
||||||
|
invalidMessage(sender, CommandUsage.JOIN);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Party party = PartyManager.getParty(args[1]);
|
||||||
|
if (party == null) {
|
||||||
|
sender.sendMessage(MiniMessage.get().parse("<red>This party does not exist.</red>"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!party.getPartyPassword().equals(args[2])) {
|
||||||
|
sender.sendMessage(MiniMessage.get().parse("<red>Invalid password.</red>"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
party.addUser(ChatUserManager.getChatUser(player.getUniqueId()));
|
||||||
|
sender.sendMessage(MiniMessage.get().parse("<green>You joined " + party.getPartyName() + "!</green>"));
|
||||||
}
|
}
|
||||||
case "leave" -> {
|
case "leave" -> {
|
||||||
|
Party party = PartyManager.getParty(player.getUniqueId());
|
||||||
|
if (party == null) {
|
||||||
|
sender.sendMessage(MiniMessage.get().parse("<red>You're not in a party.</red>"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
party.removeUser(player.getUniqueId());
|
||||||
|
if (party.getOwnerUuid().equals(player.getUniqueId())) {
|
||||||
|
if (party.getPartyUsers().size() > 0) {
|
||||||
|
ChatUser chatUser = ChatUserManager.getChatUser(party.newOwner());
|
||||||
|
sender.sendMessage(MiniMessage.get().parse("<dark_aqua>Since you own this party a new party owner will be chosen.<dark_aqua>"));
|
||||||
|
ChatPlugin.getInstance().getChatHandler().partyMessage(party, player, "<dark_aqua>" +
|
||||||
|
ChatUserManager.getChatUser(player.getUniqueId()).getDisplayName() +
|
||||||
|
" left the party, the new party owner is " + chatUser.getDisplayName());
|
||||||
|
} else {
|
||||||
|
party.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
// TODO: 07/08/2021 leave the party
|
// TODO: 07/08/2021 leave the party
|
||||||
}
|
}
|
||||||
case "remove" -> {
|
case "remove" -> {
|
||||||
// TODO: 07/08/2021 remove specified user
|
if (args.length < 2) {
|
||||||
|
invalidMessage(sender, CommandUsage.REMOVE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Party party = PartyManager.getParty(player.getUniqueId());
|
||||||
|
if (party == null) {
|
||||||
|
sender.sendMessage(MiniMessage.get().parse("<red>You're not in a party.</red>"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!party.getOwnerUuid().equals(player.getUniqueId())) {
|
||||||
|
sender.sendMessage("<red>You don't own this party.</red>");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
OfflinePlayer offlinePlayerIfCached = Bukkit.getOfflinePlayerIfCached((args[1]));
|
||||||
|
if (offlinePlayerIfCached == null) {
|
||||||
|
sender.sendMessage(MiniMessage.get().parse("<red>Unable to find this player.</red>"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
party.removeUser(ChatUserManager.getChatUser(offlinePlayerIfCached.getUniqueId()));
|
||||||
|
|
||||||
|
if (offlinePlayerIfCached.isOnline()) {
|
||||||
|
Objects.requireNonNull(offlinePlayerIfCached.getPlayer())
|
||||||
|
.sendMessage(MiniMessage.get().parse("<red>You were removed from the '" + party.getPartyName() + "' party."));
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.sendMessage(MiniMessage.get().parse("<green>You removed " + offlinePlayerIfCached.getName() + " from the party!</green>"));
|
||||||
}
|
}
|
||||||
case "delete" -> {
|
case "info" -> {
|
||||||
// TODO: 07/08/2021 ask for confirmation, when they click repeat the command but with --confirm (so if it has that at the end obv delete the party)
|
Party party = PartyManager.getParty(player.getUniqueId());
|
||||||
|
if (party == null) {
|
||||||
|
sender.sendMessage(MiniMessage.get().parse("<red>You're not in a party.</red>"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
stringBuilder.append("<gold><bold>Party info</bold>:</gold>")
|
||||||
|
.append("<green>Party name: <dark_aqua>").append(party.getPartyName()).append("</dark_aqua>\n")
|
||||||
|
.append(party.getOwnerUuid().equals(player.getUniqueId()) ? "Party password: <dark_aqua>" + party.getPartyPassword() + "</dark_aqua>\n" : "")
|
||||||
|
.append("Party owner: ").append(party.getUserDisplayName(party.getOwnerUuid())).append("\n")
|
||||||
|
.append("Party members: ");
|
||||||
|
for (String displayName : party.getPartyUsers().values()) {
|
||||||
|
stringBuilder.append(displayName).append(", ");
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuilder.delete(stringBuilder.length() - 2, stringBuilder.length());
|
||||||
|
|
||||||
|
sender.sendMessage(Utility.applyColor(stringBuilder.toString()));
|
||||||
}
|
}
|
||||||
default -> {
|
default -> {
|
||||||
// TODO: 07/08/2021 send help message
|
helpMessage(sender);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -52,4 +172,34 @@ public class PartyCommand implements CommandExecutor {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private void invalidMessage(CommandSender sender, CommandUsage commandUsage) {
|
||||||
|
sender.sendMessage(MiniMessage.get().parse("<red>Invalid command, proper usage: %command%.</red>".replaceAll("%command%", commandUsage.message)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void helpMessage(CommandSender sender) {
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
stringBuilder.append("<dark_aqua>Party commands:</dark_aqua><green>");
|
||||||
|
for (CommandUsage commandUsage : CommandUsage.values()) {
|
||||||
|
stringBuilder.append("\n- ").append(commandUsage.message);
|
||||||
|
}
|
||||||
|
stringBuilder.append("</green>");
|
||||||
|
sender.sendMessage(MiniMessage.get().parse(stringBuilder.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum CommandUsage {
|
||||||
|
CREATE("<gold>/party create <#FFE800><hover:show_text:'<gold>A party name must be 3-16 characters</gold>'><name></hover> " +
|
||||||
|
"<hover:show_text:'<gold>A party password must be 3-16 characters\n</gold>" +
|
||||||
|
"<red>When choosing a password keep in mind staff can see it and you might need to share it with other players!</red>'><password></#FFE800></hover></gold>"),
|
||||||
|
INVITE("<gold>/party invite <username></gold>"),
|
||||||
|
JOIN("<gold>/party join <party name> <password></gold>"),
|
||||||
|
LEAVE("<gold><hover:show_text:'<red>If the party owner leaves the server will choose a new party owner</red>'>/party leave</hover></gold>"),
|
||||||
|
REMOVE("<gold>/party remove <username></gold>");
|
||||||
|
|
||||||
|
private final String message;
|
||||||
|
|
||||||
|
CommandUsage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
package com.alttd.chat.handler;
|
package com.alttd.chat.handler;
|
||||||
|
|
||||||
import com.alttd.chat.ChatPlugin;
|
import com.alttd.chat.ChatPlugin;
|
||||||
import com.alttd.chat.commands.ChatChannel;
|
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
import com.alttd.chat.managers.ChatUserManager;
|
import com.alttd.chat.managers.ChatUserManager;
|
||||||
import com.alttd.chat.managers.RegexManager;
|
import com.alttd.chat.managers.RegexManager;
|
||||||
import com.alttd.chat.objects.Channel;
|
import com.alttd.chat.objects.channels.CustomChannel;
|
||||||
import com.alttd.chat.objects.ChatUser;
|
import com.alttd.chat.objects.ChatUser;
|
||||||
|
import com.alttd.chat.objects.Party;
|
||||||
import com.alttd.chat.util.GalaxyUtility;
|
import com.alttd.chat.util.GalaxyUtility;
|
||||||
import com.alttd.chat.util.Utility;
|
import com.alttd.chat.util.Utility;
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
|
|
@ -17,12 +17,10 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import net.kyori.adventure.text.minimessage.Template;
|
import net.kyori.adventure.text.minimessage.Template;
|
||||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.util.StringUtil;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -124,7 +122,7 @@ public class ChatHandler {
|
||||||
sendPluginMessage(player, "globalchat", component);
|
sendPluginMessage(player, "globalchat", component);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void chatChannel(Player player, Channel channel, String message) {
|
public void chatChannel(Player player, CustomChannel channel, String message) {
|
||||||
if (!player.hasPermission(channel.getPermission())) {
|
if (!player.hasPermission(channel.getPermission())) {
|
||||||
player.sendMessage(MiniMessage.get().parse("<red>You don't have permission to use this channel.</red>"));
|
player.sendMessage(MiniMessage.get().parse("<red>You don't have permission to use this channel.</red>"));
|
||||||
return;
|
return;
|
||||||
|
|
@ -137,7 +135,7 @@ public class ChatHandler {
|
||||||
|
|
||||||
String updatedMessage = RegexManager.replaceText(player.getName(), player.getUniqueId(), message);
|
String updatedMessage = RegexManager.replaceText(player.getName(), player.getUniqueId(), message);
|
||||||
if(updatedMessage == null) {
|
if(updatedMessage == null) {
|
||||||
GalaxyUtility.sendBlockedNotification("GC Language", player, message, "");
|
GalaxyUtility.sendBlockedNotification(channel.getChannelName() + " Language", player, message, "");
|
||||||
return; // the message was blocked
|
return; // the message was blocked
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -163,7 +161,35 @@ public class ChatHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendChatChannelMessage(Channel chatChannel, UUID uuid, Component component) {
|
public void partyMessage(Party party, Player player, String message) {
|
||||||
|
if (isMuted(player, message, "[" + party.getPartyName() + " Muted] ")) return;
|
||||||
|
|
||||||
|
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||||
|
Component senderName = user.getDisplayName();
|
||||||
|
|
||||||
|
String updatedMessage = RegexManager.replaceText(player.getName(), player.getUniqueId(), message);
|
||||||
|
if(updatedMessage == null) {
|
||||||
|
GalaxyUtility.sendBlockedNotification("Party Language", player, message, "");
|
||||||
|
return; // the message was blocked
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!player.hasPermission("chat.format")) {
|
||||||
|
updatedMessage = miniMessage.stripTokens(updatedMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(updatedMessage.contains("[i]")) updatedMessage = updatedMessage.replace("[i]", "<[i]>");
|
||||||
|
|
||||||
|
List<Template> templates = new ArrayList<>(List.of(
|
||||||
|
Template.of("sender", senderName),
|
||||||
|
Template.of("message", updatedMessage),
|
||||||
|
Template.of("server", Bukkit.getServerName()),
|
||||||
|
Template.of("[i]", itemComponent(player.getInventory().getItemInMainHand()))));
|
||||||
|
|
||||||
|
Component component = miniMessage.parse(Config.PARTY_FORMAT, templates);
|
||||||
|
sendPartyMessage(player, party.getPartyId(), component);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendChatChannelMessage(CustomChannel chatChannel, UUID uuid, Component component) {
|
||||||
if (!chatChannel.getServers().contains(Bukkit.getServerName())) return;
|
if (!chatChannel.getServers().contains(Bukkit.getServerName())) return;
|
||||||
|
|
||||||
Bukkit.getServer().getOnlinePlayers().stream()
|
Bukkit.getServer().getOnlinePlayers().stream()
|
||||||
|
|
@ -197,6 +223,16 @@ public class ChatHandler {
|
||||||
out.writeUTF(GsonComponentSerializer.gson().serialize(component));
|
out.writeUTF(GsonComponentSerializer.gson().serialize(component));
|
||||||
player.sendPluginMessage(plugin, Config.MESSAGECHANNEL, out.toByteArray());
|
player.sendPluginMessage(plugin, Config.MESSAGECHANNEL, out.toByteArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendPartyMessage(Player player, int partyId, Component component) {
|
||||||
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
|
out.writeUTF("party");
|
||||||
|
out.writeUTF(String.valueOf(partyId));
|
||||||
|
out.writeUTF(player.getUniqueId().toString());
|
||||||
|
out.writeUTF(GsonComponentSerializer.gson().serialize(component));
|
||||||
|
player.sendPluginMessage(plugin, Config.MESSAGECHANNEL, out.toByteArray());
|
||||||
|
}
|
||||||
|
|
||||||
// Start - move these to util
|
// Start - move these to util
|
||||||
|
|
||||||
private boolean isMuted(Player player, String message, String prefix) {
|
private boolean isMuted(Player player, String message, String prefix) {
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,11 @@ package com.alttd.chat.listeners;
|
||||||
|
|
||||||
import com.alttd.chat.ChatPlugin;
|
import com.alttd.chat.ChatPlugin;
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
import com.alttd.chat.database.Queries;
|
|
||||||
import com.alttd.chat.managers.ChatUserManager;
|
import com.alttd.chat.managers.ChatUserManager;
|
||||||
import com.alttd.chat.objects.Channel;
|
import com.alttd.chat.objects.channels.Channel;
|
||||||
|
import com.alttd.chat.objects.channels.CustomChannel;
|
||||||
import com.alttd.chat.objects.ChatUser;
|
import com.alttd.chat.objects.ChatUser;
|
||||||
import com.alttd.chat.util.ALogger;
|
import com.alttd.chat.util.ALogger;
|
||||||
import com.alttd.chat.util.Utility;
|
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
|
@ -79,11 +78,11 @@ public class PluginMessage implements PluginMessageListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void chatChannel(ByteArrayDataInput in) {
|
private void chatChannel(ByteArrayDataInput in) {
|
||||||
Channel chatChannel = null;
|
CustomChannel chatChannel = null;
|
||||||
UUID uuid = null;
|
UUID uuid = null;
|
||||||
Component component = null;
|
Component component = null;
|
||||||
try {
|
try {
|
||||||
chatChannel = Channel.getChatChannel(in.readUTF());
|
chatChannel = (CustomChannel) Channel.getChatChannel(in.readUTF());
|
||||||
uuid = UUID.fromString(in.readUTF());
|
uuid = UUID.fromString(in.readUTF());
|
||||||
component = GsonComponentSerializer.gson().deserialize(in.readUTF());
|
component = GsonComponentSerializer.gson().deserialize(in.readUTF());
|
||||||
} catch (Exception e) { //Idk the exception for reading too far into in.readUTF()
|
} catch (Exception e) { //Idk the exception for reading too far into in.readUTF()
|
||||||
|
|
@ -102,7 +101,7 @@ public class PluginMessage implements PluginMessageListener {
|
||||||
ALogger.warn("Didn't receive a valid message for ChatChannel " + chatChannel.getChannelName() + ".");
|
ALogger.warn("Didn't receive a valid message for ChatChannel " + chatChannel.getChannelName() + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
final Channel finalChatChannel = chatChannel;
|
final CustomChannel finalChatChannel = chatChannel;
|
||||||
final Component finalComponent = component;
|
final Component finalComponent = component;
|
||||||
final UUID finalUuid = uuid;
|
final UUID finalUuid = uuid;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,4 +26,8 @@ commands:
|
||||||
muteserver:
|
muteserver:
|
||||||
permission: command.mute-server
|
permission: command.mute-server
|
||||||
spy:
|
spy:
|
||||||
permission: command.togglespy
|
permission: command.togglespy
|
||||||
|
party:
|
||||||
|
permission: command.party
|
||||||
|
pc:
|
||||||
|
permission: command.pc
|
||||||
|
|
@ -3,9 +3,12 @@ package com.alttd.chat.handlers;
|
||||||
import com.alttd.chat.VelocityChat;
|
import com.alttd.chat.VelocityChat;
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
import com.alttd.chat.managers.ChatUserManager;
|
import com.alttd.chat.managers.ChatUserManager;
|
||||||
|
import com.alttd.chat.managers.PartyManager;
|
||||||
import com.alttd.chat.managers.RegexManager;
|
import com.alttd.chat.managers.RegexManager;
|
||||||
import com.alttd.chat.objects.ChatUser;
|
import com.alttd.chat.objects.ChatUser;
|
||||||
import com.alttd.chat.objects.Mail;
|
import com.alttd.chat.objects.Mail;
|
||||||
|
import com.alttd.chat.objects.Party;
|
||||||
|
import com.alttd.chat.util.ALogger;
|
||||||
import com.alttd.chat.util.Utility;
|
import com.alttd.chat.util.Utility;
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
|
|
@ -142,4 +145,17 @@ public class ChatHandler {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
package com.alttd.chat.listeners;
|
package com.alttd.chat.listeners;
|
||||||
|
|
||||||
import com.alttd.chat.VelocityChat;
|
import com.alttd.chat.VelocityChat;
|
||||||
import com.alttd.chat.objects.Channel;
|
import com.alttd.chat.objects.channels.CustomChannel;
|
||||||
import com.alttd.chat.util.ALogger;
|
import com.alttd.chat.util.ALogger;
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||||
|
|
@ -15,7 +14,6 @@ import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class PluginMessageListener {
|
public class PluginMessageListener {
|
||||||
|
|
@ -52,7 +50,7 @@ public class PluginMessageListener {
|
||||||
break;
|
break;
|
||||||
case "chatchannel": {
|
case "chatchannel": {
|
||||||
String channelName = in.readUTF();
|
String channelName = in.readUTF();
|
||||||
Channel chatChannel = Channel.getChatChannel(channelName);
|
CustomChannel chatChannel = (CustomChannel) CustomChannel.getChatChannel(channelName);
|
||||||
|
|
||||||
if (chatChannel == null) {
|
if (chatChannel == null) {
|
||||||
ALogger.warn("Received non existent channel" + channelName +".");
|
ALogger.warn("Received non existent channel" + channelName +".");
|
||||||
|
|
@ -64,6 +62,10 @@ public class PluginMessageListener {
|
||||||
registeredServer.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), event.getData())));
|
registeredServer.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), event.getData())));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "party": {
|
||||||
|
VelocityChat.getPlugin().getChatHandler().partyChat(in.readUTF(), UUID.fromString(in.readUTF()), GsonComponentSerializer.gson().deserialize(in.readUTF()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
VelocityChat.getPlugin().getLogger().info("server " + event.getSource());
|
VelocityChat.getPlugin().getLogger().info("server " + event.getSource());
|
||||||
ProxyServer proxy = VelocityChat.getPlugin().getProxy();
|
ProxyServer proxy = VelocityChat.getPlugin().getProxy();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user