This commit is contained in:
disclearing 2019-02-18 20:12:14 +00:00
parent babceff944
commit 8e8870043d
388 changed files with 10325 additions and 1 deletions

1
.idea/.name Normal file
View File

@ -0,0 +1 @@
Zoot-1.0-SNAPSHOT

View File

@ -0,0 +1,17 @@
<component name="ArtifactManager">
<artifact type="jar" name="zoot:jar">
<output-path>$PROJECT_DIR$/out/artifacts/zoot_jar</output-path>
<root id="archive" name="zoot.jar">
<element id="module-output" name="zoot" />
<element id="extracted-dir" path="$PROJECT_DIR$/libs/honcho-1.0-SNAPSHOT.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/apache/commons/commons-pool2/2.4.2/commons-pool2-2.4.2.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/mongodb/mongo-java-driver/3.8.2/mongo-java-driver-3.8.2.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/lombok-1.18.6.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/lib/VaultAPI-1.7.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/libs/PermissionsEx-1.23.4.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/google/code/gson/gson/2.8.5/gson-2.8.5.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/redis/clients/jedis/2.9.0/jedis-2.9.0.jar" path-in-jar="/" />
<element id="extracted-dir" path="$PROJECT_DIR$/libs/phoenix-lang-1.0-SNAPSHOT.jar" path-in-jar="/" />
</root>
</artifact>
</component>

36
.idea/compiler.xml Normal file
View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile default="true" name="Default" enabled="true" />
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="Proton" />
<module name="proton" />
<module name="zoot" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="api" target="1.8" />
<module name="bootstrap" target="1.8" />
<module name="chat" target="1.8" />
<module name="game" target="1.8" />
<module name="messaging" target="1.8" />
<module name="Proton" target="1.8" />
<module name="proton" target="1.8" />
<module name="proxy" target="1.8" />
<module name="punishments" target="1.8" />
<module name="ranks" target="1.8" />
<module name="zoot" target="1.8" />
<module name="Zoot-1.0-SNAPSHOT" target="1.8" />
</bytecodeTargetLevel>
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="Zoot-1.0-SNAPSHOT" options="-parameters" />
<module name="zoot" options="-parameters" />
</option>
</component>
</project>

View File

@ -0,0 +1,35 @@
<component name="ProjectDictionaryState">
<dictionary name="skruf">
<words>
<w>addperm</w>
<w>addpermission</w>
<w>clearinv</w>
<w>deletepermission</w>
<w>delperm</w>
<w>deserialized</w>
<w>gamemode</w>
<w>gson</w>
<w>hideplayer</w>
<w>listpermissions</w>
<w>listperms</w>
<w>mojang</w>
<w>setcolor</w>
<w>setmaxslots</w>
<w>setprefix</w>
<w>setslots</w>
<w>setspawn</w>
<w>setsuffix</w>
<w>setweight</w>
<w>setworldspawn</w>
<w>showplayer</w>
<w>teleported</w>
<w>unblacklisted</w>
<w>uninherit</w>
<w>uninherited</w>
<w>unmuted</w>
<w>uuids</w>
<w>worldspawn</w>
<w>zoot</w>
</words>
</dictionary>
</component>

13
.idea/encodings.xml Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/api" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/bootstrap" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/chat" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/game" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/messaging" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/punishments" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/ranks" charset="UTF-8" />
</component>
</project>

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: com.google.code.gson:gson:2.8.5">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/google/code/gson/gson/2.8.5/gson-2.8.5.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/google/code/gson/gson/2.8.5/gson-2.8.5-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/google/code/gson/gson/2.8.5/gson-2.8.5-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.apache.commons:commons-pool2:2.4.2">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/commons/commons-pool2/2.4.2/commons-pool2-2.4.2.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/commons/commons-pool2/2.4.2/commons-pool2-2.4.2-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/commons/commons-pool2/2.4.2/commons-pool2-2.4.2-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.mongodb:mongo-java-driver:3.8.2">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/mongodb/mongo-java-driver/3.8.2/mongo-java-driver-3.8.2.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/mongodb/mongo-java-driver/3.8.2/mongo-java-driver-3.8.2-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/mongodb/mongo-java-driver/3.8.2/mongo-java-driver-3.8.2-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: redis.clients:jedis:2.9.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/redis/clients/jedis/2.9.0/jedis-2.9.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/redis/clients/jedis/2.9.0/jedis-2.9.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/redis/clients/jedis/2.9.0/jedis-2.9.0-sources.jar!/" />
</SOURCES>
</library>
</component>

18
.idea/misc.xml Normal file
View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
<option name="ignoredFiles">
<set>
<option value="$PROJECT_DIR$/proxy/pom.xml" />
</set>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/zoot.iml" filepath="$PROJECT_DIR$/zoot.iml" />
</modules>
</component>
</project>

124
.idea/uiDesigner.xml Normal file
View File

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

1050
.idea/workspace.xml Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1 +1,31 @@
# zoot zoot.admin.broadcast
zoot.staff.clearinv
zoot.staff.gamemode
zoot.admin.heal
zoot.admin.hideplayer
zoot.staff.more
zoot.staff.rename
zoot.staff.setslots
zoot.staff.setspawn
zoot.admin.showplayer
zoot.staff.spawn
zoot.staff.alts
zoot.staff.ban
zoot.staff.check
zoot.staff.kick
zoot.staff.mute
zoot.staff.unban
zoot.staff.unmute
zoot.staff.warn
zoot.staff.grant
zoot.staff.grant
zoot.staff
zoot.staff
zoot.staff.mutechat
zoot.admin.rank
zoot.admin.rank
zoot.admin.rank
zoot.admin.rank
zoot.admin.rank
zoot.admin.rank
zoot.admin.rank

71
Zoot-1.0-SNAPSHOT.iml Normal file
View File

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="Maven: org.spigotmc:spigot-api:1.8.8-R0.1-SNAPSHOT">
<CLASSES>
<root url="jar://$MODULE_DIR$/libs/ragespigot-1.8.8-R0.1-SNAPSHOT.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.18.4" level="project" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.5" level="project" />
<orderEntry type="library" name="Maven: org.mongodb:mongo-java-driver:3.8.2" level="project" />
<orderEntry type="module-library">
<library name="Maven: com.qrakn:honcho:1.0-SNAPSHOT">
<CLASSES>
<root url="jar://$MODULE_DIR$/libs/honcho-1.0-SNAPSHOT.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Maven: com.qrakn:phoenix-lang:1.0-SNAPSHOT">
<CLASSES>
<root url="jar://$MODULE_DIR$/libs/phoenix-lang-1.0-SNAPSHOT.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Maven: com.minexd:pidgin:1.0-SNAPSHOT">
<CLASSES>
<root url="jar://$MODULE_DIR$/libs/pidgin-1.0-SNAPSHOT.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Maven: ru.tehkode:PermissionsEx:1.0-SNAPSHOT">
<CLASSES>
<root url="jar://$MODULE_DIR$/libs/PermissionsEx-1.23.4.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" scope="PROVIDED" name="Maven: net.milkbowl.vault:VaultAPI:1.7" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:bukkit:1.13.1-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-lang:commons-lang:2.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: junit:junit:4.10" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:21.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.21" level="project" />
</component>
</module>

View File

@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.minexd</groupId>
<artifactId>zoot</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
<includes>
<include>plugin.yml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>plugin.yml</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgument>-parameters</compilerArgument>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/solexspigot-1.8.8-R0.1-SNAPSHOT.jar</systemPath>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>LATEST</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/lombok-1.18.6.jar</systemPath>
</dependency>
<dependency>
<groupId>com.qrakn</groupId>
<artifactId>honcho</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/honcho-1.0-SNAPSHOT.jar</systemPath>
</dependency>
<dependency>
<groupId>com.qrakn</groupId>
<artifactId>phoenix</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/phoenix-lang-1.0-SNAPSHOT.jar</systemPath>
</dependency>
<dependency>
<groupId>ru.tehkode</groupId>
<artifactId>PermissionsEx</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/PermissionsEx-1.23.4.jar</systemPath>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/VaultAPI-1.7.jar</systemPath>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

Binary file not shown.

BIN
lib/VaultAPI-1.7.jar Normal file

Binary file not shown.

BIN
lib/honcho-1.0-SNAPSHOT.jar Normal file

Binary file not shown.

BIN
lib/lombok-1.18.6.jar Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

122
pom.xml Normal file
View File

@ -0,0 +1,122 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.minexd</groupId>
<artifactId>zoot</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgument>-parameters</compilerArgument>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>plugin.yml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>plugin.yml</exclude>
</excludes>
</resource>
</resources>
</build>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/solexspigot-1.8.8-R0.1-SNAPSHOT.jar</systemPath>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>LATEST</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/lombok-1.18.6.jar</systemPath>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>LATEST</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.8.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.qrakn</groupId>
<artifactId>honcho</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/honcho-1.0-SNAPSHOT.jar</systemPath>
</dependency>
<dependency>
<groupId>com.qrakn</groupId>
<artifactId>phoenix</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/phoenix-lang-1.0-SNAPSHOT.jar</systemPath>
</dependency>
<dependency>
<groupId>ru.tehkode</groupId>
<artifactId>PermissionsEx</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/PermissionsEx-1.23.4.jar</systemPath>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/VaultAPI-1.7.jar</systemPath>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,53 @@
package com.minexd.zoot;
import java.text.MessageFormat;
import lombok.AllArgsConstructor;
import org.bukkit.ChatColor;
@AllArgsConstructor
public enum Locale {
FAILED_TO_LOAD_PROFILE("COMMON_ERRORS.FAILED_TO_LOAD_PROFILE"),
COULD_NOT_RESOLVE_PLAYER("COMMON_ERRORS.COULD_NOT_RESOLVE_PLAYER"),
PLAYER_NOT_FOUND("COMMON_ERRORS.PLAYER_NOT_FOUND"),
RANK_NOT_FOUND("COMMON_ERRORS.RANK_NOT_FOUND"),
STAFF_CHAT("STAFF.CHAT"),
STAFF_BROADCAST_PREFIX("STAFF.BROADCAST_PREFIX"),
STAFF_JOIN_NETWORK("STAFF.JOIN_NETWORK"),
STAFF_SWITCH_SERVER("STAFF.SWITCH_SERVER"),
STAFF_LEAVE_NETWORK("STAFF.LEAVE_NETWORK"),
CLEAR_CHAT_BROADCAST("CHAT.CLEAR_CHAT_BROADCAST"),
MUTE_CHAT_BROADCAST("CHAT.MUTE_CHAT_BROADCAST"),
DELAY_CHAT_ENABLED_BROADCAST("CHAT.DELAY_CHAT_ENABLED_BROADCAST"),
DELAY_CHAT_DISABLED_BROADCAST("CHAT.DELAY_CHAT_DISABLED_BROADCAST"),
CHAT_DELAYED("CHAT.CHAT_DELAYED"),
NETWORK_BROADCAST_PREFIX("NETWORK.BROADCAST_PREFIX"),
NETWORK_RANK_REFRESHED("NETWORK.RANK_REFRESH"),
NETWORK_RANK_DELETED("NETWORK.RANK_DELETE"),
CONVERSATION_SEND_MESSAGE("CONVERSATION.SEND_MESSAGE"),
CONVERSATION_RECEIVE_MESSAGE("CONVERSATION.RECEIVE_MESSAGE"),
OPTIONS_PRIVATE_MESSAGES_ENABLED("OPTIONS.PRIVATE_MESSAGES_ENABLED"),
OPTIONS_PRIVATE_MESSAGES_DISABLED("OPTIONS.PRIVATE_MESSAGES_DISABLED"),
OPTIONS_PRIVATE_MESSAGE_SOUND_ENABLED("OPTIONS.PRIVATE_MESSAGE_SOUNDS_ENABLED"),
OPTIONS_PRIVATE_MESSAGE_SOUND_DISABLED("OPTIONS.PRIVATE_MESSAGE_SOUNDS_DISABLED"),
OPTIONS_GLOBAL_CHAT_ENABLED("OPTIONS.GLOBAL_CHAT_ENABLED"),
OPTIONS_GLOBAL_CHAT_DISABLED("OPTIONS.GLOBAL_CHAT_DISABLED");
private String path;
public String format(Object... objects) {
return new MessageFormat(ChatColor.translateAlternateColorCodes('&',
Zoot.get().getMainConfig().getString(path))).format(objects);
}
// public static final String PUBLIC_CHAT_MUTE_APPLIED = "&bThe public chat has been muted by {actor}";
// public static final String PUBLIC_CHAT_DELAY_APPLIED = "&bThe public chat has been delayed by {actor}";
// public static final String CHAT_ATTEMPT_FILTERED = "&cYour message was filtered.";
// public static final String CHAT_ATTEMPT_PLAYER_MUTED = "&cYou are currently muted for another {time-remaining}.";
// public static final String CHAT_ATTEMPT_PUBLIC_CHAT_MUTED = "&cThe public chat is currently muted.";
// public static final String CHAT_ATTEMPT_PUBLIC_CHAT_DELAYED = "&cYou may chat again in {time-remaining}.";
// public static final String OPTIONS_GLOBAL_CHAT_DISABLED = "&cYou have your public chat disabled.";
// public static final String OPTIONS_PRIVATE_CHAT_DISABLED = "&cYou have your private messages disabled.";
// public static final String PTIONS_PRIVATE_CHAT_DISABLED_OTHER = "&cThat player has their private messages disabled.";
}

View File

