Add plugin
This commit is contained in:
@@ -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>
|
||||
<artifactId>Chat</artifactId>
|
||||
<version>1.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>galaxy-chat</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean package</defaultGoal>
|
||||
<finalName>${project.name}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<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>
|
||||
</plugins>
|
||||
<resources>
|
||||
@@ -56,5 +82,10 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency><!--TODO update to version 4.0.0-->
|
||||
<groupId>org.spongepowered</groupId>
|
||||
<artifactId>configurate-yaml</artifactId>
|
||||
<version>3.7.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user