Added getplayerinfo, getlastexception, I can use op commands of this plugin
Added getplayerinfo, getlastexception, I can use op commands of this plugin
This commit is contained in:
parent
6eddb90154
commit
a119b293e7
346 changed files with 43376 additions and 21566 deletions
292
.metadata/.log
292
.metadata/.log
|
@ -453,3 +453,295 @@ user global configuration and to define the default location to store repositori
|
||||||
not correct please set the HOME environment variable and restart Eclipse. Otherwise Git for Windows and
|
not correct please set the HOME environment variable and restart Eclipse. Otherwise Git for Windows and
|
||||||
EGit might behave differently since they see different configuration options.
|
EGit might behave differently since they see different configuration options.
|
||||||
This warning can be switched off on the Team > Git > Confirmations and Warnings preference page.
|
This warning can be switched off on the Team > Git > Confirmations and Warnings preference page.
|
||||||
|
!SESSION 2015-08-09 02:28:26.809 -----------------------------------------------
|
||||||
|
eclipse.buildId=M20130204-1200
|
||||||
|
java.version=1.8.0_45
|
||||||
|
java.vendor=Oracle Corporation
|
||||||
|
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=hu_HU
|
||||||
|
Framework arguments: -product org.eclipse.epp.package.jee.product
|
||||||
|
Command-line arguments: -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.jee.product
|
||||||
|
|
||||||
|
!ENTRY org.eclipse.egit.ui 2 0 2015-08-09 02:29:00.097
|
||||||
|
!MESSAGE Warning: EGit couldn't detect the installation path "gitPrefix" of native Git. Hence EGit can't respect system level
|
||||||
|
Git settings which might be configured in ${gitPrefix}/etc/gitconfig under the native Git installation directory.
|
||||||
|
The most important of these settings is core.autocrlf. Git for Windows by default sets this parameter to true in
|
||||||
|
this system level configuration. The Git installation location can be configured on the
|
||||||
|
Team > Git > Configuration preference page's 'System Settings' tab.
|
||||||
|
This warning can be switched off on the Team > Git > Confirmations and Warnings preference page.
|
||||||
|
|
||||||
|
!ENTRY org.eclipse.egit.ui 2 0 2015-08-09 02:29:00.163
|
||||||
|
!MESSAGE Warning: The environment variable HOME is not set. The following directory will be used to store the Git
|
||||||
|
user global configuration and to define the default location to store repositories: 'C:\Users\Norbi'. If this is
|
||||||
|
not correct please set the HOME environment variable and restart Eclipse. Otherwise Git for Windows and
|
||||||
|
EGit might behave differently since they see different configuration options.
|
||||||
|
This warning can be switched off on the Team > Git > Confirmations and Warnings preference page.
|
||||||
|
!SESSION 2015-08-09 12:44:08.125 -----------------------------------------------
|
||||||
|
eclipse.buildId=M20130204-1200
|
||||||
|
java.version=1.8.0_45
|
||||||
|
java.vendor=Oracle Corporation
|
||||||
|
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=hu_HU
|
||||||
|
Framework arguments: -product org.eclipse.epp.package.jee.product
|
||||||
|
Command-line arguments: -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.jee.product
|
||||||
|
|
||||||
|
!ENTRY org.eclipse.egit.ui 2 0 2015-08-09 12:44:49.818
|
||||||
|
!MESSAGE Warning: EGit couldn't detect the installation path "gitPrefix" of native Git. Hence EGit can't respect system level
|
||||||
|
Git settings which might be configured in ${gitPrefix}/etc/gitconfig under the native Git installation directory.
|
||||||
|
The most important of these settings is core.autocrlf. Git for Windows by default sets this parameter to true in
|
||||||
|
this system level configuration. The Git installation location can be configured on the
|
||||||
|
Team > Git > Configuration preference page's 'System Settings' tab.
|
||||||
|
This warning can be switched off on the Team > Git > Confirmations and Warnings preference page.
|
||||||
|
|
||||||
|
!ENTRY org.eclipse.egit.ui 2 0 2015-08-09 12:44:49.857
|
||||||
|
!MESSAGE Warning: The environment variable HOME is not set. The following directory will be used to store the Git
|
||||||
|
user global configuration and to define the default location to store repositories: 'C:\Users\Norbi'. If this is
|
||||||
|
not correct please set the HOME environment variable and restart Eclipse. Otherwise Git for Windows and
|
||||||
|
EGit might behave differently since they see different configuration options.
|
||||||
|
This warning can be switched off on the Team > Git > Confirmations and Warnings preference page.
|
||||||
|
|
||||||
|
!ENTRY org.eclipse.jdt.core 4 4 2015-08-09 16:10:06.274
|
||||||
|
!MESSAGE JavaBuilder handling CoreException
|
||||||
|
!STACK 1
|
||||||
|
org.eclipse.core.runtime.CoreException: Could not write file: D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin\TheButtonAutoFlair\bin\tk\sznp\thebuttonautoflair\PluginMain.class.
|
||||||
|
at org.eclipse.core.internal.filesystem.Policy.error(Policy.java:55)
|
||||||
|
at org.eclipse.core.internal.filesystem.local.LocalFile.openOutputStream(LocalFile.java:397)
|
||||||
|
at org.eclipse.core.internal.localstore.FileSystemResourceManager.write(FileSystemResourceManager.java:1101)
|
||||||
|
at org.eclipse.core.internal.resources.File.internalSetContents(File.java:321)
|
||||||
|
at org.eclipse.core.internal.resources.File.setContents(File.java:360)
|
||||||
|
at org.eclipse.core.internal.resources.File.setContents(File.java:464)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.writeClassFileContents(IncrementalImageBuilder.java:835)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.writeClassFile(AbstractImageBuilder.java:857)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.acceptResult(AbstractImageBuilder.java:188)
|
||||||
|
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:510)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:365)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.compile(IncrementalImageBuilder.java:329)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:302)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.build(IncrementalImageBuilder.java:134)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildDeltas(JavaBuilder.java:265)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:193)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:726)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
|
||||||
|
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
|
||||||
|
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
|
||||||
|
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
|
||||||
|
Caused by: java.io.FileNotFoundException: D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin\TheButtonAutoFlair\bin\tk\sznp\thebuttonautoflair\PluginMain.class (A folyamat nem fér hozzá a fájlhoz, mert azt egy másik folyamat használja)
|
||||||
|
at java.io.FileOutputStream.open0(Native Method)
|
||||||
|
at java.io.FileOutputStream.open(Unknown Source)
|
||||||
|
at java.io.FileOutputStream.<init>(Unknown Source)
|
||||||
|
at org.eclipse.core.internal.filesystem.local.LocalFile.openOutputStream(LocalFile.java:388)
|
||||||
|
... 26 more
|
||||||
|
!SUBENTRY 1 org.eclipse.core.filesystem 4 272 2015-08-09 16:10:06.403
|
||||||
|
!MESSAGE Could not write file: D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin\TheButtonAutoFlair\bin\tk\sznp\thebuttonautoflair\PluginMain.class.
|
||||||
|
!STACK 0
|
||||||
|
java.io.FileNotFoundException: D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin\TheButtonAutoFlair\bin\tk\sznp\thebuttonautoflair\PluginMain.class (A folyamat nem fér hozzá a fájlhoz, mert azt egy másik folyamat használja)
|
||||||
|
at java.io.FileOutputStream.open0(Native Method)
|
||||||
|
at java.io.FileOutputStream.open(Unknown Source)
|
||||||
|
at java.io.FileOutputStream.<init>(Unknown Source)
|
||||||
|
at org.eclipse.core.internal.filesystem.local.LocalFile.openOutputStream(LocalFile.java:388)
|
||||||
|
at org.eclipse.core.internal.localstore.FileSystemResourceManager.write(FileSystemResourceManager.java:1101)
|
||||||
|
at org.eclipse.core.internal.resources.File.internalSetContents(File.java:321)
|
||||||
|
at org.eclipse.core.internal.resources.File.setContents(File.java:360)
|
||||||
|
at org.eclipse.core.internal.resources.File.setContents(File.java:464)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.writeClassFileContents(IncrementalImageBuilder.java:835)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.writeClassFile(AbstractImageBuilder.java:857)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.acceptResult(AbstractImageBuilder.java:188)
|
||||||
|
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:510)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:365)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.compile(IncrementalImageBuilder.java:329)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:302)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.build(IncrementalImageBuilder.java:134)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildDeltas(JavaBuilder.java:265)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:193)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:726)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
|
||||||
|
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
|
||||||
|
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
|
||||||
|
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
|
||||||
|
|
||||||
|
!ENTRY org.eclipse.jdt.core 4 4 2015-08-09 16:10:06.407
|
||||||
|
!MESSAGE JavaBuilder handling ImageBuilderInternalException while building: TheButtonAutoFlair
|
||||||
|
!STACK 1
|
||||||
|
org.eclipse.core.internal.resources.ResourceException: Problems encountered while deleting resources.
|
||||||
|
at org.eclipse.core.internal.resources.Resource.delete(Resource.java:816)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.removeClassFile(IncrementalImageBuilder.java:757)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.removeSecondaryTypes(IncrementalImageBuilder.java:770)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.build(IncrementalImageBuilder.java:135)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildDeltas(JavaBuilder.java:265)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:193)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:726)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
|
||||||
|
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
|
||||||
|
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
|
||||||
|
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
|
||||||
|
Contains: Could not delete 'D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin\TheButtonAutoFlair\bin\tk\sznp\thebuttonautoflair\PluginMain.class'.
|
||||||
|
org.eclipse.core.runtime.CoreException: Problems encountered while deleting files.
|
||||||
|
at org.eclipse.core.internal.filesystem.local.LocalFile.delete(LocalFile.java:131)
|
||||||
|
at org.eclipse.core.internal.resources.ResourceTree.internalDeleteFile(ResourceTree.java:304)
|
||||||
|
at org.eclipse.core.internal.resources.ResourceTree.standardDeleteFile(ResourceTree.java:785)
|
||||||
|
at org.eclipse.core.internal.resources.Resource.unprotectedDelete(Resource.java:1973)
|
||||||
|
at org.eclipse.core.internal.resources.Resource.delete(Resource.java:803)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.removeClassFile(IncrementalImageBuilder.java:757)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.removeSecondaryTypes(IncrementalImageBuilder.java:770)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.build(IncrementalImageBuilder.java:135)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildDeltas(JavaBuilder.java:265)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:193)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:726)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
|
||||||
|
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
|
||||||
|
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
|
||||||
|
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
|
||||||
|
Contains: Could not delete: D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin\TheButtonAutoFlair\bin\tk\sznp\thebuttonautoflair\PluginMain.class.
|
||||||
|
!SUBENTRY 1 org.eclipse.core.resources 4 273 2015-08-09 16:10:06.408
|
||||||
|
!MESSAGE Problems encountered while deleting resources.
|
||||||
|
!SUBENTRY 2 org.eclipse.core.resources 4 273 2015-08-09 16:10:06.408
|
||||||
|
!MESSAGE Could not delete 'D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin\TheButtonAutoFlair\bin\tk\sznp\thebuttonautoflair\PluginMain.class'.
|
||||||
|
!STACK 1
|
||||||
|
org.eclipse.core.runtime.CoreException: Problems encountered while deleting files.
|
||||||
|
at org.eclipse.core.internal.filesystem.local.LocalFile.delete(LocalFile.java:131)
|
||||||
|
at org.eclipse.core.internal.resources.ResourceTree.internalDeleteFile(ResourceTree.java:304)
|
||||||
|
at org.eclipse.core.internal.resources.ResourceTree.standardDeleteFile(ResourceTree.java:785)
|
||||||
|
at org.eclipse.core.internal.resources.Resource.unprotectedDelete(Resource.java:1973)
|
||||||
|
at org.eclipse.core.internal.resources.Resource.delete(Resource.java:803)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.removeClassFile(IncrementalImageBuilder.java:757)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.removeSecondaryTypes(IncrementalImageBuilder.java:770)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.build(IncrementalImageBuilder.java:135)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildDeltas(JavaBuilder.java:265)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:193)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:726)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
|
||||||
|
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
|
||||||
|
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
|
||||||
|
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
|
||||||
|
Contains: Could not delete: D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin\TheButtonAutoFlair\bin\tk\sznp\thebuttonautoflair\PluginMain.class.
|
||||||
|
!SUBENTRY 3 org.eclipse.core.filesystem 4 273 2015-08-09 16:10:06.408
|
||||||
|
!MESSAGE Problems encountered while deleting files.
|
||||||
|
!SUBENTRY 4 org.eclipse.core.filesystem 4 273 2015-08-09 16:10:06.408
|
||||||
|
!MESSAGE Could not delete: D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin\TheButtonAutoFlair\bin\tk\sznp\thebuttonautoflair\PluginMain.class.
|
||||||
|
|
||||||
|
!ENTRY org.eclipse.jdt.core 4 4 2015-08-09 16:10:11.009
|
||||||
|
!MESSAGE JavaBuilder handling ImageBuilderInternalException while building: TheButtonAutoFlair
|
||||||
|
!STACK 1
|
||||||
|
org.eclipse.core.internal.resources.ResourceException: Problems encountered while deleting resources.
|
||||||
|
at org.eclipse.core.internal.resources.Resource.delete(Resource.java:816)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.cleanOutputFolders(BatchImageBuilder.java:114)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.build(BatchImageBuilder.java:46)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildAll(JavaBuilder.java:254)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:178)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:726)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
|
||||||
|
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
|
||||||
|
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
|
||||||
|
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
|
||||||
|
Contains: Could not delete '/TheButtonAutoFlair/bin/tk'.
|
||||||
|
org.eclipse.core.internal.resources.ResourceException: Problems encountered while deleting resources.
|
||||||
|
at org.eclipse.core.internal.localstore.FileSystemResourceManager.delete(FileSystemResourceManager.java:352)
|
||||||
|
at org.eclipse.core.internal.resources.ResourceTree.internalDeleteFolder(ResourceTree.java:352)
|
||||||
|
at org.eclipse.core.internal.resources.ResourceTree.standardDeleteFolder(ResourceTree.java:798)
|
||||||
|
at org.eclipse.core.internal.resources.Resource.unprotectedDelete(Resource.java:1977)
|
||||||
|
at org.eclipse.core.internal.resources.Resource.delete(Resource.java:803)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.cleanOutputFolders(BatchImageBuilder.java:114)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.build(BatchImageBuilder.java:46)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildAll(JavaBuilder.java:254)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:178)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:726)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
|
||||||
|
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
|
||||||
|
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
|
||||||
|
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
|
||||||
|
Contains: Problems encountered while deleting files.
|
||||||
|
Contains: Could not delete: D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin\TheButtonAutoFlair\bin\tk\sznp\thebuttonautoflair\PluginMain.class.
|
||||||
|
Contains: Could not delete: D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin\TheButtonAutoFlair\bin\tk\sznp\thebuttonautoflair.
|
||||||
|
Contains: Could not delete: D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin\TheButtonAutoFlair\bin\tk\sznp.
|
||||||
|
Contains: Could not delete: D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin\TheButtonAutoFlair\bin\tk.
|
||||||
|
!SUBENTRY 1 org.eclipse.core.resources 4 273 2015-08-09 16:10:11.009
|
||||||
|
!MESSAGE Problems encountered while deleting resources.
|
||||||
|
!SUBENTRY 2 org.eclipse.core.resources 4 273 2015-08-09 16:10:11.010
|
||||||
|
!MESSAGE Could not delete '/TheButtonAutoFlair/bin/tk'.
|
||||||
|
!STACK 1
|
||||||
|
org.eclipse.core.internal.resources.ResourceException: Problems encountered while deleting resources.
|
||||||
|
at org.eclipse.core.internal.localstore.FileSystemResourceManager.delete(FileSystemResourceManager.java:352)
|
||||||
|
at org.eclipse.core.internal.resources.ResourceTree.internalDeleteFolder(ResourceTree.java:352)
|
||||||
|
at org.eclipse.core.internal.resources.ResourceTree.standardDeleteFolder(ResourceTree.java:798)
|
||||||
|
at org.eclipse.core.internal.resources.Resource.unprotectedDelete(Resource.java:1977)
|
||||||
|
at org.eclipse.core.internal.resources.Resource.delete(Resource.java:803)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.cleanOutputFolders(BatchImageBuilder.java:114)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.build(BatchImageBuilder.java:46)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildAll(JavaBuilder.java:254)
|
||||||
|
at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:178)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:726)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
|
||||||
|
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
|
||||||
|
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
|
||||||
|
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
|
||||||
|
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
|
||||||
|
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
|
||||||
|
Contains: Problems encountered while deleting files.
|
||||||
|
Contains: Could not delete: D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin\TheButtonAutoFlair\bin\tk\sznp\thebuttonautoflair\PluginMain.class.
|
||||||
|
Contains: Could not delete: D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin\TheButtonAutoFlair\bin\tk\sznp\thebuttonautoflair.
|
||||||
|
Contains: Could not delete: D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin\TheButtonAutoFlair\bin\tk\sznp.
|
||||||
|
Contains: Could not delete: D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin\TheButtonAutoFlair\bin\tk.
|
||||||
|
!SUBENTRY 3 org.eclipse.core.resources 4 273 2015-08-09 16:10:11.010
|
||||||
|
!MESSAGE Problems encountered while deleting resources.
|
||||||
|
!SUBENTRY 4 org.eclipse.core.filesystem 4 273 2015-08-09 16:10:11.010
|
||||||
|
!MESSAGE Problems encountered while deleting files.
|
||||||
|
!SUBENTRY 5 org.eclipse.core.filesystem 4 273 2015-08-09 16:10:11.010
|
||||||
|
!MESSAGE Could not delete: D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin\TheButtonAutoFlair\bin\tk\sznp\thebuttonautoflair\PluginMain.class.
|
||||||
|
!SUBENTRY 5 org.eclipse.core.filesystem 4 273 2015-08-09 16:10:11.010
|
||||||
|
!MESSAGE Could not delete: D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin\TheButtonAutoFlair\bin\tk\sznp\thebuttonautoflair.
|
||||||
|
!SUBENTRY 5 org.eclipse.core.filesystem 4 273 2015-08-09 16:10:11.010
|
||||||
|
!MESSAGE Could not delete: D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin\TheButtonAutoFlair\bin\tk\sznp.
|
||||||
|
!SUBENTRY 5 org.eclipse.core.filesystem 4 273 2015-08-09 16:10:11.010
|
||||||
|
!MESSAGE Could not delete: D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin\TheButtonAutoFlair\bin\tk.
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,144 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;*/
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.*/
|
||||||
|
else if(args[0].toLowerCase()=="admin")
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage(msg);
|
||||||
|
else
|
||||||
|
System.out.println(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "reload":
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "playerinfo":
|
||||||
|
DoPlayerInfo(player, args);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoPlayerInfo(Player player, String[] args)
|
||||||
|
{
|
||||||
|
//args[0] is "admin" - args[1] is "playerinfo"
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,431 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
|
||||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
|
||||||
|
|
||||||
public class PluginMain extends JavaPlugin
|
|
||||||
{ //Translated to Java: 2015.07.15.
|
|
||||||
//A user, which flair isn't obtainable:
|
|
||||||
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
|
||||||
private static PluginMain Instance;
|
|
||||||
// Fired when plugin is first enabled
|
|
||||||
@Override
|
|
||||||
public void onEnable()
|
|
||||||
{
|
|
||||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
|
||||||
//System.out.println("Original C# version: http://pastebin.com/tX8xCPbp");
|
|
||||||
//System.out.println("The Java version is... Also made by the same person.");
|
|
||||||
//System.out.println("With the help of StackOverflow and similar.");
|
|
||||||
/*catch(MalformedURLException e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
catch(IOException e)
|
|
||||||
{
|
|
||||||
}*/
|
|
||||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
|
||||||
//System.out.println("Registering commands...");
|
|
||||||
this.getCommand("u").setExecutor(new Commands());
|
|
||||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
|
||||||
Instance=this; //2015.08.08.
|
|
||||||
try {
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//AcceptedPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
//System.out.println("Name: "+name);
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("flairsignored.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//IgnoredPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
|
||||||
String line;
|
|
||||||
while((line=br.readLine())!=null)
|
|
||||||
{
|
|
||||||
String[] s=line.split(" ");
|
|
||||||
TownColors.put(s[0], s[1]);
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//System.out.println("Registering done.");
|
|
||||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
|
||||||
Thread t=new Thread(r);
|
|
||||||
t.start();
|
|
||||||
}
|
|
||||||
Boolean stop=false;
|
|
||||||
// Fired when plugin is disabled
|
|
||||||
@Override
|
|
||||||
public void onDisable()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
FileWriter fw;
|
|
||||||
fw = new FileWriter("flairsaccepted.txt");
|
|
||||||
fw.close();
|
|
||||||
fw = new FileWriter("flairsignored.txt");
|
|
||||||
fw.close();
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//for(String player : AcceptedPlayers)
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.AcceptedFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.IgnoredFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsignored.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stop=true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ThreadMethod() //<-- 2015.07.16.
|
|
||||||
{
|
|
||||||
/*System.out.println("Sleeping for 5 seconds..."); //2015.07.20.
|
|
||||||
try {
|
|
||||||
Thread.sleep(5000);
|
|
||||||
} catch (InterruptedException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
} //2015.07.20.*/
|
|
||||||
while(!stop)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
|
||||||
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
|
||||||
for(Object obj : json)
|
|
||||||
{
|
|
||||||
JSONObject item = (JSONObject)obj;
|
|
||||||
String author=item.getJSONObject("data").getString("author");
|
|
||||||
String ign=item.getJSONObject("data").getString("body");
|
|
||||||
int start = ign.indexOf("IGN:") + "IGN:".length();
|
|
||||||
int end = ign.indexOf(' ', start);
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
end=ign.indexOf('\n', start); //2015.07.15.
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
ign = ign.substring(start);
|
|
||||||
else
|
|
||||||
ign = ign.substring(start, end);
|
|
||||||
ign = ign.trim();
|
|
||||||
if(HasIGFlair(ign))
|
|
||||||
continue;
|
|
||||||
//System.out.println("Author: "+author);
|
|
||||||
try {
|
|
||||||
Thread.sleep(10);
|
|
||||||
} catch(InterruptedException ex) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
|
||||||
String flair;
|
|
||||||
if(flairdata.length > 1) //2015.07.15.
|
|
||||||
flair = flairdata[1];
|
|
||||||
else
|
|
||||||
flair="";
|
|
||||||
if (flair != "-1")
|
|
||||||
flair = flair + "s";
|
|
||||||
else
|
|
||||||
flair = "non-presser";
|
|
||||||
String flairclass;
|
|
||||||
//System.out.println("flairdata.length:"+flairdata.length);
|
|
||||||
if(flairdata.length>2)
|
|
||||||
flairclass = flairdata[2];
|
|
||||||
else
|
|
||||||
flairclass="unknown";
|
|
||||||
SetFlair(ign, flair, flairclass, author);
|
|
||||||
}
|
|
||||||
Thread.sleep(10000);
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
|
||||||
{
|
|
||||||
URL url = new URL(urlstr);
|
|
||||||
URLConnection con = url.openConnection();
|
|
||||||
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
|
||||||
InputStream in = con.getInputStream();
|
|
||||||
String encoding = con.getContentEncoding();
|
|
||||||
encoding = encoding == null ? "UTF-8" : encoding;
|
|
||||||
String body = IOUtils.toString(in, encoding);
|
|
||||||
in.close();
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
//It has to store offline player flairs too, therefore it can't use Player object
|
|
||||||
/*public static Map<String, String> PlayerFlairs=new HashMap<String, String>();
|
|
||||||
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
|
|
||||||
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
|
|
||||||
public static ArrayList<Player> Players=new ArrayList<Player>();
|
|
||||||
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
//public static Map<String, String> PlayerTowns=new HashMap<String, String>(); //2015.07.20.*/
|
|
||||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
|
||||||
public Boolean HasIGFlair(String playername)
|
|
||||||
{
|
|
||||||
/*Player player=null;
|
|
||||||
for(Player p : Players)
|
|
||||||
{
|
|
||||||
if(p.getName()==playername)
|
|
||||||
{
|
|
||||||
player=p;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(player==null)
|
|
||||||
return false;*/
|
|
||||||
//return PlayerFlairs.containsKey(playername);
|
|
||||||
//return MaybeOfflinePlayer.AllPlayers.containsKey(playername);
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
|
||||||
return p.Flair!=null; //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
|
||||||
{
|
|
||||||
String finalflair;
|
|
||||||
switch(flairclass)
|
|
||||||
{
|
|
||||||
case "press-1":
|
|
||||||
finalflair="§c("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-2":
|
|
||||||
finalflair="§6("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-3":
|
|
||||||
finalflair="§e("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-4":
|
|
||||||
finalflair="§a("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-5":
|
|
||||||
finalflair="§9("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-6":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "no-press":
|
|
||||||
finalflair="§7(non-pr.)§r";
|
|
||||||
break;
|
|
||||||
case "cheater":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "cant-press": //2015.08.08.
|
|
||||||
finalflair="§r(can't press)§r";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
finalflair="";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
|
||||||
return;
|
|
||||||
//PlayerFlairs.put(playername, finalflair);
|
|
||||||
//PlayerUserNames.put(playername, username);
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
|
||||||
p.Flair=finalflair; //2015.08.08.
|
|
||||||
p.UserName=username; //2015.08.08.
|
|
||||||
/*for(Player player : Players)
|
|
||||||
{
|
|
||||||
if(player.getName()==playername)
|
|
||||||
{
|
|
||||||
PlayerFlairs.put(player, finalflair);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
//System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass);
|
|
||||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
|
||||||
//for(Player player : Players)
|
|
||||||
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
//System.out.println("Online player: "+player.getName());
|
|
||||||
//System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername));
|
|
||||||
if(player.getName().equals(playername))
|
|
||||||
{
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
//player.setDisplayName(player.getDisplayName()+finalflair);
|
|
||||||
AppendPlayerDisplayFlair(player, username, finalflair);
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetFlair(Player player)
|
|
||||||
{ //2015.07.16.
|
|
||||||
//String flair=PlayerFlairs.get(player.getName());
|
|
||||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
|
||||||
return flair==null ? "" : flair;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
|
||||||
{
|
|
||||||
//if(IgnoredPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
|
||||||
return;
|
|
||||||
//if(AcceptedPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
|
||||||
//player.setDisplayName(player.getDisplayName()+flair);
|
|
||||||
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
else
|
|
||||||
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//System.out.println("A");
|
|
||||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
|
||||||
String[] colors = color.substring(1).split("§");
|
|
||||||
//String displayname=player.getDisplayName();
|
|
||||||
String displayname=player.getName(); //2015.08.08.
|
|
||||||
ArrayList<Integer> Positions=new ArrayList<>();
|
|
||||||
//System.out.println("B");
|
|
||||||
for(int i=0; i<displayname.length(); i++) {
|
|
||||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
|
||||||
Positions.add(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//System.out.println("C: Positions.size(): "+Positions.size());
|
|
||||||
String finalname="";
|
|
||||||
if(Positions.size()>=colors.length)
|
|
||||||
{
|
|
||||||
//System.out.println("D");
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<Positions.size(); i++)
|
|
||||||
{
|
|
||||||
int pos=Positions.get(i);
|
|
||||||
int nextpos;
|
|
||||||
if(i!=Positions.size()-1)
|
|
||||||
nextpos=Positions.get(i+1);
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
//String substr="§"+colors[x++]+displayname.substring(pos, nextpos-pos)+"§r";
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("F");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//System.out.println("E");
|
|
||||||
Positions.clear();
|
|
||||||
int unit=displayname.length()/colors.length;
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
|
||||||
{
|
|
||||||
int pos=i;
|
|
||||||
int nextpos;
|
|
||||||
if(i<displayname.length()-unit-unit)
|
|
||||||
nextpos=i+unit;
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("G");
|
|
||||||
}
|
|
||||||
//player.setDisplayName(color+displayname+"§r"+flair);
|
|
||||||
//player.setDisplayName(finalname+flair);
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=finalname+flair; //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetColorForTown(String townname)
|
|
||||||
{ //2015.07.20.
|
|
||||||
if(TownColors.containsKey(townname))
|
|
||||||
return TownColors.get(townname);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetPlayerTown(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//List<Town> towns = TownyUniverse.getDataSource().getTowns();
|
|
||||||
try {
|
|
||||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown();
|
|
||||||
return town.getName();
|
|
||||||
} catch (Exception e) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//String color = GetColorForTown(GetPlayerTown(player));
|
|
||||||
//String dname=player.getDisplayName();
|
|
||||||
//player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair)));
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Collection<? extends Player> GetPlayers()
|
|
||||||
{
|
|
||||||
return Instance.getServer().getOnlinePlayers();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,152 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;*/
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.*/
|
||||||
|
else if(args[0].toLowerCase()=="admin")
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage(msg);
|
||||||
|
else
|
||||||
|
System.out.println(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "reload":
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "playerinfo":
|
||||||
|
DoPlayerInfo(player, args);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoPlayerInfo(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
//args[0] is "admin" - args[1] is "playerinfo"
|
||||||
|
if(args.length==args[2])
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,74 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
PluginMain.Players.add(p);
|
|
||||||
//event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p));
|
|
||||||
if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20.
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p));
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
//System.out.println("Added player "+p.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
//for(Player player : PluginMain.Players)
|
|
||||||
for(int i=0; i<PluginMain.Players.size();)
|
|
||||||
{
|
|
||||||
Player player=PluginMain.Players.get(i);
|
|
||||||
if(player.getName().equals(event.getPlayer().getName()))
|
|
||||||
{
|
|
||||||
PluginMain.Players.remove(player);
|
|
||||||
//System.out.println("Removed player "+event.getPlayer().getName());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
i++; //If the player is removed, the next item will be on the same index
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
event.setFormat(event.getFormat().replaceFirst(event.getMessage(), "")+"(test)"+event.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,136 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;*/
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.*/
|
||||||
|
else if(args[0].toLowerCase()=="admin")
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage(msg);
|
||||||
|
else
|
||||||
|
System.out.println(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "reload":
|
||||||
|
DoReload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,418 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
|
||||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
|
||||||
|
|
||||||
public class PluginMain extends JavaPlugin
|
|
||||||
{ //Translated to Java: 2015.07.15.
|
|
||||||
//A user, which flair isn't obtainable:
|
|
||||||
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
|
||||||
// Fired when plugin is first enabled
|
|
||||||
@Override
|
|
||||||
public void onEnable()
|
|
||||||
{
|
|
||||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
|
||||||
//System.out.println("Original C# version: http://pastebin.com/tX8xCPbp");
|
|
||||||
//System.out.println("The Java version is... Also made by the same person.");
|
|
||||||
//System.out.println("With the help of StackOverflow and similar.");
|
|
||||||
/*catch(MalformedURLException e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
catch(IOException e)
|
|
||||||
{
|
|
||||||
}*/
|
|
||||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
|
||||||
//System.out.println("Registering commands...");
|
|
||||||
this.getCommand("u").setExecutor(new Commands());
|
|
||||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
|
||||||
try {
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//AcceptedPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("flairsignored.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//IgnoredPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
|
||||||
String line;
|
|
||||||
while((line=br.readLine())!=null)
|
|
||||||
{
|
|
||||||
String[] s=line.split(" ");
|
|
||||||
TownColors.put(s[0], s[1]);
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//System.out.println("Registering done.");
|
|
||||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
|
||||||
Thread t=new Thread(r);
|
|
||||||
t.start();
|
|
||||||
}
|
|
||||||
Boolean stop=false;
|
|
||||||
// Fired when plugin is disabled
|
|
||||||
@Override
|
|
||||||
public void onDisable()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
FileWriter fw;
|
|
||||||
fw = new FileWriter("flairsaccepted.txt");
|
|
||||||
fw.close();
|
|
||||||
fw = new FileWriter("flairsignored.txt");
|
|
||||||
fw.close();
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//for(String player : AcceptedPlayers)
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.AcceptedFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.IgnoredFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsignored.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stop=true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ThreadMethod() //<-- 2015.07.16.
|
|
||||||
{
|
|
||||||
/*System.out.println("Sleeping for 5 seconds..."); //2015.07.20.
|
|
||||||
try {
|
|
||||||
Thread.sleep(5000);
|
|
||||||
} catch (InterruptedException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
} //2015.07.20.*/
|
|
||||||
while(!stop)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
|
||||||
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
|
||||||
for(Object obj : json)
|
|
||||||
{
|
|
||||||
JSONObject item = (JSONObject)obj;
|
|
||||||
String author=item.getJSONObject("data").getString("author");
|
|
||||||
String ign=item.getJSONObject("data").getString("body");
|
|
||||||
int start = ign.indexOf("IGN:") + "IGN:".length();
|
|
||||||
int end = ign.indexOf(' ', start);
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
end=ign.indexOf('\n', start); //2015.07.15.
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
ign = ign.substring(start);
|
|
||||||
else
|
|
||||||
ign = ign.substring(start, end);
|
|
||||||
ign = ign.trim();
|
|
||||||
if(HasIGFlair(ign))
|
|
||||||
continue;
|
|
||||||
//System.out.println("Author: "+author);
|
|
||||||
try {
|
|
||||||
Thread.sleep(10);
|
|
||||||
} catch(InterruptedException ex) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
|
||||||
String flair;
|
|
||||||
if(flairdata.length > 1) //2015.07.15.
|
|
||||||
flair = flairdata[1];
|
|
||||||
else
|
|
||||||
flair="";
|
|
||||||
if (flair != "-1")
|
|
||||||
flair = flair + "s";
|
|
||||||
else
|
|
||||||
flair = "non-presser";
|
|
||||||
String flairclass;
|
|
||||||
//System.out.println("flairdata.length:"+flairdata.length);
|
|
||||||
if(flairdata.length>2)
|
|
||||||
flairclass = flairdata[2];
|
|
||||||
else
|
|
||||||
flairclass="unknown";
|
|
||||||
SetFlair(ign, flair, flairclass, author);
|
|
||||||
}
|
|
||||||
Thread.sleep(10000);
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
|
||||||
{
|
|
||||||
URL url = new URL(urlstr);
|
|
||||||
URLConnection con = url.openConnection();
|
|
||||||
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
|
||||||
InputStream in = con.getInputStream();
|
|
||||||
String encoding = con.getContentEncoding();
|
|
||||||
encoding = encoding == null ? "UTF-8" : encoding;
|
|
||||||
String body = IOUtils.toString(in, encoding);
|
|
||||||
in.close();
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
//It has to store offline player flairs too, therefore it can't use Player object
|
|
||||||
/*public static Map<String, String> PlayerFlairs=new HashMap<String, String>();
|
|
||||||
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
|
|
||||||
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
|
|
||||||
public static ArrayList<Player> Players=new ArrayList<Player>();
|
|
||||||
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
//public static Map<String, String> PlayerTowns=new HashMap<String, String>(); //2015.07.20.*/
|
|
||||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
|
||||||
public Boolean HasIGFlair(String playername)
|
|
||||||
{
|
|
||||||
/*Player player=null;
|
|
||||||
for(Player p : Players)
|
|
||||||
{
|
|
||||||
if(p.getName()==playername)
|
|
||||||
{
|
|
||||||
player=p;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(player==null)
|
|
||||||
return false;*/
|
|
||||||
//return PlayerFlairs.containsKey(playername);
|
|
||||||
return MaybeOfflinePlayer.AllPlayers.containsKey(playername);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
|
||||||
{
|
|
||||||
String finalflair;
|
|
||||||
switch(flairclass)
|
|
||||||
{
|
|
||||||
case "press-1":
|
|
||||||
finalflair="§c("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-2":
|
|
||||||
finalflair="§6("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-3":
|
|
||||||
finalflair="§e("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-4":
|
|
||||||
finalflair="§a("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-5":
|
|
||||||
finalflair="§9("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-6":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "no-press":
|
|
||||||
finalflair="§7(non-pr.)§r";
|
|
||||||
break;
|
|
||||||
case "cheater":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "cant-press": //2015.08.08.
|
|
||||||
finalflair="§r(can't press)§r";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
finalflair="";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
|
||||||
return;
|
|
||||||
//PlayerFlairs.put(playername, finalflair);
|
|
||||||
//PlayerUserNames.put(playername, username);
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
|
||||||
p.Flair=finalflair; //2015.08.08.
|
|
||||||
p.UserName=username; //2015.08.08.s
|
|
||||||
/*for(Player player : Players)
|
|
||||||
{
|
|
||||||
if(player.getName()==playername)
|
|
||||||
{
|
|
||||||
PlayerFlairs.put(player, finalflair);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
//System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass);
|
|
||||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
|
||||||
for(Player player : Players)
|
|
||||||
{
|
|
||||||
//System.out.println("Online player: "+player.getName());
|
|
||||||
//System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername));
|
|
||||||
if(player.getName().equals(playername))
|
|
||||||
{
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
//player.setDisplayName(player.getDisplayName()+finalflair);
|
|
||||||
AppendPlayerDisplayFlair(player, username, finalflair);
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetFlair(Player player)
|
|
||||||
{ //2015.07.16.
|
|
||||||
String flair=PlayerFlairs.get(player.getName());
|
|
||||||
return flair==null ? "" : flair;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
|
||||||
{
|
|
||||||
//if(IgnoredPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
|
||||||
return;
|
|
||||||
//if(AcceptedPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
|
||||||
//player.setDisplayName(player.getDisplayName()+flair);
|
|
||||||
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
else
|
|
||||||
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//System.out.println("A");
|
|
||||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
|
||||||
String[] colors = color.substring(1).split("§");
|
|
||||||
//String displayname=player.getDisplayName();
|
|
||||||
String displayname=player.getName(); //2015.08.08.
|
|
||||||
ArrayList<Integer> Positions=new ArrayList<>();
|
|
||||||
//System.out.println("B");
|
|
||||||
for(int i=0; i<displayname.length(); i++) {
|
|
||||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
|
||||||
Positions.add(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//System.out.println("C: Positions.size(): "+Positions.size());
|
|
||||||
String finalname="";
|
|
||||||
if(Positions.size()>=colors.length)
|
|
||||||
{
|
|
||||||
//System.out.println("D");
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<Positions.size(); i++)
|
|
||||||
{
|
|
||||||
int pos=Positions.get(i);
|
|
||||||
int nextpos;
|
|
||||||
if(i!=Positions.size()-1)
|
|
||||||
nextpos=Positions.get(i+1);
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
//String substr="§"+colors[x++]+displayname.substring(pos, nextpos-pos)+"§r";
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("F");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//System.out.println("E");
|
|
||||||
Positions.clear();
|
|
||||||
int unit=displayname.length()/colors.length;
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
|
||||||
{
|
|
||||||
int pos=i;
|
|
||||||
int nextpos;
|
|
||||||
if(i<displayname.length()-unit-unit)
|
|
||||||
nextpos=i+unit;
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("G");
|
|
||||||
}
|
|
||||||
//player.setDisplayName(color+displayname+"§r"+flair);
|
|
||||||
//player.setDisplayName(finalname+flair);
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=finalname+flair; //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetColorForTown(String townname)
|
|
||||||
{ //2015.07.20.
|
|
||||||
if(TownColors.containsKey(townname))
|
|
||||||
return TownColors.get(townname);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetPlayerTown(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//List<Town> towns = TownyUniverse.getDataSource().getTowns();
|
|
||||||
try {
|
|
||||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown();
|
|
||||||
return town.getName();
|
|
||||||
} catch (Exception e) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
String color = GetColorForTown(GetPlayerTown(player));
|
|
||||||
String dname=player.getDisplayName();
|
|
||||||
//player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair)));
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08.
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,413 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||||
|
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||||
|
|
||||||
|
public class PluginMain extends JavaPlugin
|
||||||
|
{ //Translated to Java: 2015.07.15.
|
||||||
|
//A user, which flair isn't obtainable:
|
||||||
|
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
||||||
|
private static PluginMain Instance;
|
||||||
|
// Fired when plugin is first enabled
|
||||||
|
@Override
|
||||||
|
public void onEnable()
|
||||||
|
{
|
||||||
|
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||||
|
this.getCommand("u").setExecutor(new Commands());
|
||||||
|
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||||
|
Instance=this; //2015.08.08.
|
||||||
|
try {
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
System.out.println("Name: " + name);
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("flairsignored.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||||
|
Thread t=new Thread(r);
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
Boolean stop=false;
|
||||||
|
// Fired when plugin is disabled
|
||||||
|
@Override
|
||||||
|
public void onDisable()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileWriter fw;
|
||||||
|
fw = new FileWriter("flairsaccepted.txt");
|
||||||
|
fw.close();
|
||||||
|
fw = new FileWriter("flairsignored.txt");
|
||||||
|
fw.close();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.AcceptedFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
try {
|
||||||
|
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.IgnoredFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
File file=new File("flairsignored.txt");
|
||||||
|
try {
|
||||||
|
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stop=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ThreadMethod() //<-- 2015.07.16.
|
||||||
|
{
|
||||||
|
while(!stop)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
||||||
|
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
||||||
|
for(Object obj : json)
|
||||||
|
{
|
||||||
|
JSONObject item = (JSONObject)obj;
|
||||||
|
String author=item.getJSONObject("data").getString("author");
|
||||||
|
String ign=item.getJSONObject("data").getString("body");
|
||||||
|
int start = ign.indexOf("IGN:") + "IGN:".length();
|
||||||
|
int end = ign.indexOf(' ', start);
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
end=ign.indexOf('\n', start); //2015.07.15.
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
ign = ign.substring(start);
|
||||||
|
else
|
||||||
|
ign = ign.substring(start, end);
|
||||||
|
ign = ign.trim();
|
||||||
|
if(HasIGFlair(ign))
|
||||||
|
continue;
|
||||||
|
try {
|
||||||
|
Thread.sleep(10);
|
||||||
|
} catch(InterruptedException ex) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
||||||
|
String flair;
|
||||||
|
if(flairdata.length > 1) //2015.07.15.
|
||||||
|
flair = flairdata[1];
|
||||||
|
else
|
||||||
|
flair="";
|
||||||
|
if (flair != "-1")
|
||||||
|
flair = flair + "s";
|
||||||
|
else
|
||||||
|
flair = "non-presser";
|
||||||
|
String flairclass;
|
||||||
|
//System.out.println("flairdata.length:"+flairdata.length);
|
||||||
|
if(flairdata.length>2)
|
||||||
|
flairclass = flairdata[2];
|
||||||
|
else
|
||||||
|
flairclass="unknown";
|
||||||
|
SetFlair(ign, flair, flairclass, author);
|
||||||
|
}
|
||||||
|
Thread.sleep(10000);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
||||||
|
{
|
||||||
|
URL url = new URL(urlstr);
|
||||||
|
URLConnection con = url.openConnection();
|
||||||
|
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
||||||
|
InputStream in = con.getInputStream();
|
||||||
|
String encoding = con.getContentEncoding();
|
||||||
|
encoding = encoding == null ? "UTF-8" : encoding;
|
||||||
|
String body = IOUtils.toString(in, encoding);
|
||||||
|
in.close();
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
//It has to store offline player flairs too, therefore it can't use Player object
|
||||||
|
/*public static Map<String, String> PlayerFlairs=new HashMap<String, String>();
|
||||||
|
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
|
||||||
|
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
|
||||||
|
public static ArrayList<Player> Players=new ArrayList<Player>();
|
||||||
|
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
|
||||||
|
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //2015.07.16.
|
||||||
|
//public static Map<String, String> PlayerTowns=new HashMap<String, String>(); //2015.07.20.*/
|
||||||
|
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||||
|
public Boolean HasIGFlair(String playername)
|
||||||
|
{
|
||||||
|
/*Player player=null;
|
||||||
|
for(Player p : Players)
|
||||||
|
{
|
||||||
|
if(p.getName()==playername)
|
||||||
|
{
|
||||||
|
player=p;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(player==null)
|
||||||
|
return false;*/
|
||||||
|
//return PlayerFlairs.containsKey(playername);
|
||||||
|
//return MaybeOfflinePlayer.AllPlayers.containsKey(playername);
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
return p.Flair!=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||||
|
{
|
||||||
|
String finalflair;
|
||||||
|
switch(flairclass)
|
||||||
|
{
|
||||||
|
case "press-1":
|
||||||
|
finalflair="§c("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-2":
|
||||||
|
finalflair="§6("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-3":
|
||||||
|
finalflair="§e("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-4":
|
||||||
|
finalflair="§a("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-5":
|
||||||
|
finalflair="§9("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-6":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "no-press":
|
||||||
|
finalflair="§7(non-pr.)§r";
|
||||||
|
break;
|
||||||
|
case "cheater":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "cant-press": //2015.08.08.
|
||||||
|
finalflair="§r(can't press)§r";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
finalflair="";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||||
|
return;
|
||||||
|
//PlayerFlairs.put(playername, finalflair);
|
||||||
|
//PlayerUserNames.put(playername, username);
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
p.Flair=finalflair; //2015.08.08.
|
||||||
|
p.UserName=username; //2015.08.08.
|
||||||
|
/*for(Player player : Players)
|
||||||
|
{
|
||||||
|
if(player.getName()==playername)
|
||||||
|
{
|
||||||
|
PlayerFlairs.put(player, finalflair);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
//System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass);
|
||||||
|
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||||
|
//for(Player player : Players)
|
||||||
|
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
//System.out.println("Online player: "+player.getName());
|
||||||
|
//System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername));
|
||||||
|
if(player.getName().equals(playername))
|
||||||
|
{
|
||||||
|
//System.out.println("DisplayName: "+player.getDisplayName());
|
||||||
|
//player.setDisplayName(player.getDisplayName()+finalflair);
|
||||||
|
AppendPlayerDisplayFlair(player, username, finalflair);
|
||||||
|
//System.out.println("DisplayName: "+player.getDisplayName());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetFlair(Player player)
|
||||||
|
{ //2015.07.16.
|
||||||
|
//String flair=PlayerFlairs.get(player.getName());
|
||||||
|
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||||
|
return flair==null ? "" : flair;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||||
|
{
|
||||||
|
//if(IgnoredPlayers.contains(player.getName()))
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
||||||
|
return;
|
||||||
|
//if(AcceptedPlayers.contains(player.getName()))
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
||||||
|
//player.setDisplayName(player.getDisplayName()+flair);
|
||||||
|
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
else
|
||||||
|
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//System.out.println("A");
|
||||||
|
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||||
|
String[] colors = color.substring(1).split("§");
|
||||||
|
//String displayname=player.getDisplayName();
|
||||||
|
String displayname=player.getName(); //2015.08.08.
|
||||||
|
ArrayList<Integer> Positions=new ArrayList<>();
|
||||||
|
//System.out.println("B");
|
||||||
|
for(int i=0; i<displayname.length(); i++) {
|
||||||
|
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||||
|
Positions.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//System.out.println("C: Positions.size(): "+Positions.size());
|
||||||
|
String finalname="";
|
||||||
|
if(Positions.size()>=colors.length)
|
||||||
|
{
|
||||||
|
//System.out.println("D");
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<Positions.size(); i++)
|
||||||
|
{
|
||||||
|
int pos=Positions.get(i);
|
||||||
|
int nextpos;
|
||||||
|
if(i!=Positions.size()-1)
|
||||||
|
nextpos=Positions.get(i+1);
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
||||||
|
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
||||||
|
//String substr="§"+colors[x++]+displayname.substring(pos, nextpos-pos)+"§r";
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
//System.out.println("F");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//System.out.println("E");
|
||||||
|
Positions.clear();
|
||||||
|
int unit=displayname.length()/colors.length;
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||||
|
{
|
||||||
|
int pos=i;
|
||||||
|
int nextpos;
|
||||||
|
if(i<displayname.length()-unit-unit)
|
||||||
|
nextpos=i+unit;
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
||||||
|
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
//System.out.println("G");
|
||||||
|
}
|
||||||
|
//player.setDisplayName(color+displayname+"§r"+flair);
|
||||||
|
//player.setDisplayName(finalname+flair);
|
||||||
|
//MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=finalname+flair; //2015.08.08.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetColorForTown(String townname)
|
||||||
|
{ //2015.07.20.
|
||||||
|
if(TownColors.containsKey(townname))
|
||||||
|
return TownColors.get(townname);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetPlayerTown(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//List<Town> towns = TownyUniverse.getDataSource().getTowns();
|
||||||
|
try {
|
||||||
|
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||||
|
return town.getName();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//String color = GetColorForTown(GetPlayerTown(player));
|
||||||
|
//String dname=player.getDisplayName();
|
||||||
|
//player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair)));
|
||||||
|
//MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<? extends Player> GetPlayers()
|
||||||
|
{
|
||||||
|
return Instance.getServer().getOnlinePlayers();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,172 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;*/
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.*/
|
||||||
|
else if(args[0].toLowerCase()=="admin")
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
SendMessage(player, msg); //2015.08.09.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
if(args.length==1)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "reload":
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "playerinfo":
|
||||||
|
DoPlayerInfo(player, args);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoPlayerInfo(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
//args[0] is "admin" - args[1] is "playerinfo"
|
||||||
|
if(args.length==2)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
}
|
||||||
|
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||||
|
{
|
||||||
|
String message="§cPlayer not found: "+args[2]+"§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
}
|
||||||
|
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||||
|
SendMessage(player, "Player name: "+p.PlayerName);
|
||||||
|
SendMessage(player, "User flair: "+p.Flair);
|
||||||
|
SendMessage(player, "Username: "+p.UserName);
|
||||||
|
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
||||||
|
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
private static void SendMessage(Player player, String message)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,39 +15,35 @@ public class PlayerListener implements Listener
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
public void onPlayerJoin(PlayerJoinEvent event)
|
||||||
{
|
{
|
||||||
Player p=event.getPlayer();
|
Player p=event.getPlayer();
|
||||||
PluginMain.Players.add(p);
|
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
||||||
//event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p));
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
||||||
if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20.
|
if(mp.Flair!=null)
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p));
|
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
||||||
else
|
else
|
||||||
{ //2015.07.20.
|
{ //2015.07.20.
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
||||||
sendRawMessage(p, json);
|
sendRawMessage(p, json);
|
||||||
}
|
}
|
||||||
//System.out.println("Added player "+p.getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
public void onPlayerLeave(PlayerQuitEvent event)
|
||||||
{
|
{
|
||||||
//for(Player player : PluginMain.Players)
|
|
||||||
for(int i=0; i<PluginMain.Players.size();)
|
|
||||||
{
|
|
||||||
Player player=PluginMain.Players.get(i);
|
|
||||||
if(player.getName().equals(event.getPlayer().getName()))
|
|
||||||
{
|
|
||||||
PluginMain.Players.remove(player);
|
|
||||||
//System.out.println("Removed player "+event.getPlayer().getName());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
i++; //If the player is removed, the next item will be on the same index
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
public void onPlayerChat(AsyncPlayerChatEvent event)
|
||||||
{
|
{
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+"(test)"+event.getMessage()); //2015.08.08.
|
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
||||||
|
String flair=player.Flair; //2015.08.08.
|
||||||
|
if(flair==null || !player.AcceptedFlair)
|
||||||
|
flair=""; //2015.08.08.
|
||||||
|
String message=event.getMessage(); //2015.08.08.
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
@ -0,0 +1,175 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;*/
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.*/
|
||||||
|
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||||
|
{
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return true; //2015.08.09.
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
SendMessage(player, msg); //2015.08.09.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
System.out.println("Args length: " + args.length);
|
||||||
|
if(args.length==1)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "reload":
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "playerinfo":
|
||||||
|
DoPlayerInfo(player, args);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoPlayerInfo(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
//args[0] is "admin" - args[1] is "playerinfo"
|
||||||
|
if(args.length==2)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||||
|
{
|
||||||
|
String message="§cPlayer not found: "+args[2]+"§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||||
|
SendMessage(player, "Player name: "+p.PlayerName);
|
||||||
|
SendMessage(player, "User flair: "+p.Flair);
|
||||||
|
SendMessage(player, "Username: "+p.UserName);
|
||||||
|
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
||||||
|
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
||||||
|
}
|
||||||
|
private static void SendMessage(Player player, String message)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,74 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
PluginMain.Players.add(p);
|
|
||||||
//event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p));
|
|
||||||
if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20.
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p));
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
//System.out.println("Added player "+p.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
//for(Player player : PluginMain.Players)
|
|
||||||
for(int i=0; i<PluginMain.Players.size();)
|
|
||||||
{
|
|
||||||
Player player=PluginMain.Players.get(i);
|
|
||||||
if(player.getName().equals(event.getPlayer().getName()))
|
|
||||||
{
|
|
||||||
PluginMain.Players.remove(player);
|
|
||||||
//System.out.println("Removed player "+event.getPlayer().getName());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
i++; //If the player is removed, the next item will be on the same index
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
event.setFormat(event.getFormat().replaceFirst(event.getMessage(), "")+"(test)"+event.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,372 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||||
|
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||||
|
|
||||||
|
public class PluginMain extends JavaPlugin
|
||||||
|
{ //Translated to Java: 2015.07.15.
|
||||||
|
//A user, which flair isn't obtainable:
|
||||||
|
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
||||||
|
private static PluginMain Instance;
|
||||||
|
// Fired when plugin is first enabled
|
||||||
|
@Override
|
||||||
|
public void onEnable()
|
||||||
|
{
|
||||||
|
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||||
|
this.getCommand("u").setExecutor(new Commands());
|
||||||
|
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||||
|
Instance=this; //2015.08.08.
|
||||||
|
try {
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
System.out.println("Name: " + name);
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("flairsignored.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||||
|
Thread t=new Thread(r);
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
Boolean stop=false;
|
||||||
|
// Fired when plugin is disabled
|
||||||
|
@Override
|
||||||
|
public void onDisable()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileWriter fw;
|
||||||
|
fw = new FileWriter("flairsaccepted.txt");
|
||||||
|
fw.close();
|
||||||
|
fw = new FileWriter("flairsignored.txt");
|
||||||
|
fw.close();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.AcceptedFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
try {
|
||||||
|
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.IgnoredFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
File file=new File("flairsignored.txt");
|
||||||
|
try {
|
||||||
|
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stop=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ThreadMethod() //<-- 2015.07.16.
|
||||||
|
{
|
||||||
|
while(!stop)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
||||||
|
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
||||||
|
for(Object obj : json)
|
||||||
|
{
|
||||||
|
JSONObject item = (JSONObject)obj;
|
||||||
|
String author=item.getJSONObject("data").getString("author");
|
||||||
|
String ign=item.getJSONObject("data").getString("body");
|
||||||
|
int start = ign.indexOf("IGN:") + "IGN:".length();
|
||||||
|
int end = ign.indexOf(' ', start);
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
end=ign.indexOf('\n', start); //2015.07.15.
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
ign = ign.substring(start);
|
||||||
|
else
|
||||||
|
ign = ign.substring(start, end);
|
||||||
|
ign = ign.trim();
|
||||||
|
if(HasIGFlair(ign))
|
||||||
|
continue;
|
||||||
|
try {
|
||||||
|
Thread.sleep(10);
|
||||||
|
} catch(InterruptedException ex) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
||||||
|
String flair;
|
||||||
|
if(flairdata.length > 1) //2015.07.15.
|
||||||
|
flair = flairdata[1];
|
||||||
|
else
|
||||||
|
flair="";
|
||||||
|
if (flair != "-1")
|
||||||
|
flair = flair + "s";
|
||||||
|
else
|
||||||
|
flair = "non-presser";
|
||||||
|
String flairclass;
|
||||||
|
if(flairdata.length>2)
|
||||||
|
flairclass = flairdata[2];
|
||||||
|
else
|
||||||
|
flairclass="unknown";
|
||||||
|
SetFlair(ign, flair, flairclass, author);
|
||||||
|
}
|
||||||
|
Thread.sleep(10000);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
||||||
|
{
|
||||||
|
URL url = new URL(urlstr);
|
||||||
|
URLConnection con = url.openConnection();
|
||||||
|
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
||||||
|
InputStream in = con.getInputStream();
|
||||||
|
String encoding = con.getContentEncoding();
|
||||||
|
encoding = encoding == null ? "UTF-8" : encoding;
|
||||||
|
String body = IOUtils.toString(in, encoding);
|
||||||
|
in.close();
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||||
|
public Boolean HasIGFlair(String playername)
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
return p.Flair!=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||||
|
{
|
||||||
|
String finalflair;
|
||||||
|
switch(flairclass)
|
||||||
|
{
|
||||||
|
case "press-1":
|
||||||
|
finalflair="§c("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-2":
|
||||||
|
finalflair="§6("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-3":
|
||||||
|
finalflair="§e("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-4":
|
||||||
|
finalflair="§a("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-5":
|
||||||
|
finalflair="§9("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-6":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "no-press":
|
||||||
|
finalflair="§7(non-pr.)§r";
|
||||||
|
break;
|
||||||
|
case "cheater":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "cant-press": //2015.08.08.
|
||||||
|
finalflair="§r(can't press)§r";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
finalflair="";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||||
|
return;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
p.Flair=finalflair; //2015.08.08.
|
||||||
|
p.UserName=username; //2015.08.08.
|
||||||
|
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||||
|
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(player.getName().equals(playername))
|
||||||
|
{
|
||||||
|
AppendPlayerDisplayFlair(player, username, finalflair);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetFlair(Player player)
|
||||||
|
{ //2015.07.16.
|
||||||
|
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||||
|
return flair==null ? "" : flair;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||||
|
{
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
||||||
|
return;
|
||||||
|
//if(AcceptedPlayers.contains(player.getName()))
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
||||||
|
//player.setDisplayName(player.getDisplayName()+flair);
|
||||||
|
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
else
|
||||||
|
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//System.out.println("A");
|
||||||
|
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||||
|
String[] colors = color.substring(1).split("§");
|
||||||
|
//String displayname=player.getDisplayName();
|
||||||
|
String displayname=player.getName(); //2015.08.08.
|
||||||
|
ArrayList<Integer> Positions=new ArrayList<>();
|
||||||
|
//System.out.println("B");
|
||||||
|
for(int i=0; i<displayname.length(); i++) {
|
||||||
|
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||||
|
Positions.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//System.out.println("C: Positions.size(): "+Positions.size());
|
||||||
|
String finalname="";
|
||||||
|
if(Positions.size()>=colors.length)
|
||||||
|
{
|
||||||
|
//System.out.println("D");
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<Positions.size(); i++)
|
||||||
|
{
|
||||||
|
int pos=Positions.get(i);
|
||||||
|
int nextpos;
|
||||||
|
if(i!=Positions.size()-1)
|
||||||
|
nextpos=Positions.get(i+1);
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
||||||
|
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
||||||
|
//String substr="§"+colors[x++]+displayname.substring(pos, nextpos-pos)+"§r";
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
//System.out.println("F");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//System.out.println("E");
|
||||||
|
Positions.clear();
|
||||||
|
int unit=displayname.length()/colors.length;
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||||
|
{
|
||||||
|
int pos=i;
|
||||||
|
int nextpos;
|
||||||
|
if(i<displayname.length()-unit-unit)
|
||||||
|
nextpos=i+unit;
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
||||||
|
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
//System.out.println("G");
|
||||||
|
}
|
||||||
|
//player.setDisplayName(color+displayname+"§r"+flair);
|
||||||
|
//player.setDisplayName(finalname+flair);
|
||||||
|
//MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=finalname+flair; //2015.08.08.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetColorForTown(String townname)
|
||||||
|
{ //2015.07.20.
|
||||||
|
if(TownColors.containsKey(townname))
|
||||||
|
return TownColors.get(townname);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetPlayerTown(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//List<Town> towns = TownyUniverse.getDataSource().getTowns();
|
||||||
|
try {
|
||||||
|
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||||
|
return town.getName();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//String color = GetColorForTown(GetPlayerTown(player));
|
||||||
|
//String dname=player.getDisplayName();
|
||||||
|
//player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair)));
|
||||||
|
//MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<? extends Player> GetPlayers()
|
||||||
|
{
|
||||||
|
return Instance.getServer().getOnlinePlayers();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,421 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.PluginManager;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
|
||||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
|
||||||
|
|
||||||
public class PluginMain extends JavaPlugin
|
|
||||||
{ //Translated to Java: 2015.07.15.
|
|
||||||
//A user, which flair isn't obtainable:
|
|
||||||
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
|
||||||
// Fired when plugin is first enabled
|
|
||||||
@Override
|
|
||||||
public void onEnable()
|
|
||||||
{
|
|
||||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
|
||||||
//System.out.println("Original C# version: http://pastebin.com/tX8xCPbp");
|
|
||||||
//System.out.println("The Java version is... Also made by the same person.");
|
|
||||||
//System.out.println("With the help of StackOverflow and similar.");
|
|
||||||
/*catch(MalformedURLException e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
catch(IOException e)
|
|
||||||
{
|
|
||||||
}*/
|
|
||||||
PluginManager manager = getServer().getPluginManager();
|
|
||||||
manager.registerEvents(new PlayerListener(), this);
|
|
||||||
//System.out.println("Registering commands...");
|
|
||||||
this.getCommand("u").setExecutor(new Commands());
|
|
||||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
|
||||||
try {
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//AcceptedPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("flairsignored.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//IgnoredPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
|
||||||
String line;
|
|
||||||
while((line=br.readLine())!=null)
|
|
||||||
{
|
|
||||||
String[] s=line.split(" ");
|
|
||||||
TownColors.put(s[0], s[1]);
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//System.out.println("Registering done.");
|
|
||||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
|
||||||
Thread t=new Thread(r);
|
|
||||||
t.start();
|
|
||||||
}
|
|
||||||
Boolean stop=false;
|
|
||||||
// Fired when plugin is disabled
|
|
||||||
@Override
|
|
||||||
public void onDisable()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
FileWriter fw;
|
|
||||||
fw = new FileWriter("flairsaccepted.txt");
|
|
||||||
fw.close();
|
|
||||||
fw = new FileWriter("flairsignored.txt");
|
|
||||||
fw.close();
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//for(String player : AcceptedPlayers)
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.AcceptedFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.IgnoredFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsignored.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stop=true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ThreadMethod() //<-- 2015.07.16.
|
|
||||||
{
|
|
||||||
/*System.out.println("Sleeping for 5 seconds..."); //2015.07.20.
|
|
||||||
try {
|
|
||||||
Thread.sleep(5000);
|
|
||||||
} catch (InterruptedException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
} //2015.07.20.*/
|
|
||||||
while(!stop)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
|
||||||
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
|
||||||
for(Object obj : json)
|
|
||||||
{
|
|
||||||
JSONObject item = (JSONObject)obj;
|
|
||||||
String author=item.getJSONObject("data").getString("author");
|
|
||||||
String ign=item.getJSONObject("data").getString("body");
|
|
||||||
int start = ign.indexOf("IGN:") + "IGN:".length();
|
|
||||||
int end = ign.indexOf(' ', start);
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
end=ign.indexOf('\n', start); //2015.07.15.
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
ign = ign.substring(start);
|
|
||||||
else
|
|
||||||
ign = ign.substring(start, end);
|
|
||||||
ign = ign.trim();
|
|
||||||
if(HasIGFlair(ign))
|
|
||||||
continue;
|
|
||||||
//System.out.println("Author: "+author);
|
|
||||||
try {
|
|
||||||
Thread.sleep(10);
|
|
||||||
} catch(InterruptedException ex) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
|
||||||
String flair;
|
|
||||||
if(flairdata.length > 1) //2015.07.15.
|
|
||||||
flair = flairdata[1];
|
|
||||||
else
|
|
||||||
flair="";
|
|
||||||
if (flair != "-1")
|
|
||||||
flair = flair + "s";
|
|
||||||
else
|
|
||||||
flair = "non-presser";
|
|
||||||
String flairclass;
|
|
||||||
//System.out.println("flairdata.length:"+flairdata.length);
|
|
||||||
if(flairdata.length>2)
|
|
||||||
flairclass = flairdata[2];
|
|
||||||
else
|
|
||||||
flairclass="unknown";
|
|
||||||
SetFlair(ign, flair, flairclass, author);
|
|
||||||
}
|
|
||||||
Thread.sleep(10000);
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
|
||||||
{
|
|
||||||
URL url = new URL(urlstr);
|
|
||||||
URLConnection con = url.openConnection();
|
|
||||||
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
|
||||||
InputStream in = con.getInputStream();
|
|
||||||
String encoding = con.getContentEncoding();
|
|
||||||
encoding = encoding == null ? "UTF-8" : encoding;
|
|
||||||
String body = IOUtils.toString(in, encoding);
|
|
||||||
in.close();
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
//It has to store offline player flairs too, therefore it can't use Player object
|
|
||||||
/*public static Map<String, String> PlayerFlairs=new HashMap<String, String>();
|
|
||||||
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
|
|
||||||
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
|
|
||||||
public static ArrayList<Player> Players=new ArrayList<Player>();
|
|
||||||
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
//public static Map<String, String> PlayerTowns=new HashMap<String, String>(); //2015.07.20.*/
|
|
||||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
|
||||||
public Boolean HasIGFlair(String playername)
|
|
||||||
{
|
|
||||||
/*Player player=null;
|
|
||||||
for(Player p : Players)
|
|
||||||
{
|
|
||||||
if(p.getName()==playername)
|
|
||||||
{
|
|
||||||
player=p;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(player==null)
|
|
||||||
return false;*/
|
|
||||||
//return PlayerFlairs.containsKey(playername);
|
|
||||||
return MaybeOfflinePlayer.AllPlayers.containsKey(playername);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
|
||||||
{
|
|
||||||
String finalflair;
|
|
||||||
switch(flairclass)
|
|
||||||
{
|
|
||||||
case "press-1":
|
|
||||||
finalflair="§c("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-2":
|
|
||||||
finalflair="§6("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-3":
|
|
||||||
finalflair="§e("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-4":
|
|
||||||
finalflair="§a("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-5":
|
|
||||||
finalflair="§9("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-6":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "no-press":
|
|
||||||
finalflair="§7(non-pr.)§r";
|
|
||||||
break;
|
|
||||||
case "cheater":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "cant-press": //2015.08.08.
|
|
||||||
finalflair="§r(can't press)§r";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
finalflair="";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
|
||||||
return;
|
|
||||||
//PlayerFlairs.put(playername, finalflair);
|
|
||||||
//PlayerUserNames.put(playername, username);
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
|
||||||
p.Flair=finalflair; //2015.08.08.
|
|
||||||
p.UserName=username; //2015.08.08.
|
|
||||||
/*for(Player player : Players)
|
|
||||||
{
|
|
||||||
if(player.getName()==playername)
|
|
||||||
{
|
|
||||||
PlayerFlairs.put(player, finalflair);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
//System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass);
|
|
||||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
|
||||||
for(Player player : Players)
|
|
||||||
{
|
|
||||||
//System.out.println("Online player: "+player.getName());
|
|
||||||
//System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername));
|
|
||||||
if(player.getName().equals(playername))
|
|
||||||
{
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
//player.setDisplayName(player.getDisplayName()+finalflair);
|
|
||||||
AppendPlayerDisplayFlair(player, username, finalflair);
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetFlair(Player player)
|
|
||||||
{ //2015.07.16.
|
|
||||||
//String flair=PlayerFlairs.get(player.getName());
|
|
||||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
|
||||||
return flair==null ? "" : flair;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
|
||||||
{
|
|
||||||
//if(IgnoredPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
|
||||||
return;
|
|
||||||
//if(AcceptedPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
|
||||||
//player.setDisplayName(player.getDisplayName()+flair);
|
|
||||||
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
else
|
|
||||||
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//System.out.println("A");
|
|
||||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
|
||||||
String[] colors = color.substring(1).split("§");
|
|
||||||
//String displayname=player.getDisplayName();
|
|
||||||
String displayname=player.getName(); //2015.08.08.
|
|
||||||
ArrayList<Integer> Positions=new ArrayList<>();
|
|
||||||
//System.out.println("B");
|
|
||||||
for(int i=0; i<displayname.length(); i++) {
|
|
||||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
|
||||||
Positions.add(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//System.out.println("C: Positions.size(): "+Positions.size());
|
|
||||||
String finalname="";
|
|
||||||
if(Positions.size()>=colors.length)
|
|
||||||
{
|
|
||||||
//System.out.println("D");
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<Positions.size(); i++)
|
|
||||||
{
|
|
||||||
int pos=Positions.get(i);
|
|
||||||
int nextpos;
|
|
||||||
if(i!=Positions.size()-1)
|
|
||||||
nextpos=Positions.get(i+1);
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
//String substr="§"+colors[x++]+displayname.substring(pos, nextpos-pos)+"§r";
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("F");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//System.out.println("E");
|
|
||||||
Positions.clear();
|
|
||||||
int unit=displayname.length()/colors.length;
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
|
||||||
{
|
|
||||||
int pos=i;
|
|
||||||
int nextpos;
|
|
||||||
if(i<displayname.length()-unit-unit)
|
|
||||||
nextpos=i+unit;
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("G");
|
|
||||||
}
|
|
||||||
//player.setDisplayName(color+displayname+"§r"+flair);
|
|
||||||
//player.setDisplayName(finalname+flair);
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=finalname+flair; //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetColorForTown(String townname)
|
|
||||||
{ //2015.07.20.
|
|
||||||
if(TownColors.containsKey(townname))
|
|
||||||
return TownColors.get(townname);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetPlayerTown(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//List<Town> towns = TownyUniverse.getDataSource().getTowns();
|
|
||||||
try {
|
|
||||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown();
|
|
||||||
return town.getName();
|
|
||||||
} catch (Exception e) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
String color = GetColorForTown(GetPlayerTown(player));
|
|
||||||
String dname=player.getDisplayName();
|
|
||||||
//player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair)));
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08.
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,353 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||||
|
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||||
|
|
||||||
|
public class PluginMain extends JavaPlugin
|
||||||
|
{ //Translated to Java: 2015.07.15.
|
||||||
|
//A user, which flair isn't obtainable:
|
||||||
|
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
||||||
|
private static PluginMain Instance;
|
||||||
|
// Fired when plugin is first enabled
|
||||||
|
@Override
|
||||||
|
public void onEnable()
|
||||||
|
{
|
||||||
|
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||||
|
this.getCommand("u").setExecutor(new Commands());
|
||||||
|
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||||
|
Instance=this; //2015.08.08.
|
||||||
|
try {
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
System.out.println("Name: " + name);
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("flairsignored.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||||
|
Thread t=new Thread(r);
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
Boolean stop=false;
|
||||||
|
// Fired when plugin is disabled
|
||||||
|
@Override
|
||||||
|
public void onDisable()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileWriter fw;
|
||||||
|
fw = new FileWriter("flairsaccepted.txt");
|
||||||
|
fw.close();
|
||||||
|
fw = new FileWriter("flairsignored.txt");
|
||||||
|
fw.close();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.AcceptedFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
try {
|
||||||
|
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.IgnoredFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
File file=new File("flairsignored.txt");
|
||||||
|
try {
|
||||||
|
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stop=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ThreadMethod() //<-- 2015.07.16.
|
||||||
|
{
|
||||||
|
while(!stop)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
||||||
|
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
||||||
|
for(Object obj : json)
|
||||||
|
{
|
||||||
|
JSONObject item = (JSONObject)obj;
|
||||||
|
String author=item.getJSONObject("data").getString("author");
|
||||||
|
String ign=item.getJSONObject("data").getString("body");
|
||||||
|
int start = ign.indexOf("IGN:") + "IGN:".length();
|
||||||
|
int end = ign.indexOf(' ', start);
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
end=ign.indexOf('\n', start); //2015.07.15.
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
ign = ign.substring(start);
|
||||||
|
else
|
||||||
|
ign = ign.substring(start, end);
|
||||||
|
ign = ign.trim();
|
||||||
|
if(HasIGFlair(ign))
|
||||||
|
continue;
|
||||||
|
try {
|
||||||
|
Thread.sleep(10);
|
||||||
|
} catch(InterruptedException ex) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
||||||
|
String flair;
|
||||||
|
if(flairdata.length > 1) //2015.07.15.
|
||||||
|
flair = flairdata[1];
|
||||||
|
else
|
||||||
|
flair="";
|
||||||
|
if (flair != "-1")
|
||||||
|
flair = flair + "s";
|
||||||
|
else
|
||||||
|
flair = "non-presser";
|
||||||
|
String flairclass;
|
||||||
|
if(flairdata.length>2)
|
||||||
|
flairclass = flairdata[2];
|
||||||
|
else
|
||||||
|
flairclass="unknown";
|
||||||
|
SetFlair(ign, flair, flairclass, author);
|
||||||
|
}
|
||||||
|
Thread.sleep(10000);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
||||||
|
{
|
||||||
|
URL url = new URL(urlstr);
|
||||||
|
URLConnection con = url.openConnection();
|
||||||
|
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
||||||
|
InputStream in = con.getInputStream();
|
||||||
|
String encoding = con.getContentEncoding();
|
||||||
|
encoding = encoding == null ? "UTF-8" : encoding;
|
||||||
|
String body = IOUtils.toString(in, encoding);
|
||||||
|
in.close();
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||||
|
public Boolean HasIGFlair(String playername)
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
return p.Flair!=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||||
|
{
|
||||||
|
String finalflair;
|
||||||
|
switch(flairclass)
|
||||||
|
{
|
||||||
|
case "press-1":
|
||||||
|
finalflair="§c("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-2":
|
||||||
|
finalflair="§6("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-3":
|
||||||
|
finalflair="§e("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-4":
|
||||||
|
finalflair="§a("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-5":
|
||||||
|
finalflair="§9("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-6":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "no-press":
|
||||||
|
finalflair="§7(non-pr.)§r";
|
||||||
|
break;
|
||||||
|
case "cheater":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "cant-press": //2015.08.08.
|
||||||
|
finalflair="§r(can't press)§r";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
finalflair="";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||||
|
return;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
p.Flair=finalflair; //2015.08.08.
|
||||||
|
p.UserName=username; //2015.08.08.
|
||||||
|
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||||
|
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(player.getName().equals(playername))
|
||||||
|
{
|
||||||
|
AppendPlayerDisplayFlair(player, username, finalflair);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetFlair(Player player)
|
||||||
|
{ //2015.07.16.
|
||||||
|
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||||
|
return flair==null ? "" : flair;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||||
|
{
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
||||||
|
return;
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
||||||
|
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
else
|
||||||
|
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||||
|
String[] colors = color.substring(1).split("§");
|
||||||
|
String displayname=player.getName(); //2015.08.08.
|
||||||
|
ArrayList<Integer> Positions=new ArrayList<>();
|
||||||
|
for(int i=0; i<displayname.length(); i++) {
|
||||||
|
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||||
|
Positions.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String finalname="";
|
||||||
|
if(Positions.size()>=colors.length)
|
||||||
|
{
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<Positions.size(); i++)
|
||||||
|
{
|
||||||
|
int pos=Positions.get(i);
|
||||||
|
int nextpos;
|
||||||
|
if(i!=Positions.size()-1)
|
||||||
|
nextpos=Positions.get(i+1);
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Positions.clear();
|
||||||
|
int unit=displayname.length()/colors.length;
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||||
|
{
|
||||||
|
int pos=i;
|
||||||
|
int nextpos;
|
||||||
|
if(i<displayname.length()-unit-unit)
|
||||||
|
nextpos=i+unit;
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetColorForTown(String townname)
|
||||||
|
{ //2015.07.20.
|
||||||
|
if(TownColors.containsKey(townname))
|
||||||
|
return TownColors.get(townname);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetPlayerTown(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
try {
|
||||||
|
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||||
|
return town.getName();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//String color = GetColorForTown(GetPlayerTown(player));
|
||||||
|
//String dname=player.getDisplayName();
|
||||||
|
//player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair)));
|
||||||
|
//MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<? extends Player> GetPlayers()
|
||||||
|
{
|
||||||
|
return Instance.getServer().getOnlinePlayers();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,74 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
PluginMain.Players.add(p);
|
|
||||||
//event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p));
|
|
||||||
if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20.
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p));
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
//System.out.println("Added player "+p.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
//for(Player player : PluginMain.Players)
|
|
||||||
for(int i=0; i<PluginMain.Players.size();)
|
|
||||||
{
|
|
||||||
Player player=PluginMain.Players.get(i);
|
|
||||||
if(player.getName().equals(event.getPlayer().getName()))
|
|
||||||
{
|
|
||||||
PluginMain.Players.remove(player);
|
|
||||||
//System.out.println("Removed player "+event.getPlayer().getName());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
i++; //If the player is removed, the next item will be on the same index
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
event.setFormat(event.getFormat().replaceFirst(event.getMessage(), "")+"(test)"+event.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,352 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||||
|
|
||||||
|
public class PluginMain extends JavaPlugin
|
||||||
|
{ //Translated to Java: 2015.07.15.
|
||||||
|
//A user, which flair isn't obtainable:
|
||||||
|
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
||||||
|
private static PluginMain Instance;
|
||||||
|
// Fired when plugin is first enabled
|
||||||
|
@Override
|
||||||
|
public void onEnable()
|
||||||
|
{
|
||||||
|
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||||
|
this.getCommand("u").setExecutor(new Commands());
|
||||||
|
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||||
|
Instance=this; //2015.08.08.
|
||||||
|
try {
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
//System.out.println("Name: " + name);
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("flairsignored.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
throw new IOException("Test"); //2015.08.09.
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||||
|
Thread t=new Thread(r);
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
Boolean stop=false;
|
||||||
|
// Fired when plugin is disabled
|
||||||
|
@Override
|
||||||
|
public void onDisable()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileWriter fw;
|
||||||
|
fw = new FileWriter("flairsaccepted.txt");
|
||||||
|
fw.close();
|
||||||
|
fw = new FileWriter("flairsignored.txt");
|
||||||
|
fw.close();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.AcceptedFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
}
|
||||||
|
bw.close();
|
||||||
|
file=new File("flairsignored.txt");
|
||||||
|
bw = new BufferedWriter(new FileWriter(file, true));
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.IgnoredFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
}
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
stop=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ThreadMethod() //<-- 2015.07.16.
|
||||||
|
{
|
||||||
|
while(!stop)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
||||||
|
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
||||||
|
for(Object obj : json)
|
||||||
|
{
|
||||||
|
JSONObject item = (JSONObject)obj;
|
||||||
|
String author=item.getJSONObject("data").getString("author");
|
||||||
|
String ign=item.getJSONObject("data").getString("body");
|
||||||
|
int start = ign.indexOf("IGN:") + "IGN:".length();
|
||||||
|
int end = ign.indexOf(' ', start);
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
end=ign.indexOf('\n', start); //2015.07.15.
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
ign = ign.substring(start);
|
||||||
|
else
|
||||||
|
ign = ign.substring(start, end);
|
||||||
|
ign = ign.trim();
|
||||||
|
if(HasIGFlair(ign))
|
||||||
|
continue;
|
||||||
|
try {
|
||||||
|
Thread.sleep(10);
|
||||||
|
} catch(InterruptedException ex) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
||||||
|
String flair;
|
||||||
|
if(flairdata.length > 1) //2015.07.15.
|
||||||
|
flair = flairdata[1];
|
||||||
|
else
|
||||||
|
flair="";
|
||||||
|
if (flair != "-1")
|
||||||
|
flair = flair + "s";
|
||||||
|
else
|
||||||
|
flair = "non-presser";
|
||||||
|
String flairclass;
|
||||||
|
if(flairdata.length>2)
|
||||||
|
flairclass = flairdata[2];
|
||||||
|
else
|
||||||
|
flairclass="unknown";
|
||||||
|
SetFlair(ign, flair, flairclass, author);
|
||||||
|
}
|
||||||
|
Thread.sleep(10000);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Exception LastException; //2015.08.09.
|
||||||
|
public static int LastExceptionTime; //2015.08.09.
|
||||||
|
|
||||||
|
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
||||||
|
{
|
||||||
|
URL url = new URL(urlstr);
|
||||||
|
URLConnection con = url.openConnection();
|
||||||
|
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
||||||
|
InputStream in = con.getInputStream();
|
||||||
|
String encoding = con.getContentEncoding();
|
||||||
|
encoding = encoding == null ? "UTF-8" : encoding;
|
||||||
|
String body = IOUtils.toString(in, encoding);
|
||||||
|
in.close();
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||||
|
public Boolean HasIGFlair(String playername)
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
return p.Flair!=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||||
|
{
|
||||||
|
String finalflair;
|
||||||
|
switch(flairclass)
|
||||||
|
{
|
||||||
|
case "press-1":
|
||||||
|
finalflair="§c("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-2":
|
||||||
|
finalflair="§6("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-3":
|
||||||
|
finalflair="§e("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-4":
|
||||||
|
finalflair="§a("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-5":
|
||||||
|
finalflair="§9("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-6":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "no-press":
|
||||||
|
finalflair="§7(non-pr.)§r";
|
||||||
|
break;
|
||||||
|
case "cheater":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "cant-press": //2015.08.08.
|
||||||
|
finalflair="§r(can't press)§r";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
finalflair="";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||||
|
return;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
p.Flair=finalflair; //2015.08.08.
|
||||||
|
p.UserName=username; //2015.08.08.
|
||||||
|
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||||
|
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(player.getName().equals(playername))
|
||||||
|
{
|
||||||
|
AppendPlayerDisplayFlair(player, username, finalflair);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetFlair(Player player)
|
||||||
|
{ //2015.07.16.
|
||||||
|
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||||
|
return flair==null ? "" : flair;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||||
|
{
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
||||||
|
return;
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
||||||
|
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
else
|
||||||
|
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||||
|
String[] colors = color.substring(1).split("§");
|
||||||
|
String displayname=player.getName(); //2015.08.08.
|
||||||
|
ArrayList<Integer> Positions=new ArrayList<>();
|
||||||
|
for(int i=0; i<displayname.length(); i++) {
|
||||||
|
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||||
|
Positions.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String finalname=""; //TODO
|
||||||
|
if(Positions.size()>=colors.length)
|
||||||
|
{
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<Positions.size(); i++)
|
||||||
|
{
|
||||||
|
int pos=Positions.get(i);
|
||||||
|
int nextpos;
|
||||||
|
if(i!=Positions.size()-1)
|
||||||
|
nextpos=Positions.get(i+1);
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Positions.clear();
|
||||||
|
int unit=displayname.length()/colors.length;
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||||
|
{
|
||||||
|
int pos=i;
|
||||||
|
int nextpos;
|
||||||
|
if(i<displayname.length()-unit-unit)
|
||||||
|
nextpos=i+unit;
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetColorForTown(String townname)
|
||||||
|
{ //2015.07.20.
|
||||||
|
if(TownColors.containsKey(townname))
|
||||||
|
return TownColors.get(townname);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetPlayerTown(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
try {
|
||||||
|
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||||
|
return town.getName();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<? extends Player> GetPlayers()
|
||||||
|
{
|
||||||
|
return Instance.getServer().getOnlinePlayers();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,66 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
import de.inventivegames.TellRawAutoMessage.Reflection;
|
||||||
|
|
||||||
|
public class PlayerListener implements Listener
|
||||||
|
{ //2015.07.16.
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event)
|
||||||
|
{
|
||||||
|
Player p=event.getPlayer();
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
||||||
|
else
|
||||||
|
{ //2015.07.20.
|
||||||
|
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
||||||
|
sendRawMessage(p, json);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerLeave(PlayerQuitEvent event)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerChat(AsyncPlayerChatEvent event)
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
||||||
|
String flair=player.Flair; //2015.08.08.
|
||||||
|
if(flair==null || !player.AcceptedFlair)
|
||||||
|
flair=""; //2015.08.08.
|
||||||
|
String message=event.getMessage();
|
||||||
|
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
||||||
|
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
||||||
|
public static void sendRawMessage(Player player, String message)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
System.out.println("1");
|
||||||
|
Object handle = Reflection.getHandle(player);
|
||||||
|
System.out.println("2");
|
||||||
|
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
|
System.out.println("3");
|
||||||
|
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
||||||
|
System.out.println("4");
|
||||||
|
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
||||||
|
System.out.println("5");
|
||||||
|
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
||||||
|
System.out.println("6");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,135 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.
|
||||||
|
else if(args[0].toLowerCase()=="admin")
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage(msg);
|
||||||
|
else
|
||||||
|
System.out.println(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,350 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||||
|
|
||||||
|
public class PluginMain extends JavaPlugin
|
||||||
|
{ //Translated to Java: 2015.07.15.
|
||||||
|
//A user, which flair isn't obtainable:
|
||||||
|
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
||||||
|
private static PluginMain Instance;
|
||||||
|
// Fired when plugin is first enabled
|
||||||
|
@Override
|
||||||
|
public void onEnable()
|
||||||
|
{
|
||||||
|
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||||
|
this.getCommand("u").setExecutor(new Commands());
|
||||||
|
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||||
|
Instance=this; //2015.08.08.
|
||||||
|
try {
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
//System.out.println("Name: " + name);
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("flairsignored.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||||
|
Thread t=new Thread(r);
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
Boolean stop=false;
|
||||||
|
// Fired when plugin is disabled
|
||||||
|
@Override
|
||||||
|
public void onDisable()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileWriter fw;
|
||||||
|
fw = new FileWriter("flairsaccepted.txt");
|
||||||
|
fw.close();
|
||||||
|
fw = new FileWriter("flairsignored.txt");
|
||||||
|
fw.close();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.AcceptedFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
}
|
||||||
|
bw.close();
|
||||||
|
file=new File("flairsignored.txt");
|
||||||
|
bw = new BufferedWriter(new FileWriter(file, true));
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.IgnoredFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
}
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
stop=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ThreadMethod() //<-- 2015.07.16.
|
||||||
|
{
|
||||||
|
while(!stop)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
||||||
|
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
||||||
|
for(Object obj : json)
|
||||||
|
{
|
||||||
|
JSONObject item = (JSONObject)obj;
|
||||||
|
String author=item.getJSONObject("data").getString("author");
|
||||||
|
String ign=item.getJSONObject("data").getString("body");
|
||||||
|
int start = ign.indexOf("IGN:") + "IGN:".length();
|
||||||
|
int end = ign.indexOf(' ', start);
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
end=ign.indexOf('\n', start); //2015.07.15.
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
ign = ign.substring(start);
|
||||||
|
else
|
||||||
|
ign = ign.substring(start, end);
|
||||||
|
ign = ign.trim();
|
||||||
|
if(HasIGFlair(ign))
|
||||||
|
continue;
|
||||||
|
try {
|
||||||
|
Thread.sleep(10);
|
||||||
|
} catch(InterruptedException ex) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
||||||
|
String flair;
|
||||||
|
if(flairdata.length > 1) //2015.07.15.
|
||||||
|
flair = flairdata[1];
|
||||||
|
else
|
||||||
|
flair="";
|
||||||
|
if (flair != "-1")
|
||||||
|
flair = flair + "s";
|
||||||
|
else
|
||||||
|
flair = "non-presser";
|
||||||
|
String flairclass;
|
||||||
|
if(flairdata.length>2)
|
||||||
|
flairclass = flairdata[2];
|
||||||
|
else
|
||||||
|
flairclass="unknown";
|
||||||
|
SetFlair(ign, flair, flairclass, author);
|
||||||
|
}
|
||||||
|
Thread.sleep(10000);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Exception LastException; //2015.08.09.
|
||||||
|
|
||||||
|
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
||||||
|
{
|
||||||
|
URL url = new URL(urlstr);
|
||||||
|
URLConnection con = url.openConnection();
|
||||||
|
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
||||||
|
InputStream in = con.getInputStream();
|
||||||
|
String encoding = con.getContentEncoding();
|
||||||
|
encoding = encoding == null ? "UTF-8" : encoding;
|
||||||
|
String body = IOUtils.toString(in, encoding);
|
||||||
|
in.close();
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||||
|
public Boolean HasIGFlair(String playername)
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
return p.Flair!=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||||
|
{
|
||||||
|
String finalflair;
|
||||||
|
switch(flairclass)
|
||||||
|
{
|
||||||
|
case "press-1":
|
||||||
|
finalflair="§c("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-2":
|
||||||
|
finalflair="§6("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-3":
|
||||||
|
finalflair="§e("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-4":
|
||||||
|
finalflair="§a("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-5":
|
||||||
|
finalflair="§9("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-6":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "no-press":
|
||||||
|
finalflair="§7(non-pr.)§r";
|
||||||
|
break;
|
||||||
|
case "cheater":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "cant-press": //2015.08.08.
|
||||||
|
finalflair="§r(can't press)§r";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
finalflair="";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||||
|
return;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
p.Flair=finalflair; //2015.08.08.
|
||||||
|
p.UserName=username; //2015.08.08.
|
||||||
|
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||||
|
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(player.getName().equals(playername))
|
||||||
|
{
|
||||||
|
AppendPlayerDisplayFlair(player, username, finalflair);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetFlair(Player player)
|
||||||
|
{ //2015.07.16.
|
||||||
|
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||||
|
return flair==null ? "" : flair;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||||
|
{
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
||||||
|
return;
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
||||||
|
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
else
|
||||||
|
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||||
|
String[] colors = color.substring(1).split("§");
|
||||||
|
String displayname=player.getName(); //2015.08.08.
|
||||||
|
ArrayList<Integer> Positions=new ArrayList<>();
|
||||||
|
for(int i=0; i<displayname.length(); i++) {
|
||||||
|
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||||
|
Positions.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String finalname=""; //TODO
|
||||||
|
if(Positions.size()>=colors.length)
|
||||||
|
{
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<Positions.size(); i++)
|
||||||
|
{
|
||||||
|
int pos=Positions.get(i);
|
||||||
|
int nextpos;
|
||||||
|
if(i!=Positions.size()-1)
|
||||||
|
nextpos=Positions.get(i+1);
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Positions.clear();
|
||||||
|
int unit=displayname.length()/colors.length;
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||||
|
{
|
||||||
|
int pos=i;
|
||||||
|
int nextpos;
|
||||||
|
if(i<displayname.length()-unit-unit)
|
||||||
|
nextpos=i+unit;
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetColorForTown(String townname)
|
||||||
|
{ //2015.07.20.
|
||||||
|
if(TownColors.containsKey(townname))
|
||||||
|
return TownColors.get(townname);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetPlayerTown(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
try {
|
||||||
|
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||||
|
return town.getName();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<? extends Player> GetPlayers()
|
||||||
|
{
|
||||||
|
return Instance.getServer().getOnlinePlayers();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
import de.inventivegames.TellRawAutoMessage.Reflection;
|
||||||
|
|
||||||
|
public class PlayerListener implements Listener
|
||||||
|
{ //2015.07.16.
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event)
|
||||||
|
{
|
||||||
|
Player p=event.getPlayer();
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
||||||
|
else
|
||||||
|
{ //2015.07.20.
|
||||||
|
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
||||||
|
sendRawMessage(p, json);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerLeave(PlayerQuitEvent event)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerChat(AsyncPlayerChatEvent event)
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
||||||
|
String flair=player.Flair; //2015.08.08.
|
||||||
|
if(flair==null || !player.AcceptedFlair)
|
||||||
|
flair=""; //2015.08.08.
|
||||||
|
String message=event.getMessage(); //2015.08.08.
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{ //2015.08.08.
|
||||||
|
message.replaceAll(p.getName(), p.getDisplayName());
|
||||||
|
}
|
||||||
|
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
||||||
|
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
||||||
|
public static void sendRawMessage(Player player, String message)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
System.out.println("1");
|
||||||
|
Object handle = Reflection.getHandle(player);
|
||||||
|
System.out.println("2");
|
||||||
|
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
|
System.out.println("3");
|
||||||
|
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
||||||
|
System.out.println("4");
|
||||||
|
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
||||||
|
System.out.println("5");
|
||||||
|
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
||||||
|
System.out.println("6");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,138 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;*/
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.*/
|
||||||
|
else if(args[0].toLowerCase()=="admin")
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage(msg);
|
||||||
|
else
|
||||||
|
System.out.println(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "reload":
|
||||||
|
DoReload(player);
|
||||||
|
case "playerinfo":
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
import de.inventivegames.TellRawAutoMessage.Reflection;
|
||||||
|
|
||||||
|
public class PlayerListener implements Listener
|
||||||
|
{ //2015.07.16.
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event)
|
||||||
|
{
|
||||||
|
Player p=event.getPlayer();
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
||||||
|
else
|
||||||
|
{ //2015.07.20.
|
||||||
|
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
||||||
|
sendRawMessage(p, json);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerLeave(PlayerQuitEvent event)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerChat(AsyncPlayerChatEvent event)
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
||||||
|
String flair=player.Flair; //2015.08.08.
|
||||||
|
if(flair==null || !player.AcceptedFlair)
|
||||||
|
flair=""; //2015.08.08.
|
||||||
|
String message=event.getMessage(); //2015.08.08.
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{ //2015.08.08.
|
||||||
|
message.replaceAll(arg0, arg1)
|
||||||
|
}
|
||||||
|
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
||||||
|
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
||||||
|
public static void sendRawMessage(Player player, String message)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
System.out.println("1");
|
||||||
|
Object handle = Reflection.getHandle(player);
|
||||||
|
System.out.println("2");
|
||||||
|
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
|
System.out.println("3");
|
||||||
|
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
||||||
|
System.out.println("4");
|
||||||
|
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
||||||
|
System.out.println("5");
|
||||||
|
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
||||||
|
System.out.println("6");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,131 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.
|
||||||
|
else if(args[0].toLowerCase()=="admin")
|
||||||
|
DoAdmin(null); //2015.08.09.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage(msg);
|
||||||
|
else
|
||||||
|
System.out.println(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player)
|
||||||
|
{
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,192 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;*/
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.*/
|
||||||
|
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||||
|
{
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return true; //2015.08.09.
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
SendMessage(player, msg); //2015.08.09.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
PluginMain.LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
System.out.println("Args length: " + args.length);
|
||||||
|
if(args.length==1)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "reload":
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "playerinfo":
|
||||||
|
DoPlayerInfo(player, args);
|
||||||
|
break;
|
||||||
|
case "getlasterror":
|
||||||
|
DoGetLastError(player, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoPlayerInfo(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
//args[0] is "admin" - args[1] is "playerinfo"
|
||||||
|
if(args.length==2)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||||
|
{
|
||||||
|
String message="§cPlayer not found: "+args[2]+"§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||||
|
SendMessage(player, "Player name: "+p.PlayerName);
|
||||||
|
SendMessage(player, "User flair: "+p.Flair);
|
||||||
|
SendMessage(player, "Username: "+p.UserName);
|
||||||
|
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
||||||
|
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
||||||
|
}
|
||||||
|
private static void SendMessage(Player player, String message)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
}
|
||||||
|
private static void DoGetLastError(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
//args[0] is "admin" - args[1] is "getlasterror"
|
||||||
|
if(args.length==2)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin getlasterror <player>§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SendMessage(player, "Last error:");
|
||||||
|
SendMessage(player, PluginMain.LastException.toString());
|
||||||
|
SendMessage(player, "Stack trace:")args;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,419 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
|
||||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
|
||||||
|
|
||||||
public class PluginMain extends JavaPlugin
|
|
||||||
{ //Translated to Java: 2015.07.15.
|
|
||||||
//A user, which flair isn't obtainable:
|
|
||||||
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
|
||||||
// Fired when plugin is first enabled
|
|
||||||
@Override
|
|
||||||
public void onEnable()
|
|
||||||
{
|
|
||||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
|
||||||
//System.out.println("Original C# version: http://pastebin.com/tX8xCPbp");
|
|
||||||
//System.out.println("The Java version is... Also made by the same person.");
|
|
||||||
//System.out.println("With the help of StackOverflow and similar.");
|
|
||||||
/*catch(MalformedURLException e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
catch(IOException e)
|
|
||||||
{
|
|
||||||
}*/
|
|
||||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
|
||||||
//System.out.println("Registering commands...");
|
|
||||||
this.getCommand("u").setExecutor(new Commands());
|
|
||||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
|
||||||
try {
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//AcceptedPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("flairsignored.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//IgnoredPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
|
||||||
String line;
|
|
||||||
while((line=br.readLine())!=null)
|
|
||||||
{
|
|
||||||
String[] s=line.split(" ");
|
|
||||||
TownColors.put(s[0], s[1]);
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//System.out.println("Registering done.");
|
|
||||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
|
||||||
Thread t=new Thread(r);
|
|
||||||
t.start();
|
|
||||||
}
|
|
||||||
Boolean stop=false;
|
|
||||||
// Fired when plugin is disabled
|
|
||||||
@Override
|
|
||||||
public void onDisable()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
FileWriter fw;
|
|
||||||
fw = new FileWriter("flairsaccepted.txt");
|
|
||||||
fw.close();
|
|
||||||
fw = new FileWriter("flairsignored.txt");
|
|
||||||
fw.close();
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//for(String player : AcceptedPlayers)
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.AcceptedFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.IgnoredFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsignored.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stop=true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ThreadMethod() //<-- 2015.07.16.
|
|
||||||
{
|
|
||||||
/*System.out.println("Sleeping for 5 seconds..."); //2015.07.20.
|
|
||||||
try {
|
|
||||||
Thread.sleep(5000);
|
|
||||||
} catch (InterruptedException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
} //2015.07.20.*/
|
|
||||||
while(!stop)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
|
||||||
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
|
||||||
for(Object obj : json)
|
|
||||||
{
|
|
||||||
JSONObject item = (JSONObject)obj;
|
|
||||||
String author=item.getJSONObject("data").getString("author");
|
|
||||||
String ign=item.getJSONObject("data").getString("body");
|
|
||||||
int start = ign.indexOf("IGN:") + "IGN:".length();
|
|
||||||
int end = ign.indexOf(' ', start);
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
end=ign.indexOf('\n', start); //2015.07.15.
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
ign = ign.substring(start);
|
|
||||||
else
|
|
||||||
ign = ign.substring(start, end);
|
|
||||||
ign = ign.trim();
|
|
||||||
if(HasIGFlair(ign))
|
|
||||||
continue;
|
|
||||||
//System.out.println("Author: "+author);
|
|
||||||
try {
|
|
||||||
Thread.sleep(10);
|
|
||||||
} catch(InterruptedException ex) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
|
||||||
String flair;
|
|
||||||
if(flairdata.length > 1) //2015.07.15.
|
|
||||||
flair = flairdata[1];
|
|
||||||
else
|
|
||||||
flair="";
|
|
||||||
if (flair != "-1")
|
|
||||||
flair = flair + "s";
|
|
||||||
else
|
|
||||||
flair = "non-presser";
|
|
||||||
String flairclass;
|
|
||||||
//System.out.println("flairdata.length:"+flairdata.length);
|
|
||||||
if(flairdata.length>2)
|
|
||||||
flairclass = flairdata[2];
|
|
||||||
else
|
|
||||||
flairclass="unknown";
|
|
||||||
SetFlair(ign, flair, flairclass, author);
|
|
||||||
}
|
|
||||||
Thread.sleep(10000);
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
|
||||||
{
|
|
||||||
URL url = new URL(urlstr);
|
|
||||||
URLConnection con = url.openConnection();
|
|
||||||
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
|
||||||
InputStream in = con.getInputStream();
|
|
||||||
String encoding = con.getContentEncoding();
|
|
||||||
encoding = encoding == null ? "UTF-8" : encoding;
|
|
||||||
String body = IOUtils.toString(in, encoding);
|
|
||||||
in.close();
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
//It has to store offline player flairs too, therefore it can't use Player object
|
|
||||||
/*public static Map<String, String> PlayerFlairs=new HashMap<String, String>();
|
|
||||||
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
|
|
||||||
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
|
|
||||||
public static ArrayList<Player> Players=new ArrayList<Player>();
|
|
||||||
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
//public static Map<String, String> PlayerTowns=new HashMap<String, String>(); //2015.07.20.*/
|
|
||||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
|
||||||
public Boolean HasIGFlair(String playername)
|
|
||||||
{
|
|
||||||
/*Player player=null;
|
|
||||||
for(Player p : Players)
|
|
||||||
{
|
|
||||||
if(p.getName()==playername)
|
|
||||||
{
|
|
||||||
player=p;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(player==null)
|
|
||||||
return false;*/
|
|
||||||
//return PlayerFlairs.containsKey(playername);
|
|
||||||
return MaybeOfflinePlayer.AllPlayers.containsKey(playername);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
|
||||||
{
|
|
||||||
String finalflair;
|
|
||||||
switch(flairclass)
|
|
||||||
{
|
|
||||||
case "press-1":
|
|
||||||
finalflair="§c("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-2":
|
|
||||||
finalflair="§6("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-3":
|
|
||||||
finalflair="§e("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-4":
|
|
||||||
finalflair="§a("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-5":
|
|
||||||
finalflair="§9("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-6":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "no-press":
|
|
||||||
finalflair="§7(non-pr.)§r";
|
|
||||||
break;
|
|
||||||
case "cheater":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "cant-press": //2015.08.08.
|
|
||||||
finalflair="§r(can't press)§r";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
finalflair="";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
|
||||||
return;
|
|
||||||
//PlayerFlairs.put(playername, finalflair);
|
|
||||||
//PlayerUserNames.put(playername, username);
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
|
||||||
p.Flair=finalflair; //2015.08.08.
|
|
||||||
p.UserName=username; //2015.08.08.
|
|
||||||
/*for(Player player : Players)
|
|
||||||
{
|
|
||||||
if(player.getName()==playername)
|
|
||||||
{
|
|
||||||
PlayerFlairs.put(player, finalflair);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
//System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass);
|
|
||||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
|
||||||
for(Player player : Players)
|
|
||||||
{
|
|
||||||
//System.out.println("Online player: "+player.getName());
|
|
||||||
//System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername));
|
|
||||||
if(player.getName().equals(playername))
|
|
||||||
{
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
//player.setDisplayName(player.getDisplayName()+finalflair);
|
|
||||||
AppendPlayerDisplayFlair(player, username, finalflair);
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetFlair(Player player)
|
|
||||||
{ //2015.07.16.
|
|
||||||
//String flair=PlayerFlairs.get(player.getName());
|
|
||||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
|
||||||
return flair==null ? "" : flair;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
|
||||||
{
|
|
||||||
//if(IgnoredPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
|
||||||
return;
|
|
||||||
//if(AcceptedPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
|
||||||
//player.setDisplayName(player.getDisplayName()+flair);
|
|
||||||
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
else
|
|
||||||
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//System.out.println("A");
|
|
||||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
|
||||||
String[] colors = color.substring(1).split("§");
|
|
||||||
//String displayname=player.getDisplayName();
|
|
||||||
String displayname=player.getName(); //2015.08.08.
|
|
||||||
ArrayList<Integer> Positions=new ArrayList<>();
|
|
||||||
//System.out.println("B");
|
|
||||||
for(int i=0; i<displayname.length(); i++) {
|
|
||||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
|
||||||
Positions.add(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//System.out.println("C: Positions.size(): "+Positions.size());
|
|
||||||
String finalname="";
|
|
||||||
if(Positions.size()>=colors.length)
|
|
||||||
{
|
|
||||||
//System.out.println("D");
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<Positions.size(); i++)
|
|
||||||
{
|
|
||||||
int pos=Positions.get(i);
|
|
||||||
int nextpos;
|
|
||||||
if(i!=Positions.size()-1)
|
|
||||||
nextpos=Positions.get(i+1);
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
//String substr="§"+colors[x++]+displayname.substring(pos, nextpos-pos)+"§r";
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("F");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//System.out.println("E");
|
|
||||||
Positions.clear();
|
|
||||||
int unit=displayname.length()/colors.length;
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
|
||||||
{
|
|
||||||
int pos=i;
|
|
||||||
int nextpos;
|
|
||||||
if(i<displayname.length()-unit-unit)
|
|
||||||
nextpos=i+unit;
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("G");
|
|
||||||
}
|
|
||||||
//player.setDisplayName(color+displayname+"§r"+flair);
|
|
||||||
//player.setDisplayName(finalname+flair);
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=finalname+flair; //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetColorForTown(String townname)
|
|
||||||
{ //2015.07.20.
|
|
||||||
if(TownColors.containsKey(townname))
|
|
||||||
return TownColors.get(townname);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetPlayerTown(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//List<Town> towns = TownyUniverse.getDataSource().getTowns();
|
|
||||||
try {
|
|
||||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown();
|
|
||||||
return town.getName();
|
|
||||||
} catch (Exception e) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
String color = GetColorForTown(GetPlayerTown(player));
|
|
||||||
String dname=player.getDisplayName();
|
|
||||||
//player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair)));
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08.
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,190 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;*/
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.*/
|
||||||
|
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||||
|
{
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return true; //2015.08.09.
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
SendMessage(player, msg); //2015.08.09.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
PluginMain.LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
System.out.println("Args length: " + args.length);
|
||||||
|
if(args.length==1)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "reload":
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "playerinfo":
|
||||||
|
DoPlayerInfo(player, args);
|
||||||
|
break;
|
||||||
|
case "getlasterror":
|
||||||
|
DoGetLastError(player, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoPlayerInfo(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
//args[0] is "admin" - args[1] is "playerinfo"
|
||||||
|
if(args.length==2)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||||
|
{
|
||||||
|
String message="§cPlayer not found: "+args[2]+"§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||||
|
SendMessage(player, "Player name: "+p.PlayerName);
|
||||||
|
SendMessage(player, "User flair: "+p.Flair);
|
||||||
|
SendMessage(player, "Username: "+p.UserName);
|
||||||
|
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
||||||
|
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
||||||
|
}
|
||||||
|
private static void SendMessage(Player player, String message)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
}
|
||||||
|
private static void DoGetLastError(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
//args[0] is "admin" - args[1] is "getlasterror"
|
||||||
|
if(PluginMain.LastException!=null)
|
||||||
|
{
|
||||||
|
SendMessage(player, "Last error:");
|
||||||
|
SendMessage(player, PluginMain.LastException.toString());
|
||||||
|
PluginMain.LastException=null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
SendMessage(player, "There were no exceptions.");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,362 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||||
|
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||||
|
|
||||||
|
public class PluginMain extends JavaPlugin
|
||||||
|
{ //Translated to Java: 2015.07.15.
|
||||||
|
//A user, which flair isn't obtainable:
|
||||||
|
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
||||||
|
private static PluginMain Instance;
|
||||||
|
// Fired when plugin is first enabled
|
||||||
|
@Override
|
||||||
|
public void onEnable()
|
||||||
|
{
|
||||||
|
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||||
|
this.getCommand("u").setExecutor(new Commands());
|
||||||
|
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||||
|
Instance=this; //2015.08.08.
|
||||||
|
try {
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
System.out.println("Name: " + name);
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("flairsignored.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||||
|
Thread t=new Thread(r);
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
Boolean stop=false;
|
||||||
|
// Fired when plugin is disabled
|
||||||
|
@Override
|
||||||
|
public void onDisable()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileWriter fw;
|
||||||
|
fw = new FileWriter("flairsaccepted.txt");
|
||||||
|
fw.close();
|
||||||
|
fw = new FileWriter("flairsignored.txt");
|
||||||
|
fw.close();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.AcceptedFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
try {
|
||||||
|
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.IgnoredFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
File file=new File("flairsignored.txt");
|
||||||
|
try {
|
||||||
|
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stop=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ThreadMethod() //<-- 2015.07.16.
|
||||||
|
{
|
||||||
|
while(!stop)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
||||||
|
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
||||||
|
for(Object obj : json)
|
||||||
|
{
|
||||||
|
JSONObject item = (JSONObject)obj;
|
||||||
|
String author=item.getJSONObject("data").getString("author");
|
||||||
|
String ign=item.getJSONObject("data").getString("body");
|
||||||
|
int start = ign.indexOf("IGN:") + "IGN:".length();
|
||||||
|
int end = ign.indexOf(' ', start);
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
end=ign.indexOf('\n', start); //2015.07.15.
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
ign = ign.substring(start);
|
||||||
|
else
|
||||||
|
ign = ign.substring(start, end);
|
||||||
|
ign = ign.trim();
|
||||||
|
if(HasIGFlair(ign))
|
||||||
|
continue;
|
||||||
|
try {
|
||||||
|
Thread.sleep(10);
|
||||||
|
} catch(InterruptedException ex) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
||||||
|
String flair;
|
||||||
|
if(flairdata.length > 1) //2015.07.15.
|
||||||
|
flair = flairdata[1];
|
||||||
|
else
|
||||||
|
flair="";
|
||||||
|
if (flair != "-1")
|
||||||
|
flair = flair + "s";
|
||||||
|
else
|
||||||
|
flair = "non-presser";
|
||||||
|
String flairclass;
|
||||||
|
if(flairdata.length>2)
|
||||||
|
flairclass = flairdata[2];
|
||||||
|
else
|
||||||
|
flairclass="unknown";
|
||||||
|
SetFlair(ign, flair, flairclass, author);
|
||||||
|
}
|
||||||
|
Thread.sleep(10000);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
||||||
|
{
|
||||||
|
URL url = new URL(urlstr);
|
||||||
|
URLConnection con = url.openConnection();
|
||||||
|
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
||||||
|
InputStream in = con.getInputStream();
|
||||||
|
String encoding = con.getContentEncoding();
|
||||||
|
encoding = encoding == null ? "UTF-8" : encoding;
|
||||||
|
String body = IOUtils.toString(in, encoding);
|
||||||
|
in.close();
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||||
|
public Boolean HasIGFlair(String playername)
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
return p.Flair!=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||||
|
{
|
||||||
|
String finalflair;
|
||||||
|
switch(flairclass)
|
||||||
|
{
|
||||||
|
case "press-1":
|
||||||
|
finalflair="§c("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-2":
|
||||||
|
finalflair="§6("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-3":
|
||||||
|
finalflair="§e("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-4":
|
||||||
|
finalflair="§a("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-5":
|
||||||
|
finalflair="§9("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-6":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "no-press":
|
||||||
|
finalflair="§7(non-pr.)§r";
|
||||||
|
break;
|
||||||
|
case "cheater":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "cant-press": //2015.08.08.
|
||||||
|
finalflair="§r(can't press)§r";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
finalflair="";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||||
|
return;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
p.Flair=finalflair; //2015.08.08.
|
||||||
|
p.UserName=username; //2015.08.08.
|
||||||
|
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||||
|
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(player.getName().equals(playername))
|
||||||
|
{
|
||||||
|
AppendPlayerDisplayFlair(player, username, finalflair);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetFlair(Player player)
|
||||||
|
{ //2015.07.16.
|
||||||
|
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||||
|
return flair==null ? "" : flair;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||||
|
{
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
||||||
|
return;
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
||||||
|
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
else
|
||||||
|
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||||
|
String[] colors = color.substring(1).split("§");
|
||||||
|
String displayname=player.getName(); //2015.08.08.
|
||||||
|
ArrayList<Integer> Positions=new ArrayList<>();
|
||||||
|
for(int i=0; i<displayname.length(); i++) {
|
||||||
|
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||||
|
Positions.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String finalname="";
|
||||||
|
if(Positions.size()>=colors.length)
|
||||||
|
{
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<Positions.size(); i++)
|
||||||
|
{
|
||||||
|
int pos=Positions.get(i);
|
||||||
|
int nextpos;
|
||||||
|
if(i!=Positions.size()-1)
|
||||||
|
nextpos=Positions.get(i+1);
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
//System.out.println("F");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//System.out.println("E");
|
||||||
|
Positions.clear();
|
||||||
|
int unit=displayname.length()/colors.length;
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||||
|
{
|
||||||
|
int pos=i;
|
||||||
|
int nextpos;
|
||||||
|
if(i<displayname.length()-unit-unit)
|
||||||
|
nextpos=i+unit;
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
||||||
|
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
//System.out.println("G");
|
||||||
|
}
|
||||||
|
//player.setDisplayName(color+displayname+"§r"+flair);
|
||||||
|
//player.setDisplayName(finalname+flair);
|
||||||
|
//MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=finalname+flair; //2015.08.08.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetColorForTown(String townname)
|
||||||
|
{ //2015.07.20.
|
||||||
|
if(TownColors.containsKey(townname))
|
||||||
|
return TownColors.get(townname);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetPlayerTown(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//List<Town> towns = TownyUniverse.getDataSource().getTowns();
|
||||||
|
try {
|
||||||
|
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||||
|
return town.getName();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//String color = GetColorForTown(GetPlayerTown(player));
|
||||||
|
//String dname=player.getDisplayName();
|
||||||
|
//player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair)));
|
||||||
|
//MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<? extends Player> GetPlayers()
|
||||||
|
{
|
||||||
|
return Instance.getServer().getOnlinePlayers();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,360 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||||
|
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||||
|
|
||||||
|
public class PluginMain extends JavaPlugin
|
||||||
|
{ //Translated to Java: 2015.07.15.
|
||||||
|
//A user, which flair isn't obtainable:
|
||||||
|
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
||||||
|
private static PluginMain Instance;
|
||||||
|
// Fired when plugin is first enabled
|
||||||
|
@Override
|
||||||
|
public void onEnable()
|
||||||
|
{
|
||||||
|
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||||
|
this.getCommand("u").setExecutor(new Commands());
|
||||||
|
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||||
|
Instance=this; //2015.08.08.
|
||||||
|
try {
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
System.out.println("Name: " + name);
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("flairsignored.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||||
|
Thread t=new Thread(r);
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
Boolean stop=false;
|
||||||
|
// Fired when plugin is disabled
|
||||||
|
@Override
|
||||||
|
public void onDisable()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileWriter fw;
|
||||||
|
fw = new FileWriter("flairsaccepted.txt");
|
||||||
|
fw.close();
|
||||||
|
fw = new FileWriter("flairsignored.txt");
|
||||||
|
fw.close();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.AcceptedFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
try {
|
||||||
|
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.IgnoredFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
File file=new File("flairsignored.txt");
|
||||||
|
try {
|
||||||
|
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stop=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ThreadMethod() //<-- 2015.07.16.
|
||||||
|
{
|
||||||
|
while(!stop)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
||||||
|
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
||||||
|
for(Object obj : json)
|
||||||
|
{
|
||||||
|
JSONObject item = (JSONObject)obj;
|
||||||
|
String author=item.getJSONObject("data").getString("author");
|
||||||
|
String ign=item.getJSONObject("data").getString("body");
|
||||||
|
int start = ign.indexOf("IGN:") + "IGN:".length();
|
||||||
|
int end = ign.indexOf(' ', start);
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
end=ign.indexOf('\n', start); //2015.07.15.
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
ign = ign.substring(start);
|
||||||
|
else
|
||||||
|
ign = ign.substring(start, end);
|
||||||
|
ign = ign.trim();
|
||||||
|
if(HasIGFlair(ign))
|
||||||
|
continue;
|
||||||
|
try {
|
||||||
|
Thread.sleep(10);
|
||||||
|
} catch(InterruptedException ex) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
||||||
|
String flair;
|
||||||
|
if(flairdata.length > 1) //2015.07.15.
|
||||||
|
flair = flairdata[1];
|
||||||
|
else
|
||||||
|
flair="";
|
||||||
|
if (flair != "-1")
|
||||||
|
flair = flair + "s";
|
||||||
|
else
|
||||||
|
flair = "non-presser";
|
||||||
|
String flairclass;
|
||||||
|
if(flairdata.length>2)
|
||||||
|
flairclass = flairdata[2];
|
||||||
|
else
|
||||||
|
flairclass="unknown";
|
||||||
|
SetFlair(ign, flair, flairclass, author);
|
||||||
|
}
|
||||||
|
Thread.sleep(10000);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
||||||
|
{
|
||||||
|
URL url = new URL(urlstr);
|
||||||
|
URLConnection con = url.openConnection();
|
||||||
|
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
||||||
|
InputStream in = con.getInputStream();
|
||||||
|
String encoding = con.getContentEncoding();
|
||||||
|
encoding = encoding == null ? "UTF-8" : encoding;
|
||||||
|
String body = IOUtils.toString(in, encoding);
|
||||||
|
in.close();
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||||
|
public Boolean HasIGFlair(String playername)
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
return p.Flair!=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||||
|
{
|
||||||
|
String finalflair;
|
||||||
|
switch(flairclass)
|
||||||
|
{
|
||||||
|
case "press-1":
|
||||||
|
finalflair="§c("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-2":
|
||||||
|
finalflair="§6("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-3":
|
||||||
|
finalflair="§e("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-4":
|
||||||
|
finalflair="§a("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-5":
|
||||||
|
finalflair="§9("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-6":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "no-press":
|
||||||
|
finalflair="§7(non-pr.)§r";
|
||||||
|
break;
|
||||||
|
case "cheater":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "cant-press": //2015.08.08.
|
||||||
|
finalflair="§r(can't press)§r";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
finalflair="";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||||
|
return;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
p.Flair=finalflair; //2015.08.08.
|
||||||
|
p.UserName=username; //2015.08.08.
|
||||||
|
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||||
|
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(player.getName().equals(playername))
|
||||||
|
{
|
||||||
|
AppendPlayerDisplayFlair(player, username, finalflair);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetFlair(Player player)
|
||||||
|
{ //2015.07.16.
|
||||||
|
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||||
|
return flair==null ? "" : flair;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||||
|
{
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
||||||
|
return;
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
||||||
|
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
else
|
||||||
|
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||||
|
String[] colors = color.substring(1).split("§");
|
||||||
|
String displayname=player.getName(); //2015.08.08.
|
||||||
|
ArrayList<Integer> Positions=new ArrayList<>();
|
||||||
|
for(int i=0; i<displayname.length(); i++) {
|
||||||
|
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||||
|
Positions.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String finalname="";
|
||||||
|
if(Positions.size()>=colors.length)
|
||||||
|
{
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<Positions.size(); i++)
|
||||||
|
{
|
||||||
|
int pos=Positions.get(i);
|
||||||
|
int nextpos;
|
||||||
|
if(i!=Positions.size()-1)
|
||||||
|
nextpos=Positions.get(i+1);
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Positions.clear();
|
||||||
|
int unit=displayname.length()/colors.length;
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||||
|
{
|
||||||
|
int pos=i;
|
||||||
|
int nextpos;
|
||||||
|
if(i<displayname.length()-unit-unit)
|
||||||
|
nextpos=i+unit;
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
||||||
|
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
//System.out.println("G");
|
||||||
|
}
|
||||||
|
//player.setDisplayName(color+displayname+"§r"+flair);
|
||||||
|
//player.setDisplayName(finalname+flair);
|
||||||
|
//MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=finalname+flair; //2015.08.08.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetColorForTown(String townname)
|
||||||
|
{ //2015.07.20.
|
||||||
|
if(TownColors.containsKey(townname))
|
||||||
|
return TownColors.get(townname);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetPlayerTown(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//List<Town> towns = TownyUniverse.getDataSource().getTowns();
|
||||||
|
try {
|
||||||
|
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||||
|
return town.getName();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//String color = GetColorForTown(GetPlayerTown(player));
|
||||||
|
//String dname=player.getDisplayName();
|
||||||
|
//player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair)));
|
||||||
|
//MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<? extends Player> GetPlayers()
|
||||||
|
{
|
||||||
|
return Instance.getServer().getOnlinePlayers();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,131 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "showerrors": //2015.08.09.
|
||||||
|
DoShowErrors(player);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.
|
||||||
|
else if(args[0].toLowerCase()=="showerrors")
|
||||||
|
DoShowErrors(null); //2015.08.09.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage(msg);
|
||||||
|
else
|
||||||
|
System.out.println(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoShowErrors(Player player)
|
||||||
|
{
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,163 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;*/
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.*/
|
||||||
|
else if(args[0].toLowerCase()=="admin")
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage(msg);
|
||||||
|
else
|
||||||
|
System.out.println(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
if(args.length==1)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "reload":
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "playerinfo":
|
||||||
|
DoPlayerInfo(player, args);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoPlayerInfo(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
//args[0] is "admin" - args[1] is "playerinfo"
|
||||||
|
if(args.length==2)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
import de.inventivegames.TellRawAutoMessage.Reflection;
|
||||||
|
|
||||||
|
public class PlayerListener implements Listener
|
||||||
|
{ //2015.07.16.
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event)
|
||||||
|
{
|
||||||
|
Player p=event.getPlayer();
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
||||||
|
else
|
||||||
|
{ //2015.07.20.
|
||||||
|
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
||||||
|
sendRawMessage(p, json);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerLeave(PlayerQuitEvent event)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerChat(AsyncPlayerChatEvent event)
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
||||||
|
String flair=player.Flair; //2015.08.08.
|
||||||
|
if(flair==null || !player.AcceptedFlair)
|
||||||
|
flair=""; //2015.08.08.
|
||||||
|
String message=event.getMessage(); //2015.08.08.
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{ //2015.08.08.
|
||||||
|
int index = message.indexOf(p.getName());
|
||||||
|
}
|
||||||
|
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
||||||
|
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
||||||
|
public static void sendRawMessage(Player player, String message)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
System.out.println("1");
|
||||||
|
Object handle = Reflection.getHandle(player);
|
||||||
|
System.out.println("2");
|
||||||
|
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
|
System.out.println("3");
|
||||||
|
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
||||||
|
System.out.println("4");
|
||||||
|
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
||||||
|
System.out.println("5");
|
||||||
|
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
||||||
|
System.out.println("6");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
import de.inventivegames.TellRawAutoMessage.Reflection;
|
||||||
|
|
||||||
|
public class PlayerListener implements Listener
|
||||||
|
{ //2015.07.16.
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event)
|
||||||
|
{
|
||||||
|
Player p=event.getPlayer();
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
||||||
|
else
|
||||||
|
{ //2015.07.20.
|
||||||
|
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
||||||
|
sendRawMessage(p, json);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerLeave(PlayerQuitEvent event)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerChat(AsyncPlayerChatEvent event)
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
||||||
|
String flair=player.Flair; //2015.08.08.
|
||||||
|
if(flair==null || !player.AcceptedFlair)
|
||||||
|
flair=""; //2015.08.08.
|
||||||
|
String message=event.getMessage(); //2015.08.08.
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{ //2015.08.08.
|
||||||
|
message.replaceAll(p.getName(), p.getDisplayName;
|
||||||
|
}
|
||||||
|
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
||||||
|
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
||||||
|
public static void sendRawMessage(Player player, String message)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
System.out.println("1");
|
||||||
|
Object handle = Reflection.getHandle(player);
|
||||||
|
System.out.println("2");
|
||||||
|
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
|
System.out.println("3");
|
||||||
|
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
||||||
|
System.out.println("4");
|
||||||
|
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
||||||
|
System.out.println("5");
|
||||||
|
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
||||||
|
System.out.println("6");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,420 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
|
||||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
|
||||||
|
|
||||||
public class PluginMain extends JavaPlugin
|
|
||||||
{ //Translated to Java: 2015.07.15.
|
|
||||||
//A user, which flair isn't obtainable:
|
|
||||||
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
|
||||||
// Fired when plugin is first enabled
|
|
||||||
@Override
|
|
||||||
public void onEnable()
|
|
||||||
{
|
|
||||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
|
||||||
//System.out.println("Original C# version: http://pastebin.com/tX8xCPbp");
|
|
||||||
//System.out.println("The Java version is... Also made by the same person.");
|
|
||||||
//System.out.println("With the help of StackOverflow and similar.");
|
|
||||||
/*catch(MalformedURLException e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
catch(IOException e)
|
|
||||||
{
|
|
||||||
}*/
|
|
||||||
PluginManager manager = getServer().getPluginManager();
|
|
||||||
manager.registerEvents(new PlayerListener(), this);
|
|
||||||
//System.out.println("Registering commands...");
|
|
||||||
this.getCommand("u").setExecutor(new Commands());
|
|
||||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
|
||||||
try {
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//AcceptedPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("flairsignored.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//IgnoredPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
|
||||||
String line;
|
|
||||||
while((line=br.readLine())!=null)
|
|
||||||
{
|
|
||||||
String[] s=line.split(" ");
|
|
||||||
TownColors.put(s[0], s[1]);
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//System.out.println("Registering done.");
|
|
||||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
|
||||||
Thread t=new Thread(r);
|
|
||||||
t.start();
|
|
||||||
}
|
|
||||||
Boolean stop=false;
|
|
||||||
// Fired when plugin is disabled
|
|
||||||
@Override
|
|
||||||
public void onDisable()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
FileWriter fw;
|
|
||||||
fw = new FileWriter("flairsaccepted.txt");
|
|
||||||
fw.close();
|
|
||||||
fw = new FileWriter("flairsignored.txt");
|
|
||||||
fw.close();
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//for(String player : AcceptedPlayers)
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.AcceptedFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.IgnoredFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsignored.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stop=true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ThreadMethod() //<-- 2015.07.16.
|
|
||||||
{
|
|
||||||
/*System.out.println("Sleeping for 5 seconds..."); //2015.07.20.
|
|
||||||
try {
|
|
||||||
Thread.sleep(5000);
|
|
||||||
} catch (InterruptedException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
} //2015.07.20.*/
|
|
||||||
while(!stop)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
|
||||||
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
|
||||||
for(Object obj : json)
|
|
||||||
{
|
|
||||||
JSONObject item = (JSONObject)obj;
|
|
||||||
String author=item.getJSONObject("data").getString("author");
|
|
||||||
String ign=item.getJSONObject("data").getString("body");
|
|
||||||
int start = ign.indexOf("IGN:") + "IGN:".length();
|
|
||||||
int end = ign.indexOf(' ', start);
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
end=ign.indexOf('\n', start); //2015.07.15.
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
ign = ign.substring(start);
|
|
||||||
else
|
|
||||||
ign = ign.substring(start, end);
|
|
||||||
ign = ign.trim();
|
|
||||||
if(HasIGFlair(ign))
|
|
||||||
continue;
|
|
||||||
//System.out.println("Author: "+author);
|
|
||||||
try {
|
|
||||||
Thread.sleep(10);
|
|
||||||
} catch(InterruptedException ex) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
|
||||||
String flair;
|
|
||||||
if(flairdata.length > 1) //2015.07.15.
|
|
||||||
flair = flairdata[1];
|
|
||||||
else
|
|
||||||
flair="";
|
|
||||||
if (flair != "-1")
|
|
||||||
flair = flair + "s";
|
|
||||||
else
|
|
||||||
flair = "non-presser";
|
|
||||||
String flairclass;
|
|
||||||
//System.out.println("flairdata.length:"+flairdata.length);
|
|
||||||
if(flairdata.length>2)
|
|
||||||
flairclass = flairdata[2];
|
|
||||||
else
|
|
||||||
flairclass="unknown";
|
|
||||||
SetFlair(ign, flair, flairclass, author);
|
|
||||||
}
|
|
||||||
Thread.sleep(10000);
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
|
||||||
{
|
|
||||||
URL url = new URL(urlstr);
|
|
||||||
URLConnection con = url.openConnection();
|
|
||||||
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
|
||||||
InputStream in = con.getInputStream();
|
|
||||||
String encoding = con.getContentEncoding();
|
|
||||||
encoding = encoding == null ? "UTF-8" : encoding;
|
|
||||||
String body = IOUtils.toString(in, encoding);
|
|
||||||
in.close();
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
//It has to store offline player flairs too, therefore it can't use Player object
|
|
||||||
/*public static Map<String, String> PlayerFlairs=new HashMap<String, String>();
|
|
||||||
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
|
|
||||||
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
|
|
||||||
public static ArrayList<Player> Players=new ArrayList<Player>();
|
|
||||||
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
//public static Map<String, String> PlayerTowns=new HashMap<String, String>(); //2015.07.20.*/
|
|
||||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
|
||||||
public Boolean HasIGFlair(String playername)
|
|
||||||
{
|
|
||||||
/*Player player=null;
|
|
||||||
for(Player p : Players)
|
|
||||||
{
|
|
||||||
if(p.getName()==playername)
|
|
||||||
{
|
|
||||||
player=p;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(player==null)
|
|
||||||
return false;*/
|
|
||||||
//return PlayerFlairs.containsKey(playername);
|
|
||||||
return MaybeOfflinePlayer.AllPlayers.containsKey(playername);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
|
||||||
{
|
|
||||||
String finalflair;
|
|
||||||
switch(flairclass)
|
|
||||||
{
|
|
||||||
case "press-1":
|
|
||||||
finalflair="§c("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-2":
|
|
||||||
finalflair="§6("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-3":
|
|
||||||
finalflair="§e("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-4":
|
|
||||||
finalflair="§a("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-5":
|
|
||||||
finalflair="§9("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-6":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "no-press":
|
|
||||||
finalflair="§7(non-pr.)§r";
|
|
||||||
break;
|
|
||||||
case "cheater":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "cant-press": //2015.08.08.
|
|
||||||
finalflair="§r(can't press)§r";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
finalflair="";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
|
||||||
return;
|
|
||||||
//PlayerFlairs.put(playername, finalflair);
|
|
||||||
//PlayerUserNames.put(playername, username);
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
|
||||||
p.Flair=finalflair; //2015.08.08.
|
|
||||||
p.UserName=username; //2015.08.08.
|
|
||||||
/*for(Player player : Players)
|
|
||||||
{
|
|
||||||
if(player.getName()==playername)
|
|
||||||
{
|
|
||||||
PlayerFlairs.put(player, finalflair);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
//System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass);
|
|
||||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
|
||||||
for(Player player : Players)
|
|
||||||
{
|
|
||||||
//System.out.println("Online player: "+player.getName());
|
|
||||||
//System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername));
|
|
||||||
if(player.getName().equals(playername))
|
|
||||||
{
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
//player.setDisplayName(player.getDisplayName()+finalflair);
|
|
||||||
AppendPlayerDisplayFlair(player, username, finalflair);
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetFlair(Player player)
|
|
||||||
{ //2015.07.16.
|
|
||||||
//String flair=PlayerFlairs.get(player.getName());
|
|
||||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
|
||||||
return flair==null ? "" : flair;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
|
||||||
{
|
|
||||||
//if(IgnoredPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
|
||||||
return;
|
|
||||||
//if(AcceptedPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
|
||||||
//player.setDisplayName(player.getDisplayName()+flair);
|
|
||||||
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
else
|
|
||||||
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//System.out.println("A");
|
|
||||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
|
||||||
String[] colors = color.substring(1).split("§");
|
|
||||||
//String displayname=player.getDisplayName();
|
|
||||||
String displayname=player.getName(); //2015.08.08.
|
|
||||||
ArrayList<Integer> Positions=new ArrayList<>();
|
|
||||||
//System.out.println("B");
|
|
||||||
for(int i=0; i<displayname.length(); i++) {
|
|
||||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
|
||||||
Positions.add(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//System.out.println("C: Positions.size(): "+Positions.size());
|
|
||||||
String finalname="";
|
|
||||||
if(Positions.size()>=colors.length)
|
|
||||||
{
|
|
||||||
//System.out.println("D");
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<Positions.size(); i++)
|
|
||||||
{
|
|
||||||
int pos=Positions.get(i);
|
|
||||||
int nextpos;
|
|
||||||
if(i!=Positions.size()-1)
|
|
||||||
nextpos=Positions.get(i+1);
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
//String substr="§"+colors[x++]+displayname.substring(pos, nextpos-pos)+"§r";
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("F");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//System.out.println("E");
|
|
||||||
Positions.clear();
|
|
||||||
int unit=displayname.length()/colors.length;
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
|
||||||
{
|
|
||||||
int pos=i;
|
|
||||||
int nextpos;
|
|
||||||
if(i<displayname.length()-unit-unit)
|
|
||||||
nextpos=i+unit;
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("G");
|
|
||||||
}
|
|
||||||
//player.setDisplayName(color+displayname+"§r"+flair);
|
|
||||||
//player.setDisplayName(finalname+flair);
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=finalname+flair; //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetColorForTown(String townname)
|
|
||||||
{ //2015.07.20.
|
|
||||||
if(TownColors.containsKey(townname))
|
|
||||||
return TownColors.get(townname);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetPlayerTown(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//List<Town> towns = TownyUniverse.getDataSource().getTowns();
|
|
||||||
try {
|
|
||||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown();
|
|
||||||
return town.getName();
|
|
||||||
} catch (Exception e) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
String color = GetColorForTown(GetPlayerTown(player));
|
|
||||||
String dname=player.getDisplayName();
|
|
||||||
//player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair)));
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08.
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,192 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;*/
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.*/
|
||||||
|
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||||
|
{
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return true; //2015.08.09.
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
SendMessage(player, msg); //2015.08.09.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
PluginMain.LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
System.out.println("Args length: " + args.length);
|
||||||
|
if(args.length==1)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "reload":
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "playerinfo":
|
||||||
|
DoPlayerInfo(player, args);
|
||||||
|
break;
|
||||||
|
case "getlasterror":
|
||||||
|
DoGetLastError(player, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoPlayerInfo(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
//args[0] is "admin" - args[1] is "playerinfo"
|
||||||
|
if(args.length==2)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||||
|
{
|
||||||
|
String message="§cPlayer not found: "+args[2]+"§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||||
|
SendMessage(player, "Player name: "+p.PlayerName);
|
||||||
|
SendMessage(player, "User flair: "+p.Flair);
|
||||||
|
SendMessage(player, "Username: "+p.UserName);
|
||||||
|
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
||||||
|
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
||||||
|
}
|
||||||
|
private static void SendMessage(Player player, String message)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
}
|
||||||
|
private static void DoGetLastError(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
//args[0] is "admin" - args[1] is "getlasterror"
|
||||||
|
if(args.length==2)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin getlasterror <player>§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SendMessage(player, "Last error:");
|
||||||
|
SendMessage(player, PluginMain.LastException.toString());
|
||||||
|
SendMessage(player, "Stack trace:");
|
||||||
|
SendMessage(player, PluginMain.LastException.getStackTrace());
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,419 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
|
||||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
|
||||||
|
|
||||||
public class PluginMain extends JavaPlugin
|
|
||||||
{ //Translated to Java: 2015.07.15.
|
|
||||||
//A user, which flair isn't obtainable:
|
|
||||||
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
|
||||||
// Fired when plugin is first enabled
|
|
||||||
@Override
|
|
||||||
public void onEnable()
|
|
||||||
{
|
|
||||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
|
||||||
//System.out.println("Original C# version: http://pastebin.com/tX8xCPbp");
|
|
||||||
//System.out.println("The Java version is... Also made by the same person.");
|
|
||||||
//System.out.println("With the help of StackOverflow and similar.");
|
|
||||||
/*catch(MalformedURLException e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
catch(IOException e)
|
|
||||||
{
|
|
||||||
}*/
|
|
||||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
|
||||||
//System.out.println("Registering commands...");
|
|
||||||
this.getCommand("u").setExecutor(new Commands());
|
|
||||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
|
||||||
try {
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//AcceptedPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("flairsignored.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//IgnoredPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
|
||||||
String line;
|
|
||||||
while((line=br.readLine())!=null)
|
|
||||||
{
|
|
||||||
String[] s=line.split(" ");
|
|
||||||
TownColors.put(s[0], s[1]);
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//System.out.println("Registering done.");
|
|
||||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
|
||||||
Thread t=new Thread(r);
|
|
||||||
t.start();
|
|
||||||
}
|
|
||||||
Boolean stop=false;
|
|
||||||
// Fired when plugin is disabled
|
|
||||||
@Override
|
|
||||||
public void onDisable()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
FileWriter fw;
|
|
||||||
fw = new FileWriter("flairsaccepted.txt");
|
|
||||||
fw.close();
|
|
||||||
fw = new FileWriter("flairsignored.txt");
|
|
||||||
fw.close();
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//for(String player : AcceptedPlayers)
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.AcceptedFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.IgnoredFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsignored.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stop=true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ThreadMethod() //<-- 2015.07.16.
|
|
||||||
{
|
|
||||||
/*System.out.println("Sleeping for 5 seconds..."); //2015.07.20.
|
|
||||||
try {
|
|
||||||
Thread.sleep(5000);
|
|
||||||
} catch (InterruptedException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
} //2015.07.20.*/
|
|
||||||
while(!stop)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
|
||||||
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
|
||||||
for(Object obj : json)
|
|
||||||
{
|
|
||||||
JSONObject item = (JSONObject)obj;
|
|
||||||
String author=item.getJSONObject("data").getString("author");
|
|
||||||
String ign=item.getJSONObject("data").getString("body");
|
|
||||||
int start = ign.indexOf("IGN:") + "IGN:".length();
|
|
||||||
int end = ign.indexOf(' ', start);
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
end=ign.indexOf('\n', start); //2015.07.15.
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
ign = ign.substring(start);
|
|
||||||
else
|
|
||||||
ign = ign.substring(start, end);
|
|
||||||
ign = ign.trim();
|
|
||||||
if(HasIGFlair(ign))
|
|
||||||
continue;
|
|
||||||
//System.out.println("Author: "+author);
|
|
||||||
try {
|
|
||||||
Thread.sleep(10);
|
|
||||||
} catch(InterruptedException ex) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
|
||||||
String flair;
|
|
||||||
if(flairdata.length > 1) //2015.07.15.
|
|
||||||
flair = flairdata[1];
|
|
||||||
else
|
|
||||||
flair="";
|
|
||||||
if (flair != "-1")
|
|
||||||
flair = flair + "s";
|
|
||||||
else
|
|
||||||
flair = "non-presser";
|
|
||||||
String flairclass;
|
|
||||||
//System.out.println("flairdata.length:"+flairdata.length);
|
|
||||||
if(flairdata.length>2)
|
|
||||||
flairclass = flairdata[2];
|
|
||||||
else
|
|
||||||
flairclass="unknown";
|
|
||||||
SetFlair(ign, flair, flairclass, author);
|
|
||||||
}
|
|
||||||
Thread.sleep(10000);
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
|
||||||
{
|
|
||||||
URL url = new URL(urlstr);
|
|
||||||
URLConnection con = url.openConnection();
|
|
||||||
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
|
||||||
InputStream in = con.getInputStream();
|
|
||||||
String encoding = con.getContentEncoding();
|
|
||||||
encoding = encoding == null ? "UTF-8" : encoding;
|
|
||||||
String body = IOUtils.toString(in, encoding);
|
|
||||||
in.close();
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
//It has to store offline player flairs too, therefore it can't use Player object
|
|
||||||
/*public static Map<String, String> PlayerFlairs=new HashMap<String, String>();
|
|
||||||
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
|
|
||||||
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
|
|
||||||
public static ArrayList<Player> Players=new ArrayList<Player>();
|
|
||||||
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
//public static Map<String, String> PlayerTowns=new HashMap<String, String>(); //2015.07.20.*/
|
|
||||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
|
||||||
public Boolean HasIGFlair(String playername)
|
|
||||||
{
|
|
||||||
/*Player player=null;
|
|
||||||
for(Player p : Players)
|
|
||||||
{
|
|
||||||
if(p.getName()==playername)
|
|
||||||
{
|
|
||||||
player=p;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(player==null)
|
|
||||||
return false;*/
|
|
||||||
//return PlayerFlairs.containsKey(playername);
|
|
||||||
return MaybeOfflinePlayer.AllPlayers.containsKey(playername);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
|
||||||
{
|
|
||||||
String finalflair;
|
|
||||||
switch(flairclass)
|
|
||||||
{
|
|
||||||
case "press-1":
|
|
||||||
finalflair="§c("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-2":
|
|
||||||
finalflair="§6("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-3":
|
|
||||||
finalflair="§e("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-4":
|
|
||||||
finalflair="§a("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-5":
|
|
||||||
finalflair="§9("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-6":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "no-press":
|
|
||||||
finalflair="§7(non-pr.)§r";
|
|
||||||
break;
|
|
||||||
case "cheater":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "cant-press": //2015.08.08.
|
|
||||||
finalflair="§r(can't press)§r";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
finalflair="";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
|
||||||
return;
|
|
||||||
//PlayerFlairs.put(playername, finalflair);
|
|
||||||
//PlayerUserNames.put(playername, username);
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
|
||||||
p.Flair=finalflair; //2015.08.08.
|
|
||||||
p.UserName=username; //2015.08.08.
|
|
||||||
/*for(Player player : Players)
|
|
||||||
{
|
|
||||||
if(player.getName()==playername)
|
|
||||||
{
|
|
||||||
PlayerFlairs.put(player, finalflair);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
//System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass);
|
|
||||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
|
||||||
for(Player player : Players)
|
|
||||||
{
|
|
||||||
//System.out.println("Online player: "+player.getName());
|
|
||||||
//System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername));
|
|
||||||
if(player.getName().equals(playername))
|
|
||||||
{
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
//player.setDisplayName(player.getDisplayName()+finalflair);
|
|
||||||
AppendPlayerDisplayFlair(player, username, finalflair);
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetFlair(Player player)
|
|
||||||
{ //2015.07.16.
|
|
||||||
//String flair=PlayerFlairs.get(player.getName());
|
|
||||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair;
|
|
||||||
return flair==null ? "" : flair;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
|
||||||
{
|
|
||||||
//if(IgnoredPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
|
||||||
return;
|
|
||||||
//if(AcceptedPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
|
||||||
//player.setDisplayName(player.getDisplayName()+flair);
|
|
||||||
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
else
|
|
||||||
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//System.out.println("A");
|
|
||||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
|
||||||
String[] colors = color.substring(1).split("§");
|
|
||||||
//String displayname=player.getDisplayName();
|
|
||||||
String displayname=player.getName(); //2015.08.08.
|
|
||||||
ArrayList<Integer> Positions=new ArrayList<>();
|
|
||||||
//System.out.println("B");
|
|
||||||
for(int i=0; i<displayname.length(); i++) {
|
|
||||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
|
||||||
Positions.add(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//System.out.println("C: Positions.size(): "+Positions.size());
|
|
||||||
String finalname="";
|
|
||||||
if(Positions.size()>=colors.length)
|
|
||||||
{
|
|
||||||
//System.out.println("D");
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<Positions.size(); i++)
|
|
||||||
{
|
|
||||||
int pos=Positions.get(i);
|
|
||||||
int nextpos;
|
|
||||||
if(i!=Positions.size()-1)
|
|
||||||
nextpos=Positions.get(i+1);
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
//String substr="§"+colors[x++]+displayname.substring(pos, nextpos-pos)+"§r";
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("F");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//System.out.println("E");
|
|
||||||
Positions.clear();
|
|
||||||
int unit=displayname.length()/colors.length;
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
|
||||||
{
|
|
||||||
int pos=i;
|
|
||||||
int nextpos;
|
|
||||||
if(i<displayname.length()-unit-unit)
|
|
||||||
nextpos=i+unit;
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("G");
|
|
||||||
}
|
|
||||||
//player.setDisplayName(color+displayname+"§r"+flair);
|
|
||||||
//player.setDisplayName(finalname+flair);
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=finalname+flair; //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetColorForTown(String townname)
|
|
||||||
{ //2015.07.20.
|
|
||||||
if(TownColors.containsKey(townname))
|
|
||||||
return TownColors.get(townname);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetPlayerTown(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//List<Town> towns = TownyUniverse.getDataSource().getTowns();
|
|
||||||
try {
|
|
||||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown();
|
|
||||||
return town.getName();
|
|
||||||
} catch (Exception e) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
String color = GetColorForTown(GetPlayerTown(player));
|
|
||||||
String dname=player.getDisplayName();
|
|
||||||
//player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair)));
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08.
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,189 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;*/
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.*/
|
||||||
|
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||||
|
{
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return true; //2015.08.09.
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
SendMessage(player, msg); //2015.08.09.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
PluginMain.LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
System.out.println("Args length: " + args.length);
|
||||||
|
if(args.length==1)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "reload":
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "playerinfo":
|
||||||
|
DoPlayerInfo(player, args);
|
||||||
|
break;
|
||||||
|
case "getlasterror":
|
||||||
|
DoGetLastError(player, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoPlayerInfo(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
//args[0] is "admin" - args[1] is "playerinfo"
|
||||||
|
if(args.length==2)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||||
|
{
|
||||||
|
String message="§cPlayer not found: "+args[2]+"§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||||
|
SendMessage(player, "Player name: "+p.PlayerName);
|
||||||
|
SendMessage(player, "User flair: "+p.Flair);
|
||||||
|
SendMessage(player, "Username: "+p.UserName);
|
||||||
|
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
||||||
|
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
||||||
|
}
|
||||||
|
private static void SendMessage(Player player, String message)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
}
|
||||||
|
private static void DoGetLastError(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
//args[0] is "admin" - args[1] is "getlasterror"
|
||||||
|
if(PluginMain.LastException!=null)
|
||||||
|
{
|
||||||
|
SendMessage(player, "Last error:");
|
||||||
|
SendMessage(player, PluginMain.LastException.toString());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
SendMessage(player, "There were no exceptions.");
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,429 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
|
||||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
|
||||||
|
|
||||||
public class PluginMain extends JavaPlugin
|
|
||||||
{ //Translated to Java: 2015.07.15.
|
|
||||||
//A user, which flair isn't obtainable:
|
|
||||||
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
|
||||||
private static PluginMain Instance;
|
|
||||||
// Fired when plugin is first enabled
|
|
||||||
@Override
|
|
||||||
public void onEnable()
|
|
||||||
{
|
|
||||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
|
||||||
//System.out.println("Original C# version: http://pastebin.com/tX8xCPbp");
|
|
||||||
//System.out.println("The Java version is... Also made by the same person.");
|
|
||||||
//System.out.println("With the help of StackOverflow and similar.");
|
|
||||||
/*catch(MalformedURLException e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
catch(IOException e)
|
|
||||||
{
|
|
||||||
}*/
|
|
||||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
|
||||||
//System.out.println("Registering commands...");
|
|
||||||
this.getCommand("u").setExecutor(new Commands());
|
|
||||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
|
||||||
Instance=this; //2015.08.08.
|
|
||||||
try {
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//AcceptedPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("flairsignored.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//IgnoredPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
|
||||||
String line;
|
|
||||||
while((line=br.readLine())!=null)
|
|
||||||
{
|
|
||||||
String[] s=line.split(" ");
|
|
||||||
TownColors.put(s[0], s[1]);
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//System.out.println("Registering done.");
|
|
||||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
|
||||||
Thread t=new Thread(r);
|
|
||||||
t.start();
|
|
||||||
}
|
|
||||||
Boolean stop=false;
|
|
||||||
// Fired when plugin is disabled
|
|
||||||
@Override
|
|
||||||
public void onDisable()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
FileWriter fw;
|
|
||||||
fw = new FileWriter("flairsaccepted.txt");
|
|
||||||
fw.close();
|
|
||||||
fw = new FileWriter("flairsignored.txt");
|
|
||||||
fw.close();
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//for(String player : AcceptedPlayers)
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.AcceptedFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.IgnoredFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsignored.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stop=true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ThreadMethod() //<-- 2015.07.16.
|
|
||||||
{
|
|
||||||
/*System.out.println("Sleeping for 5 seconds..."); //2015.07.20.
|
|
||||||
try {
|
|
||||||
Thread.sleep(5000);
|
|
||||||
} catch (InterruptedException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
} //2015.07.20.*/
|
|
||||||
while(!stop)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
|
||||||
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
|
||||||
for(Object obj : json)
|
|
||||||
{
|
|
||||||
JSONObject item = (JSONObject)obj;
|
|
||||||
String author=item.getJSONObject("data").getString("author");
|
|
||||||
String ign=item.getJSONObject("data").getString("body");
|
|
||||||
int start = ign.indexOf("IGN:") + "IGN:".length();
|
|
||||||
int end = ign.indexOf(' ', start);
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
end=ign.indexOf('\n', start); //2015.07.15.
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
ign = ign.substring(start);
|
|
||||||
else
|
|
||||||
ign = ign.substring(start, end);
|
|
||||||
ign = ign.trim();
|
|
||||||
if(HasIGFlair(ign))
|
|
||||||
continue;
|
|
||||||
//System.out.println("Author: "+author);
|
|
||||||
try {
|
|
||||||
Thread.sleep(10);
|
|
||||||
} catch(InterruptedException ex) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
|
||||||
String flair;
|
|
||||||
if(flairdata.length > 1) //2015.07.15.
|
|
||||||
flair = flairdata[1];
|
|
||||||
else
|
|
||||||
flair="";
|
|
||||||
if (flair != "-1")
|
|
||||||
flair = flair + "s";
|
|
||||||
else
|
|
||||||
flair = "non-presser";
|
|
||||||
String flairclass;
|
|
||||||
//System.out.println("flairdata.length:"+flairdata.length);
|
|
||||||
if(flairdata.length>2)
|
|
||||||
flairclass = flairdata[2];
|
|
||||||
else
|
|
||||||
flairclass="unknown";
|
|
||||||
SetFlair(ign, flair, flairclass, author);
|
|
||||||
}
|
|
||||||
Thread.sleep(10000);
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
|
||||||
{
|
|
||||||
URL url = new URL(urlstr);
|
|
||||||
URLConnection con = url.openConnection();
|
|
||||||
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
|
||||||
InputStream in = con.getInputStream();
|
|
||||||
String encoding = con.getContentEncoding();
|
|
||||||
encoding = encoding == null ? "UTF-8" : encoding;
|
|
||||||
String body = IOUtils.toString(in, encoding);
|
|
||||||
in.close();
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
//It has to store offline player flairs too, therefore it can't use Player object
|
|
||||||
/*public static Map<String, String> PlayerFlairs=new HashMap<String, String>();
|
|
||||||
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
|
|
||||||
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
|
|
||||||
public static ArrayList<Player> Players=new ArrayList<Player>();
|
|
||||||
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
//public static Map<String, String> PlayerTowns=new HashMap<String, String>(); //2015.07.20.*/
|
|
||||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
|
||||||
public Boolean HasIGFlair(String playername)
|
|
||||||
{
|
|
||||||
/*Player player=null;
|
|
||||||
for(Player p : Players)
|
|
||||||
{
|
|
||||||
if(p.getName()==playername)
|
|
||||||
{
|
|
||||||
player=p;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(player==null)
|
|
||||||
return false;*/
|
|
||||||
//return PlayerFlairs.containsKey(playername);
|
|
||||||
//return MaybeOfflinePlayer.AllPlayers.containsKey(playername);
|
|
||||||
return MaybeOfflinePlayer.AllPlayers.get(playername).Flair!=null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
|
||||||
{
|
|
||||||
String finalflair;
|
|
||||||
switch(flairclass)
|
|
||||||
{
|
|
||||||
case "press-1":
|
|
||||||
finalflair="§c("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-2":
|
|
||||||
finalflair="§6("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-3":
|
|
||||||
finalflair="§e("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-4":
|
|
||||||
finalflair="§a("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-5":
|
|
||||||
finalflair="§9("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-6":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "no-press":
|
|
||||||
finalflair="§7(non-pr.)§r";
|
|
||||||
break;
|
|
||||||
case "cheater":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "cant-press": //2015.08.08.
|
|
||||||
finalflair="§r(can't press)§r";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
finalflair="";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
|
||||||
return;
|
|
||||||
//PlayerFlairs.put(playername, finalflair);
|
|
||||||
//PlayerUserNames.put(playername, username);
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
|
||||||
p.Flair=finalflair; //2015.08.08.
|
|
||||||
p.UserName=username; //2015.08.08.
|
|
||||||
/*for(Player player : Players)
|
|
||||||
{
|
|
||||||
if(player.getName()==playername)
|
|
||||||
{
|
|
||||||
PlayerFlairs.put(player, finalflair);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
//System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass);
|
|
||||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
|
||||||
//for(Player player : Players)
|
|
||||||
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
//System.out.println("Online player: "+player.getName());
|
|
||||||
//System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername));
|
|
||||||
if(player.getName().equals(playername))
|
|
||||||
{
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
//player.setDisplayName(player.getDisplayName()+finalflair);
|
|
||||||
AppendPlayerDisplayFlair(player, username, finalflair);
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetFlair(Player player)
|
|
||||||
{ //2015.07.16.
|
|
||||||
//String flair=PlayerFlairs.get(player.getName());
|
|
||||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
|
||||||
return flair==null ? "" : flair;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
|
||||||
{
|
|
||||||
//if(IgnoredPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
|
||||||
return;
|
|
||||||
//if(AcceptedPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
|
||||||
//player.setDisplayName(player.getDisplayName()+flair);
|
|
||||||
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
else
|
|
||||||
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//System.out.println("A");
|
|
||||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
|
||||||
String[] colors = color.substring(1).split("§");
|
|
||||||
//String displayname=player.getDisplayName();
|
|
||||||
String displayname=player.getName(); //2015.08.08.
|
|
||||||
ArrayList<Integer> Positions=new ArrayList<>();
|
|
||||||
//System.out.println("B");
|
|
||||||
for(int i=0; i<displayname.length(); i++) {
|
|
||||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
|
||||||
Positions.add(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//System.out.println("C: Positions.size(): "+Positions.size());
|
|
||||||
String finalname="";
|
|
||||||
if(Positions.size()>=colors.length)
|
|
||||||
{
|
|
||||||
//System.out.println("D");
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<Positions.size(); i++)
|
|
||||||
{
|
|
||||||
int pos=Positions.get(i);
|
|
||||||
int nextpos;
|
|
||||||
if(i!=Positions.size()-1)
|
|
||||||
nextpos=Positions.get(i+1);
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
//String substr="§"+colors[x++]+displayname.substring(pos, nextpos-pos)+"§r";
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("F");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//System.out.println("E");
|
|
||||||
Positions.clear();
|
|
||||||
int unit=displayname.length()/colors.length;
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
|
||||||
{
|
|
||||||
int pos=i;
|
|
||||||
int nextpos;
|
|
||||||
if(i<displayname.length()-unit-unit)
|
|
||||||
nextpos=i+unit;
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("G");
|
|
||||||
}
|
|
||||||
//player.setDisplayName(color+displayname+"§r"+flair);
|
|
||||||
//player.setDisplayName(finalname+flair);
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=finalname+flair; //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetColorForTown(String townname)
|
|
||||||
{ //2015.07.20.
|
|
||||||
if(TownColors.containsKey(townname))
|
|
||||||
return TownColors.get(townname);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetPlayerTown(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//List<Town> towns = TownyUniverse.getDataSource().getTowns();
|
|
||||||
try {
|
|
||||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown();
|
|
||||||
return town.getName();
|
|
||||||
} catch (Exception e) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//String color = GetColorForTown(GetPlayerTown(player));
|
|
||||||
//String dname=player.getDisplayName();
|
|
||||||
//player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair)));
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Collection<? extends Player> GetPlayers()
|
|
||||||
{
|
|
||||||
return Instance.getServer().getOnlinePlayers();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,169 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;*/
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.*/
|
||||||
|
else if(args[0].toLowerCase()=="admin")
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
SendMessage(player, msg); //2015.08.09.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
if(args.length==1)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "reload":
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "playerinfo":
|
||||||
|
DoPlayerInfo(player, args);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoPlayerInfo(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
//args[0] is "admin" - args[1] is "playerinfo"
|
||||||
|
if(args.length==2)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
}
|
||||||
|
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||||
|
{
|
||||||
|
String message="§cPlayer not found: "+args[2]+"§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
}
|
||||||
|
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||||
|
SendMessage(player, "User flair: "+p.Flair);
|
||||||
|
SendMessage(player, "Player name: "+p.PlayerName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
private static void SendMessage(Player player, String message)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.IEssentials;
|
||||||
|
|
||||||
|
public class Essentials implements IEssentials {
|
||||||
|
|
||||||
|
}
|
|
@ -1,419 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
|
||||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
|
||||||
|
|
||||||
public class PluginMain extends JavaPlugin
|
|
||||||
{ //Translated to Java: 2015.07.15.
|
|
||||||
//A user, which flair isn't obtainable:
|
|
||||||
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
|
||||||
// Fired when plugin is first enabled
|
|
||||||
@Override
|
|
||||||
public void onEnable()
|
|
||||||
{
|
|
||||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
|
||||||
//System.out.println("Original C# version: http://pastebin.com/tX8xCPbp");
|
|
||||||
//System.out.println("The Java version is... Also made by the same person.");
|
|
||||||
//System.out.println("With the help of StackOverflow and similar.");
|
|
||||||
/*catch(MalformedURLException e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
catch(IOException e)
|
|
||||||
{
|
|
||||||
}*/
|
|
||||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
|
||||||
//System.out.println("Registering commands...");
|
|
||||||
this.getCommand("u").setExecutor(new Commands());
|
|
||||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
|
||||||
try {
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//AcceptedPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("flairsignored.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//IgnoredPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
|
||||||
String line;
|
|
||||||
while((line=br.readLine())!=null)
|
|
||||||
{
|
|
||||||
String[] s=line.split(" ");
|
|
||||||
TownColors.put(s[0], s[1]);
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//System.out.println("Registering done.");
|
|
||||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
|
||||||
Thread t=new Thread(r);
|
|
||||||
t.start();
|
|
||||||
}
|
|
||||||
Boolean stop=false;
|
|
||||||
// Fired when plugin is disabled
|
|
||||||
@Override
|
|
||||||
public void onDisable()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
FileWriter fw;
|
|
||||||
fw = new FileWriter("flairsaccepted.txt");
|
|
||||||
fw.close();
|
|
||||||
fw = new FileWriter("flairsignored.txt");
|
|
||||||
fw.close();
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//for(String player : AcceptedPlayers)
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.AcceptedFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.IgnoredFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsignored.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stop=true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ThreadMethod() //<-- 2015.07.16.
|
|
||||||
{
|
|
||||||
/*System.out.println("Sleeping for 5 seconds..."); //2015.07.20.
|
|
||||||
try {
|
|
||||||
Thread.sleep(5000);
|
|
||||||
} catch (InterruptedException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
} //2015.07.20.*/
|
|
||||||
while(!stop)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
|
||||||
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
|
||||||
for(Object obj : json)
|
|
||||||
{
|
|
||||||
JSONObject item = (JSONObject)obj;
|
|
||||||
String author=item.getJSONObject("data").getString("author");
|
|
||||||
String ign=item.getJSONObject("data").getString("body");
|
|
||||||
int start = ign.indexOf("IGN:") + "IGN:".length();
|
|
||||||
int end = ign.indexOf(' ', start);
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
end=ign.indexOf('\n', start); //2015.07.15.
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
ign = ign.substring(start);
|
|
||||||
else
|
|
||||||
ign = ign.substring(start, end);
|
|
||||||
ign = ign.trim();
|
|
||||||
if(HasIGFlair(ign))
|
|
||||||
continue;
|
|
||||||
//System.out.println("Author: "+author);
|
|
||||||
try {
|
|
||||||
Thread.sleep(10);
|
|
||||||
} catch(InterruptedException ex) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
|
||||||
String flair;
|
|
||||||
if(flairdata.length > 1) //2015.07.15.
|
|
||||||
flair = flairdata[1];
|
|
||||||
else
|
|
||||||
flair="";
|
|
||||||
if (flair != "-1")
|
|
||||||
flair = flair + "s";
|
|
||||||
else
|
|
||||||
flair = "non-presser";
|
|
||||||
String flairclass;
|
|
||||||
//System.out.println("flairdata.length:"+flairdata.length);
|
|
||||||
if(flairdata.length>2)
|
|
||||||
flairclass = flairdata[2];
|
|
||||||
else
|
|
||||||
flairclass="unknown";
|
|
||||||
SetFlair(ign, flair, flairclass, author);
|
|
||||||
}
|
|
||||||
Thread.sleep(10000);
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
|
||||||
{
|
|
||||||
URL url = new URL(urlstr);
|
|
||||||
URLConnection con = url.openConnection();
|
|
||||||
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
|
||||||
InputStream in = con.getInputStream();
|
|
||||||
String encoding = con.getContentEncoding();
|
|
||||||
encoding = encoding == null ? "UTF-8" : encoding;
|
|
||||||
String body = IOUtils.toString(in, encoding);
|
|
||||||
in.close();
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
//It has to store offline player flairs too, therefore it can't use Player object
|
|
||||||
/*public static Map<String, String> PlayerFlairs=new HashMap<String, String>();
|
|
||||||
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
|
|
||||||
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
|
|
||||||
public static ArrayList<Player> Players=new ArrayList<Player>();
|
|
||||||
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
//public static Map<String, String> PlayerTowns=new HashMap<String, String>(); //2015.07.20.*/
|
|
||||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
|
||||||
public Boolean HasIGFlair(String playername)
|
|
||||||
{
|
|
||||||
/*Player player=null;
|
|
||||||
for(Player p : Players)
|
|
||||||
{
|
|
||||||
if(p.getName()==playername)
|
|
||||||
{
|
|
||||||
player=p;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(player==null)
|
|
||||||
return false;*/
|
|
||||||
//return PlayerFlairs.containsKey(playername);
|
|
||||||
return MaybeOfflinePlayer.AllPlayers.containsKey(playername);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
|
||||||
{
|
|
||||||
String finalflair;
|
|
||||||
switch(flairclass)
|
|
||||||
{
|
|
||||||
case "press-1":
|
|
||||||
finalflair="§c("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-2":
|
|
||||||
finalflair="§6("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-3":
|
|
||||||
finalflair="§e("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-4":
|
|
||||||
finalflair="§a("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-5":
|
|
||||||
finalflair="§9("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-6":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "no-press":
|
|
||||||
finalflair="§7(non-pr.)§r";
|
|
||||||
break;
|
|
||||||
case "cheater":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "cant-press": //2015.08.08.
|
|
||||||
finalflair="§r(can't press)§r";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
finalflair="";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
|
||||||
return;
|
|
||||||
//PlayerFlairs.put(playername, finalflair);
|
|
||||||
//PlayerUserNames.put(playername, username);
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
|
||||||
p.Flair=finalflair; //2015.08.08.
|
|
||||||
p.UserName=username; //2015.08.08.
|
|
||||||
/*for(Player player : Players)
|
|
||||||
{
|
|
||||||
if(player.getName()==playername)
|
|
||||||
{
|
|
||||||
PlayerFlairs.put(player, finalflair);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
//System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass);
|
|
||||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
|
||||||
for(Player player : Players)
|
|
||||||
{
|
|
||||||
//System.out.println("Online player: "+player.getName());
|
|
||||||
//System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername));
|
|
||||||
if(player.getName().equals(playername))
|
|
||||||
{
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
//player.setDisplayName(player.getDisplayName()+finalflair);
|
|
||||||
AppendPlayerDisplayFlair(player, username, finalflair);
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetFlair(Player player)
|
|
||||||
{ //2015.07.16.
|
|
||||||
//String flair=PlayerFlairs.get(player.getName());
|
|
||||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName());
|
|
||||||
return flair==null ? "" : flair;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
|
||||||
{
|
|
||||||
//if(IgnoredPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
|
||||||
return;
|
|
||||||
//if(AcceptedPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
|
||||||
//player.setDisplayName(player.getDisplayName()+flair);
|
|
||||||
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
else
|
|
||||||
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//System.out.println("A");
|
|
||||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
|
||||||
String[] colors = color.substring(1).split("§");
|
|
||||||
//String displayname=player.getDisplayName();
|
|
||||||
String displayname=player.getName(); //2015.08.08.
|
|
||||||
ArrayList<Integer> Positions=new ArrayList<>();
|
|
||||||
//System.out.println("B");
|
|
||||||
for(int i=0; i<displayname.length(); i++) {
|
|
||||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
|
||||||
Positions.add(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//System.out.println("C: Positions.size(): "+Positions.size());
|
|
||||||
String finalname="";
|
|
||||||
if(Positions.size()>=colors.length)
|
|
||||||
{
|
|
||||||
//System.out.println("D");
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<Positions.size(); i++)
|
|
||||||
{
|
|
||||||
int pos=Positions.get(i);
|
|
||||||
int nextpos;
|
|
||||||
if(i!=Positions.size()-1)
|
|
||||||
nextpos=Positions.get(i+1);
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
//String substr="§"+colors[x++]+displayname.substring(pos, nextpos-pos)+"§r";
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("F");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//System.out.println("E");
|
|
||||||
Positions.clear();
|
|
||||||
int unit=displayname.length()/colors.length;
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
|
||||||
{
|
|
||||||
int pos=i;
|
|
||||||
int nextpos;
|
|
||||||
if(i<displayname.length()-unit-unit)
|
|
||||||
nextpos=i+unit;
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("G");
|
|
||||||
}
|
|
||||||
//player.setDisplayName(color+displayname+"§r"+flair);
|
|
||||||
//player.setDisplayName(finalname+flair);
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=finalname+flair; //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetColorForTown(String townname)
|
|
||||||
{ //2015.07.20.
|
|
||||||
if(TownColors.containsKey(townname))
|
|
||||||
return TownColors.get(townname);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetPlayerTown(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//List<Town> towns = TownyUniverse.getDataSource().getTowns();
|
|
||||||
try {
|
|
||||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown();
|
|
||||||
return town.getName();
|
|
||||||
} catch (Exception e) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
String color = GetColorForTown(GetPlayerTown(player));
|
|
||||||
String dname=player.getDisplayName();
|
|
||||||
//player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair)));
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08.
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -22,6 +22,7 @@ import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||||
|
|
||||||
public class PluginMain extends JavaPlugin
|
public class PluginMain extends JavaPlugin
|
||||||
|
@ -34,17 +35,7 @@ public class PluginMain extends JavaPlugin
|
||||||
public void onEnable()
|
public void onEnable()
|
||||||
{
|
{
|
||||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||||
//System.out.println("Original C# version: http://pastebin.com/tX8xCPbp");
|
|
||||||
//System.out.println("The Java version is... Also made by the same person.");
|
|
||||||
//System.out.println("With the help of StackOverflow and similar.");
|
|
||||||
/*catch(MalformedURLException e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
catch(IOException e)
|
|
||||||
{
|
|
||||||
}*/
|
|
||||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||||
//System.out.println("Registering commands...");
|
|
||||||
this.getCommand("u").setExecutor(new Commands());
|
this.getCommand("u").setExecutor(new Commands());
|
||||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||||
Instance=this; //2015.08.08.
|
Instance=this; //2015.08.08.
|
||||||
|
@ -121,7 +112,7 @@ public class PluginMain extends JavaPlugin
|
||||||
File file=new File("flairsaccepted.txt");
|
File file=new File("flairsaccepted.txt");
|
||||||
try {
|
try {
|
||||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||||
bw.write(player+"\n");
|
bw.write(player.PlayerName+"\n");
|
||||||
bw.close();
|
bw.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("Error!\n"+e);
|
System.out.println("Error!\n"+e);
|
||||||
|
@ -134,7 +125,7 @@ public class PluginMain extends JavaPlugin
|
||||||
File file=new File("flairsignored.txt");
|
File file=new File("flairsignored.txt");
|
||||||
try {
|
try {
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
||||||
bw.write(player+"\n");
|
bw.write(player.PlayerName+"\n");
|
||||||
bw.close();
|
bw.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("Error!\n"+e);
|
System.out.println("Error!\n"+e);
|
||||||
|
@ -395,7 +386,8 @@ public class PluginMain extends JavaPlugin
|
||||||
}
|
}
|
||||||
//player.setDisplayName(color+displayname+"§r"+flair);
|
//player.setDisplayName(color+displayname+"§r"+flair);
|
||||||
//player.setDisplayName(finalname+flair);
|
//player.setDisplayName(finalname+flair);
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=finalname+flair; //2015.08.08.
|
//MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=finalname+flair; //2015.08.08.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String GetColorForTown(String townname)
|
public static String GetColorForTown(String townname)
|
||||||
|
@ -409,7 +401,7 @@ public class PluginMain extends JavaPlugin
|
||||||
{ //2015.07.20.
|
{ //2015.07.20.
|
||||||
//List<Town> towns = TownyUniverse.getDataSource().getTowns();
|
//List<Town> towns = TownyUniverse.getDataSource().getTowns();
|
||||||
try {
|
try {
|
||||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown();
|
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||||
return town.getName();
|
return town.getName();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return "";
|
return "";
|
||||||
|
@ -421,7 +413,8 @@ public class PluginMain extends JavaPlugin
|
||||||
//String color = GetColorForTown(GetPlayerTown(player));
|
//String color = GetColorForTown(GetPlayerTown(player));
|
||||||
//String dname=player.getDisplayName();
|
//String dname=player.getDisplayName();
|
||||||
//player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair)));
|
//player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair)));
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08.
|
//MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Collection<? extends Player> GetPlayers()
|
public static Collection<? extends Player> GetPlayers()
|
|
@ -0,0 +1,422 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||||
|
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||||
|
|
||||||
|
public class PluginMain extends JavaPlugin
|
||||||
|
{ //Translated to Java: 2015.07.15.
|
||||||
|
//A user, which flair isn't obtainable:
|
||||||
|
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
||||||
|
private static PluginMain Instance;
|
||||||
|
// Fired when plugin is first enabled
|
||||||
|
@Override
|
||||||
|
public void onEnable()
|
||||||
|
{
|
||||||
|
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||||
|
this.getCommand("u").setExecutor(new Commands());
|
||||||
|
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||||
|
Instance=this; //2015.08.08.
|
||||||
|
try {
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
System.out.println("Name: " + name);
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("flairsignored.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
//System.out.println("Registering done.");
|
||||||
|
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||||
|
Thread t=new Thread(r);
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
Boolean stop=false;
|
||||||
|
// Fired when plugin is disabled
|
||||||
|
@Override
|
||||||
|
public void onDisable()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileWriter fw;
|
||||||
|
fw = new FileWriter("flairsaccepted.txt");
|
||||||
|
fw.close();
|
||||||
|
fw = new FileWriter("flairsignored.txt");
|
||||||
|
fw.close();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
//for(String player : AcceptedPlayers)
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.AcceptedFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
try {
|
||||||
|
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.IgnoredFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
File file=new File("flairsignored.txt");
|
||||||
|
try {
|
||||||
|
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stop=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ThreadMethod() //<-- 2015.07.16.
|
||||||
|
{
|
||||||
|
/*System.out.println("Sleeping for 5 seconds..."); //2015.07.20.
|
||||||
|
try {
|
||||||
|
Thread.sleep(5000);
|
||||||
|
} catch (InterruptedException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
} //2015.07.20.*/
|
||||||
|
while(!stop)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
||||||
|
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
||||||
|
for(Object obj : json)
|
||||||
|
{
|
||||||
|
JSONObject item = (JSONObject)obj;
|
||||||
|
String author=item.getJSONObject("data").getString("author");
|
||||||
|
String ign=item.getJSONObject("data").getString("body");
|
||||||
|
int start = ign.indexOf("IGN:") + "IGN:".length();
|
||||||
|
int end = ign.indexOf(' ', start);
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
end=ign.indexOf('\n', start); //2015.07.15.
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
ign = ign.substring(start);
|
||||||
|
else
|
||||||
|
ign = ign.substring(start, end);
|
||||||
|
ign = ign.trim();
|
||||||
|
if(HasIGFlair(ign))
|
||||||
|
continue;
|
||||||
|
//System.out.println("Author: "+author);
|
||||||
|
try {
|
||||||
|
Thread.sleep(10);
|
||||||
|
} catch(InterruptedException ex) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
||||||
|
String flair;
|
||||||
|
if(flairdata.length > 1) //2015.07.15.
|
||||||
|
flair = flairdata[1];
|
||||||
|
else
|
||||||
|
flair="";
|
||||||
|
if (flair != "-1")
|
||||||
|
flair = flair + "s";
|
||||||
|
else
|
||||||
|
flair = "non-presser";
|
||||||
|
String flairclass;
|
||||||
|
//System.out.println("flairdata.length:"+flairdata.length);
|
||||||
|
if(flairdata.length>2)
|
||||||
|
flairclass = flairdata[2];
|
||||||
|
else
|
||||||
|
flairclass="unknown";
|
||||||
|
SetFlair(ign, flair, flairclass, author);
|
||||||
|
}
|
||||||
|
Thread.sleep(10000);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
||||||
|
{
|
||||||
|
URL url = new URL(urlstr);
|
||||||
|
URLConnection con = url.openConnection();
|
||||||
|
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
||||||
|
InputStream in = con.getInputStream();
|
||||||
|
String encoding = con.getContentEncoding();
|
||||||
|
encoding = encoding == null ? "UTF-8" : encoding;
|
||||||
|
String body = IOUtils.toString(in, encoding);
|
||||||
|
in.close();
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
//It has to store offline player flairs too, therefore it can't use Player object
|
||||||
|
/*public static Map<String, String> PlayerFlairs=new HashMap<String, String>();
|
||||||
|
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
|
||||||
|
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
|
||||||
|
public static ArrayList<Player> Players=new ArrayList<Player>();
|
||||||
|
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
|
||||||
|
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //2015.07.16.
|
||||||
|
//public static Map<String, String> PlayerTowns=new HashMap<String, String>(); //2015.07.20.*/
|
||||||
|
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||||
|
public Boolean HasIGFlair(String playername)
|
||||||
|
{
|
||||||
|
/*Player player=null;
|
||||||
|
for(Player p : Players)
|
||||||
|
{
|
||||||
|
if(p.getName()==playername)
|
||||||
|
{
|
||||||
|
player=p;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(player==null)
|
||||||
|
return false;*/
|
||||||
|
//return PlayerFlairs.containsKey(playername);
|
||||||
|
//return MaybeOfflinePlayer.AllPlayers.containsKey(playername);
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
return p.Flair!=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||||
|
{
|
||||||
|
String finalflair;
|
||||||
|
switch(flairclass)
|
||||||
|
{
|
||||||
|
case "press-1":
|
||||||
|
finalflair="§c("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-2":
|
||||||
|
finalflair="§6("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-3":
|
||||||
|
finalflair="§e("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-4":
|
||||||
|
finalflair="§a("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-5":
|
||||||
|
finalflair="§9("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-6":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "no-press":
|
||||||
|
finalflair="§7(non-pr.)§r";
|
||||||
|
break;
|
||||||
|
case "cheater":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "cant-press": //2015.08.08.
|
||||||
|
finalflair="§r(can't press)§r";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
finalflair="";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||||
|
return;
|
||||||
|
//PlayerFlairs.put(playername, finalflair);
|
||||||
|
//PlayerUserNames.put(playername, username);
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
p.Flair=finalflair; //2015.08.08.
|
||||||
|
p.UserName=username; //2015.08.08.
|
||||||
|
/*for(Player player : Players)
|
||||||
|
{
|
||||||
|
if(player.getName()==playername)
|
||||||
|
{
|
||||||
|
PlayerFlairs.put(player, finalflair);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
//System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass);
|
||||||
|
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||||
|
//for(Player player : Players)
|
||||||
|
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
//System.out.println("Online player: "+player.getName());
|
||||||
|
//System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername));
|
||||||
|
if(player.getName().equals(playername))
|
||||||
|
{
|
||||||
|
//System.out.println("DisplayName: "+player.getDisplayName());
|
||||||
|
//player.setDisplayName(player.getDisplayName()+finalflair);
|
||||||
|
AppendPlayerDisplayFlair(player, username, finalflair);
|
||||||
|
//System.out.println("DisplayName: "+player.getDisplayName());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetFlair(Player player)
|
||||||
|
{ //2015.07.16.
|
||||||
|
//String flair=PlayerFlairs.get(player.getName());
|
||||||
|
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||||
|
return flair==null ? "" : flair;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||||
|
{
|
||||||
|
//if(IgnoredPlayers.contains(player.getName()))
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
||||||
|
return;
|
||||||
|
//if(AcceptedPlayers.contains(player.getName()))
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
||||||
|
//player.setDisplayName(player.getDisplayName()+flair);
|
||||||
|
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
else
|
||||||
|
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//System.out.println("A");
|
||||||
|
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||||
|
String[] colors = color.substring(1).split("§");
|
||||||
|
//String displayname=player.getDisplayName();
|
||||||
|
String displayname=player.getName(); //2015.08.08.
|
||||||
|
ArrayList<Integer> Positions=new ArrayList<>();
|
||||||
|
//System.out.println("B");
|
||||||
|
for(int i=0; i<displayname.length(); i++) {
|
||||||
|
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||||
|
Positions.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//System.out.println("C: Positions.size(): "+Positions.size());
|
||||||
|
String finalname="";
|
||||||
|
if(Positions.size()>=colors.length)
|
||||||
|
{
|
||||||
|
//System.out.println("D");
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<Positions.size(); i++)
|
||||||
|
{
|
||||||
|
int pos=Positions.get(i);
|
||||||
|
int nextpos;
|
||||||
|
if(i!=Positions.size()-1)
|
||||||
|
nextpos=Positions.get(i+1);
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
||||||
|
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
||||||
|
//String substr="§"+colors[x++]+displayname.substring(pos, nextpos-pos)+"§r";
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
//System.out.println("F");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//System.out.println("E");
|
||||||
|
Positions.clear();
|
||||||
|
int unit=displayname.length()/colors.length;
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||||
|
{
|
||||||
|
int pos=i;
|
||||||
|
int nextpos;
|
||||||
|
if(i<displayname.length()-unit-unit)
|
||||||
|
nextpos=i+unit;
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
||||||
|
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
//System.out.println("G");
|
||||||
|
}
|
||||||
|
//player.setDisplayName(color+displayname+"§r"+flair);
|
||||||
|
//player.setDisplayName(finalname+flair);
|
||||||
|
//MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=finalname+flair; //2015.08.08.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetColorForTown(String townname)
|
||||||
|
{ //2015.07.20.
|
||||||
|
if(TownColors.containsKey(townname))
|
||||||
|
return TownColors.get(townname);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetPlayerTown(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//List<Town> towns = TownyUniverse.getDataSource().getTowns();
|
||||||
|
try {
|
||||||
|
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||||
|
return town.getName();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//String color = GetColorForTown(GetPlayerTown(player));
|
||||||
|
//String dname=player.getDisplayName();
|
||||||
|
//player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair)));
|
||||||
|
//MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<? extends Player> GetPlayers()
|
||||||
|
{
|
||||||
|
return Instance.getServer().getOnlinePlayers();
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,8 +18,11 @@ public class PlayerListener implements Listener
|
||||||
//PluginMain.Players.add(p);
|
//PluginMain.Players.add(p);
|
||||||
//event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p));
|
//event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p));
|
||||||
//if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20.
|
//if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20.
|
||||||
//PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p));
|
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
||||||
if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08.
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
//PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p));
|
||||||
|
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
||||||
else
|
else
|
||||||
{ //2015.07.20.
|
{ //2015.07.20.
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
||||||
|
@ -49,7 +52,10 @@ public class PlayerListener implements Listener
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
public void onPlayerChat(AsyncPlayerChatEvent event)
|
||||||
{
|
{
|
||||||
//event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+"(test)> "+event.getMessage()); //2015.08.08.
|
//event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+"(test)> "+event.getMessage()); //2015.08.08.
|
||||||
String name;
|
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
||||||
|
String flair=player.Flair; //2015.08.08.
|
||||||
|
if(flair==null || !player.AcceptedFlair)
|
||||||
|
flair=""; //2015.08.08.
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08.
|
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08.
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,348 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||||
|
|
||||||
|
public class PluginMain extends JavaPlugin
|
||||||
|
{ //Translated to Java: 2015.07.15.
|
||||||
|
//A user, which flair isn't obtainable:
|
||||||
|
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
||||||
|
private static PluginMain Instance;
|
||||||
|
// Fired when plugin is first enabled
|
||||||
|
@Override
|
||||||
|
public void onEnable()
|
||||||
|
{
|
||||||
|
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||||
|
this.getCommand("u").setExecutor(new Commands());
|
||||||
|
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||||
|
Instance=this; //2015.08.08.
|
||||||
|
try {
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
//System.out.println("Name: " + name);
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("flairsignored.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||||
|
Thread t=new Thread(r);
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
Boolean stop=false;
|
||||||
|
// Fired when plugin is disabled
|
||||||
|
@Override
|
||||||
|
public void onDisable()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileWriter fw;
|
||||||
|
fw = new FileWriter("flairsaccepted.txt");
|
||||||
|
fw.close();
|
||||||
|
fw = new FileWriter("flairsignored.txt");
|
||||||
|
fw.close();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.AcceptedFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
bw.close();
|
||||||
|
}
|
||||||
|
file=new File("flairsignored.txt");
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.IgnoredFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
try {
|
||||||
|
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
stop=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ThreadMethod() //<-- 2015.07.16.
|
||||||
|
{
|
||||||
|
while(!stop)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
||||||
|
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
||||||
|
for(Object obj : json)
|
||||||
|
{
|
||||||
|
JSONObject item = (JSONObject)obj;
|
||||||
|
String author=item.getJSONObject("data").getString("author");
|
||||||
|
String ign=item.getJSONObject("data").getString("body");
|
||||||
|
int start = ign.indexOf("IGN:") + "IGN:".length();
|
||||||
|
int end = ign.indexOf(' ', start);
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
end=ign.indexOf('\n', start); //2015.07.15.
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
ign = ign.substring(start);
|
||||||
|
else
|
||||||
|
ign = ign.substring(start, end);
|
||||||
|
ign = ign.trim();
|
||||||
|
if(HasIGFlair(ign))
|
||||||
|
continue;
|
||||||
|
try {
|
||||||
|
Thread.sleep(10);
|
||||||
|
} catch(InterruptedException ex) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
||||||
|
String flair;
|
||||||
|
if(flairdata.length > 1) //2015.07.15.
|
||||||
|
flair = flairdata[1];
|
||||||
|
else
|
||||||
|
flair="";
|
||||||
|
if (flair != "-1")
|
||||||
|
flair = flair + "s";
|
||||||
|
else
|
||||||
|
flair = "non-presser";
|
||||||
|
String flairclass;
|
||||||
|
if(flairdata.length>2)
|
||||||
|
flairclass = flairdata[2];
|
||||||
|
else
|
||||||
|
flairclass="unknown";
|
||||||
|
SetFlair(ign, flair, flairclass, author);
|
||||||
|
}
|
||||||
|
Thread.sleep(10000);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
||||||
|
{
|
||||||
|
URL url = new URL(urlstr);
|
||||||
|
URLConnection con = url.openConnection();
|
||||||
|
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
||||||
|
InputStream in = con.getInputStream();
|
||||||
|
String encoding = con.getContentEncoding();
|
||||||
|
encoding = encoding == null ? "UTF-8" : encoding;
|
||||||
|
String body = IOUtils.toString(in, encoding);
|
||||||
|
in.close();
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||||
|
public Boolean HasIGFlair(String playername)
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
return p.Flair!=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||||
|
{
|
||||||
|
String finalflair;
|
||||||
|
switch(flairclass)
|
||||||
|
{
|
||||||
|
case "press-1":
|
||||||
|
finalflair="§c("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-2":
|
||||||
|
finalflair="§6("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-3":
|
||||||
|
finalflair="§e("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-4":
|
||||||
|
finalflair="§a("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-5":
|
||||||
|
finalflair="§9("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-6":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "no-press":
|
||||||
|
finalflair="§7(non-pr.)§r";
|
||||||
|
break;
|
||||||
|
case "cheater":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "cant-press": //2015.08.08.
|
||||||
|
finalflair="§r(can't press)§r";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
finalflair="";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||||
|
return;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
p.Flair=finalflair; //2015.08.08.
|
||||||
|
p.UserName=username; //2015.08.08.
|
||||||
|
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||||
|
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(player.getName().equals(playername))
|
||||||
|
{
|
||||||
|
AppendPlayerDisplayFlair(player, username, finalflair);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetFlair(Player player)
|
||||||
|
{ //2015.07.16.
|
||||||
|
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||||
|
return flair==null ? "" : flair;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||||
|
{
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
||||||
|
return;
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
||||||
|
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
else
|
||||||
|
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||||
|
String[] colors = color.substring(1).split("§");
|
||||||
|
String displayname=player.getName(); //2015.08.08.
|
||||||
|
ArrayList<Integer> Positions=new ArrayList<>();
|
||||||
|
for(int i=0; i<displayname.length(); i++) {
|
||||||
|
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||||
|
Positions.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String finalname=""; //TODO
|
||||||
|
if(Positions.size()>=colors.length)
|
||||||
|
{
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<Positions.size(); i++)
|
||||||
|
{
|
||||||
|
int pos=Positions.get(i);
|
||||||
|
int nextpos;
|
||||||
|
if(i!=Positions.size()-1)
|
||||||
|
nextpos=Positions.get(i+1);
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Positions.clear();
|
||||||
|
int unit=displayname.length()/colors.length;
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||||
|
{
|
||||||
|
int pos=i;
|
||||||
|
int nextpos;
|
||||||
|
if(i<displayname.length()-unit-unit)
|
||||||
|
nextpos=i+unit;
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetColorForTown(String townname)
|
||||||
|
{ //2015.07.20.
|
||||||
|
if(TownColors.containsKey(townname))
|
||||||
|
return TownColors.get(townname);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetPlayerTown(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
try {
|
||||||
|
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||||
|
return town.getName();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<? extends Player> GetPlayers()
|
||||||
|
{
|
||||||
|
return Instance.getServer().getOnlinePlayers();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,352 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||||
|
|
||||||
|
public class PluginMain extends JavaPlugin
|
||||||
|
{ //Translated to Java: 2015.07.15.
|
||||||
|
//A user, which flair isn't obtainable:
|
||||||
|
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
||||||
|
private static PluginMain Instance;
|
||||||
|
// Fired when plugin is first enabled
|
||||||
|
@Override
|
||||||
|
public void onEnable()
|
||||||
|
{
|
||||||
|
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||||
|
this.getCommand("u").setExecutor(new Commands());
|
||||||
|
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||||
|
Instance=this; //2015.08.08.
|
||||||
|
try {
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
//System.out.println("Name: " + name);
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("flairsignored.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
throw new IOException("Test"); //2015.08.09.
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||||
|
Thread t=new Thread(r);
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
Boolean stop=false;
|
||||||
|
// Fired when plugin is disabled
|
||||||
|
@Override
|
||||||
|
public void onDisable()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileWriter fw;
|
||||||
|
fw = new FileWriter("flairsaccepted.txt");
|
||||||
|
fw.close();
|
||||||
|
fw = new FileWriter("flairsignored.txt");
|
||||||
|
fw.close();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.AcceptedFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
}
|
||||||
|
bw.close();
|
||||||
|
file=new File("flairsignored.txt");
|
||||||
|
bw = new BufferedWriter(new FileWriter(file, true));
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.IgnoredFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
}
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
stop=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ThreadMethod() //<-- 2015.07.16.
|
||||||
|
{
|
||||||
|
while(!stop)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
||||||
|
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
||||||
|
for(Object obj : json)
|
||||||
|
{
|
||||||
|
JSONObject item = (JSONObject)obj;
|
||||||
|
String author=item.getJSONObject("data").getString("author");
|
||||||
|
String ign=item.getJSONObject("data").getString("body");
|
||||||
|
int start = ign.indexOf("IGN:") + "IGN:".length();
|
||||||
|
int end = ign.indexOf(' ', start);
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
end=ign.indexOf('\n', start); //2015.07.15.
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
ign = ign.substring(start);
|
||||||
|
else
|
||||||
|
ign = ign.substring(start, end);
|
||||||
|
ign = ign.trim();
|
||||||
|
if(HasIGFlair(ign))
|
||||||
|
continue;
|
||||||
|
try {
|
||||||
|
Thread.sleep(10);
|
||||||
|
} catch(InterruptedException ex) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
||||||
|
String flair;
|
||||||
|
if(flairdata.length > 1) //2015.07.15.
|
||||||
|
flair = flairdata[1];
|
||||||
|
else
|
||||||
|
flair="";
|
||||||
|
if (flair != "-1")
|
||||||
|
flair = flair + "s";
|
||||||
|
else
|
||||||
|
flair = "non-presser";
|
||||||
|
String flairclass;
|
||||||
|
if(flairdata.length>2)
|
||||||
|
flairclass = flairdata[2];
|
||||||
|
else
|
||||||
|
flairclass="unknown";
|
||||||
|
SetFlair(ign, flair, flairclass, author);
|
||||||
|
}
|
||||||
|
Thread.sleep(10000);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Exception LastException; //2015.08.09.
|
||||||
|
public static int LastExceptionTime; //2015.08.09.
|
||||||
|
|
||||||
|
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
||||||
|
{
|
||||||
|
URL url = new URL(urlstr);
|
||||||
|
URLConnection con = url.openConnection();
|
||||||
|
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
||||||
|
InputStream in = con.getInputStream();
|
||||||
|
String encoding = con.getContentEncoding();
|
||||||
|
encoding = encoding == null ? "UTF-8" : encoding;
|
||||||
|
String body = IOUtils.toString(in, encoding);
|
||||||
|
in.close();
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||||
|
public Boolean HasIGFlair(String playername)
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
return p.Flair!=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||||
|
{
|
||||||
|
String finalflair;
|
||||||
|
switch(flairclass)
|
||||||
|
{
|
||||||
|
case "press-1":
|
||||||
|
finalflair="§c("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-2":
|
||||||
|
finalflair="§6("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-3":
|
||||||
|
finalflair="§e("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-4":
|
||||||
|
finalflair="§a("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-5":
|
||||||
|
finalflair="§9("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-6":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "no-press":
|
||||||
|
finalflair="§7(non-pr.)§r";
|
||||||
|
break;
|
||||||
|
case "cheater":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "cant-press": //2015.08.08.
|
||||||
|
finalflair="§r(can't press)§r";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
finalflair="";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||||
|
return;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
p.Flair=finalflair; //2015.08.08.
|
||||||
|
p.UserName=username; //2015.08.08.
|
||||||
|
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||||
|
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(player.getName().equals(playername))
|
||||||
|
{
|
||||||
|
AppendPlayerDisplayFlair(player, username, finalflair);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetFlair(Player player)
|
||||||
|
{ //2015.07.16.
|
||||||
|
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||||
|
return flair==null ? "" : flair;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||||
|
{
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
||||||
|
return;
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
||||||
|
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
else
|
||||||
|
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||||
|
String[] colors = color.substring(1).split("§");
|
||||||
|
String displayname=player.getName(); //2015.08.08.
|
||||||
|
ArrayList<Integer> Positions=new ArrayList<>();
|
||||||
|
for(int i=0; i<displayname.length(); i++) {
|
||||||
|
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||||
|
Positions.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String finalname=""; //TODO
|
||||||
|
if(Positions.size()>=colors.length)
|
||||||
|
{
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<Positions.size(); i++)
|
||||||
|
{
|
||||||
|
int pos=Positions.get(i);
|
||||||
|
int nextpos;
|
||||||
|
if(i!=Positions.size()-1)
|
||||||
|
nextpos=Positions.get(i+1);
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Positions.clear();
|
||||||
|
int unit=displayname.length()/colors.length;
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||||
|
{
|
||||||
|
int pos=i;
|
||||||
|
int nextpos;
|
||||||
|
if(i<displayname.length()-unit-unit)
|
||||||
|
nextpos=i+unit;
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetColorForTown(String townname)
|
||||||
|
{ //2015.07.20.
|
||||||
|
if(TownColors.containsKey(townname))
|
||||||
|
return TownColors.get(townname);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetPlayerTown(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
try {
|
||||||
|
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||||
|
return town.getName();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<? extends Player> GetPlayers()
|
||||||
|
{
|
||||||
|
return Instance.getServer().getOnlinePlayers();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,421 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||||
|
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||||
|
|
||||||
|
public class PluginMain extends JavaPlugin
|
||||||
|
{ //Translated to Java: 2015.07.15.
|
||||||
|
//A user, which flair isn't obtainable:
|
||||||
|
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
||||||
|
private static PluginMain Instance;
|
||||||
|
// Fired when plugin is first enabled
|
||||||
|
@Override
|
||||||
|
public void onEnable()
|
||||||
|
{
|
||||||
|
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||||
|
this.getCommand("u").setExecutor(new Commands());
|
||||||
|
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||||
|
Instance=this; //2015.08.08.
|
||||||
|
try {
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
System.out.println("Name: " + name);
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("flairsignored.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||||
|
Thread t=new Thread(r);
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
Boolean stop=false;
|
||||||
|
// Fired when plugin is disabled
|
||||||
|
@Override
|
||||||
|
public void onDisable()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileWriter fw;
|
||||||
|
fw = new FileWriter("flairsaccepted.txt");
|
||||||
|
fw.close();
|
||||||
|
fw = new FileWriter("flairsignored.txt");
|
||||||
|
fw.close();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
//for(String player : AcceptedPlayers)
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.AcceptedFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
try {
|
||||||
|
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.IgnoredFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
File file=new File("flairsignored.txt");
|
||||||
|
try {
|
||||||
|
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stop=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ThreadMethod() //<-- 2015.07.16.
|
||||||
|
{
|
||||||
|
/*System.out.println("Sleeping for 5 seconds..."); //2015.07.20.
|
||||||
|
try {
|
||||||
|
Thread.sleep(5000);
|
||||||
|
} catch (InterruptedException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
} //2015.07.20.*/
|
||||||
|
while(!stop)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
||||||
|
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
||||||
|
for(Object obj : json)
|
||||||
|
{
|
||||||
|
JSONObject item = (JSONObject)obj;
|
||||||
|
String author=item.getJSONObject("data").getString("author");
|
||||||
|
String ign=item.getJSONObject("data").getString("body");
|
||||||
|
int start = ign.indexOf("IGN:") + "IGN:".length();
|
||||||
|
int end = ign.indexOf(' ', start);
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
end=ign.indexOf('\n', start); //2015.07.15.
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
ign = ign.substring(start);
|
||||||
|
else
|
||||||
|
ign = ign.substring(start, end);
|
||||||
|
ign = ign.trim();
|
||||||
|
if(HasIGFlair(ign))
|
||||||
|
continue;
|
||||||
|
//System.out.println("Author: "+author);
|
||||||
|
try {
|
||||||
|
Thread.sleep(10);
|
||||||
|
} catch(InterruptedException ex) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
||||||
|
String flair;
|
||||||
|
if(flairdata.length > 1) //2015.07.15.
|
||||||
|
flair = flairdata[1];
|
||||||
|
else
|
||||||
|
flair="";
|
||||||
|
if (flair != "-1")
|
||||||
|
flair = flair + "s";
|
||||||
|
else
|
||||||
|
flair = "non-presser";
|
||||||
|
String flairclass;
|
||||||
|
//System.out.println("flairdata.length:"+flairdata.length);
|
||||||
|
if(flairdata.length>2)
|
||||||
|
flairclass = flairdata[2];
|
||||||
|
else
|
||||||
|
flairclass="unknown";
|
||||||
|
SetFlair(ign, flair, flairclass, author);
|
||||||
|
}
|
||||||
|
Thread.sleep(10000);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
||||||
|
{
|
||||||
|
URL url = new URL(urlstr);
|
||||||
|
URLConnection con = url.openConnection();
|
||||||
|
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
||||||
|
InputStream in = con.getInputStream();
|
||||||
|
String encoding = con.getContentEncoding();
|
||||||
|
encoding = encoding == null ? "UTF-8" : encoding;
|
||||||
|
String body = IOUtils.toString(in, encoding);
|
||||||
|
in.close();
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
//It has to store offline player flairs too, therefore it can't use Player object
|
||||||
|
/*public static Map<String, String> PlayerFlairs=new HashMap<String, String>();
|
||||||
|
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
|
||||||
|
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
|
||||||
|
public static ArrayList<Player> Players=new ArrayList<Player>();
|
||||||
|
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
|
||||||
|
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //2015.07.16.
|
||||||
|
//public static Map<String, String> PlayerTowns=new HashMap<String, String>(); //2015.07.20.*/
|
||||||
|
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||||
|
public Boolean HasIGFlair(String playername)
|
||||||
|
{
|
||||||
|
/*Player player=null;
|
||||||
|
for(Player p : Players)
|
||||||
|
{
|
||||||
|
if(p.getName()==playername)
|
||||||
|
{
|
||||||
|
player=p;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(player==null)
|
||||||
|
return false;*/
|
||||||
|
//return PlayerFlairs.containsKey(playername);
|
||||||
|
//return MaybeOfflinePlayer.AllPlayers.containsKey(playername);
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
return p.Flair!=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||||
|
{
|
||||||
|
String finalflair;
|
||||||
|
switch(flairclass)
|
||||||
|
{
|
||||||
|
case "press-1":
|
||||||
|
finalflair="§c("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-2":
|
||||||
|
finalflair="§6("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-3":
|
||||||
|
finalflair="§e("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-4":
|
||||||
|
finalflair="§a("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-5":
|
||||||
|
finalflair="§9("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-6":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "no-press":
|
||||||
|
finalflair="§7(non-pr.)§r";
|
||||||
|
break;
|
||||||
|
case "cheater":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "cant-press": //2015.08.08.
|
||||||
|
finalflair="§r(can't press)§r";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
finalflair="";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||||
|
return;
|
||||||
|
//PlayerFlairs.put(playername, finalflair);
|
||||||
|
//PlayerUserNames.put(playername, username);
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
p.Flair=finalflair; //2015.08.08.
|
||||||
|
p.UserName=username; //2015.08.08.
|
||||||
|
/*for(Player player : Players)
|
||||||
|
{
|
||||||
|
if(player.getName()==playername)
|
||||||
|
{
|
||||||
|
PlayerFlairs.put(player, finalflair);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
//System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass);
|
||||||
|
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||||
|
//for(Player player : Players)
|
||||||
|
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
//System.out.println("Online player: "+player.getName());
|
||||||
|
//System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername));
|
||||||
|
if(player.getName().equals(playername))
|
||||||
|
{
|
||||||
|
//System.out.println("DisplayName: "+player.getDisplayName());
|
||||||
|
//player.setDisplayName(player.getDisplayName()+finalflair);
|
||||||
|
AppendPlayerDisplayFlair(player, username, finalflair);
|
||||||
|
//System.out.println("DisplayName: "+player.getDisplayName());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetFlair(Player player)
|
||||||
|
{ //2015.07.16.
|
||||||
|
//String flair=PlayerFlairs.get(player.getName());
|
||||||
|
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||||
|
return flair==null ? "" : flair;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||||
|
{
|
||||||
|
//if(IgnoredPlayers.contains(player.getName()))
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
||||||
|
return;
|
||||||
|
//if(AcceptedPlayers.contains(player.getName()))
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
||||||
|
//player.setDisplayName(player.getDisplayName()+flair);
|
||||||
|
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
else
|
||||||
|
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//System.out.println("A");
|
||||||
|
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||||
|
String[] colors = color.substring(1).split("§");
|
||||||
|
//String displayname=player.getDisplayName();
|
||||||
|
String displayname=player.getName(); //2015.08.08.
|
||||||
|
ArrayList<Integer> Positions=new ArrayList<>();
|
||||||
|
//System.out.println("B");
|
||||||
|
for(int i=0; i<displayname.length(); i++) {
|
||||||
|
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||||
|
Positions.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//System.out.println("C: Positions.size(): "+Positions.size());
|
||||||
|
String finalname="";
|
||||||
|
if(Positions.size()>=colors.length)
|
||||||
|
{
|
||||||
|
//System.out.println("D");
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<Positions.size(); i++)
|
||||||
|
{
|
||||||
|
int pos=Positions.get(i);
|
||||||
|
int nextpos;
|
||||||
|
if(i!=Positions.size()-1)
|
||||||
|
nextpos=Positions.get(i+1);
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
||||||
|
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
||||||
|
//String substr="§"+colors[x++]+displayname.substring(pos, nextpos-pos)+"§r";
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
//System.out.println("F");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//System.out.println("E");
|
||||||
|
Positions.clear();
|
||||||
|
int unit=displayname.length()/colors.length;
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||||
|
{
|
||||||
|
int pos=i;
|
||||||
|
int nextpos;
|
||||||
|
if(i<displayname.length()-unit-unit)
|
||||||
|
nextpos=i+unit;
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
||||||
|
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
//System.out.println("G");
|
||||||
|
}
|
||||||
|
//player.setDisplayName(color+displayname+"§r"+flair);
|
||||||
|
//player.setDisplayName(finalname+flair);
|
||||||
|
//MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=finalname+flair; //2015.08.08.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetColorForTown(String townname)
|
||||||
|
{ //2015.07.20.
|
||||||
|
if(TownColors.containsKey(townname))
|
||||||
|
return TownColors.get(townname);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetPlayerTown(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//List<Town> towns = TownyUniverse.getDataSource().getTowns();
|
||||||
|
try {
|
||||||
|
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||||
|
return town.getName();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//String color = GetColorForTown(GetPlayerTown(player));
|
||||||
|
//String dname=player.getDisplayName();
|
||||||
|
//player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair)));
|
||||||
|
//MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<? extends Player> GetPlayers()
|
||||||
|
{
|
||||||
|
return Instance.getServer().getOnlinePlayers();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,368 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||||
|
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||||
|
|
||||||
|
public class PluginMain extends JavaPlugin
|
||||||
|
{ //Translated to Java: 2015.07.15.
|
||||||
|
//A user, which flair isn't obtainable:
|
||||||
|
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
||||||
|
private static PluginMain Instance;
|
||||||
|
// Fired when plugin is first enabled
|
||||||
|
@Override
|
||||||
|
public void onEnable()
|
||||||
|
{
|
||||||
|
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||||
|
this.getCommand("u").setExecutor(new Commands());
|
||||||
|
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||||
|
Instance=this; //2015.08.08.
|
||||||
|
try {
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
System.out.println("Name: " + name);
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("flairsignored.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||||
|
Thread t=new Thread(r);
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
Boolean stop=false;
|
||||||
|
// Fired when plugin is disabled
|
||||||
|
@Override
|
||||||
|
public void onDisable()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileWriter fw;
|
||||||
|
fw = new FileWriter("flairsaccepted.txt");
|
||||||
|
fw.close();
|
||||||
|
fw = new FileWriter("flairsignored.txt");
|
||||||
|
fw.close();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.AcceptedFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
try {
|
||||||
|
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.IgnoredFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
File file=new File("flairsignored.txt");
|
||||||
|
try {
|
||||||
|
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stop=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ThreadMethod() //<-- 2015.07.16.
|
||||||
|
{
|
||||||
|
while(!stop)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
||||||
|
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
||||||
|
for(Object obj : json)
|
||||||
|
{
|
||||||
|
JSONObject item = (JSONObject)obj;
|
||||||
|
String author=item.getJSONObject("data").getString("author");
|
||||||
|
String ign=item.getJSONObject("data").getString("body");
|
||||||
|
int start = ign.indexOf("IGN:") + "IGN:".length();
|
||||||
|
int end = ign.indexOf(' ', start);
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
end=ign.indexOf('\n', start); //2015.07.15.
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
ign = ign.substring(start);
|
||||||
|
else
|
||||||
|
ign = ign.substring(start, end);
|
||||||
|
ign = ign.trim();
|
||||||
|
if(HasIGFlair(ign))
|
||||||
|
continue;
|
||||||
|
try {
|
||||||
|
Thread.sleep(10);
|
||||||
|
} catch(InterruptedException ex) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
||||||
|
String flair;
|
||||||
|
if(flairdata.length > 1) //2015.07.15.
|
||||||
|
flair = flairdata[1];
|
||||||
|
else
|
||||||
|
flair="";
|
||||||
|
if (flair != "-1")
|
||||||
|
flair = flair + "s";
|
||||||
|
else
|
||||||
|
flair = "non-presser";
|
||||||
|
String flairclass;
|
||||||
|
if(flairdata.length>2)
|
||||||
|
flairclass = flairdata[2];
|
||||||
|
else
|
||||||
|
flairclass="unknown";
|
||||||
|
SetFlair(ign, flair, flairclass, author);
|
||||||
|
}
|
||||||
|
Thread.sleep(10000);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
||||||
|
{
|
||||||
|
URL url = new URL(urlstr);
|
||||||
|
URLConnection con = url.openConnection();
|
||||||
|
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
||||||
|
InputStream in = con.getInputStream();
|
||||||
|
String encoding = con.getContentEncoding();
|
||||||
|
encoding = encoding == null ? "UTF-8" : encoding;
|
||||||
|
String body = IOUtils.toString(in, encoding);
|
||||||
|
in.close();
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||||
|
public Boolean HasIGFlair(String playername)
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
return p.Flair!=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||||
|
{
|
||||||
|
String finalflair;
|
||||||
|
switch(flairclass)
|
||||||
|
{
|
||||||
|
case "press-1":
|
||||||
|
finalflair="§c("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-2":
|
||||||
|
finalflair="§6("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-3":
|
||||||
|
finalflair="§e("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-4":
|
||||||
|
finalflair="§a("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-5":
|
||||||
|
finalflair="§9("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-6":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "no-press":
|
||||||
|
finalflair="§7(non-pr.)§r";
|
||||||
|
break;
|
||||||
|
case "cheater":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "cant-press": //2015.08.08.
|
||||||
|
finalflair="§r(can't press)§r";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
finalflair="";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||||
|
return;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
p.Flair=finalflair; //2015.08.08.
|
||||||
|
p.UserName=username; //2015.08.08.
|
||||||
|
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||||
|
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(player.getName().equals(playername))
|
||||||
|
{
|
||||||
|
AppendPlayerDisplayFlair(player, username, finalflair);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetFlair(Player player)
|
||||||
|
{ //2015.07.16.
|
||||||
|
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||||
|
return flair==null ? "" : flair;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||||
|
{
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
||||||
|
return;
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
||||||
|
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
else
|
||||||
|
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||||
|
String[] colors = color.substring(1).split("§");
|
||||||
|
String displayname=player.getName(); //2015.08.08.
|
||||||
|
ArrayList<Integer> Positions=new ArrayList<>();
|
||||||
|
//System.out.println("B");
|
||||||
|
for(int i=0; i<displayname.length(); i++) {
|
||||||
|
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||||
|
Positions.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//System.out.println("C: Positions.size(): "+Positions.size());
|
||||||
|
String finalname="";
|
||||||
|
if(Positions.size()>=colors.length)
|
||||||
|
{
|
||||||
|
//System.out.println("D");
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<Positions.size(); i++)
|
||||||
|
{
|
||||||
|
int pos=Positions.get(i);
|
||||||
|
int nextpos;
|
||||||
|
if(i!=Positions.size()-1)
|
||||||
|
nextpos=Positions.get(i+1);
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
||||||
|
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
||||||
|
//String substr="§"+colors[x++]+displayname.substring(pos, nextpos-pos)+"§r";
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
//System.out.println("F");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//System.out.println("E");
|
||||||
|
Positions.clear();
|
||||||
|
int unit=displayname.length()/colors.length;
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||||
|
{
|
||||||
|
int pos=i;
|
||||||
|
int nextpos;
|
||||||
|
if(i<displayname.length()-unit-unit)
|
||||||
|
nextpos=i+unit;
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
||||||
|
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
//System.out.println("G");
|
||||||
|
}
|
||||||
|
//player.setDisplayName(color+displayname+"§r"+flair);
|
||||||
|
//player.setDisplayName(finalname+flair);
|
||||||
|
//MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=finalname+flair; //2015.08.08.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetColorForTown(String townname)
|
||||||
|
{ //2015.07.20.
|
||||||
|
if(TownColors.containsKey(townname))
|
||||||
|
return TownColors.get(townname);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetPlayerTown(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//List<Town> towns = TownyUniverse.getDataSource().getTowns();
|
||||||
|
try {
|
||||||
|
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||||
|
return town.getName();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//String color = GetColorForTown(GetPlayerTown(player));
|
||||||
|
//String dname=player.getDisplayName();
|
||||||
|
//player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair)));
|
||||||
|
//MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<? extends Player> GetPlayers()
|
||||||
|
{
|
||||||
|
return Instance.getServer().getOnlinePlayers();
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,39 +15,39 @@ public class PlayerListener implements Listener
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
public void onPlayerJoin(PlayerJoinEvent event)
|
||||||
{
|
{
|
||||||
Player p=event.getPlayer();
|
Player p=event.getPlayer();
|
||||||
PluginMain.Players.add(p);
|
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
||||||
//event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p));
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
||||||
if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20.
|
if(mp.Flair!=null)
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p));
|
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
||||||
else
|
else
|
||||||
{ //2015.07.20.
|
{ //2015.07.20.
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
||||||
sendRawMessage(p, json);
|
sendRawMessage(p, json);
|
||||||
}
|
}
|
||||||
//System.out.println("Added player "+p.getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
public void onPlayerLeave(PlayerQuitEvent event)
|
||||||
{
|
{
|
||||||
//for(Player player : PluginMain.Players)
|
|
||||||
for(int i=0; i<PluginMain.Players.size();)
|
|
||||||
{
|
|
||||||
Player player=PluginMain.Players.get(i);
|
|
||||||
if(player.getName().equals(event.getPlayer().getName()))
|
|
||||||
{
|
|
||||||
PluginMain.Players.remove(player);
|
|
||||||
//System.out.println("Removed player "+event.getPlayer().getName());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
i++; //If the player is removed, the next item will be on the same index
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
public void onPlayerChat(AsyncPlayerChatEvent event)
|
||||||
{
|
{
|
||||||
event.getFormat()
|
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
||||||
|
String flair=player.Flair; //2015.08.08.
|
||||||
|
if(flair==null || !player.AcceptedFlair)
|
||||||
|
flair=""; //2015.08.08.
|
||||||
|
String message=event.getMessage(); //2015.08.08.
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{ //2015.08.08.
|
||||||
|
int index=0;
|
||||||
|
while((index = message.indexOf(p.getName()))!=-1)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
@ -15,39 +15,35 @@ public class PlayerListener implements Listener
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
public void onPlayerJoin(PlayerJoinEvent event)
|
||||||
{
|
{
|
||||||
Player p=event.getPlayer();
|
Player p=event.getPlayer();
|
||||||
PluginMain.Players.add(p);
|
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
||||||
//event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p));
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
||||||
if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20.
|
if(mp.Flair!=null)
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p));
|
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
||||||
else
|
else
|
||||||
{ //2015.07.20.
|
{ //2015.07.20.
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
||||||
sendRawMessage(p, json);
|
sendRawMessage(p, json);
|
||||||
}
|
}
|
||||||
//System.out.println("Added player "+p.getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
public void onPlayerLeave(PlayerQuitEvent event)
|
||||||
{
|
{
|
||||||
//for(Player player : PluginMain.Players)
|
|
||||||
for(int i=0; i<PluginMain.Players.size();)
|
|
||||||
{
|
|
||||||
Player player=PluginMain.Players.get(i);
|
|
||||||
if(player.getName().equals(event.getPlayer().getName()))
|
|
||||||
{
|
|
||||||
PluginMain.Players.remove(player);
|
|
||||||
//System.out.println("Removed player "+event.getPlayer().getName());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
i++; //If the player is removed, the next item will be on the same index
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
public void onPlayerChat(AsyncPlayerChatEvent event)
|
||||||
{
|
{
|
||||||
event.setFormat(event.getFormat());
|
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
||||||
|
String flair=player.Flair; //2015.08.08.
|
||||||
|
if(flair==null || !player.AcceptedFlair)
|
||||||
|
flair=""; //2015.08.08.
|
||||||
|
String message=event.getMessage(); //2015.08.08.
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
int index = message.indexOf(p.getName());
|
||||||
|
}
|
||||||
|
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
@ -0,0 +1,173 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;*/
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.*/
|
||||||
|
else if(args[0].toLowerCase()=="admin")
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage(msg);
|
||||||
|
else
|
||||||
|
System.out.println(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
if(args.length==1)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "reload":
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "playerinfo":
|
||||||
|
DoPlayerInfo(player, args);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoPlayerInfo(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
//args[0] is "admin" - args[1] is "playerinfo"
|
||||||
|
if(args.length==2)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
}
|
||||||
|
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||||
|
{
|
||||||
|
String message="§cPlayer not found: "+args[2]+"§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
}
|
||||||
|
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
private static void SendMessage(Player player, String message)
|
||||||
|
{
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,189 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;*/
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.*/
|
||||||
|
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||||
|
{
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return true; //2015.08.09.
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
SendMessage(player, msg); //2015.08.09.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
PluginMain.LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
System.out.println("Args length: " + args.length);
|
||||||
|
if(args.length==1)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "reload":
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "playerinfo":
|
||||||
|
DoPlayerInfo(player, args);
|
||||||
|
break;
|
||||||
|
case "getlasterror":
|
||||||
|
DoGetLastError(player, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoPlayerInfo(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
//args[0] is "admin" - args[1] is "playerinfo"
|
||||||
|
if(args.length==2)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||||
|
{
|
||||||
|
String message="§cPlayer not found: "+args[2]+"§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||||
|
SendMessage(player, "Player name: "+p.PlayerName);
|
||||||
|
SendMessage(player, "User flair: "+p.Flair);
|
||||||
|
SendMessage(player, "Username: "+p.UserName);
|
||||||
|
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
||||||
|
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
||||||
|
}
|
||||||
|
private static void SendMessage(Player player, String message)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
}
|
||||||
|
private static void DoGetLastError(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
//args[0] is "admin" - args[1] is "getlasterror"
|
||||||
|
if(PluginMain.LastException!=null)
|
||||||
|
{
|
||||||
|
SendMessage(player, "Last error:");
|
||||||
|
SendMessage(player, PluginMain.LastException.toString());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
SendMessage()
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,418 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
|
||||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
|
||||||
|
|
||||||
public class PluginMain extends JavaPlugin
|
|
||||||
{ //Translated to Java: 2015.07.15.
|
|
||||||
//A user, which flair isn't obtainable:
|
|
||||||
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
|
||||||
// Fired when plugin is first enabled
|
|
||||||
@Override
|
|
||||||
public void onEnable()
|
|
||||||
{
|
|
||||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
|
||||||
//System.out.println("Original C# version: http://pastebin.com/tX8xCPbp");
|
|
||||||
//System.out.println("The Java version is... Also made by the same person.");
|
|
||||||
//System.out.println("With the help of StackOverflow and similar.");
|
|
||||||
/*catch(MalformedURLException e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
catch(IOException e)
|
|
||||||
{
|
|
||||||
}*/
|
|
||||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
|
||||||
//System.out.println("Registering commands...");
|
|
||||||
this.getCommand("u").setExecutor(new Commands());
|
|
||||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
|
||||||
try {
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//AcceptedPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("flairsignored.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//IgnoredPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
|
||||||
String line;
|
|
||||||
while((line=br.readLine())!=null)
|
|
||||||
{
|
|
||||||
String[] s=line.split(" ");
|
|
||||||
TownColors.put(s[0], s[1]);
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//System.out.println("Registering done.");
|
|
||||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
|
||||||
Thread t=new Thread(r);
|
|
||||||
t.start();
|
|
||||||
}
|
|
||||||
Boolean stop=false;
|
|
||||||
// Fired when plugin is disabled
|
|
||||||
@Override
|
|
||||||
public void onDisable()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
FileWriter fw;
|
|
||||||
fw = new FileWriter("flairsaccepted.txt");
|
|
||||||
fw.close();
|
|
||||||
fw = new FileWriter("flairsignored.txt");
|
|
||||||
fw.close();
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//for(String player : AcceptedPlayers)
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.AcceptedFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.IgnoredFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsignored.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stop=true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ThreadMethod() //<-- 2015.07.16.
|
|
||||||
{
|
|
||||||
/*System.out.println("Sleeping for 5 seconds..."); //2015.07.20.
|
|
||||||
try {
|
|
||||||
Thread.sleep(5000);
|
|
||||||
} catch (InterruptedException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
} //2015.07.20.*/
|
|
||||||
while(!stop)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
|
||||||
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
|
||||||
for(Object obj : json)
|
|
||||||
{
|
|
||||||
JSONObject item = (JSONObject)obj;
|
|
||||||
String author=item.getJSONObject("data").getString("author");
|
|
||||||
String ign=item.getJSONObject("data").getString("body");
|
|
||||||
int start = ign.indexOf("IGN:") + "IGN:".length();
|
|
||||||
int end = ign.indexOf(' ', start);
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
end=ign.indexOf('\n', start); //2015.07.15.
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
ign = ign.substring(start);
|
|
||||||
else
|
|
||||||
ign = ign.substring(start, end);
|
|
||||||
ign = ign.trim();
|
|
||||||
if(HasIGFlair(ign))
|
|
||||||
continue;
|
|
||||||
//System.out.println("Author: "+author);
|
|
||||||
try {
|
|
||||||
Thread.sleep(10);
|
|
||||||
} catch(InterruptedException ex) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
|
||||||
String flair;
|
|
||||||
if(flairdata.length > 1) //2015.07.15.
|
|
||||||
flair = flairdata[1];
|
|
||||||
else
|
|
||||||
flair="";
|
|
||||||
if (flair != "-1")
|
|
||||||
flair = flair + "s";
|
|
||||||
else
|
|
||||||
flair = "non-presser";
|
|
||||||
String flairclass;
|
|
||||||
//System.out.println("flairdata.length:"+flairdata.length);
|
|
||||||
if(flairdata.length>2)
|
|
||||||
flairclass = flairdata[2];
|
|
||||||
else
|
|
||||||
flairclass="unknown";
|
|
||||||
SetFlair(ign, flair, flairclass, author);
|
|
||||||
}
|
|
||||||
Thread.sleep(10000);
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
|
||||||
{
|
|
||||||
URL url = new URL(urlstr);
|
|
||||||
URLConnection con = url.openConnection();
|
|
||||||
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
|
||||||
InputStream in = con.getInputStream();
|
|
||||||
String encoding = con.getContentEncoding();
|
|
||||||
encoding = encoding == null ? "UTF-8" : encoding;
|
|
||||||
String body = IOUtils.toString(in, encoding);
|
|
||||||
in.close();
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
//It has to store offline player flairs too, therefore it can't use Player object
|
|
||||||
/*public static Map<String, String> PlayerFlairs=new HashMap<String, String>();
|
|
||||||
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
|
|
||||||
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
|
|
||||||
public static ArrayList<Player> Players=new ArrayList<Player>();
|
|
||||||
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
//public static Map<String, String> PlayerTowns=new HashMap<String, String>(); //2015.07.20.*/
|
|
||||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
|
||||||
public Boolean HasIGFlair(String playername)
|
|
||||||
{
|
|
||||||
/*Player player=null;
|
|
||||||
for(Player p : Players)
|
|
||||||
{
|
|
||||||
if(p.getName()==playername)
|
|
||||||
{
|
|
||||||
player=p;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(player==null)
|
|
||||||
return false;*/
|
|
||||||
//return PlayerFlairs.containsKey(playername);
|
|
||||||
return MaybeOfflinePlayer.AllPlayers.containsKey(playername);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
|
||||||
{
|
|
||||||
String finalflair;
|
|
||||||
switch(flairclass)
|
|
||||||
{
|
|
||||||
case "press-1":
|
|
||||||
finalflair="§c("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-2":
|
|
||||||
finalflair="§6("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-3":
|
|
||||||
finalflair="§e("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-4":
|
|
||||||
finalflair="§a("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-5":
|
|
||||||
finalflair="§9("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-6":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "no-press":
|
|
||||||
finalflair="§7(non-pr.)§r";
|
|
||||||
break;
|
|
||||||
case "cheater":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "cant-press": //2015.08.08.
|
|
||||||
finalflair="§r(can't press)§r";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
finalflair="";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
|
||||||
return;
|
|
||||||
//PlayerFlairs.put(playername, finalflair);
|
|
||||||
//PlayerUserNames.put(playername, username);
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername);
|
|
||||||
p.Flair=finalflair;
|
|
||||||
p.UserName=username;
|
|
||||||
/*for(Player player : Players)
|
|
||||||
{
|
|
||||||
if(player.getName()==playername)
|
|
||||||
{
|
|
||||||
PlayerFlairs.put(player, finalflair);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
//System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass);
|
|
||||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
|
||||||
for(Player player : Players)
|
|
||||||
{
|
|
||||||
//System.out.println("Online player: "+player.getName());
|
|
||||||
//System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername));
|
|
||||||
if(player.getName().equals(playername))
|
|
||||||
{
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
//player.setDisplayName(player.getDisplayName()+finalflair);
|
|
||||||
AppendPlayerDisplayFlair(player, username, finalflair);
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetFlair(Player player)
|
|
||||||
{ //2015.07.16.
|
|
||||||
String flair=PlayerFlairs.get(player.getName());
|
|
||||||
return flair==null ? "" : flair;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
|
||||||
{
|
|
||||||
//if(IgnoredPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
|
||||||
return;
|
|
||||||
//if(AcceptedPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
|
||||||
//player.setDisplayName(player.getDisplayName()+flair);
|
|
||||||
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
else
|
|
||||||
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//System.out.println("A");
|
|
||||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
|
||||||
String[] colors = color.substring(1).split("§");
|
|
||||||
//String displayname=player.getDisplayName();
|
|
||||||
String displayname=player.getName(); //2015.08.08.
|
|
||||||
ArrayList<Integer> Positions=new ArrayList<>();
|
|
||||||
//System.out.println("B");
|
|
||||||
for(int i=0; i<displayname.length(); i++) {
|
|
||||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
|
||||||
Positions.add(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//System.out.println("C: Positions.size(): "+Positions.size());
|
|
||||||
String finalname="";
|
|
||||||
if(Positions.size()>=colors.length)
|
|
||||||
{
|
|
||||||
//System.out.println("D");
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<Positions.size(); i++)
|
|
||||||
{
|
|
||||||
int pos=Positions.get(i);
|
|
||||||
int nextpos;
|
|
||||||
if(i!=Positions.size()-1)
|
|
||||||
nextpos=Positions.get(i+1);
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
//String substr="§"+colors[x++]+displayname.substring(pos, nextpos-pos)+"§r";
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("F");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//System.out.println("E");
|
|
||||||
Positions.clear();
|
|
||||||
int unit=displayname.length()/colors.length;
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
|
||||||
{
|
|
||||||
int pos=i;
|
|
||||||
int nextpos;
|
|
||||||
if(i<displayname.length()-unit-unit)
|
|
||||||
nextpos=i+unit;
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("G");
|
|
||||||
}
|
|
||||||
//player.setDisplayName(color+displayname+"§r"+flair);
|
|
||||||
//player.setDisplayName(finalname+flair);
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=finalname+flair; //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetColorForTown(String townname)
|
|
||||||
{ //2015.07.20.
|
|
||||||
if(TownColors.containsKey(townname))
|
|
||||||
return TownColors.get(townname);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetPlayerTown(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//List<Town> towns = TownyUniverse.getDataSource().getTowns();
|
|
||||||
try {
|
|
||||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown();
|
|
||||||
return town.getName();
|
|
||||||
} catch (Exception e) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
String color = GetColorForTown(GetPlayerTown(player));
|
|
||||||
String dname=player.getDisplayName();
|
|
||||||
//player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair)));
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08.
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,119 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0])
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "showerrors": //2015.08.09.
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(args[0]=="reload")
|
||||||
|
DoReload(null); //2015.07.20.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage(msg);
|
||||||
|
else
|
||||||
|
System.out.println(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import net.ess3.api.IUser;
|
||||||
|
|
||||||
|
public class Essentials
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -1,418 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
|
||||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
|
||||||
|
|
||||||
public class PluginMain extends JavaPlugin
|
|
||||||
{ //Translated to Java: 2015.07.15.
|
|
||||||
//A user, which flair isn't obtainable:
|
|
||||||
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
|
||||||
// Fired when plugin is first enabled
|
|
||||||
@Override
|
|
||||||
public void onEnable()
|
|
||||||
{
|
|
||||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
|
||||||
//System.out.println("Original C# version: http://pastebin.com/tX8xCPbp");
|
|
||||||
//System.out.println("The Java version is... Also made by the same person.");
|
|
||||||
//System.out.println("With the help of StackOverflow and similar.");
|
|
||||||
/*catch(MalformedURLException e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
catch(IOException e)
|
|
||||||
{
|
|
||||||
}*/
|
|
||||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
|
||||||
//System.out.println("Registering commands...");
|
|
||||||
this.getCommand("u").setExecutor(new Commands());
|
|
||||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
|
||||||
try {
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//AcceptedPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("flairsignored.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//IgnoredPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
|
||||||
String line;
|
|
||||||
while((line=br.readLine())!=null)
|
|
||||||
{
|
|
||||||
String[] s=line.split(" ");
|
|
||||||
TownColors.put(s[0], s[1]);
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//System.out.println("Registering done.");
|
|
||||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
|
||||||
Thread t=new Thread(r);
|
|
||||||
t.start();
|
|
||||||
}
|
|
||||||
Boolean stop=false;
|
|
||||||
// Fired when plugin is disabled
|
|
||||||
@Override
|
|
||||||
public void onDisable()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
FileWriter fw;
|
|
||||||
fw = new FileWriter("flairsaccepted.txt");
|
|
||||||
fw.close();
|
|
||||||
fw = new FileWriter("flairsignored.txt");
|
|
||||||
fw.close();
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//for(String player : AcceptedPlayers)
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.AcceptedFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.IgnoredFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsignored.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stop=true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ThreadMethod() //<-- 2015.07.16.
|
|
||||||
{
|
|
||||||
/*System.out.println("Sleeping for 5 seconds..."); //2015.07.20.
|
|
||||||
try {
|
|
||||||
Thread.sleep(5000);
|
|
||||||
} catch (InterruptedException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
} //2015.07.20.*/
|
|
||||||
while(!stop)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
|
||||||
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
|
||||||
for(Object obj : json)
|
|
||||||
{
|
|
||||||
JSONObject item = (JSONObject)obj;
|
|
||||||
String author=item.getJSONObject("data").getString("author");
|
|
||||||
String ign=item.getJSONObject("data").getString("body");
|
|
||||||
int start = ign.indexOf("IGN:") + "IGN:".length();
|
|
||||||
int end = ign.indexOf(' ', start);
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
end=ign.indexOf('\n', start); //2015.07.15.
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
ign = ign.substring(start);
|
|
||||||
else
|
|
||||||
ign = ign.substring(start, end);
|
|
||||||
ign = ign.trim();
|
|
||||||
if(HasIGFlair(ign))
|
|
||||||
continue;
|
|
||||||
//System.out.println("Author: "+author);
|
|
||||||
try {
|
|
||||||
Thread.sleep(10);
|
|
||||||
} catch(InterruptedException ex) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
|
||||||
String flair;
|
|
||||||
if(flairdata.length > 1) //2015.07.15.
|
|
||||||
flair = flairdata[1];
|
|
||||||
else
|
|
||||||
flair="";
|
|
||||||
if (flair != "-1")
|
|
||||||
flair = flair + "s";
|
|
||||||
else
|
|
||||||
flair = "non-presser";
|
|
||||||
String flairclass;
|
|
||||||
//System.out.println("flairdata.length:"+flairdata.length);
|
|
||||||
if(flairdata.length>2)
|
|
||||||
flairclass = flairdata[2];
|
|
||||||
else
|
|
||||||
flairclass="unknown";
|
|
||||||
SetFlair(ign, flair, flairclass, author);
|
|
||||||
}
|
|
||||||
Thread.sleep(10000);
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
|
||||||
{
|
|
||||||
URL url = new URL(urlstr);
|
|
||||||
URLConnection con = url.openConnection();
|
|
||||||
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
|
||||||
InputStream in = con.getInputStream();
|
|
||||||
String encoding = con.getContentEncoding();
|
|
||||||
encoding = encoding == null ? "UTF-8" : encoding;
|
|
||||||
String body = IOUtils.toString(in, encoding);
|
|
||||||
in.close();
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
//It has to store offline player flairs too, therefore it can't use Player object
|
|
||||||
/*public static Map<String, String> PlayerFlairs=new HashMap<String, String>();
|
|
||||||
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
|
|
||||||
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
|
|
||||||
public static ArrayList<Player> Players=new ArrayList<Player>();
|
|
||||||
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
//public static Map<String, String> PlayerTowns=new HashMap<String, String>(); //2015.07.20.*/
|
|
||||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
|
||||||
public Boolean HasIGFlair(String playername)
|
|
||||||
{
|
|
||||||
/*Player player=null;
|
|
||||||
for(Player p : Players)
|
|
||||||
{
|
|
||||||
if(p.getName()==playername)
|
|
||||||
{
|
|
||||||
player=p;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(player==null)
|
|
||||||
return false;*/
|
|
||||||
//return PlayerFlairs.containsKey(playername);
|
|
||||||
return MaybeOfflinePlayer.AllPlayers.containsKey(playername);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
|
||||||
{
|
|
||||||
String finalflair;
|
|
||||||
switch(flairclass)
|
|
||||||
{
|
|
||||||
case "press-1":
|
|
||||||
finalflair="§c("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-2":
|
|
||||||
finalflair="§6("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-3":
|
|
||||||
finalflair="§e("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-4":
|
|
||||||
finalflair="§a("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-5":
|
|
||||||
finalflair="§9("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-6":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "no-press":
|
|
||||||
finalflair="§7(non-pr.)§r";
|
|
||||||
break;
|
|
||||||
case "cheater":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "cant-press": //2015.08.08.
|
|
||||||
finalflair="§r(can't press)§r";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
finalflair="";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
|
||||||
return;
|
|
||||||
//PlayerFlairs.put(playername, finalflair);
|
|
||||||
//PlayerUserNames.put(playername, username);
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
|
||||||
p.Flair=finalflair; //2015.08.08.
|
|
||||||
p.UserName=username; //2015.08.08
|
|
||||||
/*for(Player player : Players)
|
|
||||||
{
|
|
||||||
if(player.getName()==playername)
|
|
||||||
{
|
|
||||||
PlayerFlairs.put(player, finalflair);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
//System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass);
|
|
||||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
|
||||||
for(Player player : Players)
|
|
||||||
{
|
|
||||||
//System.out.println("Online player: "+player.getName());
|
|
||||||
//System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername));
|
|
||||||
if(player.getName().equals(playername))
|
|
||||||
{
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
//player.setDisplayName(player.getDisplayName()+finalflair);
|
|
||||||
AppendPlayerDisplayFlair(player, username, finalflair);
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetFlair(Player player)
|
|
||||||
{ //2015.07.16.
|
|
||||||
String flair=PlayerFlairs.get(player.getName());
|
|
||||||
return flair==null ? "" : flair;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
|
||||||
{
|
|
||||||
//if(IgnoredPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
|
||||||
return;
|
|
||||||
//if(AcceptedPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
|
||||||
//player.setDisplayName(player.getDisplayName()+flair);
|
|
||||||
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
else
|
|
||||||
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//System.out.println("A");
|
|
||||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
|
||||||
String[] colors = color.substring(1).split("§");
|
|
||||||
//String displayname=player.getDisplayName();
|
|
||||||
String displayname=player.getName(); //2015.08.08.
|
|
||||||
ArrayList<Integer> Positions=new ArrayList<>();
|
|
||||||
//System.out.println("B");
|
|
||||||
for(int i=0; i<displayname.length(); i++) {
|
|
||||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
|
||||||
Positions.add(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//System.out.println("C: Positions.size(): "+Positions.size());
|
|
||||||
String finalname="";
|
|
||||||
if(Positions.size()>=colors.length)
|
|
||||||
{
|
|
||||||
//System.out.println("D");
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<Positions.size(); i++)
|
|
||||||
{
|
|
||||||
int pos=Positions.get(i);
|
|
||||||
int nextpos;
|
|
||||||
if(i!=Positions.size()-1)
|
|
||||||
nextpos=Positions.get(i+1);
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
//String substr="§"+colors[x++]+displayname.substring(pos, nextpos-pos)+"§r";
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("F");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//System.out.println("E");
|
|
||||||
Positions.clear();
|
|
||||||
int unit=displayname.length()/colors.length;
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
|
||||||
{
|
|
||||||
int pos=i;
|
|
||||||
int nextpos;
|
|
||||||
if(i<displayname.length()-unit-unit)
|
|
||||||
nextpos=i+unit;
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("G");
|
|
||||||
}
|
|
||||||
//player.setDisplayName(color+displayname+"§r"+flair);
|
|
||||||
//player.setDisplayName(finalname+flair);
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=finalname+flair; //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetColorForTown(String townname)
|
|
||||||
{ //2015.07.20.
|
|
||||||
if(TownColors.containsKey(townname))
|
|
||||||
return TownColors.get(townname);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetPlayerTown(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//List<Town> towns = TownyUniverse.getDataSource().getTowns();
|
|
||||||
try {
|
|
||||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown();
|
|
||||||
return town.getName();
|
|
||||||
} catch (Exception e) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
String color = GetColorForTown(GetPlayerTown(player));
|
|
||||||
String dname=player.getDisplayName();
|
|
||||||
//player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair)));
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08.
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
import de.inventivegames.TellRawAutoMessage.Reflection;
|
||||||
|
|
||||||
|
public class PlayerListener implements Listener
|
||||||
|
{ //2015.07.16.
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event)
|
||||||
|
{
|
||||||
|
Player p=event.getPlayer();
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
||||||
|
else
|
||||||
|
{ //2015.07.20.
|
||||||
|
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
||||||
|
sendRawMessage(p, json);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerLeave(PlayerQuitEvent event)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerChat(AsyncPlayerChatEvent event)
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
||||||
|
String flair=player.Flair; //2015.08.08.
|
||||||
|
if(flair==null || !player.AcceptedFlair)
|
||||||
|
flair=""; //2015.08.08.
|
||||||
|
String message=event.getMessage(); //2015.08.08.
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{ //2015.08.08.
|
||||||
|
int index=0;
|
||||||
|
while((index = message.indexOf(p.getName()))!=-1)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
||||||
|
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
||||||
|
public static void sendRawMessage(Player player, String message)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
System.out.println("1");
|
||||||
|
Object handle = Reflection.getHandle(player);
|
||||||
|
System.out.println("2");
|
||||||
|
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
|
System.out.println("3");
|
||||||
|
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
||||||
|
System.out.println("4");
|
||||||
|
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
||||||
|
System.out.println("5");
|
||||||
|
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
||||||
|
System.out.println("6");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,66 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
import de.inventivegames.TellRawAutoMessage.Reflection;
|
||||||
|
|
||||||
|
public class PlayerListener implements Listener
|
||||||
|
{ //2015.07.16.
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event)
|
||||||
|
{
|
||||||
|
Player p=event.getPlayer();
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
||||||
|
else
|
||||||
|
{ //2015.07.20.
|
||||||
|
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
||||||
|
sendRawMessage(p, json);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerLeave(PlayerQuitEvent event)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerChat(AsyncPlayerChatEvent event)
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
||||||
|
String flair=player.Flair; //2015.08.08.
|
||||||
|
if(flair==null || !player.AcceptedFlair)
|
||||||
|
flair=""; //2015.08.08.
|
||||||
|
String message;
|
||||||
|
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
||||||
|
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
||||||
|
public static void sendRawMessage(Player player, String message)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
System.out.println("1");
|
||||||
|
Object handle = Reflection.getHandle(player);
|
||||||
|
System.out.println("2");
|
||||||
|
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
|
System.out.println("3");
|
||||||
|
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
||||||
|
System.out.println("4");
|
||||||
|
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
||||||
|
System.out.println("5");
|
||||||
|
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
||||||
|
System.out.println("6");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,132 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.
|
||||||
|
else if(args[0].toLowerCase()=="admin")
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage(msg);
|
||||||
|
else
|
||||||
|
System.out.println(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
//args[0] is "admin"
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,350 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||||
|
|
||||||
|
public class PluginMain extends JavaPlugin
|
||||||
|
{ //Translated to Java: 2015.07.15.
|
||||||
|
//A user, which flair isn't obtainable:
|
||||||
|
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
||||||
|
private static PluginMain Instance;
|
||||||
|
// Fired when plugin is first enabled
|
||||||
|
@Override
|
||||||
|
public void onEnable()
|
||||||
|
{
|
||||||
|
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||||
|
this.getCommand("u").setExecutor(new Commands());
|
||||||
|
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||||
|
Instance=this; //2015.08.08.
|
||||||
|
try {
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
//System.out.println("Name: " + name);
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("flairsignored.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||||
|
Thread t=new Thread(r);
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
Boolean stop=false;
|
||||||
|
// Fired when plugin is disabled
|
||||||
|
@Override
|
||||||
|
public void onDisable()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileWriter fw;
|
||||||
|
fw = new FileWriter("flairsaccepted.txt");
|
||||||
|
fw.close();
|
||||||
|
fw = new FileWriter("flairsignored.txt");
|
||||||
|
fw.close();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.AcceptedFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
}
|
||||||
|
bw.close();
|
||||||
|
file=new File("flairsignored.txt");
|
||||||
|
bw = new BufferedWriter(new FileWriter(file, true));
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.IgnoredFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
}
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
stop=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ThreadMethod() //<-- 2015.07.16.
|
||||||
|
{
|
||||||
|
while(!stop)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
||||||
|
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
||||||
|
for(Object obj : json)
|
||||||
|
{
|
||||||
|
JSONObject item = (JSONObject)obj;
|
||||||
|
String author=item.getJSONObject("data").getString("author");
|
||||||
|
String ign=item.getJSONObject("data").getString("body");
|
||||||
|
int start = ign.indexOf("IGN:") + "IGN:".length();
|
||||||
|
int end = ign.indexOf(' ', start);
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
end=ign.indexOf('\n', start); //2015.07.15.
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
ign = ign.substring(start);
|
||||||
|
else
|
||||||
|
ign = ign.substring(start, end);
|
||||||
|
ign = ign.trim();
|
||||||
|
if(HasIGFlair(ign))
|
||||||
|
continue;
|
||||||
|
try {
|
||||||
|
Thread.sleep(10);
|
||||||
|
} catch(InterruptedException ex) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
||||||
|
String flair;
|
||||||
|
if(flairdata.length > 1) //2015.07.15.
|
||||||
|
flair = flairdata[1];
|
||||||
|
else
|
||||||
|
flair="";
|
||||||
|
if (flair != "-1")
|
||||||
|
flair = flair + "s";
|
||||||
|
else
|
||||||
|
flair = "non-presser";
|
||||||
|
String flairclass;
|
||||||
|
if(flairdata.length>2)
|
||||||
|
flairclass = flairdata[2];
|
||||||
|
else
|
||||||
|
flairclass="unknown";
|
||||||
|
SetFlair(ign, flair, flairclass, author);
|
||||||
|
}
|
||||||
|
Thread.sleep(10000);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Exception LastException; //2015.08.09.
|
||||||
|
|
||||||
|
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
||||||
|
{
|
||||||
|
URL url = new URL(urlstr);
|
||||||
|
URLConnection con = url.openConnection();
|
||||||
|
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
||||||
|
InputStream in = con.getInputStream();
|
||||||
|
String encoding = con.getContentEncoding();
|
||||||
|
encoding = encoding == null ? "UTF-8" : encoding;
|
||||||
|
String body = IOUtils.toString(in, encoding);
|
||||||
|
in.close();
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||||
|
public Boolean HasIGFlair(String playername)
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
return p.Flair!=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||||
|
{
|
||||||
|
String finalflair;
|
||||||
|
switch(flairclass)
|
||||||
|
{
|
||||||
|
case "press-1":
|
||||||
|
finalflair="§c("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-2":
|
||||||
|
finalflair="§6("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-3":
|
||||||
|
finalflair="§e("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-4":
|
||||||
|
finalflair="§a("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-5":
|
||||||
|
finalflair="§9("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-6":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "no-press":
|
||||||
|
finalflair="§7(non-pr.)§r";
|
||||||
|
break;
|
||||||
|
case "cheater":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "cant-press": //2015.08.08.
|
||||||
|
finalflair="§r(can't press)§r";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
finalflair="";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||||
|
return;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
p.Flair=finalflair; //2015.08.08.
|
||||||
|
p.UserName=username; //2015.08.08.
|
||||||
|
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||||
|
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(player.getName().equals(playername))
|
||||||
|
{
|
||||||
|
AppendPlayerDisplayFlair(player, username, finalflair);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetFlair(Player player)
|
||||||
|
{ //2015.07.16.
|
||||||
|
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||||
|
return flair==null ? "" : flair;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||||
|
{
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
||||||
|
return;
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
||||||
|
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
else
|
||||||
|
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||||
|
String[] colors = color.substring(1).split("§");
|
||||||
|
String displayname=player.getName(); //2015.08.08.
|
||||||
|
ArrayList<Integer> Positions=new ArrayList<>();
|
||||||
|
for(int i=0; i<displayname.length(); i++) {
|
||||||
|
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||||
|
Positions.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String finalname=""; //TODO
|
||||||
|
if(Positions.size()>=colors.length)
|
||||||
|
{
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<Positions.size(); i++)
|
||||||
|
{
|
||||||
|
int pos=Positions.get(i);
|
||||||
|
int nextpos;
|
||||||
|
if(i!=Positions.size()-1)
|
||||||
|
nextpos=Positions.get(i+1);
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Positions.clear();
|
||||||
|
int unit=displayname.length()/colors.length;
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||||
|
{
|
||||||
|
int pos=i;
|
||||||
|
int nextpos;
|
||||||
|
if(i<displayname.length()-unit-unit)
|
||||||
|
nextpos=i+unit;
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetColorForTown(String townname)
|
||||||
|
{ //2015.07.20.
|
||||||
|
if(TownColors.containsKey(townname))
|
||||||
|
return TownColors.get(townname);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetPlayerTown(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
try {
|
||||||
|
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||||
|
return town.getName();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<? extends Player> GetPlayers()
|
||||||
|
{
|
||||||
|
return Instance.getServer().getOnlinePlayers();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,354 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||||
|
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||||
|
|
||||||
|
public class PluginMain extends JavaPlugin
|
||||||
|
{ //Translated to Java: 2015.07.15.
|
||||||
|
//A user, which flair isn't obtainable:
|
||||||
|
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
||||||
|
private static PluginMain Instance;
|
||||||
|
// Fired when plugin is first enabled
|
||||||
|
@Override
|
||||||
|
public void onEnable()
|
||||||
|
{
|
||||||
|
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||||
|
this.getCommand("u").setExecutor(new Commands());
|
||||||
|
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||||
|
Instance=this; //2015.08.08.
|
||||||
|
try {
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
System.out.println("Name: " + name);
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("flairsignored.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||||
|
Thread t=new Thread(r);
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
Boolean stop=false;
|
||||||
|
// Fired when plugin is disabled
|
||||||
|
@Override
|
||||||
|
public void onDisable()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileWriter fw;
|
||||||
|
fw = new FileWriter("flairsaccepted.txt");
|
||||||
|
fw.close();
|
||||||
|
fw = new FileWriter("flairsignored.txt");
|
||||||
|
fw.close();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.AcceptedFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
try {
|
||||||
|
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.IgnoredFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
File file=new File("flairsignored.txt");
|
||||||
|
try {
|
||||||
|
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stop=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ThreadMethod() //<-- 2015.07.16.
|
||||||
|
{
|
||||||
|
while(!stop)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
||||||
|
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
||||||
|
for(Object obj : json)
|
||||||
|
{
|
||||||
|
JSONObject item = (JSONObject)obj;
|
||||||
|
String author=item.getJSONObject("data").getString("author");
|
||||||
|
String ign=item.getJSONObject("data").getString("body");
|
||||||
|
int start = ign.indexOf("IGN:") + "IGN:".length();
|
||||||
|
int end = ign.indexOf(' ', start);
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
end=ign.indexOf('\n', start); //2015.07.15.
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
ign = ign.substring(start);
|
||||||
|
else
|
||||||
|
ign = ign.substring(start, end);
|
||||||
|
ign = ign.trim();
|
||||||
|
if(HasIGFlair(ign))
|
||||||
|
continue;
|
||||||
|
try {
|
||||||
|
Thread.sleep(10);
|
||||||
|
} catch(InterruptedException ex) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
||||||
|
String flair;
|
||||||
|
if(flairdata.length > 1) //2015.07.15.
|
||||||
|
flair = flairdata[1];
|
||||||
|
else
|
||||||
|
flair="";
|
||||||
|
if (flair != "-1")
|
||||||
|
flair = flair + "s";
|
||||||
|
else
|
||||||
|
flair = "non-presser";
|
||||||
|
String flairclass;
|
||||||
|
if(flairdata.length>2)
|
||||||
|
flairclass = flairdata[2];
|
||||||
|
else
|
||||||
|
flairclass="unknown";
|
||||||
|
SetFlair(ign, flair, flairclass, author);
|
||||||
|
}
|
||||||
|
Thread.sleep(10000);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
||||||
|
{
|
||||||
|
URL url = new URL(urlstr);
|
||||||
|
URLConnection con = url.openConnection();
|
||||||
|
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
||||||
|
InputStream in = con.getInputStream();
|
||||||
|
String encoding = con.getContentEncoding();
|
||||||
|
encoding = encoding == null ? "UTF-8" : encoding;
|
||||||
|
String body = IOUtils.toString(in, encoding);
|
||||||
|
in.close();
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||||
|
public Boolean HasIGFlair(String playername)
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
return p.Flair!=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||||
|
{
|
||||||
|
String finalflair;
|
||||||
|
switch(flairclass)
|
||||||
|
{
|
||||||
|
case "press-1":
|
||||||
|
finalflair="§c("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-2":
|
||||||
|
finalflair="§6("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-3":
|
||||||
|
finalflair="§e("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-4":
|
||||||
|
finalflair="§a("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-5":
|
||||||
|
finalflair="§9("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-6":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "no-press":
|
||||||
|
finalflair="§7(non-pr.)§r";
|
||||||
|
break;
|
||||||
|
case "cheater":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "cant-press": //2015.08.08.
|
||||||
|
finalflair="§r(can't press)§r";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
finalflair="";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||||
|
return;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
p.Flair=finalflair; //2015.08.08.
|
||||||
|
p.UserName=username; //2015.08.08.
|
||||||
|
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||||
|
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(player.getName().equals(playername))
|
||||||
|
{
|
||||||
|
AppendPlayerDisplayFlair(player, username, finalflair);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetFlair(Player player)
|
||||||
|
{ //2015.07.16.
|
||||||
|
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||||
|
return flair==null ? "" : flair;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||||
|
{
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
||||||
|
return;
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
||||||
|
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
else
|
||||||
|
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||||
|
String[] colors = color.substring(1).split("§");
|
||||||
|
String displayname=player.getName(); //2015.08.08.
|
||||||
|
ArrayList<Integer> Positions=new ArrayList<>();
|
||||||
|
for(int i=0; i<displayname.length(); i++) {
|
||||||
|
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||||
|
Positions.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String finalname="";
|
||||||
|
if(Positions.size()>=colors.length)
|
||||||
|
{
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<Positions.size(); i++)
|
||||||
|
{
|
||||||
|
int pos=Positions.get(i);
|
||||||
|
int nextpos;
|
||||||
|
if(i!=Positions.size()-1)
|
||||||
|
nextpos=Positions.get(i+1);
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Positions.clear();
|
||||||
|
int unit=displayname.length()/colors.length;
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||||
|
{
|
||||||
|
int pos=i;
|
||||||
|
int nextpos;
|
||||||
|
if(i<displayname.length()-unit-unit)
|
||||||
|
nextpos=i+unit;
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetColorForTown(String townname)
|
||||||
|
{ //2015.07.20.
|
||||||
|
if(TownColors.containsKey(townname))
|
||||||
|
return TownColors.get(townname);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetPlayerTown(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//List<Town> towns = TownyUniverse.getDataSource().getTowns();
|
||||||
|
try {
|
||||||
|
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||||
|
return town.getName();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//String color = GetColorForTown(GetPlayerTown(player));
|
||||||
|
//String dname=player.getDisplayName();
|
||||||
|
//player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair)));
|
||||||
|
//MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<? extends Player> GetPlayers()
|
||||||
|
{
|
||||||
|
return Instance.getServer().getOnlinePlayers();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,139 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;*/
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.*/
|
||||||
|
else if(args[0].toLowerCase()=="admin")
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage(msg);
|
||||||
|
else
|
||||||
|
System.out.println(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "reload":
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "playerinfo":
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,121 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "showerrors": //2015.08.09.
|
||||||
|
DoShowErrors(player);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.
|
||||||
|
else if(args[0].toLowerCase()=="showerrors")
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage(msg);
|
||||||
|
else
|
||||||
|
System.out.println(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,176 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;*/
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.*/
|
||||||
|
else if(args[0].toLowerCase()=="admin")
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage(msg);
|
||||||
|
else
|
||||||
|
System.out.println(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
if(args.length==1)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "reload":
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "playerinfo":
|
||||||
|
DoPlayerInfo(player, args);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoPlayerInfo(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
//args[0] is "admin" - args[1] is "playerinfo"
|
||||||
|
if(args.length==2)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||||
|
{
|
||||||
|
String message="§cPlayer not found: "+args[2]+"§r";
|
||||||
|
}
|
||||||
|
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
private static void SendMessage(Player player, String message)
|
||||||
|
{
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,136 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;*/
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.*/
|
||||||
|
else if(args[0].toLowerCase()=="admin")
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage(msg);
|
||||||
|
else
|
||||||
|
System.out.println(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "reload":
|
||||||
|
DoReload(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,190 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;*/
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.*/
|
||||||
|
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||||
|
{
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return true; //2015.08.09.
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
SendMessage(player, msg); //2015.08.09.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
PluginMain.LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
System.out.println("Args length: " + args.length);
|
||||||
|
if(args.length==1)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "reload":
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "playerinfo":
|
||||||
|
DoPlayerInfo(player, args);
|
||||||
|
break;
|
||||||
|
case "getlasterror":
|
||||||
|
DoGetLastError(player, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoPlayerInfo(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
//args[0] is "admin" - args[1] is "playerinfo"
|
||||||
|
if(args.length==2)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||||
|
{
|
||||||
|
String message="§cPlayer not found: "+args[2]+"§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||||
|
SendMessage(player, "Player name: "+p.PlayerName);
|
||||||
|
SendMessage(player, "User flair: "+p.Flair);
|
||||||
|
SendMessage(player, "Username: "+p.UserName);
|
||||||
|
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
||||||
|
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
||||||
|
}
|
||||||
|
private static void SendMessage(Player player, String message)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
}
|
||||||
|
private static void DoGetLastError(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
//args[0] is "admin" - args[1] is "getlasterror"
|
||||||
|
if(args.length==2)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin getlasterror <player>§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SendMessage(player, "Last error:");
|
||||||
|
SendMessage(player, PluginMain.LastException.toString());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,135 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.
|
||||||
|
else if(args[0].toLowerCase()=="admin")
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage(msg);
|
||||||
|
else
|
||||||
|
System.out.println(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
//args[0] is "admin"
|
||||||
|
swithc(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,428 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
|
||||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
|
||||||
|
|
||||||
public class PluginMain extends JavaPlugin
|
|
||||||
{ //Translated to Java: 2015.07.15.
|
|
||||||
//A user, which flair isn't obtainable:
|
|
||||||
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
|
||||||
private static PluginMain Instance;
|
|
||||||
// Fired when plugin is first enabled
|
|
||||||
@Override
|
|
||||||
public void onEnable()
|
|
||||||
{
|
|
||||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
|
||||||
//System.out.println("Original C# version: http://pastebin.com/tX8xCPbp");
|
|
||||||
//System.out.println("The Java version is... Also made by the same person.");
|
|
||||||
//System.out.println("With the help of StackOverflow and similar.");
|
|
||||||
/*catch(MalformedURLException e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
catch(IOException e)
|
|
||||||
{
|
|
||||||
}*/
|
|
||||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
|
||||||
//System.out.println("Registering commands...");
|
|
||||||
this.getCommand("u").setExecutor(new Commands());
|
|
||||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
|
||||||
Instance=this; //2015.08.08.
|
|
||||||
try {
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//AcceptedPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("flairsignored.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//IgnoredPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
|
||||||
String line;
|
|
||||||
while((line=br.readLine())!=null)
|
|
||||||
{
|
|
||||||
String[] s=line.split(" ");
|
|
||||||
TownColors.put(s[0], s[1]);
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//System.out.println("Registering done.");
|
|
||||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
|
||||||
Thread t=new Thread(r);
|
|
||||||
t.start();
|
|
||||||
}
|
|
||||||
Boolean stop=false;
|
|
||||||
// Fired when plugin is disabled
|
|
||||||
@Override
|
|
||||||
public void onDisable()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
FileWriter fw;
|
|
||||||
fw = new FileWriter("flairsaccepted.txt");
|
|
||||||
fw.close();
|
|
||||||
fw = new FileWriter("flairsignored.txt");
|
|
||||||
fw.close();
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//for(String player : AcceptedPlayers)
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.AcceptedFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.IgnoredFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsignored.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stop=true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ThreadMethod() //<-- 2015.07.16.
|
|
||||||
{
|
|
||||||
/*System.out.println("Sleeping for 5 seconds..."); //2015.07.20.
|
|
||||||
try {
|
|
||||||
Thread.sleep(5000);
|
|
||||||
} catch (InterruptedException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
} //2015.07.20.*/
|
|
||||||
while(!stop)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
|
||||||
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
|
||||||
for(Object obj : json)
|
|
||||||
{
|
|
||||||
JSONObject item = (JSONObject)obj;
|
|
||||||
String author=item.getJSONObject("data").getString("author");
|
|
||||||
String ign=item.getJSONObject("data").getString("body");
|
|
||||||
int start = ign.indexOf("IGN:") + "IGN:".length();
|
|
||||||
int end = ign.indexOf(' ', start);
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
end=ign.indexOf('\n', start); //2015.07.15.
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
ign = ign.substring(start);
|
|
||||||
else
|
|
||||||
ign = ign.substring(start, end);
|
|
||||||
ign = ign.trim();
|
|
||||||
if(HasIGFlair(ign))
|
|
||||||
continue;
|
|
||||||
//System.out.println("Author: "+author);
|
|
||||||
try {
|
|
||||||
Thread.sleep(10);
|
|
||||||
} catch(InterruptedException ex) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
|
||||||
String flair;
|
|
||||||
if(flairdata.length > 1) //2015.07.15.
|
|
||||||
flair = flairdata[1];
|
|
||||||
else
|
|
||||||
flair="";
|
|
||||||
if (flair != "-1")
|
|
||||||
flair = flair + "s";
|
|
||||||
else
|
|
||||||
flair = "non-presser";
|
|
||||||
String flairclass;
|
|
||||||
//System.out.println("flairdata.length:"+flairdata.length);
|
|
||||||
if(flairdata.length>2)
|
|
||||||
flairclass = flairdata[2];
|
|
||||||
else
|
|
||||||
flairclass="unknown";
|
|
||||||
SetFlair(ign, flair, flairclass, author);
|
|
||||||
}
|
|
||||||
Thread.sleep(10000);
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
|
||||||
{
|
|
||||||
URL url = new URL(urlstr);
|
|
||||||
URLConnection con = url.openConnection();
|
|
||||||
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
|
||||||
InputStream in = con.getInputStream();
|
|
||||||
String encoding = con.getContentEncoding();
|
|
||||||
encoding = encoding == null ? "UTF-8" : encoding;
|
|
||||||
String body = IOUtils.toString(in, encoding);
|
|
||||||
in.close();
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
//It has to store offline player flairs too, therefore it can't use Player object
|
|
||||||
/*public static Map<String, String> PlayerFlairs=new HashMap<String, String>();
|
|
||||||
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
|
|
||||||
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
|
|
||||||
public static ArrayList<Player> Players=new ArrayList<Player>();
|
|
||||||
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
//public static Map<String, String> PlayerTowns=new HashMap<String, String>(); //2015.07.20.*/
|
|
||||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
|
||||||
public Boolean HasIGFlair(String playername)
|
|
||||||
{
|
|
||||||
/*Player player=null;
|
|
||||||
for(Player p : Players)
|
|
||||||
{
|
|
||||||
if(p.getName()==playername)
|
|
||||||
{
|
|
||||||
player=p;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(player==null)
|
|
||||||
return false;*/
|
|
||||||
//return PlayerFlairs.containsKey(playername);
|
|
||||||
return MaybeOfflinePlayer.AllPlayers.containsKey(playername);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
|
||||||
{
|
|
||||||
String finalflair;
|
|
||||||
switch(flairclass)
|
|
||||||
{
|
|
||||||
case "press-1":
|
|
||||||
finalflair="§c("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-2":
|
|
||||||
finalflair="§6("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-3":
|
|
||||||
finalflair="§e("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-4":
|
|
||||||
finalflair="§a("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-5":
|
|
||||||
finalflair="§9("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-6":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "no-press":
|
|
||||||
finalflair="§7(non-pr.)§r";
|
|
||||||
break;
|
|
||||||
case "cheater":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "cant-press": //2015.08.08.
|
|
||||||
finalflair="§r(can't press)§r";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
finalflair="";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
|
||||||
return;
|
|
||||||
//PlayerFlairs.put(playername, finalflair);
|
|
||||||
//PlayerUserNames.put(playername, username);
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
|
||||||
p.Flair=finalflair; //2015.08.08.
|
|
||||||
p.UserName=username; //2015.08.08.
|
|
||||||
/*for(Player player : Players)
|
|
||||||
{
|
|
||||||
if(player.getName()==playername)
|
|
||||||
{
|
|
||||||
PlayerFlairs.put(player, finalflair);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
//System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass);
|
|
||||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
|
||||||
//for(Player player : Players)
|
|
||||||
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
//System.out.println("Online player: "+player.getName());
|
|
||||||
//System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername));
|
|
||||||
if(player.getName().equals(playername))
|
|
||||||
{
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
//player.setDisplayName(player.getDisplayName()+finalflair);
|
|
||||||
AppendPlayerDisplayFlair(player, username, finalflair);
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetFlair(Player player)
|
|
||||||
{ //2015.07.16.
|
|
||||||
//String flair=PlayerFlairs.get(player.getName());
|
|
||||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
|
||||||
return flair==null ? "" : flair;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
|
||||||
{
|
|
||||||
//if(IgnoredPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
|
||||||
return;
|
|
||||||
//if(AcceptedPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
|
||||||
//player.setDisplayName(player.getDisplayName()+flair);
|
|
||||||
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
else
|
|
||||||
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//System.out.println("A");
|
|
||||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
|
||||||
String[] colors = color.substring(1).split("§");
|
|
||||||
//String displayname=player.getDisplayName();
|
|
||||||
String displayname=player.getName(); //2015.08.08.
|
|
||||||
ArrayList<Integer> Positions=new ArrayList<>();
|
|
||||||
//System.out.println("B");
|
|
||||||
for(int i=0; i<displayname.length(); i++) {
|
|
||||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
|
||||||
Positions.add(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//System.out.println("C: Positions.size(): "+Positions.size());
|
|
||||||
String finalname="";
|
|
||||||
if(Positions.size()>=colors.length)
|
|
||||||
{
|
|
||||||
//System.out.println("D");
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<Positions.size(); i++)
|
|
||||||
{
|
|
||||||
int pos=Positions.get(i);
|
|
||||||
int nextpos;
|
|
||||||
if(i!=Positions.size()-1)
|
|
||||||
nextpos=Positions.get(i+1);
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
//String substr="§"+colors[x++]+displayname.substring(pos, nextpos-pos)+"§r";
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("F");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//System.out.println("E");
|
|
||||||
Positions.clear();
|
|
||||||
int unit=displayname.length()/colors.length;
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
|
||||||
{
|
|
||||||
int pos=i;
|
|
||||||
int nextpos;
|
|
||||||
if(i<displayname.length()-unit-unit)
|
|
||||||
nextpos=i+unit;
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("G");
|
|
||||||
}
|
|
||||||
//player.setDisplayName(color+displayname+"§r"+flair);
|
|
||||||
//player.setDisplayName(finalname+flair);
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=finalname+flair; //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetColorForTown(String townname)
|
|
||||||
{ //2015.07.20.
|
|
||||||
if(TownColors.containsKey(townname))
|
|
||||||
return TownColors.get(townname);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetPlayerTown(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//List<Town> towns = TownyUniverse.getDataSource().getTowns();
|
|
||||||
try {
|
|
||||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown();
|
|
||||||
return town.getName();
|
|
||||||
} catch (Exception e) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//String color = GetColorForTown(GetPlayerTown(player));
|
|
||||||
//String dname=player.getDisplayName();
|
|
||||||
//player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair)));
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Collection<? extends Player> GetPlayers()
|
|
||||||
{
|
|
||||||
return Instance.getServer().getOnlinePlayers();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,414 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||||
|
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||||
|
|
||||||
|
public class PluginMain extends JavaPlugin
|
||||||
|
{ //Translated to Java: 2015.07.15.
|
||||||
|
//A user, which flair isn't obtainable:
|
||||||
|
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
||||||
|
private static PluginMain Instance;
|
||||||
|
// Fired when plugin is first enabled
|
||||||
|
@Override
|
||||||
|
public void onEnable()
|
||||||
|
{
|
||||||
|
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||||
|
this.getCommand("u").setExecutor(new Commands());
|
||||||
|
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||||
|
Instance=this; //2015.08.08.
|
||||||
|
try {
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
System.out.println("Name: " + name);
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("flairsignored.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||||
|
Thread t=new Thread(r);
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
Boolean stop=false;
|
||||||
|
// Fired when plugin is disabled
|
||||||
|
@Override
|
||||||
|
public void onDisable()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileWriter fw;
|
||||||
|
fw = new FileWriter("flairsaccepted.txt");
|
||||||
|
fw.close();
|
||||||
|
fw = new FileWriter("flairsignored.txt");
|
||||||
|
fw.close();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.AcceptedFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
try {
|
||||||
|
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.IgnoredFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
File file=new File("flairsignored.txt");
|
||||||
|
try {
|
||||||
|
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stop=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ThreadMethod() //<-- 2015.07.16.
|
||||||
|
{
|
||||||
|
while(!stop)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
||||||
|
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
||||||
|
for(Object obj : json)
|
||||||
|
{
|
||||||
|
JSONObject item = (JSONObject)obj;
|
||||||
|
String author=item.getJSONObject("data").getString("author");
|
||||||
|
String ign=item.getJSONObject("data").getString("body");
|
||||||
|
int start = ign.indexOf("IGN:") + "IGN:".length();
|
||||||
|
int end = ign.indexOf(' ', start);
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
end=ign.indexOf('\n', start); //2015.07.15.
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
ign = ign.substring(start);
|
||||||
|
else
|
||||||
|
ign = ign.substring(start, end);
|
||||||
|
ign = ign.trim();
|
||||||
|
if(HasIGFlair(ign))
|
||||||
|
continue;
|
||||||
|
//System.out.println("Author: "+author);
|
||||||
|
try {
|
||||||
|
Thread.sleep(10);
|
||||||
|
} catch(InterruptedException ex) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
||||||
|
String flair;
|
||||||
|
if(flairdata.length > 1) //2015.07.15.
|
||||||
|
flair = flairdata[1];
|
||||||
|
else
|
||||||
|
flair="";
|
||||||
|
if (flair != "-1")
|
||||||
|
flair = flair + "s";
|
||||||
|
else
|
||||||
|
flair = "non-presser";
|
||||||
|
String flairclass;
|
||||||
|
//System.out.println("flairdata.length:"+flairdata.length);
|
||||||
|
if(flairdata.length>2)
|
||||||
|
flairclass = flairdata[2];
|
||||||
|
else
|
||||||
|
flairclass="unknown";
|
||||||
|
SetFlair(ign, flair, flairclass, author);
|
||||||
|
}
|
||||||
|
Thread.sleep(10000);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
||||||
|
{
|
||||||
|
URL url = new URL(urlstr);
|
||||||
|
URLConnection con = url.openConnection();
|
||||||
|
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
||||||
|
InputStream in = con.getInputStream();
|
||||||
|
String encoding = con.getContentEncoding();
|
||||||
|
encoding = encoding == null ? "UTF-8" : encoding;
|
||||||
|
String body = IOUtils.toString(in, encoding);
|
||||||
|
in.close();
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
//It has to store offline player flairs too, therefore it can't use Player object
|
||||||
|
/*public static Map<String, String> PlayerFlairs=new HashMap<String, String>();
|
||||||
|
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
|
||||||
|
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
|
||||||
|
public static ArrayList<Player> Players=new ArrayList<Player>();
|
||||||
|
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
|
||||||
|
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //2015.07.16.
|
||||||
|
//public static Map<String, String> PlayerTowns=new HashMap<String, String>(); //2015.07.20.*/
|
||||||
|
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||||
|
public Boolean HasIGFlair(String playername)
|
||||||
|
{
|
||||||
|
/*Player player=null;
|
||||||
|
for(Player p : Players)
|
||||||
|
{
|
||||||
|
if(p.getName()==playername)
|
||||||
|
{
|
||||||
|
player=p;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(player==null)
|
||||||
|
return false;*/
|
||||||
|
//return PlayerFlairs.containsKey(playername);
|
||||||
|
//return MaybeOfflinePlayer.AllPlayers.containsKey(playername);
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
return p.Flair!=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||||
|
{
|
||||||
|
String finalflair;
|
||||||
|
switch(flairclass)
|
||||||
|
{
|
||||||
|
case "press-1":
|
||||||
|
finalflair="§c("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-2":
|
||||||
|
finalflair="§6("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-3":
|
||||||
|
finalflair="§e("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-4":
|
||||||
|
finalflair="§a("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-5":
|
||||||
|
finalflair="§9("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-6":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "no-press":
|
||||||
|
finalflair="§7(non-pr.)§r";
|
||||||
|
break;
|
||||||
|
case "cheater":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "cant-press": //2015.08.08.
|
||||||
|
finalflair="§r(can't press)§r";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
finalflair="";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||||
|
return;
|
||||||
|
//PlayerFlairs.put(playername, finalflair);
|
||||||
|
//PlayerUserNames.put(playername, username);
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
p.Flair=finalflair; //2015.08.08.
|
||||||
|
p.UserName=username; //2015.08.08.
|
||||||
|
/*for(Player player : Players)
|
||||||
|
{
|
||||||
|
if(player.getName()==playername)
|
||||||
|
{
|
||||||
|
PlayerFlairs.put(player, finalflair);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
//System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass);
|
||||||
|
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||||
|
//for(Player player : Players)
|
||||||
|
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
//System.out.println("Online player: "+player.getName());
|
||||||
|
//System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername));
|
||||||
|
if(player.getName().equals(playername))
|
||||||
|
{
|
||||||
|
//System.out.println("DisplayName: "+player.getDisplayName());
|
||||||
|
//player.setDisplayName(player.getDisplayName()+finalflair);
|
||||||
|
AppendPlayerDisplayFlair(player, username, finalflair);
|
||||||
|
//System.out.println("DisplayName: "+player.getDisplayName());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetFlair(Player player)
|
||||||
|
{ //2015.07.16.
|
||||||
|
//String flair=PlayerFlairs.get(player.getName());
|
||||||
|
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||||
|
return flair==null ? "" : flair;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||||
|
{
|
||||||
|
//if(IgnoredPlayers.contains(player.getName()))
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
||||||
|
return;
|
||||||
|
//if(AcceptedPlayers.contains(player.getName()))
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
||||||
|
//player.setDisplayName(player.getDisplayName()+flair);
|
||||||
|
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
else
|
||||||
|
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//System.out.println("A");
|
||||||
|
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||||
|
String[] colors = color.substring(1).split("§");
|
||||||
|
//String displayname=player.getDisplayName();
|
||||||
|
String displayname=player.getName(); //2015.08.08.
|
||||||
|
ArrayList<Integer> Positions=new ArrayList<>();
|
||||||
|
//System.out.println("B");
|
||||||
|
for(int i=0; i<displayname.length(); i++) {
|
||||||
|
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||||
|
Positions.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//System.out.println("C: Positions.size(): "+Positions.size());
|
||||||
|
String finalname="";
|
||||||
|
if(Positions.size()>=colors.length)
|
||||||
|
{
|
||||||
|
//System.out.println("D");
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<Positions.size(); i++)
|
||||||
|
{
|
||||||
|
int pos=Positions.get(i);
|
||||||
|
int nextpos;
|
||||||
|
if(i!=Positions.size()-1)
|
||||||
|
nextpos=Positions.get(i+1);
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
||||||
|
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
||||||
|
//String substr="§"+colors[x++]+displayname.substring(pos, nextpos-pos)+"§r";
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
//System.out.println("F");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//System.out.println("E");
|
||||||
|
Positions.clear();
|
||||||
|
int unit=displayname.length()/colors.length;
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||||
|
{
|
||||||
|
int pos=i;
|
||||||
|
int nextpos;
|
||||||
|
if(i<displayname.length()-unit-unit)
|
||||||
|
nextpos=i+unit;
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
||||||
|
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
//System.out.println("G");
|
||||||
|
}
|
||||||
|
//player.setDisplayName(color+displayname+"§r"+flair);
|
||||||
|
//player.setDisplayName(finalname+flair);
|
||||||
|
//MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=finalname+flair; //2015.08.08.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetColorForTown(String townname)
|
||||||
|
{ //2015.07.20.
|
||||||
|
if(TownColors.containsKey(townname))
|
||||||
|
return TownColors.get(townname);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetPlayerTown(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//List<Town> towns = TownyUniverse.getDataSource().getTowns();
|
||||||
|
try {
|
||||||
|
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||||
|
return town.getName();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//String color = GetColorForTown(GetPlayerTown(player));
|
||||||
|
//String dname=player.getDisplayName();
|
||||||
|
//player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair)));
|
||||||
|
//MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<? extends Player> GetPlayers()
|
||||||
|
{
|
||||||
|
return Instance.getServer().getOnlinePlayers();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,76 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
//PluginMain.Players.add(p);
|
|
||||||
//event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p));
|
|
||||||
if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20.
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p));
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
//System.out.println("Added player "+p.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
//for(Player player : PluginMain.Players)
|
|
||||||
for(int i=0; i<PluginMain.Players.size();)
|
|
||||||
{
|
|
||||||
Player player=PluginMain.Players.get(i);
|
|
||||||
if(player.getName().equals(event.getPlayer().getName()))
|
|
||||||
{
|
|
||||||
PluginMain.Players.remove(player);
|
|
||||||
//System.out.println("Removed player "+event.getPlayer().getName());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
i++; //If the player is removed, the next item will be on the same index
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
//event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+"(test)> "+event.getMessage()); //2015.08.08.
|
|
||||||
String name;
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,75 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
PluginMain.Players.add(p);
|
|
||||||
//event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p));
|
|
||||||
if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20.
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p));
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
//System.out.println("Added player "+p.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
//for(Player player : PluginMain.Players)
|
|
||||||
for(int i=0; i<PluginMain.Players.size();)
|
|
||||||
{
|
|
||||||
Player player=PluginMain.Players.get(i);
|
|
||||||
if(player.getName().equals(event.getPlayer().getName()))
|
|
||||||
{
|
|
||||||
PluginMain.Players.remove(player);
|
|
||||||
//System.out.println("Removed player "+event.getPlayer().getName());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
i++; //If the player is removed, the next item will be on the same index
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+"(test)> "+event.getMessage()); //2015.08.08.
|
|
||||||
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+"(test)> "+event.getMessage()); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,74 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
PluginMain.Players.add(p);
|
|
||||||
//event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p));
|
|
||||||
if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20.
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p));
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
//System.out.println("Added player "+p.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
//for(Player player : PluginMain.Players)
|
|
||||||
for(int i=0; i<PluginMain.Players.size();)
|
|
||||||
{
|
|
||||||
Player player=PluginMain.Players.get(i);
|
|
||||||
if(player.getName().equals(event.getPlayer().getName()))
|
|
||||||
{
|
|
||||||
PluginMain.Players.remove(player);
|
|
||||||
//System.out.println("Removed player "+event.getPlayer().getName());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
i++; //If the player is removed, the next item will be on the same index
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
//event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+"(test)> "+event.getMessage()); //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
import de.inventivegames.TellRawAutoMessage.Reflection;
|
||||||
|
|
||||||
|
public class PlayerListener implements Listener
|
||||||
|
{ //2015.07.16.
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event)
|
||||||
|
{
|
||||||
|
Player p=event.getPlayer();
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08.
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); //2015.08.08.
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
PluginMain.AppendPlayerDisplayFlair(p, mp.UserName, mp.Flair);
|
||||||
|
else
|
||||||
|
{ //2015.07.20.
|
||||||
|
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
||||||
|
sendRawMessage(p, json);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerLeave(PlayerQuitEvent event)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerChat(AsyncPlayerChatEvent event)
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer player = MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName());
|
||||||
|
String flair=player.Flair; //2015.08.08.
|
||||||
|
if(flair==null || !player.AcceptedFlair)
|
||||||
|
flair=""; //2015.08.08.
|
||||||
|
String message=event.getMessage(); //2015.08.08.
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{ //2015.08.08.
|
||||||
|
int index=0;
|
||||||
|
while((index = message.indexOf(p.getName())!=-1)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
||||||
|
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
||||||
|
public static void sendRawMessage(Player player, String message)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
System.out.println("1");
|
||||||
|
Object handle = Reflection.getHandle(player);
|
||||||
|
System.out.println("2");
|
||||||
|
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
|
System.out.println("3");
|
||||||
|
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
||||||
|
System.out.println("4");
|
||||||
|
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
||||||
|
System.out.println("5");
|
||||||
|
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
||||||
|
System.out.println("6");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,347 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||||
|
|
||||||
|
public class PluginMain extends JavaPlugin
|
||||||
|
{ //Translated to Java: 2015.07.15.
|
||||||
|
//A user, which flair isn't obtainable:
|
||||||
|
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
||||||
|
private static PluginMain Instance;
|
||||||
|
// Fired when plugin is first enabled
|
||||||
|
@Override
|
||||||
|
public void onEnable()
|
||||||
|
{
|
||||||
|
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||||
|
this.getCommand("u").setExecutor(new Commands());
|
||||||
|
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||||
|
Instance=this; //2015.08.08.
|
||||||
|
try {
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
//System.out.println("Name: " + name);
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("flairsignored.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||||
|
Thread t=new Thread(r);
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
Boolean stop=false;
|
||||||
|
// Fired when plugin is disabled
|
||||||
|
@Override
|
||||||
|
public void onDisable()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileWriter fw;
|
||||||
|
fw = new FileWriter("flairsaccepted.txt");
|
||||||
|
fw.close();
|
||||||
|
fw = new FileWriter("flairsignored.txt");
|
||||||
|
fw.close();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.AcceptedFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
}
|
||||||
|
bw.close();
|
||||||
|
file=new File("flairsignored.txt");
|
||||||
|
bw = new BufferedWriter(new FileWriter(file, true));
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.IgnoredFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
}
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
stop=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ThreadMethod() //<-- 2015.07.16.
|
||||||
|
{
|
||||||
|
while(!stop)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
||||||
|
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
||||||
|
for(Object obj : json)
|
||||||
|
{
|
||||||
|
JSONObject item = (JSONObject)obj;
|
||||||
|
String author=item.getJSONObject("data").getString("author");
|
||||||
|
String ign=item.getJSONObject("data").getString("body");
|
||||||
|
int start = ign.indexOf("IGN:") + "IGN:".length();
|
||||||
|
int end = ign.indexOf(' ', start);
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
end=ign.indexOf('\n', start); //2015.07.15.
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
ign = ign.substring(start);
|
||||||
|
else
|
||||||
|
ign = ign.substring(start, end);
|
||||||
|
ign = ign.trim();
|
||||||
|
if(HasIGFlair(ign))
|
||||||
|
continue;
|
||||||
|
try {
|
||||||
|
Thread.sleep(10);
|
||||||
|
} catch(InterruptedException ex) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
||||||
|
String flair;
|
||||||
|
if(flairdata.length > 1) //2015.07.15.
|
||||||
|
flair = flairdata[1];
|
||||||
|
else
|
||||||
|
flair="";
|
||||||
|
if (flair != "-1")
|
||||||
|
flair = flair + "s";
|
||||||
|
else
|
||||||
|
flair = "non-presser";
|
||||||
|
String flairclass;
|
||||||
|
if(flairdata.length>2)
|
||||||
|
flairclass = flairdata[2];
|
||||||
|
else
|
||||||
|
flairclass="unknown";
|
||||||
|
SetFlair(ign, flair, flairclass, author);
|
||||||
|
}
|
||||||
|
Thread.sleep(10000);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Exception LastException; //2015.08.09.
|
||||||
|
|
||||||
|
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
||||||
|
{
|
||||||
|
URL url = new URL(urlstr);
|
||||||
|
URLConnection con = url.openConnection();
|
||||||
|
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
||||||
|
InputStream in = con.getInputStream();
|
||||||
|
String encoding = con.getContentEncoding();
|
||||||
|
encoding = encoding == null ? "UTF-8" : encoding;
|
||||||
|
String body = IOUtils.toString(in, encoding);
|
||||||
|
in.close();
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||||
|
public Boolean HasIGFlair(String playername)
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
return p.Flair!=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||||
|
{
|
||||||
|
String finalflair;
|
||||||
|
switch(flairclass)
|
||||||
|
{
|
||||||
|
case "press-1":
|
||||||
|
finalflair="§c("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-2":
|
||||||
|
finalflair="§6("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-3":
|
||||||
|
finalflair="§e("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-4":
|
||||||
|
finalflair="§a("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-5":
|
||||||
|
finalflair="§9("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-6":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "no-press":
|
||||||
|
finalflair="§7(non-pr.)§r";
|
||||||
|
break;
|
||||||
|
case "cheater":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "cant-press": //2015.08.08.
|
||||||
|
finalflair="§r(can't press)§r";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
finalflair="";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||||
|
return;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
p.Flair=finalflair; //2015.08.08.
|
||||||
|
p.UserName=username; //2015.08.08.
|
||||||
|
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||||
|
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(player.getName().equals(playername))
|
||||||
|
{
|
||||||
|
AppendPlayerDisplayFlair(player, username, finalflair);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetFlair(Player player)
|
||||||
|
{ //2015.07.16.
|
||||||
|
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||||
|
return flair==null ? "" : flair;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||||
|
{
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
||||||
|
return;
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
||||||
|
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
else
|
||||||
|
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||||
|
String[] colors = color.substring(1).split("§");
|
||||||
|
String displayname=player.getName(); //2015.08.08.
|
||||||
|
ArrayList<Integer> Positions=new ArrayList<>();
|
||||||
|
for(int i=0; i<displayname.length(); i++) {
|
||||||
|
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||||
|
Positions.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String finalname=""; //TODO
|
||||||
|
if(Positions.size()>=colors.length)
|
||||||
|
{
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<Positions.size(); i++)
|
||||||
|
{
|
||||||
|
int pos=Positions.get(i);
|
||||||
|
int nextpos;
|
||||||
|
if(i!=Positions.size()-1)
|
||||||
|
nextpos=Positions.get(i+1);
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Positions.clear();
|
||||||
|
int unit=displayname.length()/colors.length;
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||||
|
{
|
||||||
|
int pos=i;
|
||||||
|
int nextpos;
|
||||||
|
if(i<displayname.length()-unit-unit)
|
||||||
|
nextpos=i+unit;
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetColorForTown(String townname)
|
||||||
|
{ //2015.07.20.
|
||||||
|
if(TownColors.containsKey(townname))
|
||||||
|
return TownColors.get(townname);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetPlayerTown(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
try {
|
||||||
|
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||||
|
return town.getName();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<? extends Player> GetPlayers()
|
||||||
|
{
|
||||||
|
return Instance.getServer().getOnlinePlayers();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,420 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
|
||||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
|
||||||
|
|
||||||
public class PluginMain extends JavaPlugin
|
|
||||||
{ //Translated to Java: 2015.07.15.
|
|
||||||
//A user, which flair isn't obtainable:
|
|
||||||
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
|
||||||
// Fired when plugin is first enabled
|
|
||||||
@Override
|
|
||||||
public void onEnable()
|
|
||||||
{
|
|
||||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
|
||||||
//System.out.println("Original C# version: http://pastebin.com/tX8xCPbp");
|
|
||||||
//System.out.println("The Java version is... Also made by the same person.");
|
|
||||||
//System.out.println("With the help of StackOverflow and similar.");
|
|
||||||
/*catch(MalformedURLException e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
catch(IOException e)
|
|
||||||
{
|
|
||||||
}*/
|
|
||||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
|
||||||
//System.out.println("Registering commands...");
|
|
||||||
this.getCommand("u").setExecutor(new Commands());
|
|
||||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
|
||||||
try {
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//AcceptedPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("flairsignored.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//IgnoredPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
|
||||||
String line;
|
|
||||||
while((line=br.readLine())!=null)
|
|
||||||
{
|
|
||||||
String[] s=line.split(" ");
|
|
||||||
TownColors.put(s[0], s[1]);
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//System.out.println("Registering done.");
|
|
||||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
|
||||||
Thread t=new Thread(r);
|
|
||||||
t.start();
|
|
||||||
}
|
|
||||||
Boolean stop=false;
|
|
||||||
// Fired when plugin is disabled
|
|
||||||
@Override
|
|
||||||
public void onDisable()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
FileWriter fw;
|
|
||||||
fw = new FileWriter("flairsaccepted.txt");
|
|
||||||
fw.close();
|
|
||||||
fw = new FileWriter("flairsignored.txt");
|
|
||||||
fw.close();
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//for(String player : AcceptedPlayers)
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.AcceptedFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.IgnoredFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsignored.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stop=true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ThreadMethod() //<-- 2015.07.16.
|
|
||||||
{
|
|
||||||
/*System.out.println("Sleeping for 5 seconds..."); //2015.07.20.
|
|
||||||
try {
|
|
||||||
Thread.sleep(5000);
|
|
||||||
} catch (InterruptedException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
} //2015.07.20.*/
|
|
||||||
while(!stop)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
|
||||||
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
|
||||||
for(Object obj : json)
|
|
||||||
{
|
|
||||||
JSONObject item = (JSONObject)obj;
|
|
||||||
String author=item.getJSONObject("data").getString("author");
|
|
||||||
String ign=item.getJSONObject("data").getString("body");
|
|
||||||
int start = ign.indexOf("IGN:") + "IGN:".length();
|
|
||||||
int end = ign.indexOf(' ', start);
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
end=ign.indexOf('\n', start); //2015.07.15.
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
ign = ign.substring(start);
|
|
||||||
else
|
|
||||||
ign = ign.substring(start, end);
|
|
||||||
ign = ign.trim();
|
|
||||||
if(HasIGFlair(ign))
|
|
||||||
continue;
|
|
||||||
//System.out.println("Author: "+author);
|
|
||||||
try {
|
|
||||||
Thread.sleep(10);
|
|
||||||
} catch(InterruptedException ex) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
|
||||||
String flair;
|
|
||||||
if(flairdata.length > 1) //2015.07.15.
|
|
||||||
flair = flairdata[1];
|
|
||||||
else
|
|
||||||
flair="";
|
|
||||||
if (flair != "-1")
|
|
||||||
flair = flair + "s";
|
|
||||||
else
|
|
||||||
flair = "non-presser";
|
|
||||||
String flairclass;
|
|
||||||
//System.out.println("flairdata.length:"+flairdata.length);
|
|
||||||
if(flairdata.length>2)
|
|
||||||
flairclass = flairdata[2];
|
|
||||||
else
|
|
||||||
flairclass="unknown";
|
|
||||||
SetFlair(ign, flair, flairclass, author);
|
|
||||||
}
|
|
||||||
Thread.sleep(10000);
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
|
||||||
{
|
|
||||||
URL url = new URL(urlstr);
|
|
||||||
URLConnection con = url.openConnection();
|
|
||||||
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
|
||||||
InputStream in = con.getInputStream();
|
|
||||||
String encoding = con.getContentEncoding();
|
|
||||||
encoding = encoding == null ? "UTF-8" : encoding;
|
|
||||||
String body = IOUtils.toString(in, encoding);
|
|
||||||
in.close();
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
//It has to store offline player flairs too, therefore it can't use Player object
|
|
||||||
/*public static Map<String, String> PlayerFlairs=new HashMap<String, String>();
|
|
||||||
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
|
|
||||||
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
|
|
||||||
public static ArrayList<Player> Players=new ArrayList<Player>();
|
|
||||||
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
//public static Map<String, String> PlayerTowns=new HashMap<String, String>(); //2015.07.20.*/
|
|
||||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
|
||||||
public Boolean HasIGFlair(String playername)
|
|
||||||
{
|
|
||||||
/*Player player=null;
|
|
||||||
for(Player p : Players)
|
|
||||||
{
|
|
||||||
if(p.getName()==playername)
|
|
||||||
{
|
|
||||||
player=p;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(player==null)
|
|
||||||
return false;*/
|
|
||||||
//return PlayerFlairs.containsKey(playername);
|
|
||||||
return MaybeOfflinePlayer.AllPlayers.containsKey(playername);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
|
||||||
{
|
|
||||||
String finalflair;
|
|
||||||
switch(flairclass)
|
|
||||||
{
|
|
||||||
case "press-1":
|
|
||||||
finalflair="§c("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-2":
|
|
||||||
finalflair="§6("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-3":
|
|
||||||
finalflair="§e("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-4":
|
|
||||||
finalflair="§a("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-5":
|
|
||||||
finalflair="§9("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-6":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "no-press":
|
|
||||||
finalflair="§7(non-pr.)§r";
|
|
||||||
break;
|
|
||||||
case "cheater":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "cant-press": //2015.08.08.
|
|
||||||
finalflair="§r(can't press)§r";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
finalflair="";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
|
||||||
return;
|
|
||||||
//PlayerFlairs.put(playername, finalflair);
|
|
||||||
//PlayerUserNames.put(playername, username);
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
|
||||||
p.Flair=finalflair; //2015.08.08.
|
|
||||||
p.UserName=username; //2015.08.08.
|
|
||||||
/*for(Player player : Players)
|
|
||||||
{
|
|
||||||
if(player.getName()==playername)
|
|
||||||
{
|
|
||||||
PlayerFlairs.put(player, finalflair);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
//System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass);
|
|
||||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
|
||||||
//for(Player player : Players)
|
|
||||||
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
//System.out.println("Online player: "+player.getName());
|
|
||||||
//System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername));
|
|
||||||
if(player.getName().equals(playername))
|
|
||||||
{
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
//player.setDisplayName(player.getDisplayName()+finalflair);
|
|
||||||
AppendPlayerDisplayFlair(player, username, finalflair);
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetFlair(Player player)
|
|
||||||
{ //2015.07.16.
|
|
||||||
//String flair=PlayerFlairs.get(player.getName());
|
|
||||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
|
||||||
return flair==null ? "" : flair;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
|
||||||
{
|
|
||||||
//if(IgnoredPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
|
||||||
return;
|
|
||||||
//if(AcceptedPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
|
||||||
//player.setDisplayName(player.getDisplayName()+flair);
|
|
||||||
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
else
|
|
||||||
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//System.out.println("A");
|
|
||||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
|
||||||
String[] colors = color.substring(1).split("§");
|
|
||||||
//String displayname=player.getDisplayName();
|
|
||||||
String displayname=player.getName(); //2015.08.08.
|
|
||||||
ArrayList<Integer> Positions=new ArrayList<>();
|
|
||||||
//System.out.println("B");
|
|
||||||
for(int i=0; i<displayname.length(); i++) {
|
|
||||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
|
||||||
Positions.add(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//System.out.println("C: Positions.size(): "+Positions.size());
|
|
||||||
String finalname="";
|
|
||||||
if(Positions.size()>=colors.length)
|
|
||||||
{
|
|
||||||
//System.out.println("D");
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<Positions.size(); i++)
|
|
||||||
{
|
|
||||||
int pos=Positions.get(i);
|
|
||||||
int nextpos;
|
|
||||||
if(i!=Positions.size()-1)
|
|
||||||
nextpos=Positions.get(i+1);
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
//String substr="§"+colors[x++]+displayname.substring(pos, nextpos-pos)+"§r";
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("F");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//System.out.println("E");
|
|
||||||
Positions.clear();
|
|
||||||
int unit=displayname.length()/colors.length;
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
|
||||||
{
|
|
||||||
int pos=i;
|
|
||||||
int nextpos;
|
|
||||||
if(i<displayname.length()-unit-unit)
|
|
||||||
nextpos=i+unit;
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("G");
|
|
||||||
}
|
|
||||||
//player.setDisplayName(color+displayname+"§r"+flair);
|
|
||||||
//player.setDisplayName(finalname+flair);
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=finalname+flair; //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetColorForTown(String townname)
|
|
||||||
{ //2015.07.20.
|
|
||||||
if(TownColors.containsKey(townname))
|
|
||||||
return TownColors.get(townname);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetPlayerTown(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//List<Town> towns = TownyUniverse.getDataSource().getTowns();
|
|
||||||
try {
|
|
||||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown();
|
|
||||||
return town.getName();
|
|
||||||
} catch (Exception e) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
String color = GetColorForTown(GetPlayerTown(player));
|
|
||||||
String dname=player.getDisplayName();
|
|
||||||
//player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair)));
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08.
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,348 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||||
|
|
||||||
|
public class PluginMain extends JavaPlugin
|
||||||
|
{ //Translated to Java: 2015.07.15.
|
||||||
|
//A user, which flair isn't obtainable:
|
||||||
|
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
||||||
|
private static PluginMain Instance;
|
||||||
|
// Fired when plugin is first enabled
|
||||||
|
@Override
|
||||||
|
public void onEnable()
|
||||||
|
{
|
||||||
|
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||||
|
this.getCommand("u").setExecutor(new Commands());
|
||||||
|
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||||
|
Instance=this; //2015.08.08.
|
||||||
|
try {
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
System.out.println("Name: " + name);
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("flairsignored.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||||
|
Thread t=new Thread(r);
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
Boolean stop=false;
|
||||||
|
// Fired when plugin is disabled
|
||||||
|
@Override
|
||||||
|
public void onDisable()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileWriter fw;
|
||||||
|
fw = new FileWriter("flairsaccepted.txt");
|
||||||
|
fw.close();
|
||||||
|
fw = new FileWriter("flairsignored.txt");
|
||||||
|
fw.close();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.AcceptedFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
try {
|
||||||
|
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.IgnoredFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
File file=new File("flairsignored.txt");
|
||||||
|
try {
|
||||||
|
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stop=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ThreadMethod() //<-- 2015.07.16.
|
||||||
|
{
|
||||||
|
while(!stop)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
||||||
|
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
||||||
|
for(Object obj : json)
|
||||||
|
{
|
||||||
|
JSONObject item = (JSONObject)obj;
|
||||||
|
String author=item.getJSONObject("data").getString("author");
|
||||||
|
String ign=item.getJSONObject("data").getString("body");
|
||||||
|
int start = ign.indexOf("IGN:") + "IGN:".length();
|
||||||
|
int end = ign.indexOf(' ', start);
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
end=ign.indexOf('\n', start); //2015.07.15.
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
ign = ign.substring(start);
|
||||||
|
else
|
||||||
|
ign = ign.substring(start, end);
|
||||||
|
ign = ign.trim();
|
||||||
|
if(HasIGFlair(ign))
|
||||||
|
continue;
|
||||||
|
try {
|
||||||
|
Thread.sleep(10);
|
||||||
|
} catch(InterruptedException ex) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
||||||
|
String flair;
|
||||||
|
if(flairdata.length > 1) //2015.07.15.
|
||||||
|
flair = flairdata[1];
|
||||||
|
else
|
||||||
|
flair="";
|
||||||
|
if (flair != "-1")
|
||||||
|
flair = flair + "s";
|
||||||
|
else
|
||||||
|
flair = "non-presser";
|
||||||
|
String flairclass;
|
||||||
|
if(flairdata.length>2)
|
||||||
|
flairclass = flairdata[2];
|
||||||
|
else
|
||||||
|
flairclass="unknown";
|
||||||
|
SetFlair(ign, flair, flairclass, author);
|
||||||
|
}
|
||||||
|
Thread.sleep(10000);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
||||||
|
{
|
||||||
|
URL url = new URL(urlstr);
|
||||||
|
URLConnection con = url.openConnection();
|
||||||
|
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
||||||
|
InputStream in = con.getInputStream();
|
||||||
|
String encoding = con.getContentEncoding();
|
||||||
|
encoding = encoding == null ? "UTF-8" : encoding;
|
||||||
|
String body = IOUtils.toString(in, encoding);
|
||||||
|
in.close();
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||||
|
public Boolean HasIGFlair(String playername)
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
return p.Flair!=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||||
|
{
|
||||||
|
String finalflair;
|
||||||
|
switch(flairclass)
|
||||||
|
{
|
||||||
|
case "press-1":
|
||||||
|
finalflair="§c("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-2":
|
||||||
|
finalflair="§6("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-3":
|
||||||
|
finalflair="§e("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-4":
|
||||||
|
finalflair="§a("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-5":
|
||||||
|
finalflair="§9("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-6":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "no-press":
|
||||||
|
finalflair="§7(non-pr.)§r";
|
||||||
|
break;
|
||||||
|
case "cheater":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "cant-press": //2015.08.08.
|
||||||
|
finalflair="§r(can't press)§r";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
finalflair="";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||||
|
return;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
p.Flair=finalflair; //2015.08.08.
|
||||||
|
p.UserName=username; //2015.08.08.
|
||||||
|
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||||
|
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(player.getName().equals(playername))
|
||||||
|
{
|
||||||
|
AppendPlayerDisplayFlair(player, username, finalflair);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetFlair(Player player)
|
||||||
|
{ //2015.07.16.
|
||||||
|
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||||
|
return flair==null ? "" : flair;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||||
|
{
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
||||||
|
return;
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
||||||
|
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
else
|
||||||
|
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||||
|
String[] colors = color.substring(1).split("§");
|
||||||
|
String displayname=player.getName(); //2015.08.08.
|
||||||
|
ArrayList<Integer> Positions=new ArrayList<>();
|
||||||
|
for(int i=0; i<displayname.length(); i++) {
|
||||||
|
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||||
|
Positions.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String finalname="";
|
||||||
|
if(Positions.size()>=colors.length)
|
||||||
|
{
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<Positions.size(); i++)
|
||||||
|
{
|
||||||
|
int pos=Positions.get(i);
|
||||||
|
int nextpos;
|
||||||
|
if(i!=Positions.size()-1)
|
||||||
|
nextpos=Positions.get(i+1);
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Positions.clear();
|
||||||
|
int unit=displayname.length()/colors.length;
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||||
|
{
|
||||||
|
int pos=i;
|
||||||
|
int nextpos;
|
||||||
|
if(i<displayname.length()-unit-unit)
|
||||||
|
nextpos=i+unit;
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetColorForTown(String townname)
|
||||||
|
{ //2015.07.20.
|
||||||
|
if(TownColors.containsKey(townname))
|
||||||
|
return TownColors.get(townname);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetPlayerTown(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
try {
|
||||||
|
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||||
|
return town.getName();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<? extends Player> GetPlayers()
|
||||||
|
{
|
||||||
|
return Instance.getServer().getOnlinePlayers();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,347 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.CommandSource;
|
||||||
|
import com.earth2me.essentials.User;
|
||||||
|
import com.earth2me.essentials.commands.IEssentialsCommand;
|
||||||
|
|
||||||
|
import net.ess3.api.ITeleport;
|
||||||
|
import net.ess3.api.IUser;
|
||||||
|
import net.ess3.api.MaxMoneyException;
|
||||||
|
|
||||||
|
public class Essentials implements IUser
|
||||||
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addMail(String arg0) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canAfford(BigDecimal arg0) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canBuild() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean canSpawnItem(int arg0) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delHome(String arg0) throws Exception {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void enableInvulnerabilityAfterTeleport() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Player getBase() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> getConfigKeys() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getConfigMap() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getConfigMap(String arg0) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getGroup() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location getHome(String arg0) throws Exception {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location getHome(Location arg0) throws Exception {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getHomes() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getJail() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location getLastLocation() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getLastTeleportTimestamp() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location getLogoutLocation() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getMails() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BigDecimal getMoney() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandSource getSource() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ITeleport getTeleport() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getTeleportRequestTime() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void giveMoney(BigDecimal arg0) throws MaxMoneyException {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void giveMoney(BigDecimal arg0, CommandSource arg1)
|
||||||
|
throws MaxMoneyException {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasHome() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasInvulnerabilityAfterTeleport() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void healCooldown() throws Exception {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean inGroup(String arg0) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAfk() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAuthorized(String arg0) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAuthorized(IEssentialsCommand arg0) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAuthorized(IEssentialsCommand arg0, String arg1) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isGodModeEnabled() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isHidden() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isIgnoreExempt() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isVanished() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void payUser(User arg0, BigDecimal arg1) throws Exception {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void requestTeleport(User arg0, boolean arg1) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resetInvulnerabilityAfterTeleport() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMessage(String arg0) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setAfk(boolean arg0) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setConfigProperty(String arg0, Object arg1) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHidden(boolean arg0) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHome(String arg0, Location arg1) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setJail(String arg0) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setLastLocation() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setLastTeleportTimestamp(long arg0) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setLogoutLocation() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMoney(BigDecimal arg0) throws MaxMoneyException {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setVanished(boolean arg0) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void takeMoney(BigDecimal arg0) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void takeMoney(BigDecimal arg0, CommandSource arg1) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,425 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
|
||||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
|
||||||
|
|
||||||
public class PluginMain extends JavaPlugin
|
|
||||||
{ //Translated to Java: 2015.07.15.
|
|
||||||
//A user, which flair isn't obtainable:
|
|
||||||
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
|
||||||
// Fired when plugin is first enabled
|
|
||||||
@Override
|
|
||||||
public void onEnable()
|
|
||||||
{
|
|
||||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
|
||||||
//System.out.println("Original C# version: http://pastebin.com/tX8xCPbp");
|
|
||||||
//System.out.println("The Java version is... Also made by the same person.");
|
|
||||||
//System.out.println("With the help of StackOverflow and similar.");
|
|
||||||
/*catch(MalformedURLException e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
catch(IOException e)
|
|
||||||
{
|
|
||||||
}*/
|
|
||||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
|
||||||
//System.out.println("Registering commands...");
|
|
||||||
this.getCommand("u").setExecutor(new Commands());
|
|
||||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
|
||||||
try {
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//AcceptedPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("flairsignored.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//IgnoredPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
|
||||||
String line;
|
|
||||||
while((line=br.readLine())!=null)
|
|
||||||
{
|
|
||||||
String[] s=line.split(" ");
|
|
||||||
TownColors.put(s[0], s[1]);
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//System.out.println("Registering done.");
|
|
||||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
|
||||||
Thread t=new Thread(r);
|
|
||||||
t.start();
|
|
||||||
}
|
|
||||||
Boolean stop=false;
|
|
||||||
// Fired when plugin is disabled
|
|
||||||
@Override
|
|
||||||
public void onDisable()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
FileWriter fw;
|
|
||||||
fw = new FileWriter("flairsaccepted.txt");
|
|
||||||
fw.close();
|
|
||||||
fw = new FileWriter("flairsignored.txt");
|
|
||||||
fw.close();
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//for(String player : AcceptedPlayers)
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.AcceptedFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.IgnoredFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsignored.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stop=true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ThreadMethod() //<-- 2015.07.16.
|
|
||||||
{
|
|
||||||
/*System.out.println("Sleeping for 5 seconds..."); //2015.07.20.
|
|
||||||
try {
|
|
||||||
Thread.sleep(5000);
|
|
||||||
} catch (InterruptedException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
} //2015.07.20.*/
|
|
||||||
while(!stop)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
|
||||||
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
|
||||||
for(Object obj : json)
|
|
||||||
{
|
|
||||||
JSONObject item = (JSONObject)obj;
|
|
||||||
String author=item.getJSONObject("data").getString("author");
|
|
||||||
String ign=item.getJSONObject("data").getString("body");
|
|
||||||
int start = ign.indexOf("IGN:") + "IGN:".length();
|
|
||||||
int end = ign.indexOf(' ', start);
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
end=ign.indexOf('\n', start); //2015.07.15.
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
ign = ign.substring(start);
|
|
||||||
else
|
|
||||||
ign = ign.substring(start, end);
|
|
||||||
ign = ign.trim();
|
|
||||||
if(HasIGFlair(ign))
|
|
||||||
continue;
|
|
||||||
//System.out.println("Author: "+author);
|
|
||||||
try {
|
|
||||||
Thread.sleep(10);
|
|
||||||
} catch(InterruptedException ex) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
|
||||||
String flair;
|
|
||||||
if(flairdata.length > 1) //2015.07.15.
|
|
||||||
flair = flairdata[1];
|
|
||||||
else
|
|
||||||
flair="";
|
|
||||||
if (flair != "-1")
|
|
||||||
flair = flair + "s";
|
|
||||||
else
|
|
||||||
flair = "non-presser";
|
|
||||||
String flairclass;
|
|
||||||
//System.out.println("flairdata.length:"+flairdata.length);
|
|
||||||
if(flairdata.length>2)
|
|
||||||
flairclass = flairdata[2];
|
|
||||||
else
|
|
||||||
flairclass="unknown";
|
|
||||||
SetFlair(ign, flair, flairclass, author);
|
|
||||||
}
|
|
||||||
Thread.sleep(10000);
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
|
||||||
{
|
|
||||||
URL url = new URL(urlstr);
|
|
||||||
URLConnection con = url.openConnection();
|
|
||||||
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
|
||||||
InputStream in = con.getInputStream();
|
|
||||||
String encoding = con.getContentEncoding();
|
|
||||||
encoding = encoding == null ? "UTF-8" : encoding;
|
|
||||||
String body = IOUtils.toString(in, encoding);
|
|
||||||
in.close();
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
//It has to store offline player flairs too, therefore it can't use Player object
|
|
||||||
/*public static Map<String, String> PlayerFlairs=new HashMap<String, String>();
|
|
||||||
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
|
|
||||||
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
|
|
||||||
public static ArrayList<Player> Players=new ArrayList<Player>();
|
|
||||||
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
//public static Map<String, String> PlayerTowns=new HashMap<String, String>(); //2015.07.20.*/
|
|
||||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
|
||||||
public Boolean HasIGFlair(String playername)
|
|
||||||
{
|
|
||||||
/*Player player=null;
|
|
||||||
for(Player p : Players)
|
|
||||||
{
|
|
||||||
if(p.getName()==playername)
|
|
||||||
{
|
|
||||||
player=p;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(player==null)
|
|
||||||
return false;*/
|
|
||||||
//return PlayerFlairs.containsKey(playername);
|
|
||||||
return MaybeOfflinePlayer.AllPlayers.containsKey(playername);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
|
||||||
{
|
|
||||||
String finalflair;
|
|
||||||
switch(flairclass)
|
|
||||||
{
|
|
||||||
case "press-1":
|
|
||||||
finalflair="§c("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-2":
|
|
||||||
finalflair="§6("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-3":
|
|
||||||
finalflair="§e("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-4":
|
|
||||||
finalflair="§a("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-5":
|
|
||||||
finalflair="§9("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-6":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "no-press":
|
|
||||||
finalflair="§7(non-pr.)§r";
|
|
||||||
break;
|
|
||||||
case "cheater":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "cant-press": //2015.08.08.
|
|
||||||
finalflair="§r(can't press)§r";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
finalflair="";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
|
||||||
return;
|
|
||||||
//PlayerFlairs.put(playername, finalflair);
|
|
||||||
//PlayerUserNames.put(playername, username);
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
|
||||||
p.Flair=finalflair; //2015.08.08.
|
|
||||||
p.UserName=username; //2015.08.08.
|
|
||||||
/*for(Player player : Players)
|
|
||||||
{
|
|
||||||
if(player.getName()==playername)
|
|
||||||
{
|
|
||||||
PlayerFlairs.put(player, finalflair);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
//System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass);
|
|
||||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
|
||||||
//for(Player player : Players)
|
|
||||||
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
//System.out.println("Online player: "+player.getName());
|
|
||||||
//System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername));
|
|
||||||
if(player.getName().equals(playername))
|
|
||||||
{
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
//player.setDisplayName(player.getDisplayName()+finalflair);
|
|
||||||
AppendPlayerDisplayFlair(player, username, finalflair);
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetFlair(Player player)
|
|
||||||
{ //2015.07.16.
|
|
||||||
//String flair=PlayerFlairs.get(player.getName());
|
|
||||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
|
||||||
return flair==null ? "" : flair;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
|
||||||
{
|
|
||||||
//if(IgnoredPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
|
||||||
return;
|
|
||||||
//if(AcceptedPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
|
||||||
//player.setDisplayName(player.getDisplayName()+flair);
|
|
||||||
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
else
|
|
||||||
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//System.out.println("A");
|
|
||||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
|
||||||
String[] colors = color.substring(1).split("§");
|
|
||||||
//String displayname=player.getDisplayName();
|
|
||||||
String displayname=player.getName(); //2015.08.08.
|
|
||||||
ArrayList<Integer> Positions=new ArrayList<>();
|
|
||||||
//System.out.println("B");
|
|
||||||
for(int i=0; i<displayname.length(); i++) {
|
|
||||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
|
||||||
Positions.add(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//System.out.println("C: Positions.size(): "+Positions.size());
|
|
||||||
String finalname="";
|
|
||||||
if(Positions.size()>=colors.length)
|
|
||||||
{
|
|
||||||
//System.out.println("D");
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<Positions.size(); i++)
|
|
||||||
{
|
|
||||||
int pos=Positions.get(i);
|
|
||||||
int nextpos;
|
|
||||||
if(i!=Positions.size()-1)
|
|
||||||
nextpos=Positions.get(i+1);
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
//String substr="§"+colors[x++]+displayname.substring(pos, nextpos-pos)+"§r";
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("F");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//System.out.println("E");
|
|
||||||
Positions.clear();
|
|
||||||
int unit=displayname.length()/colors.length;
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
|
||||||
{
|
|
||||||
int pos=i;
|
|
||||||
int nextpos;
|
|
||||||
if(i<displayname.length()-unit-unit)
|
|
||||||
nextpos=i+unit;
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("G");
|
|
||||||
}
|
|
||||||
//player.setDisplayName(color+displayname+"§r"+flair);
|
|
||||||
//player.setDisplayName(finalname+flair);
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=finalname+flair; //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetColorForTown(String townname)
|
|
||||||
{ //2015.07.20.
|
|
||||||
if(TownColors.containsKey(townname))
|
|
||||||
return TownColors.get(townname);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetPlayerTown(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//List<Town> towns = TownyUniverse.getDataSource().getTowns();
|
|
||||||
try {
|
|
||||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown();
|
|
||||||
return town.getName();
|
|
||||||
} catch (Exception e) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
String color = GetColorForTown(GetPlayerTown(player));
|
|
||||||
String dname=player.getDisplayName();
|
|
||||||
//player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair)));
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void GetPlayers()
|
|
||||||
{
|
|
||||||
getServer().getOnlinePlayers();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,145 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;*/
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.*/
|
||||||
|
else if(args[0].toLowerCase()=="admin")
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage(msg);
|
||||||
|
else
|
||||||
|
System.out.println(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "reload":
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "playerinfo":
|
||||||
|
DoPlayerInfo(player, args);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoPlayerInfo(Player player, String[] args)
|
||||||
|
{
|
||||||
|
//args[0] is "admin" - args[1] is "playerinfo"
|
||||||
|
s
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,6 +22,7 @@ import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
import com.palmergames.bukkit.towny.object.TownyUniverse;
|
||||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||||
|
|
||||||
public class PluginMain extends JavaPlugin
|
public class PluginMain extends JavaPlugin
|
||||||
|
@ -34,15 +35,6 @@ public class PluginMain extends JavaPlugin
|
||||||
public void onEnable()
|
public void onEnable()
|
||||||
{
|
{
|
||||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||||
//System.out.println("Original C# version: http://pastebin.com/tX8xCPbp");
|
|
||||||
//System.out.println("The Java version is... Also made by the same person.");
|
|
||||||
//System.out.println("With the help of StackOverflow and similar.");
|
|
||||||
/*catch(MalformedURLException e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
catch(IOException e)
|
|
||||||
{
|
|
||||||
}*/
|
|
||||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||||
//System.out.println("Registering commands...");
|
//System.out.println("Registering commands...");
|
||||||
this.getCommand("u").setExecutor(new Commands());
|
this.getCommand("u").setExecutor(new Commands());
|
||||||
|
@ -121,7 +113,7 @@ public class PluginMain extends JavaPlugin
|
||||||
File file=new File("flairsaccepted.txt");
|
File file=new File("flairsaccepted.txt");
|
||||||
try {
|
try {
|
||||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||||
bw.write(player+"\n");
|
bw.write(player.PlayerName+"\n");
|
||||||
bw.close();
|
bw.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("Error!\n"+e);
|
System.out.println("Error!\n"+e);
|
||||||
|
@ -134,7 +126,7 @@ public class PluginMain extends JavaPlugin
|
||||||
File file=new File("flairsignored.txt");
|
File file=new File("flairsignored.txt");
|
||||||
try {
|
try {
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
||||||
bw.write(player+"\n");
|
bw.write(player.PlayerName+"\n");
|
||||||
bw.close();
|
bw.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("Error!\n"+e);
|
System.out.println("Error!\n"+e);
|
||||||
|
@ -395,7 +387,8 @@ public class PluginMain extends JavaPlugin
|
||||||
}
|
}
|
||||||
//player.setDisplayName(color+displayname+"§r"+flair);
|
//player.setDisplayName(color+displayname+"§r"+flair);
|
||||||
//player.setDisplayName(finalname+flair);
|
//player.setDisplayName(finalname+flair);
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=finalname+flair; //2015.08.08.
|
//MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=finalname+flair; //2015.08.08.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String GetColorForTown(String townname)
|
public static String GetColorForTown(String townname)
|
||||||
|
@ -409,7 +402,7 @@ public class PluginMain extends JavaPlugin
|
||||||
{ //2015.07.20.
|
{ //2015.07.20.
|
||||||
//List<Town> towns = TownyUniverse.getDataSource().getTowns();
|
//List<Town> towns = TownyUniverse.getDataSource().getTowns();
|
||||||
try {
|
try {
|
||||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown();
|
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||||
return town.getName();
|
return town.getName();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return "";
|
return "";
|
||||||
|
@ -421,7 +414,8 @@ public class PluginMain extends JavaPlugin
|
||||||
//String color = GetColorForTown(GetPlayerTown(player));
|
//String color = GetColorForTown(GetPlayerTown(player));
|
||||||
//String dname=player.getDisplayName();
|
//String dname=player.getDisplayName();
|
||||||
//player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair)));
|
//player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair)));
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08.
|
//MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Collection<? extends Player> GetPlayers()
|
public static Collection<? extends Player> GetPlayers()
|
|
@ -17,7 +17,9 @@ public class Commands implements CommandExecutor {
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
if(args.length<1)
|
if(args.length<1)
|
||||||
return false;
|
return false;
|
||||||
if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
{
|
{
|
||||||
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
return true;
|
return true;
|
||||||
|
@ -26,17 +28,12 @@ public class Commands implements CommandExecutor {
|
||||||
{
|
{
|
||||||
case "accept":
|
case "accept":
|
||||||
{
|
{
|
||||||
if(PluginMain.IgnoredPlayers.contains(player.getName()))
|
if(p.IgnoredFlair)
|
||||||
PluginMain.IgnoredPlayers.remove(player.getName());
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName());
|
|
||||||
//if(!PluginMain.AcceptedPlayers.contains(player.getName()))
|
|
||||||
if(!p.AcceptedFlair)
|
if(!p.AcceptedFlair)
|
||||||
{
|
{
|
||||||
//String flair=PluginMain.PlayerFlairs.get(player.getName());
|
|
||||||
String flair=p.Flair; //2015.08.08.
|
String flair=p.Flair; //2015.08.08.
|
||||||
//player.setDisplayName(player.getDisplayName()+flair);
|
|
||||||
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
//PluginMain.AcceptedPlayers.add(player.getName());
|
|
||||||
p.AcceptedFlair=true; //2015.08.08.
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
player.sendMessage("§6Your flair has been set:§r "+flair);
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
}
|
}
|
||||||
|
@ -46,15 +43,12 @@ public class Commands implements CommandExecutor {
|
||||||
}
|
}
|
||||||
case "ignore":
|
case "ignore":
|
||||||
{
|
{
|
||||||
if(PluginMain.AcceptedPlayers.contains(player.getName()))
|
if(p.AcceptedFlair)
|
||||||
PluginMain.AcceptedPlayers.remove(player.getName());
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName());
|
if(!p.IgnoredFlair)
|
||||||
if(!PluginMain.IgnoredPlayers.contains(player.getName()))
|
|
||||||
{
|
{
|
||||||
PluginMain.IgnoredPlayers.add(player.getName());
|
p.IgnoredFlair=true;
|
||||||
//String dname=player.getDisplayName();
|
String flair=p.Flair; //2015.08.08.
|
||||||
String flair=PluginMain.PlayerFlairs.get(player.getName());
|
|
||||||
//player.setDisplayName(dname.substring(0, dname.indexOf(flair)));
|
|
||||||
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
}
|
}
|
||||||
|
@ -93,11 +87,12 @@ public class Commands implements CommandExecutor {
|
||||||
PluginMain.TownColors.put(s[0], s[1]);
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
}
|
}
|
||||||
br.close();
|
br.close();
|
||||||
for(Player p : PluginMain.Players)
|
for(Player p : PluginMain.GetPlayers())
|
||||||
{
|
{
|
||||||
if(PluginMain.PlayerFlairs.containsKey(p.getName()))
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
{
|
{
|
||||||
String flair=PluginMain.PlayerFlairs.get(p.getName());
|
String flair=mp.Flair;
|
||||||
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
}
|
}
|
|
@ -0,0 +1,349 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||||
|
|
||||||
|
public class PluginMain extends JavaPlugin
|
||||||
|
{ //Translated to Java: 2015.07.15.
|
||||||
|
//A user, which flair isn't obtainable:
|
||||||
|
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
||||||
|
private static PluginMain Instance;
|
||||||
|
// Fired when plugin is first enabled
|
||||||
|
@Override
|
||||||
|
public void onEnable()
|
||||||
|
{
|
||||||
|
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||||
|
this.getCommand("u").setExecutor(new Commands());
|
||||||
|
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||||
|
Instance=this; //2015.08.08.
|
||||||
|
try {
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
//System.out.println("Name: " + name);
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("flairsignored.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||||
|
Thread t=new Thread(r);
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
Boolean stop=false;
|
||||||
|
// Fired when plugin is disabled
|
||||||
|
@Override
|
||||||
|
public void onDisable()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileWriter fw;
|
||||||
|
fw = new FileWriter("flairsaccepted.txt");
|
||||||
|
fw.close();
|
||||||
|
fw = new FileWriter("flairsignored.txt");
|
||||||
|
fw.close();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.AcceptedFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
}
|
||||||
|
bw.close();
|
||||||
|
file=new File("flairsignored.txt");
|
||||||
|
bw = new BufferedWriter(new FileWriter(file, true));
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.IgnoredFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
}
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
}
|
||||||
|
stop=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ThreadMethod() //<-- 2015.07.16.
|
||||||
|
{
|
||||||
|
while(!stop)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
||||||
|
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
||||||
|
for(Object obj : json)
|
||||||
|
{
|
||||||
|
JSONObject item = (JSONObject)obj;
|
||||||
|
String author=item.getJSONObject("data").getString("author");
|
||||||
|
String ign=item.getJSONObject("data").getString("body");
|
||||||
|
int start = ign.indexOf("IGN:") + "IGN:".length();
|
||||||
|
int end = ign.indexOf(' ', start);
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
end=ign.indexOf('\n', start); //2015.07.15.
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
ign = ign.substring(start);
|
||||||
|
else
|
||||||
|
ign = ign.substring(start, end);
|
||||||
|
ign = ign.trim();
|
||||||
|
if(HasIGFlair(ign))
|
||||||
|
continue;
|
||||||
|
try {
|
||||||
|
Thread.sleep(10);
|
||||||
|
} catch(InterruptedException ex) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
||||||
|
String flair;
|
||||||
|
if(flairdata.length > 1) //2015.07.15.
|
||||||
|
flair = flairdata[1];
|
||||||
|
else
|
||||||
|
flair="";
|
||||||
|
if (flair != "-1")
|
||||||
|
flair = flair + "s";
|
||||||
|
else
|
||||||
|
flair = "non-presser";
|
||||||
|
String flairclass;
|
||||||
|
if(flairdata.length>2)
|
||||||
|
flairclass = flairdata[2];
|
||||||
|
else
|
||||||
|
flairclass="unknown";
|
||||||
|
SetFlair(ign, flair, flairclass, author);
|
||||||
|
}
|
||||||
|
Thread.sleep(10000);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Exception LastException; //2015.08.09.
|
||||||
|
|
||||||
|
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
||||||
|
{
|
||||||
|
URL url = new URL(urlstr);
|
||||||
|
URLConnection con = url.openConnection();
|
||||||
|
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
||||||
|
InputStream in = con.getInputStream();
|
||||||
|
String encoding = con.getContentEncoding();
|
||||||
|
encoding = encoding == null ? "UTF-8" : encoding;
|
||||||
|
String body = IOUtils.toString(in, encoding);
|
||||||
|
in.close();
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||||
|
public Boolean HasIGFlair(String playername)
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
return p.Flair!=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||||
|
{
|
||||||
|
String finalflair;
|
||||||
|
switch(flairclass)
|
||||||
|
{
|
||||||
|
case "press-1":
|
||||||
|
finalflair="§c("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-2":
|
||||||
|
finalflair="§6("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-3":
|
||||||
|
finalflair="§e("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-4":
|
||||||
|
finalflair="§a("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-5":
|
||||||
|
finalflair="§9("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-6":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "no-press":
|
||||||
|
finalflair="§7(non-pr.)§r";
|
||||||
|
break;
|
||||||
|
case "cheater":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "cant-press": //2015.08.08.
|
||||||
|
finalflair="§r(can't press)§r";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
finalflair="";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||||
|
return;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
p.Flair=finalflair; //2015.08.08.
|
||||||
|
p.UserName=username; //2015.08.08.
|
||||||
|
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||||
|
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(player.getName().equals(playername))
|
||||||
|
{
|
||||||
|
AppendPlayerDisplayFlair(player, username, finalflair);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetFlair(Player player)
|
||||||
|
{ //2015.07.16.
|
||||||
|
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||||
|
return flair==null ? "" : flair;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||||
|
{
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
||||||
|
return;
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
||||||
|
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
else
|
||||||
|
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||||
|
String[] colors = color.substring(1).split("§");
|
||||||
|
String displayname=player.getName(); //2015.08.08.
|
||||||
|
ArrayList<Integer> Positions=new ArrayList<>();
|
||||||
|
for(int i=0; i<displayname.length(); i++) {
|
||||||
|
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||||
|
Positions.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String finalname=""; //TODO
|
||||||
|
if(Positions.size()>=colors.length)
|
||||||
|
{
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<Positions.size(); i++)
|
||||||
|
{
|
||||||
|
int pos=Positions.get(i);
|
||||||
|
int nextpos;
|
||||||
|
if(i!=Positions.size()-1)
|
||||||
|
nextpos=Positions.get(i+1);
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Positions.clear();
|
||||||
|
int unit=displayname.length()/colors.length;
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||||
|
{
|
||||||
|
int pos=i;
|
||||||
|
int nextpos;
|
||||||
|
if(i<displayname.length()-unit-unit)
|
||||||
|
nextpos=i+unit;
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetColorForTown(String townname)
|
||||||
|
{ //2015.07.20.
|
||||||
|
if(TownColors.containsKey(townname))
|
||||||
|
return TownColors.get(townname);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetPlayerTown(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
try {
|
||||||
|
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||||
|
return town.getName();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<? extends Player> GetPlayers()
|
||||||
|
{
|
||||||
|
return Instance.getServer().getOnlinePlayers();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,152 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;*/
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.*/
|
||||||
|
else if(args[0].toLowerCase()=="admin")
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage(msg);
|
||||||
|
else
|
||||||
|
System.out.println(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "reload":
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "playerinfo":
|
||||||
|
DoPlayerInfo(player, args);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoPlayerInfo(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
//args[0] is "admin" - args[1] is "playerinfo"
|
||||||
|
if(args.length==2)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,144 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;*/
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.*/
|
||||||
|
else if(args[0].toLowerCase()=="admin")
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage(msg);
|
||||||
|
else
|
||||||
|
System.out.println(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "reload":
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "playerinfo":
|
||||||
|
DoPlayerInfo(player, args);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoPlayerInfo(Player player, String[] args)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,173 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;*/
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.*/
|
||||||
|
else if(args[0].toLowerCase()=="admin")
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage(msg);
|
||||||
|
else
|
||||||
|
System.out.println(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
if(args.length==1)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "reload":
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "playerinfo":
|
||||||
|
DoPlayerInfo(player, args);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoPlayerInfo(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
//args[0] is "admin" - args[1] is "playerinfo"
|
||||||
|
if(args.length==2)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||||
|
{
|
||||||
|
String message="§cPlayer not found: "+args[2]+"§r";
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,171 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;*/
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.*/
|
||||||
|
else if(args[0].toLowerCase()=="admin")
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
SendMessage(player, msg); //2015.08.09.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
if(args.length==1)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "reload":
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "playerinfo":
|
||||||
|
DoPlayerInfo(player, args);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoPlayerInfo(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
//args[0] is "admin" - args[1] is "playerinfo"
|
||||||
|
if(args.length==2)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
}
|
||||||
|
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||||
|
{
|
||||||
|
String message="§cPlayer not found: "+args[2]+"§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
}
|
||||||
|
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||||
|
SendMessage(player, "User flair: "+p.Flair);
|
||||||
|
SendMessage(player, "Player name: "+p.PlayerName);
|
||||||
|
SendMessage(player, "Username: "+p.UserName);
|
||||||
|
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
private static void SendMessage(Player player, String message)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,173 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;*/
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.*/
|
||||||
|
else if(args[0].toLowerCase()=="admin")
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage(msg);
|
||||||
|
else
|
||||||
|
System.out.println(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
if(args.length==1)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "reload":
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "playerinfo":
|
||||||
|
DoPlayerInfo(player, args);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoPlayerInfo(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
//args[0] is "admin" - args[1] is "playerinfo"
|
||||||
|
if(args.length==2)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||||
|
{
|
||||||
|
String message="§cPlayer not found: "+args[2]+"§r";
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,170 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;*/
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.*/
|
||||||
|
else if(args[0].toLowerCase()=="admin")
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage(msg);
|
||||||
|
else
|
||||||
|
System.out.println(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
if(args.length==1)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "reload":
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "playerinfo":
|
||||||
|
DoPlayerInfo(player, args);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoPlayerInfo(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
//args[0] is "admin" - args[1] is "playerinfo"
|
||||||
|
if(args.length==2)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
}
|
||||||
|
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||||
|
{
|
||||||
|
String message="§cPlayer not found: "+args[2]+"§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
}
|
||||||
|
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
private static void SendMessage(Player player, String message)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,175 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
System.out.println("Args.length: "+args.length);
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;*/
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.*/
|
||||||
|
else if(args.length>0 && args[0].toLowerCase()=="admin") //2015.08.09.
|
||||||
|
{
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return true; //2015.08.09.
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
SendMessage(player, msg); //2015.08.09.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
System.out.println("Args length: " + args.length);
|
||||||
|
if(args.length==1)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "reload":
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "playerinfo":
|
||||||
|
DoPlayerInfo(player, args);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoPlayerInfo(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
//args[0] is "admin" - args[1] is "playerinfo"
|
||||||
|
if(args.length==2)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
}
|
||||||
|
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||||
|
{
|
||||||
|
String message="§cPlayer not found: "+args[2]+"§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||||
|
SendMessage(player, "Player name: "+p.PlayerName);
|
||||||
|
SendMessage(player, "User flair: "+p.Flair);
|
||||||
|
SendMessage(player, "Username: "+p.UserName);
|
||||||
|
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
||||||
|
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
||||||
|
}
|
||||||
|
private static void SendMessage(Player player, String message)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,432 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
|
||||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
|
||||||
|
|
||||||
public class PluginMain extends JavaPlugin
|
|
||||||
{ //Translated to Java: 2015.07.15.
|
|
||||||
//A user, which flair isn't obtainable:
|
|
||||||
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
|
||||||
private static PluginMain Instance;
|
|
||||||
// Fired when plugin is first enabled
|
|
||||||
@Override
|
|
||||||
public void onEnable()
|
|
||||||
{
|
|
||||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
|
||||||
//System.out.println("Original C# version: http://pastebin.com/tX8xCPbp");
|
|
||||||
//System.out.println("The Java version is... Also made by the same person.");
|
|
||||||
//System.out.println("With the help of StackOverflow and similar.");
|
|
||||||
/*catch(MalformedURLException e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
catch(IOException e)
|
|
||||||
{
|
|
||||||
}*/
|
|
||||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
|
||||||
//System.out.println("Registering commands...");
|
|
||||||
this.getCommand("u").setExecutor(new Commands());
|
|
||||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
|
||||||
Instance=this; //2015.08.08.
|
|
||||||
try {
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//AcceptedPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
System.out.println("Name: " + name);
|
|
||||||
System.out.println("Test: "+name.UserName);
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("flairsignored.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//IgnoredPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
|
||||||
String line;
|
|
||||||
while((line=br.readLine())!=null)
|
|
||||||
{
|
|
||||||
String[] s=line.split(" ");
|
|
||||||
TownColors.put(s[0], s[1]);
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//System.out.println("Registering done.");
|
|
||||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
|
||||||
Thread t=new Thread(r);
|
|
||||||
t.start();
|
|
||||||
}
|
|
||||||
Boolean stop=false;
|
|
||||||
// Fired when plugin is disabled
|
|
||||||
@Override
|
|
||||||
public void onDisable()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
FileWriter fw;
|
|
||||||
fw = new FileWriter("flairsaccepted.txt");
|
|
||||||
fw.close();
|
|
||||||
fw = new FileWriter("flairsignored.txt");
|
|
||||||
fw.close();
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//for(String player : AcceptedPlayers)
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.AcceptedFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.IgnoredFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsignored.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stop=true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ThreadMethod() //<-- 2015.07.16.
|
|
||||||
{
|
|
||||||
/*System.out.println("Sleeping for 5 seconds..."); //2015.07.20.
|
|
||||||
try {
|
|
||||||
Thread.sleep(5000);
|
|
||||||
} catch (InterruptedException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
} //2015.07.20.*/
|
|
||||||
while(!stop)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
|
||||||
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
|
||||||
for(Object obj : json)
|
|
||||||
{
|
|
||||||
JSONObject item = (JSONObject)obj;
|
|
||||||
String author=item.getJSONObject("data").getString("author");
|
|
||||||
String ign=item.getJSONObject("data").getString("body");
|
|
||||||
int start = ign.indexOf("IGN:") + "IGN:".length();
|
|
||||||
int end = ign.indexOf(' ', start);
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
end=ign.indexOf('\n', start); //2015.07.15.
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
ign = ign.substring(start);
|
|
||||||
else
|
|
||||||
ign = ign.substring(start, end);
|
|
||||||
ign = ign.trim();
|
|
||||||
if(HasIGFlair(ign))
|
|
||||||
continue;
|
|
||||||
//System.out.println("Author: "+author);
|
|
||||||
try {
|
|
||||||
Thread.sleep(10);
|
|
||||||
} catch(InterruptedException ex) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
|
||||||
String flair;
|
|
||||||
if(flairdata.length > 1) //2015.07.15.
|
|
||||||
flair = flairdata[1];
|
|
||||||
else
|
|
||||||
flair="";
|
|
||||||
if (flair != "-1")
|
|
||||||
flair = flair + "s";
|
|
||||||
else
|
|
||||||
flair = "non-presser";
|
|
||||||
String flairclass;
|
|
||||||
//System.out.println("flairdata.length:"+flairdata.length);
|
|
||||||
if(flairdata.length>2)
|
|
||||||
flairclass = flairdata[2];
|
|
||||||
else
|
|
||||||
flairclass="unknown";
|
|
||||||
SetFlair(ign, flair, flairclass, author);
|
|
||||||
}
|
|
||||||
Thread.sleep(10000);
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
|
||||||
{
|
|
||||||
URL url = new URL(urlstr);
|
|
||||||
URLConnection con = url.openConnection();
|
|
||||||
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
|
||||||
InputStream in = con.getInputStream();
|
|
||||||
String encoding = con.getContentEncoding();
|
|
||||||
encoding = encoding == null ? "UTF-8" : encoding;
|
|
||||||
String body = IOUtils.toString(in, encoding);
|
|
||||||
in.close();
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
//It has to store offline player flairs too, therefore it can't use Player object
|
|
||||||
/*public static Map<String, String> PlayerFlairs=new HashMap<String, String>();
|
|
||||||
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
|
|
||||||
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
|
|
||||||
public static ArrayList<Player> Players=new ArrayList<Player>();
|
|
||||||
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
//public static Map<String, String> PlayerTowns=new HashMap<String, String>(); //2015.07.20.*/
|
|
||||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
|
||||||
public Boolean HasIGFlair(String playername)
|
|
||||||
{
|
|
||||||
/*Player player=null;
|
|
||||||
for(Player p : Players)
|
|
||||||
{
|
|
||||||
if(p.getName()==playername)
|
|
||||||
{
|
|
||||||
player=p;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(player==null)
|
|
||||||
return false;*/
|
|
||||||
//return PlayerFlairs.containsKey(playername);
|
|
||||||
//return MaybeOfflinePlayer.AllPlayers.containsKey(playername);
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
|
||||||
return p.Flair!=null; //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
|
||||||
{
|
|
||||||
String finalflair;
|
|
||||||
switch(flairclass)
|
|
||||||
{
|
|
||||||
case "press-1":
|
|
||||||
finalflair="§c("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-2":
|
|
||||||
finalflair="§6("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-3":
|
|
||||||
finalflair="§e("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-4":
|
|
||||||
finalflair="§a("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-5":
|
|
||||||
finalflair="§9("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-6":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "no-press":
|
|
||||||
finalflair="§7(non-pr.)§r";
|
|
||||||
break;
|
|
||||||
case "cheater":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "cant-press": //2015.08.08.
|
|
||||||
finalflair="§r(can't press)§r";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
finalflair="";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
|
||||||
return;
|
|
||||||
//PlayerFlairs.put(playername, finalflair);
|
|
||||||
//PlayerUserNames.put(playername, username);
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
|
||||||
p.Flair=finalflair; //2015.08.08.
|
|
||||||
p.UserName=username; //2015.08.08.
|
|
||||||
/*for(Player player : Players)
|
|
||||||
{
|
|
||||||
if(player.getName()==playername)
|
|
||||||
{
|
|
||||||
PlayerFlairs.put(player, finalflair);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
//System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass);
|
|
||||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
|
||||||
//for(Player player : Players)
|
|
||||||
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
//System.out.println("Online player: "+player.getName());
|
|
||||||
//System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername));
|
|
||||||
if(player.getName().equals(playername))
|
|
||||||
{
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
//player.setDisplayName(player.getDisplayName()+finalflair);
|
|
||||||
AppendPlayerDisplayFlair(player, username, finalflair);
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetFlair(Player player)
|
|
||||||
{ //2015.07.16.
|
|
||||||
//String flair=PlayerFlairs.get(player.getName());
|
|
||||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
|
||||||
return flair==null ? "" : flair;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
|
||||||
{
|
|
||||||
//if(IgnoredPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
|
||||||
return;
|
|
||||||
//if(AcceptedPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
|
||||||
//player.setDisplayName(player.getDisplayName()+flair);
|
|
||||||
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
else
|
|
||||||
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//System.out.println("A");
|
|
||||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
|
||||||
String[] colors = color.substring(1).split("§");
|
|
||||||
//String displayname=player.getDisplayName();
|
|
||||||
String displayname=player.getName(); //2015.08.08.
|
|
||||||
ArrayList<Integer> Positions=new ArrayList<>();
|
|
||||||
//System.out.println("B");
|
|
||||||
for(int i=0; i<displayname.length(); i++) {
|
|
||||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
|
||||||
Positions.add(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//System.out.println("C: Positions.size(): "+Positions.size());
|
|
||||||
String finalname="";
|
|
||||||
if(Positions.size()>=colors.length)
|
|
||||||
{
|
|
||||||
//System.out.println("D");
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<Positions.size(); i++)
|
|
||||||
{
|
|
||||||
int pos=Positions.get(i);
|
|
||||||
int nextpos;
|
|
||||||
if(i!=Positions.size()-1)
|
|
||||||
nextpos=Positions.get(i+1);
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
//String substr="§"+colors[x++]+displayname.substring(pos, nextpos-pos)+"§r";
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("F");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//System.out.println("E");
|
|
||||||
Positions.clear();
|
|
||||||
int unit=displayname.length()/colors.length;
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
|
||||||
{
|
|
||||||
int pos=i;
|
|
||||||
int nextpos;
|
|
||||||
if(i<displayname.length()-unit-unit)
|
|
||||||
nextpos=i+unit;
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("G");
|
|
||||||
}
|
|
||||||
//player.setDisplayName(color+displayname+"§r"+flair);
|
|
||||||
//player.setDisplayName(finalname+flair);
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=finalname+flair; //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetColorForTown(String townname)
|
|
||||||
{ //2015.07.20.
|
|
||||||
if(TownColors.containsKey(townname))
|
|
||||||
return TownColors.get(townname);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetPlayerTown(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//List<Town> towns = TownyUniverse.getDataSource().getTowns();
|
|
||||||
try {
|
|
||||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown();
|
|
||||||
return town.getName();
|
|
||||||
} catch (Exception e) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//String color = GetColorForTown(GetPlayerTown(player));
|
|
||||||
//String dname=player.getDisplayName();
|
|
||||||
//player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair)));
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Collection<? extends Player> GetPlayers()
|
|
||||||
{
|
|
||||||
return Instance.getServer().getOnlinePlayers();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,351 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||||
|
|
||||||
|
public class PluginMain extends JavaPlugin
|
||||||
|
{ //Translated to Java: 2015.07.15.
|
||||||
|
//A user, which flair isn't obtainable:
|
||||||
|
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
||||||
|
private static PluginMain Instance;
|
||||||
|
// Fired when plugin is first enabled
|
||||||
|
@Override
|
||||||
|
public void onEnable()
|
||||||
|
{
|
||||||
|
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||||
|
this.getCommand("u").setExecutor(new Commands());
|
||||||
|
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
||||||
|
Instance=this; //2015.08.08.
|
||||||
|
try {
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
//System.out.println("Name: " + name);
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("flairsignored.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null)
|
||||||
|
{
|
||||||
|
String name=line.replace("\n", "");
|
||||||
|
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
}
|
||||||
|
throw new IOException("Test"); //2015.08.09.
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
||||||
|
Thread t=new Thread(r);
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
Boolean stop=false;
|
||||||
|
// Fired when plugin is disabled
|
||||||
|
@Override
|
||||||
|
public void onDisable()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileWriter fw;
|
||||||
|
fw = new FileWriter("flairsaccepted.txt");
|
||||||
|
fw.close();
|
||||||
|
fw = new FileWriter("flairsignored.txt");
|
||||||
|
fw.close();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
File file=new File("flairsaccepted.txt");
|
||||||
|
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.AcceptedFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
}
|
||||||
|
bw.close();
|
||||||
|
file=new File("flairsignored.txt");
|
||||||
|
bw = new BufferedWriter(new FileWriter(file, true));
|
||||||
|
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(!player.IgnoredFlair)
|
||||||
|
continue; //2015.08.08.
|
||||||
|
bw.write(player.PlayerName+"\n");
|
||||||
|
}
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
stop=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ThreadMethod() //<-- 2015.07.16.
|
||||||
|
{
|
||||||
|
while(!stop)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
||||||
|
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
||||||
|
for(Object obj : json)
|
||||||
|
{
|
||||||
|
JSONObject item = (JSONObject)obj;
|
||||||
|
String author=item.getJSONObject("data").getString("author");
|
||||||
|
String ign=item.getJSONObject("data").getString("body");
|
||||||
|
int start = ign.indexOf("IGN:") + "IGN:".length();
|
||||||
|
int end = ign.indexOf(' ', start);
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
end=ign.indexOf('\n', start); //2015.07.15.
|
||||||
|
if (end == -1 || end == start)
|
||||||
|
ign = ign.substring(start);
|
||||||
|
else
|
||||||
|
ign = ign.substring(start, end);
|
||||||
|
ign = ign.trim();
|
||||||
|
if(HasIGFlair(ign))
|
||||||
|
continue;
|
||||||
|
try {
|
||||||
|
Thread.sleep(10);
|
||||||
|
} catch(InterruptedException ex) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
||||||
|
String flair;
|
||||||
|
if(flairdata.length > 1) //2015.07.15.
|
||||||
|
flair = flairdata[1];
|
||||||
|
else
|
||||||
|
flair="";
|
||||||
|
if (flair != "-1")
|
||||||
|
flair = flair + "s";
|
||||||
|
else
|
||||||
|
flair = "non-presser";
|
||||||
|
String flairclass;
|
||||||
|
if(flairdata.length>2)
|
||||||
|
flairclass = flairdata[2];
|
||||||
|
else
|
||||||
|
flairclass="unknown";
|
||||||
|
SetFlair(ign, flair, flairclass, author);
|
||||||
|
}
|
||||||
|
Thread.sleep(10000);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Exception LastException; //2015.08.09.
|
||||||
|
|
||||||
|
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
||||||
|
{
|
||||||
|
URL url = new URL(urlstr);
|
||||||
|
URLConnection con = url.openConnection();
|
||||||
|
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
||||||
|
InputStream in = con.getInputStream();
|
||||||
|
String encoding = con.getContentEncoding();
|
||||||
|
encoding = encoding == null ? "UTF-8" : encoding;
|
||||||
|
String body = IOUtils.toString(in, encoding);
|
||||||
|
in.close();
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
||||||
|
public Boolean HasIGFlair(String playername)
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
return p.Flair!=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetFlair(String playername, String text, String flairclass, String username)
|
||||||
|
{
|
||||||
|
String finalflair;
|
||||||
|
switch(flairclass)
|
||||||
|
{
|
||||||
|
case "press-1":
|
||||||
|
finalflair="§c("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-2":
|
||||||
|
finalflair="§6("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-3":
|
||||||
|
finalflair="§e("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-4":
|
||||||
|
finalflair="§a("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-5":
|
||||||
|
finalflair="§9("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "press-6":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "no-press":
|
||||||
|
finalflair="§7(non-pr.)§r";
|
||||||
|
break;
|
||||||
|
case "cheater":
|
||||||
|
finalflair="§5("+text+")§r";
|
||||||
|
break;
|
||||||
|
case "cant-press": //2015.08.08.
|
||||||
|
finalflair="§r(can't press)§r";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
finalflair="";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(finalflair.length()==0) //<-- 2015.07.20.
|
||||||
|
return;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
||||||
|
p.Flair=finalflair; //2015.08.08.
|
||||||
|
p.UserName=username; //2015.08.08.
|
||||||
|
System.out.println("Added new flair to "+playername+": "+finalflair);
|
||||||
|
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
||||||
|
{
|
||||||
|
if(player.getName().equals(playername))
|
||||||
|
{
|
||||||
|
AppendPlayerDisplayFlair(player, username, finalflair);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetFlair(Player player)
|
||||||
|
{ //2015.07.16.
|
||||||
|
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
||||||
|
return flair==null ? "" : flair;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
||||||
|
{
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
||||||
|
return;
|
||||||
|
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
||||||
|
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
else
|
||||||
|
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
||||||
|
String[] colors = color.substring(1).split("§");
|
||||||
|
String displayname=player.getName(); //2015.08.08.
|
||||||
|
ArrayList<Integer> Positions=new ArrayList<>();
|
||||||
|
for(int i=0; i<displayname.length(); i++) {
|
||||||
|
if(Character.isUpperCase(displayname.charAt(i))) {
|
||||||
|
Positions.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String finalname=""; //TODO
|
||||||
|
if(Positions.size()>=colors.length)
|
||||||
|
{
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<Positions.size(); i++)
|
||||||
|
{
|
||||||
|
int pos=Positions.get(i);
|
||||||
|
int nextpos;
|
||||||
|
if(i!=Positions.size()-1)
|
||||||
|
nextpos=Positions.get(i+1);
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Positions.clear();
|
||||||
|
int unit=displayname.length()/colors.length;
|
||||||
|
int x=0;
|
||||||
|
for(int i=0; i<displayname.length()-unit; i+=unit)
|
||||||
|
{
|
||||||
|
int pos=i;
|
||||||
|
int nextpos;
|
||||||
|
if(i<displayname.length()-unit-unit)
|
||||||
|
nextpos=i+unit;
|
||||||
|
else
|
||||||
|
nextpos=displayname.length();
|
||||||
|
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
||||||
|
finalname+=substr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetColorForTown(String townname)
|
||||||
|
{ //2015.07.20.
|
||||||
|
if(TownColors.containsKey(townname))
|
||||||
|
return TownColors.get(townname);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String GetPlayerTown(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
try {
|
||||||
|
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO
|
||||||
|
return town.getName();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
||||||
|
{ //2015.07.20.
|
||||||
|
MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<? extends Player> GetPlayers()
|
||||||
|
{
|
||||||
|
return Instance.getServer().getOnlinePlayers();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,74 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
PluginMain.Players.add(p);
|
|
||||||
//event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p));
|
|
||||||
if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20.
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p));
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
//System.out.println("Added player "+p.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
//for(Player player : PluginMain.Players)
|
|
||||||
for(int i=0; i<PluginMain.Players.size();)
|
|
||||||
{
|
|
||||||
Player player=PluginMain.Players.get(i);
|
|
||||||
if(player.getName().equals(event.getPlayer().getName()))
|
|
||||||
{
|
|
||||||
PluginMain.Players.remove(player);
|
|
||||||
//System.out.println("Removed player "+event.getPlayer().getName());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
i++; //If the player is removed, the next item will be on the same index
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
event.setFormat(event.getFormat().replaceFirst(event.getMessage(), "")+"(test)"+event.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,176 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;*/
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.*/
|
||||||
|
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||||
|
{
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return true; //2015.08.09.
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
SendMessage(player, msg); //2015.08.09.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
LastException=e; //2015.08.09.
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
System.out.println("Args length: " + args.length);
|
||||||
|
if(args.length==1)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "reload":
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "playerinfo":
|
||||||
|
DoPlayerInfo(player, args);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoPlayerInfo(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
//args[0] is "admin" - args[1] is "playerinfo"
|
||||||
|
if(args.length==2)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||||
|
{
|
||||||
|
String message="§cPlayer not found: "+args[2]+"§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||||
|
SendMessage(player, "Player name: "+p.PlayerName);
|
||||||
|
SendMessage(player, "User flair: "+p.Flair);
|
||||||
|
SendMessage(player, "Username: "+p.UserName);
|
||||||
|
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
||||||
|
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
||||||
|
}
|
||||||
|
private static void SendMessage(Player player, String message)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,174 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;*/
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.*/
|
||||||
|
else if(args.length>0 && args[0].toLowerCase().equals("admin")) //2015.08.09.
|
||||||
|
{
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return true; //2015.08.09.
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
SendMessage(player, msg); //2015.08.09.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
System.out.println("Args length: " + args.length);
|
||||||
|
if(args.length==1)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin reload|playerinfo§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "reload":
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "playerinfo":
|
||||||
|
DoPlayerInfo(player, args);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoPlayerInfo(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
//args[0] is "admin" - args[1] is "playerinfo"
|
||||||
|
if(args.length==2)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
}
|
||||||
|
if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2]))
|
||||||
|
{
|
||||||
|
String message="§cPlayer not found: "+args[2]+"§r";
|
||||||
|
SendMessage(player, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]);
|
||||||
|
SendMessage(player, "Player name: "+p.PlayerName);
|
||||||
|
SendMessage(player, "User flair: "+p.Flair);
|
||||||
|
SendMessage(player, "Username: "+p.UserName);
|
||||||
|
SendMessage(player, "Flair accepted: "+p.AcceptedFlair);
|
||||||
|
SendMessage(player, "Flair ignored: "+p.IgnoredFlair);
|
||||||
|
}
|
||||||
|
private static void SendMessage(Player player, String message)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,156 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Commands implements CommandExecutor {
|
||||||
|
// This method is called, when somebody uses our command
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if(args.length<1)
|
||||||
|
return false;
|
||||||
|
MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08.
|
||||||
|
//if(!PluginMain.PlayerFlairs.containsKey(player.getName()))
|
||||||
|
if(p.Flair==null)
|
||||||
|
{
|
||||||
|
player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09.
|
||||||
|
{
|
||||||
|
case "accept":
|
||||||
|
{
|
||||||
|
if(p.IgnoredFlair)
|
||||||
|
p.IgnoredFlair=false; //2015.08.08.
|
||||||
|
if(!p.AcceptedFlair)
|
||||||
|
{
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
p.AcceptedFlair=true; //2015.08.08.
|
||||||
|
player.sendMessage("§6Your flair has been set:§r "+flair);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "ignore":
|
||||||
|
{
|
||||||
|
if(p.AcceptedFlair)
|
||||||
|
p.AcceptedFlair=false; //2015.08.08.
|
||||||
|
if(!p.IgnoredFlair)
|
||||||
|
{
|
||||||
|
p.IgnoredFlair=true;
|
||||||
|
String flair=p.Flair; //2015.08.08.
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
||||||
|
player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou already ignored this request.§r");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/*case "reload": //2015.07.20.
|
||||||
|
DoReload(player);
|
||||||
|
break;*/
|
||||||
|
case "admin": //2015.08.09.
|
||||||
|
DoAdmin(player, args);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if(args[0].toLowerCase()=="reload")
|
||||||
|
DoReload(null); //2015.07.20.*/
|
||||||
|
else if(args[0].toLowerCase()=="admin")
|
||||||
|
DoAdmin(null, args); //2015.08.09.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private static void DoReload(Player player)
|
||||||
|
{ //2015.07.20.
|
||||||
|
//if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
//{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file=new File("autoflairconfig.txt");
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
PluginMain.TownColors.clear();
|
||||||
|
BufferedReader br=new BufferedReader(new FileReader(file));
|
||||||
|
String line;
|
||||||
|
while((line=br.readLine())!=null)
|
||||||
|
{
|
||||||
|
String[] s=line.split(" ");
|
||||||
|
PluginMain.TownColors.put(s[0], s[1]);
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
for(Player p : PluginMain.GetPlayers())
|
||||||
|
{
|
||||||
|
MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName());
|
||||||
|
if(mp.Flair!=null)
|
||||||
|
{
|
||||||
|
String flair=mp.Flair;
|
||||||
|
PluginMain.RemovePlayerDisplayFlairFinal(p, flair);
|
||||||
|
PluginMain.AppendPlayerDisplayFlairFinal(p, flair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String msg="§6Reloaded config file.§r";
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage(msg);
|
||||||
|
else
|
||||||
|
System.out.println(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("Error!\n"+e);
|
||||||
|
if(player!=null)
|
||||||
|
player.sendMessage("§cAn error occured. See console for details.§r");
|
||||||
|
}
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoAdmin(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
if(player==null || player.isOp() || player.getName()=="NorbiPeti")
|
||||||
|
{
|
||||||
|
if(args.length==1)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
//args[0] is "admin"
|
||||||
|
switch(args[1].toLowerCase())
|
||||||
|
{
|
||||||
|
case "reload":
|
||||||
|
DoReload(player);
|
||||||
|
break;
|
||||||
|
case "playerinfo":
|
||||||
|
DoPlayerInfo(player, args);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.sendMessage("§cYou need to be OP to use this command.§r");
|
||||||
|
}
|
||||||
|
private static void DoPlayerInfo(Player player, String[] args)
|
||||||
|
{ //2015.08.09.
|
||||||
|
//args[0] is "admin" - args[1] is "playerinfo"
|
||||||
|
if(args.length==2)
|
||||||
|
{
|
||||||
|
String message="§cUsage: /u admin playerinfo <player>§r";
|
||||||
|
if(player==null)
|
||||||
|
System.out.println(message);
|
||||||
|
else
|
||||||
|
player.sendMessage(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
package tk.sznp.thebuttonautoflair;
|
||||||
|
|
||||||
|
public class Essentials implements IUser
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -1,74 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
import de.inventivegames.TellRawAutoMessage.Reflection;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{ //2015.07.16.
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Player p=event.getPlayer();
|
|
||||||
PluginMain.Players.add(p);
|
|
||||||
//event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p));
|
|
||||||
if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20.
|
|
||||||
PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p));
|
|
||||||
else
|
|
||||||
{ //2015.07.20.
|
|
||||||
String json="[\"\",{\"text\":\"§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to \"},{\"text\":\"[this thread.]\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Click here to go to the Reddit thread§r\"}]}}}]";
|
|
||||||
sendRawMessage(p, json);
|
|
||||||
}
|
|
||||||
//System.out.println("Added player "+p.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerLeave(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
//for(Player player : PluginMain.Players)
|
|
||||||
for(int i=0; i<PluginMain.Players.size();)
|
|
||||||
{
|
|
||||||
Player player=PluginMain.Players.get(i);
|
|
||||||
if(player.getName().equals(event.getPlayer().getName()))
|
|
||||||
{
|
|
||||||
PluginMain.Players.remove(player);
|
|
||||||
//System.out.println("Removed player "+event.getPlayer().getName());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
i++; //If the player is removed, the next item will be on the same index
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event)
|
|
||||||
{
|
|
||||||
event.setFormat(event.getFormat().replaceFirst(event.getMessage(), "")+"(test)"+event.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Class<?> nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
private static Class<?> nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat");
|
|
||||||
public static void sendRawMessage(Player player, String message)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
System.out.println("1");
|
|
||||||
Object handle = Reflection.getHandle(player);
|
|
||||||
System.out.println("2");
|
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
System.out.println("3");
|
|
||||||
Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message);
|
|
||||||
System.out.println("4");
|
|
||||||
Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized);
|
|
||||||
System.out.println("5");
|
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet);
|
|
||||||
System.out.println("6");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,430 +0,0 @@
|
||||||
package tk.sznp.thebuttonautoflair;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
|
||||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
|
||||||
|
|
||||||
public class PluginMain extends JavaPlugin
|
|
||||||
{ //Translated to Java: 2015.07.15.
|
|
||||||
//A user, which flair isn't obtainable:
|
|
||||||
//https://www.reddit.com/r/thebutton/comments/31c32v/i_pressed_the_button_without_really_thinking/
|
|
||||||
private static PluginMain Instance;
|
|
||||||
// Fired when plugin is first enabled
|
|
||||||
@Override
|
|
||||||
public void onEnable()
|
|
||||||
{
|
|
||||||
System.out.println("The Button Auto-flair Plugin by NorbiPeti (:P)");
|
|
||||||
//System.out.println("Original C# version: http://pastebin.com/tX8xCPbp");
|
|
||||||
//System.out.println("The Java version is... Also made by the same person.");
|
|
||||||
//System.out.println("With the help of StackOverflow and similar.");
|
|
||||||
/*catch(MalformedURLException e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
catch(IOException e)
|
|
||||||
{
|
|
||||||
}*/
|
|
||||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
|
||||||
//System.out.println("Registering commands...");
|
|
||||||
this.getCommand("u").setExecutor(new Commands());
|
|
||||||
this.getCommand("u").setUsage(this.getCommand("u").getUsage().replace('&', '§'));
|
|
||||||
Instance=this; //2015.08.08.
|
|
||||||
try {
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//AcceptedPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("flairsignored.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt"));
|
|
||||||
String line;
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
|
||||||
//IgnoredPlayers.add(line.replace("\n", ""));
|
|
||||||
String name=line.replace("\n", "");
|
|
||||||
MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08.
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
file=new File("autoflairconfig.txt");
|
|
||||||
if(file.exists())
|
|
||||||
{
|
|
||||||
BufferedReader br=new BufferedReader(new FileReader(file));
|
|
||||||
String line;
|
|
||||||
while((line=br.readLine())!=null)
|
|
||||||
{
|
|
||||||
String[] s=line.split(" ");
|
|
||||||
TownColors.put(s[0], s[1]);
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//System.out.println("Registering done.");
|
|
||||||
Runnable r=new Runnable(){public void run(){ThreadMethod();}};
|
|
||||||
Thread t=new Thread(r);
|
|
||||||
t.start();
|
|
||||||
}
|
|
||||||
Boolean stop=false;
|
|
||||||
// Fired when plugin is disabled
|
|
||||||
@Override
|
|
||||||
public void onDisable()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
FileWriter fw;
|
|
||||||
fw = new FileWriter("flairsaccepted.txt");
|
|
||||||
fw.close();
|
|
||||||
fw = new FileWriter("flairsignored.txt");
|
|
||||||
fw.close();
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
//for(String player : AcceptedPlayers)
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.AcceptedFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsaccepted.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw=new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
if(!player.IgnoredFlair)
|
|
||||||
continue; //2015.08.08.
|
|
||||||
File file=new File("flairsignored.txt");
|
|
||||||
try {
|
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
|
|
||||||
bw.write(player+"\n");
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stop=true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ThreadMethod() //<-- 2015.07.16.
|
|
||||||
{
|
|
||||||
/*System.out.println("Sleeping for 5 seconds..."); //2015.07.20.
|
|
||||||
try {
|
|
||||||
Thread.sleep(5000);
|
|
||||||
} catch (InterruptedException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
} //2015.07.20.*/
|
|
||||||
while(!stop)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
String body=DownloadString("https://www.reddit.com/r/TheButtonMinecraft/comments/3d25do/autoflair_system_comment_your_minecraft_name_and/.json?limit=1000");
|
|
||||||
JSONArray json=new JSONArray(body).getJSONObject(1).getJSONObject("data").getJSONArray("children");
|
|
||||||
for(Object obj : json)
|
|
||||||
{
|
|
||||||
JSONObject item = (JSONObject)obj;
|
|
||||||
String author=item.getJSONObject("data").getString("author");
|
|
||||||
String ign=item.getJSONObject("data").getString("body");
|
|
||||||
int start = ign.indexOf("IGN:") + "IGN:".length();
|
|
||||||
int end = ign.indexOf(' ', start);
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
end=ign.indexOf('\n', start); //2015.07.15.
|
|
||||||
if (end == -1 || end == start)
|
|
||||||
ign = ign.substring(start);
|
|
||||||
else
|
|
||||||
ign = ign.substring(start, end);
|
|
||||||
ign = ign.trim();
|
|
||||||
if(HasIGFlair(ign))
|
|
||||||
continue;
|
|
||||||
//System.out.println("Author: "+author);
|
|
||||||
try {
|
|
||||||
Thread.sleep(10);
|
|
||||||
} catch(InterruptedException ex) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
String[] flairdata = DownloadString("http://karmadecay.com/thebutton-data.php?users=" + author).replace("\"", "").split(":");
|
|
||||||
String flair;
|
|
||||||
if(flairdata.length > 1) //2015.07.15.
|
|
||||||
flair = flairdata[1];
|
|
||||||
else
|
|
||||||
flair="";
|
|
||||||
if (flair != "-1")
|
|
||||||
flair = flair + "s";
|
|
||||||
else
|
|
||||||
flair = "non-presser";
|
|
||||||
String flairclass;
|
|
||||||
//System.out.println("flairdata.length:"+flairdata.length);
|
|
||||||
if(flairdata.length>2)
|
|
||||||
flairclass = flairdata[2];
|
|
||||||
else
|
|
||||||
flairclass="unknown";
|
|
||||||
SetFlair(ign, flair, flairclass, author);
|
|
||||||
}
|
|
||||||
Thread.sleep(10000);
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("Error!\n"+e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String DownloadString(String urlstr) throws MalformedURLException, IOException
|
|
||||||
{
|
|
||||||
URL url = new URL(urlstr);
|
|
||||||
URLConnection con = url.openConnection();
|
|
||||||
con.setRequestProperty("User-Agent", "TheButtonAutoFlair");
|
|
||||||
InputStream in = con.getInputStream();
|
|
||||||
String encoding = con.getContentEncoding();
|
|
||||||
encoding = encoding == null ? "UTF-8" : encoding;
|
|
||||||
String body = IOUtils.toString(in, encoding);
|
|
||||||
in.close();
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
//It has to store offline player flairs too, therefore it can't use Player object
|
|
||||||
/*public static Map<String, String> PlayerFlairs=new HashMap<String, String>();
|
|
||||||
public static Map<String, String> PlayerUserNames=new HashMap<String, String>();
|
|
||||||
//public Map<Player, String> PlayerFlairs=new HashMap<Player, String>();
|
|
||||||
public static ArrayList<Player> Players=new ArrayList<Player>();
|
|
||||||
public static ArrayList<String> AcceptedPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
public static ArrayList<String> IgnoredPlayers=new ArrayList<String>(); //2015.07.16.
|
|
||||||
//public static Map<String, String> PlayerTowns=new HashMap<String, String>(); //2015.07.20.*/
|
|
||||||
public static Map<String, String> TownColors=new HashMap<String, String>(); //2015.07.20.
|
|
||||||
public Boolean HasIGFlair(String playername)
|
|
||||||
{
|
|
||||||
/*Player player=null;
|
|
||||||
for(Player p : Players)
|
|
||||||
{
|
|
||||||
if(p.getName()==playername)
|
|
||||||
{
|
|
||||||
player=p;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(player==null)
|
|
||||||
return false;*/
|
|
||||||
//return PlayerFlairs.containsKey(playername);
|
|
||||||
//return MaybeOfflinePlayer.AllPlayers.containsKey(playername);
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
|
||||||
return MaybeOfflinePlayer.AllPlayers.get(playername).Flair!=null; //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetFlair(String playername, String text, String flairclass, String username)
|
|
||||||
{
|
|
||||||
String finalflair;
|
|
||||||
switch(flairclass)
|
|
||||||
{
|
|
||||||
case "press-1":
|
|
||||||
finalflair="§c("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-2":
|
|
||||||
finalflair="§6("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-3":
|
|
||||||
finalflair="§e("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-4":
|
|
||||||
finalflair="§a("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-5":
|
|
||||||
finalflair="§9("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "press-6":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "no-press":
|
|
||||||
finalflair="§7(non-pr.)§r";
|
|
||||||
break;
|
|
||||||
case "cheater":
|
|
||||||
finalflair="§5("+text+")§r";
|
|
||||||
break;
|
|
||||||
case "cant-press": //2015.08.08.
|
|
||||||
finalflair="§r(can't press)§r";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
finalflair="";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(finalflair.length()==0) //<-- 2015.07.20.
|
|
||||||
return;
|
|
||||||
//PlayerFlairs.put(playername, finalflair);
|
|
||||||
//PlayerUserNames.put(playername, username);
|
|
||||||
MaybeOfflinePlayer p=MaybeOfflinePlayer.AddPlayerIfNeeded(playername); //2015.08.08.
|
|
||||||
p.Flair=finalflair; //2015.08.08.
|
|
||||||
p.UserName=username; //2015.08.08.
|
|
||||||
/*for(Player player : Players)
|
|
||||||
{
|
|
||||||
if(player.getName()==playername)
|
|
||||||
{
|
|
||||||
PlayerFlairs.put(player, finalflair);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
//System.out.println("SetFlair - playername: "+playername+" text: "+text+" flairclass: "+flairclass);
|
|
||||||
System.out.println("Added new flair to "+playername+": "+finalflair);
|
|
||||||
//for(Player player : Players)
|
|
||||||
for(Player player : getServer().getOnlinePlayers()) //<-- 2015.08.08.
|
|
||||||
{
|
|
||||||
//System.out.println("Online player: "+player.getName());
|
|
||||||
//System.out.println("player.getName ("+player.getName()+") == playername ("+playername+"): "+(player.getName()==playername));
|
|
||||||
if(player.getName().equals(playername))
|
|
||||||
{
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
//player.setDisplayName(player.getDisplayName()+finalflair);
|
|
||||||
AppendPlayerDisplayFlair(player, username, finalflair);
|
|
||||||
//System.out.println("DisplayName: "+player.getDisplayName());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetFlair(Player player)
|
|
||||||
{ //2015.07.16.
|
|
||||||
//String flair=PlayerFlairs.get(player.getName());
|
|
||||||
String flair=MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair; //2015.08.08.
|
|
||||||
return flair==null ? "" : flair;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlair(Player player, String username, String flair)
|
|
||||||
{
|
|
||||||
//if(IgnoredPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair)
|
|
||||||
return;
|
|
||||||
//if(AcceptedPlayers.contains(player.getName()))
|
|
||||||
if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair)
|
|
||||||
//player.setDisplayName(player.getDisplayName()+flair);
|
|
||||||
AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20.
|
|
||||||
else
|
|
||||||
player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AppendPlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//System.out.println("A");
|
|
||||||
String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters
|
|
||||||
String[] colors = color.substring(1).split("§");
|
|
||||||
//String displayname=player.getDisplayName();
|
|
||||||
String displayname=player.getName(); //2015.08.08.
|
|
||||||
ArrayList<Integer> Positions=new ArrayList<>();
|
|
||||||
//System.out.println("B");
|
|
||||||
for(int i=0; i<displayname.length(); i++) {
|
|
||||||
if(Character.isUpperCase(displayname.charAt(i))) {
|
|
||||||
Positions.add(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//System.out.println("C: Positions.size(): "+Positions.size());
|
|
||||||
String finalname="";
|
|
||||||
if(Positions.size()>=colors.length)
|
|
||||||
{
|
|
||||||
//System.out.println("D");
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<Positions.size(); i++)
|
|
||||||
{
|
|
||||||
int pos=Positions.get(i);
|
|
||||||
int nextpos;
|
|
||||||
if(i!=Positions.size()-1)
|
|
||||||
nextpos=Positions.get(i+1);
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
//String substr="§"+colors[x++]+displayname.substring(pos, nextpos-pos)+"§r";
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("F");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//System.out.println("E");
|
|
||||||
Positions.clear();
|
|
||||||
int unit=displayname.length()/colors.length;
|
|
||||||
int x=0;
|
|
||||||
for(int i=0; i<displayname.length()-unit; i+=unit)
|
|
||||||
{
|
|
||||||
int pos=i;
|
|
||||||
int nextpos;
|
|
||||||
if(i<displayname.length()-unit-unit)
|
|
||||||
nextpos=i+unit;
|
|
||||||
else
|
|
||||||
nextpos=displayname.length();
|
|
||||||
//System.out.println("pos: "+pos+" nextpos: "+nextpos);
|
|
||||||
//System.out.println("nextpos-pos: "+(nextpos-pos));
|
|
||||||
String substr="§"+colors[x++]+displayname.substring(pos, nextpos)+"§r";
|
|
||||||
finalname+=substr;
|
|
||||||
}
|
|
||||||
//System.out.println("G");
|
|
||||||
}
|
|
||||||
//player.setDisplayName(color+displayname+"§r"+flair);
|
|
||||||
//player.setDisplayName(finalname+flair);
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=finalname+flair; //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetColorForTown(String townname)
|
|
||||||
{ //2015.07.20.
|
|
||||||
if(TownColors.containsKey(townname))
|
|
||||||
return TownColors.get(townname);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String GetPlayerTown(Player player)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//List<Town> towns = TownyUniverse.getDataSource().getTowns();
|
|
||||||
try {
|
|
||||||
Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown();
|
|
||||||
return town.getName();
|
|
||||||
} catch (Exception e) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RemovePlayerDisplayFlairFinal(Player player, String flair)
|
|
||||||
{ //2015.07.20.
|
|
||||||
//String color = GetColorForTown(GetPlayerTown(player));
|
|
||||||
//String dname=player.getDisplayName();
|
|
||||||
//player.setDisplayName(dname.substring(dname.indexOf(color)+3, dname.indexOf(flair)));
|
|
||||||
MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=null; //2015.08.08.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Collection<? extends Player> GetPlayers()
|
|
||||||
{
|
|
||||||
return Instance.getServer().getOnlinePlayers();
|
|
||||||
}
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue