diff --git a/.metadata/.log b/.metadata/.log index c8fd4e5..9e28562 100644 --- a/.metadata/.log +++ b/.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 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 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.(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.(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. diff --git a/.metadata/.mylyn/.tasks.xml.zip b/.metadata/.mylyn/.tasks.xml.zip index c99ab0a..6b15865 100644 Binary files a/.metadata/.mylyn/.tasks.xml.zip and b/.metadata/.mylyn/.tasks.xml.zip differ diff --git a/.metadata/.mylyn/tasks.xml.zip b/.metadata/.mylyn/tasks.xml.zip index c10683e..1fcc9a7 100644 Binary files a/.metadata/.mylyn/tasks.xml.zip and b/.metadata/.mylyn/tasks.xml.zip differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1/601f8274873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/1/601f8274873e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..aaa641d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1/601f8274873e00151ce8ff6d4f74dabd @@ -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" + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1/60ca8b100a3e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/1/60ca8b100a3e00151c31fb33fff4337f deleted file mode 100644 index b11e849..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1/60ca8b100a3e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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 GetPlayers() - { - return Instance.getServer().getOnlinePlayers(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1/d071b8d5873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/1/d071b8d5873e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..aab975f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1/d071b8d5873e00151ce8ff6d4f74dabd @@ -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 §r"; + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/10/80a0b699f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/10/80a0b699f63d00151c31fb33fff4337f deleted file mode 100644 index 2ef29ec..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/10/80a0b699f63d00151c31fb33fff4337f +++ /dev/null @@ -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 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(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/10/d069a424873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/10/d069a424873e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..f0c8ce6 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/10/d069a424873e00151ce8ff6d4f74dabd @@ -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"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/11/50a623b5013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/11/50a623b5013e00151c31fb33fff4337f deleted file mode 100644 index d412cf3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/11/50a623b5013e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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. - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/13/602947d9303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/13/602947d9303e00151cbdba8b5f0a340e new file mode 100644 index 0000000..29ec32a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/13/602947d9303e00151cbdba8b5f0a340e @@ -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 PlayerFlairs=new HashMap(); + public static Map PlayerUserNames=new HashMap(); + //public Map PlayerFlairs=new HashMap(); + public static ArrayList Players=new ArrayList(); + public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. + public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. + //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ + public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + //System.out.println("B"); + for(int i=0; i=colors.length) + { + //System.out.println("D"); + int x=0; + for(int i=0; i 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 GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/14/d0544e5b893e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/14/d0544e5b893e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..e8f0509 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/14/d0544e5b893e00151ce8ff6d4f74dabd @@ -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 §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; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/51/505dae0ff73d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/15/6060baa6313e00151cbdba8b5f0a340e similarity index 72% rename from .metadata/.plugins/org.eclipse.core.resources/.history/51/505dae0ff73d00151c31fb33fff4337f rename to .metadata/.plugins/org.eclipse.core.resources/.history/15/6060baa6313e00151cbdba8b5f0a340e index ced3ab5..3ec657c 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/51/505dae0ff73d00151c31fb33fff4337f +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/15/6060baa6313e00151cbdba8b5f0a340e @@ -15,39 +15,35 @@ public class PlayerListener implements Listener 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)); + 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); } - //System.out.println("Added player "+p.getName()); } @EventHandler public void onPlayerLeave(PlayerQuitEvent event) { - //for(Player player : PluginMain.Players) - for(int i=0; i"))+"(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"); diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/16/c0258975a03e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/16/c0258975a03e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..47a95c0 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/16/c0258975a03e00151ce8ff6d4f74dabd @@ -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 §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); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/17/d08a7e97f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/17/d08a7e97f63d00151c31fb33fff4337f deleted file mode 100644 index 2ef29ec..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/17/d08a7e97f63d00151c31fb33fff4337f +++ /dev/null @@ -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 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(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/18/600208ef303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/18/600208ef303e00151cbdba8b5f0a340e new file mode 100644 index 0000000..70cb3d9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/18/600208ef303e00151cbdba8b5f0a340e @@ -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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + //System.out.println("B"); + for(int i=0; i=colors.length) + { + //System.out.println("D"); + int x=0; + for(int i=0; i 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 GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/19/60f2ab7f023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/19/60f2ab7f023e00151c31fb33fff4337f deleted file mode 100644 index ff19301..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/19/60f2ab7f023e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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. - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/19/701d8005313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/19/701d8005313e00151cbdba8b5f0a340e new file mode 100644 index 0000000..57c29d1 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/19/701d8005313e00151cbdba8b5f0a340e @@ -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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1a/d0fbf199f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/1a/d0fbf199f63d00151c31fb33fff4337f deleted file mode 100644 index 2ef29ec..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1a/d0fbf199f63d00151c31fb33fff4337f +++ /dev/null @@ -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 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(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1b/50a351cba13e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/1b/50a351cba13e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..db7ac07 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1b/50a351cba13e00151ce8ff6d4f74dabd @@ -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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1e/50995637313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/1e/50995637313e00151cbdba8b5f0a340e new file mode 100644 index 0000000..d33e6dc --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1e/50995637313e00151cbdba8b5f0a340e @@ -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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1f/604b1a15873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/1f/604b1a15873e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..2b6fbe4 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1f/604b1a15873e00151ce8ff6d4f74dabd @@ -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"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1f/e0251d1ba13e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/1f/e0251d1ba13e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..dcf4e9c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1f/e0251d1ba13e00151ce8ff6d4f74dabd @@ -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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/20/10fb34ff313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/20/10fb34ff313e00151cbdba8b5f0a340e new file mode 100644 index 0000000..2ade719 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/20/10fb34ff313e00151cbdba8b5f0a340e @@ -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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/21/509f004a873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/21/509f004a873e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..7947b97 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/21/509f004a873e00151ce8ff6d4f74dabd @@ -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"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/22/50b446ea313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/22/50b446ea313e00151cbdba8b5f0a340e new file mode 100644 index 0000000..eda6b64 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/22/50b446ea313e00151cbdba8b5f0a340e @@ -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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/22/50fe465a863e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/22/50fe465a863e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..4e09c08 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/22/50fe465a863e00151ce8ff6d4f74dabd @@ -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"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/24/503f4e74a13e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/24/503f4e74a13e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..fc43abf --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/24/503f4e74a13e00151ce8ff6d4f74dabd @@ -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 §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 §r"; + SendMessage(player, message); + return; + } + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + SendMessage(player, "Stack trace:")args; + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/24/d08c2d11033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/24/d08c2d11033e00151c31fb33fff4337f deleted file mode 100644 index a6a1d5d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/24/d08c2d11033e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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. - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/26/50c81932a33e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/26/50c81932a33e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..2940503 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/26/50c81932a33e00151ce8ff6d4f74dabd @@ -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 §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."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/27/60d75efa303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/27/60d75efa303e00151cbdba8b5f0a340e new file mode 100644 index 0000000..ebb1816 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/27/60d75efa303e00151cbdba8b5f0a340e @@ -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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i 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 GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/28/601d65fe303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/28/601d65fe303e00151cbdba8b5f0a340e new file mode 100644 index 0000000..0023a44 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/28/601d65fe303e00151cbdba8b5f0a340e @@ -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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i 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 GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2a/50ddd938863e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/2a/50ddd938863e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..8cba558 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2a/50ddd938863e00151ce8ff6d4f74dabd @@ -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"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2a/d0123229883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/2a/d0123229883e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..2fca4b8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2a/d0123229883e00151ce8ff6d4f74dabd @@ -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 §r"; + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + return; + } + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2a/e01483b3313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/2a/e01483b3313e00151cbdba8b5f0a340e new file mode 100644 index 0000000..2fd48b2 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2a/e01483b3313e00151cbdba8b5f0a340e @@ -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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2a/e078d72f343e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/2a/e078d72f343e00151cbdba8b5f0a340e new file mode 100644 index 0000000..d263650 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2a/e078d72f343e00151cbdba8b5f0a340e @@ -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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2b/c0dde05e023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/2b/c0dde05e023e00151c31fb33fff4337f deleted file mode 100644 index 33aea73..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2b/c0dde05e023e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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. - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2c/50dc4d96a13e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/2c/50dc4d96a13e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..c9d9ba8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2c/50dc4d96a13e00151ce8ff6d4f74dabd @@ -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 §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 §r"; + SendMessage(player, message); + return; + } + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + SendMessage(player, "Stack trace:"); + SendMessage(player, PluginMain.LastException.getStackTrace()); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2d/60a68ad9013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/2d/60a68ad9013e00151c31fb33fff4337f deleted file mode 100644 index a957fb0..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2d/60a68ad9013e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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. - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2e/50fb0e28a33e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/2e/50fb0e28a33e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..7f134f9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2e/50fb0e28a33e00151ce8ff6d4f74dabd @@ -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 §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."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2e/c0323f76053e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/2e/c0323f76053e00151c31fb33fff4337f deleted file mode 100644 index 5e25dbe..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2e/c0323f76053e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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 GetPlayers() - { - return Instance.getServer().getOnlinePlayers(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2f/6035f831893e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/2f/6035f831893e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..e2107b1 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2f/6035f831893e00151ce8ff6d4f74dabd @@ -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 §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; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2f/70a2035a333e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/2f/70a2035a333e00151cbdba8b5f0a340e new file mode 100644 index 0000000..a45dd73 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2f/70a2035a333e00151cbdba8b5f0a340e @@ -0,0 +1,7 @@ +package tk.sznp.thebuttonautoflair; + +import com.earth2me.essentials.IEssentials; + +public class Essentials implements IEssentials { + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2f/c09b39d5013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/2f/c09b39d5013e00151c31fb33fff4337f deleted file mode 100644 index 4b47b30..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2f/c09b39d5013e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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. - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c7/d00983410a3e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/30/10d5c0cc303e00151cbdba8b5f0a340e similarity index 95% rename from .metadata/.plugins/org.eclipse.core.resources/.history/c7/d00983410a3e00151c31fb33fff4337f rename to .metadata/.plugins/org.eclipse.core.resources/.history/30/10d5c0cc303e00151cbdba8b5f0a340e index 9ada4e2..8f610fd 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c7/d00983410a3e00151c31fb33fff4337f +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/30/10d5c0cc303e00151cbdba8b5f0a340e @@ -22,6 +22,7 @@ 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 @@ -34,17 +35,7 @@ public class PluginMain extends JavaPlugin 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. @@ -121,7 +112,7 @@ public class PluginMain extends JavaPlugin File file=new File("flairsaccepted.txt"); try { BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); - bw.write(player+"\n"); + bw.write(player.PlayerName+"\n"); bw.close(); } catch (IOException e) { System.out.println("Error!\n"+e); @@ -134,7 +125,7 @@ public class PluginMain extends JavaPlugin File file=new File("flairsignored.txt"); try { BufferedWriter bw = new BufferedWriter(new FileWriter(file, true)); - bw.write(player+"\n"); + bw.write(player.PlayerName+"\n"); bw.close(); } catch (IOException e) { System.out.println("Error!\n"+e); @@ -395,7 +386,8 @@ public class PluginMain extends JavaPlugin } //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()).DisplayName=finalname+flair; //2015.08.08. + MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08. } public static String GetColorForTown(String townname) @@ -409,7 +401,7 @@ public class PluginMain extends JavaPlugin { //2015.07.20. //List towns = TownyUniverse.getDataSource().getTowns(); try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); + Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO return town.getName(); } catch (Exception e) { return ""; @@ -421,7 +413,8 @@ public class PluginMain extends JavaPlugin //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()).DisplayName=null; //2015.08.08. + MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08. } public static Collection GetPlayers() diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/30/706b3ad0303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/30/706b3ad0303e00151cbdba8b5f0a340e new file mode 100644 index 0000000..206493e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/30/706b3ad0303e00151cbdba8b5f0a340e @@ -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 PlayerFlairs=new HashMap(); + public static Map PlayerUserNames=new HashMap(); + //public Map PlayerFlairs=new HashMap(); + public static ArrayList Players=new ArrayList(); + public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. + public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. + //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ + public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + //System.out.println("B"); + for(int i=0; i=colors.length) + { + //System.out.println("D"); + int x=0; + for(int i=0; i 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 GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ec/c098ba41033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/32/808056b7303e00151cbdba8b5f0a340e similarity index 84% rename from .metadata/.plugins/org.eclipse.core.resources/.history/ec/c098ba41033e00151c31fb33fff4337f rename to .metadata/.plugins/org.eclipse.core.resources/.history/32/808056b7303e00151cbdba8b5f0a340e index bcc675e..0e6c94e 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ec/c098ba41033e00151c31fb33fff4337f +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/32/808056b7303e00151cbdba8b5f0a340e @@ -18,8 +18,11 @@ public class PlayerListener implements Listener //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)); - if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + MaybeOfflinePlayer.AddPlayerIfNeeded(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 { //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\"}]}}}]"; @@ -49,7 +52,10 @@ public class PlayerListener implements Listener public void onPlayerChat(AsyncPlayerChatEvent event) { //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. } diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/32/d00979788c3e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/32/d00979788c3e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..be367ac --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/32/d00979788c3e00151ce8ff6d4f74dabd @@ -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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/32/d0cdd1d2a13e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/32/d0cdd1d2a13e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..db7ac07 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/32/d0cdd1d2a13e00151ce8ff6d4f74dabd @@ -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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/33/60a1e0d1303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/33/60a1e0d1303e00151cbdba8b5f0a340e new file mode 100644 index 0000000..f5d4fd5 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/33/60a1e0d1303e00151cbdba8b5f0a340e @@ -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 PlayerFlairs=new HashMap(); + public static Map PlayerUserNames=new HashMap(); + //public Map PlayerFlairs=new HashMap(); + public static ArrayList Players=new ArrayList(); + public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. + public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. + //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ + public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + //System.out.println("B"); + for(int i=0; i=colors.length) + { + //System.out.println("D"); + int x=0; + for(int i=0; i 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 GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/33/e0d225f4303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/33/e0d225f4303e00151cbdba8b5f0a340e new file mode 100644 index 0000000..df22067 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/33/e0d225f4303e00151cbdba8b5f0a340e @@ -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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + //System.out.println("B"); + for(int i=0; i=colors.length) + { + //System.out.println("D"); + int x=0; + for(int i=0; i 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 GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/90/00c56e06f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/34/e07767e9313e00151cbdba8b5f0a340e similarity index 73% rename from .metadata/.plugins/org.eclipse.core.resources/.history/90/00c56e06f63d00151c31fb33fff4337f rename to .metadata/.plugins/org.eclipse.core.resources/.history/34/e07767e9313e00151cbdba8b5f0a340e index 7c2048e..4531ada 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/90/00c56e06f63d00151c31fb33fff4337f +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/34/e07767e9313e00151cbdba8b5f0a340e @@ -15,39 +15,39 @@ public class PlayerListener implements Listener 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)); + 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); } - //System.out.println("Added player "+p.getName()); } @EventHandler public void onPlayerLeave(PlayerQuitEvent event) { - //for(Player player : PluginMain.Players) - for(int i=0; i"))+flair+"> "+message); //2015.08.08. } private static Class nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/cc/505a3848f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/36/e04434aa313e00151cbdba8b5f0a340e similarity index 72% rename from .metadata/.plugins/org.eclipse.core.resources/.history/cc/505a3848f63d00151c31fb33fff4337f rename to .metadata/.plugins/org.eclipse.core.resources/.history/36/e04434aa313e00151cbdba8b5f0a340e index a181e3f..d2a72bd 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/cc/505a3848f63d00151c31fb33fff4337f +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/36/e04434aa313e00151cbdba8b5f0a340e @@ -15,39 +15,35 @@ public class PlayerListener implements Listener 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)); + 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); } - //System.out.println("Added player "+p.getName()); } @EventHandler public void onPlayerLeave(PlayerQuitEvent event) { - //for(Player player : PluginMain.Players) - for(int i=0; i"))+flair+"> "+message); //2015.08.08. } private static Class nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/37/5064f5c0883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/37/5064f5c0883e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..ac79356 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/37/5064f5c0883e00151ce8ff6d4f74dabd @@ -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 §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; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/37/508af516a33e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/37/508af516a33e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..17fffa7 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/37/508af516a33e00151ce8ff6d4f74dabd @@ -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 §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() + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/38/601c14b2013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/38/601c14b2013e00151c31fb33fff4337f deleted file mode 100644 index 60f057b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/38/601c14b2013e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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. - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/38/e086e0cc843e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/38/e086e0cc843e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..a8e5994 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/38/e086e0cc843e00151ce8ff6d4f74dabd @@ -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"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/38/f01dd9d8333e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/38/f01dd9d8333e00151cbdba8b5f0a340e new file mode 100644 index 0000000..41c7113 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/38/f01dd9d8333e00151cbdba8b5f0a340e @@ -0,0 +1,8 @@ +package tk.sznp.thebuttonautoflair; + +import net.ess3.api.IUser; + +public class Essentials +{ + +} \ No newline at end of file diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/39/60013fb6013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/39/60013fb6013e00151c31fb33fff4337f deleted file mode 100644 index 6eb0212..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/39/60013fb6013e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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. - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/39/e05f8acf313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/39/e05f8acf313e00151cbdba8b5f0a340e new file mode 100644 index 0000000..153978e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/39/e05f8acf313e00151cbdba8b5f0a340e @@ -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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3a/d0a96a2e313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/3a/d0a96a2e313e00151cbdba8b5f0a340e new file mode 100644 index 0000000..5dd7da9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3a/d0a96a2e313e00151cbdba8b5f0a340e @@ -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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3a/d0b0a0be863e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/3a/d0b0a0be863e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..cacc30e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3a/d0b0a0be863e00151ce8ff6d4f74dabd @@ -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"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3a/d0f29b1ba13e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/3a/d0f29b1ba13e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..dcf4e9c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3a/d0f29b1ba13e00151ce8ff6d4f74dabd @@ -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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3b/60019f03313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/3b/60019f03313e00151cbdba8b5f0a340e new file mode 100644 index 0000000..94daee8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3b/60019f03313e00151cbdba8b5f0a340e @@ -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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i 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 GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3c/60d8cd51873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/3c/60d8cd51873e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..01037e0 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3c/60d8cd51873e00151ce8ff6d4f74dabd @@ -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"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3d/6051d217853e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/3d/6051d217853e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..e292615 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3d/6051d217853e00151ce8ff6d4f74dabd @@ -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"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3d/c0b328b0883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/3d/c0b328b0883e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..fade14e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3d/c0b328b0883e00151ce8ff6d4f74dabd @@ -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 §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; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3e/509fad42873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/3e/509fad42873e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..c25a794 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3e/509fad42873e00151ce8ff6d4f74dabd @@ -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"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3e/60cf0473a13e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/3e/60cf0473a13e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..fe6319f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3e/60cf0473a13e00151ce8ff6d4f74dabd @@ -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 §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 §r"; + SendMessage(player, message); + return; + } + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3e/e0d118c0863e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/3e/e0d118c0863e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..a8ddfb3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3e/e0d118c0863e00151ce8ff6d4f74dabd @@ -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"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3f/e0e98472053e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/3f/e0e98472053e00151c31fb33fff4337f deleted file mode 100644 index 98b7ab9..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3f/e0e98472053e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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 GetPlayers() - { - return Instance.getServer().getOnlinePlayers(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4/70e5ccd7303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/4/70e5ccd7303e00151cbdba8b5f0a340e new file mode 100644 index 0000000..06839a7 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/4/70e5ccd7303e00151cbdba8b5f0a340e @@ -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 PlayerFlairs=new HashMap(); + public static Map PlayerUserNames=new HashMap(); + //public Map PlayerFlairs=new HashMap(); + public static ArrayList Players=new ArrayList(); + public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. + public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. + //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ + public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + //System.out.println("B"); + for(int i=0; i=colors.length) + { + //System.out.println("D"); + int x=0; + for(int i=0; i 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 GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4/c0811107033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/4/c0811107033e00151c31fb33fff4337f deleted file mode 100644 index 68b1859..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4/c0811107033e00151c31fb33fff4337f +++ /dev/null @@ -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"))+"(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(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/40/b05dfb50f93d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/40/b05dfb50f93d00151c31fb33fff4337f deleted file mode 100644 index 674db06..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/40/b05dfb50f93d00151c31fb33fff4337f +++ /dev/null @@ -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"))+"(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(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/41/4092806fff3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/41/4092806fff3d00151c31fb33fff4337f deleted file mode 100644 index cbfa0ee..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/41/4092806fff3d00151c31fb33fff4337f +++ /dev/null @@ -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"))+"(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(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/42/50bc64c9313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/42/50bc64c9313e00151cbdba8b5f0a340e new file mode 100644 index 0000000..05f0ff1 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/42/50bc64c9313e00151cbdba8b5f0a340e @@ -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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/42/50ee9a65a03e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/42/50ee9a65a03e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..f7cbf9c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/42/50ee9a65a03e00151ce8ff6d4f74dabd @@ -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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/42/d0f315df033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/42/d0f315df033e00151c31fb33fff4337f deleted file mode 100644 index 2174d65..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/42/d0f315df033e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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. - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/43/70258926313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/43/70258926313e00151cbdba8b5f0a340e new file mode 100644 index 0000000..4427f9e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/43/70258926313e00151cbdba8b5f0a340e @@ -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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/43/f011b9b4333e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/43/f011b9b4333e00151cbdba8b5f0a340e new file mode 100644 index 0000000..3cde012 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/43/f011b9b4333e00151cbdba8b5f0a340e @@ -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 getConfigKeys() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Map getConfigMap() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Map 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 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 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 + + } + +} \ No newline at end of file diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/44/104410f0033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/44/104410f0033e00151c31fb33fff4337f deleted file mode 100644 index 7db7fad..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/44/104410f0033e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/44/c0bce577873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/44/c0bce577873e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..40b9c4f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/44/c0bce577873e00151ce8ff6d4f74dabd @@ -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 + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e3/90184b440c3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/46/a01312cb303e00151cbdba8b5f0a340e similarity index 96% rename from .metadata/.plugins/org.eclipse.core.resources/.history/e3/90184b440c3e00151089cca86c5b1a99 rename to .metadata/.plugins/org.eclipse.core.resources/.history/46/a01312cb303e00151cbdba8b5f0a340e index 9ada4e2..b75c29b 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e3/90184b440c3e00151089cca86c5b1a99 +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/46/a01312cb303e00151cbdba8b5f0a340e @@ -22,6 +22,7 @@ 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 @@ -34,15 +35,6 @@ public class PluginMain extends JavaPlugin 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()); @@ -121,7 +113,7 @@ public class PluginMain extends JavaPlugin File file=new File("flairsaccepted.txt"); try { BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); - bw.write(player+"\n"); + bw.write(player.PlayerName+"\n"); bw.close(); } catch (IOException e) { System.out.println("Error!\n"+e); @@ -134,7 +126,7 @@ public class PluginMain extends JavaPlugin File file=new File("flairsignored.txt"); try { BufferedWriter bw = new BufferedWriter(new FileWriter(file, true)); - bw.write(player+"\n"); + bw.write(player.PlayerName+"\n"); bw.close(); } catch (IOException e) { System.out.println("Error!\n"+e); @@ -395,7 +387,8 @@ public class PluginMain extends JavaPlugin } //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()).DisplayName=finalname+flair; //2015.08.08. + MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08. } public static String GetColorForTown(String townname) @@ -409,7 +402,7 @@ public class PluginMain extends JavaPlugin { //2015.07.20. //List towns = TownyUniverse.getDataSource().getTowns(); try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); + Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO return town.getName(); } catch (Exception e) { return ""; @@ -421,7 +414,8 @@ public class PluginMain extends JavaPlugin //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()).DisplayName=null; //2015.08.08. + MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08. } public static Collection GetPlayers() diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e1/3009907cfe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/48/60516d96843e00151ce8ff6d4f74dabd similarity index 70% rename from .metadata/.plugins/org.eclipse.core.resources/.history/e1/3009907cfe3d00151c31fb33fff4337f rename to .metadata/.plugins/org.eclipse.core.resources/.history/48/60516d96843e00151ce8ff6d4f74dabd index 22c5797..55d1b29 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e1/3009907cfe3d00151c31fb33fff4337f +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/48/60516d96843e00151ce8ff6d4f74dabd @@ -17,7 +17,9 @@ public class Commands implements CommandExecutor { Player player = (Player) sender; if(args.length<1) 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"); return true; @@ -26,17 +28,12 @@ public class Commands implements CommandExecutor { { case "accept": { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); - //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. if(!p.AcceptedFlair) { - //String flair=PluginMain.PlayerFlairs.get(player.getName()); String flair=p.Flair; //2015.08.08. - //player.setDisplayName(player.getDisplayName()+flair); PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - //PluginMain.AcceptedPlayers.add(player.getName()); p.AcceptedFlair=true; //2015.08.08. player.sendMessage("§6Your flair has been set:§r "+flair); } @@ -46,15 +43,12 @@ public class Commands implements CommandExecutor { } case "ignore": { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); + 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"); } @@ -93,11 +87,12 @@ public class Commands implements CommandExecutor { PluginMain.TownColors.put(s[0], s[1]); } 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.AppendPlayerDisplayFlairFinal(p, flair); } diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/49/50f5486fa03e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/49/50f5486fa03e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..dd0eded --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/49/50f5486fa03e00151ce8ff6d4f74dabd @@ -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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4a/50f7fce0873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/4a/50f7fce0873e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..a0eb8d2 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/4a/50f7fce0873e00151ce8ff6d4f74dabd @@ -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 §r"; + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4c/d0831972873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/4c/d0831972873e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..568b3d5 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/4c/d0831972873e00151ce8ff6d4f74dabd @@ -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) + { + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4e/e0491f86883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/4e/e0491f86883e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..010c5a2 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/4e/e0491f86883e00151ce8ff6d4f74dabd @@ -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 §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]); + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4f/50e0ec42893e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/4f/50e0ec42893e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..4e90cb1 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/4f/50e0ec42893e00151ce8ff6d4f74dabd @@ -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 §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; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/50/506a31a2883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/50/506a31a2883e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..f163736 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/50/506a31a2883e00151ce8ff6d4f74dabd @@ -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 §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; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/51/50cc60cf883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/51/50cc60cf883e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..b8cf010 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/51/50cc60cf883e00151ce8ff6d4f74dabd @@ -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 §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; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/51/50d92add8a3e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/51/50d92add8a3e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..2f5950a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/51/50d92add8a3e00151ce8ff6d4f74dabd @@ -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 §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); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/51/c0028e610a3e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/51/c0028e610a3e00151c31fb33fff4337f deleted file mode 100644 index 42c46c7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/51/c0028e610a3e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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 GetPlayers() - { - return Instance.getServer().getOnlinePlayers(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/52/d0059abea13e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/52/d0059abea13e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..690770e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/52/d0059abea13e00151ce8ff6d4f74dabd @@ -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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/53/a0405c98f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/53/a0405c98f63d00151c31fb33fff4337f deleted file mode 100644 index 2ef29ec..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/53/a0405c98f63d00151c31fb33fff4337f +++ /dev/null @@ -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 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(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/53/c0f0ed77a03e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/53/c0f0ed77a03e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..84d5a37 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/53/c0f0ed77a03e00151ce8ff6d4f74dabd @@ -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 §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); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/53/d05d36728b3e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/53/d05d36728b3e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..445cb6c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/53/d05d36728b3e00151ce8ff6d4f74dabd @@ -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 §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); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/53/d0e8e8e2873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/53/d0e8e8e2873e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..2de7e2d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/53/d0e8e8e2873e00151ce8ff6d4f74dabd @@ -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 §r"; + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/53/d0e9bcd5333e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/53/d0e9bcd5333e00151cbdba8b5f0a340e new file mode 100644 index 0000000..ca0b02d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/53/d0e9bcd5333e00151cbdba8b5f0a340e @@ -0,0 +1,6 @@ +package tk.sznp.thebuttonautoflair; + +public class Essentials implements IUser +{ + +} \ No newline at end of file diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/54/603c9698f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/54/603c9698f63d00151c31fb33fff4337f deleted file mode 100644 index 2ef29ec..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/54/603c9698f63d00151c31fb33fff4337f +++ /dev/null @@ -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 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(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/55/e0f6a187073e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/55/e0f6a187073e00151c31fb33fff4337f deleted file mode 100644 index 36a0cb6..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/55/e0f6a187073e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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 GetPlayers() - { - return Instance.getServer().getOnlinePlayers(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/56/d0b1ba48873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/56/d0b1ba48873e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..2c6aa0e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/56/d0b1ba48873e00151ce8ff6d4f74dabd @@ -0,0 +1,137 @@ +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 " + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/59/d0ec3c3e893e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/59/d0ec3c3e893e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..f7f1828 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/59/d0ec3c3e893e00151ce8ff6d4f74dabd @@ -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"; + 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 §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); + return; + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + return; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/59/e01c61f6303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/59/e01c61f6303e00151cbdba8b5f0a340e new file mode 100644 index 0000000..a2f79e3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/59/e01c61f6303e00151cbdba8b5f0a340e @@ -0,0 +1,366 @@ +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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + //System.out.println("D"); + int x=0; + for(int i=0; i 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 GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5a/60029e24a13e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/5a/60029e24a13e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..98df576 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5a/60029e24a13e00151ce8ff6d4f74dabd @@ -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(); + } + + } 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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5a/602205ac333e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/5a/602205ac333e00151cbdba8b5f0a340e new file mode 100644 index 0000000..58ffb85 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5a/602205ac333e00151cbdba8b5f0a340e @@ -0,0 +1,8 @@ +package tk.sznp.thebuttonautoflair; + +import net.ess3.api.IUser; + +public class Essentials implements IUser +{ + +} \ No newline at end of file diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5a/d014d921873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/5a/d014d921873e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..dc43ad6 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5a/d014d921873e00151ce8ff6d4f74dabd @@ -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"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3b/e033e73b033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/5a/e045f11c2e3e00151cbdba8b5f0a340e similarity index 84% rename from .metadata/.plugins/org.eclipse.core.resources/.history/3b/e033e73b033e00151c31fb33fff4337f rename to .metadata/.plugins/org.eclipse.core.resources/.history/5a/e045f11c2e3e00151cbdba8b5f0a340e index 0a39c6c..0e6c94e 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3b/e033e73b033e00151c31fb33fff4337f +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5a/e045f11c2e3e00151cbdba8b5f0a340e @@ -18,8 +18,11 @@ public class PlayerListener implements Listener //PluginMain.Players.add(p); //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); //if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. - if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) - PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + MaybeOfflinePlayer.AddPlayerIfNeeded(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 { //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\"}]}}}]"; @@ -49,7 +52,10 @@ public class PlayerListener implements Listener public void onPlayerChat(AsyncPlayerChatEvent event) { //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. } diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5c/5000959ea13e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/5c/5000959ea13e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..fe6319f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5c/5000959ea13e00151ce8ff6d4f74dabd @@ -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 §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 §r"; + SendMessage(player, message); + return; + } + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5c/d05c6ca4a13e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/5c/d05c6ca4a13e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..e1dfd78 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5c/d05c6ca4a13e00151ce8ff6d4f74dabd @@ -0,0 +1,191 @@ +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 §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 §r"; + SendMessage(player, message); + return; + } + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + SendMessage(player, "Time:") + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5d/608dcfff313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/5d/608dcfff313e00151cbdba8b5f0a340e new file mode 100644 index 0000000..2ade719 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5d/608dcfff313e00151cbdba8b5f0a340e @@ -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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5d/c03b3a38a33e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/5d/c03b3a38a33e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..772a8d8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5d/c03b3a38a33e00151ce8ff6d4f74dabd @@ -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); + default: + 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 §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."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5e/001a5b7d013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/5e/001a5b7d013e00151c31fb33fff4337f deleted file mode 100644 index 4b9f9aa..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5e/001a5b7d013e00151c31fb33fff4337f +++ /dev/null @@ -1,415 +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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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); - /*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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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. - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5f/d050dc2e043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/5f/d050dc2e043e00151c31fb33fff4337f deleted file mode 100644 index e62cdc8..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5f/d050dc2e043e00151c31fb33fff4337f +++ /dev/null @@ -1,427 +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('&', '§')); - 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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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 GetPlayers() - { - return Instance.getServer().getOnlinePlayers(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5f/d05109b3013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/5f/d05109b3013e00151c31fb33fff4337f deleted file mode 100644 index 5edf504..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5f/d05109b3013e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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. - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/62/8065dabd843e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/62/8065dabd843e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..1b10b37 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/62/8065dabd843e00151ce8ff6d4f74dabd @@ -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": + 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"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/64/50d16a24893e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/64/50d16a24893e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..80c391c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/64/50d16a24893e00151ce8ff6d4f74dabd @@ -0,0 +1,167 @@ +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 §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; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/64/60ee528d013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/64/60ee528d013e00151c31fb33fff4337f deleted file mode 100644 index 4b9f9aa..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/64/60ee528d013e00151c31fb33fff4337f +++ /dev/null @@ -1,415 +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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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); - /*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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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. - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/65/50973663863e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/65/50973663863e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..1cce5d8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/65/50973663863e00151ce8ff6d4f74dabd @@ -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, String[] args) + { + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1c/50a873c4093e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/65/50f9fa688c3e00151ce8ff6d4f74dabd similarity index 70% rename from .metadata/.plugins/org.eclipse.core.resources/.history/1c/50a873c4093e00151c31fb33fff4337f rename to .metadata/.plugins/org.eclipse.core.resources/.history/65/50f9fa688c3e00151ce8ff6d4f74dabd index 962d1ac..0aecdd3 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1c/50a873c4093e00151c31fb33fff4337f +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/65/50f9fa688c3e00151ce8ff6d4f74dabd @@ -34,17 +34,7 @@ public class PluginMain extends JavaPlugin 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. @@ -56,9 +46,8 @@ public class PluginMain extends JavaPlugin 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("Name: " + name); MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. } br.close(); @@ -70,7 +59,6 @@ public class PluginMain extends JavaPlugin 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. } @@ -91,7 +79,6 @@ public class PluginMain extends JavaPlugin } 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(); @@ -113,15 +100,14 @@ public class PluginMain extends JavaPlugin { System.out.println("Error!\n"+e); } - //for(String player : AcceptedPlayers) + 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. - File file=new File("flairsaccepted.txt"); try { - BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); - bw.write(player+"\n"); + bw.write(player.PlayerName+"\n"); bw.close(); } catch (IOException e) { System.out.println("Error!\n"+e); @@ -134,7 +120,7 @@ public class PluginMain extends JavaPlugin File file=new File("flairsignored.txt"); try { BufferedWriter bw = new BufferedWriter(new FileWriter(file, true)); - bw.write(player+"\n"); + bw.write(player.PlayerName+"\n"); bw.close(); } catch (IOException e) { System.out.println("Error!\n"+e); @@ -145,12 +131,6 @@ public class PluginMain extends JavaPlugin 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 @@ -173,7 +153,6 @@ public class PluginMain extends JavaPlugin ign = ign.trim(); if(HasIGFlair(ign)) continue; - //System.out.println("Author: "+author); try { Thread.sleep(10); } catch(InterruptedException ex) { @@ -190,7 +169,6 @@ public class PluginMain extends JavaPlugin else flair = "non-presser"; String flairclass; - //System.out.println("flairdata.length:"+flairdata.length); if(flairdata.length>2) flairclass = flairdata[2]; else @@ -219,30 +197,9 @@ public class PluginMain extends JavaPlugin return body; } - //It has to store offline player flairs too, therefore it can't use Player object - /*public static Map PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ public static Map TownColors=new HashMap(); //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. } @@ -285,32 +242,15 @@ public class PluginMain extends JavaPlugin } 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; } } @@ -318,19 +258,15 @@ public class PluginMain extends JavaPlugin 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"); @@ -338,23 +274,18 @@ public class PluginMain extends JavaPlugin 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 Positions=new ArrayList<>(); - //System.out.println("B"); for(int i=0; i=colors.length) { - //System.out.println("D"); int x=0; for(int i=0; i towns = TownyUniverse.getDataSource().getTowns(); try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); + Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO return town.getName(); } catch (Exception e) { return ""; @@ -418,10 +338,7 @@ public class PluginMain extends JavaPlugin 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 GetPlayers() diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ad/d0a7a16df93d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/65/e0e09818313e00151cbdba8b5f0a340e similarity index 75% rename from .metadata/.plugins/org.eclipse.core.resources/.history/ad/d0a7a16df93d00151c31fb33fff4337f rename to .metadata/.plugins/org.eclipse.core.resources/.history/65/e0e09818313e00151cbdba8b5f0a340e index 8bbd84b..e17c425 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ad/d0a7a16df93d00151c31fb33fff4337f +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/65/e0e09818313e00151cbdba8b5f0a340e @@ -15,39 +15,31 @@ public class PlayerListener implements Listener 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)); + 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); } - //System.out.println("Added player "+p.getName()); } @EventHandler public void onPlayerLeave(PlayerQuitEvent event) { - //for(Player player : PluginMain.Players) - for(int i=0; i"))+"(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.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. } diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/66/d0650077873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/66/d0650077873e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..1e3d1d3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/66/d0650077873e00151ce8ff6d4f74dabd @@ -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" + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/67/d08f62038d3e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/67/d08f62038d3e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..47a95c0 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/67/d08f62038d3e00151ce8ff6d4f74dabd @@ -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 §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); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/68/5008c7fc313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/68/5008c7fc313e00151cbdba8b5f0a340e new file mode 100644 index 0000000..6ba24bb --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/68/5008c7fc313e00151cbdba8b5f0a340e @@ -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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/68/f09bcae9303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/68/f09bcae9303e00151cbdba8b5f0a340e new file mode 100644 index 0000000..00b6037 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/68/f09bcae9303e00151cbdba8b5f0a340e @@ -0,0 +1,377 @@ +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 TownColors=new HashMap(); //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)) + { + //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 Positions=new ArrayList<>(); + //System.out.println("B"); + for(int i=0; i=colors.length) + { + //System.out.println("D"); + int x=0; + for(int i=0; i 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 GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6b/d0f9527cf63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/6b/d0f9527cf63d00151c31fb33fff4337f deleted file mode 100644 index 65c80c5..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6b/d0f9527cf63d00151c31fb33fff4337f +++ /dev/null @@ -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 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(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6c/60729b58a03e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/6c/60729b58a03e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..2735e70 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6c/60729b58a03e00151ce8ff6d4f74dabd @@ -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; + } + } + } + + public static Exception LastException; + + 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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6e/e0394523853e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/6e/e0394523853e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..bf1b322 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6e/e0394523853e00151ce8ff6d4f74dabd @@ -0,0 +1,122 @@ +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"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6e/e0a6ee96f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/6e/e0a6ee96f63d00151c31fb33fff4337f deleted file mode 100644 index 65c80c5..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6e/e0a6ee96f63d00151c31fb33fff4337f +++ /dev/null @@ -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 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(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6e/f0362afd313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/6e/f0362afd313e00151cbdba8b5f0a340e new file mode 100644 index 0000000..f25045c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6e/f0362afd313e00151cbdba8b5f0a340e @@ -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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7/d0b0f3a0a13e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/7/d0b0f3a0a13e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..e758703 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/7/d0b0f3a0a13e00151ce8ff6d4f74dabd @@ -0,0 +1,191 @@ +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 §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 §r"; + SendMessage(player, message); + return; + } + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + SendMessage(player, "Date:") + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/70/50a02cb8a03e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/70/50a02cb8a03e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..8fd38ad --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/70/50a02cb8a03e00151ce8ff6d4f74dabd @@ -0,0 +1,186 @@ +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; + } + } + 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 §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 playerinfo §r"; + SendMessage(player, message); + return; + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/71/f01d3f77023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/71/f01d3f77023e00151c31fb33fff4337f deleted file mode 100644 index ff19301..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/71/f01d3f77023e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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. - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/72/008777b4313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/72/008777b4313e00151cbdba8b5f0a340e new file mode 100644 index 0000000..8938516 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/72/008777b4313e00151cbdba8b5f0a340e @@ -0,0 +1,71 @@ +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; + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/72/60069e3b863e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/72/60069e3b863e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..2b45c26 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/72/60069e3b863e00151ce8ff6d4f74dabd @@ -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()=="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 DoAdmin(Player player) + { + if(player==null || player.isOp() || player.getName()=="NorbiPeti") + { + + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/72/6080d12b893e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/72/6080d12b893e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..9d9d757 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/72/6080d12b893e00151ce8ff6d4f74dabd @@ -0,0 +1,168 @@ +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 §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); + return; + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + return; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/72/704702fe313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/72/704702fe313e00151cbdba8b5f0a340e new file mode 100644 index 0000000..2ade719 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/72/704702fe313e00151cbdba8b5f0a340e @@ -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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/74/70e4dd2b313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/74/70e4dd2b313e00151cbdba8b5f0a340e new file mode 100644 index 0000000..5dd7da9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/74/70e4dd2b313e00151cbdba8b5f0a340e @@ -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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9c/d0841f77fe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/77/50df6a0f313e00151cbdba8b5f0a340e similarity index 80% rename from .metadata/.plugins/org.eclipse.core.resources/.history/9c/d0841f77fe3d00151c31fb33fff4337f rename to .metadata/.plugins/org.eclipse.core.resources/.history/77/50df6a0f313e00151cbdba8b5f0a340e index bf1e453..1cd84d0 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/9c/d0841f77fe3d00151c31fb33fff4337f +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/77/50df6a0f313e00151cbdba8b5f0a340e @@ -17,7 +17,9 @@ public class Commands implements CommandExecutor { Player player = (Player) sender; if(args.length<1) 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"); return true; @@ -26,9 +28,10 @@ public class Commands implements CommandExecutor { { case "accept": { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. //if(!PluginMain.AcceptedPlayers.contains(player.getName())) if(!p.AcceptedFlair) { @@ -46,13 +49,13 @@ public class Commands implements CommandExecutor { } case "ignore": { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) { - PluginMain.IgnoredPlayers.add(player.getName()); + p.IgnoredFlair=true; //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); @@ -92,11 +95,13 @@ public class Commands implements CommandExecutor { PluginMain.TownColors.put(s[0], s[1]); } br.close(); - for(Player p : PluginMain.Players) + //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.AppendPlayerDisplayFlairFinal(p, flair); } diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/77/c062443b883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/77/c062443b883e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..4f114f8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/77/c062443b883e00151ce8ff6d4f74dabd @@ -0,0 +1,30 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.HashMap; + +public class +String message="§cUsage: /u admin playerinfo §r"; +if(player==null) + System.out.println(message); +else + player.sendMessage(message); +return; +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; //If the user comments their name, it gets set, it doesn't matter if they accepted it or not + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername) + { + if(!AllPlayers.containsKey(playername)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + return player; + } + return AllPlayers.get(playername); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/77/d074cf98f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/77/d074cf98f63d00151c31fb33fff4337f deleted file mode 100644 index 2ef29ec..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/77/d074cf98f63d00151c31fb33fff4337f +++ /dev/null @@ -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 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(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/77/d083ff46043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/77/d083ff46043e00151c31fb33fff4337f deleted file mode 100644 index 19b9f5c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/77/d083ff46043e00151c31fb33fff4337f +++ /dev/null @@ -1,427 +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('&', '§')); - 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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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 GetPlayers() - { - return Instance.getServer().getOnlinePlayers(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/78/40118f77873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/78/40118f77873e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..68ec621 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/78/40118f77873e00151ce8ff6d4f74dabd @@ -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" + w + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/78/5065e3fff63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/78/5065e3fff63d00151c31fb33fff4337f deleted file mode 100644 index 02c6ce6..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/78/5065e3fff63d00151c31fb33fff4337f +++ /dev/null @@ -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 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(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/78/804750c0843e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/78/804750c0843e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..cf9d482 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/78/804750c0843e00151ce8ff6d4f74dabd @@ -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.08. + 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"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/78/e06b4feea03e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/78/e06b4feea03e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..a4b548a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/78/e06b4feea03e00151ce8ff6d4f74dabd @@ -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 §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 §r"; + SendMessage(player, message); + return; + } + SendMessage(player, "Last error:"); + SendMessagE(player, PluginMain.LastException.toString()); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7b/f0438a5af93d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/7b/f0438a5af93d00151c31fb33fff4337f deleted file mode 100644 index 3ca08ad..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7b/f0438a5af93d00151c31fb33fff4337f +++ /dev/null @@ -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"))+"(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(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7c/501c42e7303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/7c/501c42e7303e00151cbdba8b5f0a340e new file mode 100644 index 0000000..675fa44 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/7c/501c42e7303e00151cbdba8b5f0a340e @@ -0,0 +1,379 @@ +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 TownColors=new HashMap(); //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. + { + //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 Positions=new ArrayList<>(); + //System.out.println("B"); + for(int i=0; i=colors.length) + { + //System.out.println("D"); + int x=0; + for(int i=0; i 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 GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7c/d0cb7c99f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/7c/d0cb7c99f63d00151c31fb33fff4337f deleted file mode 100644 index 2ef29ec..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7c/d0cb7c99f63d00151c31fb33fff4337f +++ /dev/null @@ -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 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(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7e/9072727d013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/7e/9072727d013e00151c31fb33fff4337f deleted file mode 100644 index 4b9f9aa..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7e/9072727d013e00151c31fb33fff4337f +++ /dev/null @@ -1,415 +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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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); - /*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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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. - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7f/500624aa333e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/7f/500624aa333e00151cbdba8b5f0a340e new file mode 100644 index 0000000..19e1033 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/7f/500624aa333e00151cbdba8b5f0a340e @@ -0,0 +1,6 @@ +package tk.sznp.thebuttonautoflair; + +public class Essentials implements IUser +{ + +} \ No newline at end of file diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7f/e0ee0200313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/7f/e0ee0200313e00151cbdba8b5f0a340e new file mode 100644 index 0000000..5c2c1b4 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/7f/e0ee0200313e00151cbdba8b5f0a340e @@ -0,0 +1,358 @@ +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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i 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 GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8/608aaa5d333e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/8/608aaa5d333e00151cbdba8b5f0a340e new file mode 100644 index 0000000..5ff4366 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/8/608aaa5d333e00151cbdba8b5f0a340e @@ -0,0 +1,7 @@ +package tk.sznp.thebuttonautoflair; + +import net.ess3.api.IEssentials; + +public class Essentials implements IEssentials { + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8/e0936b2f853e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/8/e0936b2f853e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..4fc0380 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/8/e0936b2f853e00151ce8ff6d4f74dabd @@ -0,0 +1,129 @@ +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") + { + + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/80/50a96102873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/80/50a96102873e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..2290b1a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/80/50a96102873e00151ce8ff6d4f74dabd @@ -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()) + { + + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/81/403b869cf63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/81/403b869cf63d00151c31fb33fff4337f deleted file mode 100644 index 2ef29ec..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/81/403b869cf63d00151c31fb33fff4337f +++ /dev/null @@ -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 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(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/82/50e26929a13e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/82/50e26929a13e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..f5a9fe4 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/82/50e26929a13e00151ce8ff6d4f74dabd @@ -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 Exception("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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/82/d08e864aa03e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/82/d08e864aa03e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..a914268 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/82/d08e864aa03e00151ce8ff6d4f74dabd @@ -0,0 +1,344 @@ +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); + } + } + } + + 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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/84/50665de9a03e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/84/50665de9a03e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..35d6fc9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/84/50665de9a03e00151ce8ff6d4f74dabd @@ -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 §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 §r"; + SendMessage(player, message); + return; + } + SendMessage(player, "Last error:"); + SendMessagE(player, PluginMain.LastException); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/85/d0022215a33e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/85/d0022215a33e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..3d42d7a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/85/d0022215a33e00151ce8ff6d4f74dabd @@ -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 §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 + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/85/f037c8f6843e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/85/f037c8f6843e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..9f42545 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/85/f037c8f6843e00151ce8ff6d4f74dabd @@ -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].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. + 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"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/86/e024da2a853e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/86/e024da2a853e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..2e97c39 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/86/e024da2a853e00151ce8ff6d4f74dabd @@ -0,0 +1,129 @@ +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") + { + + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/87/d02a74358b3e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/87/d02a74358b3e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..fb490b0 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/87/d02a74358b3e00151ce8ff6d4f74dabd @@ -0,0 +1,177 @@ +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(args.length>0) + System.out.println("Args[0].length: "+args[0].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 §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); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/89/d0fdd397f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/89/d0fdd397f63d00151c31fb33fff4337f deleted file mode 100644 index 2ef29ec..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/89/d0fdd397f63d00151c31fb33fff4337f +++ /dev/null @@ -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 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(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8b/70ab04f3303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/8b/70ab04f3303e00151cbdba8b5f0a340e new file mode 100644 index 0000000..f41b292 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/8b/70ab04f3303e00151cbdba8b5f0a340e @@ -0,0 +1,370 @@ +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 TownColors=new HashMap(); //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. + //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 Positions=new ArrayList<>(); + //System.out.println("B"); + for(int i=0; i=colors.length) + { + //System.out.println("D"); + int x=0; + for(int i=0; i 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 GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8c/50aa2bf3023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/8c/50aa2bf3023e00151c31fb33fff4337f deleted file mode 100644 index 6ebcd9a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8c/50aa2bf3023e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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. - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8c/60d47714883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/8c/60d47714883e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..31f7f4b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/8c/60d47714883e00151ce8ff6d4f74dabd @@ -0,0 +1,162 @@ +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 §r"; + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + return; + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8c/d09f3274873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/8c/d09f3274873e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..1e3d1d3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/8c/d09f3274873e00151ce8ff6d4f74dabd @@ -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" + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8c/e09fcf22313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/8c/e09fcf22313e00151cbdba8b5f0a340e new file mode 100644 index 0000000..48637e8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/8c/e09fcf22313e00151cbdba8b5f0a340e @@ -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.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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e3/d08eed38f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/8e/603503de313e00151cbdba8b5f0a340e similarity index 73% rename from .metadata/.plugins/org.eclipse.core.resources/.history/e3/d08eed38f63d00151c31fb33fff4337f rename to .metadata/.plugins/org.eclipse.core.resources/.history/8e/603503de313e00151cbdba8b5f0a340e index 33f1fce..4531ada 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e3/d08eed38f63d00151c31fb33fff4337f +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/8e/603503de313e00151cbdba8b5f0a340e @@ -15,39 +15,39 @@ public class PlayerListener implements Listener 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)); + 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); } - //System.out.println("Added player "+p.getName()); } @EventHandler public void onPlayerLeave(PlayerQuitEvent event) { - //for(Player player : PluginMain.Players) - for(int i=0; i"))+flair+"> "+message); //2015.08.08. } private static Class nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/48/d0589339033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/8e/704d28bf303e00151cbdba8b5f0a340e similarity index 79% rename from .metadata/.plugins/org.eclipse.core.resources/.history/48/d0589339033e00151c31fb33fff4337f rename to .metadata/.plugins/org.eclipse.core.resources/.history/8e/704d28bf303e00151cbdba8b5f0a340e index 647cf3d..3796901 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/48/d0589339033e00151c31fb33fff4337f +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/8e/704d28bf303e00151cbdba8b5f0a340e @@ -17,8 +17,12 @@ public class PlayerListener implements Listener 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)); + //if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. + MaybeOfflinePlayer.AddPlayerIfNeeded(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 { //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\"}]}}}]"; @@ -30,25 +34,17 @@ public class PlayerListener implements Listener @EventHandler public void onPlayerLeave(PlayerQuitEvent event) { - //for(Player player : PluginMain.Players) - /*for(int i=0; i"))+"(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. + String message; event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. } diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ce/500d093f033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/8f/703888ba303e00151cbdba8b5f0a340e similarity index 83% rename from .metadata/.plugins/org.eclipse.core.resources/.history/ce/500d093f033e00151c31fb33fff4337f rename to .metadata/.plugins/org.eclipse.core.resources/.history/8f/703888ba303e00151cbdba8b5f0a340e index fa02e2a..3974f8c 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ce/500d093f033e00151c31fb33fff4337f +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/8f/703888ba303e00151cbdba8b5f0a340e @@ -18,8 +18,11 @@ public class PlayerListener implements Listener //PluginMain.Players.add(p); //event.getPlayer().setDisplayName(p.getDisplayName()+PluginMain.GetFlair(p)); //if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. - if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. - PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + MaybeOfflinePlayer.AddPlayerIfNeeded(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 { //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\"}]}}}]"; @@ -49,7 +52,11 @@ public class PlayerListener implements Listener public void onPlayerChat(AsyncPlayerChatEvent event) { //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. + String message; event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. } diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8f/e04a23618a3e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/8f/e04a23618a3e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..189cf5f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/8f/e04a23618a3e00151ce8ff6d4f74dabd @@ -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()=="admin") + { + 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") + { + 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 §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); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/90/500d3da18a3e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/90/500d3da18a3e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..ce93db7 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/90/500d3da18a3e00151ce8ff6d4f74dabd @@ -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()=="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 §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); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/90/e0cf9548333e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/90/e0cf9548333e00151cbdba8b5f0a340e new file mode 100644 index 0000000..e69de29 diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2c/50d8e8c4093e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/91/d03aaa6b8c3e00151ce8ff6d4f74dabd similarity index 70% rename from .metadata/.plugins/org.eclipse.core.resources/.history/2c/50d8e8c4093e00151c31fb33fff4337f rename to .metadata/.plugins/org.eclipse.core.resources/.history/91/d03aaa6b8c3e00151ce8ff6d4f74dabd index efbefe2..840738b 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2c/50d8e8c4093e00151c31fb33fff4337f +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/91/d03aaa6b8c3e00151ce8ff6d4f74dabd @@ -34,17 +34,7 @@ public class PluginMain extends JavaPlugin 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. @@ -56,9 +46,8 @@ public class PluginMain extends JavaPlugin String line; while ((line = br.readLine()) != null) { - //AcceptedPlayers.add(line.replace("\n", "")); String name=line.replace("\n", ""); - System.out.println("Name: "+name);s + //System.out.println("Name: " + name); MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. } br.close(); @@ -70,7 +59,6 @@ public class PluginMain extends JavaPlugin 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. } @@ -91,7 +79,6 @@ public class PluginMain extends JavaPlugin } 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(); @@ -113,15 +100,14 @@ public class PluginMain extends JavaPlugin { System.out.println("Error!\n"+e); } - //for(String player : AcceptedPlayers) + 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. - File file=new File("flairsaccepted.txt"); - try { - BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); - bw.write(player+"\n"); + bw.write(player.PlayerName+"\n"); bw.close(); } catch (IOException e) { System.out.println("Error!\n"+e); @@ -134,7 +120,7 @@ public class PluginMain extends JavaPlugin File file=new File("flairsignored.txt"); try { BufferedWriter bw = new BufferedWriter(new FileWriter(file, true)); - bw.write(player+"\n"); + bw.write(player.PlayerName+"\n"); bw.close(); } catch (IOException e) { System.out.println("Error!\n"+e); @@ -145,12 +131,6 @@ public class PluginMain extends JavaPlugin 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 @@ -173,7 +153,6 @@ public class PluginMain extends JavaPlugin ign = ign.trim(); if(HasIGFlair(ign)) continue; - //System.out.println("Author: "+author); try { Thread.sleep(10); } catch(InterruptedException ex) { @@ -190,7 +169,6 @@ public class PluginMain extends JavaPlugin else flair = "non-presser"; String flairclass; - //System.out.println("flairdata.length:"+flairdata.length); if(flairdata.length>2) flairclass = flairdata[2]; else @@ -219,30 +197,9 @@ public class PluginMain extends JavaPlugin return body; } - //It has to store offline player flairs too, therefore it can't use Player object - /*public static Map PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ public static Map TownColors=new HashMap(); //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. } @@ -285,32 +242,15 @@ public class PluginMain extends JavaPlugin } 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; } } @@ -318,19 +258,15 @@ public class PluginMain extends JavaPlugin 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"); @@ -338,23 +274,18 @@ public class PluginMain extends JavaPlugin 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 Positions=new ArrayList<>(); - //System.out.println("B"); for(int i=0; i=colors.length) { - //System.out.println("D"); int x=0; for(int i=0; i towns = TownyUniverse.getDataSource().getTowns(); try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); + Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO return town.getName(); } catch (Exception e) { return ""; @@ -418,10 +338,7 @@ public class PluginMain extends JavaPlugin 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 GetPlayers() diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/92/d085d1ac013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/92/d085d1ac013e00151c31fb33fff4337f deleted file mode 100644 index 452a530..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/92/d085d1ac013e00151c31fb33fff4337f +++ /dev/null @@ -1,416 +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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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); - - /*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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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. - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/92/e0548f13a33e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/92/e0548f13a33e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..552048a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/92/e0548f13a33e00151ce8ff6d4f74dabd @@ -0,0 +1,188 @@ +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 §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()); + } + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/93/508cb163893e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/93/508cb163893e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..846537c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/93/508cb163893e00151ce8ff6d4f74dabd @@ -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 §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); + return; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/93/e0833e34313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/93/e0833e34313e00151cbdba8b5f0a340e new file mode 100644 index 0000000..b905d63 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/93/e0833e34313e00151cbdba8b5f0a340e @@ -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+"> "+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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/94/602d1cd1873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/94/602d1cd1873e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..1ecfa95 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/94/602d1cd1873e00151ce8ff6d4f74dabd @@ -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) + { + 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" + if(args.length==args[2]) + { + String message="§cUsage: /u admin playerinfo §r"; + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/95/6076ddeb303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/95/6076ddeb303e00151cbdba8b5f0a340e new file mode 100644 index 0000000..129cab1 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/95/6076ddeb303e00151cbdba8b5f0a340e @@ -0,0 +1,374 @@ +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 TownColors=new HashMap(); //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=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 Positions=new ArrayList<>(); + //System.out.println("B"); + for(int i=0; i=colors.length) + { + //System.out.println("D"); + int x=0; + for(int i=0; i 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 GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/95/60dd0d99f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/95/60dd0d99f63d00151c31fb33fff4337f deleted file mode 100644 index 2ef29ec..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/95/60dd0d99f63d00151c31fb33fff4337f +++ /dev/null @@ -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 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(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/95/70d8d329853e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/95/70d8d329853e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..b0f40f6 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/95/70d8d329853e00151ce8ff6d4f74dabd @@ -0,0 +1,127 @@ +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") + { + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/96/50bccdcda03e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/96/50bccdcda03e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..9b36498 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/96/50bccdcda03e00151ce8ff6d4f74dabd @@ -0,0 +1,188 @@ +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 §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 §r"; + SendMessage(player, message); + return; + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/97/90b0e2b5013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/97/90b0e2b5013e00151c31fb33fff4337f deleted file mode 100644 index 5edf504..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/97/90b0e2b5013e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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. - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/97/d0fb054da23e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/97/d0fb054da23e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..fe6319f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/97/d0fb054da23e00151ce8ff6d4f74dabd @@ -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 §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 §r"; + SendMessage(player, message); + return; + } + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/97/f0d392d5303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/97/f0d392d5303e00151cbdba8b5f0a340e new file mode 100644 index 0000000..e143040 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/97/f0d392d5303e00151cbdba8b5f0a340e @@ -0,0 +1,420 @@ +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. + { + /*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 PlayerFlairs=new HashMap(); + public static Map PlayerUserNames=new HashMap(); + //public Map PlayerFlairs=new HashMap(); + public static ArrayList Players=new ArrayList(); + public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. + public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. + //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ + public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + //System.out.println("B"); + for(int i=0; i=colors.length) + { + //System.out.println("D"); + int x=0; + for(int i=0; i 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 GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/98/602c8007a33e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/98/602c8007a33e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..66207b9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/98/602c8007a33e00151ce8ff6d4f74dabd @@ -0,0 +1,184 @@ +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 §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" + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/98/a09a052a343e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/98/a09a052a343e00151cbdba8b5f0a340e new file mode 100644 index 0000000..fa6671e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/98/a09a052a343e00151cbdba8b5f0a340e @@ -0,0 +1,6 @@ +package tk.sznp.thebuttonautoflair; + +public class Essentials +{ + +} \ No newline at end of file diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/99/506d71b4013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/99/506d71b4013e00151c31fb33fff4337f deleted file mode 100644 index 5edf504..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/99/506d71b4013e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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. - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/99/6080b854333e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/99/6080b854333e00151cbdba8b5f0a340e new file mode 100644 index 0000000..5e9ffd7 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/99/6080b854333e00151cbdba8b5f0a340e @@ -0,0 +1,5 @@ +package tk.sznp.thebuttonautoflair; + +public class Essentials { + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/99/c02d2d8d8c3e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/99/c02d2d8d8c3e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..fbabed3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/99/c02d2d8d8c3e00151ce8ff6d4f74dabd @@ -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"); + bw = new BufferedWriter(new FileWriter(file, true)); + for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. + { + if(!player.IgnoredFlair) + continue; //2015.08.08. + try { + 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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9a/60a8017fa13e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/9a/60a8017fa13e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..51e8ea3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/9a/60a8017fa13e00151ce8ff6d4f74dabd @@ -0,0 +1,191 @@ +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 §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 §r"; + SendMessage(player, message); + return; + } + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + SendMessage(player, "Stack trace:"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9a/e02043ed303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/9a/e02043ed303e00151cbdba8b5f0a340e new file mode 100644 index 0000000..5681270 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/9a/e02043ed303e00151cbdba8b5f0a340e @@ -0,0 +1,373 @@ +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 TownColors=new HashMap(); //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(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 Positions=new ArrayList<>(); + //System.out.println("B"); + for(int i=0; i=colors.length) + { + //System.out.println("D"); + int x=0; + for(int i=0; i 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 GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9b/50bbab1a313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/9b/50bbab1a313e00151cbdba8b5f0a340e new file mode 100644 index 0000000..79bdfc7 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/9b/50bbab1a313e00151cbdba8b5f0a340e @@ -0,0 +1,25 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.HashMap; + +public class MaybeOfflinePlayer +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; //If the user comments their name, it gets set, it doesn't matter if they accepted it or not + public boolean AcceptedFlair; + public boolean IgnoredFlair; + //public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername) + { + if(!AllPlayers.containsKey(playername)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + return player; + } + return AllPlayers.get(playername); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9b/e0ff56f5303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/9b/e0ff56f5303e00151cbdba8b5f0a340e new file mode 100644 index 0000000..9b0f7f8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/9b/e0ff56f5303e00151cbdba8b5f0a340e @@ -0,0 +1,367 @@ +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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + //System.out.println("D"); + int x=0; + for(int i=0; i 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 GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9d/50e1b4b6883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/9d/50e1b4b6883e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..6c54b93 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/9d/50e1b4b6883e00151ce8ff6d4f74dabd @@ -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 §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; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9e/d0a0364f893e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/9e/d0a0364f893e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..95365e7 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/9e/d0a0364f893e00151ce8ff6d4f74dabd @@ -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"; + 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 §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); + SendMessage(player, "Flair ignored: "+p.IgnoredFlair); + 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; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a/505b7c3b8b3e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/a/505b7c3b8b3e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..9ac2034 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a/505b7c3b8b3e00151ce8ff6d4f74dabd @@ -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()=="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 §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); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a/d08725c0a13e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/a/d08725c0a13e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..466716b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a/d08725c0a13e00151ce8ff6d4f74dabd @@ -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; + + 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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a0/d0bbb843893e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/a0/d0bbb843893e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..cbeaea2 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a0/d0bbb843893e00151ce8ff6d4f74dabd @@ -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 §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); + 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; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a0/e0f602e4303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/a0/e0f602e4303e00151cbdba8b5f0a340e new file mode 100644 index 0000000..a994139 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a0/e0f602e4303e00151cbdba8b5f0a340e @@ -0,0 +1,389 @@ +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 TownColors=new HashMap(); //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. + /*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 Positions=new ArrayList<>(); + //System.out.println("B"); + for(int i=0; i=colors.length) + { + //System.out.println("D"); + int x=0; + for(int i=0; i 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 GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a0/f08cfd11853e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/a0/f08cfd11853e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..abbb5cd --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a0/f08cfd11853e00151ce8ff6d4f74dabd @@ -0,0 +1,120 @@ +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]=="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"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a2/60169512a33e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/a2/60169512a33e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..66207b9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a2/60169512a33e00151ce8ff6d4f74dabd @@ -0,0 +1,184 @@ +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 §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" + SendMessage(player, "Last error:"); + SendMessage(player, PluginMain.LastException.toString()); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a2/d038ff54a03e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/a2/d038ff54a03e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..e7ec0d2 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a2/d038ff54a03e00151ce8ff6d4f74dabd @@ -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); + + } + } + } + + public static Exception LastException; + + 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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a3/e09f3eb6883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/a3/e09f3eb6883e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..f48b09f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a3/e09f3eb6883e00151ce8ff6d4f74dabd @@ -0,0 +1,177 @@ +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 §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"; + 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; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a4/d0f0e8f0033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/a4/d0f0e8f0033e00151c31fb33fff4337f deleted file mode 100644 index fc57414..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a4/d0f0e8f0033e00151c31fb33fff4337f +++ /dev/null @@ -1,426 +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/ - // 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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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 GetPlayers() - { - getServer().getOnlinePlayers(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a5/50d5a85f893e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/a5/50d5a85f893e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..4af679a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a5/50d5a85f893e00151ce8ff6d4f74dabd @@ -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"; + 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 §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); + return; + } + private static void SendMessage(Player player, String message) + { //2015.08.09. + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + return; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a5/d04ca173f93d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/a5/d04ca173f93d00151c31fb33fff4337f deleted file mode 100644 index 2cb43de..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a5/d04ca173f93d00151c31fb33fff4337f +++ /dev/null @@ -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"))+"(test)> "+event.getMessage()); //2015.08.08. - - 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(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a7/d04965c4a03e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/a7/d04965c4a03e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..20ce245 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a7/d04965c4a03e00151ce8ff6d4f74dabd @@ -0,0 +1,186 @@ +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; + } + } + 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 §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 §r"; + SendMessage(player, message); + return; + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a8/d0e720d9a03e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/a8/d0e720d9a03e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..80abe71 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a8/d0e720d9a03e00151ce8ff6d4f74dabd @@ -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 §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 §r"; + SendMessage(player, message); + return; + } + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e8/e08ce196093e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/a9/40e5b0ce303e00151cbdba8b5f0a340e similarity index 95% rename from .metadata/.plugins/org.eclipse.core.resources/.history/e8/e08ce196093e00151c31fb33fff4337f rename to .metadata/.plugins/org.eclipse.core.resources/.history/a9/40e5b0ce303e00151cbdba8b5f0a340e index 6eec9c9..abca588 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e8/e08ce196093e00151c31fb33fff4337f +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a9/40e5b0ce303e00151cbdba8b5f0a340e @@ -22,6 +22,7 @@ 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 @@ -34,17 +35,7 @@ public class PluginMain extends JavaPlugin 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. @@ -56,8 +47,8 @@ public class PluginMain extends JavaPlugin 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(); @@ -120,7 +111,7 @@ public class PluginMain extends JavaPlugin File file=new File("flairsaccepted.txt"); try { BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); - bw.write(player+"\n"); + bw.write(player.PlayerName+"\n"); bw.close(); } catch (IOException e) { System.out.println("Error!\n"+e); @@ -133,7 +124,7 @@ public class PluginMain extends JavaPlugin File file=new File("flairsignored.txt"); try { BufferedWriter bw = new BufferedWriter(new FileWriter(file, true)); - bw.write(player+"\n"); + bw.write(player.PlayerName+"\n"); bw.close(); } catch (IOException e) { System.out.println("Error!\n"+e); @@ -394,7 +385,8 @@ public class PluginMain extends JavaPlugin } //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()).DisplayName=finalname+flair; //2015.08.08. + MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08. } public static String GetColorForTown(String townname) @@ -408,7 +400,7 @@ public class PluginMain extends JavaPlugin { //2015.07.20. //List towns = TownyUniverse.getDataSource().getTowns(); try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); + Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO return town.getName(); } catch (Exception e) { return ""; @@ -420,7 +412,8 @@ public class PluginMain extends JavaPlugin //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()).DisplayName=null; //2015.08.08. + MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08. } public static Collection GetPlayers() diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a9/60ef3b14313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/a9/60ef3b14313e00151cbdba8b5f0a340e new file mode 100644 index 0000000..d63a548 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a9/60ef3b14313e00151cbdba8b5f0a340e @@ -0,0 +1,118 @@ +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; + 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()) + { + 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.Players) + 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"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/aa/80130ae1833e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/aa/80130ae1833e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..9df5fd6 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/aa/80130ae1833e00151ce8ff6d4f74dabd @@ -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(), ) + } + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/aa/e0f7acb18a3e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/aa/e0f7acb18a3e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..9ac2034 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/aa/e0f7acb18a3e00151ce8ff6d4f74dabd @@ -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()=="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 §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); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ab/e0694d38883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/ab/e0694d38883e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..6549d0e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ab/e0694d38883e00151ce8ff6d4f74dabd @@ -0,0 +1,24 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.HashMap; + +public class MaybeOfflinePlayer +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; //If the user comments their name, it gets set, it doesn't matter if they accepted it or not + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername) + { + if(!AllPlayers.containsKey(playername)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + return player; + } + return AllPlayers.get(playername); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ac/d08c8651a03e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/ac/d08c8651a03e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..1533e80 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ac/d08c8651a03e00151ce8ff6d4f74dabd @@ -0,0 +1,345 @@ +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); + + } + } + } + + 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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ac/f0586fbb843e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/ac/f0586fbb843e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..4138abb --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ac/f0586fbb843e00151ce8ff6d4f74dabd @@ -0,0 +1,117 @@ +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; + 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"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ad/d05bdac3883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/ad/d05bdac3883e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..b1f2c2b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ad/d05bdac3883e00151ce8ff6d4f74dabd @@ -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 §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; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/af/505239fb033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/af/505239fb033e00151c31fb33fff4337f deleted file mode 100644 index 277ee06..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/af/505239fb033e00151c31fb33fff4337f +++ /dev/null @@ -1,426 +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/ - // 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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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 GetPlayers() - { - return getServer().getOnlinePlayers(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b/60c8a0e5303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/b/60c8a0e5303e00151cbdba8b5f0a340e new file mode 100644 index 0000000..d3c43e6 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b/60c8a0e5303e00151cbdba8b5f0a340e @@ -0,0 +1,380 @@ +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 TownColors=new HashMap(); //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 : 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 Positions=new ArrayList<>(); + //System.out.println("B"); + for(int i=0; i=colors.length) + { + //System.out.println("D"); + int x=0; + for(int i=0; i 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 GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b1/4022a6f68a3e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/b1/4022a6f68a3e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..9f8e942 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b1/4022a6f68a3e00151ce8ff6d4f74dabd @@ -0,0 +1,177 @@ +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(args.length>0) + System.out.println("Args[0]: "+args[0]); + 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 §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); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b1/503562fa893e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/b1/503562fa893e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..645942c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b1/503562fa893e00151ce8ff6d4f74dabd @@ -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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b1/60eec201313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/b1/60eec201313e00151cbdba8b5f0a340e new file mode 100644 index 0000000..de5a7f9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b1/60eec201313e00151cbdba8b5f0a340e @@ -0,0 +1,357 @@ +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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i 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 GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b1/d01b5059313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/b1/d01b5059313e00151cbdba8b5f0a340e new file mode 100644 index 0000000..8cec1f9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b1/d01b5059313e00151cbdba8b5f0a340e @@ -0,0 +1,67 @@ +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() + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b1/e03de6b6013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/b1/e03de6b6013e00151c31fb33fff4337f deleted file mode 100644 index 5edf504..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b1/e03de6b6013e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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. - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b2/e05c77a7333e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/b2/e05c77a7333e00151cbdba8b5f0a340e new file mode 100644 index 0000000..9c6bf3d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b2/e05c77a7333e00151cbdba8b5f0a340e @@ -0,0 +1,386 @@ +package tk.sznp.thebuttonautoflair; + +import java.io.File; +import java.io.InputStream; +import java.util.List; +import java.util.logging.Logger; + +import org.bukkit.Server; +import org.bukkit.World; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.generator.ChunkGenerator; +import org.bukkit.plugin.PluginDescriptionFile; +import org.bukkit.plugin.PluginLoader; +import org.bukkit.scheduler.BukkitScheduler; +import org.bukkit.scheduler.BukkitTask; + +import com.avaje.ebean.EbeanServer; +import com.earth2me.essentials.AlternativeCommandsHandler; +import com.earth2me.essentials.Backup; +import com.earth2me.essentials.CommandSource; +import com.earth2me.essentials.EssentialsTimer; +import com.earth2me.essentials.I18n; +import com.earth2me.essentials.IConf; +import com.earth2me.essentials.IEssentialsModule; +import com.earth2me.essentials.ISettings; +import com.earth2me.essentials.IUser; +import com.earth2me.essentials.TNTExplodeListener; +import com.earth2me.essentials.User; +import com.earth2me.essentials.UserMap; +import com.earth2me.essentials.Worth; +import com.earth2me.essentials.api.IItemDb; +import com.earth2me.essentials.api.IJails; +import com.earth2me.essentials.api.IWarps; +import com.earth2me.essentials.metrics.Metrics; +import com.earth2me.essentials.perm.PermissionsHandler; +import com.earth2me.essentials.register.payment.Methods; + +import net.ess3.api.IEssentials; + +public class Essentials implements IEssentials { + + @Override + public void addReloadListener(IConf arg0) { + // TODO Auto-generated method stub + + } + + @Override + public int broadcastMessage(String arg0) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public int broadcastMessage(IUser arg0, String arg1) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public int broadcastMessage(String arg0, String arg1) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public AlternativeCommandsHandler getAlternativeCommandsHandler() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Backup getBackup() { + // TODO Auto-generated method stub + return null; + } + + @Override + public I18n getI18n() { + // TODO Auto-generated method stub + return null; + } + + @Override + public IItemDb getItemDb() { + // TODO Auto-generated method stub + return null; + } + + @Override + public IJails getJails() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Metrics getMetrics() { + // TODO Auto-generated method stub + return null; + } + + @Override + public User getOfflineUser(String arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Methods getPaymentMethod() { + // TODO Auto-generated method stub + return null; + } + + @Override + public PermissionsHandler getPermissionsHandler() { + // TODO Auto-generated method stub + return null; + } + + @Override + public BukkitScheduler getScheduler() { + // TODO Auto-generated method stub + return null; + } + + @Override + public ISettings getSettings() { + // TODO Auto-generated method stub + return null; + } + + @Override + public TNTExplodeListener getTNTListener() { + // TODO Auto-generated method stub + return null; + } + + @Override + public EssentialsTimer getTimer() { + // TODO Auto-generated method stub + return null; + } + + @Override + @Deprecated + public User getUser(Object arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public User getUser(String arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public User getUser(Player arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public UserMap getUserMap() { + // TODO Auto-generated method stub + return null; + } + + @Override + public List getVanishedPlayers() { + // TODO Auto-generated method stub + return null; + } + + @Override + public IWarps getWarps() { + // TODO Auto-generated method stub + return null; + } + + @Override + public World getWorld(String arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Worth getWorth() { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean onCommandEssentials(CommandSender arg0, Command arg1, + String arg2, String[] arg3, ClassLoader arg4, String arg5, + String arg6, IEssentialsModule arg7) { + // TODO Auto-generated method stub + return false; + } + + @Override + public void reload() { + // TODO Auto-generated method stub + + } + + @Override + public BukkitTask runTaskAsynchronously(Runnable arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public BukkitTask runTaskLaterAsynchronously(Runnable arg0, long arg1) { + // TODO Auto-generated method stub + return null; + } + + @Override + public int scheduleSyncDelayedTask(Runnable arg0) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public int scheduleSyncDelayedTask(Runnable arg0, long arg1) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public int scheduleSyncRepeatingTask(Runnable arg0, long arg1, long arg2) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void setMetrics(Metrics arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void showError(CommandSource arg0, Throwable arg1, String arg2) { + // TODO Auto-generated method stub + + } + + @Override + public FileConfiguration getConfig() { + // TODO Auto-generated method stub + return null; + } + + @Override + public File getDataFolder() { + // TODO Auto-generated method stub + return null; + } + + @Override + public EbeanServer getDatabase() { + // TODO Auto-generated method stub + return null; + } + + @Override + public ChunkGenerator getDefaultWorldGenerator(String arg0, String arg1) { + // TODO Auto-generated method stub + return null; + } + + @Override + public PluginDescriptionFile getDescription() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Logger getLogger() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getName() { + // TODO Auto-generated method stub + return null; + } + + @Override + public PluginLoader getPluginLoader() { + // TODO Auto-generated method stub + return null; + } + + @Override + public InputStream getResource(String arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Server getServer() { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean isEnabled() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isNaggable() { + // TODO Auto-generated method stub + return false; + } + + @Override + public void onDisable() { + // TODO Auto-generated method stub + + } + + @Override + public void onEnable() { + // TODO Auto-generated method stub + + } + + @Override + public void onLoad() { + // TODO Auto-generated method stub + + } + + @Override + public void reloadConfig() { + // TODO Auto-generated method stub + + } + + @Override + public void saveConfig() { + // TODO Auto-generated method stub + + } + + @Override + public void saveDefaultConfig() { + // TODO Auto-generated method stub + + } + + @Override + public void saveResource(String arg0, boolean arg1) { + // TODO Auto-generated method stub + + } + + @Override + public void setNaggable(boolean arg0) { + // TODO Auto-generated method stub + + } + + @Override + public List onTabComplete(CommandSender arg0, Command arg1, + String arg2, String[] arg3) { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean onCommand(CommandSender arg0, Command arg1, String arg2, + String[] arg3) { + // TODO Auto-generated method stub + return false; + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b5/50e29274053e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/b5/50e29274053e00151c31fb33fff4337f deleted file mode 100644 index 1460680..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b5/50e29274053e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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 GetPlayers() - { - return Instance.getServer().getOnlinePlayers(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b5/60e643b8333e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/b5/60e643b8333e00151cbdba8b5f0a340e new file mode 100644 index 0000000..77f891d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b5/60e643b8333e00151cbdba8b5f0a340e @@ -0,0 +1,331 @@ +package tk.sznp.thebuttonautoflair; + +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 getConfigKeys() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Map getConfigMap() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Map 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 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 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 + + } + +} \ No newline at end of file diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b5/d057e469a03e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/b5/d057e469a03e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..3b0284f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b5/d057e469a03e00151ce8ff6d4f74dabd @@ -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); + LastException=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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b6/504cf350863e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/b6/504cf350863e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..677ad35 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b6/504cf350863e00151ce8ff6d4f74dabd @@ -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()=="showerrors") + 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"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b9/5032653a043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/5032653a043e00151c31fb33fff4337f deleted file mode 100644 index 3787be5..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b9/5032653a043e00151c31fb33fff4337f +++ /dev/null @@ -1,427 +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('&', '§')); - 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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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 GetPlayers() - { - return Instance.getServer().getOnlinePlayers(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b9/d06dd7f9023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/d06dd7f9023e00151c31fb33fff4337f deleted file mode 100644 index 7fba36b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b9/d06dd7f9023e00151c31fb33fff4337f +++ /dev/null @@ -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"))+"(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(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b9/f0e30e98f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/f0e30e98f63d00151c31fb33fff4337f deleted file mode 100644 index 2ef29ec..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b9/f0e30e98f63d00151c31fb33fff4337f +++ /dev/null @@ -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 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(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ba/70faf280883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/ba/70faf280883e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..dc9734e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ba/70faf280883e00151ce8ff6d4f74dabd @@ -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"; + 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 §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]); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ba/d05064d1013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ba/d05064d1013e00151c31fb33fff4337f deleted file mode 100644 index 5edf504..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ba/d05064d1013e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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. - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bd/d02b22e3883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/bd/d02b22e3883e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..80c391c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/bd/d02b22e3883e00151ce8ff6d4f74dabd @@ -0,0 +1,167 @@ +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 §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; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bf/60a98f74863e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/bf/60a98f74863e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..a18a6c0 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/bf/60a98f74863e00151ce8ff6d4f74dabd @@ -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, 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") + { + + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c/609f275f313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/c/609f275f313e00151cbdba8b5f0a340e new file mode 100644 index 0000000..0473087 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c/609f275f313e00151cbdba8b5f0a340e @@ -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 player : 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 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c0/b0b29cfe313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/c0/b0b29cfe313e00151cbdba8b5f0a340e new file mode 100644 index 0000000..2ade719 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c0/b0b29cfe313e00151cbdba8b5f0a340e @@ -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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c2/60afc4f8303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/c2/60afc4f8303e00151cbdba8b5f0a340e new file mode 100644 index 0000000..c708b07 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c2/60afc4f8303e00151cbdba8b5f0a340e @@ -0,0 +1,365 @@ +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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i 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 GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c4/50682add833e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/c4/50682add833e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..1529757 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c4/50682add833e00151ce8ff6d4f74dabd @@ -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(), ) + } + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c4/c0d4e9c9873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/c4/c0d4e9c9873e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..007de20 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c4/c0d4e9c9873e00151ce8ff6d4f74dabd @@ -0,0 +1,148 @@ +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" + if(args.length==args[2]) + { + String message="§cUsage: /u admin playerinfo §r"; + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c4/d04977f0303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/c4/d04977f0303e00151cbdba8b5f0a340e new file mode 100644 index 0000000..83c5482 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c4/d04977f0303e00151cbdba8b5f0a340e @@ -0,0 +1,371 @@ +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 TownColors=new HashMap(); //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) + //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 Positions=new ArrayList<>(); + //System.out.println("B"); + for(int i=0; i=colors.length) + { + //System.out.println("D"); + int x=0; + for(int i=0; i 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 GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c5/703eba51893e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/c5/703eba51893e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..cbeaea2 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c5/703eba51893e00151ce8ff6d4f74dabd @@ -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 §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); + 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; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c6/50d2a147883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/c6/50d2a147883e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..9f90e23 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c6/50d2a147883e00151ce8ff6d4f74dabd @@ -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"; + 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 §r"; + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + String message="§cUsage: /u admin playerinfo §r"; + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c7/404ceb6dff3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/404ceb6dff3d00151c31fb33fff4337f deleted file mode 100644 index 8a9dc0b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c7/404ceb6dff3d00151c31fb33fff4337f +++ /dev/null @@ -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"))+"(test)> "+event.getMessage()); //2015.08.08. - String name; - } - - 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(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c7/e0273ad2843e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/e0273ad2843e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..8f8c62d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/e0273ad2843e00151ce8ff6d4f74dabd @@ -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].toLowerCase()) + { + 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"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c9/d03887b7013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/c9/d03887b7013e00151c31fb33fff4337f deleted file mode 100644 index d412cf3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c9/d03887b7013e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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. - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c9/d0b1d9a5883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/c9/d0b1d9a5883e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..cb9cbd5 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c9/d0b1d9a5883e00151ce8ff6d4f74dabd @@ -0,0 +1,177 @@ +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 §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; + } + private static void SendMessage(Player player, String message) + { + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/cb/50dc5e1fa33e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/cb/50dc5e1fa33e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..5dc0b1d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/cb/50dc5e1fa33e00151ce8ff6d4f74dabd @@ -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 §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, ) + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/cb/d058f890873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/cb/d058f890873e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..1e3d1d3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/cb/d058f890873e00151ce8ff6d4f74dabd @@ -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" + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ce/60e64a99f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ce/60e64a99f63d00151c31fb33fff4337f deleted file mode 100644 index 2ef29ec..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ce/60e64a99f63d00151c31fb33fff4337f +++ /dev/null @@ -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 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(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ce/d07741ef023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ce/d07741ef023e00151c31fb33fff4337f deleted file mode 100644 index a6a1d5d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ce/d07741ef023e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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. - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/cf/40c8a91f043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/cf/40c8a91f043e00151c31fb33fff4337f deleted file mode 100644 index 1d416db..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/cf/40c8a91f043e00151c31fb33fff4337f +++ /dev/null @@ -1,427 +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/ - public 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('&', '§')); - 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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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 GetPlayers() - { - return getServer().getOnlinePlayers(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/cf/5089102f8a3e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/cf/5089102f8a3e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..fb810a8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/cf/5089102f8a3e00151ce8ff6d4f74dabd @@ -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 §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); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d/e05a967e8a3e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/d/e05a967e8a3e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..121a689 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d/e05a967e8a3e00151ce8ff6d4f74dabd @@ -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()=="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") + { + 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 §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); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d/e0ef36df303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/d/e0ef36df303e00151cbdba8b5f0a340e new file mode 100644 index 0000000..fb3c43d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d/e0ef36df303e00151cbdba8b5f0a340e @@ -0,0 +1,404 @@ +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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + //System.out.println("B"); + for(int i=0; i=colors.length) + { + //System.out.println("D"); + int x=0; + for(int i=0; i 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 GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d0/d054706d8c3e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/d0/d054706d8c3e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..8a2669b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d0/d054706d8c3e00151ce8ff6d4f74dabd @@ -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(); + } + 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); + } + } + } 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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d1/d0e5e980a03e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/d1/d0e5e980a03e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..14ace19 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d1/d0e5e980a03e00151ce8ff6d4f74dabd @@ -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(), ) + }*/ + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d4/708262e1303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/d4/708262e1303e00151cbdba8b5f0a340e new file mode 100644 index 0000000..42b0772 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d4/708262e1303e00151cbdba8b5f0a340e @@ -0,0 +1,391 @@ +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 TownColors=new HashMap(); //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; + //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 Positions=new ArrayList<>(); + //System.out.println("B"); + for(int i=0; i=colors.length) + { + //System.out.println("D"); + int x=0; + for(int i=0; i 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 GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d4/d0595525043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/d4/d0595525043e00151c31fb33fff4337f deleted file mode 100644 index bc1be4a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d4/d0595525043e00151c31fb33fff4337f +++ /dev/null @@ -1,427 +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('&', '§')); - 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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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 GetPlayers() - { - return getServer().getOnlinePlayers(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d5/50049d01883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/d5/50049d01883e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..ef471ff --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d5/50049d01883e00151ce8ff6d4f74dabd @@ -0,0 +1,162 @@ +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 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 §r"; + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + return; + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d5/60556449313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/d5/60556449313e00151cbdba8b5f0a340e new file mode 100644 index 0000000..3787dd7 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d5/60556449313e00151cbdba8b5f0a340e @@ -0,0 +1,67 @@ +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. + + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d5/607f4314033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/d5/607f4314033e00151c31fb33fff4337f deleted file mode 100644 index 6ca2c66..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d5/607f4314033e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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()) - { - //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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. - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d5/d023b881073e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/d5/d023b881073e00151c31fb33fff4337f deleted file mode 100644 index 3d1d393..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d5/d023b881073e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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; //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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 GetPlayers() - { - return Instance.getServer().getOnlinePlayers(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d6/e0a112fc303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/d6/e0a112fc303e00151cbdba8b5f0a340e new file mode 100644 index 0000000..d09c590 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d6/e0a112fc303e00151cbdba8b5f0a340e @@ -0,0 +1,361 @@ +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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i 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 GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6f/50a07067fe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/d6/e0a5b112313e00151cbdba8b5f0a340e similarity index 73% rename from .metadata/.plugins/org.eclipse.core.resources/.history/6f/50a07067fe3d00151c31fb33fff4337f rename to .metadata/.plugins/org.eclipse.core.resources/.history/d6/e0a5b112313e00151cbdba8b5f0a340e index 3afc0be..afdf0ca 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6f/50a07067fe3d00151c31fb33fff4337f +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d6/e0a5b112313e00151cbdba8b5f0a340e @@ -17,7 +17,9 @@ public class Commands implements CommandExecutor { Player player = (Player) sender; if(args.length<1) 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"); return true; @@ -26,18 +28,13 @@ public class Commands implements CommandExecutor { { case "accept": { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); - //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(p.IgnoredFlair) + p.IgnoredFlair=false; //2015.08.08. if(!p.AcceptedFlair) { - //String flair=PluginMain.PlayerFlairs.get(player.getName()); String flair=p.Flair; //2015.08.08. - //player.setDisplayName(player.getDisplayName()+flair); PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - //PluginMain.AcceptedPlayers.add(player.getName()); - p.AcceptedFlair=true; + p.AcceptedFlair=true; //2015.08.08. player.sendMessage("§6Your flair has been set:§r "+flair); } else @@ -46,13 +43,13 @@ public class Commands implements CommandExecutor { } case "ignore": { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + if(!p.IgnoredFlair) { - PluginMain.IgnoredPlayers.add(player.getName()); + p.IgnoredFlair=true; //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); + String flair=p.Flair; //2015.08.08. //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); @@ -92,11 +89,13 @@ public class Commands implements CommandExecutor { PluginMain.TownColors.put(s[0], s[1]); } br.close(); - for(Player p : PluginMain.Players) + //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.AppendPlayerDisplayFlairFinal(p, flair); } diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d8/e0a05c04853e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/d8/e0a05c04853e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..9f42545 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d8/e0a05c04853e00151ce8ff6d4f74dabd @@ -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].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. + 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"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d9/40c1973d8b3e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/d9/40c1973d8b3e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..63a1544 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d9/40c1973d8b3e00151ce8ff6d4f74dabd @@ -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 §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); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d9/5013ec41a33e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/d9/5013ec41a33e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..3aefeb1 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d9/5013ec41a33e00151ce8ff6d4f74dabd @@ -0,0 +1,194 @@ +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); + default + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; + } + } + 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 §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."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/da/e0386fb6a03e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/da/e0386fb6a03e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..dc1d56c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/da/e0386fb6a03e00151ce8ff6d4f74dabd @@ -0,0 +1,186 @@ +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; + } + } + 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 §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 "playerinfo" + if(args.length==2) + { + String message="§cUsage: /u admin playerinfo §r"; + SendMessage(player, message); + return; + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/dc/50e028f2023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/dc/50e028f2023e00151c31fb33fff4337f deleted file mode 100644 index 6db15de..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/dc/50e028f2023e00151c31fb33fff4337f +++ /dev/null @@ -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); - getServer().getOnlinePlayers() - //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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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. - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/dd/50875957023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/dd/50875957023e00151c31fb33fff4337f deleted file mode 100644 index a6a1d5d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/dd/50875957023e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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. - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/de/d0395f74a23e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/de/d0395f74a23e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..690770e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/de/d0395f74a23e00151ce8ff6d4f74dabd @@ -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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/df/d01c41c0f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/df/d01c41c0f63d00151c31fb33fff4337f deleted file mode 100644 index 3c6c00f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/df/d01c41c0f63d00151c31fb33fff4337f +++ /dev/null @@ -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 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(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e/e0fe31e9033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/e/e0fe31e9033e00151c31fb33fff4337f deleted file mode 100644 index 3fc50f1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e/e0fe31e9033e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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() - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e3/602ab6bd313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/e3/602ab6bd313e00151cbdba8b5f0a340e new file mode 100644 index 0000000..8938516 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e3/602ab6bd313e00151cbdba8b5f0a340e @@ -0,0 +1,71 @@ +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; + 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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e4/500e63a5a03e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/e4/500e63a5a03e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..3955c4a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e4/500e63a5a03e00151ce8ff6d4f74dabd @@ -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"); + 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; + } + } + 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 §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); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e4/50878e1b8b3e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/e4/50878e1b8b3e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..c744858 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e4/50878e1b8b3e00151ce8ff6d4f74dabd @@ -0,0 +1,177 @@ +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(args.length>0) + System.out.println("Args[0].length: "+args[0].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 §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); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e4/50af645b023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/e4/50af645b023e00151c31fb33fff4337f deleted file mode 100644 index f2a51ac..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e4/50af645b023e00151c31fb33fff4337f +++ /dev/null @@ -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 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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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. - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e4/60215032313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/e4/60215032313e00151cbdba8b5f0a340e new file mode 100644 index 0000000..ac13911 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e4/60215032313e00151cbdba8b5f0a340e @@ -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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e4/60f9a9af313e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/e4/60f9a9af313e00151cbdba8b5f0a340e new file mode 100644 index 0000000..2fd48b2 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e4/60f9a9af313e00151cbdba8b5f0a340e @@ -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(); + } + } + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e5/60ca395f8a3e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/e5/60ca395f8a3e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..da1c13d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e5/60ca395f8a3e00151ce8ff6d4f74dabd @@ -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.length>0 && 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 §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); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e5/60d93450f93d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/e5/60d93450f93d00151c31fb33fff4337f deleted file mode 100644 index 6051f6c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e5/60d93450f93d00151c31fb33fff4337f +++ /dev/null @@ -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"))+"(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(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/df/c0aa55450c3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/e5/a0c874c7303e00151cbdba8b5f0a340e similarity index 97% rename from .metadata/.plugins/org.eclipse.core.resources/.history/df/c0aa55450c3e00151089cca86c5b1a99 rename to .metadata/.plugins/org.eclipse.core.resources/.history/e5/a0c874c7303e00151cbdba8b5f0a340e index 7b905e7..ba283d2 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/df/c0aa55450c3e00151089cca86c5b1a99 +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e5/a0c874c7303e00151cbdba8b5f0a340e @@ -22,6 +22,7 @@ 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 @@ -121,7 +122,7 @@ public class PluginMain extends JavaPlugin File file=new File("flairsaccepted.txt"); try { BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); - bw.write(player+"\n"); + bw.write(player.PlayerName+"\n"); bw.close(); } catch (IOException e) { System.out.println("Error!\n"+e); @@ -134,7 +135,7 @@ public class PluginMain extends JavaPlugin File file=new File("flairsignored.txt"); try { BufferedWriter bw = new BufferedWriter(new FileWriter(file, true)); - bw.write(player+"\n"); + bw.write(player.PlayerName+"\n"); bw.close(); } catch (IOException e) { System.out.println("Error!\n"+e); @@ -396,7 +397,7 @@ public class PluginMain extends JavaPlugin //player.setDisplayName(color+displayname+"§r"+flair); //player.setDisplayName(finalname+flair); //MaybeOfflinePlayer.AllPlayers.get(player.getName()).DisplayName=finalname+flair; //2015.08.08. - MaybeOfflinePlayer.AllPlayers + MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=flair; //2015.08.08. } public static String GetColorForTown(String townname) @@ -410,7 +411,7 @@ public class PluginMain extends JavaPlugin { //2015.07.20. //List towns = TownyUniverse.getDataSource().getTowns(); try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); + Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO return town.getName(); } catch (Exception e) { return ""; @@ -422,7 +423,8 @@ public class PluginMain extends JavaPlugin //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()).DisplayName=null; //2015.08.08. + MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair=null; //2015.08.08. } public static Collection GetPlayers() diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e6/7092210c0a3e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/e6/7092210c0a3e00151c31fb33fff4337f deleted file mode 100644 index efbefe2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e6/7092210c0a3e00151c31fb33fff4337f +++ /dev/null @@ -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);s - 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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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 GetPlayers() - { - return Instance.getServer().getOnlinePlayers(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e7/50501d128d3e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/e7/50501d128d3e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..5c621bc --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e7/50501d128d3e00151ce8ff6d4f74dabd @@ -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.AppendPlayerDisplayFlair(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 §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); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/eb/50847d3fa33e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/eb/50847d3fa33e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..4430d9e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/eb/50847d3fa33e00151ce8ff6d4f74dabd @@ -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); + default: + 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 §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."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/eb/e0406b19853e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/eb/e0406b19853e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..cf9e3b7 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/eb/e0406b19853e00151ce8ff6d4f74dabd @@ -0,0 +1,122 @@ +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); + 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"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ec/d0870f36883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/ec/d0870f36883e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..897b7ad --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ec/d0870f36883e00151ce8ff6d4f74dabd @@ -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 §r"; + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + return; + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ed/d01518738c3e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/ed/d01518738c3e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..eb1e529 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ed/d01518738c3e00151ce8ff6d4f74dabd @@ -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(); + } + 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); + } + } + } 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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ed/d01a721a8b3e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/ed/d01a721a8b3e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..8bae37e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ed/d01a721a8b3e00151ce8ff6d4f74dabd @@ -0,0 +1,177 @@ +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(args.length>0) + System.out.println("Args[0].tolower: "+args[0].toLowerCase()); + 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 §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); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ed/d09b59ba873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/ed/d09b59ba873e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..dce3338 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ed/d09b59ba873e00151ce8ff6d4f74dabd @@ -0,0 +1,148 @@ +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" + if(args.length==args[2]) + { + + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ee/500395f1873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/ee/500395f1873e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..007e8c1 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ee/500395f1873e00151ce8ff6d4f74dabd @@ -0,0 +1,157 @@ +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 §r"; + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + return; + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ef/50b12f8f883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/ef/50b12f8f883e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..07653a6 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ef/50b12f8f883e00151ce8ff6d4f74dabd @@ -0,0 +1,177 @@ +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 §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]); + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + return; + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ef/d0a65f54873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/ef/d0a65f54873e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..b77e8ab --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ef/d0a65f54873e00151ce8ff6d4f74dabd @@ -0,0 +1,140 @@ +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); + break; + } + } + else + player.sendMessage("§cYou need to be OP to use this command.§r"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f/e0df3528853e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/f/e0df3528853e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..51121d3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f/e0df3528853e00151ce8ff6d4f74dabd @@ -0,0 +1,126 @@ +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) + { + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f1/5056a305043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/f1/5056a305043e00151c31fb33fff4337f deleted file mode 100644 index 277ee06..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f1/5056a305043e00151c31fb33fff4337f +++ /dev/null @@ -1,426 +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/ - // 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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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 GetPlayers() - { - return getServer().getOnlinePlayers(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f1/d02f5a6dff3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/f1/d02f5a6dff3d00151c31fb33fff4337f deleted file mode 100644 index 7fba36b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f1/d02f5a6dff3d00151c31fb33fff4337f +++ /dev/null @@ -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"))+"(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(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f1/d06c6fb0a03e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/f1/d06c6fb0a03e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..1cb7e32 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f1/d06c6fb0a03e00151ce8ff6d4f74dabd @@ -0,0 +1,180 @@ +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; + } + } + 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 §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) + { + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f3/50ae2f61873e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/f3/50ae2f61873e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..c1f1c9d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f3/50ae2f61873e00151ce8ff6d4f74dabd @@ -0,0 +1,140 @@ +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"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f4/5072900e883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/f4/5072900e883e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..e500f17 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f4/5072900e883e00151ce8ff6d4f74dabd @@ -0,0 +1,162 @@ +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 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 §r"; + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + return; + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f6/e074276da03e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/f6/e074276da03e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..d01649d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f6/e074276da03e00151ce8ff6d4f74dabd @@ -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); + 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); + } + 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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e2/60b2fa130a3e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/f8/d0bce2658c3e00151ce8ff6d4f74dabd similarity index 71% rename from .metadata/.plugins/org.eclipse.core.resources/.history/e2/60b2fa130a3e00151c31fb33fff4337f rename to .metadata/.plugins/org.eclipse.core.resources/.history/f8/d0bce2658c3e00151ce8ff6d4f74dabd index 962d1ac..1c4d5ef 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e2/60b2fa130a3e00151c31fb33fff4337f +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f8/d0bce2658c3e00151ce8ff6d4f74dabd @@ -34,17 +34,7 @@ public class PluginMain extends JavaPlugin 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. @@ -56,9 +46,8 @@ public class PluginMain extends JavaPlugin 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("Name: " + name); MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. } br.close(); @@ -70,7 +59,6 @@ public class PluginMain extends JavaPlugin 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. } @@ -91,7 +79,6 @@ public class PluginMain extends JavaPlugin } 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(); @@ -113,7 +100,6 @@ public class PluginMain extends JavaPlugin { System.out.println("Error!\n"+e); } - //for(String player : AcceptedPlayers) for(MaybeOfflinePlayer player : MaybeOfflinePlayer.AllPlayers.values()) //<-- 2015.08.08. { if(!player.AcceptedFlair) @@ -121,7 +107,7 @@ public class PluginMain extends JavaPlugin File file=new File("flairsaccepted.txt"); try { BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); - bw.write(player+"\n"); + bw.write(player.PlayerName+"\n"); bw.close(); } catch (IOException e) { System.out.println("Error!\n"+e); @@ -134,7 +120,7 @@ public class PluginMain extends JavaPlugin File file=new File("flairsignored.txt"); try { BufferedWriter bw = new BufferedWriter(new FileWriter(file, true)); - bw.write(player+"\n"); + bw.write(player.PlayerName+"\n"); bw.close(); } catch (IOException e) { System.out.println("Error!\n"+e); @@ -145,12 +131,6 @@ public class PluginMain extends JavaPlugin 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 @@ -173,7 +153,6 @@ public class PluginMain extends JavaPlugin ign = ign.trim(); if(HasIGFlair(ign)) continue; - //System.out.println("Author: "+author); try { Thread.sleep(10); } catch(InterruptedException ex) { @@ -190,7 +169,6 @@ public class PluginMain extends JavaPlugin else flair = "non-presser"; String flairclass; - //System.out.println("flairdata.length:"+flairdata.length); if(flairdata.length>2) flairclass = flairdata[2]; else @@ -219,30 +197,9 @@ public class PluginMain extends JavaPlugin return body; } - //It has to store offline player flairs too, therefore it can't use Player object - /*public static Map PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ public static Map TownColors=new HashMap(); //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. } @@ -285,32 +242,15 @@ public class PluginMain extends JavaPlugin } 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; } } @@ -318,19 +258,15 @@ public class PluginMain extends JavaPlugin 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"); @@ -338,23 +274,18 @@ public class PluginMain extends JavaPlugin 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 Positions=new ArrayList<>(); - //System.out.println("B"); for(int i=0; i=colors.length) { - //System.out.println("D"); int x=0; for(int i=0; i towns = TownyUniverse.getDataSource().getTowns(); try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); + Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO return town.getName(); } catch (Exception e) { return ""; @@ -418,10 +338,7 @@ public class PluginMain extends JavaPlugin 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 GetPlayers() diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f8/e04b0add303e00151cbdba8b5f0a340e b/.metadata/.plugins/org.eclipse.core.resources/.history/f8/e04b0add303e00151cbdba8b5f0a340e new file mode 100644 index 0000000..cf8ca2c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f8/e04b0add303e00151cbdba8b5f0a340e @@ -0,0 +1,412 @@ +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; + } + + //It has to store offline player flairs too, therefore it can't use Player object + /*public static Map PlayerFlairs=new HashMap(); + public static Map PlayerUserNames=new HashMap(); + //public Map PlayerFlairs=new HashMap(); + public static ArrayList Players=new ArrayList(); + public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. + public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. + //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ + public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + //System.out.println("B"); + for(int i=0; i=colors.length) + { + //System.out.println("D"); + int x=0; + for(int i=0; i 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 GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/fb/503cf63d883e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/fb/503cf63d883e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..aeba6ef --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/fb/503cf63d883e00151ce8ff6d4f74dabd @@ -0,0 +1,167 @@ +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 §r"; + if(player==null) + System.out.println(message); + else + player.sendMessage(message); + return; + } + if(!MaybeOfflinePlayer.AllPlayers.containsKey(args[2])) + { + + } + MaybeOfflinePlayer p = MaybeOfflinePlayer.AllPlayers.get(args[2]); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/fb/509ddae4a03e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/fb/509ddae4a03e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..2b1b3f3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/fb/509ddae4a03e00151ce8ff6d4f74dabd @@ -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 §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 §r"; + SendMessage(player, message); + return; + } + SendMessage(player, "Last error:"); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/fb/d04f5e36a33e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/fb/d04f5e36a33e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..ceb79ce --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/fb/d04f5e36a33e00151ce8ff6d4f74dabd @@ -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 §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."); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/fd/502d2d7b8c3e00151ce8ff6d4f74dabd b/.metadata/.plugins/org.eclipse.core.resources/.history/fd/502d2d7b8c3e00151ce8ff6d4f74dabd new file mode 100644 index 0000000..a3e6d23 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/fd/502d2d7b8c3e00151ce8ff6d4f74dabd @@ -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 { + 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 TownColors=new HashMap(); //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 Positions=new ArrayList<>(); + for(int i=0; i=colors.length) + { + int x=0; + for(int i=0; i GetPlayers() + { + return Instance.getServer().getOnlinePlayers(); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/fe/50e0facf023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/fe/50e0facf023e00151c31fb33fff4337f deleted file mode 100644 index ff19301..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/fe/50e0facf023e00151c31fb33fff4337f +++ /dev/null @@ -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 PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ - public static Map TownColors=new HashMap(); //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 Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length) - { - //System.out.println("D"); - int x=0; - for(int i=0; i 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. - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/RemoteSystemsTempFiles/.markers.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/RemoteSystemsTempFiles/.markers.snap index 1253ec8..58ccd56 100644 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.projects/RemoteSystemsTempFiles/.markers.snap and b/.metadata/.plugins/org.eclipse.core.resources/.projects/RemoteSystemsTempFiles/.markers.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/RemoteSystemsTempFiles/.syncinfo.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/RemoteSystemsTempFiles/.syncinfo.snap index 1253ec8..58ccd56 100644 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.projects/RemoteSystemsTempFiles/.syncinfo.snap and b/.metadata/.plugins/org.eclipse.core.resources/.projects/RemoteSystemsTempFiles/.syncinfo.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.indexes/e4/77/69/e/history.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.indexes/e4/77/69/e/history.index index f6e5158..283cb9c 100644 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.indexes/e4/77/69/e/history.index and b/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.indexes/e4/77/69/e/history.index differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.markers b/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.markers index 1f85f23..b420625 100644 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.markers and b/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.markers differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.markers.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.markers.snap index e657408..5e64307 100644 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.markers.snap and b/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.markers.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.syncinfo.snap b/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.syncinfo.snap index 1253ec8..58ccd56 100644 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.syncinfo.snap and b/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.syncinfo.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.root/.markers.snap b/.metadata/.plugins/org.eclipse.core.resources/.root/.markers.snap index 1253ec8..58ccd56 100644 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.root/.markers.snap and b/.metadata/.plugins/org.eclipse.core.resources/.root/.markers.snap differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.root/5.tree b/.metadata/.plugins/org.eclipse.core.resources/.root/7.tree similarity index 57% rename from .metadata/.plugins/org.eclipse.core.resources/.root/5.tree rename to .metadata/.plugins/org.eclipse.core.resources/.root/7.tree index 390c11a..3611074 100644 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.root/5.tree and b/.metadata/.plugins/org.eclipse.core.resources/.root/7.tree differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources b/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources index 3e5e408..0b04942 100644 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources and b/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.snap b/.metadata/.plugins/org.eclipse.core.resources/.snap index 8425340..b15ce78 100644 Binary files a/.metadata/.plugins/org.eclipse.core.resources/.snap and b/.metadata/.plugins/org.eclipse.core.resources/.snap differ diff --git a/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi b/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi index 9b6a653..86d712e 100644 --- a/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi +++ b/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi @@ -1,7 +1,7 @@ activeSchemeId:org.eclipse.ui.defaultAcceleratorConfiguration - + topLevel shellMaximized @@ -202,7 +202,7 @@ - + @@ -235,31 +235,31 @@ categoryTag:Help - + newtablook org.eclipse.e4.primaryDataStack EditorStack - + Editor org.eclipse.jdt.ui.CompilationUnitEditor removeOnHide - activeOnClose - + Editor org.eclipse.jdt.ui.CompilationUnitEditor removeOnHide - + Editor org.eclipse.jdt.ui.CompilationUnitEditor removeOnHide + activeOnClose - + Editor org.eclipse.jdt.ui.CompilationUnitEditor removeOnHide @@ -317,8 +317,8 @@ View categoryTag:General - - + + View categoryTag:General @@ -420,18 +420,18 @@ Draggable - - - - - - - - - - - - + + + + + + + + + + + + toolbarSeparator @@ -439,38 +439,38 @@ Draggable - - - + + + Draggable - - + + Draggable - - + + Draggable - - + + Draggable - - - - + + + + Draggable - - - - + + + + Draggable @@ -480,20 +480,20 @@ Draggable - - - - + + + + Draggable - - - - - - - + + + + + + + Draggable @@ -511,15 +511,15 @@ Draggable - - - - - - - - - + + + + + + + + + toolbarSeparator @@ -531,8 +531,8 @@ Draggable - - + + stretch diff --git a/.metadata/.plugins/org.eclipse.jdt.core/1508644233.index b/.metadata/.plugins/org.eclipse.jdt.core/1508644233.index index 3d68147..9b7966a 100644 Binary files a/.metadata/.plugins/org.eclipse.jdt.core/1508644233.index and b/.metadata/.plugins/org.eclipse.jdt.core/1508644233.index differ diff --git a/.metadata/.plugins/org.eclipse.jdt.core/savedIndexNames.txt b/.metadata/.plugins/org.eclipse.jdt.core/savedIndexNames.txt index 08ab0e4..7741d94 100644 --- a/.metadata/.plugins/org.eclipse.jdt.core/savedIndexNames.txt +++ b/.metadata/.plugins/org.eclipse.jdt.core/savedIndexNames.txt @@ -1,5 +1,5 @@ INDEX VERSION 1.126+D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin\.metadata\.plugins\org.eclipse.jdt.core -1508644233.index +3045053200.index 3089967703.index 2674037006.index 323251068.index @@ -22,5 +22,5 @@ INDEX VERSION 1.126+D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spi 3954291735.index 994834796.index 3604769962.index -3045053200.index +1508644233.index 3656756579.index diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/QualifiedTypeNameHistory.xml b/.metadata/.plugins/org.eclipse.jdt.ui/QualifiedTypeNameHistory.xml index 5cf3193..af0e569 100644 --- a/.metadata/.plugins/org.eclipse.jdt.ui/QualifiedTypeNameHistory.xml +++ b/.metadata/.plugins/org.eclipse.jdt.ui/QualifiedTypeNameHistory.xml @@ -37,21 +37,26 @@ - - - + + + + + + + + diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/0.png b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/0.png index 9abe3c5..a95f608 100644 Binary files a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/0.png and b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/0.png differ diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/2.png b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/2.png index a95f608..9abe3c5 100644 Binary files a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/2.png and b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/2.png differ diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/3.png b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/3.png index d198a93..31311ab 100644 Binary files a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/3.png and b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/3.png differ diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/4.png b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/4.png index a930fe1..a6abcd8 100644 Binary files a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/4.png and b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/4.png differ diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/5.png b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/5.png index c1396b1..c00d1cb 100644 Binary files a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/5.png and b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/5.png differ diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/6.png b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/6.png new file mode 100644 index 0000000..a930fe1 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/6.png differ diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/7.png b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/7.png new file mode 100644 index 0000000..d198a93 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/7.png differ diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/8.png b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/8.png new file mode 100644 index 0000000..834bd74 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/8.png differ diff --git a/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/TheButtonAutoFlair/2015/8/32/refactorings.history b/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/TheButtonAutoFlair/2015/8/32/refactorings.history new file mode 100644 index 0000000..d388da2 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/TheButtonAutoFlair/2015/8/32/refactorings.history @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/TheButtonAutoFlair/2015/8/32/refactorings.index b/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/TheButtonAutoFlair/2015/8/32/refactorings.index new file mode 100644 index 0000000..707fa27 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/TheButtonAutoFlair/2015/8/32/refactorings.index @@ -0,0 +1 @@ +1439082947025 Delete element diff --git a/.metadata/.plugins/org.eclipse.ui.editors/dialog_settings.xml b/.metadata/.plugins/org.eclipse.ui.editors/dialog_settings.xml new file mode 100644 index 0000000..50f1edb --- /dev/null +++ b/.metadata/.plugins/org.eclipse.ui.editors/dialog_settings.xml @@ -0,0 +1,5 @@ + +
+
+
+
diff --git a/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml b/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml index 8fa58f5..975f072 100644 --- a/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml +++ b/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml @@ -6,4 +6,6 @@ + + \ No newline at end of file diff --git a/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/Commands.class b/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/Commands.class index d2e0bc8..d69dec3 100644 Binary files a/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/Commands.class and b/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/Commands.class differ diff --git a/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/MaybeOfflinePlayer.class b/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/MaybeOfflinePlayer.class index a074da4..4d8f97d 100644 Binary files a/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/MaybeOfflinePlayer.class and b/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/MaybeOfflinePlayer.class differ diff --git a/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PlayerListener.class b/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PlayerListener.class index 8c0b249..37ef241 100644 Binary files a/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PlayerListener.class and b/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PlayerListener.class differ diff --git a/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PluginMain$1.class b/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PluginMain$1.class index 2fbf8d7..c70cdcc 100644 Binary files a/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PluginMain$1.class and b/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PluginMain$1.class differ diff --git a/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PluginMain.class b/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PluginMain.class index df3ad15..b00662b 100644 Binary files a/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PluginMain.class and b/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PluginMain.class differ diff --git a/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/Commands.java b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/Commands.java index 1cd84d0..21abae7 100644 --- a/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/Commands.java +++ b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/Commands.java @@ -24,22 +24,16 @@ public class Commands implements CommandExecutor { player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); return true; } - switch(args[0]) + switch(args[0].toLowerCase()) //toLowerCase: 2015.08.09. { case "accept": { - /*if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName());*/ if(p.IgnoredFlair) p.IgnoredFlair=false; //2015.08.08. - //if(!PluginMain.AcceptedPlayers.contains(player.getName())) if(!p.AcceptedFlair) { - //String flair=PluginMain.PlayerFlairs.get(player.getName()); String flair=p.Flair; //2015.08.08. - //player.setDisplayName(player.getDisplayName()+flair); PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - //PluginMain.AcceptedPlayers.add(player.getName()); p.AcceptedFlair=true; //2015.08.08. player.sendMessage("§6Your flair has been set:§r "+flair); } @@ -54,9 +48,7 @@ public class Commands implements CommandExecutor { if(!p.IgnoredFlair) { p.IgnoredFlair=true; - //String dname=player.getDisplayName(); String flair=p.Flair; //2015.08.08. - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); PluginMain.RemovePlayerDisplayFlairFinal(player, flair); //2015.07.20. player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); } @@ -64,23 +56,30 @@ public class Commands implements CommandExecutor { player.sendMessage("§cYou already ignored this request.§r"); break; } - case "reload": //2015.07.20. + /*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]=="reload") - DoReload(null); //2015.07.20. + /*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()) - { + //if(player==null || player.isOp() || player.getName()=="NorbiPeti") + //{ try { File file=new File("autoflairconfig.txt"); @@ -95,7 +94,6 @@ public class Commands implements CommandExecutor { PluginMain.TownColors.put(s[0], s[1]); } br.close(); - //for(Player p : PluginMain.Players) for(Player p : PluginMain.GetPlayers()) { MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); @@ -107,10 +105,7 @@ public class Commands implements CommandExecutor { } } String msg="§6Reloaded config file.§r"; - if(player!=null) - player.sendMessage(msg); - else - System.out.println(msg); + SendMessage(player, msg); //2015.08.09. } } catch(Exception e) @@ -118,9 +113,82 @@ public class Commands implements CommandExecutor { 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); + default: + String message="§cUsage: /u admin reload|playerinfo§r"; + SendMessage(player, message); + return; } } 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 §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."); + } } diff --git a/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/MaybeOfflinePlayer.java b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/MaybeOfflinePlayer.java index 79bdfc7..6549d0e 100644 --- a/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/MaybeOfflinePlayer.java +++ b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/MaybeOfflinePlayer.java @@ -9,7 +9,6 @@ public class MaybeOfflinePlayer public String Flair; //If the user comments their name, it gets set, it doesn't matter if they accepted it or not public boolean AcceptedFlair; public boolean IgnoredFlair; - //public String DisplayName; public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. public static MaybeOfflinePlayer AddPlayerIfNeeded(String playername) { diff --git a/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PlayerListener.java b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PlayerListener.java index 0e6c94e..a085586 100644 --- a/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PlayerListener.java +++ b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PlayerListener.java @@ -15,48 +15,35 @@ public class PlayerListener implements Listener 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. MaybeOfflinePlayer.AddPlayerIfNeeded(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 { //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"))+"(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. - event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+event.getMessage()); //2015.08.08. + String message=event.getMessage(); //2015.08.08. + /*for(Player p : PluginMain.GetPlayers()) + { //2015.08.08. + message.replaceAll(p.getName(), ) + }*/ + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+flair+"> "+message); //2015.08.08. } private static Class nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); @@ -77,6 +64,7 @@ public class PlayerListener implements Listener System.out.println("6"); } catch (Exception e) { e.printStackTrace(); + PluginMain.LastException=e; //2015.08.09. } } diff --git a/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PluginMain.java b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PluginMain.java index ba283d2..5740654 100644 --- a/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PluginMain.java +++ b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PluginMain.java @@ -22,7 +22,6 @@ 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 @@ -35,17 +34,7 @@ public class PluginMain extends JavaPlugin 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. @@ -57,9 +46,8 @@ public class PluginMain extends JavaPlugin 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("Name: " + name); MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. } br.close(); @@ -71,7 +59,6 @@ public class PluginMain extends JavaPlugin 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. } @@ -89,10 +76,11 @@ public class PluginMain extends JavaPlugin } br.close(); } + //throw new IOException("Test"); //2015.08.09. } catch (IOException e) { System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. } - //System.out.println("Registering done."); Runnable r=new Runnable(){public void run(){ThreadMethod();}}; Thread t=new Thread(r); t.start(); @@ -113,45 +101,36 @@ public class PluginMain extends JavaPlugin catch(Exception e) { System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. } - //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)); + 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(); - } 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.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); - } - } + } + bw.close(); + } catch (IOException e) { + System.out.println("Error!\n"+e); + LastException=e; //2015.08.09. + } 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 @@ -174,7 +153,6 @@ public class PluginMain extends JavaPlugin ign = ign.trim(); if(HasIGFlair(ign)) continue; - //System.out.println("Author: "+author); try { Thread.sleep(10); } catch(InterruptedException ex) { @@ -191,7 +169,6 @@ public class PluginMain extends JavaPlugin else flair = "non-presser"; String flairclass; - //System.out.println("flairdata.length:"+flairdata.length); if(flairdata.length>2) flairclass = flairdata[2]; else @@ -203,10 +180,13 @@ public class PluginMain extends JavaPlugin 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); @@ -220,30 +200,9 @@ public class PluginMain extends JavaPlugin return body; } - //It has to store offline player flairs too, therefore it can't use Player object - /*public static Map PlayerFlairs=new HashMap(); - public static Map PlayerUserNames=new HashMap(); - //public Map PlayerFlairs=new HashMap(); - public static ArrayList Players=new ArrayList(); - public static ArrayList AcceptedPlayers=new ArrayList(); //2015.07.16. - public static ArrayList IgnoredPlayers=new ArrayList(); //2015.07.16. - //public static Map PlayerTowns=new HashMap(); //2015.07.20.*/ public static Map TownColors=new HashMap(); //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. } @@ -286,32 +245,15 @@ public class PluginMain extends JavaPlugin } 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; } } @@ -319,19 +261,15 @@ public class PluginMain extends JavaPlugin 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"); @@ -339,23 +277,18 @@ public class PluginMain extends JavaPlugin 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 Positions=new ArrayList<>(); - //System.out.println("B"); for(int i=0; i=colors.length) { - //System.out.println("D"); int x=0; for(int i=0; i towns = TownyUniverse.getDataSource().getTowns(); try { Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); //TODO return town.getName(); @@ -420,10 +341,6 @@ public class PluginMain extends JavaPlugin 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. }