mirror of
https://github.com/darksaid98/TownyChat.git
synced 2026-12-01 14:38:57 +00:00
feat: tag resolvers
This commit is contained in:
5 files changed
+577
-573
No files matched your search
@@ -1,181 +1,181 @@
|
||||
<?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/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.palmergames.bukkit</groupId>
|
||||
<artifactId>TownyChat</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>0.112</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>CC BY-NC-ND 3.0</name>
|
||||
<url>http://creativecommons.org/licenses/by-nc-nd/3.0/</url>
|
||||
<comments>Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported</comments>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<organization>
|
||||
<name>TownyAdvanced</name>
|
||||
<url>https://github.com/TownyAdvanced</url>
|
||||
</organization>
|
||||
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<project.bukkitAPIVersion>1.16</project.bukkitAPIVersion>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<towny.version>0.100.0.0</towny.version>
|
||||
</properties>
|
||||
|
||||
<!-- For use with GitHub Package Registry -->
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>github</id>
|
||||
<name>GitHub TownyAdvanced Apache Maven Packages</name>
|
||||
<url>https://maven.pkg.github.com/TownyAdvanced</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:https://github.com/TownyAdvanced/TownyChat.git</connection>
|
||||
<developerConnection>scm:git:https://github.com/TownyAdvanced/TownyChat.git</developerConnection>
|
||||
<url>https://github.com/TownyAdvanced/TownyChat</url>
|
||||
</scm>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>papermc</id>
|
||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>essentials-releases</id>
|
||||
<url>https://repo.essentialsx.net/releases/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>dynmap-repo</id>
|
||||
<url>https://repo.mikeprimm.com</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>glaremasters repo</id>
|
||||
<url>https://repo.glaremasters.me/repository/towny/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>placeholderapi</id>
|
||||
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.palmergames.bukkit.towny</groupId>
|
||||
<artifactId>towny</artifactId>
|
||||
<version>${towny.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.20.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.essentialsx</groupId>
|
||||
<artifactId>EssentialsX</artifactId>
|
||||
<version>2.19.0</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>us.dynmap</groupId>
|
||||
<artifactId>dynmap-api</artifactId>
|
||||
<version>3.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.11.5</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.EssentialsX.Essentials</groupId>
|
||||
<artifactId>EssentialsXDiscord</artifactId>
|
||||
<version>57600f333c</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>net.dv8tion</groupId>
|
||||
<artifactId>JDA</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>16.0.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.bsideup.jabel</groupId>
|
||||
<artifactId>jabel-javac-plugin</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-api</artifactId>
|
||||
<version>4.14.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-minimessage</artifactId>
|
||||
<version>4.14.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-serializer-legacy</artifactId>
|
||||
<version>4.14.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean package</defaultGoal>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.11.0</version>
|
||||
<configuration>
|
||||
<release>8</release>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
<compilerArgs>
|
||||
<arg>-Xplugin:jabel</arg>
|
||||
</compilerArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
<?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/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.palmergames.bukkit</groupId>
|
||||
<artifactId>TownyChat</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>0.112</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>CC BY-NC-ND 3.0</name>
|
||||
<url>http://creativecommons.org/licenses/by-nc-nd/3.0/</url>
|
||||
<comments>Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported</comments>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<organization>
|
||||
<name>TownyAdvanced</name>
|
||||
<url>https://github.com/TownyAdvanced</url>
|
||||
</organization>
|
||||
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<project.bukkitAPIVersion>1.16</project.bukkitAPIVersion>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<towny.version>0.100.0.0</towny.version>
|
||||
</properties>
|
||||
|
||||
<!-- For use with GitHub Package Registry -->
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>github</id>
|
||||
<name>GitHub TownyAdvanced Apache Maven Packages</name>
|
||||
<url>https://maven.pkg.github.com/TownyAdvanced</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:https://github.com/TownyAdvanced/TownyChat.git</connection>
|
||||
<developerConnection>scm:git:https://github.com/TownyAdvanced/TownyChat.git</developerConnection>
|
||||
<url>https://github.com/TownyAdvanced/TownyChat</url>
|
||||
</scm>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>papermc</id>
|
||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>essentials-releases</id>
|
||||
<url>https://repo.essentialsx.net/releases/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>dynmap-repo</id>
|
||||
<url>https://repo.mikeprimm.com</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>glaremasters repo</id>
|
||||
<url>https://repo.glaremasters.me/repository/towny/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>placeholderapi</id>
|
||||
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.palmergames.bukkit.towny</groupId>
|
||||
<artifactId>towny</artifactId>
|
||||
<version>${towny.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.20.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.essentialsx</groupId>
|
||||
<artifactId>EssentialsX</artifactId>
|
||||
<version>2.19.0</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>us.dynmap</groupId>
|
||||
<artifactId>dynmap-api</artifactId>
|
||||
<version>3.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.11.5</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.EssentialsX.Essentials</groupId>
|
||||
<artifactId>EssentialsXDiscord</artifactId>
|
||||
<version>57600f333c</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>net.dv8tion</groupId>
|
||||
<artifactId>JDA</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>16.0.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.bsideup.jabel</groupId>
|
||||
<artifactId>jabel-javac-plugin</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-api</artifactId>
|
||||
<version>4.14.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-minimessage</artifactId>
|
||||
<version>4.14.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-serializer-legacy</artifactId>
|
||||
<version>4.14.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean package</defaultGoal>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.11.0</version>
|
||||
<configuration>
|
||||
<release>8</release>
|
||||
<source>14</source>
|
||||
<target>14</target>
|
||||
<compilerArgs>
|
||||
<arg>-Xplugin:jabel</arg>
|
||||
</compilerArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
</project>
|
||||
@@ -1,333 +1,333 @@
|
||||
package com.palmergames.bukkit.TownyChat;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.palmergames.adventure.platform.bukkit.BukkitAudiences;
|
||||
import com.palmergames.bukkit.TownyChat.Command.ChannelCommand;
|
||||
import com.palmergames.bukkit.TownyChat.Command.TownyChatCommand;
|
||||
import com.palmergames.bukkit.TownyChat.Command.commandobjects.ChannelJoinAliasCommand;
|
||||
import com.palmergames.bukkit.TownyChat.channels.Channel;
|
||||
import com.palmergames.bukkit.TownyChat.channels.ChannelsHolder;
|
||||
import com.palmergames.bukkit.TownyChat.config.ChatSettings;
|
||||
import com.palmergames.bukkit.TownyChat.config.ChannelsSettings;
|
||||
import com.palmergames.bukkit.TownyChat.listener.EssentialsDiscordHookListener;
|
||||
import com.palmergames.bukkit.TownyChat.listener.TownyChatPlayerListener;
|
||||
import com.palmergames.bukkit.TownyChat.tasks.onLoadedTask;
|
||||
import com.palmergames.bukkit.TownyChat.util.EssentialsIntegration;
|
||||
import com.palmergames.bukkit.towny.Towny;
|
||||
import com.palmergames.bukkit.towny.scheduling.TaskScheduler;
|
||||
import com.palmergames.bukkit.towny.scheduling.impl.BukkitTaskScheduler;
|
||||
import com.palmergames.bukkit.towny.scheduling.impl.FoliaTaskScheduler;
|
||||
import com.palmergames.util.FileMgmt;
|
||||
import com.palmergames.util.JavaUtil;
|
||||
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.dynmap.DynmapAPI;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
* Chat plugin to manage all Towny chat
|
||||
*
|
||||
* Website: http://code.google.com/a/eclipselabs.org/p/towny/
|
||||
*
|
||||
* @author ElgarL
|
||||
*/
|
||||
|
||||
public class Chat extends JavaPlugin {
|
||||
|
||||
private TownyChatPlayerListener TownyPlayerListener;
|
||||
private ChannelsHolder channels;
|
||||
|
||||
protected PluginManager pm;
|
||||
private static Chat chat = null;
|
||||
private final Object scheduler;
|
||||
private Towny towny = null;
|
||||
private DynmapAPI dynMap = null;
|
||||
private Essentials essentials = null;
|
||||
private BukkitAudiences adventure = null;
|
||||
private MiniMessage miniMessage = null;
|
||||
|
||||
private static String requiredTownyVersion = "0.100.0.0";
|
||||
public static boolean usingPlaceholderAPI = false;
|
||||
public static boolean usingEssentialsDiscord = false;
|
||||
boolean chatConfigError = false;
|
||||
boolean channelsConfigError = false;
|
||||
private static ConcurrentMap<UUID, Channel> playerChannelMap;
|
||||
|
||||
public Chat() {
|
||||
chat = this;
|
||||
this.scheduler = townyVersionCheck() ? isFoliaClassPresent() ? new FoliaTaskScheduler(this) : new BukkitTaskScheduler(this) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
pm = getServer().getPluginManager();
|
||||
channels = new ChannelsHolder(this);
|
||||
playerChannelMap = new ConcurrentHashMap<>();
|
||||
adventure = BukkitAudiences.create(this);
|
||||
miniMessage = MiniMessage.builder().build();
|
||||
|
||||
checkPlugins();
|
||||
if (towny == null || !townyVersionCheck()) {
|
||||
disableWithMessage("Towny version does not meet required minimum version: " + requiredTownyVersion.toString());
|
||||
return;
|
||||
} else {
|
||||
getLogger().info("Towny version " + towny.getDescription().getVersion() + " found.");
|
||||
}
|
||||
|
||||
loadConfigs();
|
||||
if (channelsConfigError || chatConfigError) {
|
||||
disableWithMessage("The config could not be loaded.");
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* This executes the task with a 1 tick delay avoiding the bukkit depends bug.
|
||||
* TODO: What bug is this referencing? This goes back to the first version of TownyChat.
|
||||
*/
|
||||
getScheduler().run(new onLoadedTask(this));
|
||||
|
||||
getCommand("townychat").setExecutor(new TownyChatCommand(this));
|
||||
getCommand("channel").setExecutor(new ChannelCommand(this));
|
||||
registerObjectCommands();
|
||||
}
|
||||
|
||||
private void disableWithMessage(String message) {
|
||||
getLogger().severe(message);
|
||||
getLogger().severe("Disabling TownyChat...");
|
||||
pm.disablePlugin(this);
|
||||
}
|
||||
|
||||
private boolean townyVersionCheck() {
|
||||
try {
|
||||
return Towny.isTownyVersionSupported(requiredTownyVersion);
|
||||
} catch (NoSuchMethodError e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void loadConfigs() {
|
||||
FileMgmt.checkOrCreateFolders(new String[] { getRootPath(), getTownySettingsPath() });
|
||||
chatConfigError = !ChatSettings.loadCommentedChatConfig();
|
||||
channelsConfigError = !ChannelsSettings.loadCommentedChannelsConfig();
|
||||
}
|
||||
|
||||
public static Chat getTownyChat() {
|
||||
return chat;
|
||||
}
|
||||
|
||||
public @NonNull BukkitAudiences adventure() {
|
||||
if(this.adventure == null) {
|
||||
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
|
||||
}
|
||||
return this.adventure;
|
||||
}
|
||||
|
||||
public @NonNull MiniMessage getMiniMessage() {
|
||||
return miniMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
unregisterPermissions();
|
||||
// reset any handles
|
||||
|
||||
if (adventure != null) {
|
||||
adventure.close();
|
||||
adventure = null;
|
||||
}
|
||||
miniMessage = null;
|
||||
dynMap = null;
|
||||
towny = null;
|
||||
pm = null;
|
||||
|
||||
channels = null;
|
||||
playerChannelMap = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a reload of this plugin.
|
||||
*/
|
||||
public void reload() {
|
||||
onDisable();
|
||||
onEnable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to hook any plugins we want to access.
|
||||
*/
|
||||
private void checkPlugins() {
|
||||
Plugin test;
|
||||
|
||||
test = pm.getPlugin("Towny");
|
||||
if (test != null && test instanceof Towny)
|
||||
towny = (Towny) test;
|
||||
|
||||
test = pm.getPlugin("dynmap");
|
||||
if (test != null && pm.getPlugin("dynmap").isEnabled()) {
|
||||
dynMap = (DynmapAPI) test;
|
||||
}
|
||||
|
||||
test = pm.getPlugin("PlaceholderAPI");
|
||||
if (test != null) {
|
||||
usingPlaceholderAPI = true;
|
||||
}
|
||||
|
||||
test = pm.getPlugin("EssentialsDiscord");
|
||||
if (test != null) {
|
||||
usingEssentialsDiscord = true;
|
||||
}
|
||||
|
||||
test = pm.getPlugin("Essentials");
|
||||
if (test != null && JavaUtil.classExists("com.earth2me.essentials.Essentials")) {
|
||||
this.essentials = (Essentials) test;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void registerEvents() {
|
||||
|
||||
if (TownyPlayerListener == null) {
|
||||
TownyPlayerListener = new TownyChatPlayerListener(this);
|
||||
|
||||
if (TownyPlayerListener != null)
|
||||
pm.registerEvents(TownyPlayerListener, this);
|
||||
}
|
||||
|
||||
if (usingEssentialsDiscord) {
|
||||
pm.registerEvents(new EssentialsDiscordHookListener(this), this);
|
||||
}
|
||||
}
|
||||
|
||||
public void registerPermissions() {
|
||||
// Register all Permissions.
|
||||
for (String perm : getChannelsHandler().getAllPermissions()) {
|
||||
try {
|
||||
pm.addPermission(new Permission(perm, new HashMap<String, Boolean>()));
|
||||
} catch (IllegalArgumentException e) {
|
||||
//permission already registered.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterPermissions() {
|
||||
// Register all Permissions.
|
||||
for (String perm : getChannelsHandler().getAllPermissions()) {
|
||||
pm.removePermission(new Permission(perm, new HashMap<String, Boolean>()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getRootPath() {
|
||||
return getTowny().getDataFolder().getPath();
|
||||
}
|
||||
|
||||
public String getTownySettingsPath() {
|
||||
return getRootPath() + File.separator + "settings";
|
||||
}
|
||||
|
||||
public String getChatConfigPath() {
|
||||
return getTownySettingsPath() + File.separator + "ChatConfig.yml";
|
||||
}
|
||||
|
||||
public String getChannelsConfigPath() {
|
||||
return getTownySettingsPath() + File.separator + "Channels.yml";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the channels
|
||||
*/
|
||||
public ChannelsHolder getChannelsHandler() {
|
||||
return channels;
|
||||
}
|
||||
|
||||
public Towny getTowny() {
|
||||
return towny;
|
||||
}
|
||||
|
||||
public DynmapAPI getDynmap() {
|
||||
return dynMap;
|
||||
}
|
||||
|
||||
public boolean isUsingEssentials() {
|
||||
return essentials != null;
|
||||
}
|
||||
|
||||
public Essentials getEssentials() {
|
||||
return essentials;
|
||||
}
|
||||
|
||||
public boolean isEssentialsMuted(Player player) {
|
||||
if (!isUsingEssentials())
|
||||
return false;
|
||||
return EssentialsIntegration.isMuted(player);
|
||||
}
|
||||
|
||||
public boolean isIgnoredByEssentials(Player sender, Player player) {
|
||||
if (!isUsingEssentials())
|
||||
return false;
|
||||
return EssentialsIntegration.ignoredByEssentials(sender, player);
|
||||
}
|
||||
|
||||
private void registerObjectCommands() {
|
||||
List<Command> commands = new ArrayList<Command>();
|
||||
for (Channel channel : channels.getAllChannels().values()) { // All channels
|
||||
for (String cmd : channel.getCommands()) { // All Commands of All Channels
|
||||
commands.add(new ChannelJoinAliasCommand(cmd, channel, this));
|
||||
}
|
||||
}
|
||||
try {
|
||||
final Field bukkitCommandMap = Bukkit.getServer().getClass().getDeclaredField("commandMap");
|
||||
|
||||
bukkitCommandMap.setAccessible(true);
|
||||
CommandMap commandMap = (CommandMap) bukkitCommandMap.get(Bukkit.getServer());
|
||||
|
||||
commandMap.registerAll("TownyChat", commands);
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public TownyChatPlayerListener getTownyPlayerListener() {
|
||||
return TownyPlayerListener;
|
||||
}
|
||||
|
||||
public Channel getPlayerChannel(Player player) {
|
||||
return playerChannelMap.get(player.getUniqueId());
|
||||
}
|
||||
|
||||
public void setPlayerChannel(Player player, Channel channel) {
|
||||
playerChannelMap.put(player.getUniqueId(), channel);
|
||||
}
|
||||
|
||||
public TaskScheduler getScheduler() {
|
||||
return (TaskScheduler) this.scheduler;
|
||||
}
|
||||
|
||||
private static boolean isFoliaClassPresent() {
|
||||
try {
|
||||
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
|
||||
return true;
|
||||
} catch (ClassNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
package com.palmergames.bukkit.TownyChat;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.palmergames.adventure.platform.bukkit.BukkitAudiences;
|
||||
import com.palmergames.bukkit.TownyChat.Command.ChannelCommand;
|
||||
import com.palmergames.bukkit.TownyChat.Command.TownyChatCommand;
|
||||
import com.palmergames.bukkit.TownyChat.Command.commandobjects.ChannelJoinAliasCommand;
|
||||
import com.palmergames.bukkit.TownyChat.channels.Channel;
|
||||
import com.palmergames.bukkit.TownyChat.channels.ChannelsHolder;
|
||||
import com.palmergames.bukkit.TownyChat.config.ChatSettings;
|
||||
import com.palmergames.bukkit.TownyChat.config.ChannelsSettings;
|
||||
import com.palmergames.bukkit.TownyChat.listener.EssentialsDiscordHookListener;
|
||||
import com.palmergames.bukkit.TownyChat.listener.TownyChatPlayerListener;
|
||||
import com.palmergames.bukkit.TownyChat.tasks.onLoadedTask;
|
||||
import com.palmergames.bukkit.TownyChat.util.EssentialsIntegration;
|
||||
import com.palmergames.bukkit.towny.Towny;
|
||||
import com.palmergames.bukkit.towny.scheduling.TaskScheduler;
|
||||
import com.palmergames.bukkit.towny.scheduling.impl.BukkitTaskScheduler;
|
||||
import com.palmergames.bukkit.towny.scheduling.impl.FoliaTaskScheduler;
|
||||
import com.palmergames.util.FileMgmt;
|
||||
import com.palmergames.util.JavaUtil;
|
||||
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.dynmap.DynmapAPI;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
* Chat plugin to manage all Towny chat
|
||||
*
|
||||
* Website: http://code.google.com/a/eclipselabs.org/p/towny/
|
||||
*
|
||||
* @author ElgarL
|
||||
*/
|
||||
|
||||
public class Chat extends JavaPlugin {
|
||||
|
||||
private TownyChatPlayerListener TownyPlayerListener;
|
||||
private ChannelsHolder channels;
|
||||
|
||||
protected PluginManager pm;
|
||||
private static Chat chat = null;
|
||||
private final Object scheduler;
|
||||
private Towny towny = null;
|
||||
private DynmapAPI dynMap = null;
|
||||
private Essentials essentials = null;
|
||||
private BukkitAudiences adventure = null;
|
||||
private MiniMessage miniMessage = null;
|
||||
|
||||
private static String requiredTownyVersion = "0.98.0.0";
|
||||
public static boolean usingPlaceholderAPI = false;
|
||||
public static boolean usingEssentialsDiscord = false;
|
||||
boolean chatConfigError = false;
|
||||
boolean channelsConfigError = false;
|
||||
private static ConcurrentMap<UUID, Channel> playerChannelMap;
|
||||
|
||||
public Chat() {
|
||||
chat = this;
|
||||
this.scheduler = townyVersionCheck() ? isFoliaClassPresent() ? new FoliaTaskScheduler(this) : new BukkitTaskScheduler(this) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
pm = getServer().getPluginManager();
|
||||
channels = new ChannelsHolder(this);
|
||||
playerChannelMap = new ConcurrentHashMap<>();
|
||||
adventure = BukkitAudiences.create(this);
|
||||
miniMessage = MiniMessage.builder().build();
|
||||
|
||||
checkPlugins();
|
||||
if (towny == null || !townyVersionCheck()) {
|
||||
disableWithMessage("Towny version does not meet required minimum version: " + requiredTownyVersion.toString());
|
||||
return;
|
||||
} else {
|
||||
getLogger().info("Towny version " + towny.getDescription().getVersion() + " found.");
|
||||
}
|
||||
|
||||
loadConfigs();
|
||||
if (channelsConfigError || chatConfigError) {
|
||||
disableWithMessage("The config could not be loaded.");
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* This executes the task with a 1 tick delay avoiding the bukkit depends bug.
|
||||
* TODO: What bug is this referencing? This goes back to the first version of TownyChat.
|
||||
*/
|
||||
getScheduler().run(new onLoadedTask(this));
|
||||
|
||||
getCommand("townychat").setExecutor(new TownyChatCommand(this));
|
||||
getCommand("channel").setExecutor(new ChannelCommand(this));
|
||||
registerObjectCommands();
|
||||
}
|
||||
|
||||
private void disableWithMessage(String message) {
|
||||
getLogger().severe(message);
|
||||
getLogger().severe("Disabling TownyChat...");
|
||||
pm.disablePlugin(this);
|
||||
}
|
||||
|
||||
private boolean townyVersionCheck() {
|
||||
try {
|
||||
return Towny.isTownyVersionSupported(requiredTownyVersion);
|
||||
} catch (NoSuchMethodError e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void loadConfigs() {
|
||||
FileMgmt.checkOrCreateFolders(new String[] { getRootPath(), getTownySettingsPath() });
|
||||
chatConfigError = !ChatSettings.loadCommentedChatConfig();
|
||||
channelsConfigError = !ChannelsSettings.loadCommentedChannelsConfig();
|
||||
}
|
||||
|
||||
public static Chat getTownyChat() {
|
||||
return chat;
|
||||
}
|
||||
|
||||
public @NonNull BukkitAudiences adventure() {
|
||||
if(this.adventure == null) {
|
||||
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
|
||||
}
|
||||
return this.adventure;
|
||||
}
|
||||
|
||||
public @NonNull MiniMessage getMiniMessage() {
|
||||
return miniMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
unregisterPermissions();
|
||||
// reset any handles
|
||||
|
||||
if (adventure != null) {
|
||||
adventure.close();
|
||||
adventure = null;
|
||||
}
|
||||
miniMessage = null;
|
||||
dynMap = null;
|
||||
towny = null;
|
||||
pm = null;
|
||||
|
||||
channels = null;
|
||||
playerChannelMap = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a reload of this plugin.
|
||||
*/
|
||||
public void reload() {
|
||||
onDisable();
|
||||
onEnable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to hook any plugins we want to access.
|
||||
*/
|
||||
private void checkPlugins() {
|
||||
Plugin test;
|
||||
|
||||
test = pm.getPlugin("Towny");
|
||||
if (test != null && test instanceof Towny)
|
||||
towny = (Towny) test;
|
||||
|
||||
test = pm.getPlugin("dynmap");
|
||||
if (test != null && pm.getPlugin("dynmap").isEnabled()) {
|
||||
dynMap = (DynmapAPI) test;
|
||||
}
|
||||
|
||||
test = pm.getPlugin("PlaceholderAPI");
|
||||
if (test != null) {
|
||||
usingPlaceholderAPI = true;
|
||||
}
|
||||
|
||||
test = pm.getPlugin("EssentialsDiscord");
|
||||
if (test != null) {
|
||||
usingEssentialsDiscord = true;
|
||||
}
|
||||
|
||||
test = pm.getPlugin("Essentials");
|
||||
if (test != null && JavaUtil.classExists("com.earth2me.essentials.Essentials")) {
|
||||
this.essentials = (Essentials) test;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void registerEvents() {
|
||||
|
||||
if (TownyPlayerListener == null) {
|
||||
TownyPlayerListener = new TownyChatPlayerListener(this);
|
||||
|
||||
if (TownyPlayerListener != null)
|
||||
pm.registerEvents(TownyPlayerListener, this);
|
||||
}
|
||||
|
||||
if (usingEssentialsDiscord) {
|
||||
pm.registerEvents(new EssentialsDiscordHookListener(this), this);
|
||||
}
|
||||
}
|
||||
|
||||
public void registerPermissions() {
|
||||
// Register all Permissions.
|
||||
for (String perm : getChannelsHandler().getAllPermissions()) {
|
||||
try {
|
||||
pm.addPermission(new Permission(perm, new HashMap<String, Boolean>()));
|
||||
} catch (IllegalArgumentException e) {
|
||||
//permission already registered.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterPermissions() {
|
||||
// Register all Permissions.
|
||||
for (String perm : getChannelsHandler().getAllPermissions()) {
|
||||
pm.removePermission(new Permission(perm, new HashMap<String, Boolean>()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getRootPath() {
|
||||
return getTowny().getDataFolder().getPath();
|
||||
}
|
||||
|
||||
public String getTownySettingsPath() {
|
||||
return getRootPath() + File.separator + "settings";
|
||||
}
|
||||
|
||||
public String getChatConfigPath() {
|
||||
return getTownySettingsPath() + File.separator + "ChatConfig.yml";
|
||||
}
|
||||
|
||||
public String getChannelsConfigPath() {
|
||||
return getTownySettingsPath() + File.separator + "Channels.yml";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the channels
|
||||
*/
|
||||
public ChannelsHolder getChannelsHandler() {
|
||||
return channels;
|
||||
}
|
||||
|
||||
public Towny getTowny() {
|
||||
return towny;
|
||||
}
|
||||
|
||||
public DynmapAPI getDynmap() {
|
||||
return dynMap;
|
||||
}
|
||||
|
||||
public boolean isUsingEssentials() {
|
||||
return essentials != null;
|
||||
}
|
||||
|
||||
public Essentials getEssentials() {
|
||||
return essentials;
|
||||
}
|
||||
|
||||
public boolean isEssentialsMuted(Player player) {
|
||||
if (!isUsingEssentials())
|
||||
return false;
|
||||
return EssentialsIntegration.isMuted(player);
|
||||
}
|
||||
|
||||
public boolean isIgnoredByEssentials(Player sender, Player player) {
|
||||
if (!isUsingEssentials())
|
||||
return false;
|
||||
return EssentialsIntegration.ignoredByEssentials(sender, player);
|
||||
}
|
||||
|
||||
private void registerObjectCommands() {
|
||||
List<Command> commands = new ArrayList<Command>();
|
||||
for (Channel channel : channels.getAllChannels().values()) { // All channels
|
||||
for (String cmd : channel.getCommands()) { // All Commands of All Channels
|
||||
commands.add(new ChannelJoinAliasCommand(cmd, channel, this));
|
||||
}
|
||||
}
|
||||
try {
|
||||
final Field bukkitCommandMap = Bukkit.getServer().getClass().getDeclaredField("commandMap");
|
||||
|
||||
bukkitCommandMap.setAccessible(true);
|
||||
CommandMap commandMap = (CommandMap) bukkitCommandMap.get(Bukkit.getServer());
|
||||
|
||||
commandMap.registerAll("TownyChat", commands);
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public TownyChatPlayerListener getTownyPlayerListener() {
|
||||
return TownyPlayerListener;
|
||||
}
|
||||
|
||||
public Channel getPlayerChannel(Player player) {
|
||||
return playerChannelMap.get(player.getUniqueId());
|
||||
}
|
||||
|
||||
public void setPlayerChannel(Player player, Channel channel) {
|
||||
playerChannelMap.put(player.getUniqueId(), channel);
|
||||
}
|
||||
|
||||
public TaskScheduler getScheduler() {
|
||||
return (TaskScheduler) this.scheduler;
|
||||
}
|
||||
|
||||
private static boolean isFoliaClassPresent() {
|
||||
try {
|
||||
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
|
||||
return true;
|
||||
} catch (ClassNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,62 +1,23 @@
|
||||
package com.palmergames.bukkit.TownyChat;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.Context;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.palmergames.bukkit.TownyChat.config.ChatSettings;
|
||||
import com.palmergames.bukkit.TownyChat.listener.LocalTownyChatEvent;
|
||||
import com.palmergames.bukkit.TownyChat.util.StringReplaceManager;
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.TownySettings;
|
||||
import com.palmergames.bukkit.towny.TownyUniverse;
|
||||
import com.palmergames.bukkit.towny.object.Government;
|
||||
import com.palmergames.bukkit.towny.object.Nation;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.util.Colors;
|
||||
import com.palmergames.util.StringMgmt;
|
||||
import com.palmergames.bukkit.towny.TownyUniverse;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TownyChatFormatter {
|
||||
private static StringReplaceManager<LocalTownyChatEvent> replacer = new StringReplaceManager<LocalTownyChatEvent>();
|
||||
|
||||
static {
|
||||
replacer.registerReplacer("{worldname}", event -> getWorldTag(event));
|
||||
replacer.registerReplacer("{town}", event -> getTownName(event.getResident()));
|
||||
replacer.registerReplacer("{townformatted}", event -> formatTownTag(event.getResident(), false, true));
|
||||
replacer.registerReplacer("{towntag}", event -> formatTownTag(event.getResident(), false, false));
|
||||
replacer.registerReplacer("{towntagoverride}", event -> formatTownTag(event.getResident(), true, false));
|
||||
replacer.registerReplacer("{nation}", event -> getNationName(event.getResident()));
|
||||
replacer.registerReplacer("{nationformatted}", event -> formatNationTag(event.getResident(), false, true));
|
||||
replacer.registerReplacer("{nationtag}", event -> formatNationTag(event.getResident(), false, false));
|
||||
replacer.registerReplacer("{nationtagoverride}", event -> formatNationTag(event.getResident(), true, false));
|
||||
replacer.registerReplacer("{townytag}", event -> formatTownyTag(event.getResident(), false, false));
|
||||
replacer.registerReplacer("{townyformatted}", event -> formatTownyTag(event.getResident(), false, true));
|
||||
replacer.registerReplacer("{townytagoverride}", event -> formatTownyTag(event.getResident(), true, false));
|
||||
replacer.registerReplacer("{title}", event -> getPrefix(event.getResident(), true));
|
||||
replacer.registerReplacer("{surname}", event -> getSuffix(event.getResident(), false));
|
||||
replacer.registerReplacer("{townynameprefix}", event -> getNamePrefix(event.getResident()));
|
||||
replacer.registerReplacer("{townynamepostfix}", event -> getNamePostfix(event.getResident()));
|
||||
replacer.registerReplacer("{townyprefix}", event -> getPrefix(event.getResident(), false));
|
||||
replacer.registerReplacer("{townypostfix}", event -> getSuffix(event.getResident(), false));
|
||||
replacer.registerReplacer("{townycolor}", event -> getTownyColour(event.getResident()));
|
||||
replacer.registerReplacer("{group}", event -> getVaultGroup(event.getEvent().getPlayer()));
|
||||
replacer.registerReplacer("{permprefix}", event -> getVaultPrefixSuffix(event.getResident(), "prefix"));
|
||||
replacer.registerReplacer("{permsuffix}", event -> getVaultPrefixSuffix(event.getResident(), "suffix"));
|
||||
replacer.registerReplacer("{permuserprefix}", event -> getVaultPrefixSuffix(event.getResident(), "userprefix"));
|
||||
replacer.registerReplacer("{permusersuffix}", event -> getVaultPrefixSuffix(event.getResident(), "usersuffix"));
|
||||
replacer.registerReplacer("{permgroupprefix}", event -> getVaultPrefixSuffix(event.getResident(), "groupprefix"));
|
||||
replacer.registerReplacer("{permgroupsuffix}", event -> getVaultPrefixSuffix(event.getResident(), "groupsuffix"));
|
||||
replacer.registerReplacer("{playername}", event -> event.getEvent().getPlayer().getName());
|
||||
replacer.registerReplacer("{primaryresidentrank}", event -> getPrimaryRankPrefix(event.getResident()));
|
||||
}
|
||||
static TagResolver parser(LocalTownyChatEvent event) {
|
||||
return TagResolver.resolver(
|
||||
TagResolver.resolver("worldname", Tag.inserting(Component.text(getWorldTag(event)))),
|
||||
@@ -101,12 +62,11 @@ public class TownyChatFormatter {
|
||||
return miniMessage.deserialize(message);
|
||||
}
|
||||
|
||||
public static String getChatFormat(LocalTownyChatEvent event) {
|
||||
String out = replacer.replaceAll(event.getFormat(), event) // Replace the townychat tags with their values.
|
||||
.replace("%", "") // Prevent user-inputted tags from breaking chat format.
|
||||
.replace("{modplayername}", "%1$s") // Other plugins will replace this with the DisplayName.
|
||||
.replace("{msg}", "%2$s"); // Replace the {msg} here so it's not regex parsed.
|
||||
return Colors.translateColorCodes(out);
|
||||
public static TagResolver getChatFormat(LocalTownyChatEvent event) {
|
||||
return TagResolver.builder()
|
||||
.resolver(parser(event))
|
||||
.resolver(StandardTags.defaults())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static String getWorldTag(LocalTownyChatEvent event) {
|
||||
|
||||
@@ -15,6 +15,12 @@ import com.palmergames.bukkit.towny.TownyUniverse;
|
||||
import com.palmergames.bukkit.util.Colors;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Sound;
|
||||
@@ -196,17 +202,24 @@ public class StandardChannel extends Channel {
|
||||
}
|
||||
|
||||
private void applyFormats(AsyncPlayerChatEvent event, String originalFormat, String workingFormat, Resident resident) {
|
||||
List<TagResolver> tagResolvers = new ArrayList<>();
|
||||
|
||||
// Parse out our own channelTag and msgcolour tags.
|
||||
String newFormat = parseTagAndMsgColour(workingFormat);
|
||||
tagResolvers = parseTagAndMsgColour(tagResolvers);
|
||||
// Attempt to apply the new format.
|
||||
catchFormatConversionException(event, originalFormat, newFormat);
|
||||
// catchFormatConversionException(event, originalFormat, newFormat);
|
||||
|
||||
// Fire the LocalTownyChatEvent.
|
||||
LocalTownyChatEvent chatEvent = new LocalTownyChatEvent(event, resident);
|
||||
// Format the chat line, replacing the TownyChat chat tags.
|
||||
newFormat = TownyChatFormatter.getChatFormat(chatEvent);
|
||||
tagResolvers.add(TownyChatFormatter.getChatFormat(chatEvent));
|
||||
// newFormat = TownyChatFormatter.getChatFormat(chatEvent);
|
||||
// Attempt to apply the new format.
|
||||
catchFormatConversionException(event, originalFormat, newFormat);
|
||||
// catchFormatConversionException(event, originalFormat, newFormat);
|
||||
Component component = Chat.getTownyChat().getMiniMessage().deserialize(workingFormat, tagResolvers.toArray(new TagResolver[0]));
|
||||
Audience.audience(event.getRecipients().stream().map(p -> Chat.getTownyChat().adventure().player(p)).toArray(Audience[]::new)).sendMessage(component);;
|
||||
|
||||
// event.setFormat(GsonComponentSerializer.gson().serialize(component));
|
||||
}
|
||||
|
||||
private String parseTagAndMsgColour(String format) {
|
||||
@@ -215,6 +228,16 @@ public class StandardChannel extends Channel {
|
||||
.replace("{msgcolour}", Colors.translateColorCodes(getMessageColour() != null ? getMessageColour() : ""));
|
||||
}
|
||||
|
||||
private List<TagResolver> parseTagAndMsgColour(List<TagResolver> tagResolvers) {
|
||||
tagResolvers.add(
|
||||
TagResolver.resolver(
|
||||
TagResolver.resolver("channeltag", Tag.inserting(getChannelTag() != null ? Component.text(getChannelTag()) : Component.empty())),
|
||||
TagResolver.resolver("msgcolour", Tag.inserting(getMessageColour() != null ? Component.text(getMessageColour()) : Component.empty()))
|
||||
)
|
||||
);
|
||||
return tagResolvers;
|
||||
}
|
||||
|
||||
private void catchFormatConversionException(AsyncPlayerChatEvent event, String format, String newFormat) {
|
||||
try {
|
||||
event.setFormat(newFormat);
|
||||
|
||||
@@ -13,6 +13,12 @@ import com.palmergames.bukkit.towny.object.metadata.StringDataField;
|
||||
import com.palmergames.bukkit.towny.utils.MetaDataUtil;
|
||||
import com.palmergames.bukkit.util.Colors;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.audience.Audiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@@ -21,8 +27,11 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UnknownFormatConversionException;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TownyChatPlayerListener implements Listener {
|
||||
private Chat plugin;
|
||||
@@ -127,9 +136,16 @@ public class TownyChatPlayerListener implements Listener {
|
||||
if (resident == null)
|
||||
return;
|
||||
// Nuke the channeltag and message colouring, but apply the remaining format.
|
||||
String format = plugin.getPlayerChannel(player).getFormat(player).replace("{channelTag}", "").replace("{msgcolour}", "");
|
||||
String format = plugin.getPlayerChannel(player).getFormat(player);
|
||||
|
||||
// format is left to store the original non-PAPI-parsed chat format.
|
||||
List<TagResolver> tagResolvers = new ArrayList<>();
|
||||
tagResolvers.add(
|
||||
TagResolver.resolver(
|
||||
TagResolver.resolver("channeltag", Tag.inserting(Component.empty())),
|
||||
TagResolver.resolver("msgcolour", Tag.inserting(Component.empty()))
|
||||
)
|
||||
);
|
||||
String newFormat = format;
|
||||
|
||||
// Parse any PAPI placeholders.
|
||||
@@ -137,19 +153,24 @@ public class TownyChatPlayerListener implements Listener {
|
||||
newFormat = PlaceholderAPI.setPlaceholders(player, format);
|
||||
|
||||
// Attempt to apply the new format.
|
||||
catchFormatConversionException(event, format, newFormat);
|
||||
// catchFormatConversionException(event, format, newFormat);
|
||||
|
||||
// Fire the LocalTownyChatEvent.
|
||||
LocalTownyChatEvent chatEvent = new LocalTownyChatEvent(event, resident);
|
||||
|
||||
// Format the chat line, replacing the TownyChat chat tags.
|
||||
newFormat = TownyChatFormatter.getChatFormat(chatEvent);
|
||||
tagResolvers.add(TownyChatFormatter.getChatFormat(chatEvent));
|
||||
// newFormat = TownyChatFormatter.getChatFormat(chatEvent);
|
||||
|
||||
// Attempt to apply the new format.
|
||||
catchFormatConversionException(event, format, newFormat);
|
||||
// catchFormatConversionException(event, format, newFormat);
|
||||
|
||||
// Set the format based on the global channelformat, with channeltag and msgcolour removed.
|
||||
event.setFormat(newFormat);
|
||||
// event.setFormat(newFormat);
|
||||
|
||||
Component component = Chat.getTownyChat().getMiniMessage().deserialize(newFormat, tagResolvers.toArray(new TagResolver[0]));
|
||||
Audience.audience(event.getRecipients().stream().map(p -> Chat.getTownyChat().adventure().player(p)).toArray(Audience[]::new)).sendMessage(component);;
|
||||
// event.setFormat(GsonComponentSerializer.gson().serialize(component));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user