Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2bc14973af | ||
|
|
7d3e2a04b2 | ||
|
|
ec716782e2 | ||
|
|
d67e0015b6 | ||
|
|
cb4b081672 | ||
|
|
30e33a4e58 | ||
|
|
7ca3bc7379 | ||
|
|
6dfe3195cd | ||
|
|
3e9626f67a | ||
|
|
5ca44c3419 | ||
|
|
3df7778efc | ||
|
|
95482305f3 |
146
.gitignore
vendored
146
.gitignore
vendored
@@ -1,9 +1,143 @@
|
|||||||
|
# Created by https://www.gitignore.io/api/java,linux,gradle,intellij
|
||||||
|
# Edit at https://www.gitignore.io/?templates=java,linux,gradle,intellij
|
||||||
|
|
||||||
|
### Intellij ###
|
||||||
|
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
|
||||||
|
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||||
|
|
||||||
|
# User-specific stuff
|
||||||
|
.idea/**/workspace.xml
|
||||||
|
.idea/**/tasks.xml
|
||||||
|
.idea/**/usage.statistics.xml
|
||||||
|
.idea/**/dictionaries
|
||||||
|
.idea/**/shelf
|
||||||
|
|
||||||
|
# Generated files
|
||||||
|
.idea/**/contentModel.xml
|
||||||
|
|
||||||
|
# Sensitive or high-churn files
|
||||||
|
.idea/**/dataSources/
|
||||||
|
.idea/**/dataSources.ids
|
||||||
|
.idea/**/dataSources.local.xml
|
||||||
|
.idea/**/sqlDataSources.xml
|
||||||
|
.idea/**/dynamic.xml
|
||||||
|
.idea/**/uiDesigner.xml
|
||||||
|
.idea/**/dbnavigator.xml
|
||||||
|
|
||||||
|
# Gradle
|
||||||
|
.idea/**/gradle.xml
|
||||||
|
.idea/**/libraries
|
||||||
|
|
||||||
|
# Gradle and Maven with auto-import
|
||||||
|
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||||
|
# since they will be recreated, and may cause churn. Uncomment if using
|
||||||
|
# auto-import.
|
||||||
|
# .idea/modules.xml
|
||||||
|
# .idea/*.iml
|
||||||
|
# .idea/modules
|
||||||
|
|
||||||
|
# CMake
|
||||||
|
cmake-build-*/
|
||||||
|
|
||||||
|
# Mongo Explorer plugin
|
||||||
|
.idea/**/mongoSettings.xml
|
||||||
|
|
||||||
|
# File-based project format
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
out/
|
||||||
|
|
||||||
|
# mpeltonen/sbt-idea plugin
|
||||||
|
.idea_modules/
|
||||||
|
|
||||||
|
# JIRA plugin
|
||||||
|
atlassian-ide-plugin.xml
|
||||||
|
|
||||||
|
# Cursive Clojure plugin
|
||||||
|
.idea/replstate.xml
|
||||||
|
|
||||||
|
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||||
|
com_crashlytics_export_strings.xml
|
||||||
|
crashlytics.properties
|
||||||
|
crashlytics-build.properties
|
||||||
|
fabric.properties
|
||||||
|
|
||||||
|
# Editor-based Rest Client
|
||||||
|
.idea/httpRequests
|
||||||
|
|
||||||
|
# Android studio 3.1+ serialized cache file
|
||||||
|
.idea/caches/build_file_checksums.ser
|
||||||
|
|
||||||
|
### Intellij Patch ###
|
||||||
|
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
|
||||||
|
|
||||||
|
# *.iml
|
||||||
|
# modules.xml
|
||||||
|
# .idea/misc.xml
|
||||||
|
# *.ipr
|
||||||
|
|
||||||
|
# Sonarlint plugin
|
||||||
|
.idea/sonarlint
|
||||||
|
|
||||||
|
### Java ###
|
||||||
|
# Compiled class file
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Log file
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# BlueJ files
|
||||||
|
*.ctxt
|
||||||
|
|
||||||
|
# Mobile Tools for Java (J2ME)
|
||||||
|
.mtj.tmp/
|
||||||
|
|
||||||
|
# Package Files #
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.nar
|
||||||
|
*.ear
|
||||||
|
*.zip
|
||||||
|
*.tar.gz
|
||||||
|
*.rar
|
||||||
|
|
||||||
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
|
hs_err_pid*
|
||||||
|
|
||||||
|
### Linux ###
|
||||||
|
*~
|
||||||
|
|
||||||
|
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||||
|
.fuse_hidden*
|
||||||
|
|
||||||
|
# KDE directory preferences
|
||||||
|
.directory
|
||||||
|
|
||||||
|
# Linux trash folder which might appear on any partition or disk
|
||||||
|
.Trash-*
|
||||||
|
|
||||||
|
# .nfs files are created when an open file is removed but is still being accessed
|
||||||
|
.nfs*
|
||||||
|
|
||||||
|
### Gradle ###
|
||||||
.gradle
|
.gradle
|
||||||
.classpath
|
build/
|
||||||
.project
|
bin/
|
||||||
.idea
|
|
||||||
|
|
||||||
/.settings/
|
# Ignore Gradle GUI config
|
||||||
|
gradle-app.setting
|
||||||
|
|
||||||
/build/
|
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
||||||
/bin/
|
!gradle-wrapper.jar
|
||||||
|
|
||||||
|
# Cache of project
|
||||||
|
.gradletasknamecache
|
||||||
|
|
||||||
|
# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
|
||||||
|
# gradle/wrapper/gradle-wrapper.properties
|
||||||
|
|
||||||
|
### Gradle Patch ###
|
||||||
|
**/build/
|
||||||
|
|
||||||
|
# End of https://www.gitignore.io/api/java,linux,gradle,intellij
|
||||||
72
.idea/codeStyles/Project.xml
generated
Normal file
72
.idea/codeStyles/Project.xml
generated
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<code_scheme name="Project" version="173">
|
||||||
|
<option name="LINE_SEPARATOR" value=" " />
|
||||||
|
<option name="RIGHT_MARGIN" value="160" />
|
||||||
|
<option name="FORMATTER_TAGS_ENABLED" value="true" />
|
||||||
|
<option name="SOFT_MARGINS" value="120,160" />
|
||||||
|
<JavaCodeStyleSettings>
|
||||||
|
<option name="ALIGN_MULTILINE_ANNOTATION_PARAMETERS" value="true" />
|
||||||
|
<option name="JD_ADD_BLANK_AFTER_PARM_COMMENTS" value="true" />
|
||||||
|
<option name="JD_ADD_BLANK_AFTER_RETURN" value="true" />
|
||||||
|
<option name="JD_DO_NOT_WRAP_ONE_LINE_COMMENTS" value="true" />
|
||||||
|
</JavaCodeStyleSettings>
|
||||||
|
<codeStyleSettings language="JAVA">
|
||||||
|
<option name="ALIGN_MULTILINE_CHAINED_METHODS" value="true" />
|
||||||
|
<option name="ALIGN_MULTILINE_PARAMETERS_IN_CALLS" value="true" />
|
||||||
|
<option name="ALIGN_MULTILINE_BINARY_OPERATION" value="true" />
|
||||||
|
<option name="ALIGN_MULTILINE_ASSIGNMENT" value="true" />
|
||||||
|
<option name="ALIGN_MULTILINE_TERNARY_OPERATION" value="true" />
|
||||||
|
<option name="ALIGN_MULTILINE_THROWS_LIST" value="true" />
|
||||||
|
<option name="ALIGN_MULTILINE_PARENTHESIZED_EXPRESSION" value="true" />
|
||||||
|
<option name="ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION" value="true" />
|
||||||
|
<option name="ALIGN_GROUP_FIELD_DECLARATIONS" value="true" />
|
||||||
|
<option name="ALIGN_CONSECUTIVE_VARIABLE_DECLARATIONS" value="true" />
|
||||||
|
<option name="ALIGN_SUBSEQUENT_SIMPLE_METHODS" value="true" />
|
||||||
|
<option name="SPACE_WITHIN_ARRAY_INITIALIZER_BRACES" value="true" />
|
||||||
|
<option name="SPACE_BEFORE_ARRAY_INITIALIZER_LBRACE" value="true" />
|
||||||
|
<option name="CALL_PARAMETERS_WRAP" value="1" />
|
||||||
|
<option name="CALL_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
|
||||||
|
<option name="CALL_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" />
|
||||||
|
<option name="METHOD_PARAMETERS_WRAP" value="1" />
|
||||||
|
<option name="RESOURCE_LIST_WRAP" value="5" />
|
||||||
|
<option name="THROWS_LIST_WRAP" value="1" />
|
||||||
|
<option name="EXTENDS_KEYWORD_WRAP" value="1" />
|
||||||
|
<option name="THROWS_KEYWORD_WRAP" value="1" />
|
||||||
|
<option name="METHOD_CALL_CHAIN_WRAP" value="5" />
|
||||||
|
<option name="WRAP_FIRST_METHOD_IN_CALL_CHAIN" value="true" />
|
||||||
|
<option name="TERNARY_OPERATION_WRAP" value="5" />
|
||||||
|
<option name="TERNARY_OPERATION_SIGNS_ON_NEXT_LINE" value="true" />
|
||||||
|
<option name="KEEP_SIMPLE_BLOCKS_IN_ONE_LINE" value="true" />
|
||||||
|
<option name="KEEP_SIMPLE_METHODS_IN_ONE_LINE" value="true" />
|
||||||
|
<option name="KEEP_SIMPLE_LAMBDAS_IN_ONE_LINE" value="true" />
|
||||||
|
<option name="KEEP_SIMPLE_CLASSES_IN_ONE_LINE" value="true" />
|
||||||
|
<option name="KEEP_MULTIPLE_EXPRESSIONS_IN_ONE_LINE" value="true" />
|
||||||
|
<option name="FOR_STATEMENT_WRAP" value="5" />
|
||||||
|
<option name="ARRAY_INITIALIZER_WRAP" value="5" />
|
||||||
|
<option name="ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE" value="true" />
|
||||||
|
<option name="ARRAY_INITIALIZER_RBRACE_ON_NEXT_LINE" value="true" />
|
||||||
|
<option name="ASSERT_STATEMENT_WRAP" value="1" />
|
||||||
|
<option name="ASSERT_STATEMENT_COLON_ON_NEXT_LINE" value="true" />
|
||||||
|
<option name="DOWHILE_BRACE_FORCE" value="1" />
|
||||||
|
<option name="FOR_BRACE_FORCE" value="1" />
|
||||||
|
<option name="SPACE_BEFORE_ANOTATION_PARAMETER_LIST" value="true" />
|
||||||
|
<option name="ENUM_CONSTANTS_WRAP" value="5" />
|
||||||
|
<indentOptions>
|
||||||
|
<option name="USE_TAB_CHARACTER" value="true" />
|
||||||
|
<option name="SMART_TABS" value="true" />
|
||||||
|
</indentOptions>
|
||||||
|
<arrangement>
|
||||||
|
<groups>
|
||||||
|
<group>
|
||||||
|
<type>GETTERS_AND_SETTERS</type>
|
||||||
|
<order>KEEP</order>
|
||||||
|
</group>
|
||||||
|
<group>
|
||||||
|
<type>DEPENDENT_METHODS</type>
|
||||||
|
<order>BREADTH_FIRST</order>
|
||||||
|
</group>
|
||||||
|
</groups>
|
||||||
|
</arrangement>
|
||||||
|
</codeStyleSettings>
|
||||||
|
</code_scheme>
|
||||||
|
</component>
|
||||||
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<state>
|
||||||
|
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||||
|
</state>
|
||||||
|
</component>
|
||||||
9
.idea/compiler.xml
generated
Normal file
9
.idea/compiler.xml
generated
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<bytecodeTargetLevel>
|
||||||
|
<module name="ModuleLoader.main" target="1.8" />
|
||||||
|
<module name="ModuleLoader.test" target="1.8" />
|
||||||
|
</bytecodeTargetLevel>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
4
.idea/encodings.xml
generated
Normal file
4
.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
|
||||||
|
</project>
|
||||||
26
.idea/misc.xml
generated
Normal file
26
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectInspectionProfilesVisibleTreeState">
|
||||||
|
<entry key="Project Default">
|
||||||
|
<profile-state>
|
||||||
|
<expanded-state>
|
||||||
|
<State />
|
||||||
|
<State>
|
||||||
|
<id>Manifest</id>
|
||||||
|
</State>
|
||||||
|
<State>
|
||||||
|
<id>Spelling</id>
|
||||||
|
</State>
|
||||||
|
</expanded-state>
|
||||||
|
<selected-state>
|
||||||
|
<State>
|
||||||
|
<id>SpellCheckingInspection</id>
|
||||||
|
</State>
|
||||||
|
</selected-state>
|
||||||
|
</profile-state>
|
||||||
|
</entry>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/classes" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
10
.idea/modules.xml
generated
Normal file
10
.idea/modules.xml
generated
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/ModuleLoader.iml" filepath="$PROJECT_DIR$/ModuleLoader.iml" />
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/modules/ModuleLoader.main.iml" filepath="$PROJECT_DIR$/.idea/modules/ModuleLoader.main.iml" />
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/modules/ModuleLoader.test.iml" filepath="$PROJECT_DIR$/.idea/modules/ModuleLoader.test.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
27
.idea/modules/ModuleLoader.main.iml
generated
Normal file
27
.idea/modules/ModuleLoader.main.iml
generated
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module external.linked.project.id="ModuleLoader:main" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="" external.system.module.type="sourceSet" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||||
|
<output url="file://$MODULE_DIR$/../../out/production/classes" />
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$/../../src/main">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/../../src/main/java" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/../../src/main/resources" type="java-resource" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="Gradle: org.apache.logging.log4j:log4j-1.2-api:2.11.1" level="project" />
|
||||||
|
<orderEntry type="library" name="Gradle: com.github.RedstonerServer:CommandManager:v1" level="project" />
|
||||||
|
<orderEntry type="library" name="Gradle: com.github.RedstonerServer:ChatAPI:v1" level="project" />
|
||||||
|
<orderEntry type="library" name="Gradle: org.apache.logging.log4j:log4j-core:2.11.1" level="project" />
|
||||||
|
<orderEntry type="library" name="Gradle: org.apache.logging.log4j:log4j-api:2.11.1" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Gradle: com.google.code.gson:gson:2.8.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Gradle: commons-lang:commons-lang:2.6" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Gradle: org.yaml:snakeyaml:1.23" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Gradle: org.hamcrest:hamcrest-core:1.1" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Gradle: org.spigotmc:spigot-api:1.13.2-R0.1-SNAPSHOT" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Gradle: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Gradle: junit:junit:4.10" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Gradle: net.md-5:bungeecord-chat:1.13-SNAPSHOT" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Gradle: com.google.guava:guava:21.0" level="project" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
17
.idea/modules/ModuleLoader.test.iml
generated
Normal file
17
.idea/modules/ModuleLoader.test.iml
generated
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module external.linked.project.id="ModuleLoader:test" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="" external.system.module.type="sourceSet" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||||
|
<output-test url="file://$MODULE_DIR$/../../out/test/classes" />
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$/../../src/test" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="module" module-name="ModuleLoader.main" />
|
||||||
|
<orderEntry type="library" name="Gradle: org.apache.logging.log4j:log4j-1.2-api:2.11.1" level="project" />
|
||||||
|
<orderEntry type="library" name="Gradle: com.github.RedstonerServer:CommandManager:v1" level="project" />
|
||||||
|
<orderEntry type="library" name="Gradle: com.github.RedstonerServer:ChatAPI:v1" level="project" />
|
||||||
|
<orderEntry type="library" name="Gradle: org.apache.logging.log4j:log4j-core:2.11.1" level="project" />
|
||||||
|
<orderEntry type="library" name="Gradle: org.apache.logging.log4j:log4j-api:2.11.1" level="project" />
|
||||||
|
</component>
|
||||||
|
<component name="TestModuleProperties" production-module="ModuleLoader.main" />
|
||||||
|
</module>
|
||||||
116
LICENSE.txt
Normal file
116
LICENSE.txt
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
CC0 1.0 Universal
|
||||||
|
|
||||||
|
Statement of Purpose
|
||||||
|
|
||||||
|
The laws of most jurisdictions throughout the world automatically confer
|
||||||
|
exclusive Copyright and Related Rights (defined below) upon the creator and
|
||||||
|
subsequent owner(s) (each and all, an "owner") of an original work of
|
||||||
|
authorship and/or a database (each, a "Work").
|
||||||
|
|
||||||
|
Certain owners wish to permanently relinquish those rights to a Work for the
|
||||||
|
purpose of contributing to a commons of creative, cultural and scientific
|
||||||
|
works ("Commons") that the public can reliably and without fear of later
|
||||||
|
claims of infringement build upon, modify, incorporate in other works, reuse
|
||||||
|
and redistribute as freely as possible in any form whatsoever and for any
|
||||||
|
purposes, including without limitation commercial purposes. These owners may
|
||||||
|
contribute to the Commons to promote the ideal of a free culture and the
|
||||||
|
further production of creative, cultural and scientific works, or to gain
|
||||||
|
reputation or greater distribution for their Work in part through the use and
|
||||||
|
efforts of others.
|
||||||
|
|
||||||
|
For these and/or other purposes and motivations, and without any expectation
|
||||||
|
of additional consideration or compensation, the person associating CC0 with a
|
||||||
|
Work (the "Affirmer"), to the extent that he or she is an owner of Copyright
|
||||||
|
and Related Rights in the Work, voluntarily elects to apply CC0 to the Work
|
||||||
|
and publicly distribute the Work under its terms, with knowledge of his or her
|
||||||
|
Copyright and Related Rights in the Work and the meaning and intended legal
|
||||||
|
effect of CC0 on those rights.
|
||||||
|
|
||||||
|
1. Copyright and Related Rights. A Work made available under CC0 may be
|
||||||
|
protected by copyright and related or neighboring rights ("Copyright and
|
||||||
|
Related Rights"). Copyright and Related Rights include, but are not limited
|
||||||
|
to, the following:
|
||||||
|
|
||||||
|
i. the right to reproduce, adapt, distribute, perform, display, communicate,
|
||||||
|
and translate a Work;
|
||||||
|
|
||||||
|
ii. moral rights retained by the original author(s) and/or performer(s);
|
||||||
|
|
||||||
|
iii. publicity and privacy rights pertaining to a person's image or likeness
|
||||||
|
depicted in a Work;
|
||||||
|
|
||||||
|
iv. rights protecting against unfair competition in regards to a Work,
|
||||||
|
subject to the limitations in paragraph 4(a), below;
|
||||||
|
|
||||||
|
v. rights protecting the extraction, dissemination, use and reuse of data in
|
||||||
|
a Work;
|
||||||
|
|
||||||
|
vi. database rights (such as those arising under Directive 96/9/EC of the
|
||||||
|
European Parliament and of the Council of 11 March 1996 on the legal
|
||||||
|
protection of databases, and under any national implementation thereof,
|
||||||
|
including any amended or successor version of such directive); and
|
||||||
|
|
||||||
|
vii. other similar, equivalent or corresponding rights throughout the world
|
||||||
|
based on applicable law or treaty, and any national implementations thereof.
|
||||||
|
|
||||||
|
2. Waiver. To the greatest extent permitted by, but not in contravention of,
|
||||||
|
applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
|
||||||
|
unconditionally waives, abandons, and surrenders all of Affirmer's Copyright
|
||||||
|
and Related Rights and associated claims and causes of action, whether now
|
||||||
|
known or unknown (including existing as well as future claims and causes of
|
||||||
|
action), in the Work (i) in all territories worldwide, (ii) for the maximum
|
||||||
|
duration provided by applicable law or treaty (including future time
|
||||||
|
extensions), (iii) in any current or future medium and for any number of
|
||||||
|
copies, and (iv) for any purpose whatsoever, including without limitation
|
||||||
|
commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes
|
||||||
|
the Waiver for the benefit of each member of the public at large and to the
|
||||||
|
detriment of Affirmer's heirs and successors, fully intending that such Waiver
|
||||||
|
shall not be subject to revocation, rescission, cancellation, termination, or
|
||||||
|
any other legal or equitable action to disrupt the quiet enjoyment of the Work
|
||||||
|
by the public as contemplated by Affirmer's express Statement of Purpose.
|
||||||
|
|
||||||
|
3. Public License Fallback. Should any part of the Waiver for any reason be
|
||||||
|
judged legally invalid or ineffective under applicable law, then the Waiver
|
||||||
|
shall be preserved to the maximum extent permitted taking into account
|
||||||
|
Affirmer's express Statement of Purpose. In addition, to the extent the Waiver
|
||||||
|
is so judged Affirmer hereby grants to each affected person a royalty-free,
|
||||||
|
non transferable, non sublicensable, non exclusive, irrevocable and
|
||||||
|
unconditional license to exercise Affirmer's Copyright and Related Rights in
|
||||||
|
the Work (i) in all territories worldwide, (ii) for the maximum duration
|
||||||
|
provided by applicable law or treaty (including future time extensions), (iii)
|
||||||
|
in any current or future medium and for any number of copies, and (iv) for any
|
||||||
|
purpose whatsoever, including without limitation commercial, advertising or
|
||||||
|
promotional purposes (the "License"). The License shall be deemed effective as
|
||||||
|
of the date CC0 was applied by Affirmer to the Work. Should any part of the
|
||||||
|
License for any reason be judged legally invalid or ineffective under
|
||||||
|
applicable law, such partial invalidity or ineffectiveness shall not
|
||||||
|
invalidate the remainder of the License, and in such case Affirmer hereby
|
||||||
|
affirms that he or she will not (i) exercise any of his or her remaining
|
||||||
|
Copyright and Related Rights in the Work or (ii) assert any associated claims
|
||||||
|
and causes of action with respect to the Work, in either case contrary to
|
||||||
|
Affirmer's express Statement of Purpose.
|
||||||
|
|
||||||
|
4. Limitations and Disclaimers.
|
||||||
|
|
||||||
|
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
||||||
|
surrendered, licensed or otherwise affected by this document.
|
||||||
|
|
||||||
|
b. Affirmer offers the Work as-is and makes no representations or warranties
|
||||||
|
of any kind concerning the Work, express, implied, statutory or otherwise,
|
||||||
|
including without limitation warranties of title, merchantability, fitness
|
||||||
|
for a particular purpose, non infringement, or the absence of latent or
|
||||||
|
other defects, accuracy, or the present or absence of errors, whether or not
|
||||||
|
discoverable, all to the greatest extent permissible under applicable law.
|
||||||
|
|
||||||
|
c. Affirmer disclaims responsibility for clearing rights of other persons
|
||||||
|
that may apply to the Work or any use thereof, including without limitation
|
||||||
|
any person's Copyright and Related Rights in the Work. Further, Affirmer
|
||||||
|
disclaims responsibility for obtaining any necessary consents, permissions
|
||||||
|
or other rights required for any use of the Work.
|
||||||
|
|
||||||
|
d. Affirmer understands and acknowledges that Creative Commons is not a
|
||||||
|
party to this document and has no duty or obligation with respect to this
|
||||||
|
CC0 or use of the Work.
|
||||||
|
|
||||||
|
For more information, please see
|
||||||
|
<http://creativecommons.org/publicdomain/zero/1.0/>
|
||||||
13
ModuleLoader.iml
Normal file
13
ModuleLoader.iml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module external.linked.project.id="ModuleLoader" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/out" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
19
build.gradle
19
build.gradle
@@ -19,9 +19,8 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "com.github.RedstonerServer:CommandManager:master-SNAPSHOT"
|
implementation "com.github.RedstonerServer:CommandManager:v1"
|
||||||
implementation "com.github.RedstonerServer:ChatAPI:master-SNAPSHOT"
|
implementation "com.github.RedstonerServer:ChatAPI:v1"
|
||||||
implementation "com.github.RedstonerServer:ChestAPI:master-SNAPSHOT"
|
|
||||||
|
|
||||||
compile group: 'org.apache.logging.log4j', name: 'log4j-1.2-api', version: '2.11.1'
|
compile group: 'org.apache.logging.log4j', name: 'log4j-1.2-api', version: '2.11.1'
|
||||||
|
|
||||||
@@ -30,7 +29,7 @@ dependencies {
|
|||||||
|
|
||||||
jar {
|
jar {
|
||||||
manifest {
|
manifest {
|
||||||
attributes "Class-Path": "../lib/CommandManager.jar ../lib/ChatAPI.jar ../lib/ChestAPI.jar"
|
attributes "Class-Path": "../lib/CommandManager.jar ../lib/ChatAPI.jar"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,3 +37,15 @@ task sourceJar(type: Jar, dependsOn: classes) {
|
|||||||
classifier 'sources'
|
classifier 'sources'
|
||||||
from sourceSets.main.allSource
|
from sourceSets.main.allSource
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
main {
|
||||||
|
resources {
|
||||||
|
srcDir 'src/main/java'
|
||||||
|
include '**/*.cmd'
|
||||||
|
|
||||||
|
srcDir 'src/main/resources'
|
||||||
|
include '**/*.yml'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,11 +5,12 @@ import java.lang.annotation.Retention;
|
|||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
/** The auto register annotation, to be put onto Classes that implement listener when you are too lazy to register the events yourself.
|
/**
|
||||||
|
* The auto register annotation, to be put onto Classes that implement listener when you are too lazy to register the events yourself.
|
||||||
*
|
*
|
||||||
* @author Pepich */
|
* @author Pepich
|
||||||
@Target(ElementType.TYPE)
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Target (ElementType.TYPE)
|
||||||
@Version(major = 1, minor = 0, revision = 1, compatible = 1)
|
@Retention (RetentionPolicy.RUNTIME)
|
||||||
public @interface AutoRegisterListener
|
@Version (major = 1, minor = 0, revision = 1, compatible = 1)
|
||||||
{}
|
public @interface AutoRegisterListener {}
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
package com.redstoner.annotations;
|
package com.redstoner.annotations;
|
||||||
|
|
||||||
|
import com.redstoner.misc.CommandHolderType;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
import com.redstoner.misc.CommandHolderType;
|
@Target (ElementType.TYPE)
|
||||||
|
@Retention (RetentionPolicy.RUNTIME)
|
||||||
@Target(ElementType.TYPE)
|
public @interface Commands {
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
public @interface Commands
|
|
||||||
{
|
|
||||||
CommandHolderType value();
|
CommandHolderType value();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +1,33 @@
|
|||||||
package com.redstoner.annotations;
|
package com.redstoner.annotations;
|
||||||
|
|
||||||
import java.lang.annotation.Documented;
|
import java.lang.annotation.*;
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
/** The Version annotation, to be applied to all Classes that are part of the project.
|
/**
|
||||||
|
* The Version annotation, to be applied to all Classes that are part of the project.
|
||||||
*
|
*
|
||||||
* @author Pepich */
|
* @author Pepich
|
||||||
@Target(ElementType.TYPE)
|
*/
|
||||||
|
@Target (ElementType.TYPE)
|
||||||
@Documented
|
@Documented
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention (RetentionPolicy.RUNTIME)
|
||||||
public @interface Version
|
public @interface Version {
|
||||||
{
|
/**
|
||||||
/** The major indicator of the version. Will be used for compatibility detection.
|
* The major indicator of the version. Will be used for compatibility detection.
|
||||||
*
|
*
|
||||||
* @return the major version as an int */
|
* @return the major version as an int
|
||||||
|
*/
|
||||||
int major();
|
int major();
|
||||||
|
|
||||||
int minor();
|
int minor();
|
||||||
|
|
||||||
int revision();
|
int revision();
|
||||||
|
|
||||||
/** The compatibility part of the version number. Will be used for compatibility detection.</br>
|
/**
|
||||||
|
* The compatibility part of the version number. Will be used for compatibility detection.</br>
|
||||||
* Set to -1 if it is supposed to be always compatible.</br>
|
* Set to -1 if it is supposed to be always compatible.</br>
|
||||||
* Defaults to 1.
|
* Defaults to 1.
|
||||||
*
|
*
|
||||||
* @return the smallest compatible version as an int. */
|
* @return the smallest compatible version as an int.
|
||||||
|
*/
|
||||||
int compatible() default 1;
|
int compatible() default 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,22 @@ command modules {
|
|||||||
perm moduleloader.modules.list;
|
perm moduleloader.modules.list;
|
||||||
run list;
|
run list;
|
||||||
}
|
}
|
||||||
|
-v {
|
||||||
|
help Lists all modules and their versions. Color indicates status: §aENABLED §cDISABLED;
|
||||||
|
perm moduleloader.modules.list;
|
||||||
|
run listversions;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
list {
|
list {
|
||||||
help Lists all modules. Color indicates status: §aENABLED §cDISABLED;
|
help Lists all modules. Color indicates status: §aENABLED §cDISABLED;
|
||||||
perm moduleloader.modules.list;
|
perm moduleloader.modules.list;
|
||||||
run list;
|
run list;
|
||||||
|
}
|
||||||
|
list -v {
|
||||||
|
help Lists all modules and their versions. Color indicates status: §aENABLED §cDISABLED;
|
||||||
|
perm moduleloader.modules.list;
|
||||||
|
run listversions;
|
||||||
}
|
}
|
||||||
load [string:name...] {
|
load [string:name...] {
|
||||||
help (Re)-Loads a module. WARNING: Handle with care! This has direct affect on code being executed. This command will temporarily halt the main thread until the class loading operation was completed.;
|
help (Re)-Loads a module. WARNING: Handle with care! This has direct affect on code being executed. This command will temporarily halt the main thread until the class loading operation was completed.;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -2,21 +2,20 @@ package com.redstoner.exceptions;
|
|||||||
|
|
||||||
import com.redstoner.annotations.Version;
|
import com.redstoner.annotations.Version;
|
||||||
|
|
||||||
/** To be thrown when a module is not annotated with its version. If this gets thrown, then oh boy, you're in trouble now.
|
/**
|
||||||
|
* To be thrown when a module is not annotated with its version. If this gets thrown, then oh boy, you're in trouble now.
|
||||||
*
|
*
|
||||||
* @author Pepich */
|
* @author Pepich
|
||||||
@Version(major = 1, minor = 0, revision = 0, compatible = -1)
|
*/
|
||||||
public class MissingVersionException extends Exception
|
@Version (major = 1, minor = 0, revision = 0, compatible = -1)
|
||||||
{
|
public class MissingVersionException extends Exception {
|
||||||
private static final long serialVersionUID = 4940161335512222539L;
|
private static final long serialVersionUID = 4940161335512222539L;
|
||||||
|
|
||||||
public MissingVersionException()
|
public MissingVersionException() {
|
||||||
{
|
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MissingVersionException(String message)
|
public MissingVersionException(String message) {
|
||||||
{
|
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,15 @@ public class Log4JFilter extends AbstractFilter {
|
|||||||
|
|
||||||
private static final long serialVersionUID = -5594073755007974254L;
|
private static final long serialVersionUID = -5594073755007974254L;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result filter(LogEvent event) {
|
||||||
|
Message candidate = null;
|
||||||
|
if (event != null) {
|
||||||
|
candidate = event.getMessage();
|
||||||
|
}
|
||||||
|
return validateMessage(candidate);
|
||||||
|
}
|
||||||
|
|
||||||
private static Result validateMessage(Message message) {
|
private static Result validateMessage(Message message) {
|
||||||
if (message == null) {
|
if (message == null) {
|
||||||
return Result.NEUTRAL;
|
return Result.NEUTRAL;
|
||||||
@@ -24,15 +33,6 @@ public class Log4JFilter extends AbstractFilter {
|
|||||||
: Result.NEUTRAL;
|
: Result.NEUTRAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Result filter(LogEvent event) {
|
|
||||||
Message candidate = null;
|
|
||||||
if (event != null) {
|
|
||||||
candidate = event.getMessage();
|
|
||||||
}
|
|
||||||
return validateMessage(candidate);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result filter(Logger logger, Level level, Marker marker, Message msg, Throwable t) {
|
public Result filter(Logger logger, Level level, Marker marker, Message msg, Throwable t) {
|
||||||
return validateMessage(msg);
|
return validateMessage(msg);
|
||||||
|
|||||||
@@ -1,23 +1,20 @@
|
|||||||
package com.redstoner.logging;
|
package com.redstoner.logging;
|
||||||
|
|
||||||
|
import com.redstoner.misc.Utils;
|
||||||
|
import com.redstoner.modules.Module;
|
||||||
|
import com.redstoner.modules.ModuleLogger;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
|
|
||||||
import com.redstoner.misc.Utils;
|
|
||||||
import com.redstoner.modules.Module;
|
|
||||||
import com.redstoner.modules.ModuleLogger;
|
|
||||||
|
|
||||||
public class PrivateLogManager {
|
public class PrivateLogManager {
|
||||||
|
|
||||||
private static Map<String, Module> registrar = new HashMap<>();
|
|
||||||
private static Map<String, String> commands = new HashMap<>();
|
|
||||||
|
|
||||||
private static final String ISSUED_COMMAND_TEXT = "issued server command: /";
|
private static final String ISSUED_COMMAND_TEXT = "issued server command: /";
|
||||||
private static final int ISSUED_COMMAND_TEXT_LENGTH = ISSUED_COMMAND_TEXT.length();
|
private static final int ISSUED_COMMAND_TEXT_LENGTH = ISSUED_COMMAND_TEXT.length();
|
||||||
|
private static Map<String, Module> registrar = new HashMap<>();
|
||||||
|
private static Map<String, String> commands = new HashMap<>();
|
||||||
private static ModuleLogger logger;
|
private static ModuleLogger logger;
|
||||||
|
|
||||||
public static void initialize() {
|
public static void initialize() {
|
||||||
@@ -32,7 +29,7 @@ public class PrivateLogManager {
|
|||||||
registrar.put(command, module);
|
registrar.put(command, module);
|
||||||
commands.put(command, replacement);
|
commands.put(command, replacement);
|
||||||
logger.info(module.getClass().getSimpleName() + " registered &e/" + command
|
logger.info(module.getClass().getSimpleName() + " registered &e/" + command
|
||||||
+ (replacement.equals("")? "&7. Command will not be logged!"
|
+ (replacement.equals("") ? "&7. Command will not be logged!"
|
||||||
: "&7, using replacement, &e" + replacement + "&7."));
|
: "&7, using replacement, &e" + replacement + "&7."));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +71,7 @@ public class PrivateLogManager {
|
|||||||
String command = message.substring(index + ISSUED_COMMAND_TEXT_LENGTH);
|
String command = message.substring(index + ISSUED_COMMAND_TEXT_LENGTH);
|
||||||
|
|
||||||
int spaceIndex = command.indexOf(" ");
|
int spaceIndex = command.indexOf(" ");
|
||||||
command = spaceIndex == -1? command.toLowerCase() : command.substring(0, spaceIndex).toLowerCase();
|
command = spaceIndex == -1 ? command.toLowerCase() : command.substring(0, spaceIndex).toLowerCase();
|
||||||
|
|
||||||
String replacement = commands.get(command);
|
String replacement = commands.get(command);
|
||||||
if (replacement == null)
|
if (replacement == null)
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
package com.redstoner.misc;
|
package com.redstoner.misc;
|
||||||
|
|
||||||
|
import com.redstoner.annotations.Version;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import com.redstoner.annotations.Version;
|
/**
|
||||||
|
* Classes implementing this interface can be used to define a filter for the Utils.broadcast method for sending a message to more than one, but less than all users.
|
||||||
/** Classes implementing this interface can be used to define a filter for the Utils.broadcast method for sending a message to more than one, but less than all users.
|
|
||||||
*
|
*
|
||||||
* @author Pepich */
|
* @author Pepich
|
||||||
@Version(major = 1, minor = 0, revision = 0, compatible = 1)
|
*/
|
||||||
public interface BroadcastFilter
|
@Version (major = 1, minor = 0, revision = 0, compatible = 1)
|
||||||
{
|
public interface BroadcastFilter {
|
||||||
public boolean sendTo(CommandSender recipient);
|
public boolean sendTo(CommandSender recipient);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,8 @@ package com.redstoner.misc;
|
|||||||
import com.redstoner.annotations.Version;
|
import com.redstoner.annotations.Version;
|
||||||
|
|
||||||
/** @author Pepich */
|
/** @author Pepich */
|
||||||
@Version(major = 4, minor = 0, revision = 0, compatible = -1)
|
@Version (major = 4, minor = 0, revision = 0, compatible = -1)
|
||||||
public enum CommandHolderType
|
public enum CommandHolderType {
|
||||||
{
|
|
||||||
Stream,
|
Stream,
|
||||||
File,
|
File,
|
||||||
String,
|
String,
|
||||||
|
|||||||
@@ -1,149 +1,144 @@
|
|||||||
package com.redstoner.misc;
|
package com.redstoner.misc;
|
||||||
|
|
||||||
|
import com.redstoner.annotations.Version;
|
||||||
|
import org.json.simple.JSONArray;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
import org.json.simple.parser.JSONParser;
|
||||||
|
import org.json.simple.parser.ParseException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.json.simple.JSONArray;
|
/**
|
||||||
import org.json.simple.JSONObject;
|
* This class provides simple JSON handling, like storing and loading from and to files.
|
||||||
import org.json.simple.parser.JSONParser;
|
|
||||||
import org.json.simple.parser.ParseException;
|
|
||||||
|
|
||||||
import com.redstoner.annotations.Version;
|
|
||||||
|
|
||||||
/** This class provides simple JSON handling, like storing and loading from and to files.
|
|
||||||
*
|
*
|
||||||
* @author Pepich */
|
* @author Pepich
|
||||||
@Version(major = 1, minor = 0, revision = 2, compatible = -1)
|
*/
|
||||||
public class JsonManager
|
@Version (major = 1, minor = 0, revision = 2, compatible = -1)
|
||||||
{
|
public class JsonManager {
|
||||||
private JsonManager()
|
private JsonManager() {}
|
||||||
{}
|
|
||||||
|
|
||||||
/** Loads a JSONObject from a file.
|
/**
|
||||||
|
* Loads a JSONObject from a file.
|
||||||
*
|
*
|
||||||
* @param source the file to load from.
|
* @param source the file to load from.
|
||||||
* @return the JSONObject or null if the source does not contain a valid JSONObject. */
|
*
|
||||||
public static JSONObject getObject(File source)
|
* @return the JSONObject or null if the source does not contain a valid JSONObject.
|
||||||
{
|
*/
|
||||||
|
public static JSONObject getObject(File source) {
|
||||||
if (!source.exists())
|
if (!source.exists())
|
||||||
return null;
|
return null;
|
||||||
JSONParser parser = new JSONParser();
|
JSONParser parser = new JSONParser();
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
FileReader reader = new FileReader(source);
|
FileReader reader = new FileReader(source);
|
||||||
Object rawObject = parser.parse(reader);
|
Object rawObject = parser.parse(reader);
|
||||||
reader.close();
|
reader.close();
|
||||||
JSONObject jsonObject = (JSONObject) rawObject;
|
JSONObject jsonObject = (JSONObject) rawObject;
|
||||||
return jsonObject;
|
return jsonObject;
|
||||||
|
} catch (IOException | ParseException e) {
|
||||||
}
|
}
|
||||||
catch (IOException | ParseException e)
|
|
||||||
{}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Saves a JSONObject to a file. Will create the necessary FileStructure like folders and the file itself.</br>
|
/**
|
||||||
|
* Saves a JSONObject to a file. Will create the necessary FileStructure like folders and the file itself.</br>
|
||||||
* Note that this operation will be run on a different thread and you do not need to take care of that yourself.
|
* Note that this operation will be run on a different thread and you do not need to take care of that yourself.
|
||||||
*
|
*
|
||||||
* @param object the JSONObject to save.
|
* @param object the JSONObject to save.
|
||||||
* @param destination the file to write to. */
|
* @param destination the file to write to.
|
||||||
public static void save(JSONObject object, File destination)
|
*/
|
||||||
{
|
public static void save(JSONObject object, File destination) {
|
||||||
Thread t = new Thread(new Runnable()
|
Thread t = new Thread(new Runnable() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
saveSync(object, destination);
|
saveSync(object, destination);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
t.start();
|
t.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Saves a JSONObject to a file. Will create the necessary FileStructure like folders and the file itself.</br>
|
/**
|
||||||
|
* Saves a JSONObject to a file. Will create the necessary FileStructure like folders and the file itself.</br>
|
||||||
* Note that this operation will be run on the same thread that you are calling it from!
|
* Note that this operation will be run on the same thread that you are calling it from!
|
||||||
*
|
*
|
||||||
* @param object the JSONObject to save.
|
* @param object the JSONObject to save.
|
||||||
* @param destination the file to write to. */
|
* @param destination the file to write to.
|
||||||
public static void saveSync(JSONObject object, File destination)
|
*/
|
||||||
{
|
public static void saveSync(JSONObject object, File destination) {
|
||||||
if (destination.exists())
|
if (destination.exists())
|
||||||
destination.delete();
|
destination.delete();
|
||||||
else if (!destination.getParentFile().exists())
|
else if (!destination.getParentFile().exists())
|
||||||
destination.getParentFile().mkdirs();
|
destination.getParentFile().mkdirs();
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
destination.createNewFile();
|
destination.createNewFile();
|
||||||
FileWriter writer = new FileWriter(destination);
|
FileWriter writer = new FileWriter(destination);
|
||||||
String json_string = object.toJSONString();
|
String json_string = object.toJSONString();
|
||||||
writer.write(json_string);
|
writer.write(json_string);
|
||||||
writer.flush();
|
writer.flush();
|
||||||
writer.close();
|
writer.close();
|
||||||
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
|
||||||
{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Loads a JSONArray from a file.
|
/**
|
||||||
|
* Loads a JSONArray from a file.
|
||||||
*
|
*
|
||||||
* @param source the file to load from.
|
* @param source the file to load from.
|
||||||
* @return the JSONArray or null if the source does not contain a valid JSONArray. */
|
*
|
||||||
public static JSONArray getArray(File source)
|
* @return the JSONArray or null if the source does not contain a valid JSONArray.
|
||||||
{
|
*/
|
||||||
|
public static JSONArray getArray(File source) {
|
||||||
if (!source.exists())
|
if (!source.exists())
|
||||||
return null;
|
return null;
|
||||||
JSONParser parser = new JSONParser();
|
JSONParser parser = new JSONParser();
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
Object rawObject = parser.parse(new FileReader(source));
|
Object rawObject = parser.parse(new FileReader(source));
|
||||||
JSONArray jsonArray = (JSONArray) rawObject;
|
JSONArray jsonArray = (JSONArray) rawObject;
|
||||||
return jsonArray;
|
return jsonArray;
|
||||||
|
} catch (IOException | ParseException e) {
|
||||||
}
|
}
|
||||||
catch (IOException | ParseException e)
|
|
||||||
{}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Saves a JSONArray to a file. Will create the necessary FileStructure like folders and the file itself.</br>
|
/**
|
||||||
|
* Saves a JSONArray to a file. Will create the necessary FileStructure like folders and the file itself.</br>
|
||||||
* Note that this operation will be run on a different thread and you do not need to take care of that yourself.
|
* Note that this operation will be run on a different thread and you do not need to take care of that yourself.
|
||||||
*
|
*
|
||||||
* @param object the JSONArray to save.
|
* @param object the JSONArray to save.
|
||||||
* @param destination the file to write to. */
|
* @param destination the file to write to.
|
||||||
public static void save(JSONArray array, File destination)
|
*/
|
||||||
{
|
public static void save(JSONArray array, File destination) {
|
||||||
Thread t = new Thread(new Runnable()
|
Thread t = new Thread(new Runnable() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
saveSync(array, destination);
|
saveSync(array, destination);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
t.start();
|
t.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Saves a JSONArray to a file. Will create the necessary FileStructure like folders and the file itself.</br>
|
/**
|
||||||
|
* Saves a JSONArray to a file. Will create the necessary FileStructure like folders and the file itself.</br>
|
||||||
* Note that this operation will be run on the same thread that you are calling it from!
|
* Note that this operation will be run on the same thread that you are calling it from!
|
||||||
*
|
*
|
||||||
* @param object the JSONArray to save.
|
* @param object the JSONArray to save.
|
||||||
* @param destination the file to write to. */
|
* @param destination the file to write to.
|
||||||
public static void saveSync(JSONArray array, File destination)
|
*/
|
||||||
{
|
public static void saveSync(JSONArray array, File destination) {
|
||||||
if (destination.exists())
|
if (destination.exists())
|
||||||
destination.delete();
|
destination.delete();
|
||||||
else if (!destination.getParentFile().exists())
|
else if (!destination.getParentFile().exists())
|
||||||
destination.getParentFile().mkdirs();
|
destination.getParentFile().mkdirs();
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
destination.createNewFile();
|
destination.createNewFile();
|
||||||
FileWriter writer = new FileWriter(destination);
|
FileWriter writer = new FileWriter(destination);
|
||||||
String json_string = array.toJSONString();
|
String json_string = array.toJSONString();
|
||||||
writer.write(json_string);
|
writer.write(json_string);
|
||||||
writer.flush();
|
writer.flush();
|
||||||
writer.close();
|
writer.close();
|
||||||
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
|
||||||
{}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,23 @@
|
|||||||
package com.redstoner.misc;
|
package com.redstoner.misc;
|
||||||
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import com.redstoner.annotations.Version;
|
import com.redstoner.annotations.Version;
|
||||||
import com.redstoner.coremods.moduleLoader.ModuleLoader;
|
import com.redstoner.coremods.moduleLoader.ModuleLoader;
|
||||||
import com.redstoner.logging.PrivateLogManager;
|
import com.redstoner.logging.PrivateLogManager;
|
||||||
import com.redstoner.misc.mysql.MysqlHandler;
|
import com.redstoner.misc.mysql.MysqlHandler;
|
||||||
|
|
||||||
import net.nemez.chatapi.ChatAPI;
|
import net.nemez.chatapi.ChatAPI;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
/** Main class. Duh.
|
/**
|
||||||
|
* Main class. Duh.
|
||||||
*
|
*
|
||||||
* @author Pepich */
|
* @author Pepich
|
||||||
@Version(major = 5, minor = 1, revision = 0, compatible = -1)
|
*/
|
||||||
public class Main extends JavaPlugin
|
@Version (major = 5, minor = 1, revision = 0, compatible = -1)
|
||||||
{
|
public class Main extends JavaPlugin {
|
||||||
public static JavaPlugin plugin;
|
public static JavaPlugin plugin;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable()
|
public void onEnable() {
|
||||||
{
|
|
||||||
plugin = this;
|
plugin = this;
|
||||||
|
|
||||||
PrivateLogManager.initialize();
|
PrivateLogManager.initialize();
|
||||||
@@ -33,8 +31,7 @@ public class Main extends JavaPlugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable()
|
public void onDisable() {
|
||||||
{
|
|
||||||
ModuleLoader.disableModules();
|
ModuleLoader.disableModules();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
package com.redstoner.misc;
|
package com.redstoner.misc;
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
|
|
||||||
import com.redstoner.coremods.moduleLoader.ModuleLoader;
|
import com.redstoner.coremods.moduleLoader.ModuleLoader;
|
||||||
import com.redstoner.exceptions.MissingVersionException;
|
import com.redstoner.exceptions.MissingVersionException;
|
||||||
import com.redstoner.modules.Module;
|
import com.redstoner.modules.Module;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
public class ModuleInfo {
|
public class ModuleInfo {
|
||||||
|
|
||||||
@@ -28,8 +27,7 @@ public class ModuleInfo {
|
|||||||
displayName = config.getString("displayName");
|
displayName = config.getString("displayName");
|
||||||
category = config.getString("category");
|
category = config.getString("category");
|
||||||
description = config.getString("description");
|
description = config.getString("description");
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
warning = "Descriptor file could not be loaded, using the class's name.";
|
warning = "Descriptor file could not be loaded, using the class's name.";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,12 +44,27 @@ public class ModuleInfo {
|
|||||||
} catch (MissingVersionException e) {}
|
} catch (MissingVersionException e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDisplayName() {
|
||||||
|
return displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWarning() {
|
||||||
|
return warning;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getModuleInfoHover() {
|
||||||
|
return "&8&o" + getSimpleName() + "\n"
|
||||||
|
+ "&r&e" + (getVersion() == null ? "&cVersion Missing" : getVersion())
|
||||||
|
+ "&r&9" + (ModuleLoader.hasCategories() ? "\n" + getCategory() : "")
|
||||||
|
+ "&r&7" + (getDescription() == null ? "" : "\n\n" + getDescription());
|
||||||
|
}
|
||||||
|
|
||||||
public String getSimpleName() {
|
public String getSimpleName() {
|
||||||
return simpleName;
|
return simpleName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDisplayName() {
|
public String getVersion() {
|
||||||
return displayName;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCategory() {
|
public String getCategory() {
|
||||||
@@ -62,20 +75,5 @@ public class ModuleInfo {
|
|||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getWarning() {
|
|
||||||
return warning;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getVersion() {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getModuleInfoHover() {
|
|
||||||
return "&8&o" + getSimpleName() + "\n"
|
|
||||||
+ "&r&e" + (getVersion() == null? "&cVersion Missing" : getVersion())
|
|
||||||
+ "&r&9" + (ModuleLoader.hasCategories()? "\n" + getCategory() : "")
|
|
||||||
+ "&r&7" + (getDescription() == null? "" : "\n\n" + getDescription());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,40 +1,38 @@
|
|||||||
package com.redstoner.misc;
|
package com.redstoner.misc;
|
||||||
|
|
||||||
|
import com.redstoner.annotations.Version;
|
||||||
|
import com.redstoner.coremods.moduleLoader.ModuleLoader;
|
||||||
|
import net.nemez.chatapi.ChatAPI;
|
||||||
|
import net.nemez.chatapi.click.Message;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
/**
|
||||||
import org.bukkit.command.CommandSender;
|
* The utils class containing utility functions. Those include but are not limited to sending formatted messages, broadcasts and more.
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.redstoner.annotations.Version;
|
|
||||||
import com.redstoner.coremods.moduleLoader.ModuleLoader;
|
|
||||||
|
|
||||||
import net.nemez.chatapi.ChatAPI;
|
|
||||||
import net.nemez.chatapi.click.Message;
|
|
||||||
|
|
||||||
/** The utils class containing utility functions. Those include but are not limited to sending formatted messages, broadcasts and more.
|
|
||||||
*
|
*
|
||||||
* @author Pepich */
|
* @author Pepich
|
||||||
@Version(major = 4, minor = 0, revision = 2, compatible = 1)
|
*/
|
||||||
public final class Utils
|
@Version (major = 4, minor = 0, revision = 2, compatible = 1)
|
||||||
{
|
public final class Utils {
|
||||||
/** The @SimpleDateFormat used for getting the current date. */
|
/** The Pattern for a UUID */
|
||||||
public static SimpleDateFormat dateFormat = new SimpleDateFormat("[yyyy-MM-dd HH:mm:ss]");
|
|
||||||
|
|
||||||
/** The Pattern for a UUID*/
|
|
||||||
private static final Pattern UUID_pattern = Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}");
|
private static final Pattern UUID_pattern = Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}");
|
||||||
private static final Pattern Class_pattern = Pattern.compile(".*\\.");
|
private static final Pattern Class_pattern = Pattern.compile(".*\\.");
|
||||||
private static final Pattern NoDolarSign_pattern = Pattern.compile("\\$\\d*");
|
private static final Pattern NoDolarSign_pattern = Pattern.compile("\\$\\d*");
|
||||||
|
/** The @SimpleDateFormat used for getting the current date. */
|
||||||
|
public static SimpleDateFormat dateFormat = new SimpleDateFormat("[yyyy-MM-dd HH:mm:ss]");
|
||||||
|
|
||||||
/** Hidden constructor. Do not instantiate UTILS classes! :) */
|
/** Hidden constructor. Do not instantiate UTILS classes! :) */
|
||||||
private Utils()
|
private Utils() {}
|
||||||
{}
|
|
||||||
|
|
||||||
/** This method broadcasts a message to all players and console that are allowed by the filter. Set the filter to NULL to broadcast to everyone.</br>
|
/**
|
||||||
|
* This method broadcasts a message to all players and console that are allowed by the filter. Set the filter to NULL to broadcast to everyone.</br>
|
||||||
* If you want to, you can set a message that will be logged to console. Set to null to not log anything.</br>
|
* If you want to, you can set a message that will be logged to console. Set to null to not log anything.</br>
|
||||||
* You can still allow console in the filter to log the original message.
|
* You can still allow console in the filter to log the original message.
|
||||||
*
|
*
|
||||||
@@ -43,29 +41,25 @@ public final class Utils
|
|||||||
* @param filter the BroadcastFilter to be applied.</br>
|
* @param filter the BroadcastFilter to be applied.</br>
|
||||||
* Write a class implementing the interface and pass it to this method, the "sendTo()" method will be called for each recipient.
|
* Write a class implementing the interface and pass it to this method, the "sendTo()" method will be called for each recipient.
|
||||||
* @param logmessage the log message to appear in console. Set to null to not log this (you can still log the original message by returning true in the filter).
|
* @param logmessage the log message to appear in console. Set to null to not log this (you can still log the original message by returning true in the filter).
|
||||||
* @return the amount of people that received the message. */
|
*
|
||||||
public static int broadcast(String prefix, String message, BroadcastFilter filter)
|
* @return the amount of people that received the message.
|
||||||
{
|
*/
|
||||||
|
public static int broadcast(String prefix, String message, BroadcastFilter filter) {
|
||||||
if (prefix == null)
|
if (prefix == null)
|
||||||
prefix = "§8[§2" + getCaller() + "§8]: ";
|
prefix = "§8[§2" + getCaller() + "§8]: ";
|
||||||
if (filter == null)
|
if (filter == null) {
|
||||||
{
|
for (Player p : Bukkit.getOnlinePlayers()) { p.sendMessage(prefix + message); }
|
||||||
for (Player p : Bukkit.getOnlinePlayers())
|
|
||||||
p.sendMessage(prefix + message);
|
|
||||||
Bukkit.getConsoleSender().sendMessage(prefix + message);
|
Bukkit.getConsoleSender().sendMessage(prefix + message);
|
||||||
return Bukkit.getOnlinePlayers().size() + 1;
|
return Bukkit.getOnlinePlayers().size() + 1;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (Player p : Bukkit.getOnlinePlayers())
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
if (filter.sendTo(p))
|
if (filter.sendTo(p)) {
|
||||||
{
|
|
||||||
p.sendMessage(prefix + message);
|
p.sendMessage(prefix + message);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
if (filter.sendTo(Bukkit.getConsoleSender()))
|
}
|
||||||
{
|
if (filter.sendTo(Bukkit.getConsoleSender())) {
|
||||||
Bukkit.getConsoleSender().sendMessage(prefix + message);
|
Bukkit.getConsoleSender().sendMessage(prefix + message);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
@@ -73,7 +67,22 @@ public final class Utils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method broadcasts a message to all players and console that are allowed by the filter. Set the filter to NULL to broadcast to everyone.</br>
|
/**
|
||||||
|
* This method will find the next parent caller and return their class name, omitting package names.
|
||||||
|
*
|
||||||
|
* @return the Name of the calling class.
|
||||||
|
*/
|
||||||
|
private static final String getCaller() {
|
||||||
|
StackTraceElement[] stackTrace = (new Exception()).getStackTrace();
|
||||||
|
String classname = "Utils";
|
||||||
|
for (int i = 0; classname.equals("Utils"); i++) {
|
||||||
|
classname = Class_pattern.matcher(stackTrace[i].getClassName()).replaceAll("");
|
||||||
|
}
|
||||||
|
return classname;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method broadcasts a message to all players and console that are allowed by the filter. Set the filter to NULL to broadcast to everyone.</br>
|
||||||
* If you want to, you can set a message that will be logged to console. Set to null to not log anything.</br>
|
* If you want to, you can set a message that will be logged to console. Set to null to not log anything.</br>
|
||||||
* You can still allow console in the filter to log the original message.
|
* You can still allow console in the filter to log the original message.
|
||||||
*
|
*
|
||||||
@@ -83,28 +92,22 @@ public final class Utils
|
|||||||
* Write a class implementing the interface and pass it to this method, the "sendTo()" method will be called for each recipient.
|
* Write a class implementing the interface and pass it to this method, the "sendTo()" method will be called for each recipient.
|
||||||
* @param logmessage the log message to appear in console. Set to null to not log this (you can still log the original message by returning true in the filter).
|
* @param logmessage the log message to appear in console. Set to null to not log this (you can still log the original message by returning true in the filter).
|
||||||
*/
|
*/
|
||||||
public static int broadcast(String prefix, Message message, BroadcastFilter filter)
|
public static int broadcast(String prefix, Message message, BroadcastFilter filter) {
|
||||||
{
|
|
||||||
if (prefix == null)
|
if (prefix == null)
|
||||||
prefix = "§8[§2" + getCaller() + "§8]: ";
|
prefix = "§8[§2" + getCaller() + "§8]: ";
|
||||||
if (filter == null)
|
if (filter == null) {
|
||||||
{
|
for (Player p : Bukkit.getOnlinePlayers()) { ChatAPI.createMessage(p).appendText(prefix).appendMessage(message).send(); }
|
||||||
for (Player p : Bukkit.getOnlinePlayers())
|
|
||||||
ChatAPI.createMessage(p).appendText(prefix).appendMessage(message).send();
|
|
||||||
Bukkit.getConsoleSender().sendMessage(prefix + message.getRawMessage());
|
Bukkit.getConsoleSender().sendMessage(prefix + message.getRawMessage());
|
||||||
return Bukkit.getOnlinePlayers().size() + 1;
|
return Bukkit.getOnlinePlayers().size() + 1;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (Player p : Bukkit.getOnlinePlayers())
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
if (filter.sendTo(p))
|
if (filter.sendTo(p)) {
|
||||||
{
|
|
||||||
ChatAPI.createMessage(p).appendText(prefix).appendMessage(message).send();
|
ChatAPI.createMessage(p).appendText(prefix).appendMessage(message).send();
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
if (filter.sendTo(Bukkit.getConsoleSender()))
|
}
|
||||||
{
|
if (filter.sendTo(Bukkit.getConsoleSender())) {
|
||||||
Bukkit.getConsoleSender().sendMessage(prefix + message.getRawMessage());
|
Bukkit.getConsoleSender().sendMessage(prefix + message.getRawMessage());
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
@@ -112,66 +115,58 @@ public final class Utils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method will find the next parent caller and return their class name, omitting package names.
|
/**
|
||||||
*
|
* This method will find the next parent caller and return their class name, omitting package names.
|
||||||
* @return the Name of the calling class. */
|
|
||||||
private static final String getCaller()
|
|
||||||
{
|
|
||||||
StackTraceElement[] stackTrace = (new Exception()).getStackTrace();
|
|
||||||
String classname = "Utils";
|
|
||||||
for (int i = 0; classname.equals("Utils"); i++)
|
|
||||||
{
|
|
||||||
classname = Class_pattern.matcher(stackTrace[i].getClassName()).replaceAll("");
|
|
||||||
}
|
|
||||||
return classname;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** This method will find the next parent caller and return their class name, omitting package names.
|
|
||||||
*
|
*
|
||||||
* @param directCaller used to prevent this method from returning the caller itself. Null if supposed to be ignored.
|
* @param directCaller used to prevent this method from returning the caller itself. Null if supposed to be ignored.
|
||||||
* @return the name of the calling class. */
|
*
|
||||||
public static final String getCaller(String... directCaller)
|
* @return the name of the calling class.
|
||||||
{
|
*/
|
||||||
|
public static final String getCaller(String... directCaller) {
|
||||||
if (directCaller == null || directCaller.length == 0)
|
if (directCaller == null || directCaller.length == 0)
|
||||||
return getCaller();
|
return getCaller();
|
||||||
StackTraceElement[] stackTrace = (new Exception()).getStackTrace();
|
StackTraceElement[] stackTrace = (new Exception()).getStackTrace();
|
||||||
String classname = "Utils";
|
String classname = "Utils";
|
||||||
List<String> callers = Arrays.asList(directCaller);
|
List<String> callers = Arrays.asList(directCaller);
|
||||||
for (int i = 0; callers.contains(classname) || classname.equals("Utils"); i++)
|
for (int i = 0; callers.contains(classname) || classname.equals("Utils"); i++) {
|
||||||
{
|
|
||||||
classname = Class_pattern.matcher(stackTrace[i].getClassName()).replaceAll("");
|
classname = Class_pattern.matcher(stackTrace[i].getClassName()).replaceAll("");
|
||||||
}
|
}
|
||||||
classname = NoDolarSign_pattern.matcher(classname).replaceAll("");
|
classname = NoDolarSign_pattern.matcher(classname).replaceAll("");
|
||||||
return classname;
|
return classname;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Provides a uniform way of getting the date for all modules.
|
/**
|
||||||
|
* Provides a uniform way of getting the date for all modules.
|
||||||
*
|
*
|
||||||
* @return The current date in the format "[dd-mm-yyyy hh:mm:ss]" */
|
* @return The current date in the format "[dd-mm-yyyy hh:mm:ss]"
|
||||||
public static String getDate()
|
*/
|
||||||
{
|
public static String getDate() {
|
||||||
Date date = new Date(System.currentTimeMillis());
|
Date date = new Date(System.currentTimeMillis());
|
||||||
return dateFormat.format(date);
|
return dateFormat.format(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Provides a uniform way of getting the (display)name of a @CommandSender.
|
/**
|
||||||
|
* Provides a uniform way of getting the (display)name of a @CommandSender.
|
||||||
*
|
*
|
||||||
* @param sender The @CommandSender to get the name of.
|
* @param sender The @CommandSender to get the name of.
|
||||||
* @return The DisplayName of the @CommandSender or if not a @Player, the name in blue. */
|
*
|
||||||
public static String getName(CommandSender sender)
|
* @return The DisplayName of the @CommandSender or if not a @Player, the name in blue.
|
||||||
{
|
*/
|
||||||
|
public static String getName(CommandSender sender) {
|
||||||
if (sender instanceof Player)
|
if (sender instanceof Player)
|
||||||
return ((Player) sender).getDisplayName();
|
return ((Player) sender).getDisplayName();
|
||||||
else
|
else
|
||||||
return "§9" + sender.getName();
|
return "§9" + sender.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Provides a uniform way of getting the UUID of a @CommandSender.
|
/**
|
||||||
|
* Provides a uniform way of getting the UUID of a @CommandSender.
|
||||||
*
|
*
|
||||||
* @param sender The @CommandSender to get the UUID of.
|
* @param sender The @CommandSender to get the UUID of.
|
||||||
* @return The UUID of the @CommandSender or if not a player, "CONSOLE" in blue. */
|
*
|
||||||
public static String getID(CommandSender sender)
|
* @return The UUID of the @CommandSender or if not a player, "CONSOLE" in blue.
|
||||||
{
|
*/
|
||||||
|
public static String getID(CommandSender sender) {
|
||||||
String id;
|
String id;
|
||||||
if (sender instanceof Player)
|
if (sender instanceof Player)
|
||||||
id = ((Player) sender).getUniqueId().toString();
|
id = ((Player) sender).getUniqueId().toString();
|
||||||
@@ -180,13 +175,14 @@ public final class Utils
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Checks if the string is a UUID.
|
/**
|
||||||
|
* Checks if the string is a UUID.
|
||||||
*
|
*
|
||||||
* @param toCheck String to check.
|
* @param toCheck String to check.
|
||||||
|
*
|
||||||
* @return if the string is a UUID.
|
* @return if the string is a UUID.
|
||||||
*/
|
*/
|
||||||
public static boolean isUUID(String toCheck)
|
public static boolean isUUID(String toCheck) {
|
||||||
{
|
|
||||||
return UUID_pattern.matcher(toCheck).matches();
|
return UUID_pattern.matcher(toCheck).matches();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,5 +195,4 @@ public final class Utils
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,30 @@
|
|||||||
package com.redstoner.misc;
|
package com.redstoner.misc;
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
|
||||||
|
|
||||||
import com.redstoner.annotations.Version;
|
import com.redstoner.annotations.Version;
|
||||||
import com.redstoner.exceptions.MissingVersionException;
|
import com.redstoner.exceptions.MissingVersionException;
|
||||||
|
|
||||||
/** This class can be used to compare modules against the loader version or against each other to prevent dependency issues.
|
import java.lang.annotation.Annotation;
|
||||||
*
|
|
||||||
* @author Pepich */
|
|
||||||
@Version(major = 2, minor = 1, revision = 3, compatible = 0)
|
|
||||||
public final class VersionHelper
|
|
||||||
{
|
|
||||||
private VersionHelper()
|
|
||||||
{}
|
|
||||||
|
|
||||||
/** Checks two classes versions for compatibility.
|
/**
|
||||||
|
* This class can be used to compare modules against the loader version or against each other to prevent dependency issues.
|
||||||
|
*
|
||||||
|
* @author Pepich
|
||||||
|
*/
|
||||||
|
@Version (major = 2, minor = 1, revision = 3, compatible = 0)
|
||||||
|
public final class VersionHelper {
|
||||||
|
private VersionHelper() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks two classes versions for compatibility.
|
||||||
*
|
*
|
||||||
* @param base The API to compare to.
|
* @param base The API to compare to.
|
||||||
* @param module The module to compare.
|
* @param module The module to compare.
|
||||||
|
*
|
||||||
* @return true, when the module is up to date with the API, or the API supports outdated modules.
|
* @return true, when the module is up to date with the API, or the API supports outdated modules.
|
||||||
* @throws MissingVersionException When one of the parameters is not annotated with a @Version annotation. */
|
*
|
||||||
public static boolean isCompatible(Class<?> api, Class<?> module) throws MissingVersionException
|
* @throws MissingVersionException When one of the parameters is not annotated with a @Version annotation.
|
||||||
{
|
*/
|
||||||
|
public static boolean isCompatible(Class<?> api, Class<?> module) throws MissingVersionException {
|
||||||
if (!api.isAnnotationPresent(Version.class))
|
if (!api.isAnnotationPresent(Version.class))
|
||||||
throw new MissingVersionException("The API is not annotated with a version.");
|
throw new MissingVersionException("The API is not annotated with a version.");
|
||||||
if (!module.isAnnotationPresent(Version.class))
|
if (!module.isAnnotationPresent(Version.class))
|
||||||
@@ -31,41 +34,15 @@ public final class VersionHelper
|
|||||||
return isCompatible(apiVersion, moduleVersion);
|
return isCompatible(apiVersion, moduleVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Checks two classes versions for compatibility.
|
/**
|
||||||
*
|
* Checks two versions for compatibility.
|
||||||
* @param base The API to compare to.
|
|
||||||
* @param module The module to compare.
|
|
||||||
* @return true, when the module is up to date with the API, or the API supports outdated modules.
|
|
||||||
* @throws MissingVersionException When one of the parameters is not annotated with a @Version annotation. */
|
|
||||||
public static boolean isCompatible(Version apiVersion, Class<?> module) throws MissingVersionException
|
|
||||||
{
|
|
||||||
if (!module.isAnnotationPresent(Version.class))
|
|
||||||
throw new MissingVersionException("The module is not annotated with a version.");
|
|
||||||
Version moduleVersion = module.getAnnotation(Version.class);
|
|
||||||
return isCompatible(apiVersion, moduleVersion);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Checks two classes versions for compatibility.
|
|
||||||
*
|
|
||||||
* @param base The API to compare to.
|
|
||||||
* @param module The module to compare.
|
|
||||||
* @return true, when the module is up to date with the API, or the API supports outdated modules.
|
|
||||||
* @throws MissingVersionException When one of the parameters is not annotated with a @Version annotation. */
|
|
||||||
public static boolean isCompatible(Class<?> api, Version moduleVersion) throws MissingVersionException
|
|
||||||
{
|
|
||||||
if (!api.isAnnotationPresent(Version.class))
|
|
||||||
throw new MissingVersionException("The API is not annotated with a version.");
|
|
||||||
Version apiVersion = api.getAnnotation(Version.class);
|
|
||||||
return isCompatible(apiVersion, moduleVersion);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Checks two versions for compatibility.
|
|
||||||
*
|
*
|
||||||
* @param base The API version to compare to.
|
* @param base The API version to compare to.
|
||||||
* @param module The module version to compare.
|
* @param module The module version to compare.
|
||||||
* @return true, when the module is up to date with the API, or the API supports outdated modules. */
|
*
|
||||||
public static boolean isCompatible(Version apiVersion, Version moduleVersion)
|
* @return true, when the module is up to date with the API, or the API supports outdated modules.
|
||||||
{
|
*/
|
||||||
|
public static boolean isCompatible(Version apiVersion, Version moduleVersion) {
|
||||||
if (apiVersion.major() >= moduleVersion.compatible())
|
if (apiVersion.major() >= moduleVersion.compatible())
|
||||||
return true;
|
return true;
|
||||||
if (apiVersion.compatible() == -1)
|
if (apiVersion.compatible() == -1)
|
||||||
@@ -75,75 +52,110 @@ public final class VersionHelper
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the version of a given class as a String.
|
/**
|
||||||
|
* Checks two classes versions for compatibility.
|
||||||
|
*
|
||||||
|
* @param base The API to compare to.
|
||||||
|
* @param module The module to compare.
|
||||||
|
*
|
||||||
|
* @return true, when the module is up to date with the API, or the API supports outdated modules.
|
||||||
|
*
|
||||||
|
* @throws MissingVersionException When one of the parameters is not annotated with a @Version annotation.
|
||||||
|
*/
|
||||||
|
public static boolean isCompatible(Version apiVersion, Class<?> module) throws MissingVersionException {
|
||||||
|
if (!module.isAnnotationPresent(Version.class))
|
||||||
|
throw new MissingVersionException("The module is not annotated with a version.");
|
||||||
|
Version moduleVersion = module.getAnnotation(Version.class);
|
||||||
|
return isCompatible(apiVersion, moduleVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks two classes versions for compatibility.
|
||||||
|
*
|
||||||
|
* @param base The API to compare to.
|
||||||
|
* @param module The module to compare.
|
||||||
|
*
|
||||||
|
* @return true, when the module is up to date with the API, or the API supports outdated modules.
|
||||||
|
*
|
||||||
|
* @throws MissingVersionException When one of the parameters is not annotated with a @Version annotation.
|
||||||
|
*/
|
||||||
|
public static boolean isCompatible(Class<?> api, Version moduleVersion) throws MissingVersionException {
|
||||||
|
if (!api.isAnnotationPresent(Version.class))
|
||||||
|
throw new MissingVersionException("The API is not annotated with a version.");
|
||||||
|
Version apiVersion = api.getAnnotation(Version.class);
|
||||||
|
return isCompatible(apiVersion, moduleVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the version of a given class as a String.
|
||||||
*
|
*
|
||||||
* @param clazz The class to grab the version number from.
|
* @param clazz The class to grab the version number from.
|
||||||
|
*
|
||||||
* @return The version number of the class in format major.minor.revision.compatible.
|
* @return The version number of the class in format major.minor.revision.compatible.
|
||||||
* @throws MissingVersionException If the class is not annotated with @Version. */
|
*
|
||||||
public static String getVersion(Class<?> clazz) throws MissingVersionException
|
* @throws MissingVersionException If the class is not annotated with @Version.
|
||||||
{
|
*/
|
||||||
|
public static String getVersion(Class<?> clazz) throws MissingVersionException {
|
||||||
if (!clazz.isAnnotationPresent(Version.class))
|
if (!clazz.isAnnotationPresent(Version.class))
|
||||||
throw new MissingVersionException("The given class is not associated with a version.");
|
throw new MissingVersionException("The given class is not associated with a version.");
|
||||||
Version ver = clazz.getAnnotation(Version.class);
|
Version ver = clazz.getAnnotation(Version.class);
|
||||||
return getString(ver);
|
return getString(ver);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the String representation of a version.
|
/**
|
||||||
|
* Returns the String representation of a version.
|
||||||
*
|
*
|
||||||
* @param ver The version to be represented.
|
* @param ver The version to be represented.
|
||||||
* @return The String representation. */
|
*
|
||||||
public static String getString(Version ver)
|
* @return The String representation.
|
||||||
{
|
*/
|
||||||
|
public static String getString(Version ver) {
|
||||||
return ver.major() + "." + ver.minor() + "." + ver.revision() + "." + ver.compatible();
|
return ver.major() + "." + ver.minor() + "." + ver.revision() + "." + ver.compatible();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Version getVersion(String ver)
|
public static Version getVersion(String ver) {
|
||||||
{
|
|
||||||
String[] raw = ver.split("\\.");
|
String[] raw = ver.split("\\.");
|
||||||
if (raw.length != 4)
|
if (raw.length != 4)
|
||||||
return null;
|
return null;
|
||||||
return VersionHelper.create(Integer.parseInt(raw[0]), Integer.parseInt(raw[1]), Integer.parseInt(raw[2]),
|
return VersionHelper.create(Integer.parseInt(raw[0]), Integer.parseInt(raw[1]), Integer.parseInt(raw[2]),
|
||||||
Integer.parseInt(raw[3]));
|
Integer.parseInt(raw[3])
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method creates a new Version to use for compatibility checks.
|
/**
|
||||||
|
* This method creates a new Version to use for compatibility checks.
|
||||||
*
|
*
|
||||||
* @param major The major version
|
* @param major The major version
|
||||||
* @param minor The minor version
|
* @param minor The minor version
|
||||||
* @param revision The revision
|
* @param revision The revision
|
||||||
* @param compatible The compatibility tag
|
* @param compatible The compatibility tag
|
||||||
* @return */
|
*
|
||||||
public static Version create(int major, int minor, int revision, int compatible)
|
* @return
|
||||||
{
|
*/
|
||||||
return new Version()
|
public static Version create(int major, int minor, int revision, int compatible) {
|
||||||
{
|
return new Version() {
|
||||||
@Override
|
@Override
|
||||||
public Class<? extends Annotation> annotationType()
|
public Class<? extends Annotation> annotationType() {
|
||||||
{
|
|
||||||
return Version.class;
|
return Version.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int revision()
|
public int revision() {
|
||||||
{
|
|
||||||
return revision;
|
return revision;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int minor()
|
public int minor() {
|
||||||
{
|
|
||||||
return minor;
|
return minor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int major()
|
public int major() {
|
||||||
{
|
|
||||||
return major;
|
return major;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compatible()
|
public int compatible() {
|
||||||
{
|
|
||||||
return compatible;
|
return compatible;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,91 +1,72 @@
|
|||||||
package com.redstoner.misc.mysql;
|
package com.redstoner.misc.mysql;
|
||||||
|
|
||||||
import java.io.File;
|
import com.redstoner.exceptions.NonSaveableConfigException;
|
||||||
import java.io.FileReader;
|
import com.redstoner.misc.Main;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.parser.JSONParser;
|
import org.json.simple.parser.JSONParser;
|
||||||
import org.json.simple.parser.ParseException;
|
import org.json.simple.parser.ParseException;
|
||||||
|
|
||||||
import com.redstoner.exceptions.NonSaveableConfigException;
|
import java.io.File;
|
||||||
import com.redstoner.misc.Main;
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
public class Config
|
public class Config {
|
||||||
{
|
|
||||||
private File file;
|
private File file;
|
||||||
private JSONObject config;
|
private JSONObject config;
|
||||||
private JSONParser parser;
|
private JSONParser parser;
|
||||||
|
|
||||||
public Config()
|
public Config() {
|
||||||
{
|
|
||||||
file = null;
|
file = null;
|
||||||
parser = new JSONParser();
|
parser = new JSONParser();
|
||||||
config = new JSONObject();
|
config = new JSONObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Config(JSONObject config)
|
public Config(JSONObject config) {
|
||||||
{
|
|
||||||
this.file = null;
|
this.file = null;
|
||||||
this.parser = new JSONParser();
|
this.parser = new JSONParser();
|
||||||
this.config = config;
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Config(File file) throws IOException, ParseException
|
private Config(File file) throws IOException, ParseException {
|
||||||
{
|
|
||||||
this.file = file;
|
this.file = file;
|
||||||
parser = new JSONParser();
|
parser = new JSONParser();
|
||||||
if (file.exists())
|
if (file.exists()) {
|
||||||
{
|
|
||||||
config = loadConfig(file);
|
config = loadConfig(file);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
config = new JSONObject();
|
config = new JSONObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Config getConfig(String fileName) throws IOException, ParseException
|
private JSONObject loadConfig(File file) throws IOException, ParseException {
|
||||||
{
|
|
||||||
return new Config(new File(Main.plugin.getDataFolder(), fileName));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final Config getConfig(File file) throws IOException, ParseException
|
|
||||||
{
|
|
||||||
return new Config(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
private JSONObject loadConfig(File file) throws IOException, ParseException
|
|
||||||
{
|
|
||||||
FileReader reader = new FileReader(file);
|
FileReader reader = new FileReader(file);
|
||||||
JSONObject object = (JSONObject) parser.parse(reader);
|
JSONObject object = (JSONObject) parser.parse(reader);
|
||||||
reader.close();
|
reader.close();
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final Config getConfig(String fileName) throws IOException, ParseException {
|
||||||
|
return new Config(new File(Main.plugin.getDataFolder(), fileName));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Config getConfig(File file) throws IOException, ParseException {
|
||||||
|
return new Config(file);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString() {
|
||||||
{
|
|
||||||
return config.toJSONString();
|
return config.toJSONString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONObject asObject()
|
public JSONObject asObject() {
|
||||||
{
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() throws IOException, NonSaveableConfigException
|
public void save() throws IOException, NonSaveableConfigException {
|
||||||
{
|
if (file == null) {
|
||||||
if (file == null)
|
|
||||||
{
|
|
||||||
throw new NonSaveableConfigException();
|
throw new NonSaveableConfigException();
|
||||||
}
|
}
|
||||||
PrintWriter writer = new PrintWriter(file);
|
PrintWriter writer = new PrintWriter(file);
|
||||||
@@ -93,123 +74,97 @@ public class Config
|
|||||||
writer.close();
|
writer.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refresh() throws IOException, ParseException, NonSaveableConfigException
|
public void refresh() throws IOException, ParseException, NonSaveableConfigException {
|
||||||
{
|
if (file == null) {
|
||||||
if (file == null)
|
|
||||||
{
|
|
||||||
throw new NonSaveableConfigException();
|
throw new NonSaveableConfigException();
|
||||||
}
|
}
|
||||||
loadConfig(file);
|
loadConfig(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFile(String fileName)
|
public void setFile(String fileName) {
|
||||||
{
|
|
||||||
file = new File(Main.plugin.getDataFolder(), fileName);
|
file = new File(Main.plugin.getDataFolder(), fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFile(File file)
|
public void setFile(File file) {
|
||||||
{
|
|
||||||
this.file = file;
|
this.file = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings ("unchecked")
|
||||||
public void put(String key, String value)
|
public void put(String key, String value) {
|
||||||
{
|
|
||||||
config.put(key, value);
|
config.put(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings ("unchecked")
|
||||||
public void put(String key, List<String> value)
|
public void put(String key, List<String> value) {
|
||||||
{
|
|
||||||
JSONArray array = new JSONArray();
|
JSONArray array = new JSONArray();
|
||||||
for (String entry : value)
|
for (String entry : value) {
|
||||||
{
|
|
||||||
array.add(entry);
|
array.add(entry);
|
||||||
}
|
}
|
||||||
config.put(key, array);
|
config.put(key, array);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings ("unchecked")
|
||||||
public void putArray(String key, JSONArray value)
|
public void putArray(String key, JSONArray value) {
|
||||||
{
|
|
||||||
config.put(key, value);
|
config.put(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings ("unchecked")
|
||||||
public void put(String key, Map<String, String> value)
|
public void put(String key, Map<String, String> value) {
|
||||||
{
|
|
||||||
JSONObject object = new JSONObject();
|
JSONObject object = new JSONObject();
|
||||||
for (String valKey : value.keySet())
|
for (String valKey : value.keySet()) {
|
||||||
{
|
|
||||||
String valVal = value.get(valKey);
|
String valVal = value.get(valKey);
|
||||||
object.put(valKey, valVal);
|
object.put(valKey, valVal);
|
||||||
}
|
}
|
||||||
config.put(key, object);
|
config.put(key, object);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings ("unchecked")
|
||||||
public void put(String key, JSONObject value)
|
public void put(String key, JSONObject value) {
|
||||||
{
|
|
||||||
config.put(key, value);
|
config.put(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings ("unchecked")
|
||||||
public void putAll(Map<String, String> entry)
|
public void putAll(Map<String, String> entry) {
|
||||||
{
|
for (String key : entry.keySet()) {
|
||||||
for (String key : entry.keySet())
|
|
||||||
{
|
|
||||||
String value = entry.get(key);
|
String value = entry.get(key);
|
||||||
config.put(key, value);
|
config.put(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean containsKey(String key)
|
public String get(String key) {
|
||||||
{
|
if (containsKey(key)) {
|
||||||
|
Object value = config.get(key);
|
||||||
|
if (value instanceof String) {
|
||||||
|
return (String) value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean containsKey(String key) {
|
||||||
return config.containsKey(key);
|
return config.containsKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String get(String key)
|
public String getOrDefault(String key, String defaultValue) {
|
||||||
{
|
if (containsKey(key)) {
|
||||||
if (containsKey(key))
|
|
||||||
{
|
|
||||||
Object value = config.get(key);
|
Object value = config.get(key);
|
||||||
if (value instanceof String)
|
if (value instanceof String) {
|
||||||
{
|
|
||||||
return (String) value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getOrDefault(String key, String defaultValue)
|
|
||||||
{
|
|
||||||
if (containsKey(key))
|
|
||||||
{
|
|
||||||
Object value = config.get(key);
|
|
||||||
if (value instanceof String)
|
|
||||||
{
|
|
||||||
return (String) value;
|
return (String) value;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings ("unchecked")
|
||||||
public List<String> getList(String key)
|
public List<String> getList(String key) {
|
||||||
{
|
if (containsKey(key)) {
|
||||||
if (containsKey(key))
|
|
||||||
{
|
|
||||||
Object value = config.get(key);
|
Object value = config.get(key);
|
||||||
if (value instanceof JSONArray)
|
if (value instanceof JSONArray) {
|
||||||
{
|
|
||||||
JSONArray array = (JSONArray) value;
|
JSONArray array = (JSONArray) value;
|
||||||
List<String> output = new ArrayList<String>();
|
List<String> output = new ArrayList<String>();
|
||||||
for (String entry : (String[]) array.toArray(new String[0]))
|
for (String entry : (String[]) array.toArray(new String[0])) {
|
||||||
{
|
|
||||||
output.add(entry);
|
output.add(entry);
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
@@ -218,13 +173,10 @@ public class Config
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONArray getArray(String key)
|
public JSONArray getArray(String key) {
|
||||||
{
|
if (containsKey(key)) {
|
||||||
if (containsKey(key))
|
|
||||||
{
|
|
||||||
Object value = config.get(key);
|
Object value = config.get(key);
|
||||||
if (value instanceof JSONArray)
|
if (value instanceof JSONArray) {
|
||||||
{
|
|
||||||
JSONArray array = (JSONArray) value;
|
JSONArray array = (JSONArray) value;
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
@@ -232,19 +184,15 @@ public class Config
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, String> getMap(String key)
|
public Map<String, String> getMap(String key) {
|
||||||
{
|
if (containsKey(key)) {
|
||||||
if (containsKey(key))
|
|
||||||
{
|
|
||||||
Object value = config.get(key);
|
Object value = config.get(key);
|
||||||
if (value instanceof JSONObject)
|
if (value instanceof JSONObject) {
|
||||||
{
|
|
||||||
JSONObject object = (JSONObject) value;
|
JSONObject object = (JSONObject) value;
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings ("unchecked")
|
||||||
Set<Map.Entry<String, String>> entrySet = object.entrySet();
|
Set<Map.Entry<String, String>> entrySet = object.entrySet();
|
||||||
Map<String, String> output = new HashMap<String, String>();
|
Map<String, String> output = new HashMap<String, String>();
|
||||||
for (Map.Entry<String, String> entry : entrySet)
|
for (Map.Entry<String, String> entry : entrySet) {
|
||||||
{
|
|
||||||
output.put(entry.getKey(), entry.getValue());
|
output.put(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
@@ -253,13 +201,10 @@ public class Config
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONObject getObject(String key)
|
public JSONObject getObject(String key) {
|
||||||
{
|
if (containsKey(key)) {
|
||||||
if (containsKey(key))
|
|
||||||
{
|
|
||||||
Object value = config.get(key);
|
Object value = config.get(key);
|
||||||
if (value instanceof JSONObject)
|
if (value instanceof JSONObject) {
|
||||||
{
|
|
||||||
JSONObject object = (JSONObject) value;
|
JSONObject object = (JSONObject) value;
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
@@ -267,14 +212,12 @@ public class Config
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(String key)
|
public void remove(String key) {
|
||||||
{
|
|
||||||
config.remove(key);
|
config.remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings ("unchecked")
|
||||||
public Set<Entry<String, String>> getAll()
|
public Set<Entry<String, String>> getAll() {
|
||||||
{
|
|
||||||
return config.entrySet();
|
return config.entrySet();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,91 +1,57 @@
|
|||||||
package com.redstoner.misc.mysql;
|
package com.redstoner.misc.mysql;
|
||||||
|
|
||||||
import java.io.File;
|
import com.redstoner.misc.Main;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.parser.JSONParser;
|
import org.json.simple.parser.JSONParser;
|
||||||
import org.json.simple.parser.ParseException;
|
import org.json.simple.parser.ParseException;
|
||||||
|
|
||||||
import com.redstoner.misc.Main;
|
import java.io.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class JSONManager
|
public class JSONManager {
|
||||||
{
|
public static Map<Serializable, Serializable> getConfiguration(String fileName) {
|
||||||
public static Map<Serializable, Serializable> getConfiguration(String fileName)
|
|
||||||
{
|
|
||||||
File file = new File(Main.plugin.getDataFolder(), fileName);
|
File file = new File(Main.plugin.getDataFolder(), fileName);
|
||||||
if (!file.exists())
|
if (!file.exists()) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
PrintWriter writer = new PrintWriter(file.getAbsolutePath(), "UTF-8");
|
PrintWriter writer = new PrintWriter(file.getAbsolutePath(), "UTF-8");
|
||||||
writer.println("{}");
|
writer.println("{}");
|
||||||
writer.close();
|
writer.close();
|
||||||
}
|
} catch (FileNotFoundException | UnsupportedEncodingException e) {
|
||||||
catch (FileNotFoundException | UnsupportedEncodingException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
return loadMap(file);
|
return loadMap(file);
|
||||||
}
|
} catch (IOException | ParseException e) {
|
||||||
catch (IOException | ParseException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void saveConfiguration(Map<Serializable, Serializable> config, String fileName)
|
public static Map<Serializable, Serializable> loadMap(File file) throws IOException, ParseException {
|
||||||
{
|
FileReader reader = new FileReader(file);
|
||||||
try
|
JSONObject map = (JSONObject) new JSONParser().parse(reader);
|
||||||
{
|
Map<Serializable, Serializable> entries = new HashMap<>();
|
||||||
saveMap(new File(Main.plugin.getDataFolder(), fileName), config);
|
for (Object o : map.keySet()) {
|
||||||
}
|
entries.put((Serializable) o, (Serializable) map.get(o));
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static void saveList(File file, List<Serializable> entries) throws IOException
|
|
||||||
{
|
|
||||||
JSONArray array = new JSONArray();
|
|
||||||
array.addAll(entries);
|
|
||||||
FileWriter writer = new FileWriter(file);
|
|
||||||
writer.write(array.toJSONString());
|
|
||||||
writer.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<Serializable> loadList(File file) throws IOException, ParseException
|
|
||||||
{
|
|
||||||
FileReader read = new FileReader(file);
|
|
||||||
List<Serializable> entries = new ArrayList<>();
|
|
||||||
JSONArray array = (JSONArray) new JSONParser().parse(read);
|
|
||||||
for (Object o : array)
|
|
||||||
{
|
|
||||||
entries.add((Serializable) o);
|
|
||||||
}
|
}
|
||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
public static void saveConfiguration(Map<Serializable, Serializable> config, String fileName) {
|
||||||
public static void saveMap(File file, Map<Serializable, Serializable> entries) throws IOException
|
try {
|
||||||
{
|
saveMap(new File(Main.plugin.getDataFolder(), fileName), config);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings ("unchecked")
|
||||||
|
public static void saveMap(File file, Map<Serializable, Serializable> entries) throws IOException {
|
||||||
JSONObject map = new JSONObject();
|
JSONObject map = new JSONObject();
|
||||||
map.putAll(entries);
|
map.putAll(entries);
|
||||||
FileWriter writer = new FileWriter(file);
|
FileWriter writer = new FileWriter(file);
|
||||||
@@ -93,14 +59,21 @@ public class JSONManager
|
|||||||
writer.close();
|
writer.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<Serializable, Serializable> loadMap(File file) throws IOException, ParseException
|
@SuppressWarnings ("unchecked")
|
||||||
{
|
public static void saveList(File file, List<Serializable> entries) throws IOException {
|
||||||
FileReader reader = new FileReader(file);
|
JSONArray array = new JSONArray();
|
||||||
JSONObject map = (JSONObject) new JSONParser().parse(reader);
|
array.addAll(entries);
|
||||||
Map<Serializable, Serializable> entries = new HashMap<>();
|
FileWriter writer = new FileWriter(file);
|
||||||
for (Object o : map.keySet())
|
writer.write(array.toJSONString());
|
||||||
{
|
writer.close();
|
||||||
entries.put((Serializable) o, (Serializable) map.get(o));
|
}
|
||||||
|
|
||||||
|
public static List<Serializable> loadList(File file) throws IOException, ParseException {
|
||||||
|
FileReader read = new FileReader(file);
|
||||||
|
List<Serializable> entries = new ArrayList<>();
|
||||||
|
JSONArray array = (JSONArray) new JSONParser().parse(read);
|
||||||
|
for (Object o : array) {
|
||||||
|
entries.add((Serializable) o);
|
||||||
}
|
}
|
||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,66 +1,49 @@
|
|||||||
package com.redstoner.misc.mysql;
|
package com.redstoner.misc.mysql;
|
||||||
|
|
||||||
|
import com.redstoner.misc.Main;
|
||||||
|
import com.redstoner.misc.mysql.elements.MysqlDatabase;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.json.simple.parser.ParseException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.sql.Connection;
|
import java.sql.*;
|
||||||
import java.sql.DatabaseMetaData;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
public class MysqlHandler {
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.json.simple.parser.ParseException;
|
|
||||||
|
|
||||||
import com.redstoner.misc.Main;
|
|
||||||
import com.redstoner.misc.mysql.elements.MysqlDatabase;
|
|
||||||
|
|
||||||
public class MysqlHandler
|
|
||||||
{
|
|
||||||
public static MysqlHandler INSTANCE;
|
public static MysqlHandler INSTANCE;
|
||||||
private String url, username, password;
|
private String url, username, password;
|
||||||
|
|
||||||
public MysqlHandler(String hostname, int port, String username, String password)
|
public MysqlHandler(String hostname, int port, String username, String password) {
|
||||||
{
|
|
||||||
this.url = "jdbc:mysql://" + hostname + ":" + port + "/";
|
this.url = "jdbc:mysql://" + hostname + ":" + port + "/";
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void init()
|
public static void init() {
|
||||||
{
|
|
||||||
Map<Serializable, Serializable> mysqlCredentials = new HashMap<>();
|
Map<Serializable, Serializable> mysqlCredentials = new HashMap<>();
|
||||||
File mysqlCredentialsFile = new File(Main.plugin.getDataFolder(), "mysqlCredentials.json");
|
File mysqlCredentialsFile = new File(Main.plugin.getDataFolder(), "mysqlCredentials.json");
|
||||||
if (mysqlCredentialsFile.exists())
|
if (mysqlCredentialsFile.exists()) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
mysqlCredentials = JSONManager.loadMap(mysqlCredentialsFile);
|
mysqlCredentials = JSONManager.loadMap(mysqlCredentialsFile);
|
||||||
}
|
} catch (IOException | ParseException e) {
|
||||||
catch (IOException | ParseException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
Bukkit.getConsoleSender().sendMessage(
|
Bukkit.getConsoleSender().sendMessage(
|
||||||
ChatColor.RED + "MySQL config does not exist, creating an example one, things might (will) break!");
|
ChatColor.RED + "MySQL config does not exist, creating an example one, things might (will) break!");
|
||||||
mysqlCredentials.put("hostname", "localhost");
|
mysqlCredentials.put("hostname", "localhost");
|
||||||
mysqlCredentials.put("port", "3306");
|
mysqlCredentials.put("port", "3306");
|
||||||
mysqlCredentials.put("username", "your username here");
|
mysqlCredentials.put("username", "your username here");
|
||||||
mysqlCredentials.put("password", "your password here");
|
mysqlCredentials.put("password", "your password here");
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
JSONManager.saveMap(mysqlCredentialsFile, mysqlCredentials);
|
JSONManager.saveMap(mysqlCredentialsFile, mysqlCredentials);
|
||||||
}
|
} catch (IOException e) {
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,43 +54,33 @@ public class MysqlHandler
|
|||||||
INSTANCE = new MysqlHandler(hostname, port, username, password);
|
INSTANCE = new MysqlHandler(hostname, port, username, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Connection getConnection(String databaseName) throws IllegalStateException
|
public MysqlDatabase getDatabase(String databaseName) {
|
||||||
{
|
return new MysqlDatabase(getConnection(databaseName));
|
||||||
Connection connection = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
connection = DriverManager.getConnection(url + databaseName, username, password);
|
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
|
||||||
{
|
private Connection getConnection(String databaseName) throws IllegalStateException {
|
||||||
|
Connection connection = null;
|
||||||
|
try {
|
||||||
|
connection = DriverManager.getConnection(url + databaseName, username, password);
|
||||||
|
} catch (SQLException e) {
|
||||||
throw new IllegalStateException("Cannot connect to the database!", e);
|
throw new IllegalStateException("Cannot connect to the database!", e);
|
||||||
}
|
}
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MysqlDatabase getDatabase(String databaseName)
|
public List<MysqlDatabase> getDatabases() {
|
||||||
{
|
try {
|
||||||
return new MysqlDatabase(getConnection(databaseName));
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<MysqlDatabase> getDatabases()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
List<MysqlDatabase> databases = new ArrayList<>();
|
List<MysqlDatabase> databases = new ArrayList<>();
|
||||||
Connection connection = DriverManager.getConnection(url.substring(0, url.length()), username, password);
|
Connection connection = DriverManager.getConnection(url.substring(0, url.length()), username, password);
|
||||||
DatabaseMetaData metadata = connection.getMetaData();
|
DatabaseMetaData metadata = connection.getMetaData();
|
||||||
ResultSet queryResults = metadata.getCatalogs();
|
ResultSet queryResults = metadata.getCatalogs();
|
||||||
while (queryResults.next())
|
while (queryResults.next()) {
|
||||||
{
|
|
||||||
String databaseName = queryResults.getString("TABLE_CAT");
|
String databaseName = queryResults.getString("TABLE_CAT");
|
||||||
databases.add(new MysqlDatabase(getConnection(databaseName)));
|
databases.add(new MysqlDatabase(getConnection(databaseName)));
|
||||||
}
|
}
|
||||||
connection.close();
|
connection.close();
|
||||||
return databases;
|
return databases;
|
||||||
}
|
} catch (SQLException e) {
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
package com.redstoner.misc.mysql;
|
package com.redstoner.misc.mysql;
|
||||||
|
|
||||||
import java.sql.CallableStatement;
|
import java.sql.*;
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
|
||||||
|
|
||||||
public class MysqlQueryHandler {
|
public class MysqlQueryHandler {
|
||||||
public static ResultSet queryResult(Connection connection, String query) {
|
public static ResultSet queryResult(Connection connection, String query) {
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.redstoner.misc.mysql.elements;
|
package com.redstoner.misc.mysql.elements;
|
||||||
|
|
||||||
|
import com.redstoner.misc.mysql.MysqlQueryHandler;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DatabaseMetaData;
|
import java.sql.DatabaseMetaData;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@@ -7,8 +9,6 @@ import java.sql.SQLException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.redstoner.misc.mysql.MysqlQueryHandler;
|
|
||||||
|
|
||||||
public class MysqlDatabase {
|
public class MysqlDatabase {
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
|
|
||||||
@@ -16,15 +16,6 @@ public class MysqlDatabase {
|
|||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
try {
|
|
||||||
return connection.getCatalog();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public MysqlTable getTable(String name) {
|
public MysqlTable getTable(String name) {
|
||||||
return new MysqlTable(this, name);
|
return new MysqlTable(this, name);
|
||||||
}
|
}
|
||||||
@@ -33,39 +24,6 @@ public class MysqlDatabase {
|
|||||||
return MysqlQueryHandler.queryNoResult(connection, "CREATE TABLE `" + name + "` " + getDescription(description) + ";");
|
return MysqlQueryHandler.queryNoResult(connection, "CREATE TABLE `" + name + "` " + getDescription(description) + ";");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean createTableIfNotExists(String name, MysqlField... description) {
|
|
||||||
return MysqlQueryHandler.queryNoResult(connection, "CREATE TABLE IF NOT EXISTS `" + name + "` " + getDescription(description) + ";");
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean dropTable(String name) {
|
|
||||||
return MysqlQueryHandler.queryNoResult(connection, "DROP TABLE `" + name + "`;");
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean drop() {
|
|
||||||
return MysqlQueryHandler.queryNoResult(connection, "DROP DATABASE `" + getName() + "`;");
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<MysqlTable> getTables() {
|
|
||||||
try {
|
|
||||||
List<MysqlTable> tables = new ArrayList<>();
|
|
||||||
DatabaseMetaData metadata = connection.getMetaData();
|
|
||||||
ResultSet queryResults = metadata.getTables(null, null, "%", null);
|
|
||||||
|
|
||||||
while (queryResults.next()) {
|
|
||||||
tables.add(new MysqlTable(this, queryResults.getString(3)));
|
|
||||||
}
|
|
||||||
|
|
||||||
return tables;
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Connection getConnection() {
|
|
||||||
return connection;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getDescription(MysqlField... description) {
|
private String getDescription(MysqlField... description) {
|
||||||
String desc = "(";
|
String desc = "(";
|
||||||
|
|
||||||
@@ -87,4 +45,46 @@ public class MysqlDatabase {
|
|||||||
|
|
||||||
return desc;
|
return desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean createTableIfNotExists(String name, MysqlField... description) {
|
||||||
|
return MysqlQueryHandler.queryNoResult(connection, "CREATE TABLE IF NOT EXISTS `" + name + "` " + getDescription(description) + ";");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean dropTable(String name) {
|
||||||
|
return MysqlQueryHandler.queryNoResult(connection, "DROP TABLE `" + name + "`;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean drop() {
|
||||||
|
return MysqlQueryHandler.queryNoResult(connection, "DROP DATABASE `" + getName() + "`;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
try {
|
||||||
|
return connection.getCatalog();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MysqlTable> getTables() {
|
||||||
|
try {
|
||||||
|
List<MysqlTable> tables = new ArrayList<>();
|
||||||
|
DatabaseMetaData metadata = connection.getMetaData();
|
||||||
|
ResultSet queryResults = metadata.getTables(null, null, "%", null);
|
||||||
|
|
||||||
|
while (queryResults.next()) {
|
||||||
|
tables.add(new MysqlTable(this, queryResults.getString(3)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return tables;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Connection getConnection() {
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,133 +1,113 @@
|
|||||||
package com.redstoner.misc.mysql.elements;
|
package com.redstoner.misc.mysql.elements;
|
||||||
|
|
||||||
|
import com.redstoner.misc.mysql.MysqlQueryHandler;
|
||||||
|
|
||||||
import java.sql.DatabaseMetaData;
|
import java.sql.DatabaseMetaData;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.redstoner.misc.mysql.MysqlQueryHandler;
|
public class MysqlTable {
|
||||||
|
|
||||||
public class MysqlTable
|
|
||||||
{
|
|
||||||
private MysqlDatabase database;
|
private MysqlDatabase database;
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
public MysqlTable(MysqlDatabase database, String name)
|
public MysqlTable(MysqlDatabase database, String name) {
|
||||||
{
|
|
||||||
this.database = database;
|
this.database = database;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName()
|
public String getName() {
|
||||||
{
|
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MysqlField[] describe()
|
public boolean insert(String... values) {
|
||||||
{
|
MysqlField[] description = describe();
|
||||||
try
|
if (values.length > 0 && values.length == description.length) {
|
||||||
{
|
String val = "(\"" + String.join("\",\"", values) + "\")";
|
||||||
|
return MysqlQueryHandler.queryNoResult(
|
||||||
|
database.getConnection(),
|
||||||
|
"INSERT INTO `" + name + "` VALUES " + val + ";"
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public MysqlField[] describe() {
|
||||||
|
try {
|
||||||
List<MysqlField> description = new ArrayList<>();
|
List<MysqlField> description = new ArrayList<>();
|
||||||
DatabaseMetaData metadata = database.getConnection().getMetaData();
|
DatabaseMetaData metadata = database.getConnection().getMetaData();
|
||||||
ResultSet queryResults = metadata.getColumns(null, null, name, null);
|
ResultSet queryResults = metadata.getColumns(null, null, name, null);
|
||||||
while (queryResults.next())
|
while (queryResults.next()) {
|
||||||
{
|
description.add(new MysqlField(
|
||||||
description.add(new MysqlField(queryResults.getString(4),
|
queryResults.getString(4),
|
||||||
queryResults.getString(6).split(" ")[0] + "(" + queryResults.getString(7) + ")",
|
queryResults.getString(6).split(" ")[0] + "(" + queryResults.getString(7) + ")",
|
||||||
queryResults.getBoolean(11)));
|
queryResults.getBoolean(11)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
return description.toArray(new MysqlField[0]);
|
return description.toArray(new MysqlField[0]);
|
||||||
}
|
} catch (SQLException e) {
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean insert(String... values)
|
public Object[] get(String fieldName, MysqlConstraint... constraints) {
|
||||||
{
|
ResultSet results = MysqlQueryHandler.queryResult(
|
||||||
MysqlField[] description = describe();
|
database.getConnection(),
|
||||||
if (values.length > 0 && values.length == description.length)
|
"SELECT " + fieldName + " FROM `" + name + "`" + getConstraints(constraints) + ";"
|
||||||
{
|
);
|
||||||
String val = "(\"" + String.join("\",\"", values) + "\")";
|
|
||||||
return MysqlQueryHandler.queryNoResult(database.getConnection(),
|
|
||||||
"INSERT INTO `" + name + "` VALUES " + val + ";");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object[] get(String fieldName, MysqlConstraint... constraints)
|
|
||||||
{
|
|
||||||
ResultSet results = MysqlQueryHandler.queryResult(database.getConnection(),
|
|
||||||
"SELECT " + fieldName + " FROM `" + name + "`" + getConstraints(constraints) + ";");
|
|
||||||
List<Object> resObj = new ArrayList<>();
|
List<Object> resObj = new ArrayList<>();
|
||||||
try
|
try {
|
||||||
{
|
while (results.next()) {
|
||||||
while (results.next())
|
|
||||||
{
|
|
||||||
resObj.add(results.getObject(1));
|
resObj.add(results.getObject(1));
|
||||||
}
|
}
|
||||||
}
|
} catch (SQLException e) {
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return new Object[0];
|
return new Object[0];
|
||||||
}
|
}
|
||||||
return resObj.toArray(new Object[0]);
|
return resObj.toArray(new Object[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object[] get(String statement)
|
private String getConstraints(MysqlConstraint... constraints) {
|
||||||
{
|
|
||||||
ResultSet results = MysqlQueryHandler.queryResult(database.getConnection(), statement);
|
|
||||||
List<Object> resObj = new ArrayList<>();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
while (results.next())
|
|
||||||
{
|
|
||||||
resObj.add(results.getObject(1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
return new Object[0];
|
|
||||||
}
|
|
||||||
return resObj.toArray(new Object[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean delete(MysqlConstraint... constraints)
|
|
||||||
{
|
|
||||||
return MysqlQueryHandler.queryNoResult(database.getConnection(),
|
|
||||||
"DELETE FROM `" + name + "`" + getConstraints(constraints) + ";");
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean drop()
|
|
||||||
{
|
|
||||||
return MysqlQueryHandler.queryNoResult(database.getConnection(), "DROP TABLE `" + name + "`;");
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getConstraints(MysqlConstraint... constraints)
|
|
||||||
{
|
|
||||||
String cons = "";
|
String cons = "";
|
||||||
if (constraints.length > 0)
|
if (constraints.length > 0) {
|
||||||
{
|
|
||||||
cons += " WHERE ";
|
cons += " WHERE ";
|
||||||
for (int i = 0; i < constraints.length; i++)
|
for (int i = 0; i < constraints.length; i++) {
|
||||||
{
|
|
||||||
MysqlConstraint constraint = constraints[i];
|
MysqlConstraint constraint = constraints[i];
|
||||||
cons += constraint.getFieldName() + constraint.getOperator().toString() + "\"" + constraint.getValue()
|
cons += constraint.getFieldName() + constraint.getOperator().toString() + "\"" + constraint.getValue()
|
||||||
+ "\"";
|
+ "\"";
|
||||||
if (i < constraints.length - 1)
|
if (i < constraints.length - 1) {
|
||||||
{
|
|
||||||
cons += " AND ";
|
cons += " AND ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cons;
|
return cons;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object[] get(String statement) {
|
||||||
|
ResultSet results = MysqlQueryHandler.queryResult(database.getConnection(), statement);
|
||||||
|
List<Object> resObj = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
while (results.next()) {
|
||||||
|
resObj.add(results.getObject(1));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return new Object[0];
|
||||||
|
}
|
||||||
|
return resObj.toArray(new Object[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean delete(MysqlConstraint... constraints) {
|
||||||
|
return MysqlQueryHandler.queryNoResult(
|
||||||
|
database.getConnection(),
|
||||||
|
"DELETE FROM `" + name + "`" + getConstraints(constraints) + ";"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean drop() {
|
||||||
|
return MysqlQueryHandler.queryNoResult(database.getConnection(), "DROP TABLE `" + name + "`;");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,45 +1,21 @@
|
|||||||
package com.redstoner.misc.mysql.types;
|
package com.redstoner.misc.mysql.types;
|
||||||
|
|
||||||
import com.redstoner.misc.mysql.types.date.Date;
|
import com.redstoner.misc.mysql.types.date.*;
|
||||||
import com.redstoner.misc.mysql.types.date.DateTime;
|
|
||||||
import com.redstoner.misc.mysql.types.date.Time;
|
|
||||||
import com.redstoner.misc.mysql.types.date.TimeStamp;
|
|
||||||
import com.redstoner.misc.mysql.types.date.Year;
|
|
||||||
import com.redstoner.misc.mysql.types.number.BigInt;
|
|
||||||
import com.redstoner.misc.mysql.types.number.Decimal;
|
|
||||||
import com.redstoner.misc.mysql.types.number.Double;
|
import com.redstoner.misc.mysql.types.number.Double;
|
||||||
import com.redstoner.misc.mysql.types.number.Float;
|
import com.redstoner.misc.mysql.types.number.Float;
|
||||||
import com.redstoner.misc.mysql.types.number.Int;
|
import com.redstoner.misc.mysql.types.number.*;
|
||||||
import com.redstoner.misc.mysql.types.number.MediumInt;
|
|
||||||
import com.redstoner.misc.mysql.types.number.SmallInt;
|
|
||||||
import com.redstoner.misc.mysql.types.number.TinyInt;
|
|
||||||
import com.redstoner.misc.mysql.types.text.Blob;
|
|
||||||
import com.redstoner.misc.mysql.types.text.Char;
|
|
||||||
import com.redstoner.misc.mysql.types.text.Enum;
|
import com.redstoner.misc.mysql.types.text.Enum;
|
||||||
import com.redstoner.misc.mysql.types.text.LongBlob;
|
import com.redstoner.misc.mysql.types.text.*;
|
||||||
import com.redstoner.misc.mysql.types.text.LongText;
|
|
||||||
import com.redstoner.misc.mysql.types.text.MediumBlob;
|
|
||||||
import com.redstoner.misc.mysql.types.text.MediumText;
|
|
||||||
import com.redstoner.misc.mysql.types.text.Set;
|
|
||||||
import com.redstoner.misc.mysql.types.text.Text;
|
|
||||||
import com.redstoner.misc.mysql.types.text.TinyText;
|
|
||||||
import com.redstoner.misc.mysql.types.text.VarChar;
|
|
||||||
|
|
||||||
public abstract class MysqlType
|
public abstract class MysqlType {
|
||||||
{
|
public static MysqlType getTypeFromString(String type) {
|
||||||
public abstract String getName();
|
|
||||||
|
|
||||||
public static MysqlType getTypeFromString(String type)
|
|
||||||
{
|
|
||||||
String[] splitType = type.split("\\(");
|
String[] splitType = type.split("\\(");
|
||||||
String toSwitch = splitType[0].toUpperCase();
|
String toSwitch = splitType[0].toUpperCase();
|
||||||
String value = "";
|
String value = "";
|
||||||
if (type.contains("(") && type.endsWith(")"))
|
if (type.contains("(") && type.endsWith(")")) {
|
||||||
{
|
|
||||||
value = splitType[1].substring(0, splitType[1].length() - 1);
|
value = splitType[1].substring(0, splitType[1].length() - 1);
|
||||||
}
|
}
|
||||||
switch (toSwitch)
|
switch (toSwitch) {
|
||||||
{
|
|
||||||
case "CHAR":
|
case "CHAR":
|
||||||
return new Char(Integer.valueOf(value));
|
return new Char(Integer.valueOf(value));
|
||||||
case "ENUM":
|
case "ENUM":
|
||||||
@@ -93,4 +69,6 @@ public abstract class MysqlType
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract String getName();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,23 +2,22 @@ package com.redstoner.modules;
|
|||||||
|
|
||||||
import com.redstoner.annotations.Version;
|
import com.redstoner.annotations.Version;
|
||||||
|
|
||||||
/** This class shall be used for "CoreModules", which are acting on a lower level than modules and are also exempted from being disabled or reloaded on the go.</br>
|
/**
|
||||||
|
* This class shall be used for "CoreModules", which are acting on a lower level than modules and are also exempted from being disabled or reloaded on the go.</br>
|
||||||
* Please note that CoreModules will not be known to the ModuleLoader itself!</br>
|
* Please note that CoreModules will not be known to the ModuleLoader itself!</br>
|
||||||
* Examples are the ModuleLoader and the Debugger.
|
* Examples are the ModuleLoader and the Debugger.
|
||||||
*
|
*
|
||||||
* @author Pepich */
|
* @author Pepich
|
||||||
@Version(major = 2, minor = 0, revision = 0, compatible = -1)
|
*/
|
||||||
public interface CoreModule extends Module
|
@Version (major = 2, minor = 0, revision = 0, compatible = -1)
|
||||||
{
|
public interface CoreModule extends Module {
|
||||||
/** Core modules don't need to be enabled. */
|
/** Core modules don't need to be enabled. */
|
||||||
@Override
|
@Override
|
||||||
public default boolean onEnable()
|
public default boolean onEnable() {
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Core modules don't need to be disabled. */
|
/** Core modules don't need to be disabled. */
|
||||||
@Override
|
@Override
|
||||||
public default void onDisable()
|
public default void onDisable() {}
|
||||||
{}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,52 +3,51 @@ package com.redstoner.modules;
|
|||||||
import com.redstoner.annotations.Version;
|
import com.redstoner.annotations.Version;
|
||||||
import com.redstoner.coremods.moduleLoader.ModuleLoader;
|
import com.redstoner.coremods.moduleLoader.ModuleLoader;
|
||||||
|
|
||||||
/** Interface for the Module class. Modules must always have an empty constructor to be invoked by the ModuleLoader.
|
/**
|
||||||
|
* Interface for the Module class. Modules must always have an empty constructor to be invoked by the ModuleLoader.
|
||||||
*
|
*
|
||||||
* @author Pepich */
|
* @author Pepich
|
||||||
@Version(major = 4, minor = 0, revision = 0, compatible = 0)
|
*/
|
||||||
public interface Module
|
@Version (major = 4, minor = 0, revision = 0, compatible = 0)
|
||||||
{
|
public interface Module {
|
||||||
/** Will be called when the module gets enabled. */
|
/** Will be called when the module gets enabled. */
|
||||||
public default boolean onEnable()
|
public default boolean onEnable() {
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This methods gets called after all modules were enabled, please use this method to register commands and similar. <br/>
|
/**
|
||||||
* It will only get called if and only if the module was successfully enabled. */
|
* This methods gets called after all modules were enabled, please use this method to register commands and similar. <br/>
|
||||||
public default void postEnable()
|
* It will only get called if and only if the module was successfully enabled.
|
||||||
{}
|
*/
|
||||||
|
public default void postEnable() {}
|
||||||
|
|
||||||
/** Will be called when the module gets disabled. */
|
/** Will be called when the module gets disabled. */
|
||||||
public default void onDisable()
|
public default void onDisable() {}
|
||||||
{}
|
|
||||||
|
|
||||||
/** Gets called on registration of the module, when this option is selected for command registration
|
/**
|
||||||
|
* Gets called on registration of the module, when this option is selected for command registration
|
||||||
*
|
*
|
||||||
* @return The String used for the CommandManager to register the commands. */
|
* @return The String used for the CommandManager to register the commands.
|
||||||
public default String getCommandString()
|
*/
|
||||||
{
|
public default String getCommandString() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public default ModuleLogger getLogger()
|
|
||||||
{
|
|
||||||
return ModuleLoader.getModuleLogger(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** This method gets run the very first time a module gets loaded. You can use this to set up file structures or background data. */
|
/** This method gets run the very first time a module gets loaded. You can use this to set up file structures or background data. */
|
||||||
public default void firstLoad()
|
public default void firstLoad() {}
|
||||||
{}
|
|
||||||
|
|
||||||
/** This method gets run every time a module gets loaded and its version has changed.
|
/**
|
||||||
|
* This method gets run every time a module gets loaded and its version has changed.
|
||||||
*
|
*
|
||||||
* @param old The version of the previous module. */
|
* @param old The version of the previous module.
|
||||||
public default void migrate(Version old)
|
*/
|
||||||
{}
|
public default void migrate(Version old) {}
|
||||||
|
|
||||||
default void setPrefix(final String name)
|
default void setPrefix(final String name) {
|
||||||
{
|
|
||||||
getLogger().setName(name);
|
getLogger().setName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public default ModuleLogger getLogger() {
|
||||||
|
return ModuleLoader.getModuleLogger(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,77 +1,63 @@
|
|||||||
package com.redstoner.modules;
|
package com.redstoner.modules;
|
||||||
|
|
||||||
|
import com.redstoner.annotations.Version;
|
||||||
|
import net.nemez.chatapi.ChatAPI;
|
||||||
|
import net.nemez.chatapi.click.Message;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import com.redstoner.annotations.Version;
|
@Version (major = 4, minor = 0, revision = 0, compatible = -1)
|
||||||
|
public class ModuleLogger {
|
||||||
import net.nemez.chatapi.ChatAPI;
|
|
||||||
import net.nemez.chatapi.click.Message;
|
|
||||||
|
|
||||||
@Version(major = 4, minor = 0, revision = 0, compatible = -1)
|
|
||||||
public class ModuleLogger
|
|
||||||
{
|
|
||||||
public static final String PREFIX_WARN = "§8[§eWARN§8]:§7 ";
|
public static final String PREFIX_WARN = "§8[§eWARN§8]:§7 ";
|
||||||
public static final String PREFIX_ERROR = "§8[§cERROR§8]:§7 ";
|
public static final String PREFIX_ERROR = "§8[§cERROR§8]:§7 ";
|
||||||
public static final String PREFIX_INFO = "§8[§fINFO§8]:§7 ";
|
public static final String PREFIX_INFO = "§8[§fINFO§8]:§7 ";
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
public ModuleLogger(final String name)
|
public ModuleLogger(final String name) {
|
||||||
{
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void info(final String message)
|
public void info(final String message) {
|
||||||
{
|
|
||||||
Bukkit.getConsoleSender().sendMessage(PREFIX_INFO + getPrefix() + ChatAPI.colorify(null, message));
|
Bukkit.getConsoleSender().sendMessage(PREFIX_INFO + getPrefix() + ChatAPI.colorify(null, message));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void warn(final String message)
|
public String getPrefix() {
|
||||||
{
|
return getPrefix(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPrefix(final boolean error) {
|
||||||
|
return "§8[§" + (error ? 'c' : '2') + name + "§8]§7 ";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void warn(final String message) {
|
||||||
Bukkit.getConsoleSender().sendMessage(PREFIX_WARN + getPrefix() + ChatAPI.colorify(null, message));
|
Bukkit.getConsoleSender().sendMessage(PREFIX_WARN + getPrefix() + ChatAPI.colorify(null, message));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void error(final String message)
|
public void error(final String message) {
|
||||||
{
|
|
||||||
Bukkit.getConsoleSender().sendMessage(PREFIX_ERROR + getPrefix() + ChatAPI.colorify(null, message));
|
Bukkit.getConsoleSender().sendMessage(PREFIX_ERROR + getPrefix() + ChatAPI.colorify(null, message));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void message(final CommandSender recipient, final String... message)
|
public void message(final CommandSender recipient, final String... message) {
|
||||||
{
|
|
||||||
message(recipient, false, message);
|
message(recipient, false, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void message(final CommandSender recipient, final boolean error, final String... message)
|
public void message(final CommandSender recipient, final boolean error, final String... message) {
|
||||||
{
|
|
||||||
Message m = new Message(recipient, null);
|
Message m = new Message(recipient, null);
|
||||||
if (message.length == 1)
|
if (message.length == 1)
|
||||||
m.appendText(getPrefix(error) + message[0]);
|
m.appendText(getPrefix(error) + message[0]);
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
m.appendText(getHeader());
|
m.appendText(getHeader());
|
||||||
m.appendText("&7" + String.join("\n&7", message));
|
m.appendText("&7" + String.join("\n&7", message));
|
||||||
}
|
}
|
||||||
m.send();
|
m.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPrefix()
|
public String getHeader() {
|
||||||
{
|
|
||||||
return getPrefix(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPrefix(final boolean error)
|
|
||||||
{
|
|
||||||
return "§8[§" + (error ? 'c' : '2') + name + "§8]§7 ";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getHeader()
|
|
||||||
{
|
|
||||||
return "§2--=[ " + name + " ]=--\n";
|
return "§2--=[ " + name + " ]=--\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final void setName(final String name)
|
protected final void setName(final String name) {
|
||||||
{
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: ModuleLoader
|
name: ModuleLoader
|
||||||
version: 4.0.0
|
version: 5.2.2
|
||||||
authors: [pepich1851]
|
authors: [pepich1851, psrcek, LogalDeveloper, Minenash]
|
||||||
main: com.redstoner.misc.Main
|
main: com.redstoner.misc.Main
|
||||||
softdepend: [Vault]
|
softdepend: [Vault]
|
||||||
Reference in New Issue
Block a user