@ -0,0 +1,316 @@
package com.minexd.zoot;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.minexd.zoot.chat.Chat;
import com.minexd.zoot.chat.command.ClearChatCommand;
import com.minexd.zoot.chat.command.MuteChatCommand;
import com.minexd.zoot.chat.ChatListener;
import com.minexd.zoot.chat.command.SlowChatCommand;
import com.minexd.zoot.config.ConfigValidation;
import com.minexd.zoot.essentials.Essentials;
import com.minexd.zoot.essentials.command.*;
import com.minexd.zoot.essentials.EssentialsListener;
import com.minexd.zoot.network.NetworkPacketListener;
import com.minexd.zoot.network.packet.PacketAddGrant;
import com.minexd.zoot.network.packet.PacketBroadcastPunishment;
import com.minexd.zoot.network.packet.PacketDeleteGrant;
import com.minexd.zoot.network.packet.PacketDeleteRank;
import com.minexd.zoot.network.packet.PacketRefreshRank;
import com.minexd.zoot.network.packet.PacketStaffChat;
import com.minexd.zoot.network.packet.PacketStaffJoinNetwork;
import com.minexd.zoot.network.packet.PacketStaffLeaveNetwork;
import com.minexd.zoot.network.packet.PacketStaffSwitchServer;
import com.minexd.zoot.pidgin.Pidgin;
import com.minexd.zoot.profile.Profile;
import com.minexd.zoot.profile.ProfileTypeAdapter;
import com.minexd.zoot.profile.option.command.OptionsCommand;
import com.minexd.zoot.profile.conversation.command.MessageCommand;
import com.minexd.zoot.profile.conversation.command.ReplyCommand;
import com.minexd.zoot.profile.grant.command.GrantCommand;
import com.minexd.zoot.profile.grant.command.GrantsCommand;
import com.minexd.zoot.profile.grant.GrantListener;
import com.minexd.zoot.profile.ProfileListener;
import com.minexd.zoot.profile.option.command.ToggleGlobalChatCommand;
import com.minexd.zoot.profile.option.command.TogglePrivateMessagesCommand;
import com.minexd.zoot.profile.option.command.ToggleSoundsCommand;
import com.minexd.zoot.profile.punishment.command.BanCommand;
import com.minexd.zoot.profile.punishment.command.CheckCommand;
import com.minexd.zoot.profile.punishment.command.KickCommand;
import com.minexd.zoot.profile.punishment.command.MuteCommand;
import com.minexd.zoot.profile.punishment.command.UnbanCommand;
import com.minexd.zoot.profile.punishment.command.UnmuteCommand;
import com.minexd.zoot.profile.punishment.command.WarnCommand;
import com.minexd.zoot.profile.staff.command.AltsCommand;
import com.minexd.zoot.profile.punishment.listener.PunishmentListener;
import com.minexd.zoot.profile.staff.command.StaffModeCommand;
import com.minexd.zoot.rank.Rank;
import com.minexd.zoot.rank.RankTypeAdapter;
import com.minexd.zoot.profile.staff.command.StaffChatCommand;
import com.minexd.zoot.rank.command.RankAddPermissionCommand;
import com.minexd.zoot.rank.command.RankCreateCommand;
import com.minexd.zoot.rank.command.RankDeleteCommand;
import com.minexd.zoot.rank.command.RankHelpCommand;
import com.minexd.zoot.rank.command.RankInfoCommand;
import com.minexd.zoot.rank.command.RankInheritCommand;
import com.minexd.zoot.rank.command.RankRemovePermissionCommand;
import com.minexd.zoot.rank.command.RankSetColorCommand;
import com.minexd.zoot.rank.command.RankSetPrefixCommand;
import com.minexd.zoot.rank.command.RankSetSuffixCommand;
import com.minexd.zoot.rank.command.RankSetWeightCommand;
import com.minexd.zoot.rank.command.RankUninheritCommand;
import com.minexd.zoot.rank.command.RanksCommand;
import com.minexd.zoot.util.CC;
import com.minexd.zoot.util.adapter.ChatColorTypeAdapter;
import com.minexd.zoot.util.duration.Duration;
import com.minexd.zoot.util.duration.DurationTypeAdapter;
import com.minexd.zoot.util.menu.MenuListener;
import com.minexd.zoot.cache.RedisCache;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
import com.mongodb.client.MongoDatabase;
import com.qrakn.honcho.Honcho;
import com.qrakn.phoenix.lang.file.type.BasicConfigurationFile;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
public class Zoot extends JavaPlugin {
public static final Gson GSON = new Gson();
public static final Type LIST_STRING_TYPE = new TypeToken<List<String>>() {}.getType();
private static Zoot zoot;
@Getter private BasicConfigurationFile mainConfig;
@Getter private Honcho honcho;
@Getter private Pidgin pidgin;
@Getter private MongoDatabase mongoDatabase;
@Getter private JedisPool jedisPool;
@Getter private RedisCache redisCache;
@Getter private Essentials essentials;
@Getter private Chat chat;
@Getter @Setter private boolean debug;
@Override
public void onEnable() {
zoot = this;
mainConfig = new BasicConfigurationFile(this, "config");
new ConfigValidation(mainConfig.getFile(), mainConfig.getConfiguration(), 3).check();
loadMongo();
loadRedis();
redisCache = new RedisCache(this);
essentials = new Essentials(this);
chat = new Chat(this);
honcho = new Honcho(this);
Arrays.asList(
new BroadcastCommand(),
new ClearCommand(),
new DayCommand(),
new GameModeCommand(),
new HealCommand(),
new HidePlayerCommand(),
new LocationCommand(),
new MoreCommand(),
new NightCommand(),
new RenameCommand(),
new SetSlotsCommand(),
new SetSpawnCommand(),
new ShowPlayerCommand(),
new SpawnCommand(),
new SunsetCommand(),
new ClearChatCommand(),
new SlowChatCommand(),
new AltsCommand(),
new BanCommand(),
new CheckCommand(),
new KickCommand(),
new MuteCommand(),
new UnbanCommand(),
new UnmuteCommand(),
new WarnCommand(),
new GrantCommand(),
new GrantsCommand(),
new StaffChatCommand(),
new StaffModeCommand(),
new MuteChatCommand(),
new OptionsCommand(),
new RankAddPermissionCommand(),
new RankCreateCommand(),
new RankDeleteCommand(),
new RankHelpCommand(),
new RankInfoCommand(),
new RankInheritCommand(),
new RankRemovePermissionCommand(),
new RanksCommand(),
new RankSetColorCommand(),
new RankSetPrefixCommand(),
new RankSetSuffixCommand(),
new RankSetWeightCommand(),
new RankUninheritCommand(),
new ZootDebugCommand(),
new TeleportWorldCommand(),
new MessageCommand(),
new ReplyCommand(),
new ToggleGlobalChatCommand(),
new TogglePrivateMessagesCommand(),
new ToggleSoundsCommand(),
new PingCommand(),
new ListCommand()
).forEach(honcho::registerCommand);
honcho.registerTypeAdapter(Rank.class, new RankTypeAdapter());
honcho.registerTypeAdapter(Profile.class, new ProfileTypeAdapter());
honcho.registerTypeAdapter(Duration.class, new DurationTypeAdapter());
honcho.registerTypeAdapter(ChatColor.class, new ChatColorTypeAdapter());
pidgin = new Pidgin("zoot",
mainConfig.getString("REDIS.HOST"),
mainConfig.getInteger("REDIS.PORT"),
mainConfig.getBoolean("REDIS.AUTHENTICATION.ENABLED") ?
mainConfig.getString("REDIS.AUTHENTICATION.PASSWORD") : null
);
Arrays.asList(
PacketAddGrant.class,
PacketBroadcastPunishment.class,
PacketDeleteGrant.class,
PacketDeleteRank.class,
PacketRefreshRank.class,
PacketStaffChat.class,
PacketStaffJoinNetwork.class,
PacketStaffLeaveNetwork.class,
PacketStaffSwitchServer.class
).forEach(pidgin::registerPacket);
pidgin.registerListener(new NetworkPacketListener(this));
Arrays.asList(
new ProfileListener(this),
new MenuListener(this),
new EssentialsListener(this),
new ChatListener(this),
new GrantListener(this),
new PunishmentListener(this)
).forEach(listener -> getServer().getPluginManager().registerEvents(listener, this));
Rank.init();
Profile.init();
new BukkitRunnable() {
@Override
public void run() {
for (Profile profile : Profile.getProfiles().values()) {
profile.checkGrants();
}
}
}.runTaskTimerAsynchronously(this, 20L, 20L);
}
@Override
public void onDisable() {
try {
jedisPool.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Prints a message and exception to console. If the server is not in debug mode, the messages will be suppressed.
*
* @param level The log level.
* @param message The message.
* @param exception The thrown exception.
*/
public void debug(Level level, String message, Exception exception) {
getLogger().log(level, message);
exception.printStackTrace();
}
/**
* Prints a message to console and server operators.
*
* @param message The message.
*/
public void debug(String message) {
if (debug) {
broadcastOps(CC.translate("&e(Debug) &r" + message));
}
}
/**
* Prints a message triggered by an action a player performed to console and server operators.
*
* @param player The player that triggered this log.
* @param message The message.
*/
public void debug(Player player, String message) {
if (debug) {
broadcastOps(CC.translate("&e(Debug) &r" + player.getDisplayName() + ": " + message));
}
}
/**
* Broadcasts a message to all server operators.
*
* @param message The message.
*/
public static void broadcastOps(String message) {
Bukkit.getOnlinePlayers().stream().filter(Player::isOp).forEach(op -> op.sendMessage(message));
}
private void loadMongo() {
if (mainConfig.getBoolean("MONGO.AUTHENTICATION.ENABLED")) {
ServerAddress serverAddress = new ServerAddress(mainConfig.getString("MONGO.HOST"),
mainConfig.getInteger("MONGO.PORT"));
MongoCredential credential = MongoCredential.createCredential(
mainConfig.getString("MONGO.AUTHENTICATION.USERNAME"), "admin",
mainConfig.getString("MONGO.AUTHENTICATION.PASSWORD").toCharArray());
mongoDatabase = new MongoClient(serverAddress, credential, MongoClientOptions.builder().build())
.getDatabase("zoot");
} else {
mongoDatabase = new MongoClient(mainConfig.getString("MONGO.HOST"),
mainConfig.getInteger("MONGO.PORT")).getDatabase("zoot");
}
}
private void loadRedis() {
jedisPool = new JedisPool(mainConfig.getString("REDIS.HOST"), mainConfig.getInteger("REDIS.PORT"));
if (mainConfig.getBoolean("REDIS.AUTHENTICATION.ENABLED")) {
try (Jedis jedis = jedisPool.getResource()) {
jedis.auth(mainConfig.getString("REDIS.AUTHENTICATION.PASSWORD"));
}
}
}
public static Zoot get() {
return zoot;
}
}

View File

@ -0,0 +1,30 @@
package com.minexd.zoot;
import com.minexd.zoot.profile.Profile;
import com.minexd.zoot.rank.Rank;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
public class ZootAPI {
public static ChatColor getColorOfPlayer(Player player) {
Profile profile = Profile.getProfiles().get(player.getUniqueId());
return profile == null ? ChatColor.WHITE : ChatColor.getByChar(profile.getActiveRank().getColor());
}
public static String getColoredName(Player player) {
Profile profile = Profile.getProfiles().get(player.getUniqueId());
return (profile == null ? ChatColor.WHITE : profile.getActiveRank().getColor()) + player.getName();
}
public static Rank getRankOfPlayer(Player player) {
Profile profile = Profile.getProfiles().get(player.getUniqueId());
return profile == null ? Rank.getDefaultRank() : profile.getActiveRank();
}
public static boolean isInStaffMode(Player player) {
Profile profile = Profile.getProfiles().get(player.getUniqueId());
return profile != null && player.hasPermission("zoot.staff") && profile.getStaffOptions().staffModeEnabled();
}
}

View File

@ -0,0 +1,15 @@
package com.minexd.zoot.bootstrap;
import com.minexd.zoot.Zoot;
import lombok.Getter;
@Getter
public class Bootstrapped {
protected final Zoot zoot;
public Bootstrapped(Zoot zoot) {
this.zoot = zoot;
}
}

View File

@ -0,0 +1,12 @@
package com.minexd.zoot.bootstrap;
import com.minexd.zoot.Zoot;
import org.bukkit.event.Listener;
public class BootstrappedListener extends Bootstrapped implements Listener {
public BootstrappedListener(Zoot zoot) {
super(zoot);
}
}

View File

@ -0,0 +1,114 @@
package com.minexd.zoot.cache;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.minexd.zoot.Zoot;
import com.minexd.zoot.bootstrap.Bootstrapped;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.UUID;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.json.simple.parser.ParseException;
import redis.clients.jedis.Jedis;
public class RedisCache extends Bootstrapped {
public RedisCache(Zoot zoot) {
super(zoot);
}
public UUID getUuid(String name) {
if (zoot.getServer().isPrimaryThread()) {
throw new IllegalStateException("Cannot query on main thread (Redis profile cache)");
}
try (Jedis jedis = zoot.getJedisPool().getResource()) {
String uuid = jedis.hget("uuid-cache:name-to-uuid", name.toLowerCase());
if (uuid != null) {
return UUID.fromString(uuid);
}
} catch (Exception e) {
zoot.debug(Level.WARNING, "Could not connect to redis", e);
}
try {
UUID uuid = getFromMojang(name);
if (uuid != null) {
updateNameAndUUID(name, uuid);
return uuid;
}
} catch (Exception e) {
zoot.debug(Level.WARNING, "Could not fetch from Mojang API", e);
}
return null;
}
public void updateNameAndUUID(String name, UUID uuid) {
if (Bukkit.isPrimaryThread()) {
throw new IllegalStateException("Cannot query redis on main thread!");
}
try (Jedis jedis = zoot.getJedisPool().getResource()) {
jedis.hset("uuid-cache:name-to-uuid", name.toLowerCase(), uuid.toString());
jedis.hset("uuid-cache:uuid-to-name", uuid.toString(), name);
}
}
public RedisPlayerData getPlayerData(UUID uuid) {
if (Bukkit.isPrimaryThread()) {
throw new IllegalStateException("Cannot query redis on main thread!");
}
try (Jedis jedis = zoot.getJedisPool().getResource()) {
String data = jedis.hget("player-data", uuid.toString());
if (data == null) {
return null;
}
try {
JsonObject dataJson = new JsonParser().parse(data).getAsJsonObject();
return new RedisPlayerData(dataJson);
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
public void updatePlayerData(RedisPlayerData playerData) {
try (Jedis jedis = zoot.getJedisPool().getResource()) {
jedis.hset("player-data", playerData.getUuid().toString(), playerData.getJson().toString());
}
}
private static UUID getFromMojang(String name) throws IOException, ParseException {
URL url = new URL("https://api.mojang.com/users/profiles/minecraft/" + name);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line = reader.readLine();
if (line == null) {
return null;
}
String[] id = line.split(",");
String part = id[0];
part = part.substring(7, 39);
return UUID.fromString(String.valueOf(part).replaceAll("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})",
"$1-$2-$3-$4-$5"));
}
}

View File

@ -0,0 +1,50 @@
package com.minexd.zoot.cache;
import com.google.gson.JsonObject;
import com.minexd.zoot.util.TimeUtil;
import com.minexd.zoot.util.json.JsonChain;
import java.util.UUID;
import lombok.Data;
@Data
public class RedisPlayerData {
private UUID uuid;
private String username;
private LastAction lastAction;
private String lastSeenServer;
private long lastSeenAt;
public RedisPlayerData(JsonObject object) {
this.uuid = UUID.fromString(object.get("uuid").getAsString());
this.username = object.get("username").getAsString();
this.lastAction = LastAction.valueOf(object.get("lastAction").getAsString());
this.lastSeenServer = object.get("lastSeenServer").getAsString();
this.lastSeenAt = object.get("lastSeenAt").getAsLong();
}
public RedisPlayerData(UUID uuid, String username) {
this.uuid = uuid;
this.username = username;
}
public JsonObject getJson() {
return new JsonChain()
.addProperty("uuid", uuid.toString())
.addProperty("username", username)
.addProperty("lastAction", lastAction.name())
.addProperty("lastSeenServer", lastSeenServer)
.addProperty("lastSeenAt", lastSeenAt)
.get();
}
public String getTimeAgo() {
return TimeUtil.millisToRoundedTime(System.currentTimeMillis() - lastSeenAt) + " ago";
}
public enum LastAction {
LEAVING_SERVER,
JOINING_SERVER
}
}

View File

@ -0,0 +1,80 @@
package com.minexd.zoot.chat;
import com.minexd.zoot.Zoot;
import com.minexd.zoot.bootstrap.Bootstrapped;
import com.minexd.zoot.chat.filter.ChatFilter;
import com.minexd.zoot.profile.Profile;
import com.minexd.zoot.profile.punishment.PunishmentType;
import java.util.ArrayList;
import java.util.List;
import com.minexd.zoot.util.Cooldown;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.entity.Player;
public class Chat extends Bootstrapped {
public Chat(Zoot zoot) {
super(zoot);
}
@Getter @Setter private int delayTime = 3;
@Getter private boolean publicChatMuted = false;
@Getter private boolean publicChatDelayed = false;
@Getter private final List<ChatFilter> filters = new ArrayList<>();
@Getter private List<String> filteredPhrases = new ArrayList<>();
@Getter private List<String> linkWhitelist = new ArrayList<>();
public void togglePublicChatMute() {
publicChatMuted = !publicChatMuted;
}
public void togglePublicChatDelay() {
publicChatDelayed = !publicChatDelayed;
}
public ChatAttempt attemptChatMessage(Player player, String message) {
Profile profile = Profile.getProfiles().get(player.getUniqueId());
if (profile.getActivePunishmentByType(PunishmentType.MUTE) != null) {
return new ChatAttempt(ChatAttempt.Response.PLAYER_MUTED, profile.getActivePunishmentByType(PunishmentType.MUTE));
}
if (publicChatMuted && !player.hasPermission("zoot.staff")) {
return new ChatAttempt(ChatAttempt.Response.CHAT_MUTED);
}
if (publicChatDelayed && !profile.getChatCooldown().hasExpired() && !player.hasPermission("zoot.staff")) {
ChatAttempt attempt = new ChatAttempt(ChatAttempt.Response.CHAT_DELAYED);
attempt.setValue(profile.getChatCooldown().getRemaining());
return attempt;
}
String msg = message.toLowerCase()
.replace("3", "e")
.replace("1", "i")
.replace("!", "i")
.replace("@", "a")
.replace("7", "t")
.replace("0", "o")
.replace("5", "s")
.replace("8", "b")
.replaceAll("\\p{Punct}|\\d", "").trim();
String[] words = msg.trim().split(" ");
for (ChatFilter chatFilter : filters) {
if (chatFilter.isFiltered(msg, words)) {
return new ChatAttempt(ChatAttempt.Response.MESSAGE_FILTERED);
}
}
if (publicChatDelayed) {
profile.setChatCooldown(new Cooldown(delayTime * 1000L));
}
return new ChatAttempt(ChatAttempt.Response.ALLOWED);
}
}

View File

@ -0,0 +1,39 @@
package com.minexd.zoot.chat;
import com.minexd.zoot.chat.filter.ChatFilter;
import com.minexd.zoot.profile.punishment.Punishment;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class ChatAttempt {
private Response response;
private ChatFilter filterFlagged;
private Punishment punishment;
private Object value;
public ChatAttempt(Response response) {
this.response = response;
}
public ChatAttempt(Response response, ChatFilter filterFlagged) {
this.response = response;
this.filterFlagged = filterFlagged;
}
public ChatAttempt(Response response, Punishment punishment) {
this.response = response;
this.punishment = punishment;
}
public enum Response {
ALLOWED,
MESSAGE_FILTERED,
PLAYER_MUTED,
CHAT_MUTED,
CHAT_DELAYED
}
}

View File

@ -0,0 +1,63 @@
package com.minexd.zoot.chat;
import com.minexd.zoot.Locale;
import com.minexd.zoot.Zoot;
import com.minexd.zoot.bootstrap.BootstrappedListener;
import com.minexd.zoot.chat.event.ChatAttemptEvent;
import com.minexd.zoot.util.CC;
import com.minexd.zoot.util.TimeUtil;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.AsyncPlayerChatEvent;
public class ChatListener extends BootstrappedListener {
public ChatListener(Zoot zoot) {
super(zoot);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent event) {
ChatAttempt chatAttempt = zoot.getChat().attemptChatMessage(event.getPlayer(), event.getMessage());
ChatAttemptEvent chatAttemptEvent = new ChatAttemptEvent(event.getPlayer(), chatAttempt, event.getMessage());
zoot.getServer().getPluginManager().callEvent(chatAttemptEvent);
if (!chatAttemptEvent.isCancelled()) {
switch (chatAttempt.getResponse()) {
case ALLOWED: {
event.setFormat("%1$s" + CC.RESET + ": %2$s");
}
break;
case MESSAGE_FILTERED: {
event.setCancelled(true);
chatAttempt.getFilterFlagged().punish(event.getPlayer());
}
break;
case PLAYER_MUTED: {
event.setCancelled(true);
if (chatAttempt.getPunishment().isPermanent()) {
event.getPlayer().sendMessage(CC.RED + "You are muted for forever.");
} else {
event.getPlayer().sendMessage(CC.RED + "You are muted for another " +
chatAttempt.getPunishment().getTimeRemaining() + ".");
}
}
break;
case CHAT_MUTED: {
event.setCancelled(true);
event.getPlayer().sendMessage(CC.RED + "The public chat is currently muted.");
}
break;
case CHAT_DELAYED: {
event.setCancelled(true);
event.getPlayer().sendMessage(Locale.CHAT_DELAYED.format(
TimeUtil.millisToSeconds((int) chatAttempt.getValue())) + " seconds");
}
break;
}
}
}
}

View File

@ -0,0 +1,40 @@
package com.minexd.zoot.chat.command;
import com.minexd.zoot.Locale;
import com.minexd.zoot.Zoot;
import com.minexd.zoot.profile.Profile;
import com.qrakn.honcho.command.CommandMeta;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandMeta(label = { "clearchat", "cc" }, permission = "zoot.staff.clearchat")
public class ClearChatCommand {
public void execute(CommandSender sender) {
String[] strings = new String[101];
for (Player player : Bukkit.getOnlinePlayers()) {
if (player.hasPermission("zoot.staff")) {
if (Zoot.get().getMainConfig().getBoolean("CHAT.CLEAR_CHAT_FOR_STAFF")) {
player.sendMessage(strings);
}
} else {
player.sendMessage(strings);
}
}
String senderName;
if (sender instanceof Player) {
Profile profile = Profile.getProfiles().get(((Player) sender).getUniqueId());
senderName = profile.getActiveRank().getColor() + sender.getName();
} else {
senderName = ChatColor.DARK_RED + "Console";
}
Bukkit.broadcastMessage(Locale.CLEAR_CHAT_BROADCAST.format(senderName));
}
}

View File

@ -0,0 +1,32 @@
package com.minexd.zoot.chat.command;
import com.minexd.zoot.Locale;
import com.minexd.zoot.Zoot;
import com.minexd.zoot.profile.Profile;
import com.qrakn.honcho.command.CommandMeta;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandMeta(label = "mutechat", permission = "zoot.staff.mutechat")
public class MuteChatCommand {
public void execute(CommandSender sender) {
Zoot.get().getChat().togglePublicChatMute();
String senderName;
if (sender instanceof Player) {
Profile profile = Profile.getProfiles().get(((Player) sender).getUniqueId());
senderName = profile.getActiveRank().getColor() + sender.getName();
} else {
senderName = ChatColor.DARK_RED + "Console";
}
String context = Zoot.get().getChat().isPublicChatMuted() ? "muted" : "unmuted";
Bukkit.broadcastMessage(Locale.MUTE_CHAT_BROADCAST.format(context, senderName));
}
}

View File

@ -0,0 +1,48 @@
package com.minexd.zoot.chat.command;
import com.minexd.zoot.Locale;
import com.minexd.zoot.Zoot;
import com.minexd.zoot.ZootAPI;
import com.qrakn.honcho.command.CommandMeta;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandMeta(label = "slowchat", permission = "zoot.staff.slowchat")
public class SlowChatCommand {
public void execute(CommandSender sender) {
Zoot.get().getChat().togglePublicChatDelay();
String senderName;
if (sender instanceof Player) {
senderName = ZootAPI.getColoredName((Player) sender);
} else {
senderName = ChatColor.DARK_RED + "Console";
}
String context = Zoot.get().getChat().getDelayTime() == 1 ? "" : "s";
if (Zoot.get().getChat().isPublicChatDelayed()) {
Bukkit.broadcastMessage(Locale.DELAY_CHAT_ENABLED_BROADCAST.format(senderName,
Zoot.get().getChat().getDelayTime(), context));
} else {
Bukkit.broadcastMessage(Locale.DELAY_CHAT_DISABLED_BROADCAST.format(senderName));
}
}
public void execute(CommandSender sender, Integer seconds) {
if (seconds < 0 || seconds > 60) {
sender.sendMessage(ChatColor.RED + "A delay can only be between 1-60 seconds.");
return;
}
String context = seconds == 1 ? "" : "s";
sender.sendMessage(ChatColor.GREEN + "You have updated the chat delay to " + seconds + " second" + context + ".");
Zoot.get().getChat().setDelayTime(seconds);
}
}

View File

@ -0,0 +1,25 @@
package com.minexd.zoot.chat.event;
import com.minexd.zoot.chat.ChatAttempt;
import com.minexd.zoot.util.BaseEvent;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
@Getter
public class ChatAttemptEvent extends BaseEvent implements Cancellable {
private final Player player;
private final ChatAttempt chatAttempt;
@Setter private String chatMessage;
@Setter private boolean cancelled;
@Setter private String cancelReason = "";
public ChatAttemptEvent(Player player, ChatAttempt chatAttempt, String chatMessage) {
this.player = player;
this.chatAttempt = chatAttempt;
this.chatMessage = chatMessage;
}
}

View File

@ -0,0 +1,27 @@
package com.minexd.zoot.chat.filter;
import com.minexd.zoot.Zoot;
import com.minexd.zoot.bootstrap.Bootstrapped;
import org.bukkit.entity.Player;
public abstract class ChatFilter extends Bootstrapped {
private String command;
public ChatFilter(Zoot zoot, String command) {
super(zoot);
this.command = command;
}
public abstract boolean isFiltered(String message, String[] words);
public void punish(Player player) {
if (command != null) {
zoot.getServer().dispatchCommand(zoot.getServer().getConsoleSender(), command
.replace("{player}", player.getName())
.replace("{player-uuid}", player.getUniqueId().toString()));
}
}
}

View File

@ -0,0 +1,30 @@
package com.minexd.zoot.chat.filter.impl;
import com.minexd.zoot.Zoot;
import com.minexd.zoot.chat.filter.ChatFilter;
public class ContainsFilter extends ChatFilter {
private final String phrase;
public ContainsFilter(Zoot zoot, String phrase) {
this(zoot, phrase, null);
}
public ContainsFilter(Zoot zoot, String phrase, String command) {
super(zoot, command);
this.phrase = phrase;
}
@Override
public boolean isFiltered(String message, String[] words) {
for (String word : words) {
if (word.contains(this.phrase)) {
return true;
}
}
return false;
}
}

View File

@ -0,0 +1,49 @@
package com.minexd.zoot.chat.filter.impl;
import com.minexd.zoot.Zoot;
import com.minexd.zoot.chat.filter.ChatFilter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class LinkFilter extends ChatFilter {
private static final Pattern URL_REGEX = Pattern.compile(
"^(http://www\\.|https://www\\.|http://|https://)?[a-z0-9]+([\\-.][a-z0-9]+)*\\.[a-z]{2,5}(:[0-9]{1,5})?(/.*)?$");
private static final Pattern IP_REGEX = Pattern.compile(
"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])([.,])){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$");
public LinkFilter(Zoot zoot) {
super(zoot, null);
}
@Override
public boolean isFiltered(String message, String[] words) {
for (String word : message.replace("(dot)", ".").replace("[dot]", ".").trim().split(" ")) {
boolean continueIt = false;
for (String phrase : this.zoot.getChat().getLinkWhitelist()) {
if (word.toLowerCase().contains(phrase)) {
continueIt = true;
break;
}
}
if (!continueIt) {
Matcher matcher = IP_REGEX.matcher(word);
if (matcher.matches()) {
return true;
}
matcher = URL_REGEX.matcher(word);
if (matcher.matches()) {
return true;
}
}
}
return false;
}
}

View File

@ -0,0 +1,219 @@
package com.minexd.zoot.chat.util;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
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;
import net.md_5.bungee.api.chat.TextComponent;
public class ChatComponentBuilder extends ComponentBuilder {
private static Field partsField;
private static Field currField;
static {
try {
currField = ComponentBuilder.class.getDeclaredField("current");
partsField = ComponentBuilder.class.getDeclaredField("parts");
currField.setAccessible(true);
partsField.setAccessible(true);
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
}
public ChatComponentBuilder(String text) {
super("");
this.parse(text);
}
public TextComponent getCurrent() {
try {
return (TextComponent) currField.get(this);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
public void setCurrent(TextComponent tc) {
try {
currField.set(this, tc);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
public List getParts() {
try {
return (List) partsField.get(this);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
public ChatComponentBuilder setCurrentHoverEvent(HoverEvent hoverEvent) {
this.getCurrent().setHoverEvent(hoverEvent);
return this;
}
public ChatComponentBuilder setCurrentClickEvent(ClickEvent clickEvent) {
this.getCurrent().setClickEvent(clickEvent);
return this;
}
public ChatComponentBuilder attachToEachPart(HoverEvent hoverEvent) {
for (Object part : getParts()) {
TextComponent component = (TextComponent) part;
if (component.getHoverEvent() == null) {
component.setHoverEvent(hoverEvent);
}
}
this.getCurrent().setHoverEvent(hoverEvent);
return this;
}
public ChatComponentBuilder attachToEachPart(ClickEvent clickEvent) {
for (Object part : getParts()) {
TextComponent component = (TextComponent) part;
if (component.getClickEvent() == null) {
component.setClickEvent(clickEvent);
}
}
this.getCurrent().setClickEvent(clickEvent);
return this;
}
public ChatComponentBuilder parse(String text) {
String regex = "[&§]{1}([a-fA-Fl-oL-O0-9-r]){1}";
text = text.replaceAll(regex, "§$1");
if (!Pattern.compile(regex).matcher(text).find()) {
if (getParts().isEmpty() && getCurrent() != null && getCurrent().getText().isEmpty()) {
getCurrent().setText(text);
} else {
this.append(text);
}
return this;
}
String[] words = text.split(regex);
int index = words[0].length();
for (String word : words) {
try {
if (index != words[0].length()) {
if (getParts().isEmpty() && getCurrent() != null && getCurrent().getText().isEmpty()) {
getCurrent().setText(word);
} else {
this.append(word);
}
ChatColor color = ChatColor.getByChar(text.charAt(index - 1));
if (color == ChatColor.BOLD) {
this.bold(true);
} else if (color == ChatColor.STRIKETHROUGH) {
this.strikethrough(true);
} else if (color == ChatColor.MAGIC) {
this.obfuscated(true);
} else if (color == ChatColor.UNDERLINE) {
this.underlined(true);
} else if (color == ChatColor.RESET) {
this.bold(false);
this.strikethrough(false);
this.obfuscated(false);
this.underlined(false);
} else {
this.color(color);
}
}
} catch (Exception e) {
e.printStackTrace();
}
index += word.length() + 2;
}
return this;
}
public ChatComponentBuilder append(BaseComponent[] components) {
for (BaseComponent component : components) {
append((TextComponent) component);
}
return this;
}
public ChatComponentBuilder append(TextComponent textComponent) {
if (textComponent == null) {
return this;
}
String text = textComponent.getText();
ChatColor color = textComponent.getColor();
boolean bold = textComponent.isBold();
boolean underline = textComponent.isUnderlined();
boolean italic = textComponent.isUnderlined();
boolean strike = textComponent.isStrikethrough();
HoverEvent he = textComponent.getHoverEvent();
ClickEvent ce = textComponent.getClickEvent();
append(text);
color(color);
underlined(underline);
italic(italic);
strikethrough(strike);
event(he);
event(ce);
if (textComponent.getExtra() != null) {
for (BaseComponent bc : textComponent.getExtra()) {
if (bc instanceof TextComponent) {
append((TextComponent) bc);
}
}
}
return this;
}
@Override
public BaseComponent[] create() {
List<TextComponent> components = new ArrayList<>(getParts());
components.add(getCurrent());
TextComponent first = components.get(0);
if (first.getText().isEmpty()) {
components.remove(0);
}
TextComponent last = components.get(components.size() - 1);
if (last.getText().isEmpty()) {
components.remove(components.size() - 1);
}
return components.toArray(new BaseComponent[components.size()]);
}
}

View File

@ -0,0 +1,10 @@
package com.minexd.zoot.config;
import java.io.File;
import org.bukkit.configuration.file.FileConfiguration;
public interface ConfigConversion {
void convert(File file, FileConfiguration fileConfiguration);
}

View File

@ -0,0 +1,36 @@
package com.minexd.zoot.config;
import java.io.File;
import org.bukkit.configuration.file.FileConfiguration;
public class ConfigValidation {
private final File file;
private final FileConfiguration fileConfiguration;
private final int version;
public ConfigValidation(File file, FileConfiguration fileConfiguration, int version) {
this.file = file;
this.fileConfiguration = fileConfiguration;
this.version = version;
}
public void check() {
if (fileConfiguration.contains("CONFIG_VERSION")) {
if (fileConfiguration.getInt("CONFIG_VERSION") != version) {
for (ConfigVersion version : ConfigVersion.values()) {
if (fileConfiguration.getInt("CONFIG_VERSION") < version.getNumber()) {
System.out.println("Converting current configuration into version " + version.name());
version.getConversion().convert(file, fileConfiguration);
}
}
}
} else {
for (ConfigVersion version : ConfigVersion.values()) {
System.out.println("Converting current configuration into version " + version.name());
version.getConversion().convert(file, fileConfiguration);
}
}
}
}

View File

@ -0,0 +1,20 @@
package com.minexd.zoot.config;
import com.minexd.zoot.config.impl.ConfigConversion1;
import com.minexd.zoot.config.impl.ConfigConversion2;
import com.minexd.zoot.config.impl.ConfigConversion3;
import lombok.AllArgsConstructor;
import lombok.Getter;
@AllArgsConstructor
@Getter
public enum ConfigVersion {
VERSION_1(1, new ConfigConversion1()),
VERSION_2(2, new ConfigConversion2()),
VERSION_3(3, new ConfigConversion3());
private int number;
private ConfigConversion conversion;
}

View File

@ -0,0 +1,25 @@
package com.minexd.zoot.config.impl;
import com.minexd.zoot.config.ConfigConversion;
import java.io.File;
import java.io.IOException;
import org.bukkit.configuration.file.FileConfiguration;
public class ConfigConversion1 implements ConfigConversion {
@Override
public void convert(File file, FileConfiguration fileConfiguration) {
fileConfiguration.set("CONFIG_VERSION", 1);
fileConfiguration.set("CHAT.FORMAT", "%1$s&r: %2$s");
fileConfiguration.set("CHAT.CLEAR_CHAT_BROADCAST", "&eThe chat has been cleared by &r{0}");
fileConfiguration.set("CHAT.CLEAR_CHAT_FOR_STAFF", false);
fileConfiguration.set("CHAT.MUTE_CHAT_BROADCAST", "&eThe chat has been {0} by &r{1}");
try {
fileConfiguration.save(file);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,22 @@
package com.minexd.zoot.config.impl;
import com.minexd.zoot.config.ConfigConversion;
import java.io.File;
import java.io.IOException;
import org.bukkit.configuration.file.FileConfiguration;
public class ConfigConversion2 implements ConfigConversion {
@Override
public void convert(File file, FileConfiguration fileConfiguration) {
fileConfiguration.set("CONFIG_VERSION", 2);
fileConfiguration.set("SETTINGS.UPDATE_PLAYER_LIST_NAME", true);
try {
fileConfiguration.save(file);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,30 @@
package com.minexd.zoot.config.impl;
import com.minexd.zoot.config.ConfigConversion;
import org.bukkit.configuration.file.FileConfiguration;
import java.io.File;
import java.io.IOException;
public class ConfigConversion3 implements ConfigConversion {
@Override
public void convert(File file, FileConfiguration fileConfiguration) {
fileConfiguration.set("CONFIG_VERSION", 3);
fileConfiguration.set("CONVERSATION.SEND_MESSAGE", "&7(To &r{5}{3}&7) %MSG%");
fileConfiguration.set("CONVERSATION.RECEIVE_MESSAGE", "&7(From &r{5}{3}&7) %MSG%");
fileConfiguration.set("OPTIONS.GLOBAL_CHAT_ENABLED", "&eYou &aenabled &eglobal chat.");
fileConfiguration.set("OPTIONS.GLOBAL_CHAT_DISABLED", "&eYou &cdisabled &eglobal chat.");
fileConfiguration.set("OPTIONS.PRIVATE_MESSAGES_ENABLED", "&aYou can now receive new conversations.");
fileConfiguration.set("OPTIONS.PRIVATE_MESSAGES_DISABLED", "&cYou can no longer receive new conversations. If you start a conversation with a player, they will be able to message you back.");
fileConfiguration.set("OPTIONS.PRIVATE_MESSAGE_SOUNDS_ENABLED", "&eYou &aenabled &eprivate message sounds.");
fileConfiguration.set("OPTIONS.PRIVATE_MESSAGE_SOUNDS_DISABLED", "&eYou &cdisabled &eprivate message sounds.");
try {
fileConfiguration.save(file);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,88 @@
package com.minexd.zoot.essentials;
import com.minexd.zoot.Zoot;
import com.minexd.zoot.bootstrap.Bootstrapped;
import com.minexd.zoot.essentials.event.SpawnTeleportEvent;
import com.minexd.zoot.util.LocationUtil;
import java.io.IOException;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
public class Essentials extends Bootstrapped {
private Location spawn;
public Essentials(Zoot zoot) {
super(zoot);
spawn = LocationUtil.deserialize(zoot.getMainConfig().getStringOrDefault("ESSENTIAL.SPAWN_LOCATION", null));
}
public void setSpawn(Location location) {
spawn = location;
if (spawn == null) {
zoot.getMainConfig().getConfiguration().set("ESSENTIAL.SPAWN_LOCATION", null);
} else {
zoot.getMainConfig().getConfiguration().set("ESSENTIAL.SPAWN_LOCATION", LocationUtil.serialize(this.spawn));
}
try {
zoot.getMainConfig().getConfiguration().save(zoot.getMainConfig().getFile());
} catch (IOException e) {
e.printStackTrace();
}
}
public void teleportToSpawn(Player player) {
Location location = spawn == null ? zoot.getServer().getWorlds().get(0).getSpawnLocation() : spawn;
SpawnTeleportEvent event = new SpawnTeleportEvent(player, location);
event.call();
if (!event.isCancelled() && event.getLocation() != null) {
player.teleport(event.getLocation());
}
}
public int clearEntities(World world) {
int removed = 0;
for (Entity entity : world.getEntities()) {
if (entity.getType() == EntityType.PLAYER) {
continue;
}
removed++;
entity.remove();
}
return removed;
}
public int clearEntities(World world, EntityType... excluded) {
int removed = 0;
entityLoop:
for (Entity entity : world.getEntities()) {
for (EntityType type : excluded) {
if (entity.getType() == EntityType.PLAYER) {
continue entityLoop;
}
if (entity.getType() == type) {
continue entityLoop;
}
}
removed++;
entity.remove();
}
return removed;
}
}

View File

@ -0,0 +1,52 @@
package com.minexd.zoot.essentials;
import com.minexd.zoot.Zoot;
import com.minexd.zoot.bootstrap.BootstrappedListener;
import com.minexd.zoot.util.CC;
import java.util.Arrays;
import java.util.List;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
public class EssentialsListener extends BootstrappedListener {
private static List<String> BLOCKED_COMMANDS = Arrays.asList(
"//calc",
"//eval",
"//solve",
"/bukkit:",
"/me",
"/bukkit:me",
"/minecraft:",
"/minecraft:me",
"/version",
"/ver"
);
public EssentialsListener(Zoot zoot) {
super(zoot);
}
@EventHandler(priority = EventPriority.LOWEST)
public void onCommandProcess(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
String message = (event.getMessage().startsWith("/") ? "" : "/") + event.getMessage();
for (String blockedCommand : BLOCKED_COMMANDS) {
if (message.startsWith(blockedCommand)) {
if (message.equalsIgnoreCase("/version") || message.equalsIgnoreCase("/ver")) {
if (event.getPlayer().isOp()) {
return;
}
}
player.sendMessage(CC.RED + "You cannot perform this command.");
event.setCancelled(true);
return;
}
}
}
}

View File

@ -0,0 +1,17 @@
package com.minexd.zoot.essentials.command;
import com.minexd.zoot.util.CC;
import com.qrakn.honcho.command.CommandMeta;
import com.qrakn.honcho.command.CommandOption;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
@CommandMeta(label = { "broadcast", "bc" }, options = "r", permission = "zoot.admin.broadcast")
public class BroadcastCommand {
public void execute(CommandSender sender, CommandOption option, String broadcast) {
String message = broadcast.replaceAll("(&([a-f0-9l-or]))", "\u00A7$2");
Bukkit.broadcastMessage(CC.translate((option == null ? "&6[Broadcast] &r" : "") + message));
}
}

View File

@ -0,0 +1,26 @@
package com.minexd.zoot.essentials.command;
import com.minexd.zoot.util.CC;
import com.qrakn.honcho.command.CommandMeta;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@CommandMeta(label = { "clearinv", "clear", "ci" }, permission = "zoot.admin.clearinv")
public class ClearCommand {
public void execute(Player player) {
player.getInventory().setContents(new ItemStack[36]);
player.getInventory().setArmorContents(new ItemStack[4]);
player.updateInventory();
player.sendMessage(CC.GOLD + "You cleared your inventory.");
}
public void execute(CommandSender sender, Player player) {
player.getInventory().setContents(new ItemStack[36]);
player.getInventory().setArmorContents(new ItemStack[4]);
player.updateInventory();
player.sendMessage(CC.GOLD + "Your inventory has been cleared by " + sender.getName());
}
}

View File

@ -0,0 +1,15 @@
package com.minexd.zoot.essentials.command;
import com.minexd.zoot.util.CC;
import com.qrakn.honcho.command.CommandMeta;
import org.bukkit.entity.Player;
@CommandMeta(label = "day")
public class DayCommand {
public void execute(Player player) {
player.setPlayerTime(6000L, false);
player.sendMessage(CC.GREEN + "It's now day time.");
}
}

View File

@ -0,0 +1,40 @@
package com.minexd.zoot.essentials.command;
import com.minexd.zoot.Locale;
import com.minexd.zoot.util.CC;
import com.qrakn.honcho.command.CommandMeta;
import org.bukkit.GameMode;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandMeta(label = { "gamemode", "gm" }, permission = "zoot.admin.gamemode")
public class GameModeCommand {
public void execute(Player player, GameMode gameMode) {
if (gameMode == null) {
player.sendMessage(CC.RED + "That game mode is not valid.");
return;
}
player.setGameMode(gameMode);
player.updateInventory();
player.sendMessage(CC.GOLD + "You updated your game mode.");
}
public void execute(CommandSender sender, Player target, GameMode gameMode) {
if (target == null) {
sender.sendMessage(Locale.PLAYER_NOT_FOUND.format());
return;
}
if (gameMode == null) {
sender.sendMessage(CC.RED + "That game mode is not valid.");
return;
}
target.setGameMode(gameMode);
target.updateInventory();
target.sendMessage(CC.GOLD + "Your game mode has been updated by " + sender.getName());
}
}

View File

@ -0,0 +1,33 @@
package com.minexd.zoot.essentials.command;
import com.minexd.zoot.Locale;
import com.minexd.zoot.util.CC;
import com.qrakn.honcho.command.CommandMeta;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandMeta(label = "heal", permission = "zoot.admin.heal")
public class HealCommand {
public void execute(Player player) {
player.setHealth(20.0);
player.setFoodLevel(20);
player.setSaturation(5.0F);
player.updateInventory();
player.sendMessage(CC.GOLD + "You healed yourself.");
}
public void execute(CommandSender sender, Player player) {
if (player == null) {
sender.sendMessage(Locale.PLAYER_NOT_FOUND.format());
return;
}
player.setHealth(20.0);
player.setFoodLevel(20);
player.setSaturation(5.0F);
player.updateInventory();
player.sendMessage(CC.GOLD + "You have been healed by " + sender.getName());
}
}

View File

@ -0,0 +1,13 @@
package com.minexd.zoot.essentials.command;
import com.qrakn.honcho.command.CommandMeta;
import org.bukkit.entity.Player;
@CommandMeta(label = "hideplayer", permission = "zoot.admin.hideplayer")
public class HidePlayerCommand {
public void execute(Player player, Player target) {
player.hidePlayer(target);
}
}

View File

@ -0,0 +1,53 @@
package com.minexd.zoot.essentials.command;
import com.minexd.zoot.ZootAPI;
import com.minexd.zoot.profile.Profile;
import com.minexd.zoot.rank.Rank;
import com.qrakn.honcho.command.CommandMeta;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import java.util.*;
@CommandMeta(label = "list")
public class ListCommand {
public void executue(Player sender) {
List<Player> sortedPlayers = new ArrayList<>(Bukkit.getOnlinePlayers());
sortedPlayers.sort(new Comparator<Player>() {
@Override
public int compare(Player o1, Player o2) {
Profile p1 = Profile.getByUuid(o1.getUniqueId());
Profile p2 = Profile.getByUuid(o2.getUniqueId());
return p2.getActiveRank().getWeight() - p1.getActiveRank().getWeight();
}
});
List<String> playerNames = new ArrayList<>();
for (Player player : sortedPlayers) {
playerNames.add(ZootAPI.getColoredName(player));
}
List<Rank> sortedRanks = new ArrayList<>(Rank.getRanks().values());
sortedRanks.sort(new Comparator<Rank>() {
@Override
public int compare(Rank o1, Rank o2) {
return o2.getWeight() - o1.getWeight();
}
});
List<String> rankNames = new ArrayList<>();
for (Rank rank : sortedRanks) {
rankNames.add(rank.getColor() + rank.getDisplayName());
}
sender.sendMessage(StringUtils.join(rankNames, ChatColor.WHITE + ", "));
sender.sendMessage("(" + Bukkit.getOnlinePlayers().size() + "/" + Bukkit.getMaxPlayers() + "): " +
StringUtils.join(playerNames, ChatColor.WHITE + ", "));
}
}

View File

@ -0,0 +1,15 @@
package com.minexd.zoot.essentials.command;
import com.minexd.zoot.util.LocationUtil;
import com.qrakn.honcho.command.CommandMeta;
import org.bukkit.entity.Player;
@CommandMeta(label = "loc", permission = "zoot.admin.loc")
public class LocationCommand {
public void execute(Player player) {
player.sendMessage(LocationUtil.serialize(player.getLocation()));
System.out.println(LocationUtil.serialize(player.getLocation()));
}
}

View File

@ -0,0 +1,21 @@
package com.minexd.zoot.essentials.command;
import com.minexd.zoot.util.CC;
import com.qrakn.honcho.command.CommandMeta;
import org.bukkit.entity.Player;
@CommandMeta(label = "more", permission = "zoot.admin.more")
public class MoreCommand {
public void execute(Player player) {
if (player.getItemInHand() == null) {
player.sendMessage(CC.RED + "There is nothing in your hand.");
return;
}
player.getItemInHand().setAmount(64);
player.updateInventory();
player.sendMessage(CC.GREEN + "You gave yourself more of the item in your hand.");
}
}

View File

@ -0,0 +1,15 @@
package com.minexd.zoot.essentials.command;
import com.minexd.zoot.util.CC;
import com.qrakn.honcho.command.CommandMeta;
import org.bukkit.entity.Player;
@CommandMeta(label = "night")
public class NightCommand {
public void execute(Player player) {
player.setPlayerTime(18000L, false);
player.sendMessage(CC.GREEN + "It's now night time.");
}
}

View File

@ -0,0 +1,37 @@
package com.minexd.zoot.essentials.command;
import com.minexd.zoot.ZootAPI;
import com.minexd.zoot.util.BukkitReflection;
import com.minexd.zoot.util.CC;
import com.qrakn.honcho.command.CommandMeta;
import org.bukkit.entity.Player;
@CommandMeta(label = "ping")
public class PingCommand {
public void execute(Player player) {
player.sendMessage(CC.YELLOW + "Your Ping: " + colorPing(BukkitReflection.getPing(player)));
}
public void execute(Player player, Player target) {
if (target == null) {
player.sendMessage(CC.RED + "A player with that name could not be found.");
} else {
player.sendMessage(ZootAPI.getColoredName(target) + CC.YELLOW + "'s Ping: " +
colorPing(BukkitReflection.getPing(target)));
}
}
private String colorPing(int ping) {
if (ping <= 40) {
return CC.GREEN + ping;
} else if (ping <= 70) {
return CC.YELLOW + ping;
} else if (ping <= 100) {
return CC.GOLD + ping;
} else {
return CC.RED + ping;
}
}
}

View File

@ -0,0 +1,26 @@
package com.minexd.zoot.essentials.command;
import com.minexd.zoot.util.CC;
import com.qrakn.honcho.command.CommandMeta;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@CommandMeta(label = "rename", permission = "zoot.staff.rename")
public class RenameCommand {
public void execute(Player player, String name) {
if (player.getItemInHand() != null) {
ItemStack itemStack = player.getItemInHand();
ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.setDisplayName(CC.translate(name));
itemStack.setItemMeta(itemMeta);
player.updateInventory();
player.sendMessage(CC.GREEN + "You renamed the item in your hand.");
} else {
player.sendMessage(CC.RED + "There is nothing in your hand.");
}
}
}

View File

@ -0,0 +1,17 @@
package com.minexd.zoot.essentials.command;
import com.minexd.zoot.Zoot;
import com.minexd.zoot.util.BukkitReflection;
import com.minexd.zoot.util.CC;
import com.qrakn.honcho.command.CommandMeta;
import org.bukkit.command.CommandSender;
@CommandMeta(label = "setslots", async = true, permission = "zoot.admin.setslots")
public class SetSlotsCommand {
public void execute(CommandSender sender, int slots) {
BukkitReflection.setMaxPlayers(Zoot.get().getServer(), slots);
sender.sendMessage(CC.GOLD + "You set the max slots to " + slots + ".");
}
}

View File

@ -0,0 +1,16 @@
package com.minexd.zoot.essentials.command;
import com.minexd.zoot.Zoot;
import com.minexd.zoot.util.CC;
import com.qrakn.honcho.command.CommandMeta;
import org.bukkit.entity.Player;
@CommandMeta(label = "setspawn", permission = "zoot.admin.setspawn")
public class SetSpawnCommand {
public void execute(Player player) {
Zoot.get().getEssentials().setSpawn(player.getLocation());
player.sendMessage(CC.GREEN + "You updated this world's spawn.");
}
}

View File

@ -0,0 +1,13 @@
package com.minexd.zoot.essentials.command;
import com.qrakn.honcho.command.CommandMeta;
import org.bukkit.entity.Player;
@CommandMeta(label = "showplayer", permission = "zoot.admin.showplayer")
public class ShowPlayerCommand {
public void execute(Player player, Player target) {
player.showPlayer(target);
}
}

View File

@ -0,0 +1,16 @@
package com.minexd.zoot.essentials.command;
import com.minexd.zoot.Zoot;
import com.minexd.zoot.util.CC;
import com.qrakn.honcho.command.CommandMeta;
import org.bukkit.entity.Player;
@CommandMeta(label = "spawn", permission = "zoot.staff.spawn")
public class SpawnCommand {
public void execute(Player player) {
Zoot.get().getEssentials().teleportToSpawn(player);
player.sendMessage(CC.GREEN + "You teleported to this world's spawn.");
}
}

View File

@ -0,0 +1,15 @@
package com.minexd.zoot.essentials.command;
import com.minexd.zoot.util.CC;
import com.qrakn.honcho.command.CommandMeta;
import org.bukkit.entity.Player;
@CommandMeta(label = "sunset")
public class SunsetCommand {
public void execute(Player player) {
player.setPlayerTime(12000, false);
player.sendMessage(CC.GREEN + "It's now sunset.");
}
}

View File

@ -0,0 +1,29 @@
package com.minexd.zoot.essentials.command;
import com.minexd.zoot.util.CC;
import com.qrakn.honcho.command.CommandMeta;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.entity.Player;
@CommandMeta(label = "tpworld", permission = "zoot.admin.tpworld")
public class TeleportWorldCommand {
public void execute(Player player, String worldName) {
World world = Bukkit.getWorld(worldName);
if (world == null) {
world = Bukkit.createWorld(new WorldCreator(worldName));
player.sendMessage(CC.GOLD + "Generating new world \"" + worldName + "\"");
}
if (world == null) {
player.sendMessage(CC.RED + "A world with that name does not exist.");
} else {
player.teleport(world.getSpawnLocation());
player.sendMessage(CC.GOLD + "Teleported you to " + world.getName());
}
}
}

View File

@ -0,0 +1,15 @@
package com.minexd.zoot.essentials.command;
import com.minexd.zoot.Zoot;
import com.qrakn.honcho.command.CommandMeta;
import org.bukkit.command.CommandSender;
@CommandMeta(label = "zoot debug", permission = "zoot.admin")
public class ZootDebugCommand {
public void execute(CommandSender sender) {
Zoot.get().setDebug(!Zoot.get().isDebug());
sender.sendMessage("Debug: " + Zoot.get().isDebug());
}
}

View File

@ -0,0 +1,21 @@
package com.minexd.zoot.essentials.event;
import com.minexd.zoot.util.BaseEvent;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
public class SpawnTeleportEvent extends BaseEvent implements Cancellable {
@Getter private final Player player;
@Getter @Setter private Location location;
@Getter @Setter private boolean cancelled;
public SpawnTeleportEvent(Player player, Location location) {
this.player = player;
this.location = location;
}
}

View File

@ -0,0 +1,150 @@
package com.minexd.zoot.network;
import com.minexd.zoot.pidgin.packet.handler.IncomingPacketHandler;
import com.minexd.zoot.pidgin.packet.listener.PacketListener;
import com.minexd.zoot.Locale;
import com.minexd.zoot.Zoot;
import com.minexd.zoot.network.event.ReceiveStaffChatEvent;
import com.minexd.zoot.network.packet.PacketAddGrant;
import com.minexd.zoot.network.packet.PacketBroadcastPunishment;
import com.minexd.zoot.network.packet.PacketDeleteGrant;
import com.minexd.zoot.network.packet.PacketDeleteRank;
import com.minexd.zoot.network.packet.PacketRefreshRank;
import com.minexd.zoot.network.packet.PacketStaffChat;
import com.minexd.zoot.network.packet.PacketStaffJoinNetwork;
import com.minexd.zoot.network.packet.PacketStaffLeaveNetwork;
import com.minexd.zoot.network.packet.PacketStaffSwitchServer;
import com.minexd.zoot.profile.Profile;
import com.minexd.zoot.profile.grant.Grant;
import com.minexd.zoot.profile.grant.event.GrantAppliedEvent;
import com.minexd.zoot.profile.grant.event.GrantExpireEvent;
import com.minexd.zoot.profile.punishment.Punishment;
import com.minexd.zoot.rank.Rank;
import java.util.Objects;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
public class NetworkPacketListener implements PacketListener {
private Zoot zoot;
public NetworkPacketListener(Zoot zoot) {
this.zoot = zoot;
}
@IncomingPacketHandler
public void onAddGrant(PacketAddGrant packet) {
Player player = Bukkit.getPlayer(packet.getPlayerUuid());
Grant grant = packet.getGrant();
if (player != null) {
Profile profile = Profile.getProfiles().get(player.getUniqueId());
profile.getGrants().removeIf(other -> Objects.equals(other, grant));
profile.getGrants().add(grant);
new GrantAppliedEvent(player, grant);
}
}
@IncomingPacketHandler
public void onDeleteGrant(PacketDeleteGrant packet) {
Player player = Bukkit.getPlayer(packet.getPlayerUuid());
Grant grant = packet.getGrant();
if (player != null) {
Profile profile = Profile.getProfiles().get(player.getUniqueId());
profile.getGrants().removeIf(other -> Objects.equals(other, grant));
profile.getGrants().add(grant);
new GrantExpireEvent(player, grant);
}
}
@IncomingPacketHandler
public void onBroadcastPunishment(PacketBroadcastPunishment packet) {
Punishment punishment = packet.getPunishment();
punishment.broadcast(packet.getStaff(), packet.getTarget(), packet.isSilent());
Player player = Bukkit.getPlayer(packet.getTargetUuid());
if (player != null) {
Profile profile = Profile.getProfiles().get(player.getUniqueId());
profile.getPunishments().removeIf(other -> Objects.equals(other, punishment));
profile.getPunishments().add(punishment);
if (punishment.getType().isBan()) {
new BukkitRunnable() {
@Override
public void run() {
player.kickPlayer(punishment.getKickMessage());
}
}.runTask(Zoot.get());
}
}
}
@IncomingPacketHandler
public void onRankRefresh(PacketRefreshRank packet) {
Rank rank = Rank.getRankByUuid(packet.getUuid());
if (rank == null) {
rank = new Rank(packet.getUuid(), packet.getName());
}
rank.load();
Zoot.broadcastOps(Locale.NETWORK_RANK_REFRESHED.format(Locale.NETWORK_BROADCAST_PREFIX.format(),
rank.getDisplayName()));
}
@IncomingPacketHandler
public void onRankDelete(PacketDeleteRank packet) {
Rank rank = Rank.getRanks().remove(packet.getUuid());
if (rank != null) {
Zoot.broadcastOps(Locale.NETWORK_RANK_DELETED.format(Locale.NETWORK_BROADCAST_PREFIX.format(),
rank.getDisplayName()));
}
}
@IncomingPacketHandler
public void onStaffChat(PacketStaffChat packet) {
zoot.getServer().getOnlinePlayers().stream()
.filter(onlinePlayer -> onlinePlayer.hasPermission("zoot.staff"))
.forEach(onlinePlayer -> {
ReceiveStaffChatEvent event = new ReceiveStaffChatEvent(onlinePlayer);
zoot.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
Profile profile = Profile.getProfiles().get(event.getPlayer().getUniqueId());
if (profile != null && profile.getStaffOptions().staffModeEnabled()) {
onlinePlayer.sendMessage(Locale.STAFF_CHAT.format(Locale.STAFF_BROADCAST_PREFIX.format(),
packet.getPlayerName(), packet.getServerName(), packet.getChatMessage()
));
}
}
});
}
@IncomingPacketHandler
public void onStaffJoinNetwork(PacketStaffJoinNetwork packet) {
zoot.getServer().broadcast(Locale.STAFF_JOIN_NETWORK.format(Locale.STAFF_BROADCAST_PREFIX.format(),
packet.getPlayerName(), packet.getServerName()), "zoot.staff");
}
@IncomingPacketHandler
public void onStaffLeaveNetwork(PacketStaffLeaveNetwork packet) {
zoot.getServer().broadcast(Locale.STAFF_LEAVE_NETWORK.format(Locale.STAFF_BROADCAST_PREFIX.format(),
packet.getPlayerName()), "zoot.staff");
}
@IncomingPacketHandler
public void onStaffSwitchServer(PacketStaffSwitchServer packet) {
zoot.getServer().broadcast(Locale.STAFF_SWITCH_SERVER.format(Locale.STAFF_BROADCAST_PREFIX.format(),
packet.getPlayerName(), packet.getToServerName(), packet.getFromServerName()), "zoot.staff");
}
}

View File

@ -0,0 +1,18 @@
package com.minexd.zoot.network.event;
import com.minexd.zoot.util.BaseEvent;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
public class ReceiveStaffChatEvent extends BaseEvent implements Cancellable {
@Getter private Player player;
@Getter @Setter private boolean cancelled;
public ReceiveStaffChatEvent(Player player) {
this.player = player;
}
}

View File

@ -0,0 +1,43 @@
package com.minexd.zoot.network.packet;
import com.google.gson.JsonObject;
import com.minexd.zoot.pidgin.packet.Packet;
import com.minexd.zoot.profile.grant.Grant;
import com.minexd.zoot.util.json.JsonChain;
import java.util.UUID;
import lombok.Getter;
public class PacketAddGrant implements Packet {
@Getter private UUID playerUuid;
@Getter private Grant grant;
public PacketAddGrant() {
}
public PacketAddGrant(UUID playerUuid, Grant grant) {
this.playerUuid = playerUuid;
this.grant = grant;
}
@Override
public int id() {
return 1;
}
@Override
public JsonObject serialize() {
return new JsonChain()
.addProperty("playerUuid", playerUuid.toString())
.add("grant", Grant.SERIALIZER.serialize(grant))
.get();
}
@Override
public void deserialize(JsonObject jsonObject) {
playerUuid = UUID.fromString(jsonObject.get("playerUuid").getAsString());
grant = Grant.DESERIALIZER.deserialize(jsonObject.get("grant").getAsJsonObject());
}
}

View File

@ -0,0 +1,55 @@
package com.minexd.zoot.network.packet;
import com.google.gson.JsonObject;
import com.minexd.zoot.pidgin.packet.Packet;
import com.minexd.zoot.profile.punishment.Punishment;
import com.minexd.zoot.util.json.JsonChain;
import java.util.UUID;
import lombok.Getter;
public class PacketBroadcastPunishment implements Packet {
@Getter private Punishment punishment;
@Getter private String staff;
@Getter private String target;
@Getter private UUID targetUuid;
@Getter private boolean silent;
public PacketBroadcastPunishment() {
}
public PacketBroadcastPunishment(Punishment punishment, String staff, String target, UUID targetUuid, boolean silent) {
this.punishment = punishment;
this.staff = staff;
this.target = target;
this.targetUuid = targetUuid;
this.silent = silent;
}
@Override
public int id() {
return 2;
}
@Override
public JsonObject serialize() {
return new JsonChain()
.add("punishment", Punishment.SERIALIZER.serialize(punishment))
.addProperty("staff", staff)
.addProperty("target", target)
.addProperty("targetUuid", targetUuid.toString())
.addProperty("silent", silent)
.get();
}
@Override
public void deserialize(JsonObject object) {
punishment = Punishment.DESERIALIZER.deserialize(object.get("punishment").getAsJsonObject());
staff = object.get("staff").getAsString();
target = object.get("target").getAsString();
targetUuid = UUID.fromString(object.get("targetUuid").getAsString());
silent = object.get("silent").getAsBoolean();
}
}

View File

@ -0,0 +1,43 @@
package com.minexd.zoot.network.packet;
import com.google.gson.JsonObject;
import com.minexd.zoot.pidgin.packet.Packet;
import com.minexd.zoot.profile.grant.Grant;
import com.minexd.zoot.util.json.JsonChain;
import java.util.UUID;
import lombok.Getter;
public class PacketDeleteGrant implements Packet {
@Getter private UUID playerUuid;
@Getter private Grant grant;
public PacketDeleteGrant() {
}
public PacketDeleteGrant(UUID playerUuid, Grant grant) {
this.playerUuid = playerUuid;
this.grant = grant;
}
@Override
public int id() {
return 3;
}
@Override
public JsonObject serialize() {
return new JsonChain()
.addProperty("playerUuid", playerUuid.toString())
.add("grant", Grant.SERIALIZER.serialize(grant))
.get();
}
@Override
public void deserialize(JsonObject jsonObject) {
playerUuid = UUID.fromString(jsonObject.get("playerUuid").getAsString());
grant = Grant.DESERIALIZER.deserialize(jsonObject.get("grant").getAsJsonObject());
}
}

View File

@ -0,0 +1,37 @@
package com.minexd.zoot.network.packet;
import com.google.gson.JsonObject;
import com.minexd.zoot.pidgin.packet.Packet;
import com.minexd.zoot.util.json.JsonChain;
import java.util.UUID;
import lombok.AllArgsConstructor;
import lombok.Getter;
@AllArgsConstructor
@Getter
public class PacketDeleteRank implements Packet {
private UUID uuid;
public PacketDeleteRank() {
}
@Override
public int id() {
return 4;
}
@Override
public JsonObject serialize() {
return new JsonChain()
.addProperty("uuid", uuid.toString())
.get();
}
@Override
public void deserialize(JsonObject jsonObject) {
uuid = UUID.fromString(jsonObject.get("uuid").getAsString());
}
}

View File

@ -0,0 +1,40 @@
package com.minexd.zoot.network.packet;
import com.google.gson.JsonObject;
import com.minexd.zoot.pidgin.packet.Packet;
import com.minexd.zoot.util.json.JsonChain;
import java.util.UUID;
import lombok.AllArgsConstructor;
import lombok.Getter;
@AllArgsConstructor
@Getter
public class PacketRefreshRank implements Packet {
private UUID uuid;
private String name;
public PacketRefreshRank() {
}
@Override
public int id() {
return 5;
}
@Override
public JsonObject serialize() {
return new JsonChain()
.addProperty("uuid", uuid.toString())
.addProperty("name", name)
.get();
}
@Override
public void deserialize(JsonObject jsonObject) {
uuid = UUID.fromString(jsonObject.get("uuid").getAsString());
name = jsonObject.get("name").getAsString();
}
}

View File

@ -0,0 +1,48 @@
package com.minexd.zoot.network.packet;
import com.google.gson.JsonObject;
import com.minexd.zoot.pidgin.packet.Packet;
import com.minexd.zoot.util.json.JsonChain;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class PacketStaffChat implements Packet {
private String playerName;
private String serverName;
private String chatMessage;
public PacketStaffChat() {
}
public PacketStaffChat(String playerName, String serverName, String chatMessage) {
this.playerName = playerName;
this.serverName = serverName;
this.chatMessage = chatMessage;
}
public int id() {
return 6;
}
@Override
public JsonObject serialize() {
return new JsonChain()
.addProperty("playerName", playerName)
.addProperty("serverName", serverName)
.addProperty("chatMessage", chatMessage)
.get();
}
@Override
public void deserialize(JsonObject jsonObject) {
playerName = jsonObject.get("playerName").getAsString();
serverName = jsonObject.get("serverName").getAsString();
chatMessage = jsonObject.get("chatMessage").getAsString();
}
}

View File

@ -0,0 +1,42 @@
package com.minexd.zoot.network.packet;
import com.google.gson.JsonObject;
import com.minexd.zoot.pidgin.packet.Packet;
import com.minexd.zoot.util.json.JsonChain;
import lombok.Getter;
@Getter
public class PacketStaffJoinNetwork implements Packet {
private String playerName;
private String serverName;
public PacketStaffJoinNetwork() {
}
public PacketStaffJoinNetwork(String playerName, String serverName) {
this.playerName = playerName;
this.serverName = serverName;
}
@Override
public int id() {
return 7;
}
@Override
public JsonObject serialize() {
return new JsonChain()
.addProperty("playerName", playerName)
.addProperty("serverName", serverName)
.get();
}
@Override
public void deserialize(JsonObject jsonObject) {
playerName = jsonObject.get("playerName").getAsString();
serverName = jsonObject.get("serverName").getAsString();
}
}

View File

@ -0,0 +1,42 @@
package com.minexd.zoot.network.packet;
import com.google.gson.JsonObject;
import com.minexd.zoot.pidgin.packet.Packet;
import com.minexd.zoot.util.json.JsonChain;
import lombok.Getter;
@Getter
public class PacketStaffLeaveNetwork implements Packet {
private String playerName;
private String serverName;
public PacketStaffLeaveNetwork() {
}
public PacketStaffLeaveNetwork(String playerName, String serverName) {
this.playerName = playerName;
this.serverName = serverName;
}
@Override
public int id() {
return 8;
}
@Override
public JsonObject serialize() {
return new JsonChain()
.addProperty("playerName", playerName)
.addProperty("serverName", serverName)
.get();
}
@Override
public void deserialize(JsonObject jsonObject) {
playerName = jsonObject.get("playerName").getAsString();
serverName = jsonObject.get("serverName").getAsString();
}
}

View File

@ -0,0 +1,46 @@
package com.minexd.zoot.network.packet;
import com.google.gson.JsonObject;
import com.minexd.zoot.pidgin.packet.Packet;
import com.minexd.zoot.util.json.JsonChain;
import lombok.Getter;
@Getter
public class PacketStaffSwitchServer implements Packet {
private String playerName;
private String fromServerName;
private String toServerName;
public PacketStaffSwitchServer() {
}
public PacketStaffSwitchServer(String playerName, String fromServerName, String toServerName) {
this.playerName = playerName;
this.fromServerName = fromServerName;
this.toServerName = toServerName;
}
@Override
public int id() {
return 9;
}
@Override
public JsonObject serialize() {
return new JsonChain()
.addProperty("playerName", playerName)
.addProperty("fromServerName", fromServerName)
.addProperty("toServerName", toServerName)
.get();
}
@Override
public void deserialize(JsonObject jsonObject) {
playerName = jsonObject.get("playerName").getAsString();
fromServerName = jsonObject.get("fromServerName").getAsString();
toServerName = jsonObject.get("toServerName").getAsString();
}
}

View File

@ -0,0 +1,184 @@
package com.minexd.zoot.pidgin;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.minexd.zoot.Zoot;
import com.minexd.zoot.pidgin.packet.Packet;
import com.minexd.zoot.pidgin.packet.handler.IncomingPacketHandler;
import com.minexd.zoot.pidgin.packet.handler.PacketExceptionHandler;
import com.minexd.zoot.pidgin.packet.listener.PacketListener;
import com.minexd.zoot.pidgin.packet.listener.PacketListenerData;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPubSub;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ForkJoinPool;
public class Pidgin {
private static JsonParser PARSER = new JsonParser();
private final String channel;
private JedisPool jedisPool;
private JedisPubSub jedisPubSub;
private List<PacketListenerData> packetListeners = new ArrayList<>();
private Map<Integer, Class> idToType = new HashMap<>();
private Map<Class, Integer> typeToId = new HashMap<>();
public Pidgin(String channel, String host, int port, String password) {
this.channel = channel;
this.packetListeners = new ArrayList<>();
this.jedisPool = new JedisPool(host, port);
if (password != null && !password.equals("")) {
try (Jedis jedis = this.jedisPool.getResource()) {
jedis.auth(password);
System.out.println("[Pidgin] Authenticating..");
}
}
this.setupPubSub();
}
public void sendPacket(Packet packet) {
sendPacket(packet, null);
}
public void sendPacket(Packet packet, PacketExceptionHandler exceptionHandler) {
try {
final JsonObject object = packet.serialize();
if (object == null) {
throw new IllegalStateException("Packet cannot generate null serialized data");
}
try (Jedis jedis = this.jedisPool.getResource()) {
System.out.println("[Pidgin] Attempting to publish packet..");
try {
if (Zoot.get().getMainConfig().getBoolean("REDIS.AUTHENTICATION.ENABLED")) {
jedis.auth(Zoot.get().getMainConfig().getString("REDIS.AUTHENTICATION.PASSWORD"));
}
jedis.publish(this.channel, packet.id() + ";" + object.toString());
System.out.println("[Pidgin] Successfully published packet..");
} catch (Exception ex) {
System.out.println("[Pidgin] Failed to publish packet..");
ex.printStackTrace();
}
}
} catch (Exception e) {
if (exceptionHandler != null) {
exceptionHandler.onException(e);
}
}
}
public Packet buildPacket(int id) {
if (!idToType.containsKey(id)) {
throw new IllegalStateException("A packet with that ID does not exist");
}
try {
return (Packet) idToType.get(id).newInstance();
} catch (Exception e) {
e.printStackTrace();
}
throw new IllegalStateException("Could not create new instance of packet type");
}
public void registerPacket(Class clazz) {
try {
int id = (int) clazz.getDeclaredMethod("id").invoke(clazz.newInstance(), null);
if (idToType.containsKey(id) || typeToId.containsKey(clazz)) {
throw new IllegalStateException("A packet with that ID has already been registered");
}
idToType.put(id, clazz);
typeToId.put(clazz, id);
} catch (Exception e) {
e.printStackTrace();
}
}
public void registerListener(PacketListener packetListener) {
methodLoop:
for (Method method : packetListener.getClass().getDeclaredMethods()) {
if (method.getDeclaredAnnotation(IncomingPacketHandler.class) != null) {
Class packetClass = null;
if (method.getParameters().length > 0) {
if (Packet.class.isAssignableFrom(method.getParameters()[0].getType())) {
packetClass = method.getParameters()[0].getType();
}
}
if (packetClass != null) {
this.packetListeners.add(new PacketListenerData(packetListener, method, packetClass));
}
}
}
}
private void setupPubSub() {
System.out.println("[Pidgin] Setting up PubSup..");
this.jedisPubSub = new JedisPubSub() {
@Override
public void onMessage(String channel, String message) {
if (channel.equalsIgnoreCase(Pidgin.this.channel)) {
try {
String[] args = message.split(";");
Integer id = Integer.valueOf(args[0]);
Packet packet = buildPacket(id);
if (packet != null) {
packet.deserialize(PARSER.parse(args[1]).getAsJsonObject());
for (PacketListenerData data : packetListeners) {
if (data.matches(packet)) {
data.getMethod().invoke(data.getInstance(), packet);
}
}
}
} catch (Exception e) {
System.out.println("[Pidgin] Failed to handle message");
e.printStackTrace();
}
}
}
};
ForkJoinPool.commonPool().execute(() -> {
try (Jedis jedis = this.jedisPool.getResource()) {
jedis.subscribe(this.jedisPubSub, channel);
System.out.println("[Pidgin] Successfully subscribing to channel..");
} catch (Exception exception) {
System.out.println("[Pidgin] Failed to subscribe to channel..");
exception.printStackTrace();
}
});
}
}

View File

@ -0,0 +1,13 @@
package com.minexd.zoot.pidgin.packet;
import com.google.gson.JsonObject;
public interface Packet {
int id();
JsonObject serialize();
void deserialize(JsonObject object);
}

View File

@ -0,0 +1,17 @@
package com.minexd.zoot.pidgin.packet.handler;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Identifies a method and packet type assigned to the method.
* The only valid parameter types for a method that is annotated
* by this annotation are String and Packet.
*/
@Target({ ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface IncomingPacketHandler {
}

View File

@ -0,0 +1,10 @@
package com.minexd.zoot.pidgin.packet.handler;
public class PacketExceptionHandler {
public void onException(Exception e) {
System.out.println("Failed to send packet");
e.printStackTrace();
}
}

View File

@ -0,0 +1,5 @@
package com.minexd.zoot.pidgin.packet.listener;
public interface PacketListener {
}

View File

@ -0,0 +1,26 @@
package com.minexd.zoot.pidgin.packet.listener;
import java.lang.reflect.Method;
import com.minexd.zoot.pidgin.packet.Packet;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* A wrapper class that holds all the information needed to
* identify and execute a message function.
*
*/
@AllArgsConstructor
@Getter
public class PacketListenerData {
private Object instance;
private Method method;
private Class packetClass;
public boolean matches(Packet packet) {
return this.packetClass == packet.getClass();
}
}

View File

@ -0,0 +1,330 @@
package com.minexd.zoot.profile;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.minexd.zoot.Zoot;
import com.minexd.zoot.ZootAPI;
import com.minexd.zoot.profile.conversation.ProfileConversations;
import com.minexd.zoot.profile.grant.event.GrantAppliedEvent;
import com.minexd.zoot.profile.grant.event.GrantExpireEvent;
import com.minexd.zoot.profile.option.ProfileOptions;
import com.minexd.zoot.profile.staff.ProfileStaffOptions;
import com.minexd.zoot.profile.punishment.Punishment;
import com.minexd.zoot.profile.grant.Grant;
import com.minexd.zoot.profile.punishment.PunishmentType;
import com.minexd.zoot.rank.Rank;
import com.minexd.zoot.util.Cooldown;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoCursor;
import com.mongodb.client.model.Filters;
import com.mongodb.client.model.ReplaceOptions;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import lombok.Getter;
import lombok.Setter;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo;
public class Profile {
@Getter private static Map<UUID, Profile> profiles = new HashMap<>();
private static MongoCollection<Document> collection;
@Getter @Setter private String username;
@Getter private final UUID uuid;
@Getter @Setter private Long firstSeen;
@Getter @Setter private Long lastSeen;
@Getter @Setter private String currentAddress;
@Getter private List<String> ipAddresses;
@Getter private final List<UUID> knownAlts;
@Getter private final ProfileOptions options;
@Getter private final ProfileStaffOptions staffOptions;
@Getter private final ProfileConversations conversations;
@Getter private Grant activeGrant;
@Getter private final List<Grant> grants;
@Getter private final List<Punishment> punishments;
@Getter @Setter private boolean loaded;
@Getter @Setter private Cooldown chatCooldown;
public Profile(String username, UUID uuid) {
this.username = username;
this.uuid = uuid;
this.grants = new ArrayList<>();
this.punishments = new ArrayList<>();
this.ipAddresses = new ArrayList<>();
this.knownAlts = new ArrayList<>();
this.options = new ProfileOptions();
this.staffOptions = new ProfileStaffOptions();
this.conversations = new ProfileConversations(this);
this.chatCooldown = new Cooldown(0);
load();
}
public Player getPlayer() {
return Bukkit.getPlayer(uuid);
}
public String getColoredUsername() {
return activeGrant.getRank().getColor() + username;
}
public Punishment getActivePunishmentByType(PunishmentType type) {
for (Punishment punishment : punishments) {
if (punishment.getType() == type && !punishment.isRemoved() && !punishment.hasExpired()) {
return punishment;
}
}
return null;
}
public int getPunishmentCountByType(PunishmentType type) {
int i = 0;
for (Punishment punishment : punishments) {
if (punishment.getType() == type) i++;
}
return i;
}
public Rank getActiveRank() {
return activeGrant.getRank();
}
public void activateNextGrant() {
List<Grant> grants = new ArrayList<>(this.grants);
grants.sort(Comparator.comparingInt(grant -> grant.getRank().getWeight()));
Collections.reverse(grants);
for (Grant grant : grants) {
if (!grant.isRemoved() && !grant.hasExpired()) {
if (!grant.equals(activeGrant)) {
Zoot.get().debug("");
activeGrant = grant;
setupBukkitPlayer(getPlayer());
return;
}
}
}
}
public void checkGrants() {
Player player = getPlayer();
for (Grant grant : grants) {
if (!grant.isRemoved() && grant.hasExpired()) {
grant.setRemovedAt(System.currentTimeMillis());
grant.setRemovedReason("Grant expired");
grant.setRemoved(true);
if (player != null) {
new GrantExpireEvent(player, grant).call();
}
if (grant.equals(activeGrant)) {
activateNextGrant();
}
}
}
if (activeGrant == null) {
Grant defaultGrant = new Grant(UUID.randomUUID(), Rank.getDefaultRank(), null,
System.currentTimeMillis(), "Default", Integer.MAX_VALUE);
grants.add(defaultGrant);
activeGrant = defaultGrant;
if (player != null) {
new GrantAppliedEvent(player, defaultGrant).call();
}
}
}
public void setupBukkitPlayer(Player player) {
if (player == null) {
return;
}
for (PermissionAttachmentInfo attachmentInfo : player.getEffectivePermissions()) {
if (attachmentInfo.getAttachment() == null) {
continue;
}
attachmentInfo.getAttachment().getPermissions().forEach((permission, value) -> {
attachmentInfo.getAttachment().unsetPermission(permission);
});
}
PermissionAttachment attachment = player.addAttachment(Zoot.get());
for (String perm : activeGrant.getRank().getAllPermissions()) {
attachment.setPermission(perm, true);
}
player.recalculatePermissions();
String displayName = activeGrant.getRank().getPrefix() + player.getName() + activeGrant.getRank().getSuffix();
String coloredName = ZootAPI.getColoredName(player);
player.setDisplayName(displayName);
if (Zoot.get().getMainConfig().getBoolean("SETTINGS.UPDATE_PLAYER_LIST_NAME")) {
player.setPlayerListName(coloredName);
}
}
public void load() {
Document document = collection.find(Filters.eq("uuid", uuid.toString())).first();
if (document != null) {
if (username == null) {
username = document.getString("username");
}
firstSeen = document.getLong("firstSeen");
lastSeen = document.getLong("lastSeen");
currentAddress = document.getString("currentAddress");
ipAddresses = Zoot.GSON.fromJson(document.getString("ipAddresses"), Zoot.LIST_STRING_TYPE);
Document optionsDocument = (Document) document.get("options");
options.publicChatEnabled(optionsDocument.getBoolean("publicChatEnabled"));
options.receivingNewConversations(optionsDocument.getBoolean("receivingNewConversations"));
options.playingMessageSounds(optionsDocument.getBoolean("playingMessageSounds"));
JsonArray grantList = new JsonParser().parse(document.getString("grants")).getAsJsonArray();
for (JsonElement grantData : grantList) {
// Transform into a Grant object
Grant grant = Grant.DESERIALIZER.deserialize(grantData.getAsJsonObject());
if (grant != null) {
this.grants.add(grant);
}
}
JsonArray punishmentList = new JsonParser().parse(document.getString("punishments")).getAsJsonArray();
for (JsonElement punishmentData : punishmentList) {
// Transform into a Grant object
Punishment punishment = Punishment.DESERIALIZER.deserialize(punishmentData.getAsJsonObject());
if (punishment != null) {
this.punishments.add(punishment);
}
}
}
// Update active grants
activateNextGrant();
checkGrants();
// Set loaded to true
loaded = true;
}
public void save() {
Document document = new Document();
document.put("username", username);
document.put("uuid", uuid.toString());
document.put("firstSeen", firstSeen);
document.put("lastSeen", lastSeen);
document.put("currentAddress", currentAddress);
document.put("ipAddresses", Zoot.GSON.toJson(ipAddresses, Zoot.LIST_STRING_TYPE));
Document optionsDocument = new Document();
optionsDocument.put("publicChatEnabled", options.publicChatEnabled());
optionsDocument.put("receivingNewConversations", options.receivingNewConversations());
optionsDocument.put("playingMessageSounds", options.playingMessageSounds());
document.put("options", optionsDocument);
JsonArray grantList = new JsonArray();
for (Grant grant : this.grants) {
grantList.add(Grant.SERIALIZER.serialize(grant));
}
document.put("grants", grantList.toString());
JsonArray punishmentList = new JsonArray();
for (Punishment punishment : this.punishments) {
punishmentList.add(Punishment.SERIALIZER.serialize(punishment));
}
document.put("punishments", punishmentList.toString());
collection.replaceOne(Filters.eq("uuid", uuid.toString()), document, new ReplaceOptions().upsert(true));
}
public static void init() {
collection = Zoot.get().getMongoDatabase().getCollection("profiles");
}
public static Profile getByUuid(UUID uuid) {
if (profiles.containsKey(uuid)) {
return profiles.get(uuid);
}
return new Profile(null, uuid);
}
public static Profile getByUsername(String username) {
Player player = Bukkit.getPlayer(username);
if (player != null) {
return profiles.get(player.getUniqueId());
}
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(username);
if (offlinePlayer.hasPlayedBefore()) {
if (profiles.containsKey(offlinePlayer.getUniqueId())) {
return profiles.get(offlinePlayer.getUniqueId());
}
return new Profile(offlinePlayer.getName(), offlinePlayer.getUniqueId());
}
UUID uuid = Zoot.get().getRedisCache().getUuid(username);
if (uuid != null) {
if (profiles.containsKey(uuid)) {
return profiles.get(uuid);
}
return new Profile(username, uuid);
}
return null;
}
public static List<Profile> getByIpAddress(String ipAddress) {
List<Profile> profiles = new ArrayList<>();
Bson filter = Filters.eq("currentAddress", ipAddress);
try (MongoCursor<Document> cursor = collection.find(filter).iterator()) {
while (cursor.hasNext()) {
Document document = cursor.next();
profiles.add(new Profile(document.getString("username"),
UUID.fromString(document.getString("uuid"))));
}
}
return profiles;
}
}

View File

@ -0,0 +1,171 @@
package com.minexd.zoot.profile;
import com.minexd.zoot.Locale;
import com.minexd.zoot.Zoot;
import com.minexd.zoot.bootstrap.BootstrappedListener;
import com.minexd.zoot.cache.RedisPlayerData;
import com.minexd.zoot.network.packet.PacketStaffChat;
import com.minexd.zoot.profile.punishment.Punishment;
import com.minexd.zoot.profile.punishment.PunishmentType;
import com.minexd.zoot.util.CC;
import java.util.List;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.scheduler.BukkitRunnable;
public class ProfileListener extends BootstrappedListener {
public ProfileListener(Zoot zoot) {
super(zoot);
}
@EventHandler
public void onAsyncPlayerPreLogin(AsyncPlayerPreLoginEvent event) {
Player player = Bukkit.getPlayer(event.getUniqueId());
// Need to check if player is still logged in when receiving another login attempt
// This happens when a player using a custom client can access the server list while in-game (and reconnecting)
if (player != null && player.isOnline()) {
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
event.setKickMessage(CC.RED + "You tried to login too quickly after disconnecting.\nTry again in a few seconds.");
zoot.getServer().getScheduler().runTask(zoot, () -> player.kickPlayer(CC.RED + "Duplicate login kick"));
return;
}
Profile profile = null;
try {
profile = new Profile(event.getName(), event.getUniqueId());
if (!profile.isLoaded()) {
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
event.setKickMessage(Locale.FAILED_TO_LOAD_PROFILE.format());
return;
}
if (profile.getActivePunishmentByType(PunishmentType.BAN) != null) {
handleBan(event, profile.getActivePunishmentByType(PunishmentType.BAN));
return;
}
profile.setUsername(event.getName());
if (profile.getFirstSeen() == null) {
profile.setFirstSeen(System.currentTimeMillis());
}
profile.setLastSeen(System.currentTimeMillis());
if (profile.getCurrentAddress() == null) {
profile.setCurrentAddress(event.getAddress().getHostAddress());
}
if (!profile.getIpAddresses().contains(event.getAddress().getHostAddress())) {
profile.getIpAddresses().add(event.getAddress().getHostAddress());
}
if (!profile.getCurrentAddress().equals(event.getAddress().getHostAddress())) {
List<Profile> alts = Profile.getByIpAddress(event.getAddress().getHostAddress());
for (Profile alt : alts) {
if (alt.getActivePunishmentByType(PunishmentType.BAN) != null) {
handleBan(event, alt.getActivePunishmentByType(PunishmentType.BAN));
return;
}
}
}
profile.save();
} catch (Exception e) {
e.printStackTrace();
zoot.debug(Level.SEVERE, "Failed to load profile for " + event.getName(), e);
}
if (profile == null || !profile.isLoaded()) {
event.setKickMessage(Locale.FAILED_TO_LOAD_PROFILE.format());
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
return;
}
Profile.getProfiles().put(profile.getUuid(), profile);
RedisPlayerData playerData = new RedisPlayerData(event.getUniqueId(), event.getName());
playerData.setLastAction(RedisPlayerData.LastAction.JOINING_SERVER);
playerData.setLastSeenServer(zoot.getMainConfig().getString("SERVER_NAME"));
playerData.setLastSeenAt(System.currentTimeMillis());
zoot.getRedisCache().updatePlayerData(playerData);
zoot.getRedisCache().updateNameAndUUID(event.getName(), event.getUniqueId());
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
Profile profile = Profile.getProfiles().get(player.getUniqueId());
profile.setupBukkitPlayer(player);
for (String perm : profile.getActiveGrant().getRank().getAllPermissions()) {
zoot.debug(player, perm);
}
if (player.hasPermission("zoot.staff")) {
player.sendMessage(CC.GOLD + "Your staff mode is currently: " +
(profile.getStaffOptions().staffModeEnabled() ? CC.GREEN + "Enabled" : CC.RED + "Disabled"));
}
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
Profile profile = Profile.getProfiles().remove(event.getPlayer().getUniqueId());
profile.setLastSeen(System.currentTimeMillis());
if (profile.isLoaded()) {
new BukkitRunnable() {
@Override
public void run() {
try {
profile.save();
} catch (Exception e) {
zoot.debug(Level.SEVERE, "Failed to save profile " + event.getPlayer().getName(), e);
}
}
}.runTaskAsynchronously(Zoot.get());
}
RedisPlayerData playerData = new RedisPlayerData(event.getPlayer().getUniqueId(), event.getPlayer().getName());
playerData.setLastAction(RedisPlayerData.LastAction.LEAVING_SERVER);
playerData.setLastSeenServer(zoot.getMainConfig().getString("SERVER_NAME"));
playerData.setLastSeenAt(System.currentTimeMillis());
zoot.getRedisCache().updatePlayerData(playerData);
}
@EventHandler(priority = EventPriority.LOW)
public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent event) {
Profile profile = Profile.getByUuid(event.getPlayer().getUniqueId());
if (profile.getStaffOptions().staffChatModeEnabled()) {
if (profile.getStaffOptions().staffModeEnabled()) {
Zoot.get().getPidgin().sendPacket(new PacketStaffChat(event.getPlayer().getDisplayName(),
Zoot.get().getMainConfig().getString("SERVER_NAME"), event.getMessage()));
} else {
event.getPlayer().sendMessage(CC.RED + "You must enable staff mode or disable staff chat mode.");
}
event.setCancelled(true);
}
}
private void handleBan(AsyncPlayerPreLoginEvent event, Punishment punishment) {
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
event.setKickMessage(punishment.getKickMessage());
}
}

View File

@ -0,0 +1,28 @@
package com.minexd.zoot.profile;
import com.qrakn.honcho.command.adapter.CommandTypeAdapter;
import java.util.ArrayList;
import java.util.List;
public class ProfileTypeAdapter implements CommandTypeAdapter {
public <T> T convert(String string, Class<T> type) {
return type.cast(Profile.getByUsername(string));
}
@Override
public <T> List<String> tabComplete(String string, Class<T> type) {
List<String> completed = new ArrayList<>();
for (Profile profile : Profile.getProfiles().values()) {
if (profile.getUsername() == null) continue;
if (profile.getUsername().toLowerCase().startsWith(string.toLowerCase())) {
completed.add(profile.getUsername());
}
}
return completed;
}
}

View File

@ -0,0 +1,90 @@
package com.minexd.zoot.profile.conversation;
import com.minexd.zoot.Locale;
import com.minexd.zoot.ZootAPI;
import com.minexd.zoot.profile.Profile;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import java.util.UUID;
public class Conversation {
@Getter private final UUID initiatedBy;
@Getter private final UUID target;
@Getter private long lastMessageSentAt;
@Getter private UUID lastMessageSentBy;
public Conversation(UUID initiatedBy, UUID target) {
this.initiatedBy = initiatedBy;
this.target = target;
this.lastMessageSentAt = System.currentTimeMillis();
Profile initiatorProfile = Profile.getByUuid(initiatedBy);
initiatorProfile.getConversations().getConversations().put(target, this);
Profile targetProfile = Profile.getByUuid(target);
targetProfile.getConversations().getConversations().put(initiatedBy, this);
}
public void sendMessage(Player sender, Player target, String message) {
sender.sendMessage(Locale.CONVERSATION_SEND_MESSAGE.format(
sender.getName(), sender.getDisplayName(), ZootAPI.getColorOfPlayer(sender),
target.getName(), target.getDisplayName(), ZootAPI.getColorOfPlayer(target))
.replace("%MSG%", message));
Profile targetProfile = Profile.getByUuid(target.getUniqueId());
if (targetProfile.getOptions().playingMessageSounds()) {
target.playSound(target.getLocation(), Sound.SUCCESSFUL_HIT, 1.0F, 1.0F);
}
target.sendMessage(Locale.CONVERSATION_RECEIVE_MESSAGE.format(
target.getName(), target.getDisplayName(), ZootAPI.getColorOfPlayer(target),
sender.getName(), sender.getDisplayName(), ZootAPI.getColorOfPlayer(sender))
.replace("%MSG%", message));
lastMessageSentAt = System.currentTimeMillis();
lastMessageSentBy = sender.getUniqueId();
}
public boolean validate() {
Player initiator = Bukkit.getPlayer(initiatedBy);
if (initiator == null || !initiator.isOnline()) {
destroy();
return false;
}
Player target = Bukkit.getPlayer(this.target);
if (target == null || !target.isOnline()) {
destroy();
return false;
}
return true;
}
public void destroy() {
for (Player player : new Player[] { Bukkit.getPlayer(initiatedBy), Bukkit.getPlayer(target) }) {
if (player != null && player.isOnline()) {
Profile profile = Profile.getByUuid(player.getUniqueId());
profile.getConversations().getConversations().remove(getPartner(player.getUniqueId()));
}
}
}
public UUID getPartner(UUID compareWith) {
if (initiatedBy.equals(compareWith)) {
return target;
} else if (target.equals(compareWith)) {
return initiatedBy;
}
return null;
}
}

View File

@ -0,0 +1,61 @@
package com.minexd.zoot.profile.conversation;
import com.minexd.zoot.profile.Profile;
import java.util.*;
import java.util.stream.Collectors;
import lombok.Getter;
import org.bukkit.entity.Player;
public class ProfileConversations {
@Getter private final Profile profile;
@Getter private Map<UUID, Conversation> conversations;
public ProfileConversations(Profile profile) {
this.profile = profile;
this.conversations = new HashMap<>();
}
public boolean canBeMessagedBy(Player player) {
if (!profile.getOptions().receivingNewConversations()) {
return conversations.containsKey(player.getUniqueId());
}
return true;
}
public Conversation getOrCreateConversation(Player target) {
Player sender = profile.getPlayer();
if (sender != null) {
Conversation conversation = conversations.get(target.getUniqueId());
if (conversation == null) {
conversation = new Conversation(profile.getUuid(), target.getUniqueId());
}
return conversation;
}
return null;
}
public Conversation getLastRepliedConversation() {
List<Conversation> list = conversations
.values()
.stream()
.sorted(Comparator.comparingLong(Conversation::getLastMessageSentAt))
.collect(Collectors.toList());
Collections.reverse(list);
return list.isEmpty() ? null : list.get(0);
}
public void expireAllConversations() {
this.conversations.clear();
}
}

View File

@ -0,0 +1,39 @@
package com.minexd.zoot.profile.conversation.command;
import com.minexd.zoot.profile.Profile;
import com.minexd.zoot.profile.conversation.Conversation;
import com.minexd.zoot.util.CC;
import com.qrakn.honcho.command.CommandMeta;
import org.bukkit.entity.Player;
@CommandMeta(label = { "message", "msg", "whisper", "tell", "t" })
public class MessageCommand {
public void execute(Player player, Player target, String message) {
if (player.equals(target)) {
player.sendMessage(CC.RED + "You cannot message yourself!");
return;
}
if (target == null) {
player.sendMessage(CC.RED + "A player with that name could not be found.");
return;
}
Profile playerProfile = Profile.getByUuid(player.getUniqueId());
Profile targetProfile = Profile.getByUuid(target.getUniqueId());
if (targetProfile.getConversations().canBeMessagedBy(player)) {
Conversation conversation = playerProfile.getConversations().getOrCreateConversation(target);
if (conversation.validate()) {
conversation.sendMessage(player, target, message);
} else {
player.sendMessage(CC.RED + "That player is not receiving new conversations right now.");
}
} else {
player.sendMessage(CC.RED + "That player is not receiving new conversations right now.");
}
}
}

View File

@ -0,0 +1,28 @@
package com.minexd.zoot.profile.conversation.command;
import com.minexd.zoot.profile.Profile;
import com.minexd.zoot.profile.conversation.Conversation;
import com.minexd.zoot.util.CC;
import com.qrakn.honcho.command.CommandMeta;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@CommandMeta(label = { "reply", "r" })
public class ReplyCommand {
public void execute(Player player, String message) {
Profile playerProfile = Profile.getByUuid(player.getUniqueId());
Conversation conversation = playerProfile.getConversations().getLastRepliedConversation();
if (conversation != null) {
if (conversation.validate()) {
conversation.sendMessage(player, Bukkit.getPlayer(conversation.getPartner(player.getUniqueId())), message);
} else {
player.sendMessage(CC.RED + "You can no longer reply to that player.");
}
} else {
player.sendMessage(CC.RED + "You have nobody to reply to.");
}
}
}

View File

@ -0,0 +1,68 @@
package com.minexd.zoot.profile.grant;
import com.minexd.zoot.rank.Rank;
import com.minexd.zoot.util.TimeUtil;
import java.util.Date;
import java.util.UUID;
import lombok.Getter;
import lombok.Setter;
public class Grant {
public static GrantJsonSerializer SERIALIZER = new GrantJsonSerializer();
public static GrantJsonDeserializer DESERIALIZER = new GrantJsonDeserializer();
@Getter private final UUID uuid;
@Getter private final Rank rank;
@Getter @Setter private UUID addedBy;
@Getter private final long addedAt;
@Getter private final String addedReason;
@Getter private final long duration;
@Getter @Setter private UUID removedBy;
@Getter @Setter private long removedAt;
@Getter @Setter private String removedReason;
@Getter @Setter private boolean removed;
public Grant(UUID uuid, Rank rank, UUID addedBy, long addedAt, String addedReason, long duration) {
this.uuid = uuid;
this.rank = rank;
this.addedBy = addedBy;
this.addedAt = addedAt;
this.addedReason = addedReason;
this.duration = duration;
}
public boolean isPermanent() {
return duration == Integer.MAX_VALUE;
}
public boolean hasExpired() {
return (!isPermanent()) && (System.currentTimeMillis() >= addedAt + duration);
}
public String getExpiresAtDate() {
if (duration == Integer.MAX_VALUE) {
return "Never";
}
return TimeUtil.dateToString(new Date(addedAt + duration), "&7");
}
public String getDurationText() {
if (removed) {
return "Removed";
}
if (isPermanent()) {
return "Permanent";
}
return TimeUtil.millisToRoundedTime(duration);
}
@Override
public boolean equals(Object object) {
return object instanceof Grant && ((Grant) object).uuid.equals(uuid);
}
}

Some files were not shown because too many files have changed in this diff Show More