mirror of
https://github.com/ryandw11/UltraChat.git
synced 2024-11-25 03:35:24 +01:00
Began UltraChat rewrite.
This commit is contained in:
parent
ba1106ca83
commit
b04124e416
158
pom.xml
Normal file
158
pom.xml
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
<?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>me.ryandw11</groupId>
|
||||||
|
<artifactId>UltraChat</artifactId>
|
||||||
|
<version>3.0.0</version>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<sourceDirectory>src/main/java</sourceDirectory>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>3.2.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.4</version>
|
||||||
|
<configuration>
|
||||||
|
<relocations>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.bstats</pattern>
|
||||||
|
<shadedPattern>me.ryandw11.ultrachat.bstats</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
</relocations>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.22.2</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
|
<version>2.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<skip>true</skip>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.sonatype.plugins</groupId>
|
||||||
|
<artifactId>nexus-staging-maven-plugin</artifactId>
|
||||||
|
<version>1.5.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>default-deploy</id>
|
||||||
|
<phase>deploy</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>deploy</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<serverId>nexus</serverId>
|
||||||
|
<nexusUrl>https://repo.ryandw11.com/nexus/</nexusUrl>
|
||||||
|
<skipStaging>true</skipStaging>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<distributionManagement>
|
||||||
|
<repository>
|
||||||
|
<id>nexus-releases</id>
|
||||||
|
<url>https://repo.ryandw11.com/repository/maven-releases/</url>
|
||||||
|
</repository>
|
||||||
|
<snapshotRepository>
|
||||||
|
<id>nexus-snapshots</id>
|
||||||
|
<url>https://repo.ryandw11.com/repository/maven-snapshots/</url>
|
||||||
|
</snapshotRepository>
|
||||||
|
</distributionManagement>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>placeholderapi</id>
|
||||||
|
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>Ryandw11</id>
|
||||||
|
<url>https://repo.ryandw11.com/repository/maven-releases/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>jitpack.io</id>
|
||||||
|
<url>https://jitpack.io</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.ryandw11</groupId>
|
||||||
|
<artifactId>ods</artifactId>
|
||||||
|
<version>1.0.4</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains</groupId>
|
||||||
|
<artifactId>annotations</artifactId>
|
||||||
|
<version>20.1.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.clip</groupId>
|
||||||
|
<artifactId>placeholderapi</artifactId>
|
||||||
|
<version>2.10.9</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>bukkit</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>*</groupId>
|
||||||
|
<artifactId>*</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot</artifactId>
|
||||||
|
<version>1.17-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bstats</groupId>
|
||||||
|
<artifactId>bstats-bukkit</artifactId>
|
||||||
|
<version>2.2.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.MilkBowl</groupId>
|
||||||
|
<artifactId>VaultAPI</artifactId>
|
||||||
|
<version>1.7</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
@ -1,25 +0,0 @@
|
|||||||
#---------------------------------------------------------------------#
|
|
||||||
# UltraChat #
|
|
||||||
# Channels #
|
|
||||||
#---------------------------------------------------------------------#
|
|
||||||
#
|
|
||||||
#Channel name {Note: it is better pratice to use lowercase}
|
|
||||||
#
|
|
||||||
#Notice: Turn the server off then edit ths config!
|
|
||||||
#
|
|
||||||
global:
|
|
||||||
#Channel prefix.
|
|
||||||
prefix: '&a[Global]&r'
|
|
||||||
#Channel permission, Use none for no permission.
|
|
||||||
permission: 'none'
|
|
||||||
#Messages from this channel will always appear no matter what channel the player is in.
|
|
||||||
always_appear: false
|
|
||||||
#This is the chat format ***Note the channel prefix is added by default.
|
|
||||||
#The format support components from the config.yml. See the Normal Chat for an example.
|
|
||||||
format: '%prefix% %player% %suffix%&7>> '
|
|
||||||
#Example Channel:
|
|
||||||
vip:
|
|
||||||
prefix: '&a[&6VIP&a]&r'
|
|
||||||
permission: 'channel.vip'
|
|
||||||
always_appear: false
|
|
||||||
format: '%prefix% %player% %suffix%&7>> '
|
|
@ -1,94 +0,0 @@
|
|||||||
###############################################
|
|
||||||
# Chat Color #
|
|
||||||
###############################################
|
|
||||||
chat_colors:
|
|
||||||
'&0': 'default'
|
|
||||||
'&1': 'default'
|
|
||||||
'&2': 'default'
|
|
||||||
'&3': 'default'
|
|
||||||
'&4': 'default'
|
|
||||||
'&5': 'default'
|
|
||||||
'&6': 'default'
|
|
||||||
'&7': 'default'
|
|
||||||
'&8': 'default'
|
|
||||||
'&9': 'default'
|
|
||||||
'&a': 'default'
|
|
||||||
'&b': 'default'
|
|
||||||
'&c': 'default'
|
|
||||||
'&d': 'default'
|
|
||||||
'&e': 'default'
|
|
||||||
'&f': 'default'
|
|
||||||
'&g': '{#11f014}'
|
|
||||||
|
|
||||||
###############################################
|
|
||||||
# Chat Color GUI #
|
|
||||||
###############################################
|
|
||||||
color_gui:
|
|
||||||
'Dark Blue':
|
|
||||||
color: '&1'
|
|
||||||
item: 'BLUE_WOOL'
|
|
||||||
permission: 'ultrachat.chatcolor.darkblue'
|
|
||||||
'Green':
|
|
||||||
color: '&2'
|
|
||||||
item: 'GREEN_WOOL'
|
|
||||||
permission: 'ultrachat.chatcolor.green'
|
|
||||||
'Cyan':
|
|
||||||
color: '&3'
|
|
||||||
item: 'CYAN_WOOL'
|
|
||||||
permission: 'ultrachat.chatcolor.cyan'
|
|
||||||
'Red':
|
|
||||||
color: '&4'
|
|
||||||
item: 'RED_WOOL'
|
|
||||||
permission: 'ultrachat.chatcolor.red'
|
|
||||||
'Purple':
|
|
||||||
color: '&5'
|
|
||||||
item: 'PURPLE_WOOL'
|
|
||||||
permission: 'ultrachat.chatcolor.purple'
|
|
||||||
'Orange':
|
|
||||||
color: '&6'
|
|
||||||
item: 'ORANGE_WOOL'
|
|
||||||
permission: 'ultrachat.chatcolor.orange'
|
|
||||||
'Light Gray':
|
|
||||||
color: '&7'
|
|
||||||
item: 'LIGHT_GRAY_WOOL'
|
|
||||||
permission: 'ultrachat.chatcolor.lightgray'
|
|
||||||
'Gray':
|
|
||||||
color: '&8'
|
|
||||||
item: 'GRAY_WOOL'
|
|
||||||
permission: 'ultrachat.chatcolor.gray'
|
|
||||||
'Blue':
|
|
||||||
color: '&9'
|
|
||||||
item: 'LAPIS_BLOCK'
|
|
||||||
permission: 'ultrachat.chatcolor.blue'
|
|
||||||
'Lime':
|
|
||||||
color: '&a'
|
|
||||||
item: 'LIME_WOOL'
|
|
||||||
permission: 'ultrachat.chatcolor.lime'
|
|
||||||
'Light Blue':
|
|
||||||
color: '&b'
|
|
||||||
item: 'BLUE_WOOL'
|
|
||||||
permission: 'ultrachat.chatcolor.lightblue'
|
|
||||||
'Pink':
|
|
||||||
color: '&c'
|
|
||||||
item: 'PINK_WOOL'
|
|
||||||
permission: 'ultrachat.chatcolor.pink'
|
|
||||||
'Magenta':
|
|
||||||
color: '&d'
|
|
||||||
item: 'MAGENTA_WOOL'
|
|
||||||
permission: 'ultrachat.chatcolor.magenta'
|
|
||||||
'Yellow':
|
|
||||||
color: '&e'
|
|
||||||
item: 'YELLOW_WOOL'
|
|
||||||
permission: 'ultrachat.chatcolor.yellow'
|
|
||||||
'White':
|
|
||||||
color: '&f'
|
|
||||||
item: 'WHITE_WOOL'
|
|
||||||
permission: 'ultrachat.chatcolor.white'
|
|
||||||
'Black':
|
|
||||||
color: '&0'
|
|
||||||
item: 'BLACK_WOOL'
|
|
||||||
permission: 'ultrachat.chatcolor.black'
|
|
||||||
'Pumpkin Orange':
|
|
||||||
color: '{#f59b14}'
|
|
||||||
item: 'BLACK_WOOL'
|
|
||||||
permission: 'ultrachat.chatcolor.pumpkinorange'
|
|
132
src/config.yml
132
src/config.yml
@ -1,132 +0,0 @@
|
|||||||
##############################################
|
|
||||||
# Ultra Chat #
|
|
||||||
##############################################
|
|
||||||
#Color GUI Settings:
|
|
||||||
#If true the command will be /chat color instead of /color
|
|
||||||
ChatColor_Command: false
|
|
||||||
|
|
||||||
#Used for assistance in development. Read more about it here:
|
|
||||||
# https://bstats.org/getting-started
|
|
||||||
bstats: true
|
|
||||||
#Restrict plugins from changing things in the config.
|
|
||||||
apirestrict: false
|
|
||||||
#Some of the chat formats break the mute function in plugins.
|
|
||||||
#This plugin hooks into ban/mute plugins and allow it to work.
|
|
||||||
#If set to true then the plugin will hook into that plugin.
|
|
||||||
#Suggest more ban plugins here: https://github.com/ryandw11/UltraChat/issues !
|
|
||||||
#Or ask the ban plugin author.
|
|
||||||
pluginhooks:
|
|
||||||
Essentials: true
|
|
||||||
AdvancedBan: true
|
|
||||||
|
|
||||||
|
|
||||||
#############################################
|
|
||||||
# Anti - Swear #
|
|
||||||
#############################################
|
|
||||||
|
|
||||||
Anti_Swear_Enabled: false
|
|
||||||
|
|
||||||
Blocked_Words:
|
|
||||||
- fuck
|
|
||||||
- fu
|
|
||||||
- shit
|
|
||||||
- f*ck
|
|
||||||
- crap
|
|
||||||
- ass
|
|
||||||
- jackass
|
|
||||||
- sh*t
|
|
||||||
- asshole
|
|
||||||
- fucker
|
|
||||||
|
|
||||||
#############################################
|
|
||||||
# Join Settings #
|
|
||||||
#############################################
|
|
||||||
#New player join. If the player hasn't joined the server before then this message will play. If you don't want it put none.
|
|
||||||
New_Player: '&d%player% has just joined the server for the first time! Welcome!'
|
|
||||||
|
|
||||||
#Moto of the day. You can use chat colors.
|
|
||||||
#If you have PlaceholderAPI installed you can use these placeholders: https://www.spigotmc.org/wiki/placeholderapi-placeholders/!
|
|
||||||
Motd_Enabled: true
|
|
||||||
Motd:
|
|
||||||
- '&6Welcome to the server,&r %player_name%&6.'
|
|
||||||
- '&6There are currently&b %server_online% &6players online!'
|
|
||||||
|
|
||||||
Join_Message: '&e%player% has joined the server!'
|
|
||||||
Leave_Message: '&e%player% has left the server!'
|
|
||||||
#############################################
|
|
||||||
# JSON Component #
|
|
||||||
#############################################
|
|
||||||
# This is a system to create JSON pockets with in a message.
|
|
||||||
# It uses a placerholder system to use.
|
|
||||||
#The name of the component:
|
|
||||||
JSON_Components:
|
|
||||||
normal_chat:
|
|
||||||
#The base message of the component
|
|
||||||
Message: '%prefix% %player% %suffix%'
|
|
||||||
#The component events
|
|
||||||
Events:
|
|
||||||
#A click event {Optional}
|
|
||||||
Click:
|
|
||||||
# One and only one of the Click Operations. Full list includes: {Open_URL, Run_Command, Suggest_Command}
|
|
||||||
Suggest_Command: '/msg %player%'
|
|
||||||
# When the player hovers over the base text.
|
|
||||||
Hover:
|
|
||||||
Show_Text:
|
|
||||||
- '&bLine One'
|
|
||||||
- '&3Line Two'
|
|
||||||
##############################################
|
|
||||||
# #
|
|
||||||
# Chat #
|
|
||||||
# #
|
|
||||||
##############################################
|
|
||||||
# Vailed types: normal, channel, and range.
|
|
||||||
# Set to nothing to not format the chat.
|
|
||||||
# Check the wiki for an explenation of each type!
|
|
||||||
chat_format: 'normal'
|
|
||||||
|
|
||||||
#The default color that opped players chat in. Do &r for none.
|
|
||||||
Op_Chat_Color: '&c'
|
|
||||||
|
|
||||||
#Variables: %prefix% - Gives you the players prefix. %suffix% - gives you the player suffix!
|
|
||||||
#You can use PlaceHolderAPI here! Check out the placeholders here: https://www.spigotmc.org/wiki/placeholderapi-placeholders/
|
|
||||||
#You can have unlimited custom chat formats.
|
|
||||||
#Note: If PlaceHolderAPI placeholders are not showing up please check to make sure you have the extension installed and that you reloaded the plugin.
|
|
||||||
#Notice: The JSON is only if the JSON above is set to true. JSON can also use PlaceHolderAPI!
|
|
||||||
########################
|
|
||||||
# Important Note! #
|
|
||||||
########################
|
|
||||||
# If you give a player the '*' permission they will have every single custom chat.
|
|
||||||
# When json is enabled the message is sent several times based on the number of custom formats you have!
|
|
||||||
# To avoid this give them the permission -(yourpermission). Ex: -ultrachat.chat.1
|
|
||||||
Custom_Chat:
|
|
||||||
permission_format:
|
|
||||||
'ultrachat.chat.example': '{normal_chat} &7>>'
|
|
||||||
#For any player oped.
|
|
||||||
Op_Chat: '{normal_chat} &c>> '
|
|
||||||
#The default chat when a player does not have a custom one.
|
|
||||||
Default_Chat: '{normal_chat} &7>>'
|
|
||||||
|
|
||||||
##############################################
|
|
||||||
# Channels #
|
|
||||||
##############################################
|
|
||||||
#Note: Custom Chat must be enabled for this to work!
|
|
||||||
#Edit the channels.yml when the server is stopped!
|
|
||||||
#Default Channel. This is the channel the player first joins the server. It is also given when the channel the player is on does not exsist.
|
|
||||||
Default_Channel: 'global'
|
|
||||||
#This is a list for the channels. It will only affect the list of channels. (Name should match the same as the one in the channels.yml)
|
|
||||||
Channel_List:
|
|
||||||
- global
|
|
||||||
- vip
|
|
||||||
|
|
||||||
##############################################
|
|
||||||
# Range #
|
|
||||||
##############################################
|
|
||||||
#The global channel which everyone can see.
|
|
||||||
#All of these formats support Components. See Normal Chat for an example.
|
|
||||||
Global:
|
|
||||||
format: '&6[Global]&r %prefix% %player% %suffix% &7>>'
|
|
||||||
World:
|
|
||||||
format: '&d[World]&r %prefix% %player% %suffix% &7>>'
|
|
||||||
Local:
|
|
||||||
format: '&b[Local]&r %prefix% %player% %suffix% &7>>'
|
|
||||||
range: 100
|
|
37
src/lang.yml
37
src/lang.yml
@ -1,37 +0,0 @@
|
|||||||
# %p represents player. (Not applicable to all messages)
|
|
||||||
# %s represents a message if there is one. (Not applicable to all messages)
|
|
||||||
plugin-prefix: '&7[&aUltraChat&7]'
|
|
||||||
no-perm: '&cYou do not have permission for this command.'
|
|
||||||
error-channel-enabled: '&cError: Chat channels are not enabled on this server!'
|
|
||||||
error-channel-usage: '&cError: Use /channel {channel}!'
|
|
||||||
channel-json-hover: '&5Click to join the channel!'
|
|
||||||
chat-stop-off: '&eThe chat has been &2Enabled &eby:&5 %p&e!'
|
|
||||||
chat-stop-on: '&eThe chat has been &4disabled &eby:&5 %p&e!'
|
|
||||||
stop-chat-message: '&cThe chat is currently not active.'
|
|
||||||
broadcast-prefix: '&7[&4UltraChat&7] '
|
|
||||||
chat-clear: '&3The chat has been cleared by &9%p&3!'
|
|
||||||
config-reload: '&aThe config has been reloaded!'
|
|
||||||
chat-cmd-not-valid: '&cThat is not a valid command. Do /chat help for help!'
|
|
||||||
cmd-spy-on: '&bCommand Spy Enabled!'
|
|
||||||
cmd-spy-off: '&bCommand Spy Disabled!'
|
|
||||||
cmd-spy-format: '&3[&6CommandSpy&3]&b %p: &3%s'
|
|
||||||
oth-cmd-spy-on: '&a%p&b''s command spy has been enabled!'
|
|
||||||
oth-cmd-spy-off: '&a%p&b''s command spy has been disabled!'
|
|
||||||
staff-chat-on: '&dStaff chat has been enabled!'
|
|
||||||
staff-chat-off: '&dStaff chat has been disabled!'
|
|
||||||
staff-chat-format: '&7[&dStaff Chat&7] &9%p: &3%s'
|
|
||||||
color-gui: '&aChat Color'
|
|
||||||
silent-join-message: '%p &7has joined the game silently!'
|
|
||||||
silent-leave-message: '%p &7has left the game silently!'
|
|
||||||
no-swear: '&cSwearing is not allowed on this server!'
|
|
||||||
mention: '&aSomeone has mentioned you!'
|
|
||||||
conosle-chat-log: '%p: %s'
|
|
||||||
chat-unstop-personal: '&2Chat Unstopped'
|
|
||||||
chat-stop-personal: '&2Chat Stopped'
|
|
||||||
sjoin-shown: '&bYour Join/Leave message will now be shown!'
|
|
||||||
sjoin-hide: '&bYour Join/Leave message will no longer be shown!'
|
|
||||||
sjoin-other-show: '&b%p Join/Leave message will now be shown!'
|
|
||||||
sjoin-other-hide: '&b%p Join/Leave message will no longer be shown!'
|
|
||||||
help-page-error: '&cThere are only two help pages!'
|
|
||||||
chat-color-change: 'Your chat color has been changed!'
|
|
||||||
|
|
9
src/main/java/me/ryandw11/ultrachat/UltraChat.java
Normal file
9
src/main/java/me/ryandw11/ultrachat/UltraChat.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package me.ryandw11.ultrachat;
|
||||||
|
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The main class of UltraChat.
|
||||||
|
*/
|
||||||
|
public class UltraChat extends JavaPlugin {
|
||||||
|
}
|
8
src/main/resources/plugin.yml
Normal file
8
src/main/resources/plugin.yml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
name: UltraChat
|
||||||
|
version: 3.0.0
|
||||||
|
main: me.ryandw11.ultrachat
|
||||||
|
author: Ryandw11
|
||||||
|
description: An advanced chat management plugin.
|
||||||
|
depend: [Vault]
|
||||||
|
softdepend: [PlaceholderAPI]
|
||||||
|
api-version: 1.13
|
@ -1,372 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.api.ChatType;
|
|
||||||
import me.ryandw11.ultrachat.api.Lang;
|
|
||||||
import me.ryandw11.ultrachat.api.managers.AddonManager;
|
|
||||||
import me.ryandw11.ultrachat.chatcolor.ChatColorManager;
|
|
||||||
import me.ryandw11.ultrachat.chatcolor.ChatColorUtil_Latest;
|
|
||||||
import me.ryandw11.ultrachat.chatcolor.ChatColorUtil_Old;
|
|
||||||
import me.ryandw11.ultrachat.chatcolor.ChatColorUtils;
|
|
||||||
import me.ryandw11.ultrachat.commands.*;
|
|
||||||
import me.ryandw11.ultrachat.formatting.ChannelJSON;
|
|
||||||
import me.ryandw11.ultrachat.formatting.NormalJSON;
|
|
||||||
import me.ryandw11.ultrachat.formatting.RangeJSON;
|
|
||||||
import me.ryandw11.ultrachat.gui.ColorGUI;
|
|
||||||
import me.ryandw11.ultrachat.gui.ColorGUI_1_15_R1;
|
|
||||||
import me.ryandw11.ultrachat.gui.ColorGUI_Latest;
|
|
||||||
import me.ryandw11.ultrachat.listner.*;
|
|
||||||
import me.ryandw11.ultrachat.pluginhooks.AdvancedBanMute;
|
|
||||||
import me.ryandw11.ultrachat.pluginhooks.EssentialsMute;
|
|
||||||
import me.ryandw11.ultrachat.util.Metrics;
|
|
||||||
import me.ryandw11.ultrachat.util.papi.PAPIDisabled;
|
|
||||||
import me.ryandw11.ultrachat.util.papi.PAPIEnabled;
|
|
||||||
import me.ryandw11.ultrachat.util.papi.PlaceHolderAPIHook;
|
|
||||||
import net.milkbowl.vault.chat.Chat;
|
|
||||||
import net.milkbowl.vault.permission.Permission;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Main Class
|
|
||||||
* <p>Updated for 1.16.1.</p>
|
|
||||||
* <p>Note: You should access manager classes from the {@link me.ryandw11.ultrachat.api.UltraChatAPI} class.</p>
|
|
||||||
* @author Ryandw11
|
|
||||||
* @version 2.5
|
|
||||||
*/
|
|
||||||
public class UltraChat extends JavaPlugin {
|
|
||||||
|
|
||||||
public static UltraChat plugin;
|
|
||||||
public static YamlConfiguration LANG;
|
|
||||||
public static File LANG_FILE;
|
|
||||||
public Permission perms;
|
|
||||||
public Chat chat;
|
|
||||||
public Boolean isChatStopped = false;
|
|
||||||
public ChatType chatType;
|
|
||||||
public List<UUID> staffToggle = new ArrayList<>();
|
|
||||||
public List<UUID> spyToggle = new ArrayList<>();
|
|
||||||
public PlaceHolderAPIHook papi;
|
|
||||||
public File dataFile = new File(getDataFolder() + "/data/players.yml");
|
|
||||||
public FileConfiguration data = YamlConfiguration.loadConfiguration(dataFile);
|
|
||||||
public File channelFile;
|
|
||||||
public FileConfiguration channel;
|
|
||||||
public File chatColorFile = new File(getDataFolder() + "/chatcolor.yml");
|
|
||||||
public FileConfiguration chatColorFC = YamlConfiguration.loadConfiguration(chatColorFile);
|
|
||||||
public String prefix;
|
|
||||||
public ChatColorManager chatColorManager;
|
|
||||||
public AddonManager addonManager;
|
|
||||||
public ChatColorUtils chatColorUtil;
|
|
||||||
private ColorGUI colorGUI;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEnable() {
|
|
||||||
|
|
||||||
plugin = this;
|
|
||||||
if (getServer().getPluginManager().getPlugin("Vault") == null && !setupChat()) {
|
|
||||||
getLogger().info(String.format("[%s] - Vault is not found!", getDescription().getName()));
|
|
||||||
getLogger().severe("§cWarning: You do not have Vault installed! This plugin is now disabled!");
|
|
||||||
Bukkit.getPluginManager().disablePlugin(this);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
|
||||||
getLogger().info("Hooked into PlaceholderAPI! You can use the place holders!");
|
|
||||||
papi = new PAPIEnabled();
|
|
||||||
} else {
|
|
||||||
papi = new PAPIDisabled();
|
|
||||||
}
|
|
||||||
getLogger().info(String.format("UltraChat is enabled and running fine! V: %s", getDescription().getVersion()));
|
|
||||||
if (getServer().getPluginManager().getPlugin("AdvancedBan") != null && getConfig().getBoolean("pluginhooks.AdvancedBan")) {
|
|
||||||
getLogger().info("AdvancedBan detected! Activating hook!");
|
|
||||||
getLogger().info("Mutes will now work with the chat types.");
|
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(new AdvancedBanMute(), this);
|
|
||||||
}
|
|
||||||
if (getServer().getPluginManager().getPlugin("Essentials") != null && getConfig().getBoolean("pluginhooks.Essentials")) {
|
|
||||||
getLogger().info("Essentials detected! Activating hook!");
|
|
||||||
getLogger().info("Mutes will now work with the chat types.");
|
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(new EssentialsMute(), this);
|
|
||||||
}
|
|
||||||
loadFile();
|
|
||||||
loadMethod();
|
|
||||||
registerConfig();
|
|
||||||
loadChannel();
|
|
||||||
|
|
||||||
setupPermissions();
|
|
||||||
setupChat();
|
|
||||||
setupFormatting();
|
|
||||||
loadLang();
|
|
||||||
if (plugin.getConfig().getBoolean("bstats")) {
|
|
||||||
Metrics m = new Metrics(this);
|
|
||||||
}
|
|
||||||
addonManager = new AddonManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDisable() {
|
|
||||||
getLogger().info("The plugin has been disabled correctly!");
|
|
||||||
saveFile();
|
|
||||||
saveChannel();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Setup the chat formatting.
|
|
||||||
*/
|
|
||||||
public void setupFormatting() {
|
|
||||||
String type = getConfig().getString("chat_format");
|
|
||||||
assert type != null;
|
|
||||||
if (type.equals("")) {
|
|
||||||
getLogger().info("UltraChat will not format the chat. To change this go into the config.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (type.toLowerCase()) {
|
|
||||||
case "channel":
|
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(new ChannelJSON(), this);
|
|
||||||
chatType = ChatType.CHANNEL;
|
|
||||||
getLogger().info("Channel chat mode enabled.");
|
|
||||||
break;
|
|
||||||
case "range":
|
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(new RangeJSON(), this);
|
|
||||||
Objects.requireNonNull(getCommand("global")).setExecutor(new Global());
|
|
||||||
Objects.requireNonNull(getCommand("world")).setExecutor(new World());
|
|
||||||
getLogger().info("Range chat mode enabled. The commands /global and /world are now also active.");
|
|
||||||
chatType = ChatType.RANGE;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(new NormalJSON(), this);
|
|
||||||
chatType = ChatType.NORMAL;
|
|
||||||
getLogger().info("Normal chat mode activated!");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads all of the Events and Commands.
|
|
||||||
*/
|
|
||||||
public void loadMethod() {
|
|
||||||
Objects.requireNonNull(getCommand("chat")).setExecutor(new NewChatCommand(this));
|
|
||||||
Objects.requireNonNull(getCommand("chat")).setTabCompleter(new CommandTabCompleter());
|
|
||||||
Objects.requireNonNull(getCommand("sc")).setExecutor(new StaffChat());
|
|
||||||
Objects.requireNonNull(getCommand("sctoggle")).setExecutor(new StaffChatToggle());
|
|
||||||
Objects.requireNonNull(getCommand("spy")).setExecutor(new SpyCommand());
|
|
||||||
Objects.requireNonNull(getCommand("channel")).setExecutor(new ChannelCmd());
|
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(new StopChat(), this);
|
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(new NoSwear(), this);
|
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(new Spy(), this);
|
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(new JoinListner(), this);
|
|
||||||
loadVersions();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads classes based upon the server version.
|
|
||||||
*/
|
|
||||||
private void loadVersions() {
|
|
||||||
String version;
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
|
|
||||||
|
|
||||||
} catch (ArrayIndexOutOfBoundsException w0w) {
|
|
||||||
version = " ";
|
|
||||||
}
|
|
||||||
if (version.equals("v1_14_R1") || version.equals("v1_15_R1")) {
|
|
||||||
plugin.getLogger().info("Server version is 1.14 or 1.15, enabling comparability mode.");
|
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(new Notify(), this);
|
|
||||||
colorGUI = new ColorGUI_1_15_R1();
|
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(new ColorGUI_1_15_R1(), this);
|
|
||||||
if (!(plugin.getConfig().getBoolean("ChatColor_Command")))
|
|
||||||
Objects.requireNonNull(getCommand("color")).setExecutor(new ColorGUI_1_15_R1());
|
|
||||||
|
|
||||||
this.chatColorUtil = new ChatColorUtil_Old();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(new Notify(), this);
|
|
||||||
colorGUI = new ColorGUI_Latest();
|
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(new ColorGUI_Latest(), this);
|
|
||||||
|
|
||||||
chatColorManager = new ChatColorManager(this, Objects.requireNonNull(chatColorFC.getConfigurationSection("chat_colors")));
|
|
||||||
|
|
||||||
if (!(plugin.getConfig().getBoolean("ChatColor_Command")))
|
|
||||||
Objects.requireNonNull(getCommand("color")).setExecutor(new ColorGUI_Latest());
|
|
||||||
|
|
||||||
this.chatColorUtil = new ChatColorUtil_Latest(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the ColorGUI class for the right version.
|
|
||||||
*
|
|
||||||
* @return A class that implements ColorGUI
|
|
||||||
*/
|
|
||||||
public ColorGUI getColorGUI() {
|
|
||||||
return colorGUI;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean setupChat() {
|
|
||||||
RegisteredServiceProvider<Chat> rsp = getServer().getServicesManager().getRegistration(Chat.class);
|
|
||||||
chat = rsp.getProvider();
|
|
||||||
return chat != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean setupPermissions() {
|
|
||||||
RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
|
|
||||||
perms = rsp.getProvider();
|
|
||||||
return perms != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save the data file.
|
|
||||||
*/
|
|
||||||
public void saveFile() {
|
|
||||||
try {
|
|
||||||
data.save(dataFile);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* load the data file
|
|
||||||
*/
|
|
||||||
public void loadFile() {
|
|
||||||
if (dataFile.exists()) {
|
|
||||||
try {
|
|
||||||
data.load(dataFile);
|
|
||||||
|
|
||||||
} catch (IOException | InvalidConfigurationException e) {
|
|
||||||
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
data.save(dataFile);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (chatColorFile.exists()) {
|
|
||||||
try {
|
|
||||||
chatColorFC.load(chatColorFile);
|
|
||||||
|
|
||||||
} catch (IOException | InvalidConfigurationException e) {
|
|
||||||
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
saveResource("chatcolor.yml", false);
|
|
||||||
chatColorFC = YamlConfiguration.loadConfiguration(chatColorFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save the channel file.
|
|
||||||
*/
|
|
||||||
public void saveChannel() {
|
|
||||||
|
|
||||||
try {
|
|
||||||
channel.save(channelFile);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load the cannel file.
|
|
||||||
*/
|
|
||||||
public void loadChannel() {
|
|
||||||
channelFile = new File(getDataFolder(), "channel.yml");
|
|
||||||
if (!channelFile.exists()) {
|
|
||||||
channelFile.getParentFile().mkdirs();
|
|
||||||
saveResource("channel.yml", false);
|
|
||||||
}
|
|
||||||
channel = new YamlConfiguration();
|
|
||||||
try {
|
|
||||||
channel.load(channelFile);
|
|
||||||
|
|
||||||
} catch (IOException | InvalidConfigurationException e) {
|
|
||||||
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the language file.
|
|
||||||
*
|
|
||||||
* @return The language file.
|
|
||||||
*/
|
|
||||||
public File getLangFile() {
|
|
||||||
return LANG_FILE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public YamlConfiguration getLang() {
|
|
||||||
return LANG;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load the language file.
|
|
||||||
*/
|
|
||||||
public void loadLang() {
|
|
||||||
File lang = new File(getDataFolder(), "lang.yml");
|
|
||||||
if (!lang.exists()) {
|
|
||||||
try {
|
|
||||||
getDataFolder().mkdir();
|
|
||||||
lang.createNewFile();
|
|
||||||
InputStream defConfigStream = this.getResource("lang.yml");
|
|
||||||
if (defConfigStream != null) {
|
|
||||||
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(defConfigStream));
|
|
||||||
|
|
||||||
defConfig.save(lang);
|
|
||||||
Lang.setFile(defConfig);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace(); // So they notice
|
|
||||||
getLogger().severe("The language file could not be created. Disabling plugin.");
|
|
||||||
this.setEnabled(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
YamlConfiguration conf = YamlConfiguration.loadConfiguration(lang);
|
|
||||||
for (Lang item : Lang.values()) {
|
|
||||||
if (conf.getString(item.getPath()) == null) {
|
|
||||||
conf.set(item.getPath(), item.getDefault());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Lang.setFile(conf);
|
|
||||||
LANG = conf;
|
|
||||||
LANG_FILE = lang;
|
|
||||||
try {
|
|
||||||
conf.save(getLangFile());
|
|
||||||
} catch (IOException e) {
|
|
||||||
getLogger().warning("Failed to save lang.yml.");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void registerConfig() {
|
|
||||||
saveDefaultConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.api;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The different modes chat can be in.
|
|
||||||
*/
|
|
||||||
public enum ChatType {
|
|
||||||
NORMAL,
|
|
||||||
CHANNEL,
|
|
||||||
RANGE
|
|
||||||
}
|
|
@ -1,118 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.api;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.UltraChat;
|
|
||||||
import me.ryandw11.ultrachat.formatting.PlayerFormatting;
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
|
||||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
|
||||||
import net.md_5.bungee.api.chat.HoverEvent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* API to standardize JSONChatBuilding
|
|
||||||
* <p>To be used with the MessageBuilder {@link MessageBuilder}
|
|
||||||
* @author Ryandw11
|
|
||||||
* @since 2.4
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class JSONChatBuilder {
|
|
||||||
|
|
||||||
private ComponentBuilder displayMessage;
|
|
||||||
private Player p;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a JSON Message
|
|
||||||
* @param displayMessage The base string that you would hover or click on.
|
|
||||||
*/
|
|
||||||
public JSONChatBuilder(String displayMessage) {
|
|
||||||
this.displayMessage = new ComponentBuilder(displayMessage);
|
|
||||||
p = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a JSON Message
|
|
||||||
* @param displayMessage The base string that you would hover or click on.
|
|
||||||
* @param p The player to use when doing PlaceHolders.
|
|
||||||
*/
|
|
||||||
public JSONChatBuilder(String displayMessage, Player p) {
|
|
||||||
PlayerFormatting pf = new PlayerFormatting(p);
|
|
||||||
String form = displayMessage.replace("%prefix%", pf.getPrefix())
|
|
||||||
.replace("%player%", p.getDisplayName())
|
|
||||||
.replace("%suffix%", pf.getSuffix());
|
|
||||||
this.displayMessage = new ComponentBuilder(UltraChat.plugin.papi.translatePlaceholders(form, p));
|
|
||||||
this.p = p;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a hove message. (ChatColors are translated)
|
|
||||||
* @param lore Lore
|
|
||||||
*/
|
|
||||||
public JSONChatBuilder setHoverShowText(List<String> lore) {
|
|
||||||
ComponentBuilder lores = new ComponentBuilder("");
|
|
||||||
int i = 0;
|
|
||||||
for(String s : lore) {
|
|
||||||
if(p != null)
|
|
||||||
lores.append(UltraChat.plugin.papi.translatePlaceholders(ChatColor.translateAlternateColorCodes('&', s), p));
|
|
||||||
else
|
|
||||||
lores.append(ChatColor.translateAlternateColorCodes('&', s));
|
|
||||||
if(i < lore.size() - 1)
|
|
||||||
lores.append("\n");
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
this.displayMessage.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, lores.create()));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Have the JSON open up a url.
|
|
||||||
* @param url The url
|
|
||||||
* @return The builder
|
|
||||||
*/
|
|
||||||
public JSONChatBuilder setClickOpenUrl(String url) {
|
|
||||||
this.displayMessage.event(new ClickEvent(ClickEvent.Action.OPEN_URL, url));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Have the JSON run a command.
|
|
||||||
* @param command The command to run
|
|
||||||
* @return The builder
|
|
||||||
*/
|
|
||||||
public JSONChatBuilder setClickRunCommand(String command) {
|
|
||||||
if(p == null)
|
|
||||||
this.displayMessage.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command));
|
|
||||||
else
|
|
||||||
this.displayMessage.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND,
|
|
||||||
UltraChat.plugin.papi.translatePlaceholders(command.replace("%player%", p.getName()), p)
|
|
||||||
));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Have the JSON suggest a command
|
|
||||||
* @param command The command
|
|
||||||
* @return The Builder
|
|
||||||
*/
|
|
||||||
public JSONChatBuilder setClickSuggestCommand(String command) {
|
|
||||||
if(p == null)
|
|
||||||
this.displayMessage.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command));
|
|
||||||
else
|
|
||||||
this.displayMessage.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND,
|
|
||||||
UltraChat.plugin.papi.translatePlaceholders(command.replace("%player%", p.getName()), p)
|
|
||||||
));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build the JSONChatMessage
|
|
||||||
* @return The BaseComponent[]
|
|
||||||
*/
|
|
||||||
public BaseComponent[] build() {
|
|
||||||
return this.displayMessage.create();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,92 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.api;
|
|
||||||
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
/**
|
|
||||||
* Language file
|
|
||||||
*/
|
|
||||||
public enum Lang {
|
|
||||||
PLUGIN_PREFIX("plugin-prefix","&7[&aUltraChat&7]"),
|
|
||||||
NO_PERM("no-perm", "&cYou do not have permission for this command!"),
|
|
||||||
ERROR_CHANNEL_ENABLED("error-channel-enabled", "&cError: Chat channels are not enabled on this server!"),
|
|
||||||
ERROR_CHANNEL_USAGE("error-channel-usage", "&cError: Use /channel {channel}!"),
|
|
||||||
CHANNEL_JSON_HOVER("channel-json-hover", "&5Click to join the channel!"),
|
|
||||||
CHAT_STOP_OFF("chat-stop-off", "&eThe chat has been &2Enabled &eby:&5 %p&e!"),
|
|
||||||
CHAT_STOP_ON("chat-stop-on", "&eThe chat has been &4disabled &eby:&5 %p&e!"),
|
|
||||||
BROADCAST_PREFIX("broadcast-prefix", "&7[&4UltraChat&7] "),
|
|
||||||
CHAT_CLEAR("chat-clear", "&3The chat has been cleared by &9%p&3!"),
|
|
||||||
CONFIG_RELOAD("config-reload", "&aThe config has been reloaded!"),
|
|
||||||
CHAT_CMD_NOT_VALID("chat-cmd-not-valid", "&cThat is not a valid command. Do /chat help for help!"),
|
|
||||||
CMD_SPY_ON("cmd-spy-on", "&bCommand Spy Enabled!"),
|
|
||||||
CMD_SPY_OFF("cmd-spy-off", "&bCommand Spy Disabled!"),
|
|
||||||
OTH_CMD_SPY_ON("oth-cmd-spy-on", "&a%p&b''s command spy has been enabled!"),
|
|
||||||
OTH_CMD_SPY_OFF("oth-cmd-spy-off", "&a%p&b''s command spy has ben disabled!"),
|
|
||||||
STAFF_CHAT_ON("staff-chat-on", "&dStaff chat has been enabled!"),
|
|
||||||
STAFF_CHAT_OFF("staff-chat-off", "&dStaff chat has been disabled!"),
|
|
||||||
STAFF_CHAT_FORMAT("staff-chat-format", "&7[&dStaff Chat&7] &9%p: &3%s"),
|
|
||||||
COLOR_GUI("color-gui", "&aChat Color"),
|
|
||||||
SILENT_JOIN_MESSAGE("silent-join-message", "%p &7has joined the game silently!"),
|
|
||||||
SILENT_LEAVE_MESSAGE("silent-leave-message", "%p &7has left the game silently!"),
|
|
||||||
NO_SWEAR("no-swear", "&cSwearing is not allowed on this server!"),
|
|
||||||
MENTION("mention", "&aSomeone has mentioned you!"),
|
|
||||||
CMD_SPY_FORMAT("cmd-spy-format", "&3[&6CommandSpy&3]&b %p: &3%s"),
|
|
||||||
STOP_CHAT_MESSAGE("stop-chat-message", "&cThe chat is currently not active."),
|
|
||||||
CONSOLE_CHAT_LOG("console-chat-log", "%p: %s"),
|
|
||||||
CHAT_UNSTOP_PERSONAL("chat-unstop-personal", "&2Chat Unstopped"),
|
|
||||||
CHAT_STOP_PERSONAL("chat-stop-personal", "&2Chat Stopped"),
|
|
||||||
SJOIN_SHOWN("sjoin-shown", "&bYour Join/Leave message will now be shown!"),
|
|
||||||
SJOIN_HIDE("sjoin-hide", "&bYour Join/Leave message will no longer be shown!"),
|
|
||||||
SJOIN_OTHER_SHOW("sjoin-other-show", "&b%p Join/Leave message will now be shown!"),
|
|
||||||
SJOIN_OTHER_HIDE("sjoin-other-hide", "&b%p Join/Leave message will no longer be shown!"),
|
|
||||||
HELP_PAGE_ERROR("help-page-error", "&cThere are only two help pages!"),
|
|
||||||
CHAT_COLOR_CHANGE("chat-color-change", "Your chat color has been changed!");
|
|
||||||
|
|
||||||
|
|
||||||
private String path;
|
|
||||||
private String def;
|
|
||||||
private static YamlConfiguration LANG;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Lang enum constructor.
|
|
||||||
* @param path The string path.
|
|
||||||
* @param start The default string.
|
|
||||||
*/
|
|
||||||
Lang(String path, String start) {
|
|
||||||
this.path = path;
|
|
||||||
this.def = start;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param config The config to set.
|
|
||||||
*/
|
|
||||||
public static void setFile(YamlConfiguration config) {
|
|
||||||
LANG = config;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return ChatColor.translateAlternateColorCodes('&', LANG.getString(this.path, def));
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toDefaultString(){
|
|
||||||
return LANG.getString(this.path, def);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the default value of the path.
|
|
||||||
* @return The default value of the path.
|
|
||||||
*/
|
|
||||||
public String getDefault() {
|
|
||||||
return this.def;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the path to the string.
|
|
||||||
* @return The path to the string.
|
|
||||||
*/
|
|
||||||
public String getPath() {
|
|
||||||
return this.path;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,56 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.api;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
|
||||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
|
||||||
import net.md_5.bungee.api.chat.ComponentBuilder.FormatRetention;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Easy Builder to build several JSON sections into a single message.
|
|
||||||
* {@link JSONChatBuilder}
|
|
||||||
* @author Ryandw11
|
|
||||||
* @since 2.4
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class MessageBuilder {
|
|
||||||
|
|
||||||
private ComponentBuilder component;
|
|
||||||
public MessageBuilder() {
|
|
||||||
component = new ComponentBuilder("");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a JSONChatBuilder to the message
|
|
||||||
* @param json the JSONChatBuilder to add
|
|
||||||
* @return The MessageBuilder to chain.
|
|
||||||
*/
|
|
||||||
public MessageBuilder addJSON(JSONChatBuilder json) {
|
|
||||||
component.append(json.build(), FormatRetention.NONE);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a string to the message
|
|
||||||
* @param s the string to add
|
|
||||||
* @return the builder to chain
|
|
||||||
*/
|
|
||||||
public MessageBuilder addString(String s) {
|
|
||||||
TextComponent tc = new TextComponent(s);
|
|
||||||
component.append(tc, FormatRetention.NONE);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a base component to the message
|
|
||||||
* @param bc the component to add
|
|
||||||
* @return The Buider to chain
|
|
||||||
*/
|
|
||||||
public MessageBuilder addBaseComponent(BaseComponent[] bc) {
|
|
||||||
component.append(bc, FormatRetention.NONE);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BaseComponent[] build() {
|
|
||||||
return this.component.create();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,166 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.api;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.api.managers.ChannelManager;
|
|
||||||
import me.ryandw11.ultrachat.chatcolor.ChatColorManager;
|
|
||||||
import me.ryandw11.ultrachat.chatcolor.ChatColorUtils;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.UltraChat;
|
|
||||||
import me.ryandw11.ultrachat.api.channels.ChannelBuilder;
|
|
||||||
import me.ryandw11.ultrachat.api.channels.ChatChannel;
|
|
||||||
import me.ryandw11.ultrachat.api.managers.AddonManager;
|
|
||||||
import me.ryandw11.ultrachat.formatting.PlayerFormatting;
|
|
||||||
/**
|
|
||||||
* UltraChatAPI
|
|
||||||
* @author Ryandw11
|
|
||||||
* @version 2.5
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class UltraChatAPI{
|
|
||||||
private UltraChat plugin;
|
|
||||||
public UltraChatAPI(){
|
|
||||||
this.plugin = UltraChat.plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the current channel of a player.
|
|
||||||
* @param player The uuid of the player you want to get.
|
|
||||||
* @return The chat channel.
|
|
||||||
* @deprecated Use the channel manager instead.
|
|
||||||
*/
|
|
||||||
public ChatChannel getPlayerCurrentChannel(UUID player) {
|
|
||||||
return new ChannelBuilder(plugin.data.getString(player + ".channel")).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the addon manager.
|
|
||||||
* @return The addon manager.
|
|
||||||
*/
|
|
||||||
public AddonManager getAddonManager() {
|
|
||||||
return plugin.addonManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the current chat type.
|
|
||||||
* @return chat type
|
|
||||||
*/
|
|
||||||
public ChatType getChatType(){
|
|
||||||
return plugin.chatType;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the chat mode. Can be disabled in the config.
|
|
||||||
* @param cm The chat manager
|
|
||||||
*/
|
|
||||||
public void setType(ChatType cm){
|
|
||||||
if(!plugin.getConfig().getBoolean("apirestrict")){
|
|
||||||
plugin.getConfig().set("chat_format", cm.toString().toLowerCase());
|
|
||||||
plugin.getLogger().warning("A plugin has changed your chat mode to " + cm.toString() + "!");
|
|
||||||
plugin.saveConfig();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
plugin.getLogger().warning("A plugin has tried to changed your chat type!");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Grab the player's formatting.
|
|
||||||
* @param p The player.
|
|
||||||
* @return The player's formatting.
|
|
||||||
* @deprecated Construct the {@link PlayerFormatting} class yourself.
|
|
||||||
*/
|
|
||||||
public PlayerFormatting getPlayerFormatting(Player p){
|
|
||||||
return new PlayerFormatting(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a player's color.
|
|
||||||
* <p>This will return a string Such as &4 or {#FFFFFF}.</p>
|
|
||||||
* <p>Note: The colors interpreted are from the chatcolor.yml file. To also get color data from the use {@link me.ryandw11.ultrachat.util.ChatUtil#translateColorCode(String)}</p>
|
|
||||||
* @param player The player to get the color for
|
|
||||||
* @return color code.
|
|
||||||
*/
|
|
||||||
public String getPlayerColor(Player player){
|
|
||||||
return plugin.data.getString(player.getUniqueId() + ".color");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set a player's color.
|
|
||||||
* @param player The player color to set
|
|
||||||
* @param color The color to set
|
|
||||||
* <p>Keep in mind that this color is interpreted from the chatcolor.yml file, not the default colors.</p>
|
|
||||||
*/
|
|
||||||
public void setPlayerColor(Player player, String color){
|
|
||||||
plugin.data.set(player.getUniqueId() + ".color", color);
|
|
||||||
plugin.saveFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the swear word list.
|
|
||||||
* @return Block swear words.
|
|
||||||
*/
|
|
||||||
public List<String> getSwearWords(){
|
|
||||||
return plugin.getConfig().getStringList("Blocked_Words");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the swear word list.
|
|
||||||
* @param words The words to add
|
|
||||||
*/
|
|
||||||
public void setSwearWords(List<String> words){
|
|
||||||
plugin.getConfig().set("Blocked_Words", words);
|
|
||||||
plugin.saveConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the current formatting type.
|
|
||||||
* @return The value of the config.
|
|
||||||
*/
|
|
||||||
public ChatType getFormattingType(){
|
|
||||||
return plugin.chatType;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the chat color utility interface.
|
|
||||||
* <p>Note: Most methods from this interface are wrapped in the {@link me.ryandw11.ultrachat.util.ChatUtil} class.</p>
|
|
||||||
* @return The chat color utility interface.
|
|
||||||
*/
|
|
||||||
public ChatColorUtils getChatColorUtil(){
|
|
||||||
return plugin.chatColorUtil;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the chat color manager.
|
|
||||||
* <p>Note: Most uses for this class is covered by the {@link me.ryandw11.ultrachat.util.ChatUtil} class.</p>
|
|
||||||
* <p><b>This class is only available on 1.16+ servers. This WILL return null on any version below 1.16.</b></p>
|
|
||||||
* @return The chat color manager.
|
|
||||||
*/
|
|
||||||
public ChatColorManager getChatColorManager(){
|
|
||||||
return plugin.chatColorManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChannelManager getChannelManager(){
|
|
||||||
return new ChannelManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the current active hooks.
|
|
||||||
* @return The set with the names of the plugins. Returns null if no hooks are active.
|
|
||||||
*/
|
|
||||||
public Set<String> getActiveHooks(){
|
|
||||||
Set<String> s = new HashSet<>();
|
|
||||||
if(Bukkit.getServer().getPluginManager().getPlugin("AdvancedBan") != null && plugin.getConfig().getBoolean("pluginhooks.Essentials")){
|
|
||||||
s.add("Essentials");
|
|
||||||
}
|
|
||||||
if(Bukkit.getServer().getPluginManager().getPlugin("Essentials") != null && plugin.getConfig().getBoolean("pluginhooks.AdvancedBan")){
|
|
||||||
s.add("AdvancedBan");
|
|
||||||
}
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,133 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.api.channels;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.UltraChat;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A Builder to make a channel.
|
|
||||||
* @author Ryandw11
|
|
||||||
* @since 2.3.3
|
|
||||||
*/
|
|
||||||
public class ChannelBuilder {
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
private String prefix;
|
|
||||||
private String permission;
|
|
||||||
private boolean alwaysAppear;
|
|
||||||
private String format;
|
|
||||||
private List<String> json;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Builder to create a channel.
|
|
||||||
* @param name The name of the channel (usually lowercase)
|
|
||||||
*/
|
|
||||||
public ChannelBuilder(String name) {
|
|
||||||
this.setName(name);
|
|
||||||
setPrefix("[" + name + "]");
|
|
||||||
setPermission("none");
|
|
||||||
setAlwaysAppear(false);
|
|
||||||
setJson(new ArrayList<String>());
|
|
||||||
setFormat("%prefix% %player% %suffix%&7 >> ");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the name of the channel.
|
|
||||||
* @param name The name. (Lowercase is standard)
|
|
||||||
* @return The builder
|
|
||||||
*/
|
|
||||||
public ChannelBuilder setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getPrefix() {
|
|
||||||
return prefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the prefix of the channel
|
|
||||||
* @param prefix The prefix (supports & codes)
|
|
||||||
* @return The builder
|
|
||||||
*/
|
|
||||||
public ChannelBuilder setPrefix(String prefix) {
|
|
||||||
this.prefix = prefix;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getPermission() {
|
|
||||||
return permission;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the permission for the channel.
|
|
||||||
* @param permission The permission
|
|
||||||
* @return The builder.
|
|
||||||
*/
|
|
||||||
public ChannelBuilder setPermission(String permission) {
|
|
||||||
this.permission = permission;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isAlwaysAppear() {
|
|
||||||
return alwaysAppear;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set if the channel is always appear
|
|
||||||
* @param alwaysAppear If the channel should always appear.
|
|
||||||
* @return The builder
|
|
||||||
*/
|
|
||||||
public ChannelBuilder setAlwaysAppear(boolean alwaysAppear) {
|
|
||||||
this.alwaysAppear = alwaysAppear;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build the channel
|
|
||||||
* @return The channel. Note: If the channel name is already used it will return the existing one.
|
|
||||||
*/
|
|
||||||
public ChatChannel build() {
|
|
||||||
if(UltraChat.plugin.channel.contains(this.name)) {
|
|
||||||
ConfigurationSection cs = UltraChat.plugin.channel.getConfigurationSection(this.name);
|
|
||||||
assert cs != null;
|
|
||||||
this.setPrefix(cs.getString("prefix"));
|
|
||||||
this.setPermission(cs.getString("permission"));
|
|
||||||
this.setAlwaysAppear(cs.getBoolean("always_appear"));
|
|
||||||
this.setFormat(cs.getString("format"));
|
|
||||||
this.setJson(cs.getStringList("JSON"));
|
|
||||||
}
|
|
||||||
return new ChatChannel(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getJson() {
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the json lore.
|
|
||||||
* @param json List of lore.
|
|
||||||
*/
|
|
||||||
public ChannelBuilder setJson(List<String> json) {
|
|
||||||
this.json = json;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFormat() {
|
|
||||||
return format;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChannelBuilder setFormat(String format) {
|
|
||||||
this.format = format;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,153 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.api.channels;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.UltraChat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class is used the manage channels.
|
|
||||||
* <p>Note: All set methods automatically call the {@link #update()} method.</p>
|
|
||||||
*/
|
|
||||||
public class ChatChannel {
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
private String prefix;
|
|
||||||
private String permission;
|
|
||||||
private boolean alwaysAppear;
|
|
||||||
private String format;
|
|
||||||
private List<String> json;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* For internal use only. Always use the channel builder.
|
|
||||||
* @param cb The builder that was used to build the channel.
|
|
||||||
*/
|
|
||||||
public ChatChannel(ChannelBuilder cb) {
|
|
||||||
this.name = cb.getName();
|
|
||||||
this.prefix = cb.getPrefix();
|
|
||||||
this.permission = cb.getPermission();
|
|
||||||
this.alwaysAppear = cb.isAlwaysAppear();
|
|
||||||
this.json = cb.getJson();
|
|
||||||
this.format = cb.getFormat();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the name of the channel.
|
|
||||||
* <p>Note: If this channel is the default channel then you will need to change the default channel name manually</p>
|
|
||||||
* @param name The name of the channel.
|
|
||||||
*/
|
|
||||||
public void setName(String name) {
|
|
||||||
UltraChat.plugin.channel.set(this.name, null);
|
|
||||||
this.name = name;
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the prefix of the channel.
|
|
||||||
* @return The prefix of the channel.
|
|
||||||
*/
|
|
||||||
public String getPrefix() {
|
|
||||||
return prefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the prefix of the channel.
|
|
||||||
* @param prefix The prefix of the channel.
|
|
||||||
*/
|
|
||||||
public void setPrefix(String prefix) {
|
|
||||||
this.prefix = prefix;
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the permission for the channel.
|
|
||||||
* @return The permission for the channel.
|
|
||||||
*/
|
|
||||||
public String getPermission() {
|
|
||||||
return permission;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the permission for the channel.
|
|
||||||
* @param permission The permission for the channel.
|
|
||||||
*/
|
|
||||||
public void setPermission(String permission) {
|
|
||||||
this.permission = permission;
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If the channel always appears.
|
|
||||||
* @return If the channel always appears.
|
|
||||||
*/
|
|
||||||
public boolean isAlwaysAppear() {
|
|
||||||
return alwaysAppear;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set if the channel will always appear in chat.
|
|
||||||
* @param alwaysAppear If the channel will always appear.
|
|
||||||
*/
|
|
||||||
public void setAlwaysAppear(boolean alwaysAppear) {
|
|
||||||
this.alwaysAppear = alwaysAppear;
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the json of the channel
|
|
||||||
* @return The json.
|
|
||||||
*/
|
|
||||||
public List<String> getJson() {
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the json for the channel.
|
|
||||||
* @param json The json.
|
|
||||||
*/
|
|
||||||
public void setJson(List<String> json) {
|
|
||||||
this.json = json;
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call this after every change and after initialization to save the channel to the files.
|
|
||||||
*/
|
|
||||||
private void update() {
|
|
||||||
UltraChat plugin = UltraChat.plugin;
|
|
||||||
plugin.channel.set(this.getName() + ".prefix", this.getPrefix());
|
|
||||||
plugin.channel.set(this.getName() + ".permission", this.getPrefix());
|
|
||||||
plugin.channel.set(this.getName() + ".always_appear", this.isAlwaysAppear());
|
|
||||||
plugin.channel.set(this.getName() + ".format", this.getFormat());
|
|
||||||
plugin.channel.set(this.getName() + ".JSON", this.getJson());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete the channel
|
|
||||||
* @deprecated It is not recommended to use this.
|
|
||||||
*/
|
|
||||||
public void delete() {
|
|
||||||
UltraChat.plugin.channel.set(this.getName(), null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the format of the channel.
|
|
||||||
* @return The format
|
|
||||||
*/
|
|
||||||
public String getFormat() {
|
|
||||||
return format;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the format of the channel.
|
|
||||||
* @param format The format.
|
|
||||||
*/
|
|
||||||
public void setFormat(String format) {
|
|
||||||
this.format = format;
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.api.events;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This event is called when the staff chat is used.
|
|
||||||
*/
|
|
||||||
public class StaffChatEvent extends Event {
|
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
private Player player;
|
|
||||||
private String message;
|
|
||||||
private boolean cancelled;
|
|
||||||
|
|
||||||
public StaffChatEvent(Player p, String message) {
|
|
||||||
player = p;
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the player
|
|
||||||
* @return The player. (Can be null if sent by the console)
|
|
||||||
*/
|
|
||||||
public Player getPlayer() {
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMessage() {
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCancelled() {
|
|
||||||
return cancelled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCancelled(boolean cancel) {
|
|
||||||
cancelled = cancel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,97 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.api.events;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.api.ChatType;
|
|
||||||
import me.ryandw11.ultrachat.api.events.properties.ChatProperties;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The UltraChatEvent is used when a player chats. This event gives you more information than the normal AsyncChatEvent.
|
|
||||||
* <p>Note: Since API Version 2.5 this event is only needed when you want specific ultraChat information.</p>
|
|
||||||
*/
|
|
||||||
public class UltraChatEvent extends Event{
|
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
private Player player;
|
|
||||||
private String chat;
|
|
||||||
private Set<Player> recipients;
|
|
||||||
private ChatType type;
|
|
||||||
private ChatProperties prop;
|
|
||||||
private boolean cancelled;
|
|
||||||
|
|
||||||
public UltraChatEvent(Player p, String chat, Set<Player> recipients, ChatType ct, ChatProperties properties) {
|
|
||||||
super(true);
|
|
||||||
player = p;
|
|
||||||
this.chat = chat;
|
|
||||||
this.recipients = recipients;
|
|
||||||
this.type = ct;
|
|
||||||
this.prop = properties;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Grab the recipients.
|
|
||||||
* @return The recipients.
|
|
||||||
*/
|
|
||||||
public Set<Player> getRecipients(){
|
|
||||||
return recipients;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Set the recipients.
|
|
||||||
* @param recipients The set of recipients.
|
|
||||||
*/
|
|
||||||
public void setRecipients(Set<Player> recipients){
|
|
||||||
this.recipients = recipients;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Player getPlayer() {
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMessage() {
|
|
||||||
return chat;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the message
|
|
||||||
* @param message The message.
|
|
||||||
*/
|
|
||||||
public void setMessage(String message){
|
|
||||||
chat = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCancelled(){
|
|
||||||
return cancelled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCancelled(boolean cancel){
|
|
||||||
cancelled = cancel;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the type of the chat used.
|
|
||||||
* @return The type of chat used.
|
|
||||||
*/
|
|
||||||
public ChatType getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the properties.
|
|
||||||
* @return Get the information for a certain chat event.
|
|
||||||
*/
|
|
||||||
public ChatProperties getProperties() {
|
|
||||||
return prop;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.api.events.properties;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.api.channels.ChannelBuilder;
|
|
||||||
import me.ryandw11.ultrachat.api.channels.ChatChannel;
|
|
||||||
|
|
||||||
public class ChannelProperties implements ChatProperties {
|
|
||||||
|
|
||||||
private boolean json;
|
|
||||||
private String channel;
|
|
||||||
|
|
||||||
public ChannelProperties(boolean json, String channel) {
|
|
||||||
this.json = json;
|
|
||||||
this.channel = channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isComponent() {
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChatChannel getChannel() {
|
|
||||||
ChatChannel cc = new ChannelBuilder(channel).build();
|
|
||||||
return cc;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.api.events.properties;
|
|
||||||
|
|
||||||
public interface ChatProperties {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated As of version 2.5 this will always be true as the plugin is always in JSON mode.
|
|
||||||
* @return If the plugin has json components enabled.
|
|
||||||
*/
|
|
||||||
boolean isComponent();
|
|
||||||
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.api.events.properties;
|
|
||||||
|
|
||||||
public class NormalProperties implements ChatProperties {
|
|
||||||
|
|
||||||
private boolean json;
|
|
||||||
public NormalProperties(boolean isJson) {
|
|
||||||
this.json = isJson;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isComponent() {
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.api.events.properties;
|
|
||||||
|
|
||||||
public class RangeProperties implements ChatProperties {
|
|
||||||
|
|
||||||
private boolean json;
|
|
||||||
private RangeType rt;
|
|
||||||
public RangeProperties(boolean json, RangeType rt) {
|
|
||||||
this.json = json;
|
|
||||||
this.rt = rt;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isComponent() {
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the Range mode in use.
|
|
||||||
* @return The range type.
|
|
||||||
*/
|
|
||||||
public RangeType getType() {
|
|
||||||
return rt;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.api.events.properties;
|
|
||||||
|
|
||||||
public enum RangeType {
|
|
||||||
LOCAL,
|
|
||||||
WORLD,
|
|
||||||
GLOBAL
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.api.managers;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.api.UltraChatAPI;
|
|
||||||
import me.ryandw11.ultrachat.api.placeholders.PlaceholderAddon;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class handles any addons to the plugin.
|
|
||||||
* <p>The instance of this class can be retrieved from {@link UltraChatAPI#getAddonManager()}</p>
|
|
||||||
*/
|
|
||||||
public class AddonManager {
|
|
||||||
private List<PlaceholderAddon> pa;
|
|
||||||
public AddonManager() {
|
|
||||||
pa = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add an addon
|
|
||||||
* @param pa The addon to add.
|
|
||||||
*/
|
|
||||||
public void addAddon(PlaceholderAddon pa) {
|
|
||||||
this.pa.add(pa);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the list of addons.
|
|
||||||
* @return The list of addons.
|
|
||||||
*/
|
|
||||||
public List<PlaceholderAddon> getAddons(){
|
|
||||||
return pa;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replace the placeholders in a string.
|
|
||||||
* @param s The string.
|
|
||||||
* @param p The player UUID.
|
|
||||||
* @return The string with the placeholders replaced.
|
|
||||||
*/
|
|
||||||
public String replacePlaceholders(String s, UUID p) {
|
|
||||||
String output = s;
|
|
||||||
for(PlaceholderAddon fs : pa) {
|
|
||||||
output = output.replace(fs.getName(), fs.getString(p));
|
|
||||||
}
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,140 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.api.managers;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.UltraChat;
|
|
||||||
import me.ryandw11.ultrachat.api.channels.ChannelBuilder;
|
|
||||||
import me.ryandw11.ultrachat.api.channels.ChatChannel;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class handles the channels of the plugin.
|
|
||||||
* <p>Get the instance of this class from {@link me.ryandw11.ultrachat.api.UltraChatAPI#getChannelManager()}</p>
|
|
||||||
*/
|
|
||||||
public class ChannelManager {
|
|
||||||
private UltraChat plugin;
|
|
||||||
public ChannelManager() {
|
|
||||||
this.plugin = UltraChat.plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a channel via its name
|
|
||||||
* @param name The name of the channel
|
|
||||||
* @return The channel.
|
|
||||||
*/
|
|
||||||
public ChatChannel getChannelByName(String name) {
|
|
||||||
ChannelBuilder cb = new ChannelBuilder(name);
|
|
||||||
return cb.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Grab the player's current channel.
|
|
||||||
* @param player The player to get the channel from.
|
|
||||||
* @return The player's current channel.
|
|
||||||
*/
|
|
||||||
public ChatChannel getPlayerChannel(Player player){
|
|
||||||
ChannelBuilder cb = new ChannelBuilder(plugin.data.getString(player.getUniqueId() + ".channel"));
|
|
||||||
return cb.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Grab an offline player's current channel.
|
|
||||||
* @param player The player to get the channel from.
|
|
||||||
* @return That UUID's current channel.
|
|
||||||
*/
|
|
||||||
public ChatChannel getPlayerChannel(UUID player) {
|
|
||||||
ChannelBuilder cb = new ChannelBuilder(plugin.data.getString(player + ".channel"));
|
|
||||||
return cb.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the servers default channel.
|
|
||||||
* @return Default Channel
|
|
||||||
*/
|
|
||||||
public ChatChannel getDefaultChannel(){
|
|
||||||
ChannelBuilder cb = new ChannelBuilder(plugin.getConfig().getString("Default_Channel"));
|
|
||||||
return cb.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the player's channel.
|
|
||||||
* @param player The player to set.
|
|
||||||
* @param channel The channel.
|
|
||||||
*/
|
|
||||||
public void setPlayerChannel(Player player, ChatChannel channel){
|
|
||||||
plugin.data.set(player.getUniqueId() + ".channel", channel.getName());
|
|
||||||
plugin.saveFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the player's channel.
|
|
||||||
* @param player The player to set.
|
|
||||||
* @param channel The channel.
|
|
||||||
*/
|
|
||||||
public void setPlayerChannel(UUID player, ChatChannel channel) {
|
|
||||||
plugin.data.set(player + ".channel", channel.getName());
|
|
||||||
plugin.saveFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the default channel
|
|
||||||
* @param channel The channel.
|
|
||||||
*/
|
|
||||||
public void setDefaultChannel(ChatChannel channel){
|
|
||||||
plugin.getConfig().set("Default_Config", channel.getName());
|
|
||||||
plugin.saveConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If a given channel exists (In this instance if it is save in the files)
|
|
||||||
* @param channel The channel to check.
|
|
||||||
* @return If the channel exists.
|
|
||||||
*/
|
|
||||||
public boolean channelExists(ChatChannel channel) {
|
|
||||||
return plugin.channel.contains(channel.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If a given channel exists based upon the name.
|
|
||||||
* @param name The name of the channel to check
|
|
||||||
* @return If the channel exists.
|
|
||||||
*/
|
|
||||||
public boolean channelExists(String name) {
|
|
||||||
return plugin.channel.contains(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all online players in a given channel.
|
|
||||||
* @param channel The channel to get the players from.
|
|
||||||
* @return The list of players. (Unmodifiable)
|
|
||||||
*/
|
|
||||||
public List<Player> getPlayersInChannel(ChatChannel channel){
|
|
||||||
List<Player> output = new ArrayList<>();
|
|
||||||
for(Player p : Bukkit.getOnlinePlayers()) {
|
|
||||||
if(this.getPlayerChannel(p).getName().equals(channel.getName())) {
|
|
||||||
output.add(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Collections.unmodifiableList(output);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all players in a channel online or offline.
|
|
||||||
* @param channel The channel to get the UUIDs from.
|
|
||||||
* @return The list of UUIDs. (Unmodifiable)
|
|
||||||
*/
|
|
||||||
public List<UUID> getAllPlayersInChannel(ChatChannel channel){
|
|
||||||
List<UUID> output = new ArrayList<>();
|
|
||||||
for(String s : Objects.requireNonNull(plugin.data.getConfigurationSection("")).getKeys(false)) {
|
|
||||||
UUID ud = UUID.fromString(s);
|
|
||||||
if(this.getPlayerChannel(ud).getName().equals(channel.getName())) {
|
|
||||||
output.add(ud);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Collections.unmodifiableList(output);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,278 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.api.managers;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.UltraChat;
|
|
||||||
import me.ryandw11.ultrachat.api.JSONChatBuilder;
|
|
||||||
import me.ryandw11.ultrachat.api.MessageBuilder;
|
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
|
||||||
|
|
||||||
public class JComponentManager {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the final basecomponent from a message.
|
|
||||||
* @param message The string message
|
|
||||||
* @return The final basecomponent
|
|
||||||
*/
|
|
||||||
public static BaseComponent[] formatComponents(String message) {
|
|
||||||
/*
|
|
||||||
* Parse the message for JSON components
|
|
||||||
*/
|
|
||||||
List<String> msgs = new ArrayList<String>();
|
|
||||||
List<String> compName = new ArrayList<String>();
|
|
||||||
|
|
||||||
List<String> fin = new ArrayList<String>();
|
|
||||||
|
|
||||||
String temps = "";
|
|
||||||
for(int i = 0; i < message.length(); i++) {
|
|
||||||
char c = message.charAt(i);
|
|
||||||
if(c == '{') {
|
|
||||||
msgs.add(temps);
|
|
||||||
fin.add(temps);
|
|
||||||
temps = "";
|
|
||||||
}
|
|
||||||
else if(c == '}') {
|
|
||||||
compName.add(temps);
|
|
||||||
fin.add(temps);
|
|
||||||
temps = "";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
temps += c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
msgs.add(temps);
|
|
||||||
fin.add(temps);
|
|
||||||
/*
|
|
||||||
* Generate the final BaseComponent
|
|
||||||
*/
|
|
||||||
MessageBuilder mb = new MessageBuilder();
|
|
||||||
|
|
||||||
// Loops through the final array.
|
|
||||||
for(String s : fin) {
|
|
||||||
// If the message is a normal message.
|
|
||||||
if(msgs.contains(s)) {
|
|
||||||
mb.addString(s);
|
|
||||||
}
|
|
||||||
// If the message is a component
|
|
||||||
else if(compName.contains(s)) {
|
|
||||||
ConfigurationSection cs = null;
|
|
||||||
for(String st : UltraChat.plugin.getConfig().getConfigurationSection("JSON_Components").getKeys(false)) {
|
|
||||||
if(st.equals(s)) {
|
|
||||||
cs = UltraChat.plugin.getConfig().getConfigurationSection("JSON_Components." + st);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(cs == null) {
|
|
||||||
Bukkit.getLogger().warning("Error: Can not find JSON Component named: " + s);
|
|
||||||
}else {
|
|
||||||
JSONChatBuilder jsb = new JSONChatBuilder(cs.getString("Message"));
|
|
||||||
// If the component contains the click event.
|
|
||||||
if(cs.contains("Events.Click")) {
|
|
||||||
if(cs.contains("Events.Click.Open_URL"))
|
|
||||||
jsb.setClickOpenUrl(cs.getString("Events.Click.Open_URL"));
|
|
||||||
else if(cs.contains("Events.Click.Run_Command"))
|
|
||||||
jsb.setClickRunCommand(cs.getString("Events.Click.Run_Command"));
|
|
||||||
else if(cs.contains("Events.Click.Suggest_Command"))
|
|
||||||
jsb.setClickSuggestCommand(cs.getString("Events.Click.Suggest_Command"));
|
|
||||||
}
|
|
||||||
// If the component contains the hover event.
|
|
||||||
if(cs.contains("Events.Hover")) {
|
|
||||||
if(cs.contains("Events.Hover.Show_Text"))
|
|
||||||
jsb.setHoverShowText(cs.getStringList("Events.Hover.Show_Text"));
|
|
||||||
}
|
|
||||||
|
|
||||||
mb.addJSON(jsb);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build the message builder and return it
|
|
||||||
return mb.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the final basecomponent from a message.
|
|
||||||
* @param message The string message
|
|
||||||
* @param p The player to translate PAPI for.
|
|
||||||
* @return The final basecomponent
|
|
||||||
*/
|
|
||||||
public static BaseComponent[] formatComponents(String message, Player p) {
|
|
||||||
/*
|
|
||||||
* Parse the message for JSON components
|
|
||||||
*/
|
|
||||||
List<String> msgs = new ArrayList<String>();
|
|
||||||
List<String> compName = new ArrayList<String>();
|
|
||||||
|
|
||||||
List<String> fin = new ArrayList<String>();
|
|
||||||
|
|
||||||
String temps = "";
|
|
||||||
for(int i = 0; i < message.length(); i++) {
|
|
||||||
char c = message.charAt(i);
|
|
||||||
if(c == '{') {
|
|
||||||
msgs.add(temps);
|
|
||||||
fin.add(temps);
|
|
||||||
temps = "";
|
|
||||||
}
|
|
||||||
else if(c == '}') {
|
|
||||||
compName.add(temps);
|
|
||||||
fin.add(temps);
|
|
||||||
temps = "";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
temps += c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
msgs.add(temps);
|
|
||||||
fin.add(temps);
|
|
||||||
/*
|
|
||||||
* Generate the final BaseComponent
|
|
||||||
*/
|
|
||||||
MessageBuilder mb = new MessageBuilder();
|
|
||||||
|
|
||||||
// Loops through the final array.
|
|
||||||
for(String s : fin) {
|
|
||||||
// If the message is a normal message.
|
|
||||||
if(msgs.contains(s)) {
|
|
||||||
mb.addString(s);
|
|
||||||
}
|
|
||||||
// If the message is a component
|
|
||||||
else if(compName.contains(s)) {
|
|
||||||
ConfigurationSection cs = null;
|
|
||||||
for(String st : UltraChat.plugin.getConfig().getConfigurationSection("JSON_Components").getKeys(false)) {
|
|
||||||
if(st.equals(s)) {
|
|
||||||
cs = UltraChat.plugin.getConfig().getConfigurationSection("JSON_Components." + st);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(cs == null) {
|
|
||||||
Bukkit.getLogger().warning("Error: Can not find JSON Component named: " + s);
|
|
||||||
}else {
|
|
||||||
JSONChatBuilder jsb = new JSONChatBuilder(cs.getString("Message"), p);
|
|
||||||
// If the component contains the click event.
|
|
||||||
if(cs.contains("Events.Click")) {
|
|
||||||
if(cs.contains("Events.Click.Open_URL"))
|
|
||||||
jsb.setClickOpenUrl(cs.getString("Events.Click.Open_URL"));
|
|
||||||
else if(cs.contains("Events.Click.Run_Command"))
|
|
||||||
jsb.setClickRunCommand(cs.getString("Events.Click.Run_Command"));
|
|
||||||
else if(cs.contains("Events.Click.Suggest_Command"))
|
|
||||||
jsb.setClickSuggestCommand(cs.getString("Events.Click.Suggest_Command"));
|
|
||||||
}
|
|
||||||
// If the component contains the hover event.
|
|
||||||
if(cs.contains("Events.Hover")) {
|
|
||||||
if(cs.contains("Events.Hover.Show_Text")) {
|
|
||||||
List<String> finals = new ArrayList<String>();
|
|
||||||
for(String st : cs.getStringList("Events.Hover.Show_Text")) {
|
|
||||||
finals.add(UltraChat.plugin.addonManager.replacePlaceholders(st, p.getUniqueId()));
|
|
||||||
}
|
|
||||||
jsb.setHoverShowText(finals);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
mb.addJSON(jsb);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build the message builder and return it
|
|
||||||
return mb.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the final basecomponent from a message.
|
|
||||||
* @param message The string message
|
|
||||||
* @param p The player to translate PAPI for.
|
|
||||||
* @return The final basecomponent
|
|
||||||
*/
|
|
||||||
public static BaseComponent[] formatComponents(String message, UUID p) {
|
|
||||||
/*
|
|
||||||
* Parse the message for JSON components
|
|
||||||
*/
|
|
||||||
List<String> msgs = new ArrayList<String>();
|
|
||||||
List<String> compName = new ArrayList<String>();
|
|
||||||
|
|
||||||
List<String> fin = new ArrayList<String>();
|
|
||||||
|
|
||||||
String temps = "";
|
|
||||||
for(int i = 0; i < message.length(); i++) {
|
|
||||||
char c = message.charAt(i);
|
|
||||||
if(c == '{') {
|
|
||||||
msgs.add(temps);
|
|
||||||
fin.add(temps);
|
|
||||||
temps = "";
|
|
||||||
}
|
|
||||||
else if(c == '}') {
|
|
||||||
compName.add(temps);
|
|
||||||
fin.add(temps);
|
|
||||||
temps = "";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
temps += c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
msgs.add(temps);
|
|
||||||
fin.add(temps);
|
|
||||||
/*
|
|
||||||
* Generate the final BaseComponent
|
|
||||||
*/
|
|
||||||
MessageBuilder mb = new MessageBuilder();
|
|
||||||
|
|
||||||
// Loops through the final array.
|
|
||||||
for(String s : fin) {
|
|
||||||
// If the message is a normal message.
|
|
||||||
if(msgs.contains(s)) {
|
|
||||||
mb.addString(s);
|
|
||||||
}
|
|
||||||
// If the message is a component
|
|
||||||
else if(compName.contains(s)) {
|
|
||||||
ConfigurationSection cs = null;
|
|
||||||
for(String st : UltraChat.plugin.getConfig().getConfigurationSection("JSON_Components").getKeys(false)) {
|
|
||||||
if(st.equals(s)) {
|
|
||||||
cs = UltraChat.plugin.getConfig().getConfigurationSection("JSON_Components." + st);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(cs == null) {
|
|
||||||
Bukkit.getLogger().warning("Error: Can not find JSON Component named: " + s);
|
|
||||||
}else {
|
|
||||||
JSONChatBuilder jsb = new JSONChatBuilder(cs.getString("Message"));
|
|
||||||
// If the component contains the click event.
|
|
||||||
if(cs.contains("Events.Click")) {
|
|
||||||
if(cs.contains("Events.Click.Open_URL"))
|
|
||||||
jsb.setClickOpenUrl(cs.getString("Events.Click.Open_URL"));
|
|
||||||
else if(cs.contains("Events.Click.Run_Command"))
|
|
||||||
jsb.setClickRunCommand(cs.getString("Events.Click.Run_Command"));
|
|
||||||
else if(cs.contains("Events.Click.Suggest_Command"))
|
|
||||||
jsb.setClickSuggestCommand(cs.getString("Events.Click.Suggest_Command"));
|
|
||||||
}
|
|
||||||
// If the component contains the hover event.
|
|
||||||
if(cs.contains("Events.Hover")) {
|
|
||||||
if(cs.contains("Events.Hover.Show_Text")) {
|
|
||||||
List<String> finals = new ArrayList<String>();
|
|
||||||
for(String st : cs.getStringList("Events.Hover.Show_Text")) {
|
|
||||||
finals.add(UltraChat.plugin.addonManager.replacePlaceholders(st, p));
|
|
||||||
}
|
|
||||||
jsb.setHoverShowText(finals);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
mb.addJSON(jsb);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build the message builder and return it
|
|
||||||
return mb.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.api.placeholders;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public interface PlaceholderAddon {
|
|
||||||
|
|
||||||
public String getName();
|
|
||||||
public String getString(UUID p);
|
|
||||||
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.chatcolor;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.UltraChat;
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class handles the chatcolor.yml file.
|
|
||||||
*/
|
|
||||||
public class ChatColorManager {
|
|
||||||
private Map<String, ChatColor> colorCodeMap;
|
|
||||||
|
|
||||||
public ChatColorManager(UltraChat plugin, ConfigurationSection section){
|
|
||||||
colorCodeMap = new HashMap<>();
|
|
||||||
for(String s : section.getKeys(false)){
|
|
||||||
String color = Objects.requireNonNull(section.getString(s));
|
|
||||||
if(color.equalsIgnoreCase("default"))
|
|
||||||
colorCodeMap.put(s, ChatColor.getByChar(s.replace("&", "").charAt(0)));
|
|
||||||
else{
|
|
||||||
try{
|
|
||||||
color = color.replace("{", "").replace("}", "");
|
|
||||||
colorCodeMap.put(s, ChatColor.of(color));
|
|
||||||
}catch(IllegalArgumentException ex){
|
|
||||||
plugin.getLogger().warning("Invalid chat color for " + s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, ChatColor> getMap(){
|
|
||||||
return colorCodeMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String translateMapColors(String message){
|
|
||||||
String finalMessage = message;
|
|
||||||
for(Map.Entry<String, ChatColor> entry : colorCodeMap.entrySet()){
|
|
||||||
finalMessage = finalMessage.replace(entry.getKey(), entry.getValue().toString());
|
|
||||||
}
|
|
||||||
return finalMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChatColor getChatColor(String s){
|
|
||||||
return colorCodeMap.get(s);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,103 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.chatcolor;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.UltraChat;
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class ChatColorUtil_Latest implements ChatColorUtils {
|
|
||||||
|
|
||||||
private UltraChat plugin;
|
|
||||||
public ChatColorUtil_Latest(UltraChat plugin){
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String translateChatColor(String message) {
|
|
||||||
String finalMessage = translateHexColor(message);
|
|
||||||
finalMessage = plugin.chatColorManager.translateMapColors(finalMessage);
|
|
||||||
return finalMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String translateChatColor(String message, Player p) {
|
|
||||||
String finalMessage = message;
|
|
||||||
if(p.hasPermission("ultrachat.chat.hex"))
|
|
||||||
finalMessage = translateHexColor(message);
|
|
||||||
if(p.hasPermission("ultrachat.chat.color"))
|
|
||||||
finalMessage = plugin.chatColorManager.translateMapColors(finalMessage);
|
|
||||||
return finalMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ChatColor translateChatCode(String code) {
|
|
||||||
if(code.startsWith("&")){
|
|
||||||
return plugin.chatColorManager.getChatColor(code);
|
|
||||||
}
|
|
||||||
String hexCode = code.replace("{", "").replace("}", "");
|
|
||||||
try{
|
|
||||||
return ChatColor.of(hexCode);
|
|
||||||
}catch(IllegalArgumentException ex){
|
|
||||||
return ChatColor.RED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isChatCode(String code) {
|
|
||||||
if(code.startsWith("&")){
|
|
||||||
return plugin.chatColorManager.getMap().containsKey(code);
|
|
||||||
}
|
|
||||||
String hexCode = code.replace("{", "").replace("}", "");
|
|
||||||
try{
|
|
||||||
ChatColor.of(hexCode);
|
|
||||||
}catch(IllegalArgumentException ex){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static String translateHexColor(String message){
|
|
||||||
if(!message.contains("{"))
|
|
||||||
return message;
|
|
||||||
StringBuilder finalMessage = new StringBuilder();
|
|
||||||
StringBuilder interior = new StringBuilder();
|
|
||||||
boolean readInterior = false;
|
|
||||||
for (int i = 0; i < message.length(); i++){
|
|
||||||
char c = message.charAt(i);
|
|
||||||
if(c == '{' && !readInterior){
|
|
||||||
readInterior = true;
|
|
||||||
}else if(!readInterior){
|
|
||||||
finalMessage.append(c);
|
|
||||||
} else if(c == '{'){
|
|
||||||
finalMessage.append('{');
|
|
||||||
finalMessage.append(interior);
|
|
||||||
interior = new StringBuilder();
|
|
||||||
}else if(c == '}' && interior.toString().contains("#")){
|
|
||||||
readInterior = false;
|
|
||||||
try {
|
|
||||||
finalMessage.append(ChatColor.of(interior.toString()));
|
|
||||||
}catch(IllegalArgumentException ex){
|
|
||||||
finalMessage.append("{");
|
|
||||||
finalMessage.append(interior);
|
|
||||||
finalMessage.append("}");
|
|
||||||
}finally{
|
|
||||||
interior = new StringBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
}else if(c == '}'){
|
|
||||||
readInterior = false;
|
|
||||||
finalMessage.append("{");
|
|
||||||
finalMessage.append(interior);
|
|
||||||
finalMessage.append("}");
|
|
||||||
interior = new StringBuilder();
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
interior.append(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(interior.toString().length() > 0){
|
|
||||||
finalMessage.append('{');
|
|
||||||
finalMessage.append(interior);
|
|
||||||
}
|
|
||||||
return finalMessage.toString();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.chatcolor;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class ChatColorUtil_Old implements ChatColorUtils {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String translateChatColor(String message) {
|
|
||||||
return ChatColor.translateAlternateColorCodes('&', message);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String translateChatColor(String message, Player p) {
|
|
||||||
if(p.hasPermission("ultrachat.chat.color"))
|
|
||||||
return ChatColor.translateAlternateColorCodes('&', message);
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ChatColor translateChatCode(String code) {
|
|
||||||
if(code.startsWith("&")){
|
|
||||||
return ChatColor.getByChar(code.replace("&", "").charAt(0));
|
|
||||||
}
|
|
||||||
return ChatColor.RED;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isChatCode(String code) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.chatcolor;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public interface ChatColorUtils {
|
|
||||||
String translateChatColor(String message);
|
|
||||||
String translateChatColor(String message, Player p);
|
|
||||||
ChatColor translateChatCode(String code);
|
|
||||||
boolean isChatCode(String code);
|
|
||||||
}
|
|
@ -1,87 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.commands;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.UltraChat;
|
|
||||||
import me.ryandw11.ultrachat.api.ChatType;
|
|
||||||
import me.ryandw11.ultrachat.api.Lang;
|
|
||||||
import me.ryandw11.ultrachat.api.UltraChatAPI;
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
|
||||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
|
||||||
import net.md_5.bungee.api.chat.HoverEvent;
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Ryandw11
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ChannelCmd implements CommandExecutor {
|
|
||||||
private UltraChat plugin;
|
|
||||||
public ChannelCmd(){
|
|
||||||
plugin = UltraChat.plugin;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String s, String[] args) {
|
|
||||||
|
|
||||||
|
|
||||||
Player p = (Player) sender;
|
|
||||||
if(!(p instanceof Player )) return true;
|
|
||||||
if(!p.hasPermission("ultrachat.channel")){
|
|
||||||
p.sendMessage(ChatColor.translateAlternateColorCodes('&', Lang.NO_PERM.toString()));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
UltraChatAPI uapi = new UltraChatAPI();
|
|
||||||
if(uapi.getChatType() != ChatType.CHANNEL){
|
|
||||||
p.sendMessage(ChatColor.translateAlternateColorCodes('&', Lang.ERROR_CHANNEL_ENABLED.toString()));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if(args.length != 1 && args.length != 0){
|
|
||||||
p.sendMessage(ChatColor.translateAlternateColorCodes('&', Lang.ERROR_CHANNEL_USAGE.toString()));
|
|
||||||
}
|
|
||||||
else if(args.length == 0){
|
|
||||||
p.sendMessage(ChatColor.BLUE + "-------------Chat Channels--------------");
|
|
||||||
p.sendMessage(ChatColor.GREEN + "/channel {channel} - Change you channel. [Case Sensitive!]");
|
|
||||||
p.sendMessage(ChatColor.GREEN + "/channel list - List the channels.");
|
|
||||||
}else if(args.length == 1 && args[0].equalsIgnoreCase("list")){
|
|
||||||
if(!p.hasPermission("ultrachat.channel.list")){
|
|
||||||
p.sendMessage(ChatColor.translateAlternateColorCodes('&', Lang.NO_PERM.toString()));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
ArrayList<String> chnls = (ArrayList<String>) plugin.getConfig().get("Channel_List");
|
|
||||||
p.sendMessage(ChatColor.BLUE + "-------------Channels List--------------");
|
|
||||||
for(String st : chnls){
|
|
||||||
ComponentBuilder cnl = new ComponentBuilder("- " + st);
|
|
||||||
cnl.event(new HoverEvent( HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(ChatColor.translateAlternateColorCodes('&', Lang.CHANNEL_JSON_HOVER.toString())).create() ) );
|
|
||||||
cnl.event(new ClickEvent( ClickEvent.Action.RUN_COMMAND, "/channel " + st));
|
|
||||||
cnl.color(ChatColor.GREEN);
|
|
||||||
p.spigot().sendMessage(cnl.create());
|
|
||||||
}
|
|
||||||
p.sendMessage(ChatColor.BLUE + "--------------------------------------");
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
if(!plugin.channel.contains(args[0])){
|
|
||||||
p.sendMessage(ChatColor.RED + "That channel does not exsist!");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if(plugin.data.getString(p.getUniqueId() + ".channel").equalsIgnoreCase(args[0])){
|
|
||||||
p.sendMessage(ChatColor.RED + "Error: you are currently in the channel");
|
|
||||||
}
|
|
||||||
else if(p.hasPermission(plugin.channel.getString(args[0] + ".permission")) || plugin.channel.getString(args[0] + ".permission").equalsIgnoreCase("none")){
|
|
||||||
plugin.data.set(p.getUniqueId() + ".channel", args[0]);
|
|
||||||
plugin.saveFile();
|
|
||||||
p.sendMessage(ChatColor.BLUE + "You are now in the channel " + args[0] + "!");
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
p.sendMessage(ChatColor.RED + "You do not have permission to join that channel.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.commands;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.command.TabCompleter;
|
|
||||||
|
|
||||||
public class CommandTabCompleter implements TabCompleter{
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String s, String[] args) {
|
|
||||||
if(cmd.getName().equalsIgnoreCase("chat")){
|
|
||||||
ArrayList<String> completions = new ArrayList<>();
|
|
||||||
if(args.length == 1){
|
|
||||||
completions = new ArrayList<>( Arrays.asList("help", "stop", "broadcast", "clear", "sjoin", "leave", "join", "color", "raw", "reload", "hooks"));
|
|
||||||
completions = getAppliableTabCompleters(args.length == 1 ? args[0] : "", completions);
|
|
||||||
}else{
|
|
||||||
if(args[0].equalsIgnoreCase("help")){
|
|
||||||
completions = new ArrayList<>(Arrays.asList("2"));
|
|
||||||
completions = getAppliableTabCompleters(args.length == 2 ? args[1] : "", completions);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Collections.sort(completions);
|
|
||||||
return completions;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<String> getAppliableTabCompleters(String arg, ArrayList<String> completions) {
|
|
||||||
if (arg == null || arg.equalsIgnoreCase("")) {
|
|
||||||
return completions;
|
|
||||||
}
|
|
||||||
ArrayList<String> valid = new ArrayList<>();
|
|
||||||
for (String posib : completions) {
|
|
||||||
if (posib.startsWith(arg)) {
|
|
||||||
valid.add(posib);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,74 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.commands;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.UltraChat;
|
|
||||||
import me.ryandw11.ultrachat.api.ChatType;
|
|
||||||
import me.ryandw11.ultrachat.api.Lang;
|
|
||||||
import me.ryandw11.ultrachat.api.UltraChatAPI;
|
|
||||||
import me.ryandw11.ultrachat.api.events.UltraChatEvent;
|
|
||||||
import me.ryandw11.ultrachat.api.events.properties.RangeProperties;
|
|
||||||
import me.ryandw11.ultrachat.api.events.properties.RangeType;
|
|
||||||
import me.ryandw11.ultrachat.api.managers.JComponentManager;
|
|
||||||
import me.ryandw11.ultrachat.formatting.PlayerFormatting;
|
|
||||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
|
|
||||||
public class Global implements CommandExecutor {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String s, String[] args) {
|
|
||||||
if (!(sender instanceof Player)) {
|
|
||||||
sender.sendMessage(ChatColor.RED + "This command is for players only!");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Player p = (Player) sender;
|
|
||||||
if (!p.hasPermission("ultrachat.global")) {
|
|
||||||
p.sendMessage(Lang.NO_PERM.toString());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
PlayerFormatting pf = new PlayerFormatting(p);
|
|
||||||
|
|
||||||
RangeProperties rp = new RangeProperties(true, RangeType.GLOBAL);
|
|
||||||
UltraChatEvent uce = new UltraChatEvent(p, this.getMessage(args, p),
|
|
||||||
new HashSet<>(Bukkit.getOnlinePlayers()), ChatType.RANGE, rp);
|
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(UltraChat.plugin, () ->{
|
|
||||||
Bukkit.getServer().getPluginManager().callEvent(uce);
|
|
||||||
|
|
||||||
if (uce.isCancelled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String form = pf.getGlobal().replace("%player%", p.getDisplayName())
|
|
||||||
.replace("%prefix%", pf.getPrefix())
|
|
||||||
.replace("%suffix%", pf.getSuffix())
|
|
||||||
+ pf.getColor();
|
|
||||||
|
|
||||||
ComponentBuilder cb = new ComponentBuilder("");
|
|
||||||
cb.append(JComponentManager.formatComponents(form, p));
|
|
||||||
cb.append(new TextComponent(TextComponent.fromLegacyText(UltraChat.plugin.chatColorUtil.translateChatColor(uce.getMessage(), p), pf.getColor())), ComponentBuilder.FormatRetention.NONE);
|
|
||||||
|
|
||||||
for (Player pl : uce.getRecipients()) {
|
|
||||||
pl.spigot().sendMessage(cb.create());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getMessage(String[] args, Player p) {
|
|
||||||
StringBuilder end = new StringBuilder();
|
|
||||||
for (String s : args) {
|
|
||||||
end.append(s).append(" ");
|
|
||||||
}
|
|
||||||
return end.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,231 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.commands;
|
|
||||||
|
|
||||||
import com.sun.istack.internal.NotNull;
|
|
||||||
import me.ryandw11.ultrachat.UltraChat;
|
|
||||||
import me.ryandw11.ultrachat.api.Lang;
|
|
||||||
import me.ryandw11.ultrachat.api.UltraChatAPI;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Ryandw11
|
|
||||||
*/
|
|
||||||
public class NewChatCommand implements CommandExecutor {
|
|
||||||
|
|
||||||
|
|
||||||
private UltraChat plugin;
|
|
||||||
|
|
||||||
public NewChatCommand(UltraChat plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String s, @NotNull String[] args) {
|
|
||||||
// This is not a switch statement since I want to check the argument length along with the sub command name.
|
|
||||||
if (args.length == 0) {
|
|
||||||
sender.sendMessage(ChatColor.BLUE + "=============={" + ChatColor.GREEN + "Ultra Chat" + ChatColor.BLUE + "}==============");
|
|
||||||
sender.sendMessage(ChatColor.BLUE + "Plugin developed by:" + ChatColor.GREEN + " Ryandw11");
|
|
||||||
sender.sendMessage(ChatColor.BLUE + "Version: " + ChatColor.GREEN + String.format("%s", plugin.getDescription().getVersion()));
|
|
||||||
sender.sendMessage(ChatColor.BLUE + "Plugin wiki:" + ChatColor.GREEN + " https://github.com/ryandw11/UltraChat/wiki");
|
|
||||||
sender.sendMessage(ChatColor.BLUE + "Do " + ChatColor.GREEN + " /chat help " + ChatColor.BLUE + "for the list of commands!");
|
|
||||||
sender.sendMessage(ChatColor.BLUE + "=============={" + ChatColor.GREEN + "Ultra Chat" + ChatColor.BLUE + "}==============");
|
|
||||||
|
|
||||||
} else if (args.length == 1 && args[0].equalsIgnoreCase("stop")) {
|
|
||||||
if (sender.hasPermission("ultrachat.stopchat")) {
|
|
||||||
|
|
||||||
if (plugin.isChatStopped) {
|
|
||||||
plugin.isChatStopped = false;
|
|
||||||
sender.sendMessage(Lang.CHAT_UNSTOP_PERSONAL.toString());
|
|
||||||
Bukkit.getServer().broadcastMessage(Lang.CHAT_STOP_OFF.toString().replace("%p", sender instanceof Player ? ((Player) sender).getDisplayName() :
|
|
||||||
"CONSOLE"));
|
|
||||||
} else {
|
|
||||||
plugin.isChatStopped = true;
|
|
||||||
sender.sendMessage(Lang.CHAT_STOP_PERSONAL.toString());
|
|
||||||
Bukkit.getServer().broadcastMessage(Lang.CHAT_STOP_ON.toString().replace("%p", sender instanceof Player ? ((Player) sender).getDisplayName() :
|
|
||||||
"CONSOLE"));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(Lang.NO_PERM.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} else if (args.length > 1 && args[0].equalsIgnoreCase("broadcast")) {
|
|
||||||
if (sender.hasPermission("ultrachat.broadcast")) {
|
|
||||||
StringBuilder message = new StringBuilder();
|
|
||||||
for (int i = 1; i < args.length; i++) {
|
|
||||||
message.append(" ").append(args[i]);
|
|
||||||
}
|
|
||||||
Bukkit.getServer().broadcastMessage(Lang.BROADCAST_PREFIX.toString() + ChatColor.translateAlternateColorCodes('&', message.toString()));
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(Lang.NO_PERM.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (args.length == 1 && args[0].equalsIgnoreCase("broadcast")) {
|
|
||||||
if (sender.hasPermission("ultrachat.broadcast")) {
|
|
||||||
sender.sendMessage(ChatColor.RED + "Invalid Usage: /chat broadcast (broadcast)");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
sender.sendMessage(Lang.NO_PERM.toString());
|
|
||||||
} else if (args.length == 1 && args[0].equalsIgnoreCase("clear")) {
|
|
||||||
if (sender.hasPermission("ultrachat.clearchat")) {
|
|
||||||
for (int i = 0; i < 100; i++) {
|
|
||||||
for (Player pl : Bukkit.getOnlinePlayers()) {
|
|
||||||
pl.sendMessage(" ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Bukkit.getServer().broadcastMessage(Lang.CHAT_CLEAR.toString().replace("%p", sender.getName()));
|
|
||||||
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(Lang.NO_PERM.toString());
|
|
||||||
}
|
|
||||||
} else if (args.length == 1 && args[0].equalsIgnoreCase("sjoin")) {
|
|
||||||
if (!(sender instanceof Player)) {
|
|
||||||
sender.sendMessage(ChatColor.RED + "This command is for players only!");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Player p = (Player) sender;
|
|
||||||
if (sender.hasPermission("ultrachat.sjoin")) {
|
|
||||||
if (plugin.data.getBoolean(p.getUniqueId().toString() + ".sjoin")) {
|
|
||||||
sender.sendMessage(Lang.SJOIN_SHOWN.toString());
|
|
||||||
plugin.data.set(p.getUniqueId().toString() + ".sjoin", false);
|
|
||||||
plugin.saveFile();
|
|
||||||
} else {
|
|
||||||
plugin.data.set(p.getUniqueId().toString() + ".sjoin", true);
|
|
||||||
plugin.saveFile();
|
|
||||||
sender.sendMessage(Lang.SJOIN_HIDE.toString());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(Lang.NO_PERM.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (args.length == 2 && args[0].equalsIgnoreCase("sjoin")) {
|
|
||||||
if (sender.hasPermission("ultrachat.sjoin.others")) {
|
|
||||||
Player pl = Bukkit.getServer().getPlayer(args[1]);
|
|
||||||
if (pl == null) {
|
|
||||||
sender.sendMessage(ChatColor.RED + "Player can not be null!");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (plugin.data.getBoolean(pl.getUniqueId().toString() + ".sjoin")) {
|
|
||||||
sender.sendMessage(String.format(Lang.SJOIN_OTHER_SHOW.toString(), pl.getName()));
|
|
||||||
plugin.data.set(pl.getUniqueId().toString() + ".sjoin", false);
|
|
||||||
plugin.saveFile();
|
|
||||||
} else {
|
|
||||||
plugin.data.set(pl.getUniqueId().toString() + ".sjoin", true);
|
|
||||||
plugin.saveFile();
|
|
||||||
sender.sendMessage(String.format(Lang.SJOIN_OTHER_HIDE.toString(), pl.getName()));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(Lang.NO_PERM.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (args.length == 2 && args[0].equalsIgnoreCase("join")) {
|
|
||||||
if (sender.hasPermission("ultrachat.fakejoin")) {
|
|
||||||
Bukkit.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(plugin.getConfig().getString("Join_Message")).replace("%player%", args[1])));
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(Lang.NO_PERM.toString());
|
|
||||||
}
|
|
||||||
} else if (args.length == 2 && args[0].equalsIgnoreCase("leave")) {
|
|
||||||
if (sender.hasPermission("ultrachat.fakeleave")) {
|
|
||||||
Bukkit.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(plugin.getConfig().getString("Leave_Message")).replace("%player%", args[1])));
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(Lang.NO_PERM.toString());
|
|
||||||
}
|
|
||||||
} else if (args.length == 1 && args[0].equalsIgnoreCase("help")) {
|
|
||||||
if (!sender.hasPermission("ultrachat.help")) {
|
|
||||||
sender.sendMessage(Lang.NO_PERM.toString());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
sender.sendMessage(ChatColor.BLUE + "-------------------=[" + ChatColor.GREEN + "Ultra Chat" + ChatColor.BLUE + "]=-------------------");
|
|
||||||
sender.sendMessage(ChatColor.GREEN + "/chat help" + ChatColor.BLUE + " The help command.");
|
|
||||||
sender.sendMessage(ChatColor.GREEN + "/chat stop" + ChatColor.BLUE + " Stop the chat.");
|
|
||||||
sender.sendMessage(ChatColor.GREEN + "/chat broadcast (message)" + ChatColor.BLUE + " Send a message to every player.");
|
|
||||||
sender.sendMessage(ChatColor.GREEN + "/sc (message)" + ChatColor.BLUE + " Talk in staff chat.");
|
|
||||||
sender.sendMessage(ChatColor.GREEN + "/sctoggle" + ChatColor.BLUE + " Toggle staff chat.");
|
|
||||||
sender.sendMessage(ChatColor.GREEN + "/spy" + ChatColor.BLUE + " Enable or disable command spy.");
|
|
||||||
sender.sendMessage(ChatColor.GREEN + "/chat clear" + ChatColor.BLUE + " Clear the chat.");
|
|
||||||
sender.sendMessage(ChatColor.GREEN + "/chat sjoin" + ChatColor.BLUE + " Silently join and leave the server.");
|
|
||||||
sender.sendMessage(ChatColor.BLUE + "Do" + ChatColor.GREEN + " /chat help 2" + ChatColor.BLUE + " for more help pages!");
|
|
||||||
sender.sendMessage(ChatColor.BLUE + "Plugin made by: " + ChatColor.GREEN + "Ryandw11" + ChatColor.BLUE + "! Help Page: " + ChatColor.GREEN + "1/2" + ChatColor.BLUE + ".");
|
|
||||||
sender.sendMessage(ChatColor.BLUE + "---------------------------------------------------");
|
|
||||||
|
|
||||||
} else if (args.length == 2 && args[0].equalsIgnoreCase("help")) {
|
|
||||||
if (sender.hasPermission("ultrachat.help")) {
|
|
||||||
if (args[1].equals("2")) {
|
|
||||||
sender.sendMessage(ChatColor.BLUE + "-------------------=[" + ChatColor.GREEN + "Ultra Chat" + ChatColor.BLUE + "]=-------------------");
|
|
||||||
sender.sendMessage(ChatColor.GREEN + "/chat leave (player)" + ChatColor.BLUE + " Send a fake leave message.");
|
|
||||||
sender.sendMessage(ChatColor.GREEN + "/chat join (player) " + ChatColor.BLUE + " Send a fake join message.");
|
|
||||||
sender.sendMessage(ChatColor.GREEN + "/chat color" + ChatColor.BLUE + " Change your chat color.");
|
|
||||||
sender.sendMessage(ChatColor.GREEN + "/chat raw {Message}" + ChatColor.BLUE + " Send a message in the chat without a prefix.");
|
|
||||||
sender.sendMessage(ChatColor.GREEN + "/chat reload" + ChatColor.BLUE + " Reload the config file.");
|
|
||||||
sender.sendMessage(ChatColor.GREEN + "/chat hooks" + ChatColor.BLUE + " Get the current plugin hooks!");
|
|
||||||
sender.sendMessage(ChatColor.GREEN + "/channels" + ChatColor.BLUE + " The channel command.");
|
|
||||||
sender.sendMessage(ChatColor.BLUE + "Plugin made by: " + ChatColor.GREEN + "Ryandw11" + ChatColor.BLUE + "! Help Page: " + ChatColor.GREEN + "2/2" + ChatColor.BLUE + ".");
|
|
||||||
sender.sendMessage(ChatColor.BLUE + "---------------------------------------------------");
|
|
||||||
}
|
|
||||||
if (!(args[1].equals("1") || args[1].equals("2"))) {
|
|
||||||
sender.sendMessage(Lang.HELP_PAGE_ERROR.toString());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(plugin.getConfig().getString("No_Permission"))));
|
|
||||||
}
|
|
||||||
} else if (args.length > 1 && args[0].equalsIgnoreCase("raw")) {
|
|
||||||
if (sender.hasPermission("ultrachat.raw")) {
|
|
||||||
StringBuilder message = new StringBuilder();
|
|
||||||
for (int i = 1; i < args.length; i++) {
|
|
||||||
if (i == 1) {
|
|
||||||
message.append(args[i]);
|
|
||||||
} else {
|
|
||||||
message.append(" ").append(args[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Bukkit.getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', ChatColor.translateAlternateColorCodes('&', message.toString())));
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(Lang.NO_PERM.toString());
|
|
||||||
}
|
|
||||||
} else if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
|
|
||||||
if (sender.hasPermission("ultrachat.reload")) {
|
|
||||||
plugin.reloadConfig();
|
|
||||||
plugin.loadChannel();
|
|
||||||
sender.sendMessage(Lang.CONFIG_RELOAD.toString());
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(Lang.NO_PERM.toString());
|
|
||||||
}
|
|
||||||
} else if (args.length == 1 && args[0].equalsIgnoreCase("color")) {
|
|
||||||
if (!(sender instanceof Player)) {
|
|
||||||
sender.sendMessage(ChatColor.RED + "This command is for players only!");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (sender.hasPermission("ultrachat.color"))
|
|
||||||
plugin.getColorGUI().openGUI((Player) sender, 1);
|
|
||||||
else
|
|
||||||
sender.sendMessage(Lang.NO_PERM.toString());
|
|
||||||
} else if (args.length == 1 && args[0].equalsIgnoreCase("hooks")) {
|
|
||||||
if (sender.hasPermission("ultrachat.hooks")) {
|
|
||||||
UltraChatAPI uapi = new UltraChatAPI();
|
|
||||||
sender.sendMessage(ChatColor.BLUE + "Ultra Chat Hooks:");
|
|
||||||
if (uapi.getActiveHooks() == null) {
|
|
||||||
sender.sendMessage(ChatColor.GREEN + "No hooks are currently active!");
|
|
||||||
} else {
|
|
||||||
for (String st : uapi.getActiveHooks()) {
|
|
||||||
sender.sendMessage(ChatColor.GREEN + " - " + st);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(Lang.NO_PERM.toString());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(Lang.CHAT_CMD_NOT_VALID.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,78 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.commands;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.UltraChat;
|
|
||||||
import me.ryandw11.ultrachat.api.Lang;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Spy Command class.
|
|
||||||
* @author Ryandw11
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class SpyCommand implements CommandExecutor {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private UltraChat plugin;
|
|
||||||
public SpyCommand(){
|
|
||||||
plugin = UltraChat.plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String s, String[] args) {
|
|
||||||
if(!(sender instanceof Player )){
|
|
||||||
plugin.getLogger().info("This command is for players only!");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Player p = (Player) sender;
|
|
||||||
|
|
||||||
if(args.length == 0){
|
|
||||||
if (p.hasPermission("ultrachat.spy")) {
|
|
||||||
if(!(args.length == 0)){
|
|
||||||
p.sendMessage(ChatColor.RED + "Invailed subcommand! Ussage: /spy");
|
|
||||||
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
if(plugin.spyToggle.contains(p.getUniqueId())){
|
|
||||||
p.sendMessage(Lang.CMD_SPY_OFF.toString());
|
|
||||||
plugin.spyToggle.remove(p.getUniqueId());
|
|
||||||
plugin.data.set(p.getUniqueId().toString() + ".spy", false);
|
|
||||||
plugin.saveFile();
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
plugin.spyToggle.add(p.getUniqueId());
|
|
||||||
p.sendMessage(Lang.CMD_SPY_ON.toString());
|
|
||||||
plugin.data.set(p.getUniqueId().toString() + ".spy", true);
|
|
||||||
plugin.saveFile();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}//end of perm check
|
|
||||||
}
|
|
||||||
else if(args.length == 1){
|
|
||||||
if(p.hasPermission("ultrachat.spy.others")){
|
|
||||||
Player pl = (Player) Bukkit.getServer().getPlayer(args[0]);
|
|
||||||
if(plugin.spyToggle.contains(pl.getUniqueId())){
|
|
||||||
plugin.spyToggle.remove(pl.getUniqueId());
|
|
||||||
p.sendMessage(Lang.OTH_CMD_SPY_OFF.toString().replace("%p", args[0]));
|
|
||||||
plugin.data.set(pl.getUniqueId().toString() + ".spy", false);
|
|
||||||
plugin.saveFile();
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
plugin.spyToggle.add(pl.getUniqueId());
|
|
||||||
p.sendMessage(Lang.OTH_CMD_SPY_ON.toString().replace("%p", args[0]));
|
|
||||||
plugin.data.set(pl.getUniqueId().toString() + ".spy", true);
|
|
||||||
plugin.saveFile();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,74 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.commands;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.UltraChat;
|
|
||||||
import me.ryandw11.ultrachat.api.Lang;
|
|
||||||
import me.ryandw11.ultrachat.api.events.StaffChatEvent;
|
|
||||||
import me.ryandw11.ultrachat.api.managers.JComponentManager;
|
|
||||||
|
|
||||||
public class StaffChat implements CommandExecutor {
|
|
||||||
private UltraChat plugin;
|
|
||||||
public StaffChat(){
|
|
||||||
plugin = UltraChat.plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String s, String[] args) {
|
|
||||||
|
|
||||||
CommandSender p = sender;
|
|
||||||
if(p.hasPermission("ultrachat.staffchat")){
|
|
||||||
String message = "";
|
|
||||||
|
|
||||||
if(args.length > 0){
|
|
||||||
|
|
||||||
for (int i = 0; i < args.length; i++){
|
|
||||||
message = message + " " + args[i];
|
|
||||||
}
|
|
||||||
StaffChatEvent sce;
|
|
||||||
if (p instanceof Player)
|
|
||||||
sce = new StaffChatEvent((Player) p, message);
|
|
||||||
else
|
|
||||||
sce = new StaffChatEvent(null, message);
|
|
||||||
|
|
||||||
Bukkit.getServer().getPluginManager().callEvent(sce);
|
|
||||||
|
|
||||||
if(sce.isCancelled()) return true;
|
|
||||||
|
|
||||||
for(Player p1 : Bukkit.getOnlinePlayers()){
|
|
||||||
if(p1.hasPermission("ultrachat.staffchat")){
|
|
||||||
if(!plugin.staffToggle.contains(p1.getUniqueId())){
|
|
||||||
if (p instanceof Player)
|
|
||||||
p1.spigot().sendMessage(JComponentManager.formatComponents(Lang.STAFF_CHAT_FORMAT.toString().replace("%p", p.getName()).replace("%s", message), (Player) p));
|
|
||||||
else
|
|
||||||
p1.spigot().sendMessage(JComponentManager.formatComponents(Lang.STAFF_CHAT_FORMAT.toString().replace("%p", p.getName()).replace("%s", message)));
|
|
||||||
}// end of if
|
|
||||||
}
|
|
||||||
}//end of for
|
|
||||||
plugin.getLogger().info(Lang.STAFF_CHAT_FORMAT.toString().replace("%p", p.getName()).replace("%s", message));
|
|
||||||
}//end
|
|
||||||
else{
|
|
||||||
p.sendMessage(ChatColor.RED + "Not enough words. Ussage: /sc (message)");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}//end of perm check
|
|
||||||
else{
|
|
||||||
p.sendMessage(Lang.NO_PERM.toString());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.commands;
|
|
||||||
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.UltraChat;
|
|
||||||
import me.ryandw11.ultrachat.api.Lang;
|
|
||||||
/**
|
|
||||||
* StaffChat Toggle command.
|
|
||||||
* @author Ryandw11
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class StaffChatToggle implements CommandExecutor {
|
|
||||||
|
|
||||||
private UltraChat plugin;
|
|
||||||
public StaffChatToggle(){
|
|
||||||
plugin = UltraChat.plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String s, String[] args) {
|
|
||||||
if(!(sender instanceof Player)){
|
|
||||||
plugin.getLogger().info("That command is for players only!");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Player p = (Player) sender;
|
|
||||||
if(p.hasPermission("ultrachat.staffchat.toggle")){
|
|
||||||
|
|
||||||
if(plugin.staffToggle.contains(p.getUniqueId())){
|
|
||||||
plugin.staffToggle.remove(p.getUniqueId());
|
|
||||||
p.sendMessage(Lang.STAFF_CHAT_ON.toString());
|
|
||||||
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
plugin.staffToggle.add(p.getUniqueId());
|
|
||||||
p.sendMessage(Lang.STAFF_CHAT_OFF.toString());
|
|
||||||
}
|
|
||||||
}//end of perm check
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,72 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.commands;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
import com.sun.istack.internal.NotNull;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.UltraChat;
|
|
||||||
import me.ryandw11.ultrachat.api.ChatType;
|
|
||||||
import me.ryandw11.ultrachat.api.Lang;
|
|
||||||
import me.ryandw11.ultrachat.api.events.UltraChatEvent;
|
|
||||||
import me.ryandw11.ultrachat.api.events.properties.RangeProperties;
|
|
||||||
import me.ryandw11.ultrachat.api.events.properties.RangeType;
|
|
||||||
import me.ryandw11.ultrachat.api.managers.JComponentManager;
|
|
||||||
import me.ryandw11.ultrachat.formatting.PlayerFormatting;
|
|
||||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
|
|
||||||
public class World implements CommandExecutor {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String s, @NotNull String[] args) {
|
|
||||||
if (!(sender instanceof Player)) {
|
|
||||||
sender.sendMessage(ChatColor.RED + "This command is for players only!");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Player p = (Player) sender;
|
|
||||||
if (!p.hasPermission("ultrachat.world")) {
|
|
||||||
p.sendMessage(Lang.NO_PERM.toString());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
PlayerFormatting pf = new PlayerFormatting(p);
|
|
||||||
|
|
||||||
RangeProperties rp = new RangeProperties(true, RangeType.WORLD);
|
|
||||||
UltraChatEvent uce = new UltraChatEvent(p, this.getMessage(args, p),
|
|
||||||
new HashSet<>(p.getWorld().getPlayers()), ChatType.RANGE, rp);
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(UltraChat.plugin, () -> {
|
|
||||||
Bukkit.getServer().getPluginManager().callEvent(uce);
|
|
||||||
|
|
||||||
if (uce.isCancelled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String form = pf.getWorld().replace("%player%", p.getDisplayName())
|
|
||||||
.replace("%prefix%", pf.getPrefix())
|
|
||||||
.replace("%suffix%", pf.getSuffix()) + pf.getColor();
|
|
||||||
ComponentBuilder cb = new ComponentBuilder("");
|
|
||||||
cb.append(JComponentManager.formatComponents(form, p));
|
|
||||||
cb.append(new TextComponent(TextComponent.fromLegacyText(pf.getColor() + UltraChat.plugin.chatColorUtil.translateChatColor(uce.getMessage(), p), pf.getColor())), ComponentBuilder.FormatRetention.NONE);
|
|
||||||
|
|
||||||
for (Player pl : uce.getRecipients()) {
|
|
||||||
pl.spigot().sendMessage(cb.create());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getMessage(String[] args, Player p) {
|
|
||||||
StringBuilder end = new StringBuilder();
|
|
||||||
for (String s : args) {
|
|
||||||
end.append(s).append(" ");
|
|
||||||
}
|
|
||||||
return end.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,89 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.formatting;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.util.ChatUtil;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.UltraChat;
|
|
||||||
import me.ryandw11.ultrachat.api.ChatType;
|
|
||||||
import me.ryandw11.ultrachat.api.events.UltraChatEvent;
|
|
||||||
import me.ryandw11.ultrachat.api.events.properties.ChannelProperties;
|
|
||||||
import me.ryandw11.ultrachat.api.managers.JComponentManager;
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles channels with components enabled.
|
|
||||||
* @author Ryandw11
|
|
||||||
* @since 2.5
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ChannelJSON implements Listener {
|
|
||||||
|
|
||||||
private UltraChat plugin;
|
|
||||||
public ChannelJSON() {
|
|
||||||
this.plugin = UltraChat.plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
|
||||||
public void onChat(AsyncPlayerChatEvent e){
|
|
||||||
Player p = e.getPlayer();
|
|
||||||
PlayerFormatting pf = new PlayerFormatting(p);
|
|
||||||
String channel = plugin.data.getString(p.getUniqueId() + ".channel");
|
|
||||||
|
|
||||||
ChannelProperties cp = new ChannelProperties(true, channel);
|
|
||||||
|
|
||||||
if(!plugin.channel.getBoolean(channel + ".always_appear")){
|
|
||||||
UltraChatEvent uce = new UltraChatEvent(p, e.getMessage(), new HashSet<>(e.getRecipients()), ChatType.CHANNEL, cp);
|
|
||||||
Bukkit.getServer().getPluginManager().callEvent(uce);
|
|
||||||
// Remove recipients from main events to prevent double messages.
|
|
||||||
e.getRecipients().clear();
|
|
||||||
if(uce.isCancelled()) return;
|
|
||||||
for(Player pl : uce.getRecipients()){
|
|
||||||
if(plugin.data.getString(pl.getUniqueId() + ".channel").equals(channel)){
|
|
||||||
if(pl.hasPermission(Objects.requireNonNull(plugin.channel.getString(channel + ".permission"))) || Objects.requireNonNull(plugin.channel.getString(channel + ".permission")).equalsIgnoreCase("none")){
|
|
||||||
String format = ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(plugin.channel.getString(channel + ".prefix")))
|
|
||||||
+ ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(plugin.channel.getString(channel + ".format")))
|
|
||||||
.replace("%prefix%", pf.getPrefix())
|
|
||||||
.replace("%suffix%", pf.getSuffix())
|
|
||||||
.replace("%player%", p.getDisplayName())
|
|
||||||
+ pf.getColor();
|
|
||||||
|
|
||||||
ComponentBuilder cb = new ComponentBuilder("");
|
|
||||||
cb.append(JComponentManager.formatComponents(format, p));
|
|
||||||
cb.append(new TextComponent(TextComponent.fromLegacyText(plugin.chatColorUtil.translateChatColor(uce.getMessage(), p), pf.getColor())), ComponentBuilder.FormatRetention.NONE);
|
|
||||||
pl.spigot().sendMessage(cb.create());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
UltraChatEvent uce = new UltraChatEvent(p, e.getMessage(), new HashSet<>(e.getRecipients()), ChatType.CHANNEL, cp);
|
|
||||||
Bukkit.getServer().getPluginManager().callEvent(uce);
|
|
||||||
e.getRecipients().clear();
|
|
||||||
if(!uce.isCancelled())
|
|
||||||
for(Player pl : uce.getRecipients()){
|
|
||||||
String formats = ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(plugin.channel.getString(channel + ".prefix")))
|
|
||||||
+ ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(plugin.channel.getString(channel + ".format")))
|
|
||||||
.replace("%prefix%", pf.getPrefix())
|
|
||||||
.replace("%suffix%", pf.getSuffix())
|
|
||||||
.replace("%player%", p.getDisplayName())
|
|
||||||
+ pf.getColor();
|
|
||||||
|
|
||||||
ComponentBuilder cb = new ComponentBuilder("");
|
|
||||||
cb.append(JComponentManager.formatComponents(formats, p));
|
|
||||||
cb.append(new TextComponent(TextComponent.fromLegacyText(plugin.chatColorUtil.translateChatColor(uce.getMessage(), p), pf.getColor())), ComponentBuilder.FormatRetention.NONE);
|
|
||||||
pl.spigot().sendMessage(cb.create());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,102 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.formatting;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.UltraChat;
|
|
||||||
import me.ryandw11.ultrachat.api.ChatType;
|
|
||||||
import me.ryandw11.ultrachat.api.events.UltraChatEvent;
|
|
||||||
import me.ryandw11.ultrachat.api.events.properties.NormalProperties;
|
|
||||||
import me.ryandw11.ultrachat.api.managers.JComponentManager;
|
|
||||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles the Normal Chat when in JSON mode.
|
|
||||||
* @author Ryandw11
|
|
||||||
* @since 2.5
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class NormalJSON implements Listener {
|
|
||||||
|
|
||||||
private UltraChat plugin;
|
|
||||||
|
|
||||||
public NormalJSON() {
|
|
||||||
this.plugin = UltraChat.plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
|
||||||
public void onChat(AsyncPlayerChatEvent e) {
|
|
||||||
Player p = e.getPlayer();
|
|
||||||
PlayerFormatting pf = new PlayerFormatting(p);
|
|
||||||
|
|
||||||
// Call the UltraChatEvent (This is an optional Event).
|
|
||||||
NormalProperties np = new NormalProperties(true);
|
|
||||||
UltraChatEvent event = new UltraChatEvent(p, e.getMessage(), new HashSet<>(e.getRecipients()), ChatType.NORMAL, np);
|
|
||||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Remove all players from the normal event.
|
|
||||||
e.getRecipients().clear();
|
|
||||||
|
|
||||||
if (p.isOp()) {
|
|
||||||
String formats = pf.getOpFormat()
|
|
||||||
.replace("%prefix%", pf.getPrefix())
|
|
||||||
.replace("%suffix%", pf.getSuffix())
|
|
||||||
.replace("%player%", p.getDisplayName()) + pf.getColor();
|
|
||||||
|
|
||||||
for (Player pl : event.getRecipients()) {
|
|
||||||
ComponentBuilder cb = new ComponentBuilder("");
|
|
||||||
cb.append(JComponentManager.formatComponents(formats, p));
|
|
||||||
cb.append(new TextComponent(TextComponent.fromLegacyText(pf.getColor() + plugin.chatColorUtil.translateChatColor(event.getMessage()), pf.getColor())), ComponentBuilder.FormatRetention.NONE);
|
|
||||||
pl.spigot().sendMessage(cb.create());
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// If the player is not op
|
|
||||||
for (String key : Objects.requireNonNull(plugin.getConfig().getConfigurationSection("Custom_Chat.permission_format")).getKeys(false)) {
|
|
||||||
String permission = plugin.getConfig().getString("Custom_Chat.permission_format." + key + ".permission");
|
|
||||||
assert permission != null;
|
|
||||||
if (p.hasPermission(permission)) {
|
|
||||||
String formats = pf.getCustomFormat(key)
|
|
||||||
.replace("%prefix%", pf.getPrefix())
|
|
||||||
.replace("%suffix%", pf.getSuffix())
|
|
||||||
.replace("%player%", p.getDisplayName())
|
|
||||||
+ pf.getColor();
|
|
||||||
|
|
||||||
for (Player pl : event.getRecipients()) {
|
|
||||||
ComponentBuilder cb = new ComponentBuilder("");
|
|
||||||
cb.append(JComponentManager.formatComponents(formats, p));
|
|
||||||
cb.append(new TextComponent(TextComponent.fromLegacyText(pf.getColor() + plugin.chatColorUtil.translateChatColor(event.getMessage(), p), pf.getColor())), ComponentBuilder.FormatRetention.NONE);
|
|
||||||
pl.spigot().sendMessage(cb.create());
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Normal player check
|
|
||||||
*/
|
|
||||||
String formats = pf.getDefaultFormat()
|
|
||||||
.replace("%prefix%", pf.getPrefix())
|
|
||||||
.replace("%suffix%", pf.getSuffix())
|
|
||||||
.replace("%player%", p.getDisplayName())
|
|
||||||
+ pf.getColor();
|
|
||||||
for (Player pl : event.getRecipients()) {
|
|
||||||
ComponentBuilder cb = new ComponentBuilder("");
|
|
||||||
cb.append(JComponentManager.formatComponents(formats, p));
|
|
||||||
cb.append(new TextComponent(TextComponent.fromLegacyText(pf.getColor() + plugin.chatColorUtil.translateChatColor(event.getMessage(), p), pf.getColor())), ComponentBuilder.FormatRetention.NONE);
|
|
||||||
pl.spigot().sendMessage(cb.create());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,79 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.formatting;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.util.ChatUtil;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.UltraChat;
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class for formatting player chat easily.
|
|
||||||
* @author Ryandw11
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class PlayerFormatting {
|
|
||||||
private UltraChat plugin;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the formatting for a player.
|
|
||||||
* @param p
|
|
||||||
*/
|
|
||||||
public PlayerFormatting(Player p){
|
|
||||||
plugin = UltraChat.plugin;
|
|
||||||
|
|
||||||
color = plugin.data.getString(p.getUniqueId() + ".color");
|
|
||||||
prefix = ChatUtil.translateColorCodes( plugin.chat.getPlayerPrefix(p));
|
|
||||||
suffix = ChatUtil.translateColorCodes( plugin.chat.getPlayerSuffix(p));
|
|
||||||
formatOp = plugin.papi.translatePlaceholders(ChatUtil.translateColorCodes(Objects.requireNonNull(plugin.getConfig().getString("Custom_Chat.Op_Chat"))), p);
|
|
||||||
defaults = plugin.papi.translatePlaceholders(ChatUtil.translateColorCodes( Objects.requireNonNull(plugin.getConfig().getString("Custom_Chat.Default_Chat"))), p);
|
|
||||||
global = plugin.papi.translatePlaceholders(ChatUtil.translateColorCodes( Objects.requireNonNull(plugin.getConfig().getString("Global.format"))), p);
|
|
||||||
world = plugin.papi.translatePlaceholders(ChatUtil.translateColorCodes( Objects.requireNonNull(plugin.getConfig().getString("World.format"))), p);
|
|
||||||
local = plugin.papi.translatePlaceholders(ChatUtil.translateColorCodes( Objects.requireNonNull(plugin.getConfig().getString("Local.format"))), p);
|
|
||||||
this.p = p;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Player p;
|
|
||||||
private String prefix;
|
|
||||||
private String suffix;
|
|
||||||
public String color;
|
|
||||||
private String formatOp;
|
|
||||||
private String defaults;
|
|
||||||
private String global;
|
|
||||||
private String world;
|
|
||||||
private String local;
|
|
||||||
|
|
||||||
public String getGlobal(){
|
|
||||||
return global;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getWorld(){
|
|
||||||
return world;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLocal(){
|
|
||||||
return local;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPrefix(){
|
|
||||||
return prefix;
|
|
||||||
}
|
|
||||||
public String getSuffix(){
|
|
||||||
return suffix;
|
|
||||||
}
|
|
||||||
public ChatColor getColor(){
|
|
||||||
return ChatUtil.translateColorCode(color);
|
|
||||||
}
|
|
||||||
public String getOpFormat(){
|
|
||||||
return formatOp;
|
|
||||||
}
|
|
||||||
public String getDefaultFormat(){
|
|
||||||
return defaults;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCustomFormat(String key) {
|
|
||||||
return plugin.papi.translatePlaceholders(ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(plugin.getConfig().getString("Custom_Chat.permission_format." + key + ".format"))), p);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,79 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.formatting;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.util.ChatUtil;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.UltraChat;
|
|
||||||
import me.ryandw11.ultrachat.api.ChatType;
|
|
||||||
import me.ryandw11.ultrachat.api.events.UltraChatEvent;
|
|
||||||
import me.ryandw11.ultrachat.api.events.properties.RangeProperties;
|
|
||||||
import me.ryandw11.ultrachat.api.events.properties.RangeType;
|
|
||||||
import me.ryandw11.ultrachat.api.managers.JComponentManager;
|
|
||||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
|
||||||
|
|
||||||
public class RangeJSON implements Listener {
|
|
||||||
|
|
||||||
private UltraChat plugin;
|
|
||||||
|
|
||||||
public RangeJSON() {
|
|
||||||
this.plugin = UltraChat.plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
|
||||||
public void onChat(AsyncPlayerChatEvent e) {
|
|
||||||
Player p = e.getPlayer();
|
|
||||||
PlayerFormatting pf = new PlayerFormatting(p);
|
|
||||||
e.getRecipients().removeAll(Bukkit.getOnlinePlayers());
|
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
|
||||||
e.getRecipients().addAll(getNearbyPlayers(p));
|
|
||||||
e.getRecipients().add(p);
|
|
||||||
|
|
||||||
RangeProperties rp = new RangeProperties(true, RangeType.LOCAL);
|
|
||||||
|
|
||||||
UltraChatEvent uce = new UltraChatEvent(p, e.getMessage(), new HashSet<>(e.getRecipients()), ChatType.RANGE, rp);
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, ()->{
|
|
||||||
Bukkit.getServer().getPluginManager().callEvent(uce);
|
|
||||||
e.getRecipients().clear();
|
|
||||||
if (!uce.isCancelled()) {
|
|
||||||
for (Player pl : uce.getRecipients()) {
|
|
||||||
|
|
||||||
String formats = pf.getLocal()
|
|
||||||
.replace("%player%", p.getDisplayName())
|
|
||||||
.replace("%prefix%", pf.getPrefix())
|
|
||||||
.replace("%suffix%", pf.getSuffix())
|
|
||||||
+ pf.getColor();
|
|
||||||
|
|
||||||
ComponentBuilder cb = new ComponentBuilder("");
|
|
||||||
cb.append(JComponentManager.formatComponents(formats, p));
|
|
||||||
cb.append(new TextComponent(TextComponent.fromLegacyText(plugin.chatColorUtil.translateChatColor(uce.getMessage(), p), pf.getColor())), ComponentBuilder.FormatRetention.NONE);
|
|
||||||
pl.spigot().sendMessage(cb.create());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private ArrayList<Player> getNearbyPlayers(Player pl) {
|
|
||||||
ArrayList<Player> nearby = new ArrayList<Player>();
|
|
||||||
double range = plugin.getConfig().getDouble("Local.range");
|
|
||||||
for (Entity e : pl.getNearbyEntities(range, range, range)) {
|
|
||||||
if (e instanceof Player) {
|
|
||||||
nearby.add((Player) e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nearby;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,130 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.formatting;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.util.ChatUtil;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.UltraChat;
|
|
||||||
import me.ryandw11.ultrachat.api.ChatType;
|
|
||||||
import me.ryandw11.ultrachat.api.UltraChatAPI;
|
|
||||||
import me.ryandw11.ultrachat.api.channels.ChatChannel;
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Ryandw11
|
|
||||||
* @since 2.4
|
|
||||||
*/
|
|
||||||
public class UUIDFormating {
|
|
||||||
|
|
||||||
private UltraChat plugin;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the formatting for an offline player.
|
|
||||||
* @param ud The UUID for the player.
|
|
||||||
* @param world The world the plugin grabs the prefixes for.
|
|
||||||
*/
|
|
||||||
public UUIDFormating(UUID ud, String world){
|
|
||||||
plugin = UltraChat.plugin;
|
|
||||||
|
|
||||||
OfflinePlayer op = Bukkit.getOfflinePlayer(ud);
|
|
||||||
|
|
||||||
color = Objects.requireNonNull(plugin.data.getString(ud + ".color"));
|
|
||||||
try {
|
|
||||||
prefix = ChatUtil.translateColorCodes( plugin.chat.getPlayerPrefix(world, op));
|
|
||||||
suffix = ChatUtil.translateColorCodes( plugin.chat.getPlayerSuffix(world, op));
|
|
||||||
}
|
|
||||||
catch(NullPointerException ex) {
|
|
||||||
prefix = plugin.chat.getPlayerPrefix(world, op);
|
|
||||||
suffix = plugin.chat.getPlayerSuffix(world, op);
|
|
||||||
}
|
|
||||||
formatOp = ChatUtil.translateColorCodes( Objects.requireNonNull(plugin.getConfig().getString("Custom_Chat.Op_Chat")));
|
|
||||||
defaults = ChatUtil.translateColorCodes( Objects.requireNonNull(plugin.getConfig().getString("Custom_Chat.Default_Chat")));
|
|
||||||
global = ChatUtil.translateColorCodes( Objects.requireNonNull(plugin.getConfig().getString("Global.format")));
|
|
||||||
this.world = ChatUtil.translateColorCodes( Objects.requireNonNull(plugin.getConfig().getString("World.format")));
|
|
||||||
local = ChatUtil.translateColorCodes(Objects.requireNonNull(plugin.getConfig().getString("Local.format")));
|
|
||||||
this.op = op;
|
|
||||||
worldName = world;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String prefix;
|
|
||||||
private String suffix;
|
|
||||||
public String color;
|
|
||||||
private String formatOp;
|
|
||||||
private String defaults;
|
|
||||||
private String global;
|
|
||||||
private String world;
|
|
||||||
private String local;
|
|
||||||
private OfflinePlayer op;
|
|
||||||
private String worldName;
|
|
||||||
|
|
||||||
public String getGlobal(){
|
|
||||||
return global;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getWorld(){
|
|
||||||
return world;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLocal(){
|
|
||||||
return local;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPrefix(){
|
|
||||||
return prefix;
|
|
||||||
}
|
|
||||||
public String getSuffix(){
|
|
||||||
return suffix;
|
|
||||||
}
|
|
||||||
public ChatColor getColor(){
|
|
||||||
return ChatUtil.translateColorCode(color);
|
|
||||||
}
|
|
||||||
public String getOpFormat(){
|
|
||||||
return formatOp;
|
|
||||||
}
|
|
||||||
public String getDefaultFormat(){
|
|
||||||
return defaults;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCustomFormat(String key) {
|
|
||||||
return plugin.getConfig().getString("Custom_Chat.permission_format." + key + ".format");
|
|
||||||
}
|
|
||||||
|
|
||||||
public OfflinePlayer getOfflinePlayer() {
|
|
||||||
return op;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the active format for a player.
|
|
||||||
* @return The active format
|
|
||||||
* @since 2.4
|
|
||||||
*/
|
|
||||||
public String getActiveFormat() {
|
|
||||||
UltraChatAPI uapi = new UltraChatAPI();
|
|
||||||
if(uapi.getChatType() == ChatType.NORMAL) {
|
|
||||||
if(op.isOp()) return this.getOpFormat();
|
|
||||||
|
|
||||||
for (String key : Objects.requireNonNull(plugin.getConfig().getConfigurationSection("Custom_Chat.permission_format")).getKeys(false)) {
|
|
||||||
String permission = plugin.getConfig().getString("Custom_Chat.permission_format." + key + ".permission");
|
|
||||||
assert permission != null;
|
|
||||||
if (plugin.perms.playerHas(worldName, op, plugin.getConfig().getString(permission))) {
|
|
||||||
return this.getCustomFormat(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this.getDefaultFormat();
|
|
||||||
}
|
|
||||||
else if(uapi.getChatType() == ChatType.CHANNEL) {
|
|
||||||
ChatChannel cc = uapi.getPlayerCurrentChannel(op.getUniqueId());
|
|
||||||
return cc.getFormat();
|
|
||||||
}
|
|
||||||
else if(uapi.getChatType() == ChatType.RANGE) {
|
|
||||||
return plugin.getConfig().getString("Local.format");
|
|
||||||
}
|
|
||||||
|
|
||||||
return "ERROR: COULD NOT GET ACTIVE TYPE";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.gui;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
/**
|
|
||||||
* Provides compatibility with older versions.
|
|
||||||
* @author Ryandw11
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface ColorGUI {
|
|
||||||
void openGUI(Player p, int page);
|
|
||||||
}
|
|
@ -1,372 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.gui;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.UltraChat;
|
|
||||||
import me.ryandw11.ultrachat.api.Lang;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
||||||
import org.bukkit.event.inventory.InventoryType;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ColorGUI class.
|
|
||||||
* Updated for 1.14-1.15
|
|
||||||
* @author Ryandw11
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ColorGUI_1_15_R1 implements CommandExecutor, Listener, ColorGUI{
|
|
||||||
|
|
||||||
private UltraChat plugin;
|
|
||||||
public ColorGUI_1_15_R1(){
|
|
||||||
plugin = UltraChat.plugin;
|
|
||||||
}
|
|
||||||
public void openGUI(Player p, int page){
|
|
||||||
Inventory i = Bukkit.createInventory(null, InventoryType.CHEST, Lang.COLOR_GUI.toString());
|
|
||||||
|
|
||||||
ItemStack darkblueitem = new ItemStack(Material.BLUE_WOOL);
|
|
||||||
ItemMeta darkbluemeta = darkblueitem.getItemMeta();
|
|
||||||
|
|
||||||
ItemStack greenitem = new ItemStack(Material.GREEN_WOOL);
|
|
||||||
ItemMeta greenmeta = greenitem.getItemMeta();
|
|
||||||
|
|
||||||
ItemStack lightblueitem = new ItemStack(Material.CYAN_WOOL);
|
|
||||||
ItemMeta lightbluemeta = lightblueitem.getItemMeta();
|
|
||||||
|
|
||||||
ItemStack reditem = new ItemStack(Material.RED_WOOL);
|
|
||||||
ItemMeta redmeta = reditem.getItemMeta();
|
|
||||||
|
|
||||||
ItemStack purpleitem = new ItemStack(Material.PURPLE_WOOL);
|
|
||||||
ItemMeta purplemeta = purpleitem.getItemMeta();
|
|
||||||
|
|
||||||
ItemStack golditem = new ItemStack(Material.ORANGE_WOOL);
|
|
||||||
ItemMeta goldmeta = golditem.getItemMeta();
|
|
||||||
|
|
||||||
ItemStack lightgrayitem = new ItemStack(Material.LIGHT_GRAY_WOOL);
|
|
||||||
ItemMeta lightgraymeta = lightgrayitem.getItemMeta();
|
|
||||||
|
|
||||||
ItemStack grayitem = new ItemStack(Material.GRAY_WOOL);
|
|
||||||
ItemMeta graymeta = grayitem.getItemMeta();
|
|
||||||
|
|
||||||
ItemStack blueitem = new ItemStack(Material.LAPIS_BLOCK);
|
|
||||||
ItemMeta bluemeta = blueitem.getItemMeta();
|
|
||||||
|
|
||||||
ItemStack lightgreenitem = new ItemStack(Material.LIME_WOOL);
|
|
||||||
ItemMeta lightgreenmeta = lightgreenitem.getItemMeta();
|
|
||||||
|
|
||||||
ItemStack aquaitem = new ItemStack(Material.LIGHT_BLUE_WOOL);
|
|
||||||
ItemMeta aquameta = aquaitem.getItemMeta();
|
|
||||||
|
|
||||||
ItemStack lightreditem = new ItemStack(Material.PINK_WOOL);
|
|
||||||
ItemMeta lightredmeta = lightreditem.getItemMeta();
|
|
||||||
|
|
||||||
ItemStack pinkitem = new ItemStack(Material.MAGENTA_WOOL);
|
|
||||||
ItemMeta pinkmeta = pinkitem.getItemMeta();
|
|
||||||
|
|
||||||
ItemStack yellowitem = new ItemStack(Material.YELLOW_WOOL);
|
|
||||||
ItemMeta yellowmeta = yellowitem.getItemMeta();
|
|
||||||
|
|
||||||
ItemStack whiteitem = new ItemStack(Material.WHITE_WOOL);
|
|
||||||
ItemMeta whitemeta = whiteitem.getItemMeta();
|
|
||||||
|
|
||||||
//==========================================================
|
|
||||||
|
|
||||||
darkbluemeta.setDisplayName("§1Dark Blue Color Chat");
|
|
||||||
darkblueitem.setItemMeta(darkbluemeta);
|
|
||||||
|
|
||||||
greenmeta.setDisplayName("§2Green Color Chat");
|
|
||||||
greenitem.setItemMeta(greenmeta);
|
|
||||||
|
|
||||||
lightbluemeta.setDisplayName("§3Cyan Color Chat");
|
|
||||||
lightblueitem.setItemMeta(lightbluemeta);
|
|
||||||
|
|
||||||
redmeta.setDisplayName("§4Red Color Chat");
|
|
||||||
reditem.setItemMeta(redmeta);
|
|
||||||
|
|
||||||
purplemeta.setDisplayName("§5Purple Color Chat");
|
|
||||||
purpleitem.setItemMeta(purplemeta);
|
|
||||||
|
|
||||||
goldmeta.setDisplayName("§6Gold Color Chat");
|
|
||||||
golditem.setItemMeta(goldmeta);
|
|
||||||
|
|
||||||
lightgraymeta.setDisplayName("§7Light Gray Color Chat");
|
|
||||||
lightgrayitem.setItemMeta(lightgraymeta);
|
|
||||||
|
|
||||||
graymeta.setDisplayName("§8Gray Color Chat");
|
|
||||||
grayitem.setItemMeta(graymeta);
|
|
||||||
|
|
||||||
bluemeta.setDisplayName("§9Blue Color Chat");
|
|
||||||
blueitem.setItemMeta(bluemeta);
|
|
||||||
|
|
||||||
lightgreenmeta.setDisplayName("§aLight Green Color Chat");
|
|
||||||
lightgreenitem.setItemMeta(lightgreenmeta);
|
|
||||||
|
|
||||||
aquameta.setDisplayName("§bAqua Color Chat");
|
|
||||||
aquaitem.setItemMeta(aquameta);
|
|
||||||
|
|
||||||
lightredmeta.setDisplayName("§cLight Red Color Chat");
|
|
||||||
lightreditem.setItemMeta(lightredmeta);
|
|
||||||
|
|
||||||
pinkmeta.setDisplayName("§dMagenta Color Chat");
|
|
||||||
pinkitem.setItemMeta(pinkmeta);
|
|
||||||
|
|
||||||
yellowmeta.setDisplayName("§eYellow Color Chat");
|
|
||||||
yellowitem.setItemMeta(yellowmeta);
|
|
||||||
|
|
||||||
whitemeta.setDisplayName("§fWhite Color Chat");
|
|
||||||
whiteitem.setItemMeta(whitemeta);
|
|
||||||
//==========================================================
|
|
||||||
|
|
||||||
ItemStack holder = new ItemStack(Material.GRAY_STAINED_GLASS_PANE, 1);
|
|
||||||
ItemMeta holderM = holder.getItemMeta();
|
|
||||||
holderM.setDisplayName(" ");
|
|
||||||
holder.setItemMeta(holderM);
|
|
||||||
|
|
||||||
for(int o = 15; o < 27; o++) {
|
|
||||||
i.setItem(o, holder);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
i.setItem(0, darkblueitem);
|
|
||||||
i.setItem(1, greenitem);
|
|
||||||
i.setItem(2, lightblueitem);
|
|
||||||
i.setItem(3, reditem);
|
|
||||||
i.setItem(4, purpleitem);
|
|
||||||
i.setItem(5, golditem);
|
|
||||||
i.setItem(6, lightgrayitem);
|
|
||||||
i.setItem(7, grayitem);
|
|
||||||
i.setItem(8, blueitem);
|
|
||||||
i.setItem(9, lightgreenitem);
|
|
||||||
i.setItem(10, aquaitem);
|
|
||||||
i.setItem(11, lightreditem);
|
|
||||||
i.setItem(12, pinkitem);
|
|
||||||
i.setItem(13, yellowitem);
|
|
||||||
i.setItem(14, whiteitem);
|
|
||||||
|
|
||||||
|
|
||||||
p.openInventory(i);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* Command
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String s, String[] args) {
|
|
||||||
if(!(sender instanceof Player)){
|
|
||||||
plugin.getLogger().info("This command is for players only!");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Player p = (Player) sender;
|
|
||||||
if(p.hasPermission("ultrachat.color")){
|
|
||||||
openGUI(p.getPlayer(), 0);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
p.sendMessage(Lang.NO_PERM.toString());
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* Event
|
|
||||||
*/
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onInventoryClickEvent(InventoryClickEvent e){
|
|
||||||
try {
|
|
||||||
if(e.getView() == null || e.getView().getTitle() == null) return;
|
|
||||||
if(!e.getView().getTitle().equalsIgnoreCase(Lang.COLOR_GUI.toString())) return;
|
|
||||||
}catch(IllegalStateException ex) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Player p = (Player) e.getWhoClicked();
|
|
||||||
e.setCancelled(true);
|
|
||||||
|
|
||||||
if(e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR || !e.getCurrentItem().hasItemMeta()){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//================
|
|
||||||
ItemStack item = e.getCurrentItem();
|
|
||||||
|
|
||||||
if(!e.getInventory().contains(item)) return;
|
|
||||||
|
|
||||||
switch(item.getType()) {
|
|
||||||
case LAPIS_BLOCK:
|
|
||||||
if(p.hasPermission("ultrachat.color.blue")){
|
|
||||||
p.sendMessage(ChatColor.BLUE + "You choose blue color chat!");
|
|
||||||
p.closeInventory();
|
|
||||||
plugin.data.set(p.getUniqueId() + ".color", "&9");
|
|
||||||
plugin.saveFile();
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
p.sendMessage(ChatColor.RED + "You do not have permission for this color!");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case WHITE_WOOL:
|
|
||||||
p.sendMessage(ChatColor.WHITE + "You choose white color chat!");
|
|
||||||
p.closeInventory();
|
|
||||||
plugin.data.set(p.getUniqueId() + ".color", "&f");
|
|
||||||
plugin.saveFile();
|
|
||||||
break;
|
|
||||||
case ORANGE_WOOL:
|
|
||||||
if(p.hasPermission("ultrachat.color.gold")){
|
|
||||||
p.sendMessage(ChatColor.GOLD + "You choose gold color chat!");
|
|
||||||
p.closeInventory();
|
|
||||||
plugin.data.set(p.getUniqueId() + ".color", "&6");
|
|
||||||
plugin.saveFile();
|
|
||||||
}else{
|
|
||||||
p.sendMessage(ChatColor.RED + "You do not have permission for this color!");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MAGENTA_WOOL:
|
|
||||||
if(p.hasPermission("ultrachat.color.magenta")){
|
|
||||||
p.sendMessage(ChatColor.LIGHT_PURPLE + "You choose magenta color chat!");
|
|
||||||
p.closeInventory();
|
|
||||||
plugin.data.set(p.getUniqueId() + ".color", "&d");
|
|
||||||
plugin.saveFile();
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
p.sendMessage(ChatColor.RED + "You do not have permission for this color!");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
case LIGHT_BLUE_WOOL:
|
|
||||||
if(p.hasPermission("ultrachat.color.aqua")){
|
|
||||||
p.sendMessage(ChatColor.AQUA + "You choose Aqua color chat!");
|
|
||||||
p.closeInventory();
|
|
||||||
plugin.data.set(p.getUniqueId() + ".color", "&b");
|
|
||||||
plugin.saveFile();
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
p.sendMessage(ChatColor.RED + "You do not have permission for this color!");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
case YELLOW_WOOL:
|
|
||||||
if(p.hasPermission("ultrachat.color.yellow")){
|
|
||||||
p.sendMessage(ChatColor.YELLOW + "You choose yellow color chat!");
|
|
||||||
p.closeInventory();
|
|
||||||
plugin.data.set(p.getUniqueId() + ".color", "&e");
|
|
||||||
plugin.saveFile();
|
|
||||||
}else{
|
|
||||||
p.sendMessage(ChatColor.RED + "You do not have permission for this color!");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LIME_WOOL:
|
|
||||||
if(p.hasPermission("ultrachat.color.lightgreen")){
|
|
||||||
p.sendMessage(ChatColor.GREEN + "You choose light green color chat!");
|
|
||||||
p.closeInventory();
|
|
||||||
plugin.data.set(p.getUniqueId() + ".color", "&a");
|
|
||||||
plugin.saveFile();
|
|
||||||
}else{
|
|
||||||
p.sendMessage(ChatColor.RED + "You do not have permission for this color!");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case PINK_WOOL:
|
|
||||||
if(p.hasPermission("ultrachat.color.lightred")){
|
|
||||||
p.sendMessage(ChatColor.RED + "You choose light red color chat!");
|
|
||||||
p.closeInventory();
|
|
||||||
plugin.data.set(p.getUniqueId() + ".color", "&c");
|
|
||||||
plugin.saveFile();
|
|
||||||
}else{
|
|
||||||
p.sendMessage(ChatColor.RED + "You do not have permission for this color!");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case GRAY_WOOL:
|
|
||||||
if(p.hasPermission("ultrachat.color.gray")){
|
|
||||||
p.sendMessage(ChatColor.DARK_GRAY + "You choose gray color chat!");
|
|
||||||
p.closeInventory();
|
|
||||||
plugin.data.set(p.getUniqueId() + ".color", "&8");
|
|
||||||
plugin.saveFile();
|
|
||||||
}else{
|
|
||||||
p.sendMessage(ChatColor.RED + "You do not have permission for this color!");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case LIGHT_GRAY_WOOL:
|
|
||||||
if(p.hasPermission("ultrachat.color.lightgray")){
|
|
||||||
p.sendMessage(ChatColor.GRAY + "You choose light gray color chat!");
|
|
||||||
p.closeInventory();
|
|
||||||
plugin.data.set(p.getUniqueId() + ".color", "&7");
|
|
||||||
plugin.saveFile();
|
|
||||||
}else{
|
|
||||||
p.sendMessage(ChatColor.RED + "You do not have permission for this color!");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CYAN_WOOL:
|
|
||||||
if(p.hasPermission("ultrachat.color.cyan")){
|
|
||||||
p.sendMessage(ChatColor.DARK_AQUA + "You choose cyan color chat!");
|
|
||||||
p.closeInventory();
|
|
||||||
plugin.data.set(p.getUniqueId() + ".color", "&3");
|
|
||||||
plugin.saveFile();
|
|
||||||
}else{
|
|
||||||
p.sendMessage(ChatColor.RED + "You do not have permission for this color!");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case PURPLE_WOOL:
|
|
||||||
if(p.hasPermission("ultrachat.color.purple")){
|
|
||||||
p.sendMessage(ChatColor.DARK_PURPLE + "You choose purple color chat!");
|
|
||||||
p.closeInventory();
|
|
||||||
plugin.data.set(p.getUniqueId() + ".color", "&5");
|
|
||||||
plugin.saveFile();
|
|
||||||
}else{
|
|
||||||
p.sendMessage(ChatColor.RED + "You do not have permission for this color!");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case BLUE_WOOL:
|
|
||||||
if(p.hasPermission("ultrachat.color.darkblue")){
|
|
||||||
p.sendMessage(ChatColor.DARK_BLUE + "You choose dark blue color chat!");
|
|
||||||
p.closeInventory();
|
|
||||||
plugin.data.set(p.getUniqueId() + ".color", "&1");
|
|
||||||
plugin.saveFile();
|
|
||||||
}else{
|
|
||||||
p.sendMessage(ChatColor.RED + "You do not have permission for this color!");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case GREEN_WOOL:
|
|
||||||
if(p.hasPermission("ultrachat.color.green")){
|
|
||||||
p.sendMessage(ChatColor.DARK_GREEN + "You choose green color chat!");
|
|
||||||
p.closeInventory();
|
|
||||||
plugin.data.set(p.getUniqueId() + ".color", "&2");
|
|
||||||
plugin.saveFile();
|
|
||||||
}else{
|
|
||||||
p.sendMessage(ChatColor.RED + "You do not have permission for this color!");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case RED_WOOL:
|
|
||||||
if(p.hasPermission("ultrachat.color.red")){
|
|
||||||
p.sendMessage(ChatColor.DARK_RED + "You choose red color chat!");
|
|
||||||
p.closeInventory();
|
|
||||||
plugin.data.set(p.getUniqueId() + ".color", "&4");
|
|
||||||
plugin.saveFile();
|
|
||||||
}else{
|
|
||||||
p.sendMessage(ChatColor.RED + "You do not have permission for this color!");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case GRAY_STAINED_GLASS_PANE:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
p.sendMessage(ChatColor.WHITE + "You choose white color chat!");
|
|
||||||
p.closeInventory();
|
|
||||||
plugin.data.set(p.getUniqueId() + ".color", "&f");
|
|
||||||
plugin.saveFile();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,216 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.gui;
|
|
||||||
|
|
||||||
import com.sun.istack.internal.NotNull;
|
|
||||||
import me.ryandw11.ultrachat.util.ChatUtil;
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.UltraChat;
|
|
||||||
import me.ryandw11.ultrachat.api.Lang;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ColorGUI class.
|
|
||||||
* Updated for 1.16+
|
|
||||||
* @author Ryandw11
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ColorGUI_Latest implements CommandExecutor, Listener, ColorGUI{
|
|
||||||
|
|
||||||
private UltraChat plugin;
|
|
||||||
private List<String> colors;
|
|
||||||
public ColorGUI_Latest(){
|
|
||||||
plugin = UltraChat.plugin;
|
|
||||||
colors = new ArrayList<>(Objects.requireNonNull(plugin.chatColorFC.getConfigurationSection("color_gui")).getKeys(false));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void openGUI(Player p, int page){
|
|
||||||
Inventory inv = Bukkit.createInventory(null, 9*3, Lang.COLOR_GUI.toString());
|
|
||||||
|
|
||||||
int i = getMin(page);
|
|
||||||
int invSlot = 0;
|
|
||||||
while(i < colors.size() && i < getMax(page)){
|
|
||||||
ConfigurationSection section = plugin.chatColorFC.getConfigurationSection("color_gui." + colors.get(i));
|
|
||||||
assert section != null;
|
|
||||||
if(p.hasPermission(Objects.requireNonNull(section.getString("permission")))){
|
|
||||||
ItemStack item = new ItemStack(Objects.requireNonNull(Material.getMaterial(Objects.requireNonNull(section.getString("item")))));
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
|
||||||
assert meta != null;
|
|
||||||
meta.setDisplayName(ChatUtil.translateColorCode(section.getString("color")) + section.getName());
|
|
||||||
meta.setLore(Collections.singletonList(ChatColor.AQUA + "Click this to set your chat color!"));
|
|
||||||
item.setItemMeta(meta);
|
|
||||||
inv.setItem(invSlot, item);
|
|
||||||
}else{
|
|
||||||
inv.setItem(invSlot, getNoPermItem());
|
|
||||||
}
|
|
||||||
|
|
||||||
invSlot++;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
setBottom(inv, page);
|
|
||||||
p.openInventory(inv);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getMax(int page){
|
|
||||||
return 9 * (2 * page);
|
|
||||||
}
|
|
||||||
private int getMin(int page){
|
|
||||||
return (9 * (page*2)) - (9*2);
|
|
||||||
}
|
|
||||||
|
|
||||||
private ItemStack getNoPermItem(){
|
|
||||||
ItemStack itemStack = new ItemStack(Material.LIGHT_GRAY_STAINED_GLASS_PANE);
|
|
||||||
ItemMeta meta = itemStack.getItemMeta();
|
|
||||||
assert meta != null;
|
|
||||||
meta.setDisplayName(ChatColor.RED + "You do not have permission for this color!");
|
|
||||||
itemStack.setItemMeta(meta);
|
|
||||||
return itemStack;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ItemStack getBottomStack(){
|
|
||||||
ItemStack bottomStack = new ItemStack(Material.GRAY_STAINED_GLASS_PANE);
|
|
||||||
ItemMeta bottomMeta = bottomStack.getItemMeta();
|
|
||||||
assert bottomMeta != null;
|
|
||||||
bottomMeta.setDisplayName(ChatColor.GRAY + " ");
|
|
||||||
bottomStack.setItemMeta(bottomMeta);
|
|
||||||
return bottomStack;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ItemStack getPrevStack(int page){
|
|
||||||
ItemStack prevPage = new ItemStack(Material.PURPLE_STAINED_GLASS_PANE);
|
|
||||||
ItemMeta prevMeta = prevPage.getItemMeta();
|
|
||||||
assert prevMeta != null;
|
|
||||||
prevMeta.setDisplayName(ChatColor.LIGHT_PURPLE + "<< Previous Page");
|
|
||||||
prevPage.setItemMeta(prevMeta);
|
|
||||||
if(page > 1)
|
|
||||||
prevPage.setAmount(page-1);
|
|
||||||
return prevPage;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ItemStack getCurrentStack(int page){
|
|
||||||
ItemStack currentPage = new ItemStack(Material.GRAY_STAINED_GLASS_PANE);
|
|
||||||
ItemMeta currentMeta = currentPage.getItemMeta();
|
|
||||||
assert currentMeta != null;
|
|
||||||
currentMeta.setDisplayName(ChatColor.GRAY + "Current Page: " + page);
|
|
||||||
currentPage.setItemMeta(currentMeta);
|
|
||||||
currentPage.setAmount(page);
|
|
||||||
return currentPage;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ItemStack getNextStack(int page){
|
|
||||||
ItemStack nextPage = new ItemStack(Material.RED_STAINED_GLASS_PANE);
|
|
||||||
ItemMeta nextMeta = nextPage.getItemMeta();
|
|
||||||
assert nextMeta != null;
|
|
||||||
nextMeta.setDisplayName(ChatColor.RED + "Next Page >>");
|
|
||||||
nextPage.setItemMeta(nextMeta);
|
|
||||||
nextPage.setAmount(page+1);
|
|
||||||
return nextPage;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setBottom(Inventory inventory, int page){
|
|
||||||
ItemStack bottomStack = getBottomStack();
|
|
||||||
ItemStack prevPage = getPrevStack(page);
|
|
||||||
ItemStack currentPage = getCurrentStack(page);
|
|
||||||
ItemStack nextPage = getNextStack(page);
|
|
||||||
for(int i = 18; i < 27; i++){
|
|
||||||
if(i == 21 && page > 1){
|
|
||||||
inventory.setItem(i, prevPage);
|
|
||||||
}else if(i == 22){
|
|
||||||
inventory.setItem(i, currentPage);
|
|
||||||
}else if(i == 23 && colors.size() > getMax(page)){
|
|
||||||
inventory.setItem(i, nextPage);
|
|
||||||
}else{
|
|
||||||
inventory.setItem(i, bottomStack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Command
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String s, @NotNull String[] args) {
|
|
||||||
if(!(sender instanceof Player)){
|
|
||||||
plugin.getLogger().info("This command is for players only!");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Player p = (Player) sender;
|
|
||||||
if(p.hasPermission("ultrachat.color")){
|
|
||||||
openGUI(p.getPlayer(), 1);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
p.sendMessage(Lang.NO_PERM.toString());
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* Event
|
|
||||||
*/
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onInventoryClickEvent(InventoryClickEvent e){
|
|
||||||
try {
|
|
||||||
if(e.getView() == null || e.getView().getTitle() == null) return;
|
|
||||||
if(!e.getView().getTitle().equalsIgnoreCase(Lang.COLOR_GUI.toString())) return;
|
|
||||||
}catch(IllegalStateException ex) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Player p = (Player) e.getWhoClicked();
|
|
||||||
e.setCancelled(true);
|
|
||||||
|
|
||||||
if(e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR || !e.getCurrentItem().hasItemMeta()){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int page = Objects.requireNonNull(e.getInventory().getItem(22)).getAmount();
|
|
||||||
|
|
||||||
ItemStack item = e.getCurrentItem();
|
|
||||||
if(!e.getInventory().contains(item)) return;
|
|
||||||
|
|
||||||
if(item.equals(getBottomStack()) || item.equals(getCurrentStack(page)) || item.equals(getNoPermItem())) return;
|
|
||||||
if(item.equals(getNextStack(page))){
|
|
||||||
p.closeInventory();
|
|
||||||
openGUI(p, page+1);
|
|
||||||
}else if(item.equals(getPrevStack(page))){
|
|
||||||
p.closeInventory();
|
|
||||||
openGUI(p, page-1);
|
|
||||||
}else{
|
|
||||||
ConfigurationSection section = plugin.chatColorFC.getConfigurationSection("color_gui."
|
|
||||||
+ ChatColor.stripColor(Objects.requireNonNull(item.getItemMeta()).getDisplayName()));
|
|
||||||
|
|
||||||
assert section != null;
|
|
||||||
if(!p.hasPermission(Objects.requireNonNull(section.getString("permission")))){
|
|
||||||
p.sendMessage(ChatColor.RED + "You do not have permission to use this chat color!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
plugin.data.set(p.getUniqueId() + ".color", section.getString("color"));
|
|
||||||
plugin.saveFile();
|
|
||||||
|
|
||||||
p.spigot().sendMessage(TextComponent.fromLegacyText(plugin.chatColorUtil.translateChatColor(section.getString("color") + Lang.CHAT_COLOR_CHANGE)));
|
|
||||||
|
|
||||||
p.closeInventory();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,127 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.listner;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.UltraChat;
|
|
||||||
import me.ryandw11.ultrachat.api.Lang;
|
|
||||||
import me.ryandw11.ultrachat.api.managers.JComponentManager;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.util.ChatUtil;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Ryandw11
|
|
||||||
*/
|
|
||||||
public class JoinListner implements Listener {
|
|
||||||
|
|
||||||
private UltraChat plugin;
|
|
||||||
|
|
||||||
public JoinListner() {
|
|
||||||
plugin = UltraChat.plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onJoin(PlayerJoinEvent event) {
|
|
||||||
Player p = event.getPlayer();
|
|
||||||
|
|
||||||
if (plugin.data.contains(p.getUniqueId().toString())) {
|
|
||||||
if (!(plugin.channel.contains(Objects.requireNonNull(plugin.data.getString(p.getUniqueId() + ".channel"))))) {
|
|
||||||
/*
|
|
||||||
* Fail safe so that if the player joins with an invalid channel it goes back to default.
|
|
||||||
*/
|
|
||||||
plugin.data.set(p.getUniqueId() + ".channel", plugin.getConfig().getString("Default_Channel"));
|
|
||||||
plugin.saveFile();
|
|
||||||
|
|
||||||
} else if (!(plugin.data.contains(p.getUniqueId().toString() + ".spy"))) {
|
|
||||||
plugin.data.set(p.getUniqueId().toString() + ".spy", false);
|
|
||||||
plugin.saveFile();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
plugin.data.set(p.getUniqueId().toString() + ".color", "&f");
|
|
||||||
plugin.data.set(p.getUniqueId().toString() + ".sjoin", false);
|
|
||||||
plugin.data.set(p.getUniqueId().toString() + ".spy", false);
|
|
||||||
plugin.data.set(p.getUniqueId().toString() + ".channel", plugin.getConfig().getString("Default_Channel"));
|
|
||||||
plugin.saveFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (plugin.data.getBoolean(p.getUniqueId().toString() + ".sjoin")) {
|
|
||||||
event.setJoinMessage("");
|
|
||||||
for (Player pl : Bukkit.getOnlinePlayers()) {
|
|
||||||
if (pl.hasPermission("ultrachat.sjoin.alert")) {
|
|
||||||
pl.sendMessage(Lang.SILENT_JOIN_MESSAGE.toString().replace("%p", p.getDisplayName()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
String Join = ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(plugin.getConfig().getString("Join_Message")).replace("%player%", p.getName()));
|
|
||||||
event.setJoinMessage(Join);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* On leave event
|
|
||||||
*/
|
|
||||||
@EventHandler
|
|
||||||
public void onLeave(PlayerQuitEvent event) {
|
|
||||||
|
|
||||||
Player p = event.getPlayer();
|
|
||||||
if (plugin.data.getBoolean(p.getUniqueId().toString() + ".sjoin")) {
|
|
||||||
event.setQuitMessage("");
|
|
||||||
for (Player pl : Bukkit.getOnlinePlayers()) {
|
|
||||||
if (pl.hasPermission("ultrachat.sjoin.alert")) {
|
|
||||||
pl.sendMessage(Lang.SILENT_LEAVE_MESSAGE.toString().replace("%p", p.getDisplayName()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
|
|
||||||
String leave = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Leave_Message").replace("%player%", p.getName()));
|
|
||||||
event.setQuitMessage(leave);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* For MOTD
|
|
||||||
*/
|
|
||||||
@EventHandler
|
|
||||||
public void MOTD(PlayerJoinEvent event) {
|
|
||||||
Player p = event.getPlayer();
|
|
||||||
if (plugin.getConfig().getBoolean("Motd_Enabled")) {
|
|
||||||
List<String> motd = plugin.getConfig().getStringList("Motd");
|
|
||||||
for (String OutPut : motd) {
|
|
||||||
String message = OutPut;
|
|
||||||
message = plugin.papi.translatePlaceholders(message, p);
|
|
||||||
p.spigot().sendMessage(JComponentManager.formatComponents(plugin.chatColorUtil.translateChatColor(message), p));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If there is a new player.
|
|
||||||
*/
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void NewPlayer(PlayerJoinEvent event) {
|
|
||||||
Player p = event.getPlayer();
|
|
||||||
if (!(p.hasPlayedBefore()) && !(Objects.requireNonNull(plugin.getConfig().getString("New_Player")).equalsIgnoreCase("none"))) {
|
|
||||||
String msg = ChatUtil.translateColorCodes(Objects.requireNonNull(plugin.getConfig().getString("New_Player")).replace("%player%", p.getDisplayName()));
|
|
||||||
for (Player pl : Bukkit.getOnlinePlayers()) {
|
|
||||||
pl.spigot().sendMessage(JComponentManager.formatComponents(msg, p));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.listner;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.UltraChat;
|
|
||||||
import me.ryandw11.ultrachat.api.Lang;
|
|
||||||
import me.ryandw11.ultrachat.api.events.UltraChatEvent;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Ryandw11
|
|
||||||
*/
|
|
||||||
public class NoSwear implements Listener {
|
|
||||||
|
|
||||||
private UltraChat plugin;
|
|
||||||
|
|
||||||
public NoSwear() {
|
|
||||||
plugin = UltraChat.plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onJsonChat(UltraChatEvent event) {
|
|
||||||
if (plugin.getConfig().getBoolean("Anti_Swear_Enabled")) {
|
|
||||||
Player p = event.getPlayer();
|
|
||||||
|
|
||||||
|
|
||||||
List<String> swear = plugin.getConfig().getStringList("Blocked_Words");
|
|
||||||
|
|
||||||
String Message = " " + event.getMessage().toLowerCase().replace(".", "") + " ";
|
|
||||||
|
|
||||||
for (String swearWord : swear) {
|
|
||||||
//Check if world chat is enabled
|
|
||||||
if (Message.contains(swearWord + " ") || Message.contains(" " + swearWord + " ") || Message.contains(" " + swearWord) || Message.contains(swearWord)) {
|
|
||||||
//else do this:
|
|
||||||
event.setCancelled(true);
|
|
||||||
p.sendMessage(Lang.NO_SWEAR.toString());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.listner;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.api.Lang;
|
|
||||||
import me.ryandw11.ultrachat.api.events.UltraChatEvent;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Sound;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Ryandw11
|
|
||||||
* Updated for 1.13
|
|
||||||
*/
|
|
||||||
public class Notify implements Listener {
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onJsonChat(UltraChatEvent e) {
|
|
||||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
|
||||||
if (e.getMessage().contains("@" + p.getName())) {
|
|
||||||
p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 10, 0);
|
|
||||||
p.sendMessage(Lang.MENTION.toString().replace("%p", e.getPlayer().getDisplayName()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.listner;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.UltraChat;
|
|
||||||
import me.ryandw11.ultrachat.api.Lang;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
|
||||||
|
|
||||||
public class Spy implements Listener {
|
|
||||||
|
|
||||||
private UltraChat plugin;
|
|
||||||
|
|
||||||
public Spy() {
|
|
||||||
plugin = UltraChat.plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerCommand(PlayerCommandPreprocessEvent event) {
|
|
||||||
Player p1 = (Player) event.getPlayer();
|
|
||||||
String msg = event.getMessage();//get user name
|
|
||||||
|
|
||||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
|
||||||
if (plugin.spyToggle.contains(p.getUniqueId())) {
|
|
||||||
p.sendMessage(Lang.CMD_SPY_FORMAT.toString().replace("%p", p1.getName()).replace("%s", msg));
|
|
||||||
}// end of if
|
|
||||||
|
|
||||||
|
|
||||||
}//end of for loop
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.listner;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.UltraChat;
|
|
||||||
import me.ryandw11.ultrachat.api.Lang;
|
|
||||||
import me.ryandw11.ultrachat.api.events.UltraChatEvent;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prevent players from chatting when the chat is stopped.
|
|
||||||
*
|
|
||||||
* @author Ryandw11
|
|
||||||
*/
|
|
||||||
public class StopChat implements Listener {
|
|
||||||
|
|
||||||
private UltraChat plugin;
|
|
||||||
|
|
||||||
public StopChat() {
|
|
||||||
plugin = UltraChat.plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onChat(UltraChatEvent e) {
|
|
||||||
Player p = e.getPlayer();
|
|
||||||
if (plugin.isChatStopped) {
|
|
||||||
if (!p.hasPermission("ultrachat.stopchat.bypass")) {
|
|
||||||
e.setCancelled(true);
|
|
||||||
p.sendMessage(Lang.STOP_CHAT_MESSAGE.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.pluginhooks;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
|
|
||||||
import me.leoko.advancedban.manager.PunishmentManager;
|
|
||||||
import me.leoko.advancedban.manager.UUIDManager;
|
|
||||||
import me.ryandw11.ultrachat.api.events.UltraChatEvent;
|
|
||||||
|
|
||||||
public class AdvancedBanMute implements Listener{
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void jsonChat(UltraChatEvent e){
|
|
||||||
Player p = e.getPlayer();
|
|
||||||
if(PunishmentManager.get().isMuted(UUIDManager.get().getUUID(p.getName()))){
|
|
||||||
e.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.pluginhooks;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
|
|
||||||
import com.earth2me.essentials.Essentials;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.api.events.UltraChatEvent;
|
|
||||||
|
|
||||||
public class EssentialsMute implements Listener{
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void jsonChat(UltraChatEvent e){
|
|
||||||
Player p = e.getPlayer();
|
|
||||||
Essentials ess = (Essentials) Bukkit.getPluginManager().getPlugin("Essentials");
|
|
||||||
assert ess != null;
|
|
||||||
if(ess.getUser(p).isMuted()){
|
|
||||||
e.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.util;
|
|
||||||
|
|
||||||
import me.ryandw11.ultrachat.UltraChat;
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is a utility class to make chat easier.
|
|
||||||
*/
|
|
||||||
public class ChatUtil {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Translates the message into color codes.
|
|
||||||
* <p>This also translates hex color codes: {#FFFFFF}</p>
|
|
||||||
* @param message The message to translate
|
|
||||||
* @return The translated message.
|
|
||||||
*/
|
|
||||||
public static String translateColorCodes(String message){
|
|
||||||
return UltraChat.plugin.chatColorUtil.translateChatColor(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String translateColorCodes(String message, Player p){
|
|
||||||
return UltraChat.plugin.chatColorUtil.translateChatColor(message, p);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ChatColor translateColorCode(String code){
|
|
||||||
return UltraChat.plugin.chatColorUtil.translateChatCode(code);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,668 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.util;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
|
||||||
import org.bukkit.plugin.ServicePriority;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import org.json.simple.JSONArray;
|
|
||||||
import org.json.simple.JSONObject;
|
|
||||||
|
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Timer;
|
|
||||||
import java.util.TimerTask;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.zip.GZIPOutputStream;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* bStats collects some data for plugin authors.
|
|
||||||
*
|
|
||||||
* Check out https://bStats.org/ to learn more about bStats!
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public class Metrics {
|
|
||||||
|
|
||||||
static {
|
|
||||||
// You can use the property to disable the check in your test environment
|
|
||||||
if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) {
|
|
||||||
// Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D
|
|
||||||
final String defaultPackage = new String(
|
|
||||||
new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'});
|
|
||||||
final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
|
|
||||||
// We want to make sure nobody just copy & pastes the example and use the wrong package names
|
|
||||||
if (Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage)) {
|
|
||||||
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// The version of this bStats class
|
|
||||||
public static final int B_STATS_VERSION = 1;
|
|
||||||
|
|
||||||
// The url to which the data is sent
|
|
||||||
private static final String URL = "https://bStats.org/submitData/bukkit";
|
|
||||||
|
|
||||||
// Should failed requests be logged?
|
|
||||||
private static boolean logFailedRequests;
|
|
||||||
|
|
||||||
// The uuid of the server
|
|
||||||
private static String serverUUID;
|
|
||||||
|
|
||||||
// The plugin
|
|
||||||
private final JavaPlugin plugin;
|
|
||||||
|
|
||||||
// A list with all custom charts
|
|
||||||
private final List<CustomChart> charts = new ArrayList<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class constructor.
|
|
||||||
*
|
|
||||||
* @param plugin The plugin which stats should be submitted.
|
|
||||||
*/
|
|
||||||
public Metrics(JavaPlugin plugin) {
|
|
||||||
if (plugin == null) {
|
|
||||||
throw new IllegalArgumentException("Plugin cannot be null!");
|
|
||||||
}
|
|
||||||
this.plugin = plugin;
|
|
||||||
|
|
||||||
// Get the config file
|
|
||||||
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
|
|
||||||
File configFile = new File(bStatsFolder, "config.yml");
|
|
||||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
|
||||||
|
|
||||||
// Check if the config file exists
|
|
||||||
if (!config.isSet("serverUuid")) {
|
|
||||||
|
|
||||||
// Add default values
|
|
||||||
config.addDefault("enabled", true);
|
|
||||||
// Every server gets it's unique random id.
|
|
||||||
config.addDefault("serverUuid", UUID.randomUUID().toString());
|
|
||||||
// Should failed request be logged?
|
|
||||||
config.addDefault("logFailedRequests", false);
|
|
||||||
|
|
||||||
// Inform the server owners about bStats
|
|
||||||
config.options().header(
|
|
||||||
"bStats collects some data for plugin authors like how many servers are using their plugins.\n" +
|
|
||||||
"To honor their work, you should not disable it.\n" +
|
|
||||||
"This has nearly no effect on the server performance!\n" +
|
|
||||||
"Check out https://bStats.org/ to learn more :)"
|
|
||||||
).copyDefaults(true);
|
|
||||||
try {
|
|
||||||
config.save(configFile);
|
|
||||||
} catch (IOException ignored) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load the data
|
|
||||||
serverUUID = config.getString("serverUuid");
|
|
||||||
logFailedRequests = config.getBoolean("logFailedRequests", false);
|
|
||||||
if (config.getBoolean("enabled", true)) {
|
|
||||||
boolean found = false;
|
|
||||||
// Search for all other bStats Metrics classes to see if we are the first one
|
|
||||||
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
|
|
||||||
try {
|
|
||||||
service.getField("B_STATS_VERSION"); // Our identifier :)
|
|
||||||
found = true; // We aren't the first
|
|
||||||
break;
|
|
||||||
} catch (NoSuchFieldException ignored) { }
|
|
||||||
}
|
|
||||||
// Register our service
|
|
||||||
Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal);
|
|
||||||
if (!found) {
|
|
||||||
// We are the first!
|
|
||||||
startSubmitting();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a custom chart.
|
|
||||||
*
|
|
||||||
* @param chart The chart to add.
|
|
||||||
*/
|
|
||||||
public void addCustomChart(CustomChart chart) {
|
|
||||||
if (chart == null) {
|
|
||||||
throw new IllegalArgumentException("Chart cannot be null!");
|
|
||||||
}
|
|
||||||
charts.add(chart);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts the Scheduler which submits our data every 30 minutes.
|
|
||||||
*/
|
|
||||||
private void startSubmitting() {
|
|
||||||
final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags
|
|
||||||
timer.scheduleAtFixedRate(new TimerTask() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (!plugin.isEnabled()) { // Plugin was disabled
|
|
||||||
timer.cancel();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler
|
|
||||||
// Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
|
|
||||||
Bukkit.getScheduler().runTask(plugin, new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
submitData();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, 1000*60*5, 1000*60*30);
|
|
||||||
// Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
|
|
||||||
// WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
|
|
||||||
// WARNING: Just don't do it!
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the plugin specific data.
|
|
||||||
* This method is called using Reflection.
|
|
||||||
*
|
|
||||||
* @return The plugin specific data.
|
|
||||||
*/
|
|
||||||
public JSONObject getPluginData() {
|
|
||||||
JSONObject data = new JSONObject();
|
|
||||||
|
|
||||||
String pluginName = plugin.getDescription().getName();
|
|
||||||
String pluginVersion = plugin.getDescription().getVersion();
|
|
||||||
|
|
||||||
data.put("pluginName", pluginName); // Append the name of the plugin
|
|
||||||
data.put("pluginVersion", pluginVersion); // Append the version of the plugin
|
|
||||||
JSONArray customCharts = new JSONArray();
|
|
||||||
for (CustomChart customChart : charts) {
|
|
||||||
// Add the data of the custom charts
|
|
||||||
JSONObject chart = customChart.getRequestJsonObject();
|
|
||||||
if (chart == null) { // If the chart is null, we skip it
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
customCharts.add(chart);
|
|
||||||
}
|
|
||||||
data.put("customCharts", customCharts);
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the server specific data.
|
|
||||||
*
|
|
||||||
* @return The server specific data.
|
|
||||||
*/
|
|
||||||
private JSONObject getServerData() {
|
|
||||||
// Minecraft specific data
|
|
||||||
int playerAmount;
|
|
||||||
try {
|
|
||||||
// Around MC 1.8 the return type was changed to a collection from an array,
|
|
||||||
// This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
|
|
||||||
Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
|
|
||||||
playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
|
|
||||||
? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
|
|
||||||
: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
|
|
||||||
} catch (Exception e) {
|
|
||||||
playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
|
|
||||||
}
|
|
||||||
int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
|
|
||||||
String bukkitVersion = org.bukkit.Bukkit.getVersion();
|
|
||||||
bukkitVersion = bukkitVersion.substring(bukkitVersion.indexOf("MC: ") + 4, bukkitVersion.length() - 1);
|
|
||||||
|
|
||||||
// OS/Java specific data
|
|
||||||
String javaVersion = System.getProperty("java.version");
|
|
||||||
String osName = System.getProperty("os.name");
|
|
||||||
String osArch = System.getProperty("os.arch");
|
|
||||||
String osVersion = System.getProperty("os.version");
|
|
||||||
int coreCount = Runtime.getRuntime().availableProcessors();
|
|
||||||
|
|
||||||
JSONObject data = new JSONObject();
|
|
||||||
|
|
||||||
data.put("serverUUID", serverUUID);
|
|
||||||
|
|
||||||
data.put("playerAmount", playerAmount);
|
|
||||||
data.put("onlineMode", onlineMode);
|
|
||||||
data.put("bukkitVersion", bukkitVersion);
|
|
||||||
|
|
||||||
data.put("javaVersion", javaVersion);
|
|
||||||
data.put("osName", osName);
|
|
||||||
data.put("osArch", osArch);
|
|
||||||
data.put("osVersion", osVersion);
|
|
||||||
data.put("coreCount", coreCount);
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Collects the data and sends it afterwards.
|
|
||||||
*/
|
|
||||||
private void submitData() {
|
|
||||||
final JSONObject data = getServerData();
|
|
||||||
|
|
||||||
JSONArray pluginData = new JSONArray();
|
|
||||||
// Search for all other bStats Metrics classes to get their plugin data
|
|
||||||
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
|
|
||||||
try {
|
|
||||||
service.getField("B_STATS_VERSION"); // Our identifier :)
|
|
||||||
|
|
||||||
for (RegisteredServiceProvider<?> provider : Bukkit.getServicesManager().getRegistrations(service)) {
|
|
||||||
try {
|
|
||||||
pluginData.add(provider.getService().getMethod("getPluginData").invoke(provider.getProvider()));
|
|
||||||
} catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { }
|
|
||||||
}
|
|
||||||
} catch (NoSuchFieldException ignored) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
data.put("plugins", pluginData);
|
|
||||||
|
|
||||||
// Create a new thread for the connection to the bStats server
|
|
||||||
new Thread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
// Send the data
|
|
||||||
sendData(data);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// Something went wrong! :(
|
|
||||||
if (logFailedRequests) {
|
|
||||||
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends the data to the bStats server.
|
|
||||||
*
|
|
||||||
* @param data The data to send.
|
|
||||||
* @throws Exception If the request failed.
|
|
||||||
*/
|
|
||||||
private static void sendData(JSONObject data) throws Exception {
|
|
||||||
if (data == null) {
|
|
||||||
throw new IllegalArgumentException("Data cannot be null!");
|
|
||||||
}
|
|
||||||
if (Bukkit.isPrimaryThread()) {
|
|
||||||
throw new IllegalAccessException("This method must not be called from the main thread!");
|
|
||||||
}
|
|
||||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
|
|
||||||
|
|
||||||
// Compress the data to save bandwidth
|
|
||||||
byte[] compressedData = compress(data.toString());
|
|
||||||
|
|
||||||
// Add headers
|
|
||||||
connection.setRequestMethod("POST");
|
|
||||||
connection.addRequestProperty("Accept", "application/json");
|
|
||||||
connection.addRequestProperty("Connection", "close");
|
|
||||||
connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
|
|
||||||
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
|
|
||||||
connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
|
|
||||||
connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
|
|
||||||
|
|
||||||
// Send data
|
|
||||||
connection.setDoOutput(true);
|
|
||||||
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
|
|
||||||
outputStream.write(compressedData);
|
|
||||||
outputStream.flush();
|
|
||||||
outputStream.close();
|
|
||||||
|
|
||||||
connection.getInputStream().close(); // We don't care about the response - Just send our data :)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gzips the given String.
|
|
||||||
*
|
|
||||||
* @param str The string to gzip.
|
|
||||||
* @return The gzipped String.
|
|
||||||
* @throws IOException If the compression failed.
|
|
||||||
*/
|
|
||||||
private static byte[] compress(final String str) throws IOException {
|
|
||||||
if (str == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
||||||
GZIPOutputStream gzip = new GZIPOutputStream(outputStream);
|
|
||||||
gzip.write(str.getBytes("UTF-8"));
|
|
||||||
gzip.close();
|
|
||||||
return outputStream.toByteArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a custom chart.
|
|
||||||
*/
|
|
||||||
public static abstract class CustomChart {
|
|
||||||
|
|
||||||
// The id of the chart
|
|
||||||
final String chartId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class constructor.
|
|
||||||
*
|
|
||||||
* @param chartId The id of the chart.
|
|
||||||
*/
|
|
||||||
CustomChart(String chartId) {
|
|
||||||
if (chartId == null || chartId.isEmpty()) {
|
|
||||||
throw new IllegalArgumentException("ChartId cannot be null or empty!");
|
|
||||||
}
|
|
||||||
this.chartId = chartId;
|
|
||||||
}
|
|
||||||
|
|
||||||
private JSONObject getRequestJsonObject() {
|
|
||||||
JSONObject chart = new JSONObject();
|
|
||||||
chart.put("chartId", chartId);
|
|
||||||
try {
|
|
||||||
JSONObject data = getChartData();
|
|
||||||
if (data == null) {
|
|
||||||
// If the data is null we don't send the chart.
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
chart.put("data", data);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
if (logFailedRequests) {
|
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return chart;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract JSONObject getChartData() throws Exception;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a custom simple pie.
|
|
||||||
*/
|
|
||||||
public static class SimplePie extends CustomChart {
|
|
||||||
|
|
||||||
private final Callable<String> callable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class constructor.
|
|
||||||
*
|
|
||||||
* @param chartId The id of the chart.
|
|
||||||
* @param callable The callable which is used to request the chart data.
|
|
||||||
*/
|
|
||||||
public SimplePie(String chartId, Callable<String> callable) {
|
|
||||||
super(chartId);
|
|
||||||
this.callable = callable;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected JSONObject getChartData() throws Exception {
|
|
||||||
JSONObject data = new JSONObject();
|
|
||||||
String value = callable.call();
|
|
||||||
if (value == null || value.isEmpty()) {
|
|
||||||
// Null = skip the chart
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
data.put("value", value);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a custom advanced pie.
|
|
||||||
*/
|
|
||||||
public static class AdvancedPie extends CustomChart {
|
|
||||||
|
|
||||||
private final Callable<Map<String, Integer>> callable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class constructor.
|
|
||||||
*
|
|
||||||
* @param chartId The id of the chart.
|
|
||||||
* @param callable The callable which is used to request the chart data.
|
|
||||||
*/
|
|
||||||
public AdvancedPie(String chartId, Callable<Map<String, Integer>> callable) {
|
|
||||||
super(chartId);
|
|
||||||
this.callable = callable;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected JSONObject getChartData() throws Exception {
|
|
||||||
JSONObject data = new JSONObject();
|
|
||||||
JSONObject values = new JSONObject();
|
|
||||||
Map<String, Integer> map = callable.call();
|
|
||||||
if (map == null || map.isEmpty()) {
|
|
||||||
// Null = skip the chart
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
boolean allSkipped = true;
|
|
||||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
|
||||||
if (entry.getValue() == 0) {
|
|
||||||
continue; // Skip this invalid
|
|
||||||
}
|
|
||||||
allSkipped = false;
|
|
||||||
values.put(entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
if (allSkipped) {
|
|
||||||
// Null = skip the chart
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
data.put("values", values);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a custom drilldown pie.
|
|
||||||
*/
|
|
||||||
public static class DrilldownPie extends CustomChart {
|
|
||||||
|
|
||||||
private final Callable<Map<String, Map<String, Integer>>> callable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class constructor.
|
|
||||||
*
|
|
||||||
* @param chartId The id of the chart.
|
|
||||||
* @param callable The callable which is used to request the chart data.
|
|
||||||
*/
|
|
||||||
public DrilldownPie(String chartId, Callable<Map<String, Map<String, Integer>>> callable) {
|
|
||||||
super(chartId);
|
|
||||||
this.callable = callable;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JSONObject getChartData() throws Exception {
|
|
||||||
JSONObject data = new JSONObject();
|
|
||||||
JSONObject values = new JSONObject();
|
|
||||||
Map<String, Map<String, Integer>> map = callable.call();
|
|
||||||
if (map == null || map.isEmpty()) {
|
|
||||||
// Null = skip the chart
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
boolean reallyAllSkipped = true;
|
|
||||||
for (Map.Entry<String, Map<String, Integer>> entryValues : map.entrySet()) {
|
|
||||||
JSONObject value = new JSONObject();
|
|
||||||
boolean allSkipped = true;
|
|
||||||
for (Map.Entry<String, Integer> valueEntry : map.get(entryValues.getKey()).entrySet()) {
|
|
||||||
value.put(valueEntry.getKey(), valueEntry.getValue());
|
|
||||||
allSkipped = false;
|
|
||||||
}
|
|
||||||
if (!allSkipped) {
|
|
||||||
reallyAllSkipped = false;
|
|
||||||
values.put(entryValues.getKey(), value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (reallyAllSkipped) {
|
|
||||||
// Null = skip the chart
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
data.put("values", values);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a custom single line chart.
|
|
||||||
*/
|
|
||||||
public static class SingleLineChart extends CustomChart {
|
|
||||||
|
|
||||||
private final Callable<Integer> callable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class constructor.
|
|
||||||
*
|
|
||||||
* @param chartId The id of the chart.
|
|
||||||
* @param callable The callable which is used to request the chart data.
|
|
||||||
*/
|
|
||||||
public SingleLineChart(String chartId, Callable<Integer> callable) {
|
|
||||||
super(chartId);
|
|
||||||
this.callable = callable;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected JSONObject getChartData() throws Exception {
|
|
||||||
JSONObject data = new JSONObject();
|
|
||||||
int value = callable.call();
|
|
||||||
if (value == 0) {
|
|
||||||
// Null = skip the chart
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
data.put("value", value);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a custom multi line chart.
|
|
||||||
*/
|
|
||||||
public static class MultiLineChart extends CustomChart {
|
|
||||||
|
|
||||||
private final Callable<Map<String, Integer>> callable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class constructor.
|
|
||||||
*
|
|
||||||
* @param chartId The id of the chart.
|
|
||||||
* @param callable The callable which is used to request the chart data.
|
|
||||||
*/
|
|
||||||
public MultiLineChart(String chartId, Callable<Map<String, Integer>> callable) {
|
|
||||||
super(chartId);
|
|
||||||
this.callable = callable;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected JSONObject getChartData() throws Exception {
|
|
||||||
JSONObject data = new JSONObject();
|
|
||||||
JSONObject values = new JSONObject();
|
|
||||||
Map<String, Integer> map = callable.call();
|
|
||||||
if (map == null || map.isEmpty()) {
|
|
||||||
// Null = skip the chart
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
boolean allSkipped = true;
|
|
||||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
|
||||||
if (entry.getValue() == 0) {
|
|
||||||
continue; // Skip this invalid
|
|
||||||
}
|
|
||||||
allSkipped = false;
|
|
||||||
values.put(entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
if (allSkipped) {
|
|
||||||
// Null = skip the chart
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
data.put("values", values);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a custom simple bar chart.
|
|
||||||
*/
|
|
||||||
public static class SimpleBarChart extends CustomChart {
|
|
||||||
|
|
||||||
private final Callable<Map<String, Integer>> callable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class constructor.
|
|
||||||
*
|
|
||||||
* @param chartId The id of the chart.
|
|
||||||
* @param callable The callable which is used to request the chart data.
|
|
||||||
*/
|
|
||||||
public SimpleBarChart(String chartId, Callable<Map<String, Integer>> callable) {
|
|
||||||
super(chartId);
|
|
||||||
this.callable = callable;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected JSONObject getChartData() throws Exception {
|
|
||||||
JSONObject data = new JSONObject();
|
|
||||||
JSONObject values = new JSONObject();
|
|
||||||
Map<String, Integer> map = callable.call();
|
|
||||||
if (map == null || map.isEmpty()) {
|
|
||||||
// Null = skip the chart
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
|
||||||
JSONArray categoryValues = new JSONArray();
|
|
||||||
categoryValues.add(entry.getValue());
|
|
||||||
values.put(entry.getKey(), categoryValues);
|
|
||||||
}
|
|
||||||
data.put("values", values);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a custom advanced bar chart.
|
|
||||||
*/
|
|
||||||
public static class AdvancedBarChart extends CustomChart {
|
|
||||||
|
|
||||||
private final Callable<Map<String, int[]>> callable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class constructor.
|
|
||||||
*
|
|
||||||
* @param chartId The id of the chart.
|
|
||||||
* @param callable The callable which is used to request the chart data.
|
|
||||||
*/
|
|
||||||
public AdvancedBarChart(String chartId, Callable<Map<String, int[]>> callable) {
|
|
||||||
super(chartId);
|
|
||||||
this.callable = callable;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected JSONObject getChartData() throws Exception {
|
|
||||||
JSONObject data = new JSONObject();
|
|
||||||
JSONObject values = new JSONObject();
|
|
||||||
Map<String, int[]> map = callable.call();
|
|
||||||
if (map == null || map.isEmpty()) {
|
|
||||||
// Null = skip the chart
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
boolean allSkipped = true;
|
|
||||||
for (Map.Entry<String, int[]> entry : map.entrySet()) {
|
|
||||||
if (entry.getValue().length == 0) {
|
|
||||||
continue; // Skip this invalid
|
|
||||||
}
|
|
||||||
allSkipped = false;
|
|
||||||
JSONArray categoryValues = new JSONArray();
|
|
||||||
for (int categoryValue : entry.getValue()) {
|
|
||||||
categoryValues.add(categoryValue);
|
|
||||||
}
|
|
||||||
values.put(entry.getKey(), categoryValues);
|
|
||||||
}
|
|
||||||
if (allSkipped) {
|
|
||||||
// Null = skip the chart
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
data.put("values", values);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.util.papi;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class PAPIDisabled implements PlaceHolderAPIHook {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String translatePlaceholders(String s, Player p) {
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.util.papi;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
|
||||||
|
|
||||||
public class PAPIEnabled implements PlaceHolderAPIHook{
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String translatePlaceholders(String s, Player p) {
|
|
||||||
return PlaceholderAPI.setPlaceholders(p, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package me.ryandw11.ultrachat.util.papi;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public interface PlaceHolderAPIHook {
|
|
||||||
public String translatePlaceholders(String s, Player p);
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
name: UltraChat
|
|
||||||
version: 2.5
|
|
||||||
main: me.ryandw11.ultrachat.UltraChat
|
|
||||||
author: Ryandw11
|
|
||||||
description: A chat formatting plugin.
|
|
||||||
depend: [Vault, PlaceholderAPI]
|
|
||||||
softdepend: [AdvancedBan, Essentials]
|
|
||||||
api-version: 1.13
|
|
||||||
commands:
|
|
||||||
chat:
|
|
||||||
description: The main command for the plugin.
|
|
||||||
aliases: [UltraChat, uchat, ultrac, uc]
|
|
||||||
sc:
|
|
||||||
description: The staff chat command.
|
|
||||||
aliases: [Staffchat, schat, staffc]
|
|
||||||
sctoggle:
|
|
||||||
description: Toggle the staff chat from showing up.
|
|
||||||
aliases: [StaffchatToggle, schattoggle, staffct, sct]
|
|
||||||
spy:
|
|
||||||
description: See commands that other players type.
|
|
||||||
aliases: [spycmd, cmds, uspy, ucspy]
|
|
||||||
color:
|
|
||||||
description: Change your chat color.
|
|
||||||
aliases: [ccolor, chatcolor, uchatcolor, uccolor, chat color]
|
|
||||||
channel:
|
|
||||||
description: Change the channel you are using or display the help.
|
|
||||||
aliases: [chan, cn, ch, channels]
|
|
||||||
global:
|
|
||||||
description: Used when using range chat!
|
|
||||||
aliases: [g, gl, ug]
|
|
||||||
world:
|
|
||||||
description: Used when using range chat!
|
|
||||||
aliases: [w, wo, uw]
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user