Add plugin
This commit is contained in:
parent
001d64b521
commit
4aa4726a4e
|
|
@ -1,8 +1,10 @@
|
||||||
package com.alttd.chat;
|
package com.alttd.velocitychat;
|
||||||
|
|
||||||
import com.alttd.chat.database.DatabaseConnection;
|
import com.alttd.velocitychat.database.DatabaseConnection;
|
||||||
import net.luckperms.api.LuckPerms;
|
import net.luckperms.api.LuckPerms;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public interface ChatAPI {
|
public interface ChatAPI {
|
||||||
|
|
||||||
ChatAPI get();
|
ChatAPI get();
|
||||||
|
|
@ -10,4 +12,11 @@ public interface ChatAPI {
|
||||||
LuckPerms getLuckPerms();
|
LuckPerms getLuckPerms();
|
||||||
|
|
||||||
DatabaseConnection getDataBase();
|
DatabaseConnection getDataBase();
|
||||||
|
|
||||||
|
String getPrefix(UUID uuid);
|
||||||
|
|
||||||
|
String getPrefix(UUID uuid, boolean all);
|
||||||
|
|
||||||
|
String getStaffPrefix(UUID uuid);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,15 @@
|
||||||
package com.alttd.chat;
|
package com.alttd.velocitychat;
|
||||||
|
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.velocitychat.config.Config;
|
||||||
import com.alttd.chat.database.DatabaseConnection;
|
import com.alttd.velocitychat.database.DatabaseConnection;
|
||||||
import net.luckperms.api.LuckPerms;
|
import net.luckperms.api.LuckPerms;
|
||||||
import net.luckperms.api.LuckPermsProvider;
|
import net.luckperms.api.LuckPermsProvider;
|
||||||
|
import net.luckperms.api.model.group.Group;
|
||||||
|
import net.luckperms.api.model.user.User;
|
||||||
|
|
||||||
import java.io.File;
|
import java.util.Collection;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class ChatImplementation implements ChatAPI{
|
public class ChatImplementation implements ChatAPI{
|
||||||
|
|
||||||
|
|
@ -14,9 +18,9 @@ public class ChatImplementation implements ChatAPI{
|
||||||
private LuckPerms luckPerms;
|
private LuckPerms luckPerms;
|
||||||
private DatabaseConnection databaseConnection;
|
private DatabaseConnection databaseConnection;
|
||||||
|
|
||||||
ChatImplementation() {
|
public ChatImplementation() {
|
||||||
instance = this;
|
instance = this;
|
||||||
Config.init(new File(System.getProperty("user.home")));
|
Config.init();
|
||||||
// init database
|
// init database
|
||||||
// init depends//or set them the first time they are called?
|
// init depends//or set them the first time they are called?
|
||||||
}
|
}
|
||||||
|
|
@ -42,5 +46,36 @@ public class ChatImplementation implements ChatAPI{
|
||||||
return databaseConnection;
|
return databaseConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPrefix(UUID uuid) {
|
||||||
|
return getPrefix(uuid, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPrefix(UUID uuid, boolean all) {
|
||||||
|
// TODO cache these components on load, and return them here?
|
||||||
|
StringBuilder prefix = new StringBuilder();
|
||||||
|
LuckPerms luckPerms = getLuckPerms();
|
||||||
|
User user = luckPerms.getUserManager().getUser(uuid);
|
||||||
|
if(user == null) return "";
|
||||||
|
if(all) {
|
||||||
|
Collection<Group> inheritedGroups = user.getInheritedGroups(user.getQueryOptions());
|
||||||
|
inheritedGroups.stream()
|
||||||
|
.sorted(Comparator.comparingInt(o -> o.getWeight().orElse(0)))
|
||||||
|
.forEach(group -> {
|
||||||
|
if (Config.PREFIXGROUPS.contains(group.getName())) {
|
||||||
|
prefix.append("<white>[").append(group.getCachedData().getMetaData().getPrefix()).append("]</white>");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
prefix.append("<white>[").append(user.getCachedData().getMetaData().getPrefix()).append("]</white>");
|
||||||
|
return prefix.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getStaffPrefix(UUID uuid) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alttd.chat.config;
|
package com.alttd.velocitychat.config;
|
||||||
|
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
@ -28,8 +28,8 @@ public final class Config {
|
||||||
static int version;
|
static int version;
|
||||||
static boolean verbose;
|
static boolean verbose;
|
||||||
|
|
||||||
public static void init(File path) {
|
public static void init() {
|
||||||
CONFIG_FILE = new File(path, "config.yml");;
|
CONFIG_FILE = new File(new File(System.getProperty("user.home")), "config.yml");;
|
||||||
configLoader = YAMLConfigurationLoader.builder()
|
configLoader = YAMLConfigurationLoader.builder()
|
||||||
.setFile(CONFIG_FILE)
|
.setFile(CONFIG_FILE)
|
||||||
.setFlowStyle(DumperOptions.FlowStyle.BLOCK)
|
.setFlowStyle(DumperOptions.FlowStyle.BLOCK)
|
||||||
|
|
@ -150,9 +150,11 @@ public final class Config {
|
||||||
|
|
||||||
/** 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 String CONSOLENAME = "Console";
|
||||||
private static void settings() {
|
private static void settings() {
|
||||||
PREFIXGROUPS = getList("settings.prefix-groups",
|
PREFIXGROUPS = getList("settings.prefix-groups",
|
||||||
Lists.newArrayList("discord", "socialmedia", "eventteam", "eventleader", "youtube", "twitch", "developer"));
|
Lists.newArrayList("discord", "socialmedia", "eventteam", "eventleader", "youtube", "twitch", "developer"));
|
||||||
|
CONSOLENAME = getString("settings.console-name", CONSOLENAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> MESSAGECOMMANDALIASES = new ArrayList<>();
|
public static List<String> MESSAGECOMMANDALIASES = new ArrayList<>();
|
||||||
|
|
@ -168,13 +170,11 @@ public final class Config {
|
||||||
MESSAGERECIEVER = getString("commands.message.reciever-message", MESSAGERECIEVER);
|
MESSAGERECIEVER = getString("commands.message.reciever-message", MESSAGERECIEVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> GCCOMMANDALIASES = new ArrayList<>();
|
|
||||||
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></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></gray></white>";
|
||||||
public static String GCPERMISSION = "proxy.globalchat";
|
public static String GCPERMISSION = "proxy.globalchat";
|
||||||
private static void globalChat() {
|
private static void globalChat() {
|
||||||
MESSAGERECIEVER = getString("commands.globalchat.format", MESSAGERECIEVER);
|
MESSAGERECIEVER = getString("commands.globalchat.format", MESSAGERECIEVER);
|
||||||
GCPERMISSION = getString("commands.globalchat.view-chat-permission", GCPERMISSION);
|
GCPERMISSION = getString("commands.globalchat.view-chat-permission", GCPERMISSION);
|
||||||
GCCOMMANDALIASES = getList("commands.globalchat.aliases", Lists.newArrayList("gc"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> GACECOMMANDALIASES = new ArrayList<>();
|
public static List<String> GACECOMMANDALIASES = new ArrayList<>();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alttd.chat.database;
|
package com.alttd.velocitychat.database;
|
||||||
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package com.alttd.chat.database;
|
package com.alttd.velocitychat.database;
|
||||||
|
|
||||||
import com.alttd.chat.objects.Party;
|
import com.alttd.velocitychat.objects.Party;
|
||||||
import com.alttd.chat.objects.PartyUser;
|
import com.alttd.velocitychat.objects.PartyUser;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
|
@ -64,8 +64,8 @@ public class Queries {
|
||||||
|
|
||||||
//Ignore
|
//Ignore
|
||||||
|
|
||||||
public static void getIgnoredUsers() { //TODO store this in a user object or something?
|
public static void getIgnoredUsers() { //TODO store this in a user object or something? -> ChatPlayer
|
||||||
HashMap<UUID, ArrayList<UUID>> ignoredUsers = new HashMap<>(); //TODO Replace with a proper way/location to store this in
|
HashMap<UUID, ArrayList<UUID>> ignoredUsers = new HashMap<>(); //TODO Replace with a proper way/location to store this in -> a list<UUID> in ChatPlayer?
|
||||||
String query = "SELECT * FROM ignored_users";
|
String query = "SELECT * FROM ignored_users";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alttd.chat.objects;
|
package com.alttd.velocitychat.objects;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package com.alttd.chat.objects;
|
package com.alttd.velocitychat.objects;
|
||||||
|
|
||||||
import com.alttd.chat.database.Queries;
|
import com.alttd.velocitychat.database.Queries;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package com.alttd.chat.objects;
|
package com.alttd.velocitychat.objects;
|
||||||
|
|
||||||
import com.alttd.chat.database.Queries;
|
import com.alttd.velocitychat.database.Queries;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alttd.chat.objects;
|
package com.alttd.velocitychat.objects;
|
||||||
|
|
||||||
public class Regex {
|
public class Regex {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alttd.chat.objects;
|
package com.alttd.velocitychat.objects;
|
||||||
|
|
||||||
public enum RegexType {
|
public enum RegexType {
|
||||||
REPLACE("replace"),
|
REPLACE("replace"),
|
||||||
|
|
|
||||||
69
galaxy/dependency-reduced-pom.xml
Normal file
69
galaxy/dependency-reduced-pom.xml
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>Chat</artifactId>
|
||||||
|
<groupId>com.alttd.chat</groupId>
|
||||||
|
<version>1.0</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>galaxy-chat</artifactId>
|
||||||
|
<build>
|
||||||
|
<defaultGoal>clean package</defaultGoal>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
<finalName>${project.name}</finalName>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<artifactSet>
|
||||||
|
<includes>
|
||||||
|
<include>net.kyori:adventure-text-minimessage</include>
|
||||||
|
<include>com.alttd.chat:chat-api</include>
|
||||||
|
<include>org.spongepowered:configurate-yaml</include>
|
||||||
|
<include>org.spongepowered:configurate-core</include>
|
||||||
|
</includes>
|
||||||
|
<excludes>
|
||||||
|
<exclude>META-INF/*.MF</exclude>
|
||||||
|
</excludes>
|
||||||
|
</artifactSet>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>Alttd-Nexus</id>
|
||||||
|
<url>http://leo:8081/snapshots/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alttd.galaxy</groupId>
|
||||||
|
<artifactId>galaxy-api</artifactId>
|
||||||
|
<version>1.16.5-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.target>11</maven.compiler.target>
|
||||||
|
<maven.compiler.source>11</maven.compiler.source>
|
||||||
|
</properties>
|
||||||
|
</project>
|
||||||
|
|
@ -13,20 +13,46 @@
|
||||||
<groupId>com.alttd.chat</groupId>
|
<groupId>com.alttd.chat</groupId>
|
||||||
<artifactId>Chat</artifactId>
|
<artifactId>Chat</artifactId>
|
||||||
<version>1.0</version>
|
<version>1.0</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>galaxy-chat</artifactId>
|
<artifactId>galaxy-chat</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
<defaultGoal>clean package</defaultGoal>
|
||||||
|
<finalName>${project.name}</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.4</version>
|
||||||
|
<configuration>
|
||||||
|
<artifactSet>
|
||||||
|
<includes>
|
||||||
|
<include>net.kyori:adventure-text-minimessage</include>
|
||||||
|
<include>com.alttd.chat:chat-api</include>
|
||||||
|
<include>org.spongepowered:configurate-yaml</include>
|
||||||
|
<include>org.spongepowered:configurate-core</include>
|
||||||
|
</includes>
|
||||||
|
<excludes>
|
||||||
|
<exclude>META-INF/*.MF</exclude>
|
||||||
|
</excludes>
|
||||||
|
</artifactSet>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
<resources>
|
<resources>
|
||||||
|
|
@ -56,5 +82,10 @@
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency><!--TODO update to version 4.0.0-->
|
||||||
|
<groupId>org.spongepowered</groupId>
|
||||||
|
<artifactId>configurate-yaml</artifactId>
|
||||||
|
<version>3.7.1</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
52
galaxy/src/main/java/com/alttd/chat/ChatPlugin.java
Normal file
52
galaxy/src/main/java/com/alttd/chat/ChatPlugin.java
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.alttd.chat;
|
||||||
|
|
||||||
|
import com.alttd.chat.commands.GlobalChat;
|
||||||
|
import com.alttd.chat.handler.ChatHandler;
|
||||||
|
import com.alttd.chat.listeners.PlayerListener;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
public class ChatPlugin extends JavaPlugin {
|
||||||
|
|
||||||
|
private static ChatPlugin instance;
|
||||||
|
|
||||||
|
private ChatAPI chatAPI;
|
||||||
|
private ChatHandler chatHandler;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
instance = this;
|
||||||
|
chatAPI = new ChatImplementation();
|
||||||
|
chatHandler = new ChatHandler();
|
||||||
|
registerListener(new PlayerListener());
|
||||||
|
registerCommand("globalchat", new GlobalChat());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
instance = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerListener(Listener... listeners) {
|
||||||
|
for (Listener listener : listeners) {
|
||||||
|
getServer().getPluginManager().registerEvents(listener, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerCommand(String commandName, CommandExecutor CommandExecutor) {
|
||||||
|
getCommand(commandName).setExecutor(CommandExecutor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ChatPlugin getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChatAPI getChatAPI() {
|
||||||
|
return chatAPI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChatHandler getChatHandler() {
|
||||||
|
return chatHandler;
|
||||||
|
}
|
||||||
|
}
|
||||||
18
galaxy/src/main/java/com/alttd/chat/commands/GlobalChat.java
Normal file
18
galaxy/src/main/java/com/alttd/chat/commands/GlobalChat.java
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
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;
|
||||||
|
|
||||||
|
public class GlobalChat implements CommandExecutor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
String message = StringUtils.join(args, " ", 0, args.length);
|
||||||
|
ChatPlugin.getInstance().getChatHandler().globalChat(sender, message);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
49
galaxy/src/main/java/com/alttd/chat/handler/ChatHandler.java
Normal file
49
galaxy/src/main/java/com/alttd/chat/handler/ChatHandler.java
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.alttd.chat.handler;
|
||||||
|
|
||||||
|
import com.alttd.chat.ChatPlugin;
|
||||||
|
import com.alttd.chat.config.Config;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class ChatHandler {
|
||||||
|
|
||||||
|
private ChatPlugin plugin;
|
||||||
|
|
||||||
|
public ChatHandler() {
|
||||||
|
plugin = ChatPlugin.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void globalChat(CommandSender source, String message) {
|
||||||
|
String senderName, prefix = "";
|
||||||
|
Map<String, String> map = new HashMap<>();
|
||||||
|
|
||||||
|
if (source instanceof Player) {
|
||||||
|
Player sender = (Player) source;
|
||||||
|
senderName = sender.getDisplayName();
|
||||||
|
prefix = plugin.getChatAPI().getPrefix(sender.getUniqueId());
|
||||||
|
} else {
|
||||||
|
senderName = Config.CONSOLENAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
MiniMessage miniMessage = MiniMessage.get();
|
||||||
|
if(!source.hasPermission("chat.format"))
|
||||||
|
message = miniMessage.stripTokens(message);
|
||||||
|
|
||||||
|
map.put("sender", senderName);
|
||||||
|
map.put("message", message);
|
||||||
|
map.put("server", Bukkit.getServerName());
|
||||||
|
map.put("prefix", prefix);
|
||||||
|
|
||||||
|
Component component = miniMessage.parse(Config.GCFORMAT, map);
|
||||||
|
|
||||||
|
Bukkit.broadcast(component, Config.GCPERMISSION);
|
||||||
|
// TODO this should be a plugin message, so proxy can handle the forwarding, we only do this on server level for [i] support
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.alttd.chat.listeners;
|
||||||
|
|
||||||
|
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
public class PlayerListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
public void onPlayerChat(AsyncChatEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
}
|
||||||
11
galaxy/src/main/resources/plugin.yml
Normal file
11
galaxy/src/main/resources/plugin.yml
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
name: ChatPlugin
|
||||||
|
version: ${project.version}
|
||||||
|
main: com.alttd.chat.ChatPlugin
|
||||||
|
api-version: 1.16
|
||||||
|
authors: [Destro, Teriuihi]
|
||||||
|
depend: [LuckPerms]
|
||||||
|
commands:
|
||||||
|
globalchat:
|
||||||
|
permission: command.globalchat
|
||||||
|
permission-message: You do not have permission!
|
||||||
|
aliases: gc
|
||||||
|
|
@ -1,12 +1,14 @@
|
||||||
package com.alttd.chat;
|
package com.alttd.velocitychat;
|
||||||
|
|
||||||
import com.alttd.chat.commands.GlobalAdminChat;
|
import com.alttd.chat.ChatAPI;
|
||||||
import com.alttd.chat.commands.GlobalChat;
|
import com.alttd.chat.ChatImplementation;
|
||||||
import com.alttd.chat.commands.GlobalChatToggle;
|
import com.alttd.velocitychat.commands.GlobalAdminChat;
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.velocitychat.commands.GlobalChat;
|
||||||
|
import com.alttd.velocitychat.commands.GlobalChatToggle;
|
||||||
import com.alttd.chat.database.DatabaseConnection;
|
import com.alttd.chat.database.DatabaseConnection;
|
||||||
import com.alttd.chat.handlers.ChatHandler;
|
import com.alttd.velocitychat.handlers.ChatHandler;
|
||||||
import com.alttd.chat.listeners.ChatListener;
|
import com.alttd.velocitychat.listeners.ChatListener;
|
||||||
|
import com.alttd.velocitychat.listeners.PluginMessageListener;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||||
|
|
@ -14,6 +16,8 @@ import com.velocitypowered.api.plugin.Dependency;
|
||||||
import com.velocitypowered.api.plugin.Plugin;
|
import com.velocitypowered.api.plugin.Plugin;
|
||||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||||
|
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
@ -35,6 +39,9 @@ public class ChatPlugin {
|
||||||
private DatabaseConnection databaseConnection;
|
private DatabaseConnection databaseConnection;
|
||||||
private ChatHandler chatHandler;
|
private ChatHandler chatHandler;
|
||||||
|
|
||||||
|
private final ChannelIdentifier channelIdentifier =
|
||||||
|
MinecraftChannelIdentifier.from("customplugin:mychannel");
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ChatPlugin(ProxyServer proxyServer, Logger proxyLogger, @DataDirectory Path proxydataDirectory) {
|
public ChatPlugin(ProxyServer proxyServer, Logger proxyLogger, @DataDirectory Path proxydataDirectory) {
|
||||||
plugin = this;
|
plugin = this;
|
||||||
|
|
@ -45,8 +52,7 @@ public class ChatPlugin {
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||||
Config.init(getDataDirectory());
|
//Config.init(getDataDirectory());
|
||||||
loadCommands();
|
|
||||||
chatAPI = new ChatImplementation();
|
chatAPI = new ChatImplementation();
|
||||||
databaseConnection = chatAPI.getDataBase();
|
databaseConnection = chatAPI.getDataBase();
|
||||||
if (!databaseConnection.initialize()) {
|
if (!databaseConnection.initialize()) {
|
||||||
|
|
@ -55,6 +61,10 @@ public class ChatPlugin {
|
||||||
}
|
}
|
||||||
chatHandler = new ChatHandler();
|
chatHandler = new ChatHandler();
|
||||||
server.getEventManager().register(this, new ChatListener());
|
server.getEventManager().register(this, new ChatListener());
|
||||||
|
|
||||||
|
server.getEventManager().register(this, new PluginMessageListener(channelIdentifier));
|
||||||
|
|
||||||
|
loadCommands();
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getDataDirectory() {
|
public File getDataDirectory() {
|
||||||
|
|
@ -65,6 +75,9 @@ public class ChatPlugin {
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DatabaseConnection getDatabaseConnection() {
|
||||||
|
return databaseConnection;
|
||||||
|
}
|
||||||
|
|
||||||
public Logger getLogger() {
|
public Logger getLogger() {
|
||||||
return logger;
|
return logger;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alttd.chat.api;
|
package com.alttd.velocitychat.api;
|
||||||
|
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alttd.chat.api;
|
package com.alttd.velocitychat.api;
|
||||||
|
|
||||||
|
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package com.alttd.chat.commands;
|
package com.alttd.velocitychat.commands;
|
||||||
|
|
||||||
import com.alttd.chat.api.GlobalAdminChatEvent;
|
import com.alttd.velocitychat.api.GlobalAdminChatEvent;
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
package com.alttd.chat.commands;
|
package com.alttd.velocitychat.commands;
|
||||||
|
|
||||||
import com.alttd.chat.ChatPlugin;
|
|
||||||
import com.alttd.chat.config.Config;
|
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||||
|
|
@ -17,12 +15,11 @@ public class GlobalChat {
|
||||||
public GlobalChat(ProxyServer proxyServer) {
|
public GlobalChat(ProxyServer proxyServer) {
|
||||||
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder
|
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder
|
||||||
.<CommandSource>literal("globalchat")
|
.<CommandSource>literal("globalchat")
|
||||||
.requires(ctx -> ctx.hasPermission(Config.GCPERMISSION))
|
|
||||||
.requires(ctx -> ctx.hasPermission("command.proxy.globalchat"))// TODO permission system? load permissions from config?
|
.requires(ctx -> ctx.hasPermission("command.proxy.globalchat"))// TODO permission system? load permissions from config?
|
||||||
.then(RequiredArgumentBuilder
|
.then(RequiredArgumentBuilder
|
||||||
.<CommandSource, String>argument("message", StringArgumentType.greedyString())
|
.<CommandSource, String>argument("message", StringArgumentType.greedyString())
|
||||||
.executes(context -> {
|
.executes(context -> {
|
||||||
ChatPlugin.getPlugin().getChatHandler().globalChat(context.getSource(), context.getArgument("message", String.class));
|
//ChatPlugin.getPlugin().getChatHandler().globalChat(context.getSource(), context.getArgument("message", String.class));
|
||||||
return 1;
|
return 1;
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
@ -33,10 +30,6 @@ public class GlobalChat {
|
||||||
|
|
||||||
CommandMeta.Builder metaBuilder = proxyServer.getCommandManager().metaBuilder(brigadierCommand);
|
CommandMeta.Builder metaBuilder = proxyServer.getCommandManager().metaBuilder(brigadierCommand);
|
||||||
|
|
||||||
for (String alias : Config.GCCOMMANDALIASES) {
|
|
||||||
metaBuilder.aliases(alias);
|
|
||||||
}
|
|
||||||
|
|
||||||
CommandMeta meta = metaBuilder.build();
|
CommandMeta meta = metaBuilder.build();
|
||||||
|
|
||||||
proxyServer.getCommandManager().register(meta, brigadierCommand);
|
proxyServer.getCommandManager().register(meta, brigadierCommand);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package com.alttd.chat.commands;
|
package com.alttd.velocitychat.commands;
|
||||||
|
|
||||||
import com.alttd.chat.ChatPlugin;
|
import com.alttd.velocitychat.ChatPlugin;
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package com.alttd.chat.commands;
|
package com.alttd.velocitychat.commands;
|
||||||
|
|
||||||
import com.alttd.chat.ChatPlugin;
|
import com.alttd.velocitychat.ChatPlugin;
|
||||||
import com.alttd.chat.api.PrivateMessageEvent;
|
import com.alttd.velocitychat.api.PrivateMessageEvent;
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.alttd.chat.config;
|
package com.alttd.velocitychat.config;
|
||||||
|
|
||||||
|
import com.alttd.chat.config.Config;
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
|
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
package com.alttd.chat.handlers;
|
package com.alttd.velocitychat.handlers;
|
||||||
|
|
||||||
import com.alttd.chat.ChatPlugin;
|
import com.alttd.velocitychat.ChatPlugin;
|
||||||
import com.alttd.chat.api.PrivateMessageEvent;
|
import com.alttd.velocitychat.api.PrivateMessageEvent;
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
|
import com.alttd.chat.objects.ChatPlayer;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
package com.alttd.chat.listeners;
|
package com.alttd.velocitychat.listeners;
|
||||||
|
|
||||||
import com.alttd.chat.ChatPlugin;
|
import com.alttd.velocitychat.ChatPlugin;
|
||||||
import com.alttd.chat.api.GlobalAdminChatEvent;
|
import com.alttd.velocitychat.api.GlobalAdminChatEvent;
|
||||||
import com.alttd.chat.api.PrivateMessageEvent;
|
import com.alttd.velocitychat.api.PrivateMessageEvent;
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
import com.velocitypowered.api.event.PostOrder;
|
import com.velocitypowered.api.event.PostOrder;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package com.alttd.chat.listeners;
|
package com.alttd.velocitychat.listeners;
|
||||||
|
|
||||||
import com.alttd.chat.ChatPlugin;
|
import com.alttd.velocitychat.ChatPlugin;
|
||||||
import com.alttd.chat.handlers.ChatPlayer;
|
import com.alttd.chat.objects.ChatPlayer;
|
||||||
import com.velocitypowered.api.event.PostOrder;
|
import com.velocitypowered.api.event.PostOrder;
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
||||||
|
|
@ -11,7 +11,7 @@ public class PlayerListener {
|
||||||
|
|
||||||
@Subscribe(order = PostOrder.FIRST)
|
@Subscribe(order = PostOrder.FIRST)
|
||||||
public void onPlayerLogin(LoginEvent event) {
|
public void onPlayerLogin(LoginEvent event) {
|
||||||
ChatPlugin.getPlugin().getChatHandler().addPlayer(new ChatPlayer(event.getPlayer()));
|
ChatPlugin.getPlugin().getChatHandler().addPlayer(new ChatPlayer(event.getPlayer().getUniqueId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alttd.chat.util;
|
package com.alttd.velocitychat.util;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user