TC/NC & Removed old config stuff
Moved town/nation colors into their component Removed save command that was apparently there since 2015 It still loads the town/nation colors from the old config if needed Notification sound/pitch were the last config options to be converted over #85
This commit is contained in:
parent
3f387a9775
commit
0802de4b6f
15 changed files with 556 additions and 530 deletions
542
pom.xml
542
pom.xml
|
@ -1,263 +1,281 @@
|
|||
<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>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>The Button Minecraft Chat Plugin</name>
|
||||
<description>The Button Minecraft Chat Plugin</description>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src</directory>
|
||||
<excludes>
|
||||
<exclude>**/*.java</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<includes>
|
||||
<include>*.properties</include>
|
||||
<include>*.yml</include>
|
||||
<include>*.csv</include>
|
||||
<include>*.txt</include>
|
||||
</includes>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<finalName>ButtonChat</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.3</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.4.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>net.sourceforge.htmlcleaner:htmlcleaner</include>
|
||||
<include>org.javassist:javassist</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>target</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>2.12.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
<phase>test</phase>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<testFailureIgnore>true</testFailureIgnore>
|
||||
<useSystemClassLoader>false
|
||||
</useSystemClassLoader> <!-- https://stackoverflow.com/a/53012553/2703239 -->
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- <plugin>
|
||||
<groupId>pl.project13.maven</groupId>
|
||||
<artifactId>git-commit-id-plugin</artifactId>
|
||||
<version>2.2.5</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>get-the-git-infos</id>
|
||||
<goals>
|
||||
<goal>revision</goal>
|
||||
</goals>
|
||||
*NOTE*: The default phase of revision is initialize, but in case you want to change it, you can do so by adding the phase here
|
||||
<phase>initialize</phase>
|
||||
<configuration>
|
||||
<injectAllReactorProjects>true</injectAllReactorProjects>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>validate-the-git-infos</id>
|
||||
<goals>
|
||||
<goal>validateRevision</goal>
|
||||
</goals>
|
||||
*NOTE*: The default phase of validateRevision is verify, but in case you want to change it, you can do so by adding the phase here
|
||||
<phase>package</phase>
|
||||
<configuration>
|
||||
<validationProperties>
|
||||
- <validationProperty>
|
||||
<name>validating git dirty</name>
|
||||
<value>${git.branch}</value>
|
||||
<shouldMatchTo>dev</shouldMatchTo>
|
||||
</validationProperty> -
|
||||
</validationProperties>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<injectAllReactorProjects>true</injectAllReactorProjects>
|
||||
<verbose>true</verbose>
|
||||
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
|
||||
</configuration>
|
||||
</plugin> -->
|
||||
<!-- <plugin> <groupId>org.basepom.maven</groupId> <artifactId>duplicate-finder-maven-plugin</artifactId>
|
||||
<version>1.2.1</version> <executions> <execution> <goals> <goal>check</goal>
|
||||
</goals> </execution> </executions> </plugin> -->
|
||||
</plugins>
|
||||
</build>
|
||||
<groupId>buttondevteam</groupId>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack</id>
|
||||
<url>https://jitpack.io/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>Essentials</id>
|
||||
<url>http://repo.ess3.net/content/repositories/essrel/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>Votifier</id>
|
||||
<url>https://dl.bintray.com/nuvotifier/maven/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>Minigames</id>
|
||||
<url>http://maven.addstar.com.au/artifactory/release</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>vault-repo</id>
|
||||
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
|
||||
</repository>
|
||||
<!-- <repository> <id>WorldEdit</id> <url>http://maven.sk89q.com/artifactory/repo</url>
|
||||
</repository> -->
|
||||
<repository>
|
||||
<id>projectlombok.org</id>
|
||||
<url>http://projectlombok.org/mavenrepo</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.12.2-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.TBMCPlugins.ButtonCore</groupId>
|
||||
<artifactId>ButtonCore</artifactId>
|
||||
<version>${env.TRAVIS_BRANCH}-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/net.sourceforge.htmlcleaner/htmlcleaner -->
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.htmlcleaner</groupId>
|
||||
<artifactId>htmlcleaner</artifactId>
|
||||
<version>2.16</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.reflections/reflections -->
|
||||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
<artifactId>reflections</artifactId>
|
||||
<version>0.9.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ess3</groupId>
|
||||
<artifactId>Essentials</artifactId>
|
||||
<version>2.13.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.TBMCPlugins.ButtonCore</groupId>
|
||||
<artifactId>Towny</artifactId>
|
||||
<version>8d3b6b6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.vexsoftware</groupId>
|
||||
<artifactId>nuvotifier-universal</artifactId>
|
||||
<version>2.3.4</version>
|
||||
</dependency>
|
||||
<!-- <dependency> <groupId>au.com.mineauz</groupId> <artifactId>Minigames</artifactId>
|
||||
<version>1.8.0</version> </dependency> -->
|
||||
<dependency>
|
||||
<groupId>net.milkbowl.vault</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.16.16</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.12.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.webbukkit</groupId>
|
||||
<artifactId>Dynmap-Towny</artifactId>
|
||||
<version>master-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.webbukkit</groupId>
|
||||
<artifactId>Dynmap</artifactId>
|
||||
<version>v2.5</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/junit/junit -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<artifactId>ButtonChat</artifactId>
|
||||
<organization>
|
||||
<name>TBMCPlugins</name>
|
||||
<url>https://github.com/TBMCPlugins</url>
|
||||
</organization>
|
||||
<properties>
|
||||
<!-- github server corresponds to entry in ~/.m2/settings.xml -->
|
||||
<github.global.server>githubo</github.global.server>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<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>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>The Button Minecraft Chat Plugin</name>
|
||||
<description>The Button Minecraft Chat Plugin</description>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src</directory>
|
||||
<excludes>
|
||||
<exclude>**/*.java</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<includes>
|
||||
<include>*.properties</include>
|
||||
<include>*.yml</include>
|
||||
<include>*.csv</include>
|
||||
<include>*.txt</include>
|
||||
</includes>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<finalName>ButtonChat</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.3</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.4.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>net.sourceforge.htmlcleaner:htmlcleaner</include>
|
||||
<include>org.javassist:javassist</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>target</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>2.12.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
<phase>test</phase>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<testFailureIgnore>true</testFailureIgnore>
|
||||
<useSystemClassLoader>false
|
||||
</useSystemClassLoader> <!-- https://stackoverflow.com/a/53012553/2703239 -->
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- <plugin>
|
||||
<groupId>pl.project13.maven</groupId>
|
||||
<artifactId>git-commit-id-plugin</artifactId>
|
||||
<version>2.2.5</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>get-the-git-infos</id>
|
||||
<goals>
|
||||
<goal>revision</goal>
|
||||
</goals>
|
||||
*NOTE*: The default phase of revision is initialize, but in case you want to change it, you can do so by adding the phase here
|
||||
<phase>initialize</phase>
|
||||
<configuration>
|
||||
<injectAllReactorProjects>true</injectAllReactorProjects>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>validate-the-git-infos</id>
|
||||
<goals>
|
||||
<goal>validateRevision</goal>
|
||||
</goals>
|
||||
*NOTE*: The default phase of validateRevision is verify, but in case you want to change it, you can do so by adding the phase here
|
||||
<phase>package</phase>
|
||||
<configuration>
|
||||
<validationProperties>
|
||||
- <validationProperty>
|
||||
<name>validating git dirty</name>
|
||||
<value>${git.branch}</value>
|
||||
<shouldMatchTo>dev</shouldMatchTo>
|
||||
</validationProperty> -
|
||||
</validationProperties>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<injectAllReactorProjects>true</injectAllReactorProjects>
|
||||
<verbose>true</verbose>
|
||||
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
|
||||
</configuration>
|
||||
</plugin> -->
|
||||
<!-- <plugin> <groupId>org.basepom.maven</groupId> <artifactId>duplicate-finder-maven-plugin</artifactId>
|
||||
<version>1.2.1</version> <executions> <execution> <goals> <goal>check</goal>
|
||||
</goals> </execution> </executions> </plugin> -->
|
||||
</plugins>
|
||||
</build>
|
||||
<groupId>buttondevteam</groupId>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack</id>
|
||||
<url>https://jitpack.io/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>Essentials</id>
|
||||
<url>http://repo.ess3.net/content/repositories/essrel/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>Votifier</id>
|
||||
<url>https://dl.bintray.com/nuvotifier/maven/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>Minigames</id>
|
||||
<url>http://maven.addstar.com.au/artifactory/release</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>vault-repo</id>
|
||||
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
|
||||
</repository>
|
||||
<!-- <repository> <id>WorldEdit</id> <url>http://maven.sk89q.com/artifactory/repo</url>
|
||||
</repository> -->
|
||||
<repository>
|
||||
<id>projectlombok.org</id>
|
||||
<url>http://projectlombok.org/mavenrepo</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.12.2-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.TBMCPlugins.ButtonCore</groupId>
|
||||
<artifactId>ButtonCore</artifactId>
|
||||
<version>${branch}-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/net.sourceforge.htmlcleaner/htmlcleaner -->
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.htmlcleaner</groupId>
|
||||
<artifactId>htmlcleaner</artifactId>
|
||||
<version>2.16</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.reflections/reflections -->
|
||||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
<artifactId>reflections</artifactId>
|
||||
<version>0.9.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ess3</groupId>
|
||||
<artifactId>Essentials</artifactId>
|
||||
<version>2.13.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.TBMCPlugins.ButtonCore</groupId>
|
||||
<artifactId>Towny</artifactId>
|
||||
<version>8d3b6b6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.vexsoftware</groupId>
|
||||
<artifactId>nuvotifier-universal</artifactId>
|
||||
<version>2.3.4</version>
|
||||
</dependency>
|
||||
<!-- <dependency> <groupId>au.com.mineauz</groupId> <artifactId>Minigames</artifactId>
|
||||
<version>1.8.0</version> </dependency> -->
|
||||
<dependency>
|
||||
<groupId>net.milkbowl.vault</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.16.16</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.12.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.webbukkit</groupId>
|
||||
<artifactId>Dynmap-Towny</artifactId>
|
||||
<version>master-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.webbukkit</groupId>
|
||||
<artifactId>Dynmap</artifactId>
|
||||
<version>v2.5</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/junit/junit -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<artifactId>ButtonChat</artifactId>
|
||||
<organization>
|
||||
<name>TBMCPlugins</name>
|
||||
<url>https://github.com/TBMCPlugins</url>
|
||||
</organization>
|
||||
<properties>
|
||||
<!-- github server corresponds to entry in ~/.m2/settings.xml -->
|
||||
<github.global.server>githubo</github.global.server>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<branch>
|
||||
master
|
||||
</branch> <!-- Should be master if building ButtonCore locally - the CI will overwrite it (see below) -->
|
||||
</properties>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>ci</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>env.TRAVIS_BRANCH</name>
|
||||
</property>
|
||||
</activation>
|
||||
<properties>
|
||||
<!-- Override only if necessary -->
|
||||
<branch>${env.TRAVIS_BRANCH}</branch>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
|
@ -46,7 +46,7 @@ public class ChatProcessing {
|
|||
private static final Pattern ITALIC_PATTERN = Pattern.compile("\\*");
|
||||
private static final Pattern BOLD_PATTERN = Pattern.compile("\\*\\*");
|
||||
private static final Pattern CODE_PATTERN = Pattern.compile("`");
|
||||
private static final Pattern MASKED_LINK_PATTERN = Pattern.compile("\\[([^\\[\\]])\\]\\(([^()])\\)");
|
||||
private static final Pattern MASKED_LINK_PATTERN = Pattern.compile("\\[([^\\[\\]])]\\(([^()])\\)");
|
||||
private static final Pattern SOMEONE_PATTERN = Pattern.compile("@someone"); //TODO
|
||||
private static final Pattern STRIKETHROUGH_PATTERN = Pattern.compile("~~");
|
||||
private static final Color[] RainbowPresserColors = new Color[]{Color.Red, Color.Gold, Color.Yellow, Color.Green,
|
||||
|
@ -285,11 +285,11 @@ public class ChatProcessing {
|
|||
}
|
||||
ChatPlayer mpp = TBMCPlayer.getPlayer(nottest ? p.getUniqueId() : new UUID(0, 0), ChatPlayer.class);
|
||||
if (nottest) {
|
||||
if (PlayerListener.NotificationSound == null)
|
||||
if (PluginMain.Instance.notificationSound().get().length() == 0)
|
||||
p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f); // TODO: Airhorn
|
||||
else
|
||||
p.playSound(p.getLocation(), PlayerListener.NotificationSound, 1.0f,
|
||||
(float) PlayerListener.NotificationPitch);
|
||||
p.playSound(p.getLocation(), PluginMain.Instance.notificationSound().get(), 1.0f,
|
||||
PluginMain.Instance.notificationPitch().get());
|
||||
}
|
||||
String color = String.format("§%x", (mpp.GetFlairColor() == 0x00 ? 0xb : mpp.GetFlairColor()));
|
||||
return color + (nottest ? p.getName() : pn.get()) + "§r"; //Fix name casing, except when testing
|
||||
|
@ -305,11 +305,11 @@ public class ChatProcessing {
|
|||
+ match.toLowerCase() + " but was reported as online.");
|
||||
return "§c" + match + "§r";
|
||||
}
|
||||
if (PlayerListener.NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f);
|
||||
else
|
||||
p.playSound(p.getLocation(), PlayerListener.NotificationSound, 1.0f,
|
||||
(float) PlayerListener.NotificationPitch);
|
||||
if (PluginMain.Instance.notificationSound().get().length() == 0)
|
||||
p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f); // TODO: Airhorn
|
||||
else
|
||||
p.playSound(p.getLocation(), PluginMain.Instance.notificationSound().get(), 1.0f,
|
||||
PluginMain.Instance.notificationPitch().get());
|
||||
return PluginMain.essentials.getUser(p).getNickname();
|
||||
}
|
||||
error.accept("Player nicknamed " + match.toLowerCase()
|
||||
|
|
|
@ -1,42 +1,30 @@
|
|||
package buttondevteam.chat;
|
||||
|
||||
import buttondevteam.chat.commands.YeehawCommand;
|
||||
import buttondevteam.chat.commands.ucmds.TownColorCommand;
|
||||
import buttondevteam.chat.components.TownColorComponent;
|
||||
import buttondevteam.chat.components.announce.AnnouncerComponent;
|
||||
import buttondevteam.chat.components.flair.FlairComponent;
|
||||
import buttondevteam.chat.components.towncolors.TownColorComponent;
|
||||
import buttondevteam.chat.components.towncolors.TownyListener;
|
||||
import buttondevteam.chat.components.towny.TownyComponent;
|
||||
import buttondevteam.chat.listener.PlayerJoinLeaveListener;
|
||||
import buttondevteam.chat.listener.PlayerListener;
|
||||
import buttondevteam.chat.listener.TownyListener;
|
||||
import buttondevteam.component.channel.Channel;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.architecture.ButtonPlugin;
|
||||
import buttondevteam.lib.architecture.Component;
|
||||
import buttondevteam.lib.architecture.ConfigData;
|
||||
import buttondevteam.lib.chat.Color;
|
||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import lombok.val;
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.dynmap.towny.DTBridge;
|
||||
import org.dynmap.towny.DynmapTownyPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
||||
public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15.
|
||||
// A user, which flair isn't obtainable:
|
||||
// https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
||||
public static PluginMain Instance;
|
||||
|
@ -47,9 +35,17 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
|||
public static Channel TownChat;
|
||||
public static Channel NationChat;
|
||||
|
||||
public ConfigData<String> notificationSound() {
|
||||
return getIConfig().getData("notificationSound", "");
|
||||
}
|
||||
|
||||
public ConfigData<Float> notificationPitch() {
|
||||
return getIConfig().getData("notificationPitch", 1.0f);
|
||||
}
|
||||
|
||||
// Fired when plugin is first enabled
|
||||
@Override
|
||||
public void onEnable() {
|
||||
public void pluginEnable() {
|
||||
Instance = this;
|
||||
PluginMain.essentials = (Essentials) (Bukkit.getPluginManager().getPlugin("Essentials"));
|
||||
|
||||
|
@ -58,24 +54,13 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
|||
TBMCCoreAPI.RegisterEventsForExceptions(new TownyListener(), this);
|
||||
TBMCChatAPI.AddCommands(this, YeehawCommand.class);
|
||||
Console = this.getServer().getConsoleSender();
|
||||
LoadFiles();
|
||||
|
||||
SB = getServer().getScoreboardManager().getMainScoreboard(); // Main can be detected with @a[score_...]
|
||||
|
||||
Component.registerComponent(this, new TownyComponent());
|
||||
TownColors.keySet().removeIf(t -> !TownyComponent.TU.getTownsMap().containsKey(t)); // Removes town colors for deleted/renamed towns
|
||||
NationColor.keySet().removeIf(n -> !TownyComponent.TU.getNationsMap().containsKey(n)); // Removes nation colors for deleted/renamed nations
|
||||
|
||||
TBMCChatAPI.RegisterChatChannel(new Channel("§7RP§f", Color.Gray, "rp", null)); //Since it's null, it's recognised as global
|
||||
|
||||
Bukkit.getScheduler().runTask(this, () -> {
|
||||
val dtp = (DynmapTownyPlugin) Bukkit.getPluginManager().getPlugin("Dynmap-Towny");
|
||||
if (dtp == null)
|
||||
return;
|
||||
for (val entry : TownColors.entrySet())
|
||||
setTownColor(dtp, buttondevteam.chat.commands.ucmds.admin.TownColorCommand.getTownNameCased(entry.getKey()), entry.getValue());
|
||||
});
|
||||
|
||||
if (!setupEconomy() || !setupPermissions())
|
||||
TBMCCoreAPI.SendException("We're in trouble", new Exception("Failed to set up economy or permissions!"));
|
||||
|
||||
|
@ -84,85 +69,11 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
|||
Component.registerComponent(this, new AnnouncerComponent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a town's color on Dynmap.
|
||||
*
|
||||
* @param dtp A reference for the Dynmap-Towny plugin
|
||||
* @param town The town's name using the correct casing
|
||||
* @param colors The town's colors
|
||||
*/
|
||||
public static void setTownColor(DynmapTownyPlugin dtp, String town, Color[] colors) {
|
||||
Function<Color, Integer> c2i = c -> c.getRed() << 16 | c.getGreen() << 8 | c.getBlue();
|
||||
try {
|
||||
DTBridge.setTownColor(dtp, town, c2i.apply(colors[0]),
|
||||
c2i.apply(colors.length > 1 ? colors[1] : colors[0]));
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("Failed to set town color for town " + town + "!", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Essentials essentials = null;
|
||||
|
||||
// Fired when plugin is disabled
|
||||
@Override
|
||||
public void onDisable() {
|
||||
SaveFiles();
|
||||
}
|
||||
|
||||
/**
|
||||
* Names lowercased
|
||||
*/
|
||||
public static Map<String, Color[]> TownColors = new HashMap<>();
|
||||
/**
|
||||
* Names lowercased - nation color gets added to town colors when needed
|
||||
*/
|
||||
public static Map<String, Color> NationColor = new HashMap<>();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void LoadFiles() {
|
||||
PluginMain.Instance.getLogger().info("Loading files...");
|
||||
try {
|
||||
File file = new File("TBMC/chatsettings.yml");
|
||||
if (file.exists()) {
|
||||
YamlConfiguration yc = new YamlConfiguration();
|
||||
yc.load(file);
|
||||
PlayerListener.NotificationSound = yc.getString("notificationsound");
|
||||
PlayerListener.NotificationPitch = yc.getDouble("notificationpitch");
|
||||
val cs = yc.getConfigurationSection("towncolors");
|
||||
if (cs != null)
|
||||
TownColors.putAll(cs.getValues(true).entrySet().stream()
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, v -> ((List<String>) v.getValue()).stream()
|
||||
.map(Color::valueOf).toArray(Color[]::new))));
|
||||
TownColorCommand.ColorCount = (byte) yc.getInt("towncolorcount", 1);
|
||||
val ncs = yc.getConfigurationSection("nationcolors");
|
||||
if (ncs != null)
|
||||
NationColor.putAll(ncs.getValues(true).entrySet().stream()
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, v -> Color.valueOf((String) v.getValue()))));
|
||||
PluginMain.Instance.getLogger().info("Loaded files!");
|
||||
} else
|
||||
PluginMain.Instance.getLogger().info("No files to load, first run probably.");
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("Error while loading chat files!", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SaveFiles() {
|
||||
PluginMain.Instance.getLogger().info("Saving files...");
|
||||
try {
|
||||
File file = new File("TBMC/chatsettings.yml");
|
||||
YamlConfiguration yc = new YamlConfiguration();
|
||||
yc.set("notificationsound", PlayerListener.NotificationSound);
|
||||
yc.set("notificationpitch", PlayerListener.NotificationPitch);
|
||||
yc.createSection("towncolors", TownColors.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey,
|
||||
v -> Arrays.stream(v.getValue()).map(Enum::toString).toArray(String[]::new))));
|
||||
yc.set("towncolorcount", TownColorCommand.ColorCount);
|
||||
yc.createSection("nationcolors", NationColor.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey,
|
||||
v -> v.getValue().toString())));
|
||||
yc.save(file);
|
||||
PluginMain.Instance.getLogger().info("Saved files!");
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("Error while loading chat files!", e);
|
||||
}
|
||||
public void pluginDisable() {
|
||||
}
|
||||
|
||||
public static Permission permission = null;
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
package buttondevteam.chat.commands.ucmds.admin;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
|
||||
public class SaveCommand extends AdminCommandBase {
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { "§6---- Save config ----",
|
||||
"This command saves the config file(s)" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias,
|
||||
String[] args) {
|
||||
PluginMain.SaveFiles(); // 2015.08.09.
|
||||
sender.sendMessage("§bSaved files. Now you can edit them and reload if you want.§r");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package buttondevteam.chat.components;
|
||||
|
||||
import buttondevteam.lib.architecture.Component;
|
||||
import buttondevteam.lib.architecture.ConfigData;
|
||||
|
||||
public class TownColorComponent extends Component {
|
||||
public ConfigData<Byte> colorCount() { //TODO
|
||||
return getConfig().getData("colorCount", (byte) 1, cc -> (byte) cc, cc -> (int) cc);
|
||||
}
|
||||
|
||||
public ConfigData<Boolean> useNationColors() { //TODO
|
||||
return getConfig().getData("useNationColors", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void enable() {
|
||||
//TODO: Don't register all commands automatically (welp)
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void disable() {
|
||||
|
||||
}
|
||||
}
|
|
@ -1,9 +1,8 @@
|
|||
package buttondevteam.chat.commands.ucmds;
|
||||
package buttondevteam.chat.components.towncolors;
|
||||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.chat.commands.ucmds.UCommandBase;
|
||||
import buttondevteam.chat.components.towny.TownyComponent;
|
||||
import buttondevteam.chat.listener.PlayerJoinLeaveListener;
|
||||
import buttondevteam.lib.chat.Color;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
|
||||
|
@ -54,7 +53,7 @@ public class NColorCommand extends UCommandBase {
|
|||
return true;
|
||||
}
|
||||
String[] nameparts = arg.split("[|:]");
|
||||
Color[] towncolors = PluginMain.TownColors.get(town.getName().toLowerCase());
|
||||
Color[] towncolors = TownColorComponent.TownColors.get(town.getName().toLowerCase());
|
||||
if (towncolors == null) {
|
||||
player.sendMessage("§cYour town doesn't have a color set. The town mayor can set it using /u towncolor.");
|
||||
return true;
|
||||
|
@ -72,8 +71,8 @@ public class NColorCommand extends UCommandBase {
|
|||
return true;
|
||||
}
|
||||
ChatPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class).NameColorLocations()
|
||||
.set(new ArrayList<>(Arrays.stream(nameparts).map(np -> np.length()).collect(Collectors.toList()))); // No byte[], no TIntArrayList
|
||||
PlayerJoinLeaveListener.updatePlayerColors(player);
|
||||
.set(new ArrayList<>(Arrays.stream(nameparts).map(String::length).collect(Collectors.toList()))); // No byte[], no TIntArrayList
|
||||
TownColorComponent.updatePlayerColors(player);
|
||||
player.sendMessage("§bName colors set: " + player.getDisplayName());
|
||||
return true;
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package buttondevteam.chat.commands.ucmds;
|
||||
package buttondevteam.chat.components.towncolors;
|
||||
|
||||
import buttondevteam.chat.commands.ucmds.UCommandBase;
|
||||
import buttondevteam.chat.components.towny.TownyComponent;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
|
@ -44,6 +45,6 @@ public class NationColorCommand extends UCommandBase {
|
|||
player.sendMessage("§cCouldn't find your town/nation... Error reported.");
|
||||
return true;
|
||||
}
|
||||
return buttondevteam.chat.commands.ucmds.admin.NationColorCommand.SetNationColor(player, alias, a);
|
||||
return buttondevteam.chat.components.towncolors.admin.NationColorCommand.SetNationColor(player, alias, a);
|
||||
}
|
||||
}
|
|
@ -1,11 +1,13 @@
|
|||
package buttondevteam.chat.commands.ucmds;
|
||||
package buttondevteam.chat.components.towncolors;
|
||||
|
||||
import buttondevteam.chat.commands.ucmds.UCommandBase;
|
||||
import buttondevteam.chat.components.towny.TownyComponent;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import lombok.val;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandClass // TODO: /u u when annotation not present
|
||||
|
@ -14,7 +16,8 @@ public class TownColorCommand extends UCommandBase {
|
|||
@Override
|
||||
public String GetHelpText(String alias)[] {
|
||||
StringBuilder cns = new StringBuilder(" <colorname1>");
|
||||
for (int i = 2; i <= ColorCount; i++)
|
||||
val comp = (TownColorComponent) getComponent();
|
||||
for (int i = 2; i <= comp.colorCount().get(); i++)
|
||||
cns.append(" [colorname").append(i).append("]");
|
||||
return new String[] { //
|
||||
"§6---- Town Color ----", //
|
||||
|
@ -26,8 +29,6 @@ public class TownColorCommand extends UCommandBase {
|
|||
};
|
||||
}
|
||||
|
||||
public static byte ColorCount;
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(Player player, String alias, String[] args) {
|
||||
Resident res;
|
||||
|
@ -36,8 +37,9 @@ public class TownColorCommand extends UCommandBase {
|
|||
player.sendMessage("§cYou need to be the mayor of a town to set it's colors.");
|
||||
return true;
|
||||
}
|
||||
if (args.length > ColorCount) {
|
||||
player.sendMessage("You can only use " + ColorCount + " color" + (ColorCount > 1 ? "s" : "") + ".");
|
||||
val comp = (TownColorComponent) getComponent();
|
||||
if (args.length > comp.colorCount().get()) {
|
||||
player.sendMessage("You can only use " + comp.colorCount().get() + " color" + (comp.colorCount().get() > 1 ? "s" : "") + ".");
|
||||
return true;
|
||||
}
|
||||
String[] a = new String[args.length + 1];
|
||||
|
@ -49,6 +51,6 @@ public class TownColorCommand extends UCommandBase {
|
|||
player.sendMessage("§cCouldn't find your town... Error reported.");
|
||||
return true;
|
||||
}
|
||||
return buttondevteam.chat.commands.ucmds.admin.TownColorCommand.SetTownColor(player, alias, a);
|
||||
return buttondevteam.chat.components.towncolors.admin.TownColorCommand.SetTownColor(player, alias, a);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,201 @@
|
|||
package buttondevteam.chat.components.towncolors;
|
||||
|
||||
import buttondevteam.chat.ChatPlayer;
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.chat.components.towncolors.admin.TCCount;
|
||||
import buttondevteam.chat.components.towny.TownyComponent;
|
||||
import buttondevteam.core.ComponentManager;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.architecture.Component;
|
||||
import buttondevteam.lib.architecture.ComponentMetadata;
|
||||
import buttondevteam.lib.architecture.ConfigData;
|
||||
import buttondevteam.lib.chat.Color;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import lombok.experimental.var;
|
||||
import lombok.val;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.dynmap.towny.DTBridge;
|
||||
import org.dynmap.towny.DynmapTownyPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ComponentMetadata(depends = TownyComponent.class)
|
||||
public class TownColorComponent extends Component {
|
||||
/**
|
||||
* Names lowercased
|
||||
*/
|
||||
public static Map<String, Color[]> TownColors = new HashMap<>();
|
||||
/**
|
||||
* Names lowercased - nation color gets added to town colors when needed
|
||||
*/
|
||||
public static Map<String, Color> NationColor = new HashMap<>();
|
||||
|
||||
public ConfigData<Byte> colorCount() {
|
||||
return getConfig().getData("colorCount", (byte) 1, cc -> (byte) cc, cc -> (int) cc);
|
||||
}
|
||||
|
||||
public ConfigData<Boolean> useNationColors() { //TODO
|
||||
return getConfig().getData("useNationColors", true);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected void enable() {
|
||||
//TODO: Don't register all commands automatically (welp)
|
||||
Consumer<ConfigurationSection> loadTC = cs -> TownColorComponent.TownColors.putAll(cs.getValues(true).entrySet().stream()
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, v -> ((List<String>) v.getValue()).stream()
|
||||
.map(Color::valueOf).toArray(Color[]::new))));
|
||||
Consumer<ConfigurationSection> loadNC = ncs ->
|
||||
TownColorComponent.NationColor.putAll(ncs.getValues(true).entrySet().stream()
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, v -> Color.valueOf((String) v.getValue()))));
|
||||
var cs = getConfig().getConfig().getConfigurationSection("towncolors");
|
||||
if (cs != null)
|
||||
loadTC.accept(cs);
|
||||
else
|
||||
load_old(loadTC, null); //Load old data
|
||||
var ncs = getConfig().getConfig().getConfigurationSection("nationcolors");
|
||||
if (ncs != null)
|
||||
loadNC.accept(ncs);
|
||||
else
|
||||
load_old(null, loadNC); //Why not choose by making different args null
|
||||
|
||||
TownColors.keySet().removeIf(t -> !TownyComponent.TU.getTownsMap().containsKey(t)); // Removes town colors for deleted/renamed towns
|
||||
NationColor.keySet().removeIf(n -> !TownyComponent.TU.getNationsMap().containsKey(n)); // Removes nation colors for deleted/renamed nations
|
||||
|
||||
Bukkit.getScheduler().runTask(getPlugin(), () -> {
|
||||
val dtp = (DynmapTownyPlugin) Bukkit.getPluginManager().getPlugin("Dynmap-Towny");
|
||||
if (dtp == null)
|
||||
return;
|
||||
for (val entry : TownColors.entrySet())
|
||||
setTownColor(dtp, buttondevteam.chat.components.towncolors.admin.TownColorCommand.getTownNameCased(entry.getKey()), entry.getValue());
|
||||
});
|
||||
|
||||
registerCommand(new TownColorCommand());
|
||||
registerCommand(new NationColorCommand());
|
||||
registerCommand(new buttondevteam.chat.components.towncolors.admin.TownColorCommand());
|
||||
registerCommand(new buttondevteam.chat.components.towncolors.admin.NationColorCommand());
|
||||
registerCommand(new TCCount());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void disable() {
|
||||
getConfig().getConfig().createSection("towncolors", TownColors.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey,
|
||||
v -> Arrays.stream(v.getValue()).map(Enum::toString).toArray(String[]::new))));
|
||||
getConfig().getConfig().createSection("nationcolors", NationColor.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey,
|
||||
v -> v.getValue().toString())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a town's color on Dynmap.
|
||||
*
|
||||
* @param dtp A reference for the Dynmap-Towny plugin
|
||||
* @param town The town's name using the correct casing
|
||||
* @param colors The town's colors
|
||||
*/
|
||||
|
||||
public static void setTownColor(DynmapTownyPlugin dtp, String town, Color[] colors) {
|
||||
Function<Color, Integer> c2i = c -> c.getRed() << 16 | c.getGreen() << 8 | c.getBlue();
|
||||
try {
|
||||
DTBridge.setTownColor(dtp, town, c2i.apply(colors[0]),
|
||||
c2i.apply(colors.length > 1 ? colors[1] : colors[0]));
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("Failed to set town color for town " + town + "!", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String getPlayerNickname(Player player, User user, ChatPlayer cp) {
|
||||
String nickname = user.getNick(true);
|
||||
if (nickname.contains("~")) //StartsWith doesn't work because of color codes
|
||||
nickname = nickname.replace("~", ""); //It gets stacked otherwise
|
||||
String name = ChatColor.stripColor(nickname); //Enforce "town colors" on non-members
|
||||
val res = TownyComponent.TU.getResidentMap().get(player.getName().toLowerCase());
|
||||
if (res == null || !res.hasTown())
|
||||
return name;
|
||||
try {
|
||||
Color[] clrs = Optional.ofNullable(
|
||||
TownColors.get(res.getTown().getName().toLowerCase())
|
||||
).orElse(new Color[]{Color.White}); //Use white as default town color
|
||||
StringBuilder ret = new StringBuilder();
|
||||
AtomicInteger prevlen = new AtomicInteger();
|
||||
BiFunction<Color, Integer, String> anyColoredNamePart = (c, len) -> "§" //Len==0 if last part
|
||||
+ Integer.toHexString(c.ordinal()) // 'Odds' are the last character is chopped off so we make sure to include all chars at the end
|
||||
+ (len == 0 ? name.substring(prevlen.get())
|
||||
: name.substring(prevlen.get(), prevlen.addAndGet(len)));
|
||||
BiFunction<Integer, Integer, String> coloredNamePart = (len, i)
|
||||
-> anyColoredNamePart.apply(clrs[i], i + 1 == clrs.length ? 0 : len);
|
||||
final int len = name.length() / (clrs.length + 1); //The above param is needed because this isn't always passed
|
||||
Color nc;
|
||||
/*if(res.getTown().hasNation()
|
||||
&&(nc=PluginMain.NationColor.get(res.getTown().getNation().getName().toLowerCase()))!=null)
|
||||
len = name.length() / (clrs.length+1);
|
||||
else
|
||||
len = name.length() / clrs.length;*/
|
||||
val nclar = cp.NameColorLocations().get();
|
||||
int[] ncl = nclar == null ? null : nclar.stream().mapToInt(Integer::intValue).toArray();
|
||||
if (ncl != null && (Arrays.stream(ncl).sum() != name.length() || ncl.length != clrs.length + 1)) //+1: Nation color
|
||||
ncl = null; // Reset if name length changed
|
||||
//System.out.println("ncl: "+Arrays.toString(ncl)+" - sum: "+Arrays.stream(ncl).sum()+" - name len: "+name.length());
|
||||
if (!res.getTown().hasNation()
|
||||
|| (nc = NationColor.get(res.getTown().getNation().getName().toLowerCase())) == null)
|
||||
nc = Color.White;
|
||||
ret.append(anyColoredNamePart.apply(nc, ncl == null ? len : ncl[0])); //Make first color the nation color
|
||||
for (int i = 0; i < clrs.length; i++)
|
||||
//ret.append(coloredNamePart.apply(ncl == null ? len : (nc==null?ncl[i]:ncl[i+1]), i));
|
||||
ret.append(coloredNamePart.apply(ncl == null ? len : ncl[i + 1], i));
|
||||
return ret.toString();
|
||||
} catch (NotRegisteredException e) {
|
||||
return nickname;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the component is enabled
|
||||
*/
|
||||
public static void updatePlayerColors(Player player) { //Probably while ingame (/u ncolor)
|
||||
updatePlayerColors(player, ChatPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the component is enabled
|
||||
*/
|
||||
public static void updatePlayerColors(Player player, ChatPlayer cp) { //Probably at join - nop, nicknames
|
||||
if (!ComponentManager.isEnabled(TownColorComponent.class))
|
||||
return;
|
||||
User user = PluginMain.essentials.getUser(player);
|
||||
user.setNickname(getPlayerNickname(player, user, cp));
|
||||
user.setDisplayNick(); //These won't fire the nick change event
|
||||
cp.FlairUpdate(); //Update in list
|
||||
}
|
||||
|
||||
private static void load_old(Consumer<ConfigurationSection> loadTC,
|
||||
Consumer<ConfigurationSection> loadNC) {
|
||||
PluginMain.Instance.getLogger().info("Loading files...");
|
||||
try {
|
||||
File file = new File("TBMC/chatsettings.yml");
|
||||
if (file.exists()) {
|
||||
YamlConfiguration yc = new YamlConfiguration();
|
||||
yc.load(file);
|
||||
ConfigurationSection cs;
|
||||
if (loadTC != null && (cs = yc.getConfigurationSection("towncolors")) != null)
|
||||
loadTC.accept(cs);
|
||||
if (loadNC != null && (cs = yc.getConfigurationSection("nationcolors")) != null)
|
||||
loadNC.accept(cs);
|
||||
PluginMain.Instance.getLogger().info("Loaded files!");
|
||||
} else
|
||||
PluginMain.Instance.getLogger().info("No files to load, first run probably.");
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("Error while loading chat files!", e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package buttondevteam.chat.listener;
|
||||
package buttondevteam.chat.components.towncolors;
|
||||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import com.earth2me.essentials.User;
|
||||
|
@ -16,21 +16,21 @@ import java.util.Objects;
|
|||
public class TownyListener implements Listener {
|
||||
@EventHandler
|
||||
public void onTownRename(RenameTownEvent event) {
|
||||
val clrs = PluginMain.TownColors.remove(event.getOldName().toLowerCase());
|
||||
val clrs = TownColorComponent.TownColors.remove(event.getOldName().toLowerCase());
|
||||
if (clrs != null)
|
||||
PluginMain.TownColors.put(event.getTown().getName().toLowerCase(), clrs);
|
||||
TownColorComponent.TownColors.put(event.getTown().getName().toLowerCase(), clrs);
|
||||
}
|
||||
|
||||
@EventHandler //Gets called on town load as well
|
||||
public void onTownJoin(TownAddResidentEvent event) {
|
||||
Player p = Bukkit.getPlayer(event.getResident().getName());
|
||||
if (p != null)
|
||||
PlayerJoinLeaveListener.updatePlayerColors(p);
|
||||
TownColorComponent.updatePlayerColors(p);
|
||||
}
|
||||
|
||||
public static void updateTownMembers(Town town) {
|
||||
town.getResidents().stream().map(r -> Bukkit.getPlayer(r.getName()))
|
||||
.filter(Objects::nonNull).forEach(PlayerJoinLeaveListener::updatePlayerColors);
|
||||
.filter(Objects::nonNull).forEach(TownColorComponent::updatePlayerColors);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -47,7 +47,7 @@ public class TownyListener implements Listener {
|
|||
|
||||
@EventHandler
|
||||
public void onTownDelete(DeleteTownEvent event) {
|
||||
PluginMain.TownColors.remove(event.getTownName().toLowerCase());
|
||||
TownColorComponent.TownColors.remove(event.getTownName().toLowerCase());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -61,9 +61,9 @@ public class TownyListener implements Listener {
|
|||
|
||||
@EventHandler
|
||||
public void onNationRename(RenameNationEvent event) {
|
||||
val clrs = PluginMain.NationColor.remove(event.getOldName().toLowerCase());
|
||||
val clrs = TownColorComponent.NationColor.remove(event.getOldName().toLowerCase());
|
||||
if (clrs != null)
|
||||
PluginMain.NationColor.put(event.getNation().getName().toLowerCase(), clrs);
|
||||
TownColorComponent.NationColor.put(event.getNation().getName().toLowerCase(), clrs);
|
||||
}
|
||||
|
||||
@EventHandler //Gets called on town load as well
|
||||
|
@ -78,7 +78,7 @@ public class TownyListener implements Listener {
|
|||
|
||||
@EventHandler
|
||||
public void onNationDelete(DeleteNationEvent event) {
|
||||
PluginMain.NationColor.remove(event.getNationName().toLowerCase());
|
||||
TownColorComponent.NationColor.remove(event.getNationName().toLowerCase());
|
||||
}
|
||||
|
||||
@EventHandler
|
|
@ -1,8 +1,10 @@
|
|||
package buttondevteam.chat.commands.ucmds.admin;
|
||||
package buttondevteam.chat.components.towncolors.admin;
|
||||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.chat.commands.ucmds.admin.AdminCommandBase;
|
||||
import buttondevteam.chat.components.towncolors.TownColorComponent;
|
||||
import buttondevteam.chat.components.towncolors.TownyListener;
|
||||
import buttondevteam.chat.components.towny.TownyComponent;
|
||||
import buttondevteam.chat.listener.TownyListener;
|
||||
import buttondevteam.lib.chat.Color;
|
||||
import com.palmergames.bukkit.towny.object.Nation;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
|
@ -40,14 +42,14 @@ public class NationColorCommand extends AdminCommandBase {
|
|||
val c = TownColorCommand.getColorOrSendError(args[1], sender);
|
||||
if (!c.isPresent()) return true;
|
||||
if (!c.get().getName().equals(Color.White.getName())) { //Default nation color
|
||||
for (val nc : PluginMain.NationColor.values()) {
|
||||
for (val nc : TownColorComponent.NationColor.values()) {
|
||||
if (nc.getName().equals(c.get().getName())) {
|
||||
sender.sendMessage("§cAnother nation already uses this color!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
PluginMain.NationColor.put(args[0].toLowerCase(), c.get());
|
||||
TownColorComponent.NationColor.put(args[0].toLowerCase(), c.get());
|
||||
Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> {
|
||||
for (Town t : nation.getTowns())
|
||||
TownyListener.updateTownMembers(t);
|
|
@ -1,5 +1,8 @@
|
|||
package buttondevteam.chat.commands.ucmds.admin;
|
||||
package buttondevteam.chat.components.towncolors.admin;
|
||||
|
||||
import buttondevteam.chat.commands.ucmds.admin.AdminCommandBase;
|
||||
import buttondevteam.chat.components.towncolors.TownColorComponent;
|
||||
import lombok.val;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class TCCount extends AdminCommandBase {
|
||||
|
@ -20,7 +23,8 @@ public class TCCount extends AdminCommandBase {
|
|||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
buttondevteam.chat.commands.ucmds.TownColorCommand.ColorCount = count;
|
||||
val comp = (TownColorComponent) getComponent();
|
||||
comp.colorCount().set(count);
|
||||
sender.sendMessage("Color count set to " + count);
|
||||
return true;
|
||||
}
|
|
@ -1,8 +1,10 @@
|
|||
package buttondevteam.chat.commands.ucmds.admin;
|
||||
package buttondevteam.chat.components.towncolors.admin;
|
||||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.chat.commands.ucmds.admin.AdminCommandBase;
|
||||
import buttondevteam.chat.components.towncolors.TownColorComponent;
|
||||
import buttondevteam.chat.components.towncolors.TownyListener;
|
||||
import buttondevteam.chat.components.towny.TownyComponent;
|
||||
import buttondevteam.chat.listener.TownyListener;
|
||||
import buttondevteam.lib.chat.Color;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import lombok.val;
|
||||
|
@ -48,16 +50,16 @@ public class TownColorCommand extends AdminCommandBase {
|
|||
return true;
|
||||
clrs[i - 1] = c.get();
|
||||
}
|
||||
for (Map.Entry<String, Color[]> other : PluginMain.TownColors.entrySet()) {
|
||||
for (Map.Entry<String, Color[]> other : TownColorComponent.TownColors.entrySet()) {
|
||||
Color nc, tnc;
|
||||
try {
|
||||
nc = PluginMain.NationColor.get(TownyComponent.TU.getTownsMap().get(other.getKey()).getNation().getName().toLowerCase());
|
||||
nc = TownColorComponent.NationColor.get(TownyComponent.TU.getTownsMap().get(other.getKey()).getNation().getName().toLowerCase());
|
||||
} catch (Exception e) { //Too lazy for lots of null-checks and it may throw exceptions anyways
|
||||
nc = null;
|
||||
}
|
||||
if (nc == null) nc = Color.White; //Default nation color
|
||||
try {
|
||||
tnc = PluginMain.NationColor.get(targetTown.getNation().getName().toLowerCase());
|
||||
tnc = TownColorComponent.NationColor.get(targetTown.getNation().getName().toLowerCase());
|
||||
} catch (Exception e) {
|
||||
tnc = null;
|
||||
}
|
||||
|
@ -75,7 +77,7 @@ public class TownColorCommand extends AdminCommandBase {
|
|||
}
|
||||
}
|
||||
}
|
||||
PluginMain.TownColors.put(args[0].toLowerCase(), clrs);
|
||||
TownColorComponent.TownColors.put(args[0].toLowerCase(), clrs);
|
||||
TownyListener.updateTownMembers(targetTown);
|
||||
|
||||
val dtp = (DynmapTownyPlugin) Bukkit.getPluginManager().getPlugin("Dynmap-Towny");
|
||||
|
@ -84,7 +86,7 @@ public class TownColorCommand extends AdminCommandBase {
|
|||
PluginMain.Instance.getLogger().warning("Dynmap-Towny not found for setting town color!");
|
||||
return true;
|
||||
}
|
||||
PluginMain.setTownColor(dtp, targetTown.getName(), clrs);
|
||||
TownColorComponent.setTownColor(dtp, targetTown.getName(), clrs);
|
||||
sender.sendMessage("§bColor(s) set.");
|
||||
return true;
|
||||
}
|
|
@ -7,28 +7,19 @@ import buttondevteam.chat.commands.UnlolCommand;
|
|||
import buttondevteam.chat.commands.ucmds.HistoryCommand;
|
||||
import buttondevteam.chat.components.flair.FlairComponent;
|
||||
import buttondevteam.chat.components.flair.FlairStates;
|
||||
import buttondevteam.chat.components.towny.TownyComponent;
|
||||
import buttondevteam.chat.components.towncolors.TownColorComponent;
|
||||
import buttondevteam.core.ComponentManager;
|
||||
import buttondevteam.lib.chat.Color;
|
||||
import buttondevteam.lib.player.TBMCPlayerJoinEvent;
|
||||
import buttondevteam.lib.player.TBMCPlayerLoadEvent;
|
||||
import buttondevteam.lib.player.TBMCPlayerSaveEvent;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import lombok.val;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
import java.util.Timer;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class PlayerJoinLeaveListener implements Listener {
|
||||
|
||||
|
@ -70,7 +61,7 @@ public class PlayerJoinLeaveListener implements Listener {
|
|||
nwithoutformatting = p.getName();
|
||||
PlayerListener.nicknames.forcePut(nwithoutformatting.toLowerCase(), p.getUniqueId());
|
||||
|
||||
updatePlayerColors(p, cp); //TO!DO: Doesn't have effect - It can help to register the listener
|
||||
TownColorComponent.updatePlayerColors(p, cp); //TO!DO: Doesn't have effect - It can help to register the listener
|
||||
|
||||
if (cp.ChatOnly || p.getGameMode().equals(GameMode.SPECTATOR)) {
|
||||
cp.ChatOnly = false;
|
||||
|
@ -90,60 +81,4 @@ public class PlayerJoinLeaveListener implements Listener {
|
|||
UnlolCommand.Lastlol.values().removeIf(lld -> lld.getLolowner().equals(event.getPlayer()));
|
||||
}
|
||||
|
||||
private static String getPlayerNickname(Player player, User user, ChatPlayer cp) {
|
||||
String nickname = user.getNick(true);
|
||||
if (nickname.contains("~")) //StartsWith doesn't work because of color codes
|
||||
nickname = nickname.replace("~", ""); //It gets stacked otherwise
|
||||
String name = ChatColor.stripColor(nickname); //Enforce "town colors" on non-members
|
||||
val res = TownyComponent.TU.getResidentMap().get(player.getName().toLowerCase());
|
||||
if (res == null || !res.hasTown())
|
||||
return name;
|
||||
try {
|
||||
Color[] clrs = Optional.ofNullable(
|
||||
PluginMain.TownColors.get(res.getTown().getName().toLowerCase())
|
||||
).orElse(new Color[]{Color.White}); //Use white as default town color
|
||||
StringBuilder ret = new StringBuilder();
|
||||
AtomicInteger prevlen = new AtomicInteger();
|
||||
BiFunction<Color, Integer, String> anyColoredNamePart = (c, len) -> "§" //Len==0 if last part
|
||||
+ Integer.toHexString(c.ordinal()) // 'Odds' are the last character is chopped off so we make sure to include all chars at the end
|
||||
+ (len == 0 ? name.substring(prevlen.get())
|
||||
: name.substring(prevlen.get(), prevlen.addAndGet(len)));
|
||||
BiFunction<Integer, Integer, String> coloredNamePart = (len, i)
|
||||
-> anyColoredNamePart.apply(clrs[i], i + 1 == clrs.length ? 0 : len);
|
||||
final int len = name.length() / (clrs.length + 1); //The above param is needed because this isn't always passed
|
||||
Color nc;
|
||||
/*if(res.getTown().hasNation()
|
||||
&&(nc=PluginMain.NationColor.get(res.getTown().getNation().getName().toLowerCase()))!=null)
|
||||
len = name.length() / (clrs.length+1);
|
||||
else
|
||||
len = name.length() / clrs.length;*/
|
||||
val nclar = cp.NameColorLocations().get();
|
||||
int[] ncl = nclar == null ? null : nclar.stream().mapToInt(Integer::intValue).toArray();
|
||||
if (ncl != null && (Arrays.stream(ncl).sum() != name.length() || ncl.length != clrs.length + 1)) //+1: Nation color
|
||||
ncl = null; // Reset if name length changed
|
||||
//System.out.println("ncl: "+Arrays.toString(ncl)+" - sum: "+Arrays.stream(ncl).sum()+" - name len: "+name.length());
|
||||
if (!res.getTown().hasNation()
|
||||
|| (nc = PluginMain.NationColor.get(res.getTown().getNation().getName().toLowerCase())) == null)
|
||||
nc = Color.White;
|
||||
ret.append(anyColoredNamePart.apply(nc, ncl == null ? len : ncl[0])); //Make first color the nation color
|
||||
for (int i = 0; i < clrs.length; i++)
|
||||
//ret.append(coloredNamePart.apply(ncl == null ? len : (nc==null?ncl[i]:ncl[i+1]), i));
|
||||
ret.append(coloredNamePart.apply(ncl == null ? len : ncl[i + 1], i));
|
||||
return ret.toString();
|
||||
} catch (NotRegisteredException e) {
|
||||
return nickname;
|
||||
}
|
||||
}
|
||||
|
||||
public static void updatePlayerColors(Player player) { //Probably while ingame (/u ncolor)
|
||||
updatePlayerColors(player, ChatPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class));
|
||||
}
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public static void updatePlayerColors(Player player, ChatPlayer cp) { //Probably at join - nop, nicknames
|
||||
User user = PluginMain.essentials.getUser(player);
|
||||
user.setNickname(getPlayerNickname(player, user, cp));
|
||||
user.setDisplayNick(); //These won't fire the nick change event
|
||||
cp.FlairUpdate(); //Update in list
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import buttondevteam.chat.ChatProcessing;
|
|||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.chat.commands.ucmds.HistoryCommand;
|
||||
import buttondevteam.chat.components.flair.FlairComponent;
|
||||
import buttondevteam.chat.components.towncolors.TownColorComponent;
|
||||
import buttondevteam.component.channel.Channel;
|
||||
import buttondevteam.component.channel.ChatChannelRegisterEvent;
|
||||
import buttondevteam.component.channel.ChatRoom;
|
||||
|
@ -52,9 +53,6 @@ public class PlayerListener implements Listener {
|
|||
*/
|
||||
public static BiMap<String, UUID> nicknames = HashBiMap.create();
|
||||
|
||||
public static String NotificationSound;
|
||||
public static double NotificationPitch;
|
||||
|
||||
public final static String[] LaughStrings = new String[]{"xd", "lel", "lawl", "kek", "lmao", "hue", "hah", "rofl"};
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
|
@ -286,7 +284,7 @@ public class PlayerListener implements Listener {
|
|||
nicknames.inverse().forcePut(e.getAffected().getBase().getUniqueId(), ChatColor.stripColor(nick).toLowerCase());
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(PluginMain.Instance, () -> {
|
||||
PlayerJoinLeaveListener.updatePlayerColors(e.getAffected().getBase()); //Won't fire this event again
|
||||
TownColorComponent.updatePlayerColors(e.getAffected().getBase()); //Won't fire this event again
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue