From 8de31369f8aa36f5837f993d687e778bfb6b1143 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 8 Aug 2015 22:58:45 +0200 Subject: [PATCH] Added can't press flair, OO, compatible with Essentials - Added can't press flair - Made an object, instead of many Maps - Using chat formatting instead of display names --- .metadata/.log | 177 +++++++ .metadata/.mylyn/.tasks.xml.zip | Bin 250 -> 250 bytes .metadata/.mylyn/tasks.xml.zip | Bin 250 -> 250 bytes .../0/4026a562ef2e001511a3ba75618c68e5 | 343 -------------- .../0/6088cf20022f001511a3ba75618c68e5 | 68 --- .../0/a0189d31a72b00151fa6e49f3e10bf0b | 48 -- .../0/d057cb01fa3d00151c31fb33fff4337f | 7 + .../1/10092140c52e001511a3ba75618c68e5 | 307 ------------ .../1/60ca8b100a3e00151c31fb33fff4337f | 431 +++++++++++++++++ .../1/d0997b1b023e00151c31fb33fff4337f | 125 +++++ .../1/f03cfc260d3e00151089cca86c5b1a99 | 434 +++++++++++++++++ .../10/704e9345022f001511a3ba75618c68e5 | 73 --- .../10/70a9b080083e00151c31fb33fff4337f | 25 + .../10/80a0b699f63d00151c31fb33fff4337f | 74 +++ .../10/e03d4f54f62e001511a3ba75618c68e5 | 383 --------------- .../11/302d82aec52e001511a3ba75618c68e5 | 312 ------------- .../11/50857fe1f93d00151c31fb33fff4337f | 5 + .../11/50a623b5013e00151c31fb33fff4337f | 418 +++++++++++++++++ .../11/6040761c022f001511a3ba75618c68e5 | 67 --- .../11/703abcfff12e001511a3ba75618c68e5 | 371 --------------- .../11/b0a0fc59e42d0015105bf01c854e42e3 | 286 ------------ .../11/e02f8f8d083e00151c31fb33fff4337f | 126 +++++ .../12/2027da9cac2b00151fa6e49f3e10bf0b | 73 --- .../13/604732c5f52e001511a3ba75618c68e5 | 382 --------------- .../13/b00ee04cc72e001511a3ba75618c68e5 | 319 ------------- .../14/70fadb62ff2e001511a3ba75618c68e5 | 49 -- .../14/901ce7a4912b00151fa6e49f3e10bf0b | 27 -- .../14/d01b6d05f52e001511a3ba75618c68e5 | 382 --------------- .../15/20b3105acf2e001511a3ba75618c68e5 | 92 ---- .../15/4032ab5dbf2e001511a3ba75618c68e5 | 64 --- .../15/602ef8eded2e001511a3ba75618c68e5 | 337 -------------- .../15/9032115ca42b00151fa6e49f3e10bf0b | 37 -- .../15/905b71c7ed2e001511a3ba75618c68e5 | 336 -------------- .../15/d05be66e043e00151c31fb33fff4337f | 126 +++++ .../16/10971668a42b00151fa6e49f3e10bf0b | 41 -- .../16/b03d628ac42e001511a3ba75618c68e5 | 294 ------------ .../17/202ded81a92b00151fa6e49f3e10bf0b | 61 --- .../17/90bccd90922b00151fa6e49f3e10bf0b | 16 - .../17/a0348882a92b00151fa6e49f3e10bf0b | 63 --- .../17/d004cf02fd3d00151c31fb33fff4337f | 24 + .../17/d08a7e97f63d00151c31fb33fff4337f | 74 +++ .../18/2072884bc02e001511a3ba75618c68e5 | 292 ------------ .../18/a075b55fc92e001511a3ba75618c68e5 | 333 ------------- .../18/e00b6b58ef2e001511a3ba75618c68e5 | 343 -------------- .../18/e024139bf02e001511a3ba75618c68e5 | 354 -------------- .../18/e07d8480f52e001511a3ba75618c68e5 | 382 --------------- .../19/0072a52f022f001511a3ba75618c68e5 | 69 --- .../19/60f2ab7f023e00151c31fb33fff4337f | 421 +++++++++++++++++ .../1a/a09f2e39c52e001511a3ba75618c68e5 | 307 ------------ .../1a/c0cfb22dc02e001511a3ba75618c68e5 | 292 ------------ .../1a/d0fbf199f63d00151c31fb33fff4337f | 74 +++ .../1b/9066f985a92b00151fa6e49f3e10bf0b | 63 --- .../1b/f0224de8f62e001511a3ba75618c68e5 | 384 --------------- .../1b/f0c4a095083e00151c31fb33fff4337f | 126 +++++ .../1c/50a873c4093e00151c31fb33fff4337f | 431 +++++++++++++++++ .../1c/6074bf28f12e001511a3ba75618c68e5 | 361 --------------- .../1c/609377ad0d3e00151089cca86c5b1a99 | 437 ++++++++++++++++++ .../1c/90a675ce902b00151fa6e49f3e10bf0b | 21 - .../1d/2083e990ac2b00151fa6e49f3e10bf0b | 244 ---------- .../1e/10a41e97ee2e001511a3ba75618c68e5 | 341 -------------- .../1e/504c9d52ef2e001511a3ba75618c68e5 | 343 -------------- .../1e/a0220ef3ab2b00151fa6e49f3e10bf0b | 254 ---------- .../1f/2028de3fcf2e001511a3ba75618c68e5 | 85 ---- .../1f/b00d77f0c42e001511a3ba75618c68e5 | 307 ------------ .../2/c07312e9bf2e001511a3ba75618c68e5 | 291 ------------ .../20/a01363d8a82b00151fa6e49f3e10bf0b | 50 -- .../20/a040189aaf2b00151fa6e49f3e10bf0b | 285 ------------ .../20/a0f94f72cf2e001511a3ba75618c68e5 | 94 ---- .../21/6079da59fa2e001511a3ba75618c68e5 | 391 ---------------- .../21/9091585acf2e001511a3ba75618c68e5 | 92 ---- .../22/10b43daf9b2b00151fa6e49f3e10bf0b | 43 -- .../22/a0bbe40cc52e001511a3ba75618c68e5 | 307 ------------ .../23/40423b2bcf2e001511a3ba75618c68e5 | 67 --- .../23/60878d1afb2e001511a3ba75618c68e5 | 397 ---------------- .../23/a0089f13c62e001511a3ba75618c68e5 | 312 ------------- .../24/205b7a17d32e001511a3ba75618c68e5 | 335 -------------- .../24/60c0f732f92e001511a3ba75618c68e5 | 389 ---------------- .../24/b0050f65c02e001511a3ba75618c68e5 | 292 ------------ .../24/d08c2d11033e00151c31fb33fff4337f | 419 +++++++++++++++++ .../26/103a93e1922b00151fa6e49f3e10bf0b | 31 -- .../26/908a556aa42b00151fa6e49f3e10bf0b | 41 -- .../26/d01f259ef02e001511a3ba75618c68e5 | 355 -------------- .../27/603d2e77012f001511a3ba75618c68e5 | 67 --- .../27/6094151b012f001511a3ba75618c68e5 | 50 -- .../27/7096e0b1f12e001511a3ba75618c68e5 | 370 --------------- .../27/70ba5e30032f001511a3ba75618c68e5 | 78 ---- .../27/d0c61635023e00151c31fb33fff4337f | 125 +++++ .../28/50c3d09efd3d00151c31fb33fff4337f | 26 ++ .../29/4085cc81fe3d00151c31fb33fff4337f | 122 +++++ .../29/500adc32083e00151c31fb33fff4337f | 25 + .../29/50dd5657043e00151c31fb33fff4337f | 125 +++++ .../2a/104eb717a72b00151fa6e49f3e10bf0b | 47 -- .../2a/20a4e0af0d3e00151089cca86c5b1a99 | 434 +++++++++++++++++ .../2a/20defcdbc72e001511a3ba75618c68e5 | 322 ------------- .../2a/304ef98cc22e001511a3ba75618c68e5 | 294 ------------ .../2b/b071b16acf2e001511a3ba75618c68e5 | 93 ---- .../2b/c0dde05e023e00151c31fb33fff4337f | 420 +++++++++++++++++ .../2c/20ac6667d22e001511a3ba75618c68e5 | 99 ---- .../2c/50d8e8c4093e00151c31fb33fff4337f | 431 +++++++++++++++++ .../2d/20ebe2afc42e001511a3ba75618c68e5 | 294 ------------ .../2d/60a68ad9013e00151c31fb33fff4337f | 419 +++++++++++++++++ .../2d/9018d69a922b00151fa6e49f3e10bf0b | 17 - .../2d/c0b10f0c023e00151c31fb33fff4337f | 124 +++++ .../2e/204539a2c72e001511a3ba75618c68e5 | 321 ------------- .../2e/c0323f76053e00151c31fb33fff4337f | 429 +++++++++++++++++ .../2f/10f28f28922b00151fa6e49f3e10bf0b | 32 -- .../2f/60c08aa1ed2e001511a3ba75618c68e5 | 335 -------------- .../2f/901fe416a72b00151fa6e49f3e10bf0b | 47 -- .../2f/c09b39d5013e00151c31fb33fff4337f | 419 +++++++++++++++++ .../3/60b156f3ed2e001511a3ba75618c68e5 | 337 -------------- .../3/a0abcccdac2b00151fa6e49f3e10bf0b | 265 ----------- .../30/60904025fd2e001511a3ba75618c68e5 | 44 -- .../30/a046033cc92e001511a3ba75618c68e5 | 332 ------------- .../31/2034c778a42b00151fa6e49f3e10bf0b | 41 -- .../32/104e4dffa62b00151fa6e49f3e10bf0b | 45 -- .../32/306725aec52e001511a3ba75618c68e5 | 311 ------------- .../32/60416866f22e001511a3ba75618c68e5 | 378 --------------- .../32/c036aae2063e00151c31fb33fff4337f | 84 ++++ .../32/e0bd8a0af82e001511a3ba75618c68e5 | 108 ----- .../33/307f3ebec52e001511a3ba75618c68e5 | 312 ------------- .../33/608c284a083e00151c31fb33fff4337f | 126 +++++ .../33/90978488a42b00151fa6e49f3e10bf0b | 42 -- .../33/b022d410ae2b00151fa6e49f3e10bf0b | 278 ----------- .../33/e0e8f0d9c42e001511a3ba75618c68e5 | 299 ------------ .../34/20530121c82e001511a3ba75618c68e5 | 323 ------------- .../34/2066c3cdc82e001511a3ba75618c68e5 | 326 ------------- .../35/20ec61bbc52e001511a3ba75618c68e5 | 312 ------------- .../35/90f4067f922b00151fa6e49f3e10bf0b | 16 - .../35/a0d28e1ac92e001511a3ba75618c68e5 | 327 ------------- .../35/d0feddc3f12e001511a3ba75618c68e5 | 373 --------------- .../36/407f1825013e00151c31fb33fff4337f | 124 +++++ .../37/400d6ebfbf2e001511a3ba75618c68e5 | 287 ------------ .../37/a0adde5a022b00151fa6e49f3e10bf0b | 11 - .../38/30ed4da8d12e001511a3ba75618c68e5 | 98 ---- .../38/601c14b2013e00151c31fb33fff4337f | 418 +++++++++++++++++ .../38/609a0a5fef2e001511a3ba75618c68e5 | 343 -------------- .../39/10f83522922b00151fa6e49f3e10bf0b | 32 -- .../39/60013fb6013e00151c31fb33fff4337f | 418 +++++++++++++++++ .../39/7076fe6ff92e001511a3ba75618c68e5 | 389 ---------------- .../39/e0e3f38efd2e001511a3ba75618c68e5 | 47 -- .../3a/20e5cd02ae2b00151fa6e49f3e10bf0b | 280 ----------- .../3a/300567b8d12e001511a3ba75618c68e5 | 334 ------------- .../3a/705720220d3e00151089cca86c5b1a99 | 433 +++++++++++++++++ .../3a/f0edd7def02e001511a3ba75618c68e5 | 360 --------------- .../3b/d0078548033e00151c31fb33fff4337f | 78 ++++ .../3b/e033e73b033e00151c31fb33fff4337f | 77 +++ .../3c/100230c7c72e001511a3ba75618c68e5 | 322 ------------- .../3c/508e5c2c053e00151c31fb33fff4337f | 25 + .../3d/2034d8fed22e001511a3ba75618c68e5 | 105 ----- .../3d/b0b429e1c52e001511a3ba75618c68e5 | 312 ------------- .../3e/501e53c6c12e001511a3ba75618c68e5 | 294 ------------ .../3e/d041c107f12e001511a3ba75618c68e5 | 361 --------------- .../3e/f09f99a6f12e001511a3ba75618c68e5 | 369 --------------- .../3f/10680ce29a2b00151fa6e49f3e10bf0b | 37 -- .../3f/5082b24efd3d00151c31fb33fff4337f | 24 + .../3f/70140e5a0c3e00151089cca86c5b1a99 | 432 +++++++++++++++++ .../3f/90d2ea4ac02e001511a3ba75618c68e5 | 292 ------------ .../3f/a049a4739b2b00151fa6e49f3e10bf0b | 41 -- .../3f/d0ae2988f02e001511a3ba75618c68e5 | 354 -------------- .../3f/d0bd9472043e00151c31fb33fff4337f | 126 +++++ .../3f/e0e98472053e00151c31fb33fff4337f | 428 +++++++++++++++++ .../3f/f076feeff32e001511a3ba75618c68e5 | 382 --------------- .../4/10509394922b00151fa6e49f3e10bf0b | 17 - .../4/108ef6e9912b00151fa6e49f3e10bf0b | 28 -- .../4/3024cc05d32e001511a3ba75618c68e5 | 106 ----- .../4/a0e0d29f9f2b00151fa6e49f3e10bf0b | 43 -- .../4/c0811107033e00151c31fb33fff4337f | 76 +++ .../4/d01b9292fc3d00151c31fb33fff4337f | 15 + .../40/105c688c912b00151fa6e49f3e10bf0b | 21 - .../40/607238ae0d3e00151089cca86c5b1a99 | 434 +++++++++++++++++ .../40/60fa6e10f22e001511a3ba75618c68e5 | 374 --------------- .../b05dfb50f93d00151c31fb33fff4337f} | 13 +- .../40/d04fb27d033e00151c31fb33fff4337f | 81 ++++ .../40/e0ff0e3eef2e001511a3ba75618c68e5 | 342 -------------- .../41/1054ae18ae2b00151fa6e49f3e10bf0b | 278 ----------- .../41/2061287bcf2e001511a3ba75618c68e5 | 94 ---- .../41/4092806fff3d00151c31fb33fff4337f | 74 +++ .../41/50a33590fe3d00151c31fb33fff4337f | 123 +++++ .../42/2024a5f8922b00151fa6e49f3e10bf0b | 32 -- .../42/40b2c0ee063e00151c31fb33fff4337f | 83 ++++ .../42/d0f315df033e00151c31fb33fff4337f | 420 +++++++++++++++++ .../42/e062ef3ef12e001511a3ba75618c68e5 | 368 --------------- .../43/90fd3642a02b00151fa6e49f3e10bf0b | 44 -- .../43/d0b51c31023e00151c31fb33fff4337f | 125 +++++ .../43/e0daac42032f001511a3ba75618c68e5 | 72 --- .../44/104410f0033e00151c31fb33fff4337f | 425 +++++++++++++++++ .../44/40c13c85083e00151c31fb33fff4337f | 25 + .../44/60baddbded2e001511a3ba75618c68e5 | 336 -------------- .../44/a0066f16c82e001511a3ba75618c68e5 | 323 ------------- .../45/c091f870e42d0015105bf01c854e42e3 | 286 ------------ .../45/e004d2d0f82e001511a3ba75618c68e5 | 385 --------------- .../46/20536196af2b00151fa6e49f3e10bf0b | 279 ----------- .../46/2068e749c72e001511a3ba75618c68e5 | 314 ------------- .../46/206c822bc92e001511a3ba75618c68e5 | 332 ------------- .../46/a096e8f7ad2b00151fa6e49f3e10bf0b | 277 ----------- .../46/e0388548ef2e001511a3ba75618c68e5 | 343 -------------- .../47/705caa25022f001511a3ba75618c68e5 | 68 --- .../47/8013b362f02e001511a3ba75618c68e5 | 353 -------------- .../47/a0a57ff6bf2e001511a3ba75618c68e5 | 292 ------------ .../48/00ffdb60ef2e001511a3ba75618c68e5 | 343 -------------- .../48/201c7a82af2b00151fa6e49f3e10bf0b | 274 ----------- .../48/d0589339033e00151c31fb33fff4337f | 76 +++ .../49/203ebd45a02b00151fa6e49f3e10bf0b | 44 -- .../49/20448ca9d22e001511a3ba75618c68e5 | 101 ---- .../49/208701fac42e001511a3ba75618c68e5 | 307 ------------ .../49/c0672b28053e00151c31fb33fff4337f | 25 + .../4a/20621c6bc72e001511a3ba75618c68e5 | 319 ------------- .../4a/20820eeea32b00151fa6e49f3e10bf0b | 36 -- .../4a/20f4346aad2b00151fa6e49f3e10bf0b | 267 ----------- .../4a/30a94cffc42e001511a3ba75618c68e5 | 307 ------------ .../4b/705083c4fa2e001511a3ba75618c68e5 | 393 ---------------- .../4b/f0e8f6d8fa2e001511a3ba75618c68e5 | 397 ---------------- .../4c/20839fc6ac2b00151fa6e49f3e10bf0b | 262 ----------- .../4c/60dfd6bffa2e001511a3ba75618c68e5 | 392 ---------------- .../4c/90d951d1922b00151fa6e49f3e10bf0b | 28 -- .../4c/b0f836d6c52e001511a3ba75618c68e5 | 312 ------------- .../4d/20fbcf08ae2b00151fa6e49f3e10bf0b | 278 ----------- .../4d/601ac327ee2e001511a3ba75618c68e5 | 338 -------------- .../4d/9088f56f922b00151fa6e49f3e10bf0b | 12 - .../4d/908b4f17a72b00151fa6e49f3e10bf0b | 47 -- .../4d/908e89caac2b00151fa6e49f3e10bf0b | 262 ----------- .../4e/a03b5be2ab2b00151fa6e49f3e10bf0b | 263 ----------- .../4e/e0d3ac3b0c3e00151089cca86c5b1a99 | 25 + .../4f/60f90ef1ef2e001511a3ba75618c68e5 | 348 -------------- .../4f/e0992796ee2e001511a3ba75618c68e5 | 340 -------------- .../5/10e7f335902b00151fa6e49f3e10bf0b | 19 - .../5/20f29cc9c12e001511a3ba75618c68e5 | 294 ------------ .../5/c0df337dfd3d00151c31fb33fff4337f | 27 ++ .../51/505dae0ff73d00151c31fb33fff4337f | 74 +++ .../51/c0028e610a3e00151c31fb33fff4337f | 432 +++++++++++++++++ .../51/c08e14f8c52e001511a3ba75618c68e5 | 311 ------------- .../52/e033be44f12e001511a3ba75618c68e5 | 368 --------------- .../52/e07bf409f92e001511a3ba75618c68e5 | 385 --------------- .../52/e098cc7eee2e001511a3ba75618c68e5 | 338 -------------- .../53/2088f35ac62e001511a3ba75618c68e5 | 314 ------------- .../53/60a94d43f02e001511a3ba75618c68e5 | 352 -------------- .../53/a0405c98f63d00151c31fb33fff4337f | 74 +++ .../53/e0c3c4b6f22e001511a3ba75618c68e5 | 378 --------------- .../53/e0e025b8fa2e001511a3ba75618c68e5 | 391 ---------------- .../54/603c9698f63d00151c31fb33fff4337f | 74 +++ .../54/a08c9aaec42e001511a3ba75618c68e5 | 294 ------------ .../55/108abd59cf2e001511a3ba75618c68e5 | 92 ---- .../55/e0f6a187073e00151c31fb33fff4337f | 430 +++++++++++++++++ .../56/600fc5d9ef2e001511a3ba75618c68e5 | 347 -------------- .../57/c08f160bae2b00151fa6e49f3e10bf0b | 278 ----------- .../58/209579d6922b00151fa6e49f3e10bf0b | 17 - .../58/306a8bbfc82e001511a3ba75618c68e5 | 326 ------------- .../58/60ed80d2f82e001511a3ba75618c68e5 | 385 --------------- .../5a/807ce202f92e001511a3ba75618c68e5 | 385 --------------- .../5a/f0233823022f001511a3ba75618c68e5 | 68 --- .../5b/20a3e001a72b00151fa6e49f3e10bf0b | 46 -- .../5b/c04677b1c42e001511a3ba75618c68e5 | 294 ------------ .../5b/e0bdb4c2ed2e001511a3ba75618c68e5 | 336 -------------- .../5b/e0c3bfdabf2e001511a3ba75618c68e5 | 288 ------------ .../5c/20130c91c92e001511a3ba75618c68e5 | 333 ------------- .../5c/501d5bcfed2e001511a3ba75618c68e5 | 335 -------------- .../5d/e022cf5fef2e001511a3ba75618c68e5 | 343 -------------- .../5d/f02ee61e022f001511a3ba75618c68e5 | 68 --- .../001a5b7d013e00151c31fb33fff4337f} | 45 +- .../5f/20fb7c76c72e001511a3ba75618c68e5 | 321 ------------- .../5f/60d7f94a0e3e00151089cca86c5b1a99 | 434 +++++++++++++++++ .../5f/c0841a72043e00151c31fb33fff4337f | 126 +++++ .../5f/d050dc2e043e00151c31fb33fff4337f | 427 +++++++++++++++++ .../5f/d05109b3013e00151c31fb33fff4337f | 418 +++++++++++++++++ .../6/30c2f2eec52e001511a3ba75618c68e5 | 315 ------------- .../6/e0073580012f001511a3ba75618c68e5 | 67 --- .../009554caf93d00151c31fb33fff4337f} | 0 .../60/607ba075fd3d00151c31fb33fff4337f | 26 ++ .../60/90821217a72b00151fa6e49f3e10bf0b | 47 -- .../61/208a799fac2b00151fa6e49f3e10bf0b | 260 ----------- .../62/502ee671043e00151c31fb33fff4337f | 126 +++++ .../62/60642c63ff2e001511a3ba75618c68e5 | 49 -- .../62/b0ef74cace2e001511a3ba75618c68e5 | 329 ------------- .../63/70033eb0c42e001511a3ba75618c68e5 | 294 ------------ .../63/a0335f19c62e001511a3ba75618c68e5 | 313 ------------- .../60ee528d013e00151c31fb33fff4337f} | 42 +- .../64/a05293039b2b00151fa6e49f3e10bf0b | 38 -- .../64/f003f832f82e001511a3ba75618c68e5 | 112 ----- .../64/f0a40a23fa2e001511a3ba75618c68e5 | 391 ---------------- .../65/10f38b46902b00151fa6e49f3e10bf0b | 21 - .../65/208daefe922b00151fa6e49f3e10bf0b | 32 -- .../65/90b2d49d922b00151fa6e49f3e10bf0b | 34 -- .../65/a0018c88c52e001511a3ba75618c68e5 | 307 ------------ .../65/c05049b70e2b00151fa6e49f3e10bf0b | 11 - .../66/20dd83e3ab2b00151fa6e49f3e10bf0b | 261 ----------- .../66/40244c64fd3d00151c31fb33fff4337f | 25 + .../67/602639aefe2e001511a3ba75618c68e5 | 47 -- .../67/70de873d032f001511a3ba75618c68e5 | 78 ---- .../67/b0a2021dd22e001511a3ba75618c68e5 | 334 ------------- .../67/f0473bebf93d00151c31fb33fff4337f | 6 + .../69/a0742e97c42e001511a3ba75618c68e5 | 294 ------------ .../69/a09f55a6d12e001511a3ba75618c68e5 | 98 ---- .../6a/a041c51ecf2e001511a3ba75618c68e5 | 64 --- .../6a/a0a9b7c0d22e001511a3ba75618c68e5 | 101 ---- .../6b/501ffbd8fb3d00151c31fb33fff4337f | 14 + .../6b/9087a916a72b00151fa6e49f3e10bf0b | 47 -- .../d0f9527cf63d00151c31fb33fff4337f} | 7 +- .../6c/20839ed9c42e001511a3ba75618c68e5 | 299 ------------ .../6c/a046c61ba72b00151fa6e49f3e10bf0b | 47 -- .../6c/b0c9b7a0d12e001511a3ba75618c68e5 | 97 ---- .../6c/e07524e9f93d00151c31fb33fff4337f | 6 + .../6d/20da2322c82e001511a3ba75618c68e5 | 323 ------------- .../6d/a06ed898a42b00151fa6e49f3e10bf0b | 45 -- .../6e/30f5a3bca82b00151fa6e49f3e10bf0b | 48 -- .../6e/70483370012f001511a3ba75618c68e5 | 65 --- .../6e/e0a6ee96f63d00151c31fb33fff4337f | 74 +++ .../6e/e0ff0a20022f001511a3ba75618c68e5 | 68 --- .../6f/40d1681c083e00151c31fb33fff4337f | 83 ++++ .../50a07067fe3d00151c31fb33fff4337f} | 13 +- .../6f/7051f7cef82e001511a3ba75618c68e5 | 385 --------------- .../d08b30cdf93d00151c31fb33fff4337f} | 2 +- .../6f/e0adbb55f02e001511a3ba75618c68e5 | 352 -------------- .../7/20e4b24fcf2e001511a3ba75618c68e5 | 85 ---- .../7/30377337c92e001511a3ba75618c68e5 | 332 ------------- .../7/90461043a02b00151fa6e49f3e10bf0b | 44 -- .../7/a0481e0ac52e001511a3ba75618c68e5 | 307 ------------ .../70/1027fc0ba92b00151fa6e49f3e10bf0b | 54 --- .../70/200aa244a02b00151fa6e49f3e10bf0b | 44 -- .../71/20ba4f46a02b00151fa6e49f3e10bf0b | 44 -- .../71/a031557dad2b00151fa6e49f3e10bf0b | 270 ----------- .../71/c0147a73043e00151c31fb33fff4337f | 126 +++++ .../71/f01d3f77023e00151c31fb33fff4337f | 421 +++++++++++++++++ .../72/601fd2f0013e00151c31fb33fff4337f | 124 +++++ .../73/2024f08eac2b00151fa6e49f3e10bf0b | 81 ---- .../73/40821671043e00151c31fb33fff4337f | 126 +++++ .../73/90090df6912b00151fa6e49f3e10bf0b | 28 -- .../73/e0bd2a55032f001511a3ba75618c68e5 | 78 ---- .../74/20c870fec42e001511a3ba75618c68e5 | 307 ------------ .../74/30231013d32e001511a3ba75618c68e5 | 335 -------------- .../74/b044220ec52e001511a3ba75618c68e5 | 307 ------------ .../76/606cb261f02e001511a3ba75618c68e5 | 353 -------------- .../76/609ffee6f52e001511a3ba75618c68e5 | 383 --------------- .../76/7043c1cded2e001511a3ba75618c68e5 | 336 -------------- .../76/9077f3faab2b00151fa6e49f3e10bf0b | 74 --- .../77/207e8f0bc02e001511a3ba75618c68e5 | 63 --- .../77/6089e238ef2e001511a3ba75618c68e5 | 341 -------------- .../77/70d77550fa2e001511a3ba75618c68e5 | 391 ---------------- .../77/d074cf98f63d00151c31fb33fff4337f | 74 +++ .../77/d083ff46043e00151c31fb33fff4337f | 427 +++++++++++++++++ .../78/5065e3fff63d00151c31fb33fff4337f | 74 +++ .../78/d07f6c71c12e001511a3ba75618c68e5 | 293 ------------ .../78/f0825bd8063e00151c31fb33fff4337f | 83 ++++ .../79/003d5ea2ed2e001511a3ba75618c68e5 | 335 -------------- .../79/203a486fa92b00151fa6e49f3e10bf0b | 59 --- .../79/e003d641f82e001511a3ba75618c68e5 | 112 ----- .../7a/4046a21a013e00151c31fb33fff4337f | 123 +++++ .../7a/606aad24f82e001511a3ba75618c68e5 | 111 ----- .../7a/80cff965ef2e001511a3ba75618c68e5 | 343 -------------- .../7a/e04691cdfa2e001511a3ba75618c68e5 | 398 ---------------- .../7b/004a78fdfc3d00151c31fb33fff4337f | 21 + .../7b/1078ea5ba12b00151fa6e49f3e10bf0b | 44 -- .../7b/402ae40dc52e001511a3ba75618c68e5 | 307 ------------ .../7b/6014043bf02e001511a3ba75618c68e5 | 351 -------------- .../7b/c081221f023e00151c31fb33fff4337f | 125 +++++ .../7b/f0438a5af93d00151c31fb33fff4337f | 75 +++ .../7c/201f6405c92e001511a3ba75618c68e5 | 326 ------------- .../7c/2055c958c62e001511a3ba75618c68e5 | 313 ------------- .../7c/6026172bf92e001511a3ba75618c68e5 | 387 ---------------- .../7c/a0d8547cad2b00151fa6e49f3e10bf0b | 270 ----------- .../7c/d0cb7c99f63d00151c31fb33fff4337f | 74 +++ .../7d/202437fbc82e001511a3ba75618c68e5 | 326 ------------- .../7d/b01607f8c42e001511a3ba75618c68e5 | 307 ------------ .../7e/10cadbb0c42e001511a3ba75618c68e5 | 294 ------------ .../7e/500698dcbf2e001511a3ba75618c68e5 | 288 ------------ .../7e/60a3a83aef2e001511a3ba75618c68e5 | 344 -------------- .../9072727d013e00151c31fb33fff4337f} | 42 +- .../7e/a031352fad2b00151fa6e49f3e10bf0b | 267 ----------- .../7f/702359e9f02e001511a3ba75618c68e5 | 360 --------------- .../7f/7097cde3b82e001511a3ba75618c68e5 | 63 --- .../8/2023cbe9c42e001511a3ba75618c68e5 | 300 ------------ .../8/60032e9cf32e001511a3ba75618c68e5 | 382 --------------- .../8/6022721bf82e001511a3ba75618c68e5 | 110 ----- .../8/a0da1bac9b2b00151fa6e49f3e10bf0b | 43 -- .../8/e0108b91fa2e001511a3ba75618c68e5 | 391 ---------------- .../8/e047daf4063e00151c31fb33fff4337f | 83 ++++ .../80/20e2900fc02e001511a3ba75618c68e5 | 64 --- .../80/6030fe14fb2e001511a3ba75618c68e5 | 397 ---------------- .../80/e08df834032f001511a3ba75618c68e5 | 78 ---- .../81/207849dec52e001511a3ba75618c68e5 | 311 ------------- .../81/20e90798ad2b00151fa6e49f3e10bf0b | 270 ----------- .../81/403b869cf63d00151c31fb33fff4337f | 74 +++ .../81/a0d37509c52e001511a3ba75618c68e5 | 307 ------------ .../81/a0e017eec72e001511a3ba75618c68e5 | 322 ------------- .../82/104d961b932b00151fa6e49f3e10bf0b | 35 -- .../82/20829588912b00151fa6e49f3e10bf0b | 21 - .../82/20ae0cc5ac2b00151fa6e49f3e10bf0b | 260 ----------- .../83/705f6955012f001511a3ba75618c68e5 | 63 --- .../83/90504e9eac2b00151fa6e49f3e10bf0b | 67 --- .../83/a0b48585922b00151fa6e49f3e10bf0b | 16 - .../84/20ae50cfce2e001511a3ba75618c68e5 | 329 ------------- .../84/e0cafcb5f02e001511a3ba75618c68e5 | 355 -------------- .../85/7082ce5ff62e001511a3ba75618c68e5 | 383 --------------- .../85/e0142d0af52e001511a3ba75618c68e5 | 382 --------------- .../85/e0445a04f82e001511a3ba75618c68e5 | 108 ----- .../86/a0aaceebab2b00151fa6e49f3e10bf0b | 63 --- .../87/80345c38902b00151fa6e49f3e10bf0b | 20 - .../87/a020dca2ad2b00151fa6e49f3e10bf0b | 273 ----------- .../87/c0ee9e2cc02e001511a3ba75618c68e5 | 292 ------------ .../87/e0091494f32e001511a3ba75618c68e5 | 382 --------------- .../88/20510e4a922b00151fa6e49f3e10bf0b | 0 .../88/e001984d0e3e00151089cca86c5b1a99 | 434 +++++++++++++++++ .../89/d0fdd397f63d00151c31fb33fff4337f | 74 +++ .../89/e09bd143ef2e001511a3ba75618c68e5 | 342 -------------- .../8a/a0819610a72b00151fa6e49f3e10bf0b | 46 -- .../8b/6006432e032f001511a3ba75618c68e5 | 73 --- .../8b/b08c1511c82e001511a3ba75618c68e5 | 323 ------------- .../8b/d0c1d07df02e001511a3ba75618c68e5 | 353 -------------- .../8b/e0e354c4ee2e001511a3ba75618c68e5 | 341 -------------- .../8c/50aa2bf3023e00151c31fb33fff4337f | 418 +++++++++++++++++ .../8c/60ddc035f72e001511a3ba75618c68e5 | 384 --------------- .../8d/60933f62ff2e001511a3ba75618c68e5 | 49 -- .../8d/60bb3fa1f22e001511a3ba75618c68e5 | 378 --------------- .../8d/d0631404023e00151c31fb33fff4337f | 125 +++++ .../8d/e0e833fff72e001511a3ba75618c68e5 | 108 ----- .../8e/20ff3826c62e001511a3ba75618c68e5 | 313 ------------- .../8f/205432bcc82e001511a3ba75618c68e5 | 324 ------------- .../9/70788731022f001511a3ba75618c68e5 | 72 --- .../9/a0706393c92e001511a3ba75618c68e5 | 330 ------------- .../00c56e06f63d00151c31fb33fff4337f} | 2 +- .../90/308d0ce3bf2e001511a3ba75618c68e5 | 291 ------------ .../90/6069aa58f02e001511a3ba75618c68e5 | 352 -------------- .../90/b04b6599ac2b00151fa6e49f3e10bf0b | 253 ---------- .../90/e0c2706bf72e001511a3ba75618c68e5 | 385 --------------- .../91/a005e2c5c42e001511a3ba75618c68e5 | 299 ------------ .../92/10894b16a72b00151fa6e49f3e10bf0b | 47 -- .../92/60ec4bcded2e001511a3ba75618c68e5 | 337 -------------- .../92/c0e52982cf2e001511a3ba75618c68e5 | 94 ---- .../d085d1ac013e00151c31fb33fff4337f} | 49 +- .../92/d0efd7c1fe3d00151c31fb33fff4337f | 122 +++++ .../92/e057acf2fe2e001511a3ba75618c68e5 | 47 -- .../93/20fa36e4a32b00151fa6e49f3e10bf0b | 35 -- .../93/b0d3830fc92e001511a3ba75618c68e5 | 327 ------------- .../93/b0d47969d22e001511a3ba75618c68e5 | 100 ---- .../93/d0279c5a053e00151c31fb33fff4337f | 81 ++++ .../94/20da4983ad2b00151fa6e49f3e10bf0b | 270 ----------- .../94/903495c2a32b00151fa6e49f3e10bf0b | 32 -- .../94/a0596c02ad2b00151fa6e49f3e10bf0b | 268 ----------- .../95/605f63960d3e00151089cca86c5b1a99 | 436 +++++++++++++++++ .../95/60dd0d99f63d00151c31fb33fff4337f | 74 +++ .../95/a0b5088a9b2b00151fa6e49f3e10bf0b | 42 -- .../95/f0eeaa17fd2e001511a3ba75618c68e5 | 44 -- .../97/00499c49012f001511a3ba75618c68e5 | 79 ---- .../97/6096c38cfd2e001511a3ba75618c68e5 | 47 -- .../97/90b0e2b5013e00151c31fb33fff4337f | 418 +++++++++++++++++ .../97/d0e97d74fc3d00151c31fb33fff4337f | 15 + .../98/b0f95768c12e001511a3ba75618c68e5 | 293 ------------ .../98/e00fcf2df82e001511a3ba75618c68e5 | 111 ----- .../99/506d71b4013e00151c31fb33fff4337f | 418 +++++++++++++++++ .../99/603c843af82e001511a3ba75618c68e5 | 112 ----- .../99/a045560ec82e001511a3ba75618c68e5 | 322 ------------- .../99/e0cf6ed0f02e001511a3ba75618c68e5 | 356 -------------- .../9a/e0576b12f82e001511a3ba75618c68e5 | 111 ----- .../9b/f056a849012f001511a3ba75618c68e5 | 79 ---- .../9c/a0b5740cad2b00151fa6e49f3e10bf0b | 67 --- .../d0841f77fe3d00151c31fb33fff4337f} | 15 +- .../9d/1061e789922b00151fa6e49f3e10bf0b | 16 - .../9d/60c3c8dcf82e001511a3ba75618c68e5 | 385 --------------- .../9d/e0ffd477033e00151c31fb33fff4337f | 78 ++++ .../9e/90fa2465922b00151fa6e49f3e10bf0b | 37 -- .../9f/1004ed17a72b00151fa6e49f3e10bf0b | 47 -- .../9f/9012fdfea32b00151fa6e49f3e10bf0b | 36 -- .../9f/90f1d8f29a2b00151fa6e49f3e10bf0b | 38 -- .../9f/e052f695fd2e001511a3ba75618c68e5 | 47 -- .../a/008424df922b00151fa6e49f3e10bf0b | 28 -- .../a/20c0c033a02b00151fa6e49f3e10bf0b | 43 -- .../a/705c51af0d3e00151089cca86c5b1a99 | 434 +++++++++++++++++ .../a/80754cfbf72e001511a3ba75618c68e5 | 107 ----- .../a/c0191a3f023e00151c31fb33fff4337f | 125 +++++ .../a/e0a46b3df82e001511a3ba75618c68e5 | 112 ----- .../a0/30a4e47faf2b00151fa6e49f3e10bf0b | 279 ----------- .../a0/602b122cfd2e001511a3ba75618c68e5 | 397 ---------------- .../a0/e0c38940ef2e001511a3ba75618c68e5 | 341 -------------- .../a0/e0ec5f84012f001511a3ba75618c68e5 | 67 --- .../a1/302a6e59d22e001511a3ba75618c68e5 | 99 ---- .../a2/205f1d48a92b00151fa6e49f3e10bf0b | 57 --- .../a2/d087eaeb063e00151c31fb33fff4337f | 83 ++++ .../a3/109449b7ac2b00151fa6e49f3e10bf0b | 259 ----------- .../a3/70684cbef22e001511a3ba75618c68e5 | 382 --------------- .../a3/a0b004efd22e001511a3ba75618c68e5 | 335 -------------- .../a4/605a1b57ef2e001511a3ba75618c68e5 | 343 -------------- .../a4/80b15bca902b00151fa6e49f3e10bf0b | 21 - .../a4/903b023fa42b00151fa6e49f3e10bf0b | 36 -- .../a4/d0f0e8f0033e00151c31fb33fff4337f | 426 +++++++++++++++++ .../a5/a032f69ec82e001511a3ba75618c68e5 | 322 ------------- .../a5/d04ca173f93d00151c31fb33fff4337f | 76 +++ .../a6/30615366ef2e001511a3ba75618c68e5 | 343 -------------- .../a7/7048aedcf62e001511a3ba75618c68e5 | 383 --------------- .../a7/a0feefeac52e001511a3ba75618c68e5 | 312 ------------- .../a8/20776c1dc92e001511a3ba75618c68e5 | 333 ------------- .../a8/50ba8ab4043e00151c31fb33fff4337f | 81 ++++ .../a9/600d733bf12e001511a3ba75618c68e5 | 365 --------------- .../a9/6080831f022f001511a3ba75618c68e5 | 68 --- .../a9/f0f38415f82e001511a3ba75618c68e5 | 112 ----- .../aa/a089d581ad2b00151fa6e49f3e10bf0b | 270 ----------- .../aa/b0d2228ec52e001511a3ba75618c68e5 | 310 ------------- .../aa/e0af633fee2e001511a3ba75618c68e5 | 338 -------------- .../ab/2091a3e5d22e001511a3ba75618c68e5 | 335 -------------- .../ab/20d4c998cf2e001511a3ba75618c68e5 | 97 ---- .../ab/c074771bfa3d00151c31fb33fff4337f | 11 + .../ab/e0241976f62e001511a3ba75618c68e5 | 383 --------------- .../ac/209cc836c52e001511a3ba75618c68e5 | 307 ------------ .../ac/5065ec8ffe3d00151c31fb33fff4337f | 122 +++++ .../ac/e05e031af22e001511a3ba75618c68e5 | 376 --------------- .../ad/102621c3912b00151fa6e49f3e10bf0b | 28 -- .../ad/d0a7a16df93d00151c31fb33fff4337f | 75 +++ .../ad/e0eec742012f001511a3ba75618c68e5 | 4 - .../ae/60376ea0ee2e001511a3ba75618c68e5 | 341 -------------- .../af/00b3c459f02e001511a3ba75618c68e5 | 352 -------------- .../af/505239fb033e00151c31fb33fff4337f | 426 +++++++++++++++++ .../af/708b111d012f001511a3ba75618c68e5 | 65 --- .../af/a0a41840c52e001511a3ba75618c68e5 | 307 ------------ .../af/e01790d7f82e001511a3ba75618c68e5 | 385 --------------- .../b/40053f0ee52d0015105bf01c854e42e3 | 287 ------------ .../b/50330699ef2e001511a3ba75618c68e5 | 343 -------------- .../b1/204e43add12e001511a3ba75618c68e5 | 98 ---- .../b1/90d6a166922b00151fa6e49f3e10bf0b | 12 - .../b1/b0d96b12ae2b00151fa6e49f3e10bf0b | 278 ----------- .../b1/e03de6b6013e00151c31fb33fff4337f | 418 +++++++++++++++++ .../b2/e02b9ea1ee2e001511a3ba75618c68e5 | 341 -------------- .../b3/20455670d22e001511a3ba75618c68e5 | 100 ---- .../b3/b0196cc5c12e001511a3ba75618c68e5 | 294 ------------ .../b3/e0282178012f001511a3ba75618c68e5 | 67 --- .../b4/709af161ff2e001511a3ba75618c68e5 | 47 -- .../b4/a0608155c72e001511a3ba75618c68e5 | 319 ------------- .../b4/a0d4cfa39b2b00151fa6e49f3e10bf0b | 42 -- .../b5/50e29274053e00151c31fb33fff4337f | 429 +++++++++++++++++ .../b5/703791ec052f001511a3ba75618c68e5 | 398 ---------------- .../b5/c0ca4f18013e00151c31fb33fff4337f | 122 +++++ .../b5/d0028812fa3d00151c31fb33fff4337f | 10 + .../b5/d00a745e053e00151c31fb33fff4337f | 83 ++++ .../b6/5024b6e30d3e00151089cca86c5b1a99 | 83 ++++ .../b6/604a1fa6f22e001511a3ba75618c68e5 | 378 --------------- .../b6/609d3f28ee2e001511a3ba75618c68e5 | 338 -------------- .../b6/90a348520c3e00151089cca86c5b1a99 | 432 +++++++++++++++++ .../b6/a0d78e97a42b00151fa6e49f3e10bf0b | 43 -- .../b6/e0d9140ff82e001511a3ba75618c68e5 | 111 ----- .../b7/500aa169fd3d00151c31fb33fff4337f | 25 + .../b7/a002ab6dcf2e001511a3ba75618c68e5 | 93 ---- .../b8/108b64cac52e001511a3ba75618c68e5 | 304 ------------ .../b8/2084fc30ad2b00151fa6e49f3e10bf0b | 267 ----------- .../b8/a05981c0ac2b00151fa6e49f3e10bf0b | 260 ----------- .../b8/b00f8654d22e001511a3ba75618c68e5 | 98 ---- .../b9/20a7d70dc52e001511a3ba75618c68e5 | 307 ------------ .../b9/409c8390fe3d00151c31fb33fff4337f | 122 +++++ .../b9/40c2f665ef2e001511a3ba75618c68e5 | 343 -------------- .../b9/5032653a043e00151c31fb33fff4337f | 427 +++++++++++++++++ .../b9/50eb23fc013e00151c31fb33fff4337f | 125 +++++ .../b9/d06dd7f9023e00151c31fb33fff4337f | 76 +++ .../b9/f0e30e98f63d00151c31fb33fff4337f | 74 +++ .../ba/20380095912b00151fa6e49f3e10bf0b | 21 - .../ba/50775507fd3d00151c31fb33fff4337f | 24 + .../ba/d013f5efc12e001511a3ba75618c68e5 | 294 ------------ .../ba/d05064d1013e00151c31fb33fff4337f | 418 +++++++++++++++++ .../bb/30c1a2d8c82e001511a3ba75618c68e5 | 326 ------------- .../bb/600ef5ddf82e001511a3ba75618c68e5 | 385 --------------- .../bb/60b5d072043e00151c31fb33fff4337f | 126 +++++ .../bb/a010fc64a42b00151fa6e49f3e10bf0b | 41 -- .../bb/a0fbec03ac2b00151fa6e49f3e10bf0b | 245 ---------- .../bb/b00f19f8d22e001511a3ba75618c68e5 | 101 ---- .../bb/e0bd71c4f22e001511a3ba75618c68e5 | 382 --------------- .../bc/204e03f6a82b00151fa6e49f3e10bf0b | 50 -- .../bc/30d0c335ad2b00151fa6e49f3e10bf0b | 267 ----------- .../bd/d05bd96d083e00151c31fb33fff4337f | 26 ++ .../be/102c495fa42b00151fa6e49f3e10bf0b | 39 -- .../be/206ef6f9c52e001511a3ba75618c68e5 | 312 ------------- .../be/d0face78043e00151c31fb33fff4337f | 126 +++++ .../bf/30eef93ec52e001511a3ba75618c68e5 | 307 ------------ .../bf/40b7a880bf2e001511a3ba75618c68e5 | 64 --- .../bf/a0c81b95c12e001511a3ba75618c68e5 | 293 ------------ .../c/106816bd922b00151fa6e49f3e10bf0b | 30 -- .../c/2058cec6a82b00151fa6e49f3e10bf0b | 49 -- .../c/206bd40cc92e001511a3ba75618c68e5 | 327 ------------- .../c/40594044033e00151c31fb33fff4337f | 78 ++++ .../c/a03dc224c62e001511a3ba75618c68e5 | 313 ------------- .../c/a0bbdf39cf2e001511a3ba75618c68e5 | 70 --- .../c0/2087239bc52e001511a3ba75618c68e5 | 311 ------------- .../c0/609e9b12f22e001511a3ba75618c68e5 | 376 --------------- .../c0/e0ca4cccf82e001511a3ba75618c68e5 | 385 --------------- .../c1/402ed649c02e001511a3ba75618c68e5 | 292 ------------ .../c2/e08d9071fc3d00151c31fb33fff4337f | 14 + .../c3/20dba6edad2b00151fa6e49f3e10bf0b | 276 ----------- .../c3/50421721013e00151c31fb33fff4337f | 123 +++++ .../c3/709abd11f22e001511a3ba75618c68e5 | 375 --------------- .../c3/90b90e40c52e001511a3ba75618c68e5 | 307 ------------ .../c3/b0db23b2a92b00151fa6e49f3e10bf0b | 63 --- .../c4/30128891cf2e001511a3ba75618c68e5 | 95 ---- .../c4/60544486ed2e001511a3ba75618c68e5 | 335 -------------- .../c4/e0191ea8ed2e001511a3ba75618c68e5 | 336 -------------- .../c5/105bfc5c922b00151fa6e49f3e10bf0b | 7 - .../c5/205ef9e6c72e001511a3ba75618c68e5 | 322 ------------- .../c5/e0bc896e043e00151c31fb33fff4337f | 126 +++++ .../c6/508d4163ef2e001511a3ba75618c68e5 | 343 -------------- .../c6/70f7bb04f92e001511a3ba75618c68e5 | 385 --------------- .../c6/c0dc5f8ffe3d00151c31fb33fff4337f | 122 +++++ .../c6/d022346e043e00151c31fb33fff4337f | 126 +++++ .../c6/e0f20f06f22e001511a3ba75618c68e5 | 372 --------------- .../c7/3015ce54d22e001511a3ba75618c68e5 | 98 ---- .../c7/30e525880d3e00151089cca86c5b1a99 | 435 +++++++++++++++++ .../c7/404ceb6dff3d00151c31fb33fff4337f | 75 +++ .../c7/6023b583002f001511a3ba75618c68e5 | 51 -- .../c7/d00983410a3e00151c31fb33fff4337f | 431 +++++++++++++++++ .../c7/d05586b7fe3d00151c31fb33fff4337f | 122 +++++ .../c7/e0524424f92e001511a3ba75618c68e5 | 386 ---------------- .../c7/f00aad3f023e00151c31fb33fff4337f | 125 +++++ .../c7/f0d24c00f82e001511a3ba75618c68e5 | 108 ----- .../c8/2097812fd22e001511a3ba75618c68e5 | 335 -------------- .../c9/70756544052f001511a3ba75618c68e5 | 397 ---------------- .../c9/a00609beac2b00151fa6e49f3e10bf0b | 260 ----------- .../c9/d03887b7013e00151c31fb33fff4337f | 418 +++++++++++++++++ .../ca/10df867da42b00151fa6e49f3e10bf0b | 42 -- .../ca/c067eb62d32e001511a3ba75618c68e5 | 335 -------------- .../cb/a082a1d5a82b00151fa6e49f3e10bf0b | 49 -- .../cb/e00c8ff2f32e001511a3ba75618c68e5 | 382 --------------- .../cc/10137161ef2e001511a3ba75618c68e5 | 343 -------------- .../cc/10d57c5c0d3e00151089cca86c5b1a99 | 434 +++++++++++++++++ .../cc/306aac51cf2e001511a3ba75618c68e5 | 92 ---- .../505a3848f63d00151c31fb33fff4337f} | 5 +- .../cc/60cf3d08f22e001511a3ba75618c68e5 | 373 --------------- .../ce/10db96ee9a2b00151fa6e49f3e10bf0b | 38 -- .../ce/500d093f033e00151c31fb33fff4337f | 77 +++ .../ce/60e64a99f63d00151c31fb33fff4337f | 74 +++ .../d00a337efe3d00151c31fb33fff4337f} | 22 +- .../ce/d07741ef023e00151c31fb33fff4337f | 419 +++++++++++++++++ .../cf/40c8a91f043e00151c31fb33fff4337f | 427 +++++++++++++++++ .../cf/509e01bffe3d00151c31fb33fff4337f | 122 +++++ .../cf/50fc0176fd3d00151c31fb33fff4337f | 27 ++ .../d/10091b68922b00151fa6e49f3e10bf0b | 13 - .../d/a0a4134fd42e001511a3ba75618c68e5 | 335 -------------- .../d/f0722227012f001511a3ba75618c68e5 | 63 --- .../d0/20e069c0c42e001511a3ba75618c68e5 | 294 ------------ .../d0/40969eebfc3d00151c31fb33fff4337f | 19 + .../d0/60e816e10d3e00151089cca86c5b1a99 | 82 ++++ .../d0/90ea12feac2b00151fa6e49f3e10bf0b | 265 ----------- .../d0/a0b7202ba92b00151fa6e49f3e10bf0b | 55 --- .../d0/e00161a0f72e001511a3ba75618c68e5 | 385 --------------- .../d0/e03bfec4f12e001511a3ba75618c68e5 | 371 --------------- .../d1/1064daeba32b00151fa6e49f3e10bf0b | 35 -- .../d1/50a093b2d12e001511a3ba75618c68e5 | 328 ------------- .../d1/706be4b5f12e001511a3ba75618c68e5 | 373 --------------- .../d2/a0f5e567cf2e001511a3ba75618c68e5 | 93 ---- .../d2/d0f664fd013e00151c31fb33fff4337f | 125 +++++ .../d2/e0d75c1cf52e001511a3ba75618c68e5 | 382 --------------- .../d3/606f612ef92e001511a3ba75618c68e5 | 389 ---------------- .../d4/60100fb6043e00151c31fb33fff4337f | 81 ++++ .../d4/906a60a69b2b00151fa6e49f3e10bf0b | 43 -- .../d4/a06157d2d22e001511a3ba75618c68e5 | 101 ---- .../d4/a0c84ebbac2b00151fa6e49f3e10bf0b | 260 ----------- .../d4/a0f792099b2b00151fa6e49f3e10bf0b | 39 -- .../d4/d0595525043e00151c31fb33fff4337f | 427 +++++++++++++++++ .../d5/607f4314033e00151c31fb33fff4337f | 420 +++++++++++++++++ .../d5/b0f64d23d22e001511a3ba75618c68e5 | 335 -------------- .../d5/d023b881073e00151c31fb33fff4337f | 429 +++++++++++++++++ .../d6/201352cfac2b00151fa6e49f3e10bf0b | 265 ----------- .../d6/d059d3b7fd3d00151c31fb33fff4337f | 25 + .../d6/e08d6864ff2e001511a3ba75618c68e5 | 49 -- .../d7/5064fb90fe3d00151c31fb33fff4337f | 123 +++++ .../d7/60dd2311f02e001511a3ba75618c68e5 | 351 -------------- .../d7/c0293873043e00151c31fb33fff4337f | 126 +++++ .../d7/d06d9fe5f93d00151c31fb33fff4337f | 5 + .../d8/f05418d3042f001511a3ba75618c68e5 | 397 ---------------- .../d8/f0762d6f043e00151c31fb33fff4337f | 126 +++++ .../d9/a0effc8dcf2e001511a3ba75618c68e5 | 94 ---- .../da/3015c517d22e001511a3ba75618c68e5 | 334 ------------- .../da/60d0a320f52e001511a3ba75618c68e5 | 382 --------------- .../da/90595120922b00151fa6e49f3e10bf0b | 28 -- .../da/a0ee8a65cf2e001511a3ba75618c68e5 | 92 ---- .../da/b01aba10d22e001511a3ba75618c68e5 | 98 ---- .../da/e028ee36ee2e001511a3ba75618c68e5 | 338 -------------- .../da/f088765c0c3e00151089cca86c5b1a99 | 433 +++++++++++++++++ .../db/600bbc16013e00151c31fb33fff4337f | 122 +++++ .../db/60525316f62e001511a3ba75618c68e5 | 383 --------------- .../db/d0069951053e00151c31fb33fff4337f | 26 ++ .../db/e0afd61c022f001511a3ba75618c68e5 | 68 --- .../db/e0beb2d9fa2e001511a3ba75618c68e5 | 397 ---------------- .../dc/20e486bcc52e001511a3ba75618c68e5 | 305 ------------ .../dc/50e028f2023e00151c31fb33fff4337f | 420 +++++++++++++++++ .../dc/d0bfbbf2bf2e001511a3ba75618c68e5 | 291 ------------ .../dd/200daaf7c52e001511a3ba75618c68e5 | 315 ------------- .../dd/20e88117c62e001511a3ba75618c68e5 | 312 ------------- .../dd/50875957023e00151c31fb33fff4337f | 419 +++++++++++++++++ .../dd/a0d6be9fc42e001511a3ba75618c68e5 | 294 ------------ .../dd/e083e020f82e001511a3ba75618c68e5 | 111 ----- .../de/10304fc2912b00151fa6e49f3e10bf0b | 28 -- .../de/500da46afb3d00151c31fb33fff4337f | 11 + .../de/d037d008fa3d00151c31fb33fff4337f | 9 + .../de/f0a001d10d3e00151089cca86c5b1a99 | 82 ++++ .../df/300c6d49c02e001511a3ba75618c68e5 | 292 ------------ .../df/40c1de71cf2e001511a3ba75618c68e5 | 94 ---- .../df/a0feec31ad2b00151fa6e49f3e10bf0b | 267 ----------- .../df/c06a7eb00d3e00151089cca86c5b1a99 | 434 +++++++++++++++++ .../df/c0aa55450c3e00151089cca86c5b1a99 | 432 +++++++++++++++++ .../df/d01c41c0f63d00151c31fb33fff4337f | 74 +++ .../e/20950642c92e001511a3ba75618c68e5 | 333 ------------- .../e/e0fe31e9033e00151c31fb33fff4337f | 425 +++++++++++++++++ .../3009907cfe3d00151c31fb33fff4337f} | 17 +- .../e1/a0985d119b2b00151fa6e49f3e10bf0b | 41 -- .../e1/a0ddeb7bad2b00151fa6e49f3e10bf0b | 269 ----------- .../e1/d020d619fa3d00151c31fb33fff4337f | 10 + .../e1/e0d02fe9ed2e001511a3ba75618c68e5 | 336 -------------- .../e2/30cf0cc0c82e001511a3ba75618c68e5 | 325 ------------- .../e2/60b2fa130a3e00151c31fb33fff4337f | 431 +++++++++++++++++ .../e2/e09936ccef2e001511a3ba75618c68e5 | 347 -------------- .../e3/90184b440c3e00151089cca86c5b1a99 | 431 +++++++++++++++++ .../e3/a0978eb0c82e001511a3ba75618c68e5 | 324 ------------- .../d08eed38f63d00151c31fb33fff4337f} | 4 +- .../e4/20573e85ad2b00151fa6e49f3e10bf0b | 270 ----------- .../e4/50af645b023e00151c31fb33fff4337f | 420 +++++++++++++++++ .../e5/607d36ccf02e001511a3ba75618c68e5 | 355 -------------- .../e5/60d93450f93d00151c31fb33fff4337f | 74 +++ .../e5/e039cfb8f22e001511a3ba75618c68e5 | 381 --------------- .../e6/7092210c0a3e00151c31fb33fff4337f | 431 +++++++++++++++++ .../e6/a040ea06ad2b00151fa6e49f3e10bf0b | 268 ----------- .../e6/c0b7626f043e00151c31fb33fff4337f | 126 +++++ .../e6/d0c6108f083e00151c31fb33fff4337f | 126 +++++ .../e6/e09fc270f02e001511a3ba75618c68e5 | 353 -------------- .../e7/d06d6706fd3d00151c31fb33fff4337f | 24 + .../e8/10533cf0ad2b00151fa6e49f3e10bf0b | 276 ----------- .../e8/207d10c3f52a00151fa6e49f3e10bf0b | 6 - .../e8/e08ce196093e00151c31fb33fff4337f | 430 +++++++++++++++++ .../e9/a0aad154902b00151fa6e49f3e10bf0b | 21 - .../ea/40a8228bfe3d00151c31fb33fff4337f | 122 +++++ .../ea/5018d788033e00151c31fb33fff4337f | 81 ++++ .../ea/a085533dcf2e001511a3ba75618c68e5 | 85 ---- .../ea/d0facaee052f001511a3ba75618c68e5 | 398 ---------------- .../eb/a0999107ac2b00151fa6e49f3e10bf0b | 245 ---------- .../ec/30fe1899d22e001511a3ba75618c68e5 | 100 ---- .../ec/90418517a72b00151fa6e49f3e10bf0b | 47 -- .../ec/c098ba41033e00151c31fb33fff4337f | 77 +++ .../ec/c0d3c395fc3d00151c31fb33fff4337f | 19 + .../ec/d0cc5971043e00151c31fb33fff4337f | 126 +++++ .../ed/e0feb053f22e001511a3ba75618c68e5 | 378 --------------- .../ed/f09acb29f62e001511a3ba75618c68e5 | 383 --------------- .../f/30dc59d9c82e001511a3ba75618c68e5 | 326 ------------- .../f/4081c9edc12e001511a3ba75618c68e5 | 294 ------------ .../f/902d449b9b2b00151fa6e49f3e10bf0b | 42 -- .../f/a035f604a92b00151fa6e49f3e10bf0b | 50 -- .../f0/30004907d32e001511a3ba75618c68e5 | 107 ----- .../f0/904f621cc82e001511a3ba75618c68e5 | 323 ------------- .../f0/d01b9bcffc3d00151c31fb33fff4337f | 19 + .../f0/e006e534f82e001511a3ba75618c68e5 | 112 ----- .../f1/5056a305043e00151c31fb33fff4337f | 426 +++++++++++++++++ .../f1/d02f5a6dff3d00151c31fb33fff4337f | 76 +++ .../f2/e0fcf2d8f02e001511a3ba75618c68e5 | 356 -------------- .../f3/102d06a3fe2e001511a3ba75618c68e5 | 47 -- .../f3/d0a2d21dfa3d00151c31fb33fff4337f | 11 + .../f4/00874f9ef72e001511a3ba75618c68e5 | 385 --------------- .../f4/100cd858cf2e001511a3ba75618c68e5 | 92 ---- .../f4/908b5426932b00151fa6e49f3e10bf0b | 37 -- .../f4/d034285bfd3d00151c31fb33fff4337f | 25 + .../f5/606e09ccfa2e001511a3ba75618c68e5 | 393 ---------------- .../f6/20de0123932b00151fa6e49f3e10bf0b | 36 -- .../f6/a065bef2c42e001511a3ba75618c68e5 | 307 ------------ .../f7/20ed419eaf2b00151fa6e49f3e10bf0b | 286 ------------ .../f7/30fdd3fbc42e001511a3ba75618c68e5 | 307 ------------ .../f7/60d64f66fd2e001511a3ba75618c68e5 | 44 -- .../f8/108fca500c3e00151089cca86c5b1a99 | 432 +++++++++++++++++ .../f8/20e60535a72b00151fa6e49f3e10bf0b | 48 -- .../f8/e0c1b81ef82e001511a3ba75618c68e5 | 110 ----- .../f9/6022dfe8f92e001511a3ba75618c68e5 | 391 ---------------- .../f9/60a3e283fd2e001511a3ba75618c68e5 | 45 -- .../fa/201779a3d22e001511a3ba75618c68e5 | 101 ---- .../fa/d03cd67b033e00151c31fb33fff4337f | 81 ++++ .../fb/6086a867ee2e001511a3ba75618c68e5 | 338 -------------- .../fb/806b4e4ac02e001511a3ba75618c68e5 | 292 ------------ .../fb/b0ab4825c62e001511a3ba75618c68e5 | 313 ------------- .../fc/3086b133c72e001511a3ba75618c68e5 | 314 ------------- .../fc/50e6e65e043e00151c31fb33fff4337f | 125 +++++ .../fd/80dba9e9f02e001511a3ba75618c68e5 | 360 --------------- .../fe/50283165ef2e001511a3ba75618c68e5 | 343 -------------- .../fe/50e0facf023e00151c31fb33fff4337f | 421 +++++++++++++++++ .../fe/e0151cd4ef2e001511a3ba75618c68e5 | 347 -------------- .../ff/60ae02e4fe2e001511a3ba75618c68e5 | 47 -- .../ff/90825a06932b00151fa6e49f3e10bf0b | 35 -- .../ff/b08757dc9a2b00151fa6e49f3e10bf0b | 37 -- .../ff/f0d7250df42e001511a3ba75618c68e5 | 382 --------------- .../RemoteSystemsTempFiles/.markers.snap | Bin 720 -> 48 bytes .../RemoteSystemsTempFiles/.syncinfo.snap | Bin 720 -> 48 bytes .../.indexes/af/history.index | Bin 118 -> 0 bytes .../.indexes/e4/77/69/e/history.index | Bin 13391 -> 4779 bytes .../.indexes/e4/81/43/bf/history.index | Bin 162 -> 0 bytes .../.indexes/e4/history.index | Bin 101 -> 0 bytes .../.projects/TheButtonAutoFlair/.markers | Bin 887 -> 1468 bytes .../TheButtonAutoFlair/.markers.snap | Bin 34515 -> 4754 bytes .../TheButtonAutoFlair/.syncinfo.snap | Bin 720 -> 48 bytes .../.root/.markers.snap | Bin 720 -> 48 bytes .../org.eclipse.core.resources/.root/2.tree | Bin 3730 -> 0 bytes .../org.eclipse.core.resources/.root/5.tree | Bin 0 -> 5679 bytes .../.safetable/org.eclipse.core.resources | Bin 36407 -> 4058 bytes .../.plugins/org.eclipse.core.resources/.snap | Bin 29107 -> 1898 bytes .../.settings/org.eclipse.jdt.ui.prefs | 2 +- .../.settings/org.eclipse.jst.jsp.core.prefs | 2 +- .../org.eclipse.e4.workbench/workbench.xmi | 139 +++--- .../org.eclipse.jdt.core/1508644233.index | Bin 16240 -> 16667 bytes .../externalLibsTimeStamps | Bin 1593 -> 1593 bytes .../org.eclipse.jdt.core/nonChainingJarsCache | Bin 293 -> 638 bytes .../org.eclipse.jdt.core/savedIndexNames.txt | 38 +- .../QualifiedTypeNameHistory.xml | 23 +- .../org.eclipse.jdt.ui/dialog_settings.xml | 8 +- .../org.eclipse.jdt.ui/jdt-images/1.png | Bin 490 -> 283 bytes .../org.eclipse.jdt.ui/jdt-images/2.png | Bin 436 -> 238 bytes .../org.eclipse.jdt.ui/jdt-images/3.png | Bin 194 -> 147 bytes .../org.eclipse.jdt.ui/jdt-images/4.png | Bin 283 -> 509 bytes .../org.eclipse.jdt.ui/jdt-images/5.png | Bin 277 -> 159 bytes .../org.eclipse.jdt.ui/jdt-images/6.png | Bin 238 -> 0 bytes .../org.eclipse.jdt.ui/jdt-images/7.png | Bin 509 -> 0 bytes .../org.eclipse.jdt.ui/jdt-images/8.png | Bin 159 -> 0 bytes .../org.eclipse.jdt.ui/jdt-images/9.png | Bin 292 -> 0 bytes .../taglibindex/1508644233.dat | Bin 0 -> 134 bytes .../org.eclipse.search/dialog_settings.xml | 4 + .../org.eclipse.ui.ide/dialog_settings.xml | 8 + .../org.eclipse.ui.workbench/workingsets.xml | 3 + TheButtonAutoFlair.jar | Bin 60744 -> 62002 bytes .../tk/sznp/thebuttonautoflair/Commands.class | Bin 4203 -> 4241 bytes .../MaybeOfflinePlayer.class | Bin 0 -> 1182 bytes .../thebuttonautoflair/PlayerListener.class | Bin 4343 -> 4725 bytes .../thebuttonautoflair/PluginMain$1.class | Bin 675 -> 675 bytes .../sznp/thebuttonautoflair/PluginMain.class | Bin 12702 -> 13170 bytes TheButtonAutoFlair/p.javaproj | 17 + .../tk/sznp/thebuttonautoflair/Commands.java | 37 +- .../MaybeOfflinePlayer.java | 25 + .../thebuttonautoflair/PlayerListener.java | 21 +- .../sznp/thebuttonautoflair/PluginMain.java | 79 +++- 822 files changed, 38114 insertions(+), 123388 deletions(-) delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/0/4026a562ef2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/0/6088cf20022f001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/0/a0189d31a72b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/0/d057cb01fa3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1/10092140c52e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1/60ca8b100a3e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1/d0997b1b023e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1/f03cfc260d3e00151089cca86c5b1a99 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/10/704e9345022f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/10/70a9b080083e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/10/80a0b699f63d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/10/e03d4f54f62e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/11/302d82aec52e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/11/50857fe1f93d00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/11/50a623b5013e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/11/6040761c022f001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/11/703abcfff12e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/11/b0a0fc59e42d0015105bf01c854e42e3 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/11/e02f8f8d083e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/12/2027da9cac2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/13/604732c5f52e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/13/b00ee04cc72e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/14/70fadb62ff2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/14/901ce7a4912b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/14/d01b6d05f52e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/15/20b3105acf2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/15/4032ab5dbf2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/15/602ef8eded2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/15/9032115ca42b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/15/905b71c7ed2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/15/d05be66e043e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/16/10971668a42b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/16/b03d628ac42e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/17/202ded81a92b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/17/90bccd90922b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/17/a0348882a92b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/17/d004cf02fd3d00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/17/d08a7e97f63d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/18/2072884bc02e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/18/a075b55fc92e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/18/e00b6b58ef2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/18/e024139bf02e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/18/e07d8480f52e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/19/0072a52f022f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/19/60f2ab7f023e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1a/a09f2e39c52e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1a/c0cfb22dc02e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1a/d0fbf199f63d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1b/9066f985a92b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1b/f0224de8f62e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1b/f0c4a095083e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1c/50a873c4093e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1c/6074bf28f12e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1c/609377ad0d3e00151089cca86c5b1a99 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1c/90a675ce902b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1d/2083e990ac2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1e/10a41e97ee2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1e/504c9d52ef2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1e/a0220ef3ab2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1f/2028de3fcf2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/1f/b00d77f0c42e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2/c07312e9bf2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/20/a01363d8a82b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/20/a040189aaf2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/20/a0f94f72cf2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/21/6079da59fa2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/21/9091585acf2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/22/10b43daf9b2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/22/a0bbe40cc52e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/23/40423b2bcf2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/23/60878d1afb2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/23/a0089f13c62e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/24/205b7a17d32e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/24/60c0f732f92e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/24/b0050f65c02e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/24/d08c2d11033e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/26/103a93e1922b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/26/908a556aa42b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/26/d01f259ef02e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/27/603d2e77012f001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/27/6094151b012f001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/27/7096e0b1f12e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/27/70ba5e30032f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/27/d0c61635023e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/28/50c3d09efd3d00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/29/4085cc81fe3d00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/29/500adc32083e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/29/50dd5657043e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2a/104eb717a72b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2a/20a4e0af0d3e00151089cca86c5b1a99 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2a/20defcdbc72e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2a/304ef98cc22e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2b/b071b16acf2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2b/c0dde05e023e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2c/20ac6667d22e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2c/50d8e8c4093e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2d/20ebe2afc42e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2d/60a68ad9013e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2d/9018d69a922b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2d/c0b10f0c023e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2e/204539a2c72e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2e/c0323f76053e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2f/10f28f28922b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2f/60c08aa1ed2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2f/901fe416a72b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/2f/c09b39d5013e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3/60b156f3ed2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3/a0abcccdac2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/30/60904025fd2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/30/a046033cc92e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/31/2034c778a42b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/32/104e4dffa62b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/32/306725aec52e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/32/60416866f22e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/32/c036aae2063e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/32/e0bd8a0af82e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/33/307f3ebec52e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/33/608c284a083e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/33/90978488a42b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/33/b022d410ae2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/33/e0e8f0d9c42e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/34/20530121c82e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/34/2066c3cdc82e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/35/20ec61bbc52e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/35/90f4067f922b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/35/a0d28e1ac92e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/35/d0feddc3f12e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/36/407f1825013e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/37/400d6ebfbf2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/37/a0adde5a022b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/38/30ed4da8d12e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/38/601c14b2013e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/38/609a0a5fef2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/39/10f83522922b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/39/60013fb6013e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/39/7076fe6ff92e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/39/e0e3f38efd2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3a/20e5cd02ae2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3a/300567b8d12e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3a/705720220d3e00151089cca86c5b1a99 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3a/f0edd7def02e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3b/d0078548033e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3b/e033e73b033e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3c/100230c7c72e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3c/508e5c2c053e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3d/2034d8fed22e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3d/b0b429e1c52e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3e/501e53c6c12e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3e/d041c107f12e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3e/f09f99a6f12e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3f/10680ce29a2b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3f/5082b24efd3d00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3f/70140e5a0c3e00151089cca86c5b1a99 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3f/90d2ea4ac02e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3f/a049a4739b2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3f/d0ae2988f02e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3f/d0bd9472043e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3f/e0e98472053e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/3f/f076feeff32e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4/10509394922b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4/108ef6e9912b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4/3024cc05d32e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4/a0e0d29f9f2b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4/c0811107033e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4/d01b9292fc3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/40/105c688c912b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/40/607238ae0d3e00151089cca86c5b1a99 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/40/60fa6e10f22e001511a3ba75618c68e5 rename .metadata/.plugins/org.eclipse.core.resources/.history/{f1/e0e3f27f032f001511a3ba75618c68e5 => 40/b05dfb50f93d00151c31fb33fff4337f} (89%) create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/40/d04fb27d033e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/40/e0ff0e3eef2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/41/1054ae18ae2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/41/2061287bcf2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/41/4092806fff3d00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/41/50a33590fe3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/42/2024a5f8922b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/42/40b2c0ee063e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/42/d0f315df033e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/42/e062ef3ef12e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/43/90fd3642a02b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/43/d0b51c31023e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/43/e0daac42032f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/44/104410f0033e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/44/40c13c85083e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/44/60baddbded2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/44/a0066f16c82e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/45/c091f870e42d0015105bf01c854e42e3 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/45/e004d2d0f82e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/46/20536196af2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/46/2068e749c72e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/46/206c822bc92e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/46/a096e8f7ad2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/46/e0388548ef2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/47/705caa25022f001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/47/8013b362f02e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/47/a0a57ff6bf2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/48/00ffdb60ef2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/48/201c7a82af2b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/48/d0589339033e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/49/203ebd45a02b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/49/20448ca9d22e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/49/208701fac42e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/49/c0672b28053e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4a/20621c6bc72e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4a/20820eeea32b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4a/20f4346aad2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4a/30a94cffc42e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4b/705083c4fa2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4b/f0e8f6d8fa2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4c/20839fc6ac2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4c/60dfd6bffa2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4c/90d951d1922b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4c/b0f836d6c52e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4d/20fbcf08ae2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4d/601ac327ee2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4d/9088f56f922b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4d/908b4f17a72b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4d/908e89caac2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4e/a03b5be2ab2b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4e/e0d3ac3b0c3e00151089cca86c5b1a99 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4f/60f90ef1ef2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/4f/e0992796ee2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5/10e7f335902b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5/20f29cc9c12e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5/c0df337dfd3d00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/51/505dae0ff73d00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/51/c0028e610a3e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/51/c08e14f8c52e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/52/e033be44f12e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/52/e07bf409f92e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/52/e098cc7eee2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/53/2088f35ac62e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/53/60a94d43f02e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/53/a0405c98f63d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/53/e0c3c4b6f22e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/53/e0e025b8fa2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/54/603c9698f63d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/54/a08c9aaec42e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/55/108abd59cf2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/55/e0f6a187073e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/56/600fc5d9ef2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/57/c08f160bae2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/58/209579d6922b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/58/306a8bbfc82e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/58/60ed80d2f82e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5a/807ce202f92e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5a/f0233823022f001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5b/20a3e001a72b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5b/c04677b1c42e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5b/e0bdb4c2ed2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5b/e0c3bfdabf2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5c/20130c91c92e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5c/501d5bcfed2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5d/e022cf5fef2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5d/f02ee61e022f001511a3ba75618c68e5 rename .metadata/.plugins/org.eclipse.core.resources/.history/{83/60141ae3042f001511a3ba75618c68e5 => 5e/001a5b7d013e00151c31fb33fff4337f} (87%) delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5f/20fb7c76c72e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5f/60d7f94a0e3e00151089cca86c5b1a99 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5f/c0841a72043e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5f/d050dc2e043e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/5f/d05109b3013e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6/30c2f2eec52e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6/e0073580012f001511a3ba75618c68e5 rename .metadata/.plugins/org.eclipse.core.resources/.history/{2/3097a03f012f001511a3ba75618c68e5 => 60/009554caf93d00151c31fb33fff4337f} (100%) create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/60/607ba075fd3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/60/90821217a72b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/61/208a799fac2b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/62/502ee671043e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/62/60642c63ff2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/62/b0ef74cace2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/63/70033eb0c42e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/63/a0335f19c62e001511a3ba75618c68e5 rename .metadata/.plugins/org.eclipse.core.resources/.history/{2a/10f997ed052f001511a3ba75618c68e5 => 64/60ee528d013e00151c31fb33fff4337f} (87%) delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/64/a05293039b2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/64/f003f832f82e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/64/f0a40a23fa2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/65/10f38b46902b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/65/208daefe922b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/65/90b2d49d922b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/65/a0018c88c52e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/65/c05049b70e2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/66/20dd83e3ab2b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/66/40244c64fd3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/67/602639aefe2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/67/70de873d032f001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/67/b0a2021dd22e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/67/f0473bebf93d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/69/a0742e97c42e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/69/a09f55a6d12e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6a/a041c51ecf2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6a/a0a9b7c0d22e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6b/501ffbd8fb3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6b/9087a916a72b00151fa6e49f3e10bf0b rename .metadata/.plugins/org.eclipse.core.resources/.history/{ff/e0d13c89032f001511a3ba75618c68e5 => 6b/d0f9527cf63d00151c31fb33fff4337f} (95%) delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6c/20839ed9c42e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6c/a046c61ba72b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6c/b0c9b7a0d12e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6c/e07524e9f93d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6d/20da2322c82e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6d/a06ed898a42b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6e/30f5a3bca82b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6e/70483370012f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6e/e0a6ee96f63d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6e/e0ff0a20022f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6f/40d1681c083e00151c31fb33fff4337f rename .metadata/.plugins/org.eclipse.core.resources/.history/{bc/e06e426ff82e001511a3ba75618c68e5 => 6f/50a07067fe3d00151c31fb33fff4337f} (87%) delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6f/7051f7cef82e001511a3ba75618c68e5 rename .metadata/.plugins/org.eclipse.core.resources/.history/{88/807be056922b00151fa6e49f3e10bf0b => 6f/d08b30cdf93d00151c31fb33fff4337f} (54%) delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/6f/e0adbb55f02e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7/20e4b24fcf2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7/30377337c92e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7/90461043a02b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7/a0481e0ac52e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/70/1027fc0ba92b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/70/200aa244a02b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/71/20ba4f46a02b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/71/a031557dad2b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/71/c0147a73043e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/71/f01d3f77023e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/72/601fd2f0013e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/73/2024f08eac2b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/73/40821671043e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/73/90090df6912b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/73/e0bd2a55032f001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/74/20c870fec42e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/74/30231013d32e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/74/b044220ec52e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/76/606cb261f02e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/76/609ffee6f52e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/76/7043c1cded2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/76/9077f3faab2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/77/207e8f0bc02e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/77/6089e238ef2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/77/70d77550fa2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/77/d074cf98f63d00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/77/d083ff46043e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/78/5065e3fff63d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/78/d07f6c71c12e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/78/f0825bd8063e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/79/003d5ea2ed2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/79/203a486fa92b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/79/e003d641f82e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7a/4046a21a013e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7a/606aad24f82e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7a/80cff965ef2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7a/e04691cdfa2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7b/004a78fdfc3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7b/1078ea5ba12b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7b/402ae40dc52e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7b/6014043bf02e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7b/c081221f023e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7b/f0438a5af93d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7c/201f6405c92e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7c/2055c958c62e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7c/6026172bf92e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7c/a0d8547cad2b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7c/d0cb7c99f63d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7d/202437fbc82e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7d/b01607f8c42e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7e/10cadbb0c42e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7e/500698dcbf2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7e/60a3a83aef2e001511a3ba75618c68e5 rename .metadata/.plugins/org.eclipse.core.resources/.history/{60/60a8e9e7052f001511a3ba75618c68e5 => 7e/9072727d013e00151c31fb33fff4337f} (87%) delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7e/a031352fad2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7f/702359e9f02e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/7f/7097cde3b82e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8/2023cbe9c42e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8/60032e9cf32e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8/6022721bf82e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8/a0da1bac9b2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8/e0108b91fa2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8/e047daf4063e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/80/20e2900fc02e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/80/6030fe14fb2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/80/e08df834032f001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/81/207849dec52e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/81/20e90798ad2b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/81/403b869cf63d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/81/a0d37509c52e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/81/a0e017eec72e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/82/104d961b932b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/82/20829588912b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/82/20ae0cc5ac2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/83/705f6955012f001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/83/90504e9eac2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/83/a0b48585922b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/84/20ae50cfce2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/84/e0cafcb5f02e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/85/7082ce5ff62e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/85/e0142d0af52e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/85/e0445a04f82e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/86/a0aaceebab2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/87/80345c38902b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/87/a020dca2ad2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/87/c0ee9e2cc02e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/87/e0091494f32e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/88/20510e4a922b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/88/e001984d0e3e00151089cca86c5b1a99 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/89/d0fdd397f63d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/89/e09bd143ef2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8a/a0819610a72b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8b/6006432e032f001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8b/b08c1511c82e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8b/d0c1d07df02e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8b/e0e354c4ee2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8c/50aa2bf3023e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8c/60ddc035f72e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8d/60933f62ff2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8d/60bb3fa1f22e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8d/d0631404023e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8d/e0e833fff72e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8e/20ff3826c62e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/8f/205432bcc82e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/9/70788731022f001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/9/a0706393c92e001511a3ba75618c68e5 rename .metadata/.plugins/org.eclipse.core.resources/.history/{cb/f0ea1f21052f001511a3ba75618c68e5 => 90/00c56e06f63d00151c31fb33fff4337f} (99%) delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/90/308d0ce3bf2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/90/6069aa58f02e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/90/b04b6599ac2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/90/e0c2706bf72e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/91/a005e2c5c42e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/92/10894b16a72b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/92/60ec4bcded2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/92/c0e52982cf2e001511a3ba75618c68e5 rename .metadata/.plugins/org.eclipse.core.resources/.history/{a/e03728d7042f001511a3ba75618c68e5 => 92/d085d1ac013e00151c31fb33fff4337f} (86%) create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/92/d0efd7c1fe3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/92/e057acf2fe2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/93/20fa36e4a32b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/93/b0d3830fc92e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/93/b0d47969d22e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/93/d0279c5a053e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/94/20da4983ad2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/94/903495c2a32b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/94/a0596c02ad2b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/95/605f63960d3e00151089cca86c5b1a99 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/95/60dd0d99f63d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/95/a0b5088a9b2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/95/f0eeaa17fd2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/97/00499c49012f001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/97/6096c38cfd2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/97/90b0e2b5013e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/97/d0e97d74fc3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/98/b0f95768c12e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/98/e00fcf2df82e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/99/506d71b4013e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/99/603c843af82e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/99/a045560ec82e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/99/e0cf6ed0f02e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/9a/e0576b12f82e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/9b/f056a849012f001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/9c/a0b5740cad2b00151fa6e49f3e10bf0b rename .metadata/.plugins/org.eclipse.core.resources/.history/{fa/60103664f82e001511a3ba75618c68e5 => 9c/d0841f77fe3d00151c31fb33fff4337f} (86%) delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/9d/1061e789922b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/9d/60c3c8dcf82e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/9d/e0ffd477033e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/9e/90fa2465922b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/9f/1004ed17a72b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/9f/9012fdfea32b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/9f/90f1d8f29a2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/9f/e052f695fd2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a/008424df922b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a/20c0c033a02b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a/705c51af0d3e00151089cca86c5b1a99 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a/80754cfbf72e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a/c0191a3f023e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a/e0a46b3df82e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a0/30a4e47faf2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a0/602b122cfd2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a0/e0c38940ef2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a0/e0ec5f84012f001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a1/302a6e59d22e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a2/205f1d48a92b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a2/d087eaeb063e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a3/109449b7ac2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a3/70684cbef22e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a3/a0b004efd22e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a4/605a1b57ef2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a4/80b15bca902b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a4/903b023fa42b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a4/d0f0e8f0033e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a5/a032f69ec82e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a5/d04ca173f93d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a6/30615366ef2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a7/7048aedcf62e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a7/a0feefeac52e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a8/20776c1dc92e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a8/50ba8ab4043e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a9/600d733bf12e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a9/6080831f022f001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/a9/f0f38415f82e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/aa/a089d581ad2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/aa/b0d2228ec52e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/aa/e0af633fee2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ab/2091a3e5d22e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ab/20d4c998cf2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ab/c074771bfa3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ab/e0241976f62e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ac/209cc836c52e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ac/5065ec8ffe3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ac/e05e031af22e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ad/102621c3912b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ad/d0a7a16df93d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ad/e0eec742012f001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ae/60376ea0ee2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/af/00b3c459f02e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/af/505239fb033e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/af/708b111d012f001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/af/a0a41840c52e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/af/e01790d7f82e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b/40053f0ee52d0015105bf01c854e42e3 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b/50330699ef2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b1/204e43add12e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b1/90d6a166922b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b1/b0d96b12ae2b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b1/e03de6b6013e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b2/e02b9ea1ee2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b3/20455670d22e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b3/b0196cc5c12e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b3/e0282178012f001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b4/709af161ff2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b4/a0608155c72e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b4/a0d4cfa39b2b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b5/50e29274053e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b5/703791ec052f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b5/c0ca4f18013e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b5/d0028812fa3d00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b5/d00a745e053e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b6/5024b6e30d3e00151089cca86c5b1a99 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b6/604a1fa6f22e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b6/609d3f28ee2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b6/90a348520c3e00151089cca86c5b1a99 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b6/a0d78e97a42b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b6/e0d9140ff82e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b7/500aa169fd3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b7/a002ab6dcf2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b8/108b64cac52e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b8/2084fc30ad2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b8/a05981c0ac2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b8/b00f8654d22e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b9/20a7d70dc52e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b9/409c8390fe3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b9/40c2f665ef2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b9/5032653a043e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b9/50eb23fc013e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b9/d06dd7f9023e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/b9/f0e30e98f63d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ba/20380095912b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ba/50775507fd3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ba/d013f5efc12e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ba/d05064d1013e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/bb/30c1a2d8c82e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/bb/600ef5ddf82e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/bb/60b5d072043e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/bb/a010fc64a42b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/bb/a0fbec03ac2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/bb/b00f19f8d22e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/bb/e0bd71c4f22e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/bc/204e03f6a82b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/bc/30d0c335ad2b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/bd/d05bd96d083e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/be/102c495fa42b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/be/206ef6f9c52e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/be/d0face78043e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/bf/30eef93ec52e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/bf/40b7a880bf2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/bf/a0c81b95c12e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c/106816bd922b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c/2058cec6a82b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c/206bd40cc92e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c/40594044033e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c/a03dc224c62e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c/a0bbdf39cf2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c0/2087239bc52e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c0/609e9b12f22e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c0/e0ca4cccf82e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c1/402ed649c02e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c2/e08d9071fc3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c3/20dba6edad2b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c3/50421721013e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c3/709abd11f22e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c3/90b90e40c52e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c3/b0db23b2a92b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c4/30128891cf2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c4/60544486ed2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c4/e0191ea8ed2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c5/105bfc5c922b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c5/205ef9e6c72e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c5/e0bc896e043e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c6/508d4163ef2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c6/70f7bb04f92e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c6/c0dc5f8ffe3d00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c6/d022346e043e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c6/e0f20f06f22e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c7/3015ce54d22e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c7/30e525880d3e00151089cca86c5b1a99 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c7/404ceb6dff3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c7/6023b583002f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c7/d00983410a3e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c7/d05586b7fe3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c7/e0524424f92e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c7/f00aad3f023e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c7/f0d24c00f82e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c8/2097812fd22e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c9/70756544052f001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c9/a00609beac2b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/c9/d03887b7013e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ca/10df867da42b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ca/c067eb62d32e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/cb/a082a1d5a82b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/cb/e00c8ff2f32e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/cc/10137161ef2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/cc/10d57c5c0d3e00151089cca86c5b1a99 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/cc/306aac51cf2e001511a3ba75618c68e5 rename .metadata/.plugins/org.eclipse.core.resources/.history/{6f/e053c88a032f001511a3ba75618c68e5 => cc/505a3848f63d00151c31fb33fff4337f} (95%) delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/cc/60cf3d08f22e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ce/10db96ee9a2b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ce/500d093f033e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ce/60e64a99f63d00151c31fb33fff4337f rename .metadata/.plugins/org.eclipse.core.resources/.history/{ab/60ddb85af82e001511a3ba75618c68e5 => ce/d00a337efe3d00151c31fb33fff4337f} (81%) create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ce/d07741ef023e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/cf/40c8a91f043e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/cf/509e01bffe3d00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/cf/50fc0176fd3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d/10091b68922b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d/a0a4134fd42e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d/f0722227012f001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d0/20e069c0c42e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d0/40969eebfc3d00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d0/60e816e10d3e00151089cca86c5b1a99 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d0/90ea12feac2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d0/a0b7202ba92b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d0/e00161a0f72e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d0/e03bfec4f12e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d1/1064daeba32b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d1/50a093b2d12e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d1/706be4b5f12e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d2/a0f5e567cf2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d2/d0f664fd013e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d2/e0d75c1cf52e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d3/606f612ef92e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d4/60100fb6043e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d4/906a60a69b2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d4/a06157d2d22e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d4/a0c84ebbac2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d4/a0f792099b2b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d4/d0595525043e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d5/607f4314033e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d5/b0f64d23d22e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d5/d023b881073e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d6/201352cfac2b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d6/d059d3b7fd3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d6/e08d6864ff2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d7/5064fb90fe3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d7/60dd2311f02e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d7/c0293873043e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d7/d06d9fe5f93d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d8/f05418d3042f001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d8/f0762d6f043e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/d9/a0effc8dcf2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/da/3015c517d22e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/da/60d0a320f52e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/da/90595120922b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/da/a0ee8a65cf2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/da/b01aba10d22e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/da/e028ee36ee2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/da/f088765c0c3e00151089cca86c5b1a99 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/db/600bbc16013e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/db/60525316f62e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/db/d0069951053e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/db/e0afd61c022f001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/db/e0beb2d9fa2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/dc/20e486bcc52e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/dc/50e028f2023e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/dc/d0bfbbf2bf2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/dd/200daaf7c52e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/dd/20e88117c62e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/dd/50875957023e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/dd/a0d6be9fc42e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/dd/e083e020f82e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/de/10304fc2912b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/de/500da46afb3d00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/de/d037d008fa3d00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/de/f0a001d10d3e00151089cca86c5b1a99 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/df/300c6d49c02e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/df/40c1de71cf2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/df/a0feec31ad2b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/df/c06a7eb00d3e00151089cca86c5b1a99 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/df/c0aa55450c3e00151089cca86c5b1a99 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/df/d01c41c0f63d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e/20950642c92e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e/e0fe31e9033e00151c31fb33fff4337f rename .metadata/.plugins/org.eclipse.core.resources/.history/{61/60e73961f82e001511a3ba75618c68e5 => e1/3009907cfe3d00151c31fb33fff4337f} (83%) delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e1/a0985d119b2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e1/a0ddeb7bad2b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e1/d020d619fa3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e1/e0d02fe9ed2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e2/30cf0cc0c82e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e2/60b2fa130a3e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e2/e09936ccef2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e3/90184b440c3e00151089cca86c5b1a99 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e3/a0978eb0c82e001511a3ba75618c68e5 rename .metadata/.plugins/org.eclipse.core.resources/.history/{64/705f43f0042f001511a3ba75618c68e5 => e3/d08eed38f63d00151c31fb33fff4337f} (96%) delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e4/20573e85ad2b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e4/50af645b023e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e5/607d36ccf02e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e5/60d93450f93d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e5/e039cfb8f22e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e6/7092210c0a3e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e6/a040ea06ad2b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e6/c0b7626f043e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e6/d0c6108f083e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e6/e09fc270f02e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e7/d06d6706fd3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e8/10533cf0ad2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e8/207d10c3f52a00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e8/e08ce196093e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/e9/a0aad154902b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ea/40a8228bfe3d00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ea/5018d788033e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ea/a085533dcf2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ea/d0facaee052f001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/eb/a0999107ac2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ec/30fe1899d22e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ec/90418517a72b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ec/c098ba41033e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ec/c0d3c395fc3d00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ec/d0cc5971043e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ed/e0feb053f22e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ed/f09acb29f62e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f/30dc59d9c82e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f/4081c9edc12e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f/902d449b9b2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f/a035f604a92b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f0/30004907d32e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f0/904f621cc82e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f0/d01b9bcffc3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f0/e006e534f82e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f1/5056a305043e00151c31fb33fff4337f create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f1/d02f5a6dff3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f2/e0fcf2d8f02e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f3/102d06a3fe2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f3/d0a2d21dfa3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f4/00874f9ef72e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f4/100cd858cf2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f4/908b5426932b00151fa6e49f3e10bf0b create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f4/d034285bfd3d00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f5/606e09ccfa2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f6/20de0123932b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f6/a065bef2c42e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f7/20ed419eaf2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f7/30fdd3fbc42e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f7/60d64f66fd2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f8/108fca500c3e00151089cca86c5b1a99 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f8/20e60535a72b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f8/e0c1b81ef82e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f9/6022dfe8f92e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/f9/60a3e283fd2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/fa/201779a3d22e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/fa/d03cd67b033e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/fb/6086a867ee2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/fb/806b4e4ac02e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/fb/b0ab4825c62e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/fc/3086b133c72e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/fc/50e6e65e043e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/fd/80dba9e9f02e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/fe/50283165ef2e001511a3ba75618c68e5 create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/fe/50e0facf023e00151c31fb33fff4337f delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/fe/e0151cd4ef2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ff/60ae02e4fe2e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ff/90825a06932b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ff/b08757dc9a2b00151fa6e49f3e10bf0b delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.history/ff/f0d7250df42e001511a3ba75618c68e5 delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.indexes/af/history.index delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.indexes/e4/81/43/bf/history.index delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.indexes/e4/history.index delete mode 100644 .metadata/.plugins/org.eclipse.core.resources/.root/2.tree create mode 100644 .metadata/.plugins/org.eclipse.core.resources/.root/5.tree delete mode 100644 .metadata/.plugins/org.eclipse.jdt.ui/jdt-images/6.png delete mode 100644 .metadata/.plugins/org.eclipse.jdt.ui/jdt-images/7.png delete mode 100644 .metadata/.plugins/org.eclipse.jdt.ui/jdt-images/8.png delete mode 100644 .metadata/.plugins/org.eclipse.jdt.ui/jdt-images/9.png create mode 100644 .metadata/.plugins/org.eclipse.jst.jsp.core/taglibindex/1508644233.dat create mode 100644 TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/MaybeOfflinePlayer.class create mode 100644 TheButtonAutoFlair/p.javaproj create mode 100644 TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/MaybeOfflinePlayer.java diff --git a/.metadata/.log b/.metadata/.log index e2e6a43..c8fd4e5 100644 --- a/.metadata/.log +++ b/.metadata/.log @@ -276,3 +276,180 @@ org.eclipse.core.runtime.AssertionFailedException: assertion failed: at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584) at org.eclipse.equinox.launcher.Main.run(Main.java:1438) +!SESSION 2015-07-27 17:30:41.381 ----------------------------------------------- +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-07-27 17:31:56.400 +!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-07-27 17:31:56.421 +!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-08 18:30:00.907 ----------------------------------------------- +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 -product org.eclipse.epp.package.jee.product +Command-line arguments: -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.jee.product -data D:\Z - Norbi cucca\0 Projektek\TheButtonMCAutoFlairProto\Spigot plugin -product org.eclipse.epp.package.jee.product + +!ENTRY org.eclipse.egit.ui 2 0 2015-08-08 18:30:23.469 +!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-08 18:30:23.581 +!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.jface 2 0 2015-08-08 20:21:36.761 +!MESSAGE Keybinding conflicts occurred. They may interfere with normal accelerator operation. +!SUBENTRY 1 org.eclipse.jface 2 0 2015-08-08 20:21:36.761 +!MESSAGE A conflict occurred for ALT+SHIFT+ARROW_DOWN: +Binding(ALT+SHIFT+ARROW_DOWN, + ParameterizedCommand(Command(org.eclipse.jdt.ui.edit.text.java.select.last,Restore Last Selection, + Restore last selection, + Category(org.eclipse.ui.category.edit,Edit,null,true), + org.eclipse.ui.internal.MakeHandlersGo@7ce87f9d, + ,,true),null), + org.eclipse.ui.defaultAcceleratorConfiguration, + org.eclipse.jdt.ui.javaEditorScope,,,system) +Binding(ALT+SHIFT+ARROW_DOWN, + ParameterizedCommand(Command(org.eclipse.mylyn.tasks.ui.command.markTaskReadGoToNextUnread,Mark Task Read and Go To Next Unread Task, + , + Category(org.eclipse.mylyn.tasks.ui.commands,Task Repositories,null,true), + org.eclipse.ui.internal.MakeHandlersGo@e944541, + ,,true),null), + org.eclipse.ui.defaultAcceleratorConfiguration, + org.eclipse.mylyn.tasks.ui.views.tasks,,,system) +!SUBENTRY 1 org.eclipse.jface 2 0 2015-08-08 20:21:36.761 +!MESSAGE A conflict occurred for ALT+ARROW_DOWN: +Binding(ALT+ARROW_DOWN, + ParameterizedCommand(Command(org.eclipse.mylyn.tasks.ui.command.goToNextUnread,Go To Next Unread Task, + , + Category(org.eclipse.ui.category.navigate,Navigate,null,true), + org.eclipse.ui.internal.MakeHandlersGo@6198e9b5, + ,,true),null), + org.eclipse.ui.defaultAcceleratorConfiguration, + org.eclipse.mylyn.tasks.ui.views.tasks,,,system) +Binding(ALT+ARROW_DOWN, + ParameterizedCommand(Command(org.eclipse.ui.edit.text.moveLineDown,Move Lines Down, + Moves the selected lines down, + Category(org.eclipse.ui.category.textEditor,Text Editing,Text Editing Commands,true), + org.eclipse.ui.internal.MakeHandlersGo@1c89cec5, + ,,true),null), + org.eclipse.ui.defaultAcceleratorConfiguration, + org.eclipse.ui.textEditorScope,,,system) +!SUBENTRY 1 org.eclipse.jface 2 0 2015-08-08 20:21:36.761 +!MESSAGE A conflict occurred for ALT+SHIFT+ARROW_UP: +Binding(ALT+SHIFT+ARROW_UP, + ParameterizedCommand(Command(org.eclipse.jdt.ui.edit.text.java.select.enclosing,Select Enclosing Element, + Expand selection to include enclosing element, + Category(org.eclipse.ui.category.edit,Edit,null,true), + org.eclipse.ui.internal.MakeHandlersGo@1447bef2, + ,,true),null), + org.eclipse.ui.defaultAcceleratorConfiguration, + org.eclipse.jdt.ui.javaEditorScope,,,system) +Binding(ALT+SHIFT+ARROW_UP, + ParameterizedCommand(Command(org.eclipse.mylyn.tasks.ui.command.markTaskReadGoToPreviousUnread,Mark Task Read and Go To Previous Unread Task, + , + Category(org.eclipse.mylyn.tasks.ui.commands,Task Repositories,null,true), + org.eclipse.ui.internal.MakeHandlersGo@2b6c3f70, + ,,true),null), + org.eclipse.ui.defaultAcceleratorConfiguration, + org.eclipse.mylyn.tasks.ui.views.tasks,,,system) +!SUBENTRY 1 org.eclipse.jface 2 0 2015-08-08 20:21:36.761 +!MESSAGE A conflict occurred for ALT+SHIFT+U: +Binding(ALT+SHIFT+U, + ParameterizedCommand(Command(org.eclipse.jdt.ui.edit.text.remove.occurrence.annotations,Remove Occurrence Annotations, + Removes the occurrence annotations from the current editor, + Category(org.eclipse.jdt.ui.category.source,Source,Java Source Actions,true), + org.eclipse.ui.internal.MakeHandlersGo@77ec911, + ,,true),null), + org.eclipse.ui.defaultAcceleratorConfiguration, + org.eclipse.jdt.ui.javaEditorScope,,,system) +Binding(ALT+SHIFT+U, + ParameterizedCommand(Command(org.eclipse.mylyn.tasks.ui.command.markTaskUnread,Mark Task Unread, + , + Category(org.eclipse.mylyn.tasks.ui.commands,Task Repositories,null,true), + org.eclipse.ui.internal.MakeHandlersGo@55d3c0dd, + ,,true),null), + org.eclipse.ui.defaultAcceleratorConfiguration, + org.eclipse.mylyn.tasks.ui.views.tasks,,,system) +!SUBENTRY 1 org.eclipse.jface 2 0 2015-08-08 20:21:36.761 +!MESSAGE A conflict occurred for INSERT: +Binding(INSERT, + ParameterizedCommand(Command(org.eclipse.mylyn.tasks.ui.command.new.local.task,New Local Task, + , + Category(org.eclipse.mylyn.tasks.ui.commands,Task Repositories,null,true), + org.eclipse.ui.internal.MakeHandlersGo@7c4a44bb, + ,,true),null), + org.eclipse.ui.defaultAcceleratorConfiguration, + org.eclipse.mylyn.tasks.ui.views.tasks,,,system) +Binding(INSERT, + ParameterizedCommand(Command(org.eclipse.ui.edit.text.toggleOverwrite,Toggle Overwrite, + Toggle overwrite mode, + Category(org.eclipse.ui.category.textEditor,Text Editing,Text Editing Commands,true), + org.eclipse.ui.internal.MakeHandlersGo@369773fd, + ,,true),null), + org.eclipse.ui.defaultAcceleratorConfiguration, + org.eclipse.ui.textEditorScope,,,system) +!SUBENTRY 1 org.eclipse.jface 2 0 2015-08-08 20:21:36.761 +!MESSAGE A conflict occurred for ALT+ARROW_UP: +Binding(ALT+ARROW_UP, + ParameterizedCommand(Command(org.eclipse.mylyn.tasks.ui.command.goToPreviousUnread,Go To Previous Unread Task, + , + Category(org.eclipse.ui.category.navigate,Navigate,null,true), + org.eclipse.ui.internal.MakeHandlersGo@5d7399f9, + ,,true),null), + org.eclipse.ui.defaultAcceleratorConfiguration, + org.eclipse.mylyn.tasks.ui.views.tasks,,,system) +Binding(ALT+ARROW_UP, + ParameterizedCommand(Command(org.eclipse.ui.edit.text.moveLineUp,Move Lines Up, + Moves the selected lines up, + Category(org.eclipse.ui.category.textEditor,Text Editing,Text Editing Commands,true), + org.eclipse.ui.internal.MakeHandlersGo@47d0127f, + ,,true),null), + org.eclipse.ui.defaultAcceleratorConfiguration, + org.eclipse.ui.textEditorScope,,,system) +!SESSION 2015-08-08 22:18:57.768 ----------------------------------------------- +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-08 22:19:31.422 +!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-08 22:19:31.528 +!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. diff --git a/.metadata/.mylyn/.tasks.xml.zip b/.metadata/.mylyn/.tasks.xml.zip index 93e1057579de7bb1cfe13000a22e0fe3a708612c..c99ab0a6b4c0f9f394bfcd87af0733a32346fb5f 100644 GIT binary patch delta 30 icmeyx_=}M*z?+#xgn@&DgJIPs4)=+CD_FqvE(ZX9=?MP- delta 30 icmeyx_=}M*z?+#xgn@&DgW>h8FK!e0R 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/0/6088cf20022f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/0/6088cf20022f001511a3ba75618c68e5 deleted file mode 100644 index ee7bab6..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/0/6088cf20022f001511a3ba75618c68e5 +++ /dev/null @@ -1,68 +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("ChatSerializer"); - private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); - public static void sendRawMessage(Player player, String message) { - try { - System.out.prinom - Object handle = Reflection.getHandle(player); - Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); - Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); - Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); - Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); - } catch (Exception e) { - e.printStackTrace(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/0/a0189d31a72b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/0/a0189d31a72b00151fa6e49f3e10bf0b deleted file mode 100644 index c87d327..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/0/a0189d31a72b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,48 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/0/d057cb01fa3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/0/d057cb01fa3d00151c31fb33fff4337f new file mode 100644 index 0000000..8915820 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/0/d057cb01fa3d00151c31fb33fff4337f @@ -0,0 +1,7 @@ +package tk.sznp.thebuttonautoflair; + +public class MaybeOfflinePlayer { + String PlayerName; + String UserName; + String Flair; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1/10092140c52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/1/10092140c52e001511a3ba75618c68e5 deleted file mode 100644 index d656c74..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1/10092140c52e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String[] line=br.readLine().split(" "); - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1/60ca8b100a3e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/1/60ca8b100a3e00151c31fb33fff4337f new file mode 100644 index 0000000..b11e849 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1/60ca8b100a3e00151c31fb33fff4337f @@ -0,0 +1,431 @@ +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/d0997b1b023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/1/d0997b1b023e00151c31fb33fff4337f new file mode 100644 index 0000000..2650c6f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1/d0997b1b023e00151c31fb33fff4337f @@ -0,0 +1,125 @@ +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(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); + } + 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 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"); + } + 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) + + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + 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/1/f03cfc260d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/1/f03cfc260d3e00151089cca86c5b1a99 new file mode 100644 index 0000000..ee35a22 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1/f03cfc260d3e00151089cca86c5b1a99 @@ -0,0 +1,434 @@ +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)"); + //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. + 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/10/704e9345022f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/10/704e9345022f001511a3ba75618c68e5 deleted file mode 100644 index 15a6d77..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/10/704e9345022f001511a3ba75618c68e5 +++ /dev/null @@ -1,73 +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("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.prinln("3"); - Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); - System.out.prinln("4"); - Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); - System.out.prinln("5"); - Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); - System.out.prinln("6"); - } catch (Exception e) { - e.printStackTrace(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/10/70a9b080083e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/10/70a9b080083e00151c31fb33fff4337f new file mode 100644 index 0000000..3c5dbca --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/10/70a9b080083e00151c31fb33fff4337f @@ -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; + 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/10/80a0b699f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/10/80a0b699f63d00151c31fb33fff4337f new file mode 100644 index 0000000..2ef29ec --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/10/80a0b699f63d00151c31fb33fff4337f @@ -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(); + 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/e03d4f54f62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/10/e03d4f54f62e001511a3ba75618c68e5 deleted file mode 100644 index d7a829b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/10/e03d4f54f62e001511a3ba75618c68e5 +++ /dev/null @@ -1,383 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/11/302d82aec52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/11/302d82aec52e001511a3ba75618c68e5 deleted file mode 100644 index 5a80116..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/11/302d82aec52e001511a3ba75618c68e5 +++ /dev/null @@ -1,312 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PlayerTowns.put(s[0], s[1]) - } - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/11/50857fe1f93d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/11/50857fe1f93d00151c31fb33fff4337f new file mode 100644 index 0000000..cf0bfb7 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/11/50857fe1f93d00151c31fb33fff4337f @@ -0,0 +1,5 @@ +package tk.sznp.thebuttonautoflair; + +public class MaybeOfflinePlayer { + +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/11/50a623b5013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/11/50a623b5013e00151c31fb33fff4337f new file mode 100644 index 0000000..d412cf3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/11/50a623b5013e00151c31fb33fff4337f @@ -0,0 +1,418 @@ +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/11/6040761c022f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/11/6040761c022f001511a3ba75618c68e5 deleted file mode 100644 index bfe0c85..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/11/6040761c022f001511a3ba75618c68e5 +++ /dev/null @@ -1,67 +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("ChatSerializer"); - private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); - public static void sendRawMessage(Player player, String message) { - try { - Object handle = Reflection.getHandle(player); - Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); - Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); - Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); - Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); - } catch (Exception e) { - e.printStackTrace(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/11/703abcfff12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/11/703abcfff12e001511a3ba75618c68e5 deleted file mode 100644 index c747271..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/11/703abcfff12e001511a3ba75618c68e5 +++ /dev/null @@ -1,371 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/11/b0a0fc59e42d0015105bf01c854e42e3 b/.metadata/.plugins/org.eclipse.core.resources/.history/11/b0a0fc59e42d0015105bf01c854e42e3 deleted file mode 100644 index e0a12bf..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/11/b0a0fc59e42d0015105bf01c854e42e3 +++ /dev/null @@ -1,286 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/11/e02f8f8d083e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/11/e02f8f8d083e00151c31fb33fff4337f new file mode 100644 index 0000000..4b994f9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/11/e02f8f8d083e00151c31fb33fff4337f @@ -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]) + { + 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); + } + 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 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"); + } + 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.HasFlair) + { + 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/12/2027da9cac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/12/2027da9cac2b00151fa6e49f3e10bf0b deleted file mode 100644 index 60393ed..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/12/2027da9cac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,73 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedWriter; -import java.io.FileWriter; -import java.io.IOException; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/13/604732c5f52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/13/604732c5f52e001511a3ba75618c68e5 deleted file mode 100644 index 77fab60..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/13/604732c5f52e001511a3ba75618c68e5 +++ /dev/null @@ -1,382 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/13/b00ee04cc72e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/13/b00ee04cc72e001511a3ba75618c68e5 deleted file mode 100644 index 3db0df2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/13/b00ee04cc72e001511a3ba75618c68e5 +++ /dev/null @@ -1,319 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String name) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/14/70fadb62ff2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/14/70fadb62ff2e001511a3ba75618c68e5 deleted file mode 100644 index 17fc5c8..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/14/70fadb62ff2e001511a3ba75618c68e5 +++ /dev/null @@ -1,49 +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; - -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 - { - 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\"}]}}}]"; - } - //System.out.println("Added player "+p.getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/15/20b3105acf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/15/20b3105acf2e001511a3ba75618c68e5 deleted file mode 100644 index 771250c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/15/20b3105acf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,92 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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": - if(player.isOp()) - { - try - { - File 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(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/15/4032ab5dbf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/15/4032ab5dbf2e001511a3ba75618c68e5 deleted file mode 100644 index 3e34365..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/15/4032ab5dbf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,64 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/15/602ef8eded2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/15/602ef8eded2e001511a3ba75618c68e5 deleted file mode 100644 index 73ed72d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/15/602ef8eded2e001511a3ba75618c68e5 +++ /dev/null @@ -1,337 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/15/9032115ca42b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/15/9032115ca42b00151fa6e49f3e10bf0b deleted file mode 100644 index 6bf5b8a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/15/9032115ca42b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,37 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - PluginMain.IgnoredPlayers.add(player.getName()); - break; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/15/905b71c7ed2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/15/905b71c7ed2e001511a3ba75618c68e5 deleted file mode 100644 index e0c4ba7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/15/905b71c7ed2e001511a3ba75618c68e5 +++ /dev/null @@ -1,336 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/15/d05be66e043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/15/d05be66e043e00151c31fb33fff4337f new file mode 100644 index 0000000..87c0c13 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/15/d05be66e043e00151c31fb33fff4337f @@ -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]) + { + 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); + } + 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 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"); + } + 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(p.Flair!=null) + { + String flair=p.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/16/10971668a42b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/16/10971668a42b00151fa6e49f3e10bf0b deleted file mode 100644 index c068fb0..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/16/10971668a42b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,41 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - PluginMain.IgnoredPlayers.add(player.getName()); - break; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/16/b03d628ac42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/16/b03d628ac42e001511a3ba75618c68e5 deleted file mode 100644 index 26cb915..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/16/b03d628ac42e001511a3ba75618c68e5 +++ /dev/null @@ -1,294 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForClass(flairclass); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/17/202ded81a92b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/17/202ded81a92b00151fa6e49f3e10bf0b deleted file mode 100644 index fd3d75b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/17/202ded81a92b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,61 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("$cYou already have this flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - } - break; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/17/90bccd90922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/17/90bccd90922b00151fa6e49f3e10bf0b deleted file mode 100644 index 83b80c4..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/17/90bccd90922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,16 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.util.function.Predicate; - -public class MyPredicate implements Predicate -{ - public MyPredicate(T first) - { - - } - @Override - public boolean test(T second) { - return false; - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/17/a0348882a92b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/17/a0348882a92b00151fa6e49f3e10bf0b deleted file mode 100644 index e7f8c34..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/17/a0348882a92b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,63 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("$cYou already have this flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/17/d004cf02fd3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/17/d004cf02fd3d00151c31fb33fff4337f new file mode 100644 index 0000000..95612ac --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/17/d004cf02fd3d00151c31fb33fff4337f @@ -0,0 +1,24 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer { + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static void AddPlayer(String playername) + { + if(!AllPlayers.contains(name)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/17/d08a7e97f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/17/d08a7e97f63d00151c31fb33fff4337f new file mode 100644 index 0000000..2ef29ec --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/17/d08a7e97f63d00151c31fb33fff4337f @@ -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(); + 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/2072884bc02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/18/2072884bc02e001511a3ba75618c68e5 deleted file mode 100644 index 27b8fb2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/18/2072884bc02e001511a3ba75618c68e5 +++ /dev/null @@ -1,292 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/18/a075b55fc92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/18/a075b55fc92e001511a3ba75618c68e5 deleted file mode 100644 index 5aaf0eb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/18/a075b55fc92e001511a3ba75618c68e5 +++ /dev/null @@ -1,333 +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.List; -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.Towny; -import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List towns = TownyUniverse.getDataSource().getTowns(); - try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - return town.getName(); - } catch (NotRegisteredException e) { - return ""; - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/18/e00b6b58ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/18/e00b6b58ef2e001511a3ba75618c68e5 deleted file mode 100644 index 1191621..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/18/e00b6b58ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,343 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/18/e024139bf02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/18/e024139bf02e001511a3ba75618c68e5 deleted file mode 100644 index fcb3b5d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/18/e024139bf02e001511a3ba75618c68e5 +++ /dev/null @@ -1,354 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/18/e07d8480f52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/18/e07d8480f52e001511a3ba75618c68e5 deleted file mode 100644 index 6563824..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/18/e07d8480f52e001511a3ba75618c68e5 +++ /dev/null @@ -1,382 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/19/0072a52f022f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/19/0072a52f022f001511a3ba75618c68e5 deleted file mode 100644 index 5f7d8f2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/19/0072a52f022f001511a3ba75618c68e5 +++ /dev/null @@ -1,69 +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("ChatSerializer"); - private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); - public static void sendRawMessage(Player player, String message) { - try { - System.out.prinln("1"); - Object handle = Reflection.getHandle(player); - System.out.prinln("2"); - Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); - Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); - Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); - Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); - } catch (Exception e) { - e.printStackTrace(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/19/60f2ab7f023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/19/60f2ab7f023e00151c31fb33fff4337f new file mode 100644 index 0000000..ff19301 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/19/60f2ab7f023e00151c31fb33fff4337f @@ -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.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/1a/a09f2e39c52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/1a/a09f2e39c52e001511a3ba75618c68e5 deleted file mode 100644 index 733faf0..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1a/a09f2e39c52e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String line=br.readLine(); - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1a/c0cfb22dc02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/1a/c0cfb22dc02e001511a3ba75618c68e5 deleted file mode 100644 index c6a0024..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1a/c0cfb22dc02e001511a3ba75618c68e5 +++ /dev/null @@ -1,292 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - //player.setDisplayName(player.getDisplayName()+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1a/d0fbf199f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/1a/d0fbf199f63d00151c31fb33fff4337f new file mode 100644 index 0000000..2ef29ec --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1a/d0fbf199f63d00151c31fb33fff4337f @@ -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(); + 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/9066f985a92b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/1b/9066f985a92b00151fa6e49f3e10bf0b deleted file mode 100644 index 81e2c15..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1b/9066f985a92b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,63 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("$cYou already have this flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1b/f0224de8f62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/1b/f0224de8f62e001511a3ba75618c68e5 deleted file mode 100644 index 90475e6..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1b/f0224de8f62e001511a3ba75618c68e5 +++ /dev/null @@ -1,384 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1b/f0c4a095083e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/1b/f0c4a095083e00151c31fb33fff4337f new file mode 100644 index 0000000..f174b9f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1b/f0c4a095083e00151c31fb33fff4337f @@ -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.HasFlair) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + 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); + } + 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 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"); + } + 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/1c/50a873c4093e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/1c/50a873c4093e00151c31fb33fff4337f new file mode 100644 index 0000000..962d1ac --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1c/50a873c4093e00151c31fb33fff4337f @@ -0,0 +1,431 @@ +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/1c/6074bf28f12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/1c/6074bf28f12e001511a3ba75618c68e5 deleted file mode 100644 index c0911e7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1c/6074bf28f12e001511a3ba75618c68e5 +++ /dev/null @@ -1,361 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1c/609377ad0d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/1c/609377ad0d3e00151089cca86c5b1a99 new file mode 100644 index 0000000..752fdf8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/1c/609377ad0d3e00151089cca86c5b1a99 @@ -0,0 +1,437 @@ +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)"); + //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())) + System.out.println("PlayerName: "+player.getName()); + System.out.println(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair); + System.out.println(MaybeOfflinePlayer.AllPlayers.get(player.getName()).Flair); + 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/1c/90a675ce902b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/1c/90a675ce902b00151fa6e49f3e10bf0b deleted file mode 100644 index 5159433..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1c/90a675ce902b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,21 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerJoinEvent; - -public class PlayerListener implements Listener -{ - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1d/2083e990ac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/1d/2083e990ac2b00151fa6e49f3e10bf0b deleted file mode 100644 index d91dba8..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1d/2083e990ac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,244 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - 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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1e/10a41e97ee2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/1e/10a41e97ee2e001511a3ba75618c68e5 deleted file mode 100644 index 7afefee..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1e/10a41e97ee2e001511a3ba75618c68e5 +++ /dev/null @@ -1,341 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - int x=0> - while((x=displayname.indexOf("§", x))) - Positions.add(x) - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1e/504c9d52ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/1e/504c9d52ef2e001511a3ba75618c68e5 deleted file mode 100644 index 40a3922..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1e/504c9d52ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,343 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=displayname.length()-1; i>=0; i--) { - if(Character.isUpperCase(str.charAt(i))) { - return i; - } - } - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1e/a0220ef3ab2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/1e/a0220ef3ab2b00151fa6e49f3e10bf0b deleted file mode 100644 index e303e38..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1e/a0220ef3ab2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,254 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - 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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1f/2028de3fcf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/1f/2028de3fcf2e001511a3ba75618c68e5 deleted file mode 100644 index 86b0fad..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1f/2028de3fcf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,85 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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": - if(player.isOp()) - { - 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(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/1f/b00d77f0c42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/1f/b00d77f0c42e001511a3ba75618c68e5 deleted file mode 100644 index ca48d16..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/1f/b00d77f0c42e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - 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); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2/c07312e9bf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/2/c07312e9bf2e001511a3ba75618c68e5 deleted file mode 100644 index 809f9c9..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2/c07312e9bf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,291 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - } - - public static void AppendPlayerDisplayFlairFinal(Player player, String flair) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/20/a01363d8a82b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/20/a01363d8a82b00151fa6e49f3e10bf0b deleted file mode 100644 index f20c6cb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/20/a01363d8a82b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,50 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - player.setDisplayName(.substring(0, dname)); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/20/a040189aaf2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/20/a040189aaf2b00151fa6e49f3e10bf0b deleted file mode 100644 index 63131ae..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/20/a040189aaf2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,285 +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; - -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", "")); - } - 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", "")); - } - 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 - { - } - for(String player : AcceptedPlayers) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/20/a0f94f72cf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/20/a0f94f72cf2e001511a3ba75618c68e5 deleted file mode 100644 index bbe6918..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/20/a0f94f72cf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,94 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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. - if(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(); - player.sendMessage(") - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/21/6079da59fa2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/21/6079da59fa2e001511a3ba75618c68e5 deleted file mode 100644 index cbdeaa3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/21/6079da59fa2e001511a3ba75618c68e5 +++ /dev/null @@ -1,391 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - ArrayList Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length)) //TODO - { - //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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/21/9091585acf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/21/9091585acf2e001511a3ba75618c68e5 deleted file mode 100644 index 771250c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/21/9091585acf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,92 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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": - if(player.isOp()) - { - try - { - File 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(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/22/10b43daf9b2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/22/10b43daf9b2b00151fa6e49f3e10bf0b deleted file mode 100644 index cae7823..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/22/10b43daf9b2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,43 +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; - -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)); - System.out.println("Added player "+event.getPlayer().getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.ini"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - br.readLine(); - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/23/40423b2bcf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/23/40423b2bcf2e001511a3ba75618c68e5 deleted file mode 100644 index 7259f0b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/23/40423b2bcf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,67 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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": - - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/23/60878d1afb2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/23/60878d1afb2e001511a3ba75618c68e5 deleted file mode 100644 index b85b6bf..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/23/60878d1afb2e001511a3ba75618c68e5 +++ /dev/null @@ -1,397 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/23/a0089f13c62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/23/a0089f13c62e001511a3ba75618c68e5 deleted file mode 100644 index 527c743..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/23/a0089f13c62e001511a3ba75618c68e5 +++ /dev/null @@ -1,312 +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; - -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", "")); - } - 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", "")); - } - 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(" "); - PlayerTowns.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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/24/205b7a17d32e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/24/205b7a17d32e001511a3ba75618c68e5 deleted file mode 100644 index 3c67f45..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/24/205b7a17d32e001511a3ba75618c68e5 +++ /dev/null @@ -1,335 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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), dname.indexOf(flair))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/24/60c0f732f92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/24/60c0f732f92e001511a3ba75618c68e5 deleted file mode 100644 index 12740b3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/24/60c0f732f92e001511a3ba75618c68e5 +++ /dev/null @@ -1,389 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - ArrayList Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length)) //TODO - { - //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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/24/b0050f65c02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/24/b0050f65c02e001511a3ba75618c68e5 deleted file mode 100644 index 27b8fb2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/24/b0050f65c02e001511a3ba75618c68e5 +++ /dev/null @@ -1,292 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/24/d08c2d11033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/24/d08c2d11033e00151c31fb33fff4337f new file mode 100644 index 0000000..a6a1d5d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/24/d08c2d11033e00151c31fb33fff4337f @@ -0,0 +1,419 @@ +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/103a93e1922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/26/103a93e1922b00151fa6e49f3e10bf0b deleted file mode 100644 index 943ae61..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/26/103a93e1922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,31 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - for(Player player : PluginMain.Players) - { - - } - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/26/908a556aa42b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/26/908a556aa42b00151fa6e49f3e10bf0b deleted file mode 100644 index a3ec0f3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/26/908a556aa42b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,41 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - PluginMain.AcceptedPlayers.add(player.getName()); - break; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/26/d01f259ef02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/26/d01f259ef02e001511a3ba75618c68e5 deleted file mode 100644 index e57ddce..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/26/d01f259ef02e001511a3ba75618c68e5 +++ /dev/null @@ -1,355 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/27/603d2e77012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/27/603d2e77012f001511a3ba75618c68e5 deleted file mode 100644 index 3b279ea..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/27/603d2e77012f001511a3ba75618c68e5 +++ /dev/null @@ -1,67 +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 - { - 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\"}]}}}]"; - p.sendTitle(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("ChatSerializer"); - private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); - public static void sendRawMessage(Player player, String message) { - try { - Object handle = Reflection.getHandle(player); - Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); - Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); - Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); - Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); - } catch (Exception e) { - e.printStackTrace(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/27/6094151b012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/27/6094151b012f001511a3ba75618c68e5 deleted file mode 100644 index 050f11a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/27/6094151b012f001511a3ba75618c68e5 +++ /dev/null @@ -1,50 +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; - -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 - { - 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\"}]}}}]"; - p.sendTitle(json, ""; - } - //System.out.println("Added player "+p.getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i 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); - } - - 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; - default: - finalflair=""; - break; - } - if(finalflair.length()>0) //<-- 2015.07.20. - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/27/70ba5e30032f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/27/70ba5e30032f001511a3ba75618c68e5 deleted file mode 100644 index 826a700..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/27/70ba5e30032f001511a3ba75618c68e5 +++ /dev/null @@ -1,78 +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("ChatSerializer"); - private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); - public static void sendRawMessage(Player player, String message) { - if (majorVersion < 1.8 || (majorVersion == 1.8 && lesserVersion == 1)) { - chatSerializerClazz = Reflection.getNMSClass("ChatSerializer"); - } else { - chatSerializerClazz = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); - } - 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/27/d0c61635023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/27/d0c61635023e00151c31fb33fff4337f new file mode 100644 index 0000000..e00eae6 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/27/d0c61635023e00151c31fb33fff4337f @@ -0,0 +1,125 @@ +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(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); + } + 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 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"); + } + 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(MaybeOfflinePlayer p : MaybeOfflinePlayer.AllPlayers.values()) + { + if(p.Flair!=null) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + 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/28/50c3d09efd3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/28/50c3d09efd3d00151c31fb33fff4337f new file mode 100644 index 0000000..52c12fe --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/28/50c3d09efd3d00151c31fb33fff4337f @@ -0,0 +1,26 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.HashMap; + +public class MaybeOfflinePlayer +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + 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/29/4085cc81fe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/29/4085cc81fe3d00151c31fb33fff4337f new file mode 100644 index 0000000..77b05cb --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/29/4085cc81fe3d00151c31fb33fff4337f @@ -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; + if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + 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.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); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(PluginMain.AcceptedPlayers.contains(player.getName())) + PluginMain.AcceptedPlayers.remove(player.getName()); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + 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))); + 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) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + 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/29/500adc32083e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/29/500adc32083e00151c31fb33fff4337f new file mode 100644 index 0000000..3c5dbca --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/29/500adc32083e00151c31fb33fff4337f @@ -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; + 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/29/50dd5657043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/29/50dd5657043e00151c31fb33fff4337f new file mode 100644 index 0000000..772f7ef --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/29/50dd5657043e00151c31fb33fff4337f @@ -0,0 +1,125 @@ +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(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); + } + 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 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"); + } + 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(MaybeOfflinePlayer p : MaybeOfflinePlayer.AllPlayers.values()) + { + if(p.Flair!=null) + { + String flair=p.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/2a/104eb717a72b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/2a/104eb717a72b00151fa6e49f3e10bf0b deleted file mode 100644 index 96a6182..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2a/104eb717a72b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,47 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2a/20a4e0af0d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/2a/20a4e0af0d3e00151089cca86c5b1a99 new file mode 100644 index 0000000..efac5c3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2a/20a4e0af0d3e00151089cca86c5b1a99 @@ -0,0 +1,434 @@ +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)"); + //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(); //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/20defcdbc72e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/2a/20defcdbc72e001511a3ba75618c68e5 deleted file mode 100644 index a330c1e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2a/20defcdbc72e001511a3ba75618c68e5 +++ /dev/null @@ -1,322 +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.Towny; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - Towny.getTownyInstance() - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2a/304ef98cc22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/2a/304ef98cc22e001511a3ba75618c68e5 deleted file mode 100644 index 26cb915..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2a/304ef98cc22e001511a3ba75618c68e5 +++ /dev/null @@ -1,294 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForClass(flairclass); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2b/b071b16acf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/2b/b071b16acf2e001511a3ba75618c68e5 deleted file mode 100644 index 6d662be..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2b/b071b16acf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,93 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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. - if(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(); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2b/c0dde05e023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/2b/c0dde05e023e00151c31fb33fff4337f new file mode 100644 index 0000000..33aea73 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2b/c0dde05e023e00151c31fb33fff4337f @@ -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.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/20ac6667d22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/2c/20ac6667d22e001511a3ba75618c68e5 deleted file mode 100644 index e8fbbda..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2c/20ac6667d22e001511a3ba75618c68e5 +++ /dev/null @@ -1,99 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //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"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(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.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2c/50d8e8c4093e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/2c/50d8e8c4093e00151c31fb33fff4337f new file mode 100644 index 0000000..efbefe2 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2c/50d8e8c4093e00151c31fb33fff4337f @@ -0,0 +1,431 @@ +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/2d/20ebe2afc42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/2d/20ebe2afc42e001511a3ba75618c68e5 deleted file mode 100644 index 5eb70f1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2d/20ebe2afc42e001511a3ba75618c68e5 +++ /dev/null @@ -1,294 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2d/60a68ad9013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/2d/60a68ad9013e00151c31fb33fff4337f new file mode 100644 index 0000000..a957fb0 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2d/60a68ad9013e00151c31fb33fff4337f @@ -0,0 +1,419 @@ +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/2d/9018d69a922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/2d/9018d69a922b00151fa6e49f3e10bf0b deleted file mode 100644 index b78276f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2d/9018d69a922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,17 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.util.function.Predicate; - -public class MyPredicate implements Predicate -{ - private T First; - public MyPredicate(T first) - { - First=first; - } - @Override - public boolean test(T second) { - return false; - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2d/c0b10f0c023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/2d/c0b10f0c023e00151c31fb33fff4337f new file mode 100644 index 0000000..1174627 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2d/c0b10f0c023e00151c31fb33fff4337f @@ -0,0 +1,124 @@ +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(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); + } + 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 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"); + } + 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) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + 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/2e/204539a2c72e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/2e/204539a2c72e001511a3ba75618c68e5 deleted file mode 100644 index 86fec34..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2e/204539a2c72e001511a3ba75618c68e5 +++ /dev/null @@ -1,321 +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.Towny; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2e/c0323f76053e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/2e/c0323f76053e00151c31fb33fff4337f new file mode 100644 index 0000000..5e25dbe --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2e/c0323f76053e00151c31fb33fff4337f @@ -0,0 +1,429 @@ +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/10f28f28922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/2f/10f28f28922b00151fa6e49f3e10bf0b deleted file mode 100644 index d531bbb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2f/10f28f28922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,32 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - PluginMain.Players.removeIf({ - public boolean test() - event.getPlayer().getName() - }); - } - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2f/60c08aa1ed2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/2f/60c08aa1ed2e001511a3ba75618c68e5 deleted file mode 100644 index 9308b28..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2f/60c08aa1ed2e001511a3ba75618c68e5 +++ /dev/null @@ -1,335 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2f/901fe416a72b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/2f/901fe416a72b00151fa6e49f3e10bf0b deleted file mode 100644 index 96a6182..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2f/901fe416a72b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,47 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2f/c09b39d5013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/2f/c09b39d5013e00151c31fb33fff4337f new file mode 100644 index 0000000..4b47b30 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/2f/c09b39d5013e00151c31fb33fff4337f @@ -0,0 +1,419 @@ +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/3/60b156f3ed2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/3/60b156f3ed2e001511a3ba75618c68e5 deleted file mode 100644 index 70fcc26..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3/60b156f3ed2e001511a3ba75618c68e5 +++ /dev/null @@ -1,337 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3/a0abcccdac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/3/a0abcccdac2b00151fa6e49f3e10bf0b deleted file mode 100644 index 4a26d75..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3/a0abcccdac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,265 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/30/60904025fd2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/30/60904025fd2e001511a3ba75618c68e5 deleted file mode 100644 index ccbc91e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/30/60904025fd2e001511a3ba75618c68e5 +++ /dev/null @@ -1,44 +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; - -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)); - PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); - System.out.println("Added player "+p.getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { - //List towns = TownyUniverse.getDataSource().getTowns(); - try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - } catch (NotRegisteredException e) { - return ""; - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/31/2034c778a42b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/31/2034c778a42b00151fa6e49f3e10bf0b deleted file mode 100644 index c068fb0..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/31/2034c778a42b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,41 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - PluginMain.IgnoredPlayers.add(player.getName()); - break; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/32/104e4dffa62b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/32/104e4dffa62b00151fa6e49f3e10bf0b deleted file mode 100644 index a6ddc4b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/32/104e4dffa62b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,45 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/32/306725aec52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/32/306725aec52e001511a3ba75618c68e5 deleted file mode 100644 index 925a0ad..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/32/306725aec52e001511a3ba75618c68e5 +++ /dev/null @@ -1,311 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - } - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/32/60416866f22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/32/60416866f22e001511a3ba75618c68e5 deleted file mode 100644 index 531359c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/32/60416866f22e001511a3ba75618c68e5 +++ /dev/null @@ -1,378 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/32/c036aae2063e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/32/c036aae2063e00151c31fb33fff4337f new file mode 100644 index 0000000..55ba7c3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/32/c036aae2063e00151c31fb33fff4337f @@ -0,0 +1,84 @@ +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. + if(!MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08. + //PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + 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. + String flair=MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName()).Flair; //2015.08.08. + if(flair==null) + flair=""; //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/32/e0bd8a0af82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/32/e0bd8a0af82e001511a3ba75618c68e5 deleted file mode 100644 index af92130..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/32/e0bd8a0af82e001511a3ba75618c68e5 +++ /dev/null @@ -1,108 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //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"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(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) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } - private static void DoReload() -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/33/307f3ebec52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/33/307f3ebec52e001511a3ba75618c68e5 deleted file mode 100644 index 88f4fdc..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/33/307f3ebec52e001511a3ba75618c68e5 +++ /dev/null @@ -1,312 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PlayerTowns.put(s[0], s[1]); - } - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/33/608c284a083e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/33/608c284a083e00151c31fb33fff4337f new file mode 100644 index 0000000..1cd84d0 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/33/608c284a083e00151c31fb33fff4337f @@ -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]) + { + 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); + } + 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 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"); + } + 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/33/90978488a42b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/33/90978488a42b00151fa6e49f3e10bf0b deleted file mode 100644 index 0eddca0..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/33/90978488a42b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,42 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - PluginMain.IgnoredPlayers.add(player.getName()); - break; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/33/b022d410ae2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/33/b022d410ae2b00151fa6e49f3e10bf0b deleted file mode 100644 index 991c247..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/33/b022d410ae2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,278 +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; - -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", "")); - } - br.close(); - } - file=new File("flairsignored.txt"); - if(file.exists()) - { - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - } - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/33/e0e8f0d9c42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/33/e0e8f0d9c42e001511a3ba75618c68e5 deleted file mode 100644 index eaca8b5..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/33/e0e8f0d9c42e001511a3ba75618c68e5 +++ /dev/null @@ -1,299 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/34/20530121c82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/34/20530121c82e001511a3ba75618c68e5 deleted file mode 100644 index 04da5b0..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/34/20530121c82e001511a3ba75618c68e5 +++ /dev/null @@ -1,323 +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.Towny; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - new Class(1, 2); - getPlugin()).getTownyInstance() - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/34/2066c3cdc82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/34/2066c3cdc82e001511a3ba75618c68e5 deleted file mode 100644 index 7f3bbf4..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/34/2066c3cdc82e001511a3ba75618c68e5 +++ /dev/null @@ -1,326 +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.List; -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.Towny; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - List towns = TownyUniverse.getDataSource().getTowns(); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/35/20ec61bbc52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/35/20ec61bbc52e001511a3ba75618c68e5 deleted file mode 100644 index 88f4fdc..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/35/20ec61bbc52e001511a3ba75618c68e5 +++ /dev/null @@ -1,312 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PlayerTowns.put(s[0], s[1]); - } - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/35/90f4067f922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/35/90f4067f922b00151fa6e49f3e10bf0b deleted file mode 100644 index 9b0e0e3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/35/90f4067f922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,16 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.util.function.Predicate; - -public class MyPredicate implements Predicate -{ - public MyPredicate() - { - - } - @Override - public boolean test(T arg0) { - return false; - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/35/a0d28e1ac92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/35/a0d28e1ac92e001511a3ba75618c68e5 deleted file mode 100644 index 5533282..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/35/a0d28e1ac92e001511a3ba75618c68e5 +++ /dev/null @@ -1,327 +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.List; -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.Towny; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { - //List towns = TownyUniverse.getDataSource().getTowns(); - WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/35/d0feddc3f12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/35/d0feddc3f12e001511a3ba75618c68e5 deleted file mode 100644 index 59cc8af..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/35/d0feddc3f12e001511a3ba75618c68e5 +++ /dev/null @@ -1,373 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - if(finalflair.length()>0) //<-- 2015.07.20. - { - System.out.println() - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/36/407f1825013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/36/407f1825013e00151c31fb33fff4337f new file mode 100644 index 0000000..d5af4e4 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/36/407f1825013e00151c31fb33fff4337f @@ -0,0 +1,124 @@ +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; + if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if(p.IgnoredFlair) + p.IgnoredFlair=false; + //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); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + 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"); + } + 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) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + 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/37/400d6ebfbf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/37/400d6ebfbf2e001511a3ba75618c68e5 deleted file mode 100644 index 2715e75..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/37/400d6ebfbf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,287 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/37/a0adde5a022b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/37/a0adde5a022b00151fa6e49f3e10bf0b deleted file mode 100644 index 4378554..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/37/a0adde5a022b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,11 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.4 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning -org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning -org.eclipse.jdt.core.compiler.source=1.3 diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/38/30ed4da8d12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/38/30ed4da8d12e001511a3ba75618c68e5 deleted file mode 100644 index 6cc0638..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/38/30ed4da8d12e001511a3ba75618c68e5 +++ /dev/null @@ -1,98 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); - 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. - if(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(); - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/38/601c14b2013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/38/601c14b2013e00151c31fb33fff4337f new file mode 100644 index 0000000..60f057b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/38/601c14b2013e00151c31fb33fff4337f @@ -0,0 +1,418 @@ +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/609a0a5fef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/38/609a0a5fef2e001511a3ba75618c68e5 deleted file mode 100644 index 61344f8..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/38/609a0a5fef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,343 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/39/10f83522922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/39/10f83522922b00151fa6e49f3e10bf0b deleted file mode 100644 index 3473cd2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/39/10f83522922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,32 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - PluginMain.Players.removeIf({ - public boolean - event.getPlayer().getName() - }); - } - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/39/60013fb6013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/39/60013fb6013e00151c31fb33fff4337f new file mode 100644 index 0000000..6eb0212 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/39/60013fb6013e00151c31fb33fff4337f @@ -0,0 +1,418 @@ +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/7076fe6ff92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/39/7076fe6ff92e001511a3ba75618c68e5 deleted file mode 100644 index 98fe805..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/39/7076fe6ff92e001511a3ba75618c68e5 +++ /dev/null @@ -1,389 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - ArrayList Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length)) //TODO - { - //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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/39/e0e3f38efd2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/39/e0e3f38efd2e001511a3ba75618c68e5 deleted file mode 100644 index 15b366e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/39/e0e3f38efd2e001511a3ba75618c68e5 +++ /dev/null @@ -1,47 +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; - -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 - p.sendRawMessage("§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to this thread."); - //System.out.println("Added player "+p.getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i 1) //2015.07.15. - flair = flairdata[1]; - else - flair=""; - if (flair != "-1") - flair = flair + "s"; - else - flair = "non-presser"; - String flairclass; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3a/300567b8d12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/3a/300567b8d12e001511a3ba75618c68e5 deleted file mode 100644 index 3b04630..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3a/300567b8d12e001511a3ba75618c68e5 +++ /dev/null @@ -1,334 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List towns = TownyUniverse.getDataSource().getTowns(); - try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - return town.getName(); - } catch (Exception e) { - return ""; - } - } - - public static void AppendPlayerDisplayFlairFinal(Player player, String flair) - { //2015.07.20. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3a/705720220d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/3a/705720220d3e00151089cca86c5b1a99 new file mode 100644 index 0000000..ad07236 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3a/705720220d3e00151089cca86c5b1a99 @@ -0,0 +1,433 @@ +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. + 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/3a/f0edd7def02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/3a/f0edd7def02e001511a3ba75618c68e5 deleted file mode 100644 index 4c78085..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3a/f0edd7def02e001511a3ba75618c68e5 +++ /dev/null @@ -1,360 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3b/d0078548033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/3b/d0078548033e00151c31fb33fff4337f new file mode 100644 index 0000000..e51b439 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3b/d0078548033e00151c31fb33fff4337f @@ -0,0 +1,78 @@ +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)); + if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + + 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/3b/e033e73b033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/3b/e033e73b033e00151c31fb33fff4337f new file mode 100644 index 0000000..0a39c6c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3b/e033e73b033e00151c31fb33fff4337f @@ -0,0 +1,77 @@ +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. + if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) + 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/3c/100230c7c72e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/3c/100230c7c72e001511a3ba75618c68e5 deleted file mode 100644 index 1153508..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3c/100230c7c72e001511a3ba75618c68e5 +++ /dev/null @@ -1,322 +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.Towny; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - Towny - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3c/508e5c2c053e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/3c/508e5c2c053e00151c31fb33fff4337f new file mode 100644 index 0000000..3c5dbca --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3c/508e5c2c053e00151c31fb33fff4337f @@ -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; + 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/3d/2034d8fed22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/3d/2034d8fed22e001511a3ba75618c68e5 deleted file mode 100644 index 9964f07..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3d/2034d8fed22e001511a3ba75618c68e5 +++ /dev/null @@ -1,105 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //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"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(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) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - PluginMain.AppendPlayerDisplayFlairFinal(p, PluginMain.PlayerFlairs.get(p.getName())); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3d/b0b429e1c52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/3d/b0b429e1c52e001511a3ba75618c68e5 deleted file mode 100644 index c61e3d0..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3d/b0b429e1c52e001511a3ba75618c68e5 +++ /dev/null @@ -1,312 +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; - -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", "")); - } - 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", "")); - } - br.close(); - } - File file=new File("autoflairconfig.txt"); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PlayerTowns.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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - try { - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3e/501e53c6c12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/3e/501e53c6c12e001511a3ba75618c68e5 deleted file mode 100644 index 99bad29..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3e/501e53c6c12e001511a3ba75618c68e5 +++ /dev/null @@ -1,294 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForClass(flairclass); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3e/d041c107f12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/3e/d041c107f12e001511a3ba75618c68e5 deleted file mode 100644 index f7c314c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3e/d041c107f12e001511a3ba75618c68e5 +++ /dev/null @@ -1,361 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3e/f09f99a6f12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/3e/f09f99a6f12e001511a3ba75618c68e5 deleted file mode 100644 index 44ffb2e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3e/f09f99a6f12e001511a3ba75618c68e5 +++ /dev/null @@ -1,369 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3f/10680ce29a2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/3f/10680ce29a2b00151fa6e49f3e10bf0b deleted file mode 100644 index 1468afb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3f/10680ce29a2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,37 +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; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - System.out.println("Added player "+event.getPlayer().getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - for(Player player : PluginMain.Players) - { - if(player.getName()==event.getPlayer().getName()) - { - PluginMain.Players.remove(player); - System.out.println("Removed player "+event.getPlayer().getName()); - } - } - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3f/5082b24efd3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/3f/5082b24efd3d00151c31fb33fff4337f new file mode 100644 index 0000000..cad1a26 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3f/5082b24efd3d00151c31fb33fff4337f @@ -0,0 +1,24 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer { + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static void AddPlayer(String playername) + { + if(!AllPlayers.containsKey(playername)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3f/70140e5a0c3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/3f/70140e5a0c3e00151089cca86c5b1a99 new file mode 100644 index 0000000..090b35d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3f/70140e5a0c3e00151089cca86c5b1a99 @@ -0,0 +1,432 @@ +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/3f/90d2ea4ac02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/3f/90d2ea4ac02e001511a3ba75618c68e5 deleted file mode 100644 index 27b8fb2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3f/90d2ea4ac02e001511a3ba75618c68e5 +++ /dev/null @@ -1,292 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3f/a049a4739b2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/3f/a049a4739b2b00151fa6e49f3e10bf0b deleted file mode 100644 index ffdc685..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3f/a049a4739b2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,41 +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; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - System.out.println("Added player "+event.getPlayer().getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/3f/d0bd9472043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/3f/d0bd9472043e00151c31fb33fff4337f new file mode 100644 index 0000000..87c0c13 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3f/d0bd9472043e00151c31fb33fff4337f @@ -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]) + { + 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); + } + 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 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"); + } + 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(p.Flair!=null) + { + String flair=p.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/3f/e0e98472053e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/3f/e0e98472053e00151c31fb33fff4337f new file mode 100644 index 0000000..98b7ab9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/3f/e0e98472053e00151c31fb33fff4337f @@ -0,0 +1,428 @@ +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/3f/f076feeff32e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/3f/f076feeff32e001511a3ba75618c68e5 deleted file mode 100644 index a29ee53..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/3f/f076feeff32e001511a3ba75618c68e5 +++ /dev/null @@ -1,382 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4/10509394922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/4/10509394922b00151fa6e49f3e10bf0b deleted file mode 100644 index a8ca2dd..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4/10509394922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,17 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.util.function.Predicate; - -public class MyPredicate implements Predicate -{ - private T First; - public MyPredicate(T first) - { - - } - @Override - public boolean test(T second) { - return false; - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4/108ef6e9912b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/4/108ef6e9912b00151fa6e49f3e10bf0b deleted file mode 100644 index c356b04..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4/108ef6e9912b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,28 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - PluginMain.Players.remove(event.getPlayer()); - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4/3024cc05d32e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/4/3024cc05d32e001511a3ba75618c68e5 deleted file mode 100644 index acb2c43..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4/3024cc05d32e001511a3ba75618c68e5 +++ /dev/null @@ -1,106 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //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"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(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) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - PluginMain.RemovePlayerDisplayFlairFinal(p, flair) - PluginMain.AppendPlayerDisplayFlairFinal(p, PluginMain.PlayerFlairs.get(p.getName())); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4/a0e0d29f9f2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/4/a0e0d29f9f2b00151fa6e49f3e10bf0b deleted file mode 100644 index c5d4b24..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4/a0e0d29f9f2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,43 +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; - -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)); - 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/4/d01b9292fc3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/4/d01b9292fc3d00151c31fb33fff4337f new file mode 100644 index 0000000..153d7e5 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/4/d01b9292fc3d00151c31fb33fff4337f @@ -0,0 +1,15 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer { + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/40/105c688c912b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/40/105c688c912b00151fa6e49f3e10bf0b deleted file mode 100644 index a7cb33e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/40/105c688c912b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,21 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerJoinEvent; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/40/607238ae0d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/40/607238ae0d3e00151089cca86c5b1a99 new file mode 100644 index 0000000..efac5c3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/40/607238ae0d3e00151089cca86c5b1a99 @@ -0,0 +1,434 @@ +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)"); + //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(); //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/40/60fa6e10f22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/40/60fa6e10f22e001511a3ba75618c68e5 deleted file mode 100644 index 040ad3c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/40/60fa6e10f22e001511a3ba75618c68e5 +++ /dev/null @@ -1,374 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - System.out.println("B"); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f1/e0e3f27f032f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/40/b05dfb50f93d00151c31fb33fff4337f similarity index 89% rename from .metadata/.plugins/org.eclipse.core.resources/.history/f1/e0e3f27f032f001511a3ba75618c68e5 rename to .metadata/.plugins/org.eclipse.core.resources/.history/40/b05dfb50f93d00151c31fb33fff4337f index edf98d5..674db06 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f1/e0e3f27f032f001511a3ba75618c68e5 +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/40/b05dfb50f93d00151c31fb33fff4337f @@ -17,7 +17,7 @@ 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. + if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); else { //2015.07.20. @@ -47,17 +47,14 @@ public class PlayerListener implements Listener @EventHandler public void onPlayerChat(AsyncPlayerChatEvent event) { - + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+"(test)> "+event.getMessage()); //2015.08.08. + event.setFormat(event.getFormat().substring(0, event.getFormat().indexOf(">"))+"(test)> "+event.getMessage()); //2015.08.08. } private static Class nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); - public static void sendRawMessage(Player player, String message) { - if (majorVersion < 1.8 || (majorVersion == 1.8 && lesserVersion == 1)) { - chatSerializerClazz = Reflection.getNMSClass("ChatSerializer"); - } else { - chatSerializerClazz = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); - } + public static void sendRawMessage(Player player, String message) + { try { System.out.println("1"); Object handle = Reflection.getHandle(player); diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/40/d04fb27d033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/40/d04fb27d033e00151c31fb33fff4337f new file mode 100644 index 0000000..dc9b8e8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/40/d04fb27d033e00151c31fb33fff4337f @@ -0,0 +1,81 @@ +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. + if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + //PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName())); + PluginMain.AppendPlayerDisplayFlair(player, p, 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. + 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/e0ff0e3eef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/40/e0ff0e3eef2e001511a3ba75618c68e5 deleted file mode 100644 index 9791b18..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/40/e0ff0e3eef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,342 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>();for(int i=str.length()-1; i>=0; i--) { - if(Character.isUpperCase(str.charAt(i))) { - return i; - } - } - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/41/1054ae18ae2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/41/1054ae18ae2b00151fa6e49f3e10bf0b deleted file mode 100644 index fa2aaa3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/41/1054ae18ae2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,278 +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; - -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", "")); - } - br.close(); - } - file=new File("flairsignored.txt"); - if(file.exists()) - { - BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - } - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/41/2061287bcf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/41/2061287bcf2e001511a3ba75618c68e5 deleted file mode 100644 index 819aa05..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/41/2061287bcf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,94 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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. - if(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(); - player.sendMessage("") - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/41/4092806fff3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/41/4092806fff3d00151c31fb33fff4337f new file mode 100644 index 0000000..cbfa0ee --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/41/4092806fff3d00151c31fb33fff4337f @@ -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(); + 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/41/50a33590fe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/41/50a33590fe3d00151c31fb33fff4337f new file mode 100644 index 0000000..e66301f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/41/50a33590fe3d00151c31fb33fff4337f @@ -0,0 +1,123 @@ +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; + if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + 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.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); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(PluginMain.AcceptedPlayers.contains(player.getName())) + PluginMain.AcceptedPlayers.remove(player.getName()); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + 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"); + } + 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) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + 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/42/2024a5f8922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/42/2024a5f8922b00151fa6e49f3e10bf0b deleted file mode 100644 index 42c83a9..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/42/2024a5f8922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,32 +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; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - for(Player player : PluginMain.Players) - { - - } - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/42/40b2c0ee063e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/42/40b2c0ee063e00151c31fb33fff4337f new file mode 100644 index 0000000..6528677 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/42/40b2c0ee063e00151c31fb33fff4337f @@ -0,0 +1,83 @@ +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. + if(!MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08. + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(mp.) + //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. + String flair=MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName()).Flair; //2015.08.08. + if(flair==null) + flair=""; //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/42/d0f315df033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/42/d0f315df033e00151c31fb33fff4337f new file mode 100644 index 0000000..2174d65 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/42/d0f315df033e00151c31fb33fff4337f @@ -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.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/42/e062ef3ef12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/42/e062ef3ef12e001511a3ba75618c68e5 deleted file mode 100644 index 35b1ef4..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/42/e062ef3ef12e001511a3ba75618c68e5 +++ /dev/null @@ -1,368 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/43/90fd3642a02b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/43/90fd3642a02b00151fa6e49f3e10bf0b deleted file mode 100644 index 117042d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/43/90fd3642a02b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,44 +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; - -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)); - - System.out.println("Added player "+p.getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i 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/40c13c85083e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/44/40c13c85083e00151c31fb33fff4337f new file mode 100644 index 0000000..913297a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/44/40c13c85083e00151c31fb33fff4337f @@ -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 + 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/44/60baddbded2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/44/60baddbded2e001511a3ba75618c68e5 deleted file mode 100644 index e85bce7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/44/60baddbded2e001511a3ba75618c68e5 +++ /dev/null @@ -1,336 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - color.split("§"); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/44/a0066f16c82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/44/a0066f16c82e001511a3ba75618c68e5 deleted file mode 100644 index 0b7f624..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/44/a0066f16c82e001511a3ba75618c68e5 +++ /dev/null @@ -1,323 +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.Towny; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - new Class(); - getPlugin()).getTownyInstance() - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/45/c091f870e42d0015105bf01c854e42e3 b/.metadata/.plugins/org.eclipse.core.resources/.history/45/c091f870e42d0015105bf01c854e42e3 deleted file mode 100644 index c02963d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/45/c091f870e42d0015105bf01c854e42e3 +++ /dev/null @@ -1,286 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/45/e004d2d0f82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/45/e004d2d0f82e001511a3ba75618c68e5 deleted file mode 100644 index 5d41449..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/45/e004d2d0f82e001511a3ba75618c68e5 +++ /dev/null @@ -1,385 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/46/20536196af2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/46/20536196af2b00151fa6e49f3e10bf0b deleted file mode 100644 index e14aa25..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/46/20536196af2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,279 +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; - -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", "")); - } - 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", "")); - } - 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() - { - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.close(); - for(String player : AcceptedPlayers) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/46/2068e749c72e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/46/2068e749c72e001511a3ba75618c68e5 deleted file mode 100644 index 0b5a48a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/46/2068e749c72e001511a3ba75618c68e5 +++ /dev/null @@ -1,314 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/46/206c822bc92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/46/206c822bc92e001511a3ba75618c68e5 deleted file mode 100644 index da014e9..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/46/206c822bc92e001511a3ba75618c68e5 +++ /dev/null @@ -1,332 +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.List; -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.Towny; -import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { - //List towns = TownyUniverse.getDataSource().getTowns(); - try { - WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - } catch (NotRegisteredException e) { - e.printStackTrace(); - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/46/a096e8f7ad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/46/a096e8f7ad2b00151fa6e49f3e10bf0b deleted file mode 100644 index e2d98d8..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/46/a096e8f7ad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,277 +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; - -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", "")); - } - br.close(); - } - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - 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(String player : IgnoredPlayers) - { - File file=new File("flairsignored.txt"); - if(file.exists()) - { - 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. - { - 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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/46/e0388548ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/46/e0388548ef2e001511a3ba75618c68e5 deleted file mode 100644 index af6ce5a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/46/e0388548ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,343 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=str.length()-1; i>=0; i--) { - if(Character.isUpperCase(str.charAt(i))) { - return i; - } - } - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/47/705caa25022f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/47/705caa25022f001511a3ba75618c68e5 deleted file mode 100644 index 8e8ee0b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/47/705caa25022f001511a3ba75618c68e5 +++ /dev/null @@ -1,68 +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("ChatSerializer"); - private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); - public static void sendRawMessage(Player player, String message) { - try { - System.out.prinln("1"); - Object handle = Reflection.getHandle(player); - Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); - Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); - Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); - Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); - } catch (Exception e) { - e.printStackTrace(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/47/8013b362f02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/47/8013b362f02e001511a3ba75618c68e5 deleted file mode 100644 index 74f40d7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/47/8013b362f02e001511a3ba75618c68e5 +++ /dev/null @@ -1,353 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/47/a0a57ff6bf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/47/a0a57ff6bf2e001511a3ba75618c68e5 deleted file mode 100644 index a5a14a8..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/47/a0a57ff6bf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,292 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //player.setDisplayName(player.getDisplayName()+flair); - AppendPlayerDisplayFlairFinal(player, flair); - 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. - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/48/00ffdb60ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/48/00ffdb60ef2e001511a3ba75618c68e5 deleted file mode 100644 index e75cd9b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/48/00ffdb60ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,343 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/48/201c7a82af2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/48/201c7a82af2b00151fa6e49f3e10bf0b deleted file mode 100644 index 952edc1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/48/201c7a82af2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,274 +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; - -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", "")); - } - 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", "")); - } - 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() - { - for(String player : AcceptedPlayers) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/48/d0589339033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/48/d0589339033e00151c31fb33fff4337f new file mode 100644 index 0000000..647cf3d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/48/d0589339033e00151c31fb33fff4337f @@ -0,0 +1,76 @@ +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/49/203ebd45a02b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/49/203ebd45a02b00151fa6e49f3e10bf0b deleted file mode 100644 index 6400ba7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/49/203ebd45a02b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,44 +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; - -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)); - PluginMain.AppendPlayerDisplayFlair(p, PluginMain.GetFlair(p)); - System.out.println("Added player "+p.getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.ini"); - try { - BufferedReader bw=new BufferedWriter(new FileWriter(file, true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/49/c0672b28053e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/49/c0672b28053e00151c31fb33fff4337f new file mode 100644 index 0000000..3c5dbca --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/49/c0672b28053e00151c31fb33fff4337f @@ -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; + 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/4a/20621c6bc72e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/4a/20621c6bc72e001511a3ba75618c68e5 deleted file mode 100644 index 1698679..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4a/20621c6bc72e001511a3ba75618c68e5 +++ /dev/null @@ -1,319 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4a/20820eeea32b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/4a/20820eeea32b00151fa6e49f3e10bf0b deleted file mode 100644 index f6c23d1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4a/20820eeea32b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,36 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - break; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4a/20f4346aad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/4a/20f4346aad2b00151fa6e49f3e10bf0b deleted file mode 100644 index 294da4a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4a/20f4346aad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,267 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - for(String player : IgnoredPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsignored.txt", true)); - bw.write(player+"\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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4a/30a94cffc42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/4a/30a94cffc42e001511a3ba75618c68e5 deleted file mode 100644 index b2818dd..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4a/30a94cffc42e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.ini"); - try { - BufferedReader bw=new BufferedReader(new FileReader(file); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4b/705083c4fa2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/4b/705083c4fa2e001511a3ba75618c68e5 deleted file mode 100644 index 76ca3b9..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4b/705083c4fa2e001511a3ba75618c68e5 +++ /dev/null @@ -1,393 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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..."); - Thread.currentThread().sleep(5000); - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4b/f0e8f6d8fa2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/4b/f0e8f6d8fa2e001511a3ba75618c68e5 deleted file mode 100644 index 2a3f96f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4b/f0e8f6d8fa2e001511a3ba75618c68e5 +++ /dev/null @@ -1,397 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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.currentThread().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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4c/20839fc6ac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/4c/20839fc6ac2b00151fa6e49f3e10bf0b deleted file mode 100644 index f1290c4..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4c/20839fc6ac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,262 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4c/60dfd6bffa2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/4c/60dfd6bffa2e001511a3ba75618c68e5 deleted file mode 100644 index bd869fe..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4c/60dfd6bffa2e001511a3ba75618c68e5 +++ /dev/null @@ -1,392 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - Thread.currentThread().sleep(5000); - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4c/90d951d1922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/4c/90d951d1922b00151fa6e49f3e10bf0b deleted file mode 100644 index 3465813..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4c/90d951d1922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,28 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - PluginMain.Players.removeIf(new MyPredicate(event.getPlayer().getName())) - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4c/b0f836d6c52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/4c/b0f836d6c52e001511a3ba75618c68e5 deleted file mode 100644 index ca9c279..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4c/b0f836d6c52e001511a3ba75618c68e5 +++ /dev/null @@ -1,312 +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; - -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", "")); - } - 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", "")); - } - br.close(); - } - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PlayerTowns.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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4d/20fbcf08ae2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/4d/20fbcf08ae2b00151fa6e49f3e10bf0b deleted file mode 100644 index 957fef4..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4d/20fbcf08ae2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,278 +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; - -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", "")); - } - br.close(); - } - file=new File("flairsignored.txt"); - if(file.exists()) - { - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - } - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4d/601ac327ee2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/4d/601ac327ee2e001511a3ba75618c68e5 deleted file mode 100644 index 4c2dd15..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4d/601ac327ee2e001511a3ba75618c68e5 +++ /dev/null @@ -1,338 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4d/9088f56f922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/4d/9088f56f922b00151fa6e49f3e10bf0b deleted file mode 100644 index 68c2345..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4d/9088f56f922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,12 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.util.function.Predicate; - -public class MyPredicate implements Predicate -{ - @Override - public boolean test(T arg0) { - return false; - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4d/908b4f17a72b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/4d/908b4f17a72b00151fa6e49f3e10bf0b deleted file mode 100644 index 96a6182..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4d/908b4f17a72b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,47 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4d/908e89caac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/4d/908e89caac2b00151fa6e49f3e10bf0b deleted file mode 100644 index 91b55dd..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4d/908e89caac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,262 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4e/a03b5be2ab2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/4e/a03b5be2ab2b00151fa6e49f3e10bf0b deleted file mode 100644 index d262e27..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4e/a03b5be2ab2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,263 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - 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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4e/e0d3ac3b0c3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/4e/e0d3ac3b0c3e00151089cca86c5b1a99 new file mode 100644 index 0000000..66ed2d6 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/4e/e0d3ac3b0c3e00151089cca86c5b1a99 @@ -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/4f/60f90ef1ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/4f/60f90ef1ef2e001511a3ba75618c68e5 deleted file mode 100644 index e736b23..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4f/60f90ef1ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,348 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - - } - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/4f/e0992796ee2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/4f/e0992796ee2e001511a3ba75618c68e5 deleted file mode 100644 index 3e7496c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/4f/e0992796ee2e001511a3ba75618c68e5 +++ /dev/null @@ -1,340 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - int x; - Positions.add(x) - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5/10e7f335902b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/5/10e7f335902b00151fa6e49f3e10bf0b deleted file mode 100644 index 5efa072..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5/10e7f335902b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,19 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; - -public class PlayerListener implements Listener -{ - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5/20f29cc9c12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/5/20f29cc9c12e001511a3ba75618c68e5 deleted file mode 100644 index 99bad29..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5/20f29cc9c12e001511a3ba75618c68e5 +++ /dev/null @@ -1,294 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForClass(flairclass); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5/c0df337dfd3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/5/c0df337dfd3d00151c31fb33fff4337f new file mode 100644 index 0000000..e7a09c9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5/c0df337dfd3d00151c31fb33fff4337f @@ -0,0 +1,27 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + 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/51/505dae0ff73d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/51/505dae0ff73d00151c31fb33fff4337f new file mode 100644 index 0000000..ced3ab5 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/51/505dae0ff73d00151c31fb33fff4337f @@ -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(); + 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/51/c0028e610a3e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/51/c0028e610a3e00151c31fb33fff4337f new file mode 100644 index 0000000..42c46c7 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/51/c0028e610a3e00151c31fb33fff4337f @@ -0,0 +1,432 @@ +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/51/c08e14f8c52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/51/c08e14f8c52e001511a3ba75618c68e5 deleted file mode 100644 index 1747200..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/51/c08e14f8c52e001511a3ba75618c68e5 +++ /dev/null @@ -1,311 +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; - -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", "")); - } - 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", "")); - } - 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(" "); - PlayerTowns.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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/52/e033be44f12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/52/e033be44f12e001511a3ba75618c68e5 deleted file mode 100644 index 3786f45..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/52/e033be44f12e001511a3ba75618c68e5 +++ /dev/null @@ -1,368 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/52/e07bf409f92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/52/e07bf409f92e001511a3ba75618c68e5 deleted file mode 100644 index 2f2755c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/52/e07bf409f92e001511a3ba75618c68e5 +++ /dev/null @@ -1,385 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - ArrayList Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length)) //TODO - { - //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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/52/e098cc7eee2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/52/e098cc7eee2e001511a3ba75618c68e5 deleted file mode 100644 index 6c85bd0..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/52/e098cc7eee2e001511a3ba75618c68e5 +++ /dev/null @@ -1,338 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/53/2088f35ac62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/53/2088f35ac62e001511a3ba75618c68e5 deleted file mode 100644 index 6ba35d2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/53/2088f35ac62e001511a3ba75618c68e5 +++ /dev/null @@ -1,314 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/53/60a94d43f02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/53/60a94d43f02e001511a3ba75618c68e5 deleted file mode 100644 index eada3e3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/53/60a94d43f02e001511a3ba75618c68e5 +++ /dev/null @@ -1,352 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - int x=0; - for(int pos : Positions) - { - - } - } - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/53/a0405c98f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/53/a0405c98f63d00151c31fb33fff4337f new file mode 100644 index 0000000..2ef29ec --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/53/a0405c98f63d00151c31fb33fff4337f @@ -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(); + 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/e0c3c4b6f22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/53/e0c3c4b6f22e001511a3ba75618c68e5 deleted file mode 100644 index f56e706..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/53/e0c3c4b6f22e001511a3ba75618c68e5 +++ /dev/null @@ -1,378 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/53/e0e025b8fa2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/53/e0e025b8fa2e001511a3ba75618c68e5 deleted file mode 100644 index 4ce38cd..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/53/e0e025b8fa2e001511a3ba75618c68e5 +++ /dev/null @@ -1,391 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/54/603c9698f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/54/603c9698f63d00151c31fb33fff4337f new file mode 100644 index 0000000..2ef29ec --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/54/603c9698f63d00151c31fb33fff4337f @@ -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(); + 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/54/a08c9aaec42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/54/a08c9aaec42e001511a3ba75618c68e5 deleted file mode 100644 index 33f4ba4..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/54/a08c9aaec42e001511a3ba75618c68e5 +++ /dev/null @@ -1,294 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/55/108abd59cf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/55/108abd59cf2e001511a3ba75618c68e5 deleted file mode 100644 index 771250c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/55/108abd59cf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,92 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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": - if(player.isOp()) - { - try - { - File 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(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/55/e0f6a187073e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/55/e0f6a187073e00151c31fb33fff4337f new file mode 100644 index 0000000..36a0cb6 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/55/e0f6a187073e00151c31fb33fff4337f @@ -0,0 +1,430 @@ +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/600fc5d9ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/56/600fc5d9ef2e001511a3ba75618c68e5 deleted file mode 100644 index cbee395..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/56/600fc5d9ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,347 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - - } - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/57/c08f160bae2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/57/c08f160bae2b00151fa6e49f3e10bf0b deleted file mode 100644 index bc3f19b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/57/c08f160bae2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,278 +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; - -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", "")); - } - br.close(); - } - file=new File("flairsignored.txt"); - if(file.exists()) - { - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - } - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/58/209579d6922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/58/209579d6922b00151fa6e49f3e10bf0b deleted file mode 100644 index 97da094..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/58/209579d6922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,17 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.util.function.Predicate; - -public class MyPredicate implements Predicate -{ - private T First; - public MyPredicate(T first) - { - First=first; - } - @Override - public boolean test(T second) { - return First.equals(second); - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/58/306a8bbfc82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/58/306a8bbfc82e001511a3ba75618c68e5 deleted file mode 100644 index c7bce3d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/58/306a8bbfc82e001511a3ba75618c68e5 +++ /dev/null @@ -1,326 +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.List; -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.Towny; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - List towns = TownyUniverse.getDataSource().getTowns(); - getPlugin()).getTownyInstance() - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/58/60ed80d2f82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/58/60ed80d2f82e001511a3ba75618c68e5 deleted file mode 100644 index 0f71b25..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/58/60ed80d2f82e001511a3ba75618c68e5 +++ /dev/null @@ -1,385 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5a/807ce202f92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/5a/807ce202f92e001511a3ba75618c68e5 deleted file mode 100644 index 48bef66..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5a/807ce202f92e001511a3ba75618c68e5 +++ /dev/null @@ -1,385 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - ArrayList Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length)) //TODO - { - //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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5a/f0233823022f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/5a/f0233823022f001511a3ba75618c68e5 deleted file mode 100644 index acbe1ae..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5a/f0233823022f001511a3ba75618c68e5 +++ /dev/null @@ -1,68 +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("ChatSerializer"); - private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); - public static void sendRawMessage(Player player, String message) { - try { - System.out.prinln - Object handle = Reflection.getHandle(player); - Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); - Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); - Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); - Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); - } catch (Exception e) { - e.printStackTrace(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5b/20a3e001a72b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/5b/20a3e001a72b00151fa6e49f3e10bf0b deleted file mode 100644 index 9f645a0..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5b/20a3e001a72b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,46 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - player.sendMessage("§6Your flair has been set."); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5b/c04677b1c42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/5b/c04677b1c42e001511a3ba75618c68e5 deleted file mode 100644 index 5eb70f1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5b/c04677b1c42e001511a3ba75618c68e5 +++ /dev/null @@ -1,294 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5b/e0bdb4c2ed2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/5b/e0bdb4c2ed2e001511a3ba75618c68e5 deleted file mode 100644 index e85bce7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5b/e0bdb4c2ed2e001511a3ba75618c68e5 +++ /dev/null @@ -1,336 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - color.split("§"); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5b/e0c3bfdabf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/5b/e0c3bfdabf2e001511a3ba75618c68e5 deleted file mode 100644 index dab2673..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5b/e0c3bfdabf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,288 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - } - - public -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5c/20130c91c92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/5c/20130c91c92e001511a3ba75618c68e5 deleted file mode 100644 index 5aaf0eb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5c/20130c91c92e001511a3ba75618c68e5 +++ /dev/null @@ -1,333 +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.List; -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.Towny; -import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List towns = TownyUniverse.getDataSource().getTowns(); - try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - return town.getName(); - } catch (NotRegisteredException e) { - return ""; - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5c/501d5bcfed2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/5c/501d5bcfed2e001511a3ba75618c68e5 deleted file mode 100644 index 9308b28..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5c/501d5bcfed2e001511a3ba75618c68e5 +++ /dev/null @@ -1,335 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5d/e022cf5fef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/5d/e022cf5fef2e001511a3ba75618c68e5 deleted file mode 100644 index e75cd9b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5d/e022cf5fef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,343 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5d/f02ee61e022f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/5d/f02ee61e022f001511a3ba75618c68e5 deleted file mode 100644 index 75d84da..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/5d/f02ee61e022f001511a3ba75618c68e5 +++ /dev/null @@ -1,68 +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("ChatSerializer"); - private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); - public static void sendRawMessage(Player player, String message) { - try { - System.out.println() - Object handle = Reflection.getHandle(player); - Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); - Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); - Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); - Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); - } catch (Exception e) { - e.printStackTrace(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/83/60141ae3042f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/5e/001a5b7d013e00151c31fb33fff4337f similarity index 87% rename from .metadata/.plugins/org.eclipse.core.resources/.history/83/60141ae3042f001511a3ba75618c68e5 rename to .metadata/.plugins/org.eclipse.core.resources/.history/5e/001a5b7d013e00151c31fb33fff4337f index 7e04469..4b9f9aa 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/83/60141ae3042f001511a3ba75618c68e5 +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5e/001a5b7d013e00151c31fb33fff4337f @@ -53,7 +53,9 @@ public class PluginMain extends JavaPlugin String line; while ((line = br.readLine()) != null) { - AcceptedPlayers.add(line.replace("\n", "")); + //AcceptedPlayers.add(line.replace("\n", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. } br.close(); } @@ -64,7 +66,9 @@ public class PluginMain extends JavaPlugin String line; while ((line = br.readLine()) != null) { - IgnoredPlayers.add(line.replace("\n", "")); + //IgnoredPlayers.add(line.replace("\n", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. } br.close(); } @@ -105,8 +109,11 @@ public class PluginMain extends JavaPlugin { System.out.println("Error!\n"+e); } - for(String player : AcceptedPlayers) + //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)); @@ -116,8 +123,10 @@ public class PluginMain extends JavaPlugin System.out.println("Error!\n"+e); } } - for(String player : IgnoredPlayers) + 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)); @@ -207,13 +216,13 @@ public class PluginMain extends JavaPlugin } //It has to store offline player flairs too, therefore it can't use Player object - public static Map PlayerFlairs=new HashMap(); + /*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 PlayerTowns=new HashMap(); //2015.07.20.*/ public static Map TownColors=new HashMap(); //2015.07.20. public Boolean HasIGFlair(String playername) { @@ -228,7 +237,8 @@ public class PluginMain extends JavaPlugin } if(player==null) return false;*/ - return PlayerFlairs.containsKey(playername); + //return PlayerFlairs.containsKey(playername); + return MaybeOfflinePlayer.AllPlayers.containsKey(playername); } public void SetFlair(String playername, String text, String flairclass, String username) @@ -260,6 +270,9 @@ public class PluginMain extends JavaPlugin case "cheater": finalflair="§5("+text+")§r"; break; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; default: finalflair=""; break; @@ -301,9 +314,11 @@ public class PluginMain extends JavaPlugin public static void AppendPlayerDisplayFlair(Player player, String username, String flair) { - if(IgnoredPlayers.contains(player.getName())) + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) return; - if(AcceptedPlayers.contains(player.getName())) + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) //player.setDisplayName(player.getDisplayName()+flair); AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. else @@ -314,10 +329,9 @@ public class PluginMain extends JavaPlugin { //2015.07.20. //System.out.println("A"); String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters - if(color!="") - { String[] colors = color.substring(1).split("§"); - String displayname=player.getDisplayName(); + //String displayname=player.getDisplayName(); + String displayname=player.getName(); //2015.08.08. ArrayList Positions=new ArrayList<>(); //System.out.println("B"); for(int i=0; i 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - Towny.getPlugin(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/5f/60d7f94a0e3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/5f/60d7f94a0e3e00151089cca86c5b1a99 new file mode 100644 index 0000000..efac5c3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5f/60d7f94a0e3e00151089cca86c5b1a99 @@ -0,0 +1,434 @@ +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)"); + //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(); //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/5f/c0841a72043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/5f/c0841a72043e00151c31fb33fff4337f new file mode 100644 index 0000000..87c0c13 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5f/c0841a72043e00151c31fb33fff4337f @@ -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]) + { + 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); + } + 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 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"); + } + 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(p.Flair!=null) + { + String flair=p.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/5f/d050dc2e043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/5f/d050dc2e043e00151c31fb33fff4337f new file mode 100644 index 0000000..e62cdc8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5f/d050dc2e043e00151c31fb33fff4337f @@ -0,0 +1,427 @@ +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 new file mode 100644 index 0000000..5edf504 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/5f/d05109b3013e00151c31fb33fff4337f @@ -0,0 +1,418 @@ +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/6/30c2f2eec52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/6/30c2f2eec52e001511a3ba75618c68e5 deleted file mode 100644 index 6d85d43..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6/30c2f2eec52e001511a3ba75618c68e5 +++ /dev/null @@ -1,315 +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; - -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", "")); - } - 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", "")); - } - 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(" "); - PlayerTowns.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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - try { - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6/e0073580012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/6/e0073580012f001511a3ba75618c68e5 deleted file mode 100644 index 3b1ae41..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6/e0073580012f001511a3ba75618c68e5 +++ /dev/null @@ -1,67 +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 - { - 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\"}]}}}]"; - - } - //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("ChatSerializer"); - private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); - public static void sendRawMessage(Player player, String message) { - try { - Object handle = Reflection.getHandle(player); - Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); - Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); - Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); - Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); - } catch (Exception e) { - e.printStackTrace(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2/3097a03f012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/60/009554caf93d00151c31fb33fff4337f similarity index 100% rename from .metadata/.plugins/org.eclipse.core.resources/.history/2/3097a03f012f001511a3ba75618c68e5 rename to .metadata/.plugins/org.eclipse.core.resources/.history/60/009554caf93d00151c31fb33fff4337f diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/60/607ba075fd3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/60/607ba075fd3d00151c31fb33fff4337f new file mode 100644 index 0000000..989d005 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/60/607ba075fd3d00151c31fb33fff4337f @@ -0,0 +1,26 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + 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; + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/60/90821217a72b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/60/90821217a72b00151fa6e49f3e10bf0b deleted file mode 100644 index 96a6182..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/60/90821217a72b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,47 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/61/208a799fac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/61/208a799fac2b00151fa6e49f3e10bf0b deleted file mode 100644 index cb194ad..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/61/208a799fac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,260 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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 { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - PluginMain.IgnoredPlayers.add(player.getName()); - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/62/502ee671043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/62/502ee671043e00151c31fb33fff4337f new file mode 100644 index 0000000..87c0c13 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/62/502ee671043e00151c31fb33fff4337f @@ -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]) + { + 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); + } + 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 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"); + } + 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(p.Flair!=null) + { + String flair=p.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/62/60642c63ff2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/62/60642c63ff2e001511a3ba75618c68e5 deleted file mode 100644 index 17fc5c8..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/62/60642c63ff2e001511a3ba75618c68e5 +++ /dev/null @@ -1,49 +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; - -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 - { - 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\"}]}}}]"; - } - //System.out.println("Added player "+p.getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List towns = TownyUniverse.getDataSource().getTowns(); - try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - return town.getName(); - } catch (NotRegisteredException e) { - return ""; - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/63/70033eb0c42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/63/70033eb0c42e001511a3ba75618c68e5 deleted file mode 100644 index 5eb70f1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/63/70033eb0c42e001511a3ba75618c68e5 +++ /dev/null @@ -1,294 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/63/a0335f19c62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/63/a0335f19c62e001511a3ba75618c68e5 deleted file mode 100644 index a36a552..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/63/a0335f19c62e001511a3ba75618c68e5 +++ /dev/null @@ -1,313 +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; - -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", "")); - } - 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", "")); - } - 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(" "); - PlayerTowns.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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 PlayerTowns=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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - if() - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/2a/10f997ed052f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/64/60ee528d013e00151c31fb33fff4337f similarity index 87% rename from .metadata/.plugins/org.eclipse.core.resources/.history/2a/10f997ed052f001511a3ba75618c68e5 rename to .metadata/.plugins/org.eclipse.core.resources/.history/64/60ee528d013e00151c31fb33fff4337f index c5f649b..4b9f9aa 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/2a/10f997ed052f001511a3ba75618c68e5 +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/64/60ee528d013e00151c31fb33fff4337f @@ -53,7 +53,9 @@ public class PluginMain extends JavaPlugin String line; while ((line = br.readLine()) != null) { - AcceptedPlayers.add(line.replace("\n", "")); + //AcceptedPlayers.add(line.replace("\n", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. } br.close(); } @@ -64,7 +66,9 @@ public class PluginMain extends JavaPlugin String line; while ((line = br.readLine()) != null) { - IgnoredPlayers.add(line.replace("\n", "")); + //IgnoredPlayers.add(line.replace("\n", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. } br.close(); } @@ -105,8 +109,11 @@ public class PluginMain extends JavaPlugin { System.out.println("Error!\n"+e); } - for(String player : AcceptedPlayers) + //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)); @@ -116,8 +123,10 @@ public class PluginMain extends JavaPlugin System.out.println("Error!\n"+e); } } - for(String player : IgnoredPlayers) + 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)); @@ -207,13 +216,13 @@ public class PluginMain extends JavaPlugin } //It has to store offline player flairs too, therefore it can't use Player object - public static Map PlayerFlairs=new HashMap(); + /*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 PlayerTowns=new HashMap(); //2015.07.20.*/ public static Map TownColors=new HashMap(); //2015.07.20. public Boolean HasIGFlair(String playername) { @@ -228,7 +237,8 @@ public class PluginMain extends JavaPlugin } if(player==null) return false;*/ - return PlayerFlairs.containsKey(playername); + //return PlayerFlairs.containsKey(playername); + return MaybeOfflinePlayer.AllPlayers.containsKey(playername); } public void SetFlair(String playername, String text, String flairclass, String username) @@ -260,6 +270,9 @@ public class PluginMain extends JavaPlugin case "cheater": finalflair="§5("+text+")§r"; break; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; default: finalflair=""; break; @@ -301,9 +314,11 @@ public class PluginMain extends JavaPlugin public static void AppendPlayerDisplayFlair(Player player, String username, String flair) { - if(IgnoredPlayers.contains(player.getName())) + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) return; - if(AcceptedPlayers.contains(player.getName())) + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) //player.setDisplayName(player.getDisplayName()+flair); AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. else @@ -315,7 +330,8 @@ public class PluginMain extends JavaPlugin //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.getDisplayName(); + String displayname=player.getName(); //2015.08.08. ArrayList Positions=new ArrayList<>(); //System.out.println("B"); for(int i=0; i 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - ArrayList Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length)) //TODO - { - //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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/65/10f38b46902b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/65/10f38b46902b00151fa6e49f3e10bf0b deleted file mode 100644 index c9898ce..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/65/10f38b46902b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,21 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerJoinEvent; - -public class PlayerListener implements Listener -{ - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/65/208daefe922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/65/208daefe922b00151fa6e49f3e10bf0b deleted file mode 100644 index ae466d0..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/65/208daefe922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,32 +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; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - for(Player player : PluginMain.Players) - { - if(player.getName()==event.getPlayer().getName()) - } - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/65/90b2d49d922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/65/90b2d49d922b00151fa6e49f3e10bf0b deleted file mode 100644 index 84fb851..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/65/90b2d49d922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,34 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - PluginMain.Players.removeIf({ - public boolean test(T var) - { - return var==event.getPlayer().getName(); - } - }); - } - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/65/a0018c88c52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/65/a0018c88c52e001511a3ba75618c68e5 deleted file mode 100644 index d656c74..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/65/a0018c88c52e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String[] line=br.readLine().split(" "); - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/65/c05049b70e2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/65/c05049b70e2b00151fa6e49f3e10bf0b deleted file mode 100644 index 416f4fb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/65/c05049b70e2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,11 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.5 diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/66/20dd83e3ab2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/66/20dd83e3ab2b00151fa6e49f3e10bf0b deleted file mode 100644 index 6828280..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/66/20dd83e3ab2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,261 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - 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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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); - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/66/40244c64fd3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/66/40244c64fd3d00151c31fb33fff4337f new file mode 100644 index 0000000..3278b5c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/66/40244c64fd3d00151c31fb33fff4337f @@ -0,0 +1,25 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static MaybeOfflinePlayer AddPlayer(String playername) + { + if(!AllPlayers.containsKey(playername)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/67/602639aefe2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/67/602639aefe2e001511a3ba75618c68e5 deleted file mode 100644 index e6f7c88..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/67/602639aefe2e001511a3ba75618c68e5 +++ /dev/null @@ -1,47 +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; - -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 - p.sendRawMessage("["",{"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"}]}}}]"); - //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("ChatSerializer"); - Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); - if (majorVersion < 1.8 || (majorVersion == 1.8 && lesserVersion == 1)) { - chatSerializerClazz = Reflection.getNMSClass("ChatSerializer"); - } else { - chatSerializerClazz = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); - } - 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/67/b0a2021dd22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/67/b0a2021dd22e001511a3ba75618c68e5 deleted file mode 100644 index 0f1ce1b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/67/b0a2021dd22e001511a3ba75618c68e5 +++ /dev/null @@ -1,334 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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)); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/67/f0473bebf93d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/67/f0473bebf93d00151c31fb33fff4337f new file mode 100644 index 0000000..eed0fb5 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/67/f0473bebf93d00151c31fb33fff4337f @@ -0,0 +1,6 @@ +package tk.sznp.thebuttonautoflair; + +public class MaybeOfflinePlayer { + String PlayerName; + String UserName; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/69/a0742e97c42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/69/a0742e97c42e001511a3ba75618c68e5 deleted file mode 100644 index 26cb915..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/69/a0742e97c42e001511a3ba75618c68e5 +++ /dev/null @@ -1,294 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForClass(flairclass); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/69/a09f55a6d12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/69/a09f55a6d12e001511a3ba75618c68e5 deleted file mode 100644 index 9bae755..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/69/a09f55a6d12e001511a3ba75618c68e5 +++ /dev/null @@ -1,98 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - - 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. - if(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(); - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6a/a041c51ecf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/6a/a041c51ecf2e001511a3ba75618c68e5 deleted file mode 100644 index 3cfa3e2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6a/a041c51ecf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,64 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6a/a0a9b7c0d22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/6a/a0a9b7c0d22e001511a3ba75618c68e5 deleted file mode 100644 index 0f3bc9d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6a/a0a9b7c0d22e001511a3ba75618c68e5 +++ /dev/null @@ -1,101 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //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"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(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) - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - PluginMain.PlayerFlairs.get(p.getName()) - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6b/501ffbd8fb3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/6b/501ffbd8fb3d00151c31fb33fff4337f new file mode 100644 index 0000000..9e3f840 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6b/501ffbd8fb3d00151c31fb33fff4337f @@ -0,0 +1,14 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; + +public class MaybeOfflinePlayer { + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static ArrayList AllPlayers=new ArrayList<>(); //2015.08.08. +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6b/9087a916a72b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/6b/9087a916a72b00151fa6e49f3e10bf0b deleted file mode 100644 index 96a6182..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6b/9087a916a72b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,47 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ff/e0d13c89032f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/6b/d0f9527cf63d00151c31fb33fff4337f similarity index 95% rename from .metadata/.plugins/org.eclipse.core.resources/.history/ff/e0d13c89032f001511a3ba75618c68e5 rename to .metadata/.plugins/org.eclipse.core.resources/.history/6b/d0f9527cf63d00151c31fb33fff4337f index dea68be..65c80c5 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ff/e0d13c89032f001511a3ba75618c68e5 +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6b/d0f9527cf63d00151c31fb33fff4337f @@ -17,7 +17,7 @@ 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. + if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); else { //2015.07.20. @@ -47,12 +47,13 @@ public class PlayerListener implements Listener @EventHandler public void onPlayerChat(AsyncPlayerChatEvent event) { - + event.setFormat(event.getFormat()+"(test)"); } private static Class nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); - public static void sendRawMessage(Player player, String message) {} + public static void sendRawMessage(Player player, String message) + { try { System.out.println("1"); Object handle = Reflection.getHandle(player); diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6c/20839ed9c42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/6c/20839ed9c42e001511a3ba75618c68e5 deleted file mode 100644 index eaca8b5..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6c/20839ed9c42e001511a3ba75618c68e5 +++ /dev/null @@ -1,299 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6c/a046c61ba72b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/6c/a046c61ba72b00151fa6e49f3e10bf0b deleted file mode 100644 index 96a6182..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6c/a046c61ba72b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,47 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6c/b0c9b7a0d12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/6c/b0c9b7a0d12e001511a3ba75618c68e5 deleted file mode 100644 index 2430204..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6c/b0c9b7a0d12e001511a3ba75618c68e5 +++ /dev/null @@ -1,97 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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. - if(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(); - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6c/e07524e9f93d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/6c/e07524e9f93d00151c31fb33fff4337f new file mode 100644 index 0000000..c2c0b73 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6c/e07524e9f93d00151c31fb33fff4337f @@ -0,0 +1,6 @@ +package tk.sznp.thebuttonautoflair; + +public class MaybeOfflinePlayer { + String PlayerName; + String +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6d/20da2322c82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/6d/20da2322c82e001511a3ba75618c68e5 deleted file mode 100644 index a2d13aa..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6d/20da2322c82e001511a3ba75618c68e5 +++ /dev/null @@ -1,323 +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.Towny; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - new Class(1); - getPlugin()).getTownyInstance() - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6d/a06ed898a42b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/6d/a06ed898a42b00151fa6e49f3e10bf0b deleted file mode 100644 index b0caf66..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6d/a06ed898a42b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,45 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6e/30f5a3bca82b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/6e/30f5a3bca82b00151fa6e49f3e10bf0b deleted file mode 100644 index dc99e3c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6e/30f5a3bca82b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,48 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6e/70483370012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/6e/70483370012f001511a3ba75618c68e5 deleted file mode 100644 index 61f45e9..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6e/70483370012f001511a3ba75618c68e5 +++ /dev/null @@ -1,65 +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 - { - 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\"}]}}}]"; - p.sendTitle(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/e0ff0a20022f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/6e/e0ff0a20022f001511a3ba75618c68e5 deleted file mode 100644 index f754c67..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6e/e0ff0a20022f001511a3ba75618c68e5 +++ /dev/null @@ -1,68 +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("ChatSerializer"); - private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); - public static void sendRawMessage(Player player, String message) { - try { - System.out.prin - Object handle = Reflection.getHandle(player); - Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); - Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); - Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); - Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); - } catch (Exception e) { - e.printStackTrace(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6f/40d1681c083e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/6f/40d1681c083e00151c31fb33fff4337f new file mode 100644 index 0000000..b9b01d7 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6f/40d1681c083e00151c31fb33fff4337f @@ -0,0 +1,83 @@ +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. + 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\"}]}}}]"; + 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 flair=MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName()).Flair; //2015.08.08. + if(flair==null) + flair=""; //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/bc/e06e426ff82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/6f/50a07067fe3d00151c31fb33fff4337f similarity index 87% rename from .metadata/.plugins/org.eclipse.core.resources/.history/bc/e06e426ff82e001511a3ba75618c68e5 rename to .metadata/.plugins/org.eclipse.core.resources/.history/6f/50a07067fe3d00151c31fb33fff4337f index 4f472d3..3afc0be 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/bc/e06e426ff82e001511a3ba75618c68e5 +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6f/50a07067fe3d00151c31fb33fff4337f @@ -28,12 +28,16 @@ public class Commands implements CommandExecutor { { if(PluginMain.IgnoredPlayers.contains(player.getName())) PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) { - String flair=PluginMain.PlayerFlairs.get(player.getName()); + //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()); + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; player.sendMessage("§6Your flair has been set:§r "+flair); } else @@ -107,7 +111,8 @@ public class Commands implements CommandExecutor { catch(Exception e) { System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); } } else diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6f/7051f7cef82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/6f/7051f7cef82e001511a3ba75618c68e5 deleted file mode 100644 index 72effcc..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6f/7051f7cef82e001511a3ba75618c68e5 +++ /dev/null @@ -1,385 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/88/807be056922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/6f/d08b30cdf93d00151c31fb33fff4337f similarity index 54% rename from .metadata/.plugins/org.eclipse.core.resources/.history/88/807be056922b00151fa6e49f3e10bf0b rename to .metadata/.plugins/org.eclipse.core.resources/.history/6f/d08b30cdf93d00151c31fb33fff4337f index 3712479..b36faea 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/88/807be056922b00151fa6e49f3e10bf0b +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/6f/d08b30cdf93d00151c31fb33fff4337f @@ -1,5 +1,5 @@ package tk.sznp.thebuttonautoflair; -public class MyPredicate { +public class MaybeOfflinePlayer { } diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6f/e0adbb55f02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/6f/e0adbb55f02e001511a3ba75618c68e5 deleted file mode 100644 index eada3e3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6f/e0adbb55f02e001511a3ba75618c68e5 +++ /dev/null @@ -1,352 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - int x=0; - for(int pos : Positions) - { - - } - } - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7/20e4b24fcf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7/20e4b24fcf2e001511a3ba75618c68e5 deleted file mode 100644 index fae6f98..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7/20e4b24fcf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,85 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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": - if(player.isOp()) - { - File 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(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7/30377337c92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7/30377337c92e001511a3ba75618c68e5 deleted file mode 100644 index 1f98b63..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7/30377337c92e001511a3ba75618c68e5 +++ /dev/null @@ -1,332 +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.List; -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.Towny; -import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { - //List towns = TownyUniverse.getDataSource().getTowns(); - try { - WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - } catch (NotRegisteredException e) { - return ""; - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7/90461043a02b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/7/90461043a02b00151fa6e49f3e10bf0b deleted file mode 100644 index 6400ba7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7/90461043a02b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,44 +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; - -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)); - PluginMain.AppendPlayerDisplayFlair(p, PluginMain.GetFlair(p)); - System.out.println("Added player "+p.getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.ini"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - br.readLine(); - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/70/1027fc0ba92b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/70/1027fc0ba92b00151fa6e49f3e10bf0b deleted file mode 100644 index bb87baa..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/70/1027fc0ba92b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,54 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - break; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/70/200aa244a02b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/70/200aa244a02b00151fa6e49f3e10bf0b deleted file mode 100644 index 6400ba7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/70/200aa244a02b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,44 +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; - -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)); - PluginMain.AppendPlayerDisplayFlair(p, PluginMain.GetFlair(p)); - System.out.println("Added player "+p.getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i 1) //2015.07.15. - flair = flairdata[1]; - else - flair=""; - if (flair != "-1") - flair = flair + "s"; - else - flair = "non-presser"; - String flairclass; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/71/c0147a73043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/71/c0147a73043e00151c31fb33fff4337f new file mode 100644 index 0000000..87c0c13 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/71/c0147a73043e00151c31fb33fff4337f @@ -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]) + { + 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); + } + 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 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"); + } + 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(p.Flair!=null) + { + String flair=p.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/71/f01d3f77023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/71/f01d3f77023e00151c31fb33fff4337f new file mode 100644 index 0000000..ff19301 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/71/f01d3f77023e00151c31fb33fff4337f @@ -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.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/601fd2f0013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/72/601fd2f0013e00151c31fb33fff4337f new file mode 100644 index 0000000..0f9b45b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/72/601fd2f0013e00151c31fb33fff4337f @@ -0,0 +1,124 @@ +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; + if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); //2015.08.08. + /*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); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + 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"); + } + 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) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + 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/73/2024f08eac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/73/2024f08eac2b00151fa6e49f3e10bf0b deleted file mode 100644 index 35f3f9e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/73/2024f08eac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,81 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedWriter; -import java.io.FileWriter; -import java.io.IOException; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/73/40821671043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/73/40821671043e00151c31fb33fff4337f new file mode 100644 index 0000000..87c0c13 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/73/40821671043e00151c31fb33fff4337f @@ -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]) + { + 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); + } + 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 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"); + } + 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(p.Flair!=null) + { + String flair=p.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/73/90090df6912b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/73/90090df6912b00151fa6e49f3e10bf0b deleted file mode 100644 index 01dd5bb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/73/90090df6912b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,28 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - PluginMain.Players.removeIf(event.getPlayer().getName()); - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/73/e0bd2a55032f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/73/e0bd2a55032f001511a3ba75618c68e5 deleted file mode 100644 index 826a700..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/73/e0bd2a55032f001511a3ba75618c68e5 +++ /dev/null @@ -1,78 +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("ChatSerializer"); - private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); - public static void sendRawMessage(Player player, String message) { - if (majorVersion < 1.8 || (majorVersion == 1.8 && lesserVersion == 1)) { - chatSerializerClazz = Reflection.getNMSClass("ChatSerializer"); - } else { - chatSerializerClazz = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); - } - 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/20c870fec42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/74/20c870fec42e001511a3ba75618c68e5 deleted file mode 100644 index 2382e2c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/74/20c870fec42e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.ini"); - try { - BufferedReader bw=new BufferedReader(new FileReader(file, true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/74/30231013d32e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/74/30231013d32e001511a3ba75618c68e5 deleted file mode 100644 index ca7e83d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/74/30231013d32e001511a3ba75618c68e5 +++ /dev/null @@ -1,335 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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(flair), dname.indexOf(flair))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/74/b044220ec52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/74/b044220ec52e001511a3ba75618c68e5 deleted file mode 100644 index 8e2d176..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/74/b044220ec52e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.ini"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String line=br.readLine(); - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/76/606cb261f02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/76/606cb261f02e001511a3ba75618c68e5 deleted file mode 100644 index 62811da..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/76/606cb261f02e001511a3ba75618c68e5 +++ /dev/null @@ -1,353 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/76/609ffee6f52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/76/609ffee6f52e001511a3ba75618c68e5 deleted file mode 100644 index 0907c87..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/76/609ffee6f52e001511a3ba75618c68e5 +++ /dev/null @@ -1,383 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/76/7043c1cded2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/76/7043c1cded2e001511a3ba75618c68e5 deleted file mode 100644 index e0c4ba7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/76/7043c1cded2e001511a3ba75618c68e5 +++ /dev/null @@ -1,336 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/76/9077f3faab2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/76/9077f3faab2b00151fa6e49f3e10bf0b deleted file mode 100644 index d2dc6a8..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/76/9077f3faab2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,74 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedWriter; -import java.io.FileWriter; -import java.io.IOException; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/77/207e8f0bc02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/77/207e8f0bc02e001511a3ba75618c68e5 deleted file mode 100644 index af8da27..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/77/207e8f0bc02e001511a3ba75618c68e5 +++ /dev/null @@ -1,63 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/77/6089e238ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/77/6089e238ef2e001511a3ba75618c68e5 deleted file mode 100644 index dfd495b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/77/6089e238ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,341 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - int x=0; - while((x=displayname.indexOf("§", x))!=-1) - Positions.add(x); - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/77/70d77550fa2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/77/70d77550fa2e001511a3ba75618c68e5 deleted file mode 100644 index 9f1861e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/77/70d77550fa2e001511a3ba75618c68e5 +++ /dev/null @@ -1,391 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - ArrayList Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length)) //TODO - { - //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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/77/d074cf98f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/77/d074cf98f63d00151c31fb33fff4337f new file mode 100644 index 0000000..2ef29ec --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/77/d074cf98f63d00151c31fb33fff4337f @@ -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(); + 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 new file mode 100644 index 0000000..19b9f5c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/77/d083ff46043e00151c31fb33fff4337f @@ -0,0 +1,427 @@ +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/5065e3fff63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/78/5065e3fff63d00151c31fb33fff4337f new file mode 100644 index 0000000..02c6ce6 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/78/5065e3fff63d00151c31fb33fff4337f @@ -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(); + 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/d07f6c71c12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/78/d07f6c71c12e001511a3ba75618c68e5 deleted file mode 100644 index 717b2d5..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/78/d07f6c71c12e001511a3ba75618c68e5 +++ /dev/null @@ -1,293 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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, String flairclass) - { - if(IgnoredPlayers.contains(player.getName())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForClass(flairclass); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/78/f0825bd8063e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/78/f0825bd8063e00151c31fb33fff4337f new file mode 100644 index 0000000..3dd6e6b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/78/f0825bd8063e00151c31fb33fff4337f @@ -0,0 +1,83 @@ +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. + if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + //PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + 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. + String flair=MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName()).Flair; //2015.08.08. + if(flair==null) + flair=""; //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/79/003d5ea2ed2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/79/003d5ea2ed2e001511a3ba75618c68e5 deleted file mode 100644 index 9308b28..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/79/003d5ea2ed2e001511a3ba75618c68e5 +++ /dev/null @@ -1,335 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/79/203a486fa92b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/79/203a486fa92b00151fa6e49f3e10bf0b deleted file mode 100644 index af31df7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/79/203a486fa92b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,59 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("$cYou already have this flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - break; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/79/e003d641f82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/79/e003d641f82e001511a3ba75618c68e5 deleted file mode 100644 index 1efbd17..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/79/e003d641f82e001511a3ba75618c68e5 +++ /dev/null @@ -1,112 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //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"); - } - 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.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) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - 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/7a/4046a21a013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/7a/4046a21a013e00151c31fb33fff4337f new file mode 100644 index 0000000..c604fd3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/7a/4046a21a013e00151c31fb33fff4337f @@ -0,0 +1,123 @@ +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; + if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + + //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); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + 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"); + } + 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) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + 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/7a/606aad24f82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7a/606aad24f82e001511a3ba75618c68e5 deleted file mode 100644 index f3f57fc..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7a/606aad24f82e001511a3ba75618c68e5 +++ /dev/null @@ -1,111 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //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"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } - private static void DoReload(Player player) - { - if(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) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - 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/7a/80cff965ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7a/80cff965ef2e001511a3ba75618c68e5 deleted file mode 100644 index e75cd9b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7a/80cff965ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,343 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7a/e04691cdfa2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7a/e04691cdfa2e001511a3ba75618c68e5 deleted file mode 100644 index ef2e051..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7a/e04691cdfa2e001511a3ba75618c68e5 +++ /dev/null @@ -1,398 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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.currentThread().sleep(5000); - } catch (InterruptedException e1) { - // TODO Auto-generated catch block - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7b/004a78fdfc3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/7b/004a78fdfc3d00151c31fb33fff4337f new file mode 100644 index 0000000..2867be2 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/7b/004a78fdfc3d00151c31fb33fff4337f @@ -0,0 +1,21 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer { + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static void AddPlayer(String playername) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7b/1078ea5ba12b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/7b/1078ea5ba12b00151fa6e49f3e10bf0b deleted file mode 100644 index 6400ba7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7b/1078ea5ba12b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,44 +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; - -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)); - PluginMain.AppendPlayerDisplayFlair(p, PluginMain.GetFlair(p)); - System.out.println("Added player "+p.getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.ini"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String line=br.readLine(); - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7b/6014043bf02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7b/6014043bf02e001511a3ba75618c68e5 deleted file mode 100644 index 7e4bd99..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7b/6014043bf02e001511a3ba75618c68e5 +++ /dev/null @@ -1,351 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - for(int pos : Positions) - { - - } - } - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7b/c081221f023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/7b/c081221f023e00151c31fb33fff4337f new file mode 100644 index 0000000..7a8d627 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/7b/c081221f023e00151c31fb33fff4337f @@ -0,0 +1,125 @@ +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(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); + } + 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 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"); + } + 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(MaybeOfflinePlayer : MaybeOfflinePlayer.AllPlayers.values()) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + 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/7b/f0438a5af93d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/7b/f0438a5af93d00151c31fb33fff4337f new file mode 100644 index 0000000..3ca08ad --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/7b/f0438a5af93d00151c31fb33fff4337f @@ -0,0 +1,75 @@ +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/201f6405c92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7c/201f6405c92e001511a3ba75618c68e5 deleted file mode 100644 index 806bf88..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7c/201f6405c92e001511a3ba75618c68e5 +++ /dev/null @@ -1,326 +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.List; -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.Towny; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - //List towns = TownyUniverse.getDataSource().getTowns(); - WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7c/2055c958c62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7c/2055c958c62e001511a3ba75618c68e5 deleted file mode 100644 index e3ae66e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7c/2055c958c62e001511a3ba75618c68e5 +++ /dev/null @@ -1,313 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - if() - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7c/6026172bf92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7c/6026172bf92e001511a3ba75618c68e5 deleted file mode 100644 index 06b0607..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7c/6026172bf92e001511a3ba75618c68e5 +++ /dev/null @@ -1,387 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - ArrayList Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length)) //TODO - { - //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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7c/a0d8547cad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/7c/a0d8547cad2b00151fa6e49f3e10bf0b deleted file mode 100644 index fdff40e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7c/a0d8547cad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,270 +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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - 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(String player : IgnoredPlayers) - { - File file=new File("flairsignored.txt"File file=new File( - 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. - { - 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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7c/d0cb7c99f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/7c/d0cb7c99f63d00151c31fb33fff4337f new file mode 100644 index 0000000..2ef29ec --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/7c/d0cb7c99f63d00151c31fb33fff4337f @@ -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(); + 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/7d/202437fbc82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7d/202437fbc82e001511a3ba75618c68e5 deleted file mode 100644 index b922dfb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7d/202437fbc82e001511a3ba75618c68e5 +++ /dev/null @@ -1,326 +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.List; -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.Towny; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - //List towns = TownyUniverse.getDataSource().getTowns(); - TownyUniverse.getDataSource() - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7d/b01607f8c42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7d/b01607f8c42e001511a3ba75618c68e5 deleted file mode 100644 index 5b5a4cf..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7d/b01607f8c42e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.ini"); - try { - BufferedWriter bw=new BufferedWriter(new FileWriter(file, true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7e/10cadbb0c42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7e/10cadbb0c42e001511a3ba75618c68e5 deleted file mode 100644 index 5eb70f1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7e/10cadbb0c42e001511a3ba75618c68e5 +++ /dev/null @@ -1,294 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7e/500698dcbf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7e/500698dcbf2e001511a3ba75618c68e5 deleted file mode 100644 index 4825715..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7e/500698dcbf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,288 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - } - - public static void AppendPlayerDisplayFlairFinal(Player player, String username, String flair); -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7e/60a3a83aef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7e/60a3a83aef2e001511a3ba75618c68e5 deleted file mode 100644 index a9b2226..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7e/60a3a83aef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,344 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>();for(int i=str.length()-1; i>=0; i--) { - if(Character.isUpperCase(str.charAt(i))) { - return i; - } - } - return -1; - } - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/60/60a8e9e7052f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7e/9072727d013e00151c31fb33fff4337f similarity index 87% rename from .metadata/.plugins/org.eclipse.core.resources/.history/60/60a8e9e7052f001511a3ba75618c68e5 rename to .metadata/.plugins/org.eclipse.core.resources/.history/7e/9072727d013e00151c31fb33fff4337f index c5f649b..4b9f9aa 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/60/60a8e9e7052f001511a3ba75618c68e5 +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/7e/9072727d013e00151c31fb33fff4337f @@ -53,7 +53,9 @@ public class PluginMain extends JavaPlugin String line; while ((line = br.readLine()) != null) { - AcceptedPlayers.add(line.replace("\n", "")); + //AcceptedPlayers.add(line.replace("\n", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. } br.close(); } @@ -64,7 +66,9 @@ public class PluginMain extends JavaPlugin String line; while ((line = br.readLine()) != null) { - IgnoredPlayers.add(line.replace("\n", "")); + //IgnoredPlayers.add(line.replace("\n", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. } br.close(); } @@ -105,8 +109,11 @@ public class PluginMain extends JavaPlugin { System.out.println("Error!\n"+e); } - for(String player : AcceptedPlayers) + //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)); @@ -116,8 +123,10 @@ public class PluginMain extends JavaPlugin System.out.println("Error!\n"+e); } } - for(String player : IgnoredPlayers) + 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)); @@ -207,13 +216,13 @@ public class PluginMain extends JavaPlugin } //It has to store offline player flairs too, therefore it can't use Player object - public static Map PlayerFlairs=new HashMap(); + /*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 PlayerTowns=new HashMap(); //2015.07.20.*/ public static Map TownColors=new HashMap(); //2015.07.20. public Boolean HasIGFlair(String playername) { @@ -228,7 +237,8 @@ public class PluginMain extends JavaPlugin } if(player==null) return false;*/ - return PlayerFlairs.containsKey(playername); + //return PlayerFlairs.containsKey(playername); + return MaybeOfflinePlayer.AllPlayers.containsKey(playername); } public void SetFlair(String playername, String text, String flairclass, String username) @@ -260,6 +270,9 @@ public class PluginMain extends JavaPlugin case "cheater": finalflair="§5("+text+")§r"; break; + case "cant-press": //2015.08.08. + finalflair="§r(can't press)§r"; + break; default: finalflair=""; break; @@ -301,9 +314,11 @@ public class PluginMain extends JavaPlugin public static void AppendPlayerDisplayFlair(Player player, String username, String flair) { - if(IgnoredPlayers.contains(player.getName())) + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) return; - if(AcceptedPlayers.contains(player.getName())) + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) //player.setDisplayName(player.getDisplayName()+flair); AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. else @@ -315,7 +330,8 @@ public class PluginMain extends JavaPlugin //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.getDisplayName(); + String displayname=player.getName(); //2015.08.08. ArrayList Positions=new ArrayList<>(); //System.out.println("B"); for(int i=0; i 1) //2015.07.15. - flair = flairdata[1]; - else - flair=""; - if (flair != "-1") - flair = flair + "s"; - else - flair = "non-presser"; - String flairclass; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7f/702359e9f02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7f/702359e9f02e001511a3ba75618c68e5 deleted file mode 100644 index 4c78085..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7f/702359e9f02e001511a3ba75618c68e5 +++ /dev/null @@ -1,360 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/7f/7097cde3b82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/7f/7097cde3b82e001511a3ba75618c68e5 deleted file mode 100644 index af8da27..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/7f/7097cde3b82e001511a3ba75618c68e5 +++ /dev/null @@ -1,63 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8/2023cbe9c42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/8/2023cbe9c42e001511a3ba75618c68e5 deleted file mode 100644 index cbe6671..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8/2023cbe9c42e001511a3ba75618c68e5 +++ /dev/null @@ -1,300 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8/60032e9cf32e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/8/60032e9cf32e001511a3ba75618c68e5 deleted file mode 100644 index 697d60a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8/60032e9cf32e001511a3ba75618c68e5 +++ /dev/null @@ -1,382 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8/6022721bf82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/8/6022721bf82e001511a3ba75618c68e5 deleted file mode 100644 index 59d582c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8/6022721bf82e001511a3ba75618c68e5 +++ /dev/null @@ -1,110 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //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"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(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) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } - private static void DoReload(Player player) - { - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8/a0da1bac9b2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/8/a0da1bac9b2b00151fa6e49f3e10bf0b deleted file mode 100644 index 57879b6..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8/a0da1bac9b2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,43 +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; - -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(event.getPlayer().getDisplayName()+PluginMain.GetFlair(event.getPlayer())); - System.out.println("Added player "+event.getPlayer().getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8/e047daf4063e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/8/e047daf4063e00151c31fb33fff4337f new file mode 100644 index 0000000..e46f27a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/8/e047daf4063e00151c31fb33fff4337f @@ -0,0 +1,83 @@ +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. + 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.) + //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. + String flair=MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName()).Flair; //2015.08.08. + if(flair==null) + flair=""; //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/80/20e2900fc02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/80/20e2900fc02e001511a3ba75618c68e5 deleted file mode 100644 index 3ec87d6..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/80/20e2900fc02e001511a3ba75618c68e5 +++ /dev/null @@ -1,64 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/80/6030fe14fb2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/80/6030fe14fb2e001511a3ba75618c68e5 deleted file mode 100644 index ae5e7f4..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/80/6030fe14fb2e001511a3ba75618c68e5 +++ /dev/null @@ -1,397 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/80/e08df834032f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/80/e08df834032f001511a3ba75618c68e5 deleted file mode 100644 index e1f6a66..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/80/e08df834032f001511a3ba75618c68e5 +++ /dev/null @@ -1,78 +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("ChatSerializer"); - private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); - if (majorVersion < 1.8 || (majorVersion == 1.8 && lesserVersion == 1)) { - chatSerializerClazz = Reflection.getNMSClass("ChatSerializer"); - } else { - chatSerializerClazz = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); - } - 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/81/207849dec52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/81/207849dec52e001511a3ba75618c68e5 deleted file mode 100644 index 434f059..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/81/207849dec52e001511a3ba75618c68e5 +++ /dev/null @@ -1,311 +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; - -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", "")); - } - 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", "")); - } - br.close(); - } - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PlayerTowns.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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - try { - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/81/20e90798ad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/81/20e90798ad2b00151fa6e49f3e10bf0b deleted file mode 100644 index 3213c84..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/81/20e90798ad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,270 +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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/81/403b869cf63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/81/403b869cf63d00151c31fb33fff4337f new file mode 100644 index 0000000..2ef29ec --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/81/403b869cf63d00151c31fb33fff4337f @@ -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(); + 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/81/a0d37509c52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/81/a0d37509c52e001511a3ba75618c68e5 deleted file mode 100644 index 9d7ca6c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/81/a0d37509c52e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.ini"); - try { - BufferedReader bw=new BufferedReader(new FileReader(file)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/81/a0e017eec72e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/81/a0e017eec72e001511a3ba75618c68e5 deleted file mode 100644 index 8fe8b10..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/81/a0e017eec72e001511a3ba75618c68e5 +++ /dev/null @@ -1,322 +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.Towny; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - GetPlugin(typeof(Towny)).getTownyInstance() - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/82/104d961b932b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/82/104d961b932b00151fa6e49f3e10bf0b deleted file mode 100644 index 83367d1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/82/104d961b932b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,35 +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; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - for(Player player : PluginMain.Players) - { - if(player.getName()==event.getPlayer().getName()) - { - PluginMain.Players.remove(player); - } - } - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/82/20829588912b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/82/20829588912b00151fa6e49f3e10bf0b deleted file mode 100644 index a7cb33e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/82/20829588912b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,21 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerJoinEvent; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/82/20ae0cc5ac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/82/20ae0cc5ac2b00151fa6e49f3e10bf0b deleted file mode 100644 index dd4918e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/82/20ae0cc5ac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,260 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/83/705f6955012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/83/705f6955012f001511a3ba75618c68e5 deleted file mode 100644 index a8af32e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/83/705f6955012f001511a3ba75618c68e5 +++ /dev/null @@ -1,63 +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; - -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 - { - 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\"}]}}}]"; - p.sendTitle(json, ""; - } - //System.out.println("Added player "+p.getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i implements Predicate -{ - public MyPredicate() - { - - } - @Override - public boolean test(T arg0) { - return false; - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/84/20ae50cfce2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/84/20ae50cfce2e001511a3ba75618c68e5 deleted file mode 100644 index f21d16c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/84/20ae50cfce2e001511a3ba75618c68e5 +++ /dev/null @@ -1,329 +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.exceptions.NotRegisteredException; -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List towns = TownyUniverse.getDataSource().getTowns(); - try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - return town.getName(); - } catch (Exception e) { - return ""; - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/84/e0cafcb5f02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/84/e0cafcb5f02e001511a3ba75618c68e5 deleted file mode 100644 index e57ddce..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/84/e0cafcb5f02e001511a3ba75618c68e5 +++ /dev/null @@ -1,355 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/85/7082ce5ff62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/85/7082ce5ff62e001511a3ba75618c68e5 deleted file mode 100644 index 918616a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/85/7082ce5ff62e001511a3ba75618c68e5 +++ /dev/null @@ -1,383 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/85/e0142d0af52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/85/e0142d0af52e001511a3ba75618c68e5 deleted file mode 100644 index 632b739..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/85/e0142d0af52e001511a3ba75618c68e5 +++ /dev/null @@ -1,382 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/85/e0445a04f82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/85/e0445a04f82e001511a3ba75618c68e5 deleted file mode 100644 index 578542e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/85/e0445a04f82e001511a3ba75618c68e5 +++ /dev/null @@ -1,108 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //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"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(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) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } - private static void -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/86/a0aaceebab2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/86/a0aaceebab2b00151fa6e49f3e10bf0b deleted file mode 100644 index 7df9428..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/86/a0aaceebab2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,63 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/87/80345c38902b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/87/80345c38902b00151fa6e49f3e10bf0b deleted file mode 100644 index b82c33d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/87/80345c38902b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,20 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; - -public class PlayerListener implements Listener -{ - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/87/a020dca2ad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/87/a020dca2ad2b00151fa6e49f3e10bf0b deleted file mode 100644 index b63521c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/87/a020dca2ad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,273 +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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - File file=new File("flairsaccepted.txt"); - if(file.exists()) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/87/c0ee9e2cc02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/87/c0ee9e2cc02e001511a3ba75618c68e5 deleted file mode 100644 index da85eaa..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/87/c0ee9e2cc02e001511a3ba75618c68e5 +++ /dev/null @@ -1,292 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/87/e0091494f32e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/87/e0091494f32e001511a3ba75618c68e5 deleted file mode 100644 index 31580b5..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/87/e0091494f32e001511a3ba75618c68e5 +++ /dev/null @@ -1,382 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/88/20510e4a922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/88/20510e4a922b00151fa6e49f3e10bf0b deleted file mode 100644 index e69de29..0000000 diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/88/e001984d0e3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/88/e001984d0e3e00151089cca86c5b1a99 new file mode 100644 index 0000000..e7381d7 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/88/e001984d0e3e00151089cca86c5b1a99 @@ -0,0 +1,434 @@ +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)"); + //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.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+"\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/89/d0fdd397f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/89/d0fdd397f63d00151c31fb33fff4337f new file mode 100644 index 0000000..2ef29ec --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/89/d0fdd397f63d00151c31fb33fff4337f @@ -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(); + 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/89/e09bd143ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/89/e09bd143ef2e001511a3ba75618c68e5 deleted file mode 100644 index 5aac582..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/89/e09bd143ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,342 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>();for(int i=str.length()-1; i>=0; i--) { - if(Character.isUpperCase(str.charAt(i))) { - return i; - } - } - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8a/a0819610a72b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/8a/a0819610a72b00151fa6e49f3e10bf0b deleted file mode 100644 index bd6f4db..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8a/a0819610a72b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,46 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - player.sendMessage("§6Your flair has been set.§r"); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8b/6006432e032f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/8b/6006432e032f001511a3ba75618c68e5 deleted file mode 100644 index 8cd553b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8b/6006432e032f001511a3ba75618c68e5 +++ /dev/null @@ -1,73 +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("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/b08c1511c82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/8b/b08c1511c82e001511a3ba75618c68e5 deleted file mode 100644 index 308b3ef..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8b/b08c1511c82e001511a3ba75618c68e5 +++ /dev/null @@ -1,323 +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.Towny; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - new Class(); - getPlugin()).getTownyInstance() - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8b/d0c1d07df02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/8b/d0c1d07df02e001511a3ba75618c68e5 deleted file mode 100644 index 3e53c9d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8b/d0c1d07df02e001511a3ba75618c68e5 +++ /dev/null @@ -1,353 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8b/e0e354c4ee2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/8b/e0e354c4ee2e001511a3ba75618c68e5 deleted file mode 100644 index dfd495b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8b/e0e354c4ee2e001511a3ba75618c68e5 +++ /dev/null @@ -1,341 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - int x=0; - while((x=displayname.indexOf("§", x))!=-1) - Positions.add(x); - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8c/50aa2bf3023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/8c/50aa2bf3023e00151c31fb33fff4337f new file mode 100644 index 0000000..6ebcd9a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/8c/50aa2bf3023e00151c31fb33fff4337f @@ -0,0 +1,418 @@ +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/60ddc035f72e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/8c/60ddc035f72e001511a3ba75618c68e5 deleted file mode 100644 index 1caf9ba..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8c/60ddc035f72e001511a3ba75618c68e5 +++ /dev/null @@ -1,384 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8d/60933f62ff2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/8d/60933f62ff2e001511a3ba75618c68e5 deleted file mode 100644 index 17fc5c8..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8d/60933f62ff2e001511a3ba75618c68e5 +++ /dev/null @@ -1,49 +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; - -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 - { - 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\"}]}}}]"; - } - //System.out.println("Added player "+p.getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8d/d0631404023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/8d/d0631404023e00151c31fb33fff4337f new file mode 100644 index 0000000..ab9966d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/8d/d0631404023e00151c31fb33fff4337f @@ -0,0 +1,125 @@ +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(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); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + 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"); + } + 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) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + 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/8d/e0e833fff72e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/8d/e0e833fff72e001511a3ba75618c68e5 deleted file mode 100644 index 8048a43..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8d/e0e833fff72e001511a3ba75618c68e5 +++ /dev/null @@ -1,108 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //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"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(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) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8e/20ff3826c62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/8e/20ff3826c62e001511a3ba75618c68e5 deleted file mode 100644 index e3ae66e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8e/20ff3826c62e001511a3ba75618c68e5 +++ /dev/null @@ -1,313 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - if() - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/8f/205432bcc82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/8f/205432bcc82e001511a3ba75618c68e5 deleted file mode 100644 index 859c4a1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/8f/205432bcc82e001511a3ba75618c68e5 +++ /dev/null @@ -1,324 +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.Towny; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - List towns = TownyUniverse.getDataSource().getTowns(); - getPlugin()).getTownyInstance() - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9/70788731022f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/9/70788731022f001511a3ba75618c68e5 deleted file mode 100644 index ac3cc81..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/9/70788731022f001511a3ba75618c68e5 +++ /dev/null @@ -1,72 +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("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.prinln("3"); - Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); - System.out.prinln("4"); - Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); - System.out.prinln("5"); - Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); - } catch (Exception e) { - e.printStackTrace(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9/a0706393c92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/9/a0706393c92e001511a3ba75618c68e5 deleted file mode 100644 index a9a1f7e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/9/a0706393c92e001511a3ba75618c68e5 +++ /dev/null @@ -1,330 +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.List; -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.exceptions.NotRegisteredException; -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List towns = TownyUniverse.getDataSource().getTowns(); - try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - return town.getName(); - } catch (NotRegisteredException e) { - return ""; - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/cb/f0ea1f21052f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/90/00c56e06f63d00151c31fb33fff4337f similarity index 99% rename from .metadata/.plugins/org.eclipse.core.resources/.history/cb/f0ea1f21052f001511a3ba75618c68e5 rename to .metadata/.plugins/org.eclipse.core.resources/.history/90/00c56e06f63d00151c31fb33fff4337f index 93cc476..7c2048e 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/cb/f0ea1f21052f001511a3ba75618c68e5 +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/90/00c56e06f63d00151c31fb33fff4337f @@ -47,7 +47,7 @@ public class PlayerListener implements Listener @EventHandler public void onPlayerChat(AsyncPlayerChatEvent event) { - + event.getFormat() } private static Class nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/90/308d0ce3bf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/90/308d0ce3bf2e001511a3ba75618c68e5 deleted file mode 100644 index 5930458..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/90/308d0ce3bf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,291 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - } - - public static void AppendPlayerDisplayFlairFinal(Player player, String username, String flair) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/90/6069aa58f02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/90/6069aa58f02e001511a3ba75618c68e5 deleted file mode 100644 index f09d90a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/90/6069aa58f02e001511a3ba75618c68e5 +++ /dev/null @@ -1,352 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/90/b04b6599ac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/90/b04b6599ac2b00151fa6e49f3e10bf0b deleted file mode 100644 index 2a9f0f9..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/90/b04b6599ac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,253 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - PluginMain.IgnoredPlayers.add(player.getName()); - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/90/e0c2706bf72e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/90/e0c2706bf72e001511a3ba75618c68e5 deleted file mode 100644 index fb7f1e5..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/90/e0c2706bf72e001511a3ba75618c68e5 +++ /dev/null @@ -1,385 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/91/a005e2c5c42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/91/a005e2c5c42e001511a3ba75618c68e5 deleted file mode 100644 index 1a58760..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/91/a005e2c5c42e001511a3ba75618c68e5 +++ /dev/null @@ -1,299 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/92/10894b16a72b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/92/10894b16a72b00151fa6e49f3e10bf0b deleted file mode 100644 index e429509..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/92/10894b16a72b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,47 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+); - player.sendMessage("§6Your flair has been set.§r"); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/92/60ec4bcded2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/92/60ec4bcded2e001511a3ba75618c68e5 deleted file mode 100644 index 6211871..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/92/60ec4bcded2e001511a3ba75618c68e5 +++ /dev/null @@ -1,337 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/92/c0e52982cf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/92/c0e52982cf2e001511a3ba75618c68e5 deleted file mode 100644 index 62be9eb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/92/c0e52982cf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,94 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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. - if(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(); - player.sendMessage("Reloaded config file."); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a/e03728d7042f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/92/d085d1ac013e00151c31fb33fff4337f similarity index 86% rename from .metadata/.plugins/org.eclipse.core.resources/.history/a/e03728d7042f001511a3ba75618c68e5 rename to .metadata/.plugins/org.eclipse.core.resources/.history/92/d085d1ac013e00151c31fb33fff4337f index 1cfbaab..452a530 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a/e03728d7042f001511a3ba75618c68e5 +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/92/d085d1ac013e00151c31fb33fff4337f @@ -53,7 +53,9 @@ public class PluginMain extends JavaPlugin String line; while ((line = br.readLine()) != null) { - AcceptedPlayers.add(line.replace("\n", "")); + //AcceptedPlayers.add(line.replace("\n", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).AcceptedFlair=true; //2015.08.08. } br.close(); } @@ -64,7 +66,9 @@ public class PluginMain extends JavaPlugin String line; while ((line = br.readLine()) != null) { - IgnoredPlayers.add(line.replace("\n", "")); + //IgnoredPlayers.add(line.replace("\n", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. } br.close(); } @@ -105,8 +109,11 @@ public class PluginMain extends JavaPlugin { System.out.println("Error!\n"+e); } - for(String player : AcceptedPlayers) + //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)); @@ -116,8 +123,10 @@ public class PluginMain extends JavaPlugin System.out.println("Error!\n"+e); } } - for(String player : IgnoredPlayers) + 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)); @@ -207,13 +216,13 @@ public class PluginMain extends JavaPlugin } //It has to store offline player flairs too, therefore it can't use Player object - public static Map PlayerFlairs=new HashMap(); + /*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 PlayerTowns=new HashMap(); //2015.07.20.*/ public static Map TownColors=new HashMap(); //2015.07.20. public Boolean HasIGFlair(String playername) { @@ -228,7 +237,8 @@ public class PluginMain extends JavaPlugin } if(player==null) return false;*/ - return PlayerFlairs.containsKey(playername); + //return PlayerFlairs.containsKey(playername); + return MaybeOfflinePlayer.AllPlayers.containsKey(playername); } public void SetFlair(String playername, String text, String flairclass, String username) @@ -260,14 +270,18 @@ public class PluginMain extends JavaPlugin 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); + //PlayerFlairs.put(playername, finalflair); + //PlayerUserNames.put(playername, username); + /*for(Player player : Players) { if(player.getName()==playername) @@ -301,9 +315,11 @@ public class PluginMain extends JavaPlugin public static void AppendPlayerDisplayFlair(Player player, String username, String flair) { - if(IgnoredPlayers.contains(player.getName())) + //if(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) return; - if(AcceptedPlayers.contains(player.getName())) + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) //player.setDisplayName(player.getDisplayName()+flair); AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. else @@ -314,10 +330,9 @@ public class PluginMain extends JavaPlugin { //2015.07.20. //System.out.println("A"); String color = GetColorForTown(GetPlayerTown(player)); //TO!DO: Multiple colors put on first capital letters - if(color!="") - { String[] colors = color.substring(1).split("§"); - String displayname=player.getDisplayName(); + //String displayname=player.getDisplayName(); + String displayname=player.getName(); //2015.08.08. ArrayList Positions=new ArrayList<>(); //System.out.println("B"); for(int i=0; i 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { - //List towns = TownyUniverse.getDataSource().getTowns(); - WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/93/b0d47969d22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/93/b0d47969d22e001511a3ba75618c68e5 deleted file mode 100644 index 0c1561d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/93/b0d47969d22e001511a3ba75618c68e5 +++ /dev/null @@ -1,100 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //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"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(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 player : PluginMain.AcceptedPlayers) - ; - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/93/d0279c5a053e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/93/d0279c5a053e00151c31fb33fff4337f new file mode 100644 index 0000000..522f375 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/93/d0279c5a053e00151c31fb33fff4337f @@ -0,0 +1,81 @@ +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. + if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + //PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + 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. + String flair=MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName()).Flair; //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/94/20da4983ad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/94/20da4983ad2b00151fa6e49f3e10bf0b deleted file mode 100644 index 3213c84..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/94/20da4983ad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,270 +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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/94/903495c2a32b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/94/903495c2a32b00151fa6e49f3e10bf0b deleted file mode 100644 index d3e458a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/94/903495c2a32b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,32 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if() - switch(args[0]) - { - case "accept": - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - break; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/94/a0596c02ad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/94/a0596c02ad2b00151fa6e49f3e10bf0b deleted file mode 100644 index df61cfc..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/94/a0596c02ad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,268 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/95/605f63960d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/95/605f63960d3e00151089cca86c5b1a99 new file mode 100644 index 0000000..9aaee42 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/95/605f63960d3e00151089cca86c5b1a99 @@ -0,0 +1,436 @@ +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)"); + //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())) + System.out.println("PlayerName: "+player.getName()); + System.out.println(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair); + 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 new file mode 100644 index 0000000..2ef29ec --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/95/60dd0d99f63d00151c31fb33fff4337f @@ -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(); + 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/a0b5088a9b2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/95/a0b5088a9b2b00151fa6e49f3e10bf0b deleted file mode 100644 index 8ab59e5..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/95/a0b5088a9b2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,42 +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; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - event.getPlayer(). - System.out.println("Added player "+event.getPlayer().getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i getNMSClass(String className) { - String fullName = "net.minecraft.server." + getVersion() + className; - Class clazz = null; - try { - clazz = Class.forName(fullName); - } catch (Exception e) { - e.printStackTrace(); - } - return clazz; - } - - public static Class getOBCClass(String className) { - String fullName = "org.bukkit.craftbukkit." + getVersion() + className; - Class clazz = null; - try { - clazz = Class.forName(fullName); - } catch (Exception e) { - e.printStackTrace(); - } - return clazz; - } - - public static Object getHandle(Object obj) { - try { - return getMethod(obj.getClass(), "getHandle").invoke(obj); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - public static Field getField(Class clazz, String name) { - try { - Field field = clazz.getDeclaredField(name); - field.setAccessible(true); - return field; - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - public static Method getMethod(Class clazz, String name, Class... args) { - for (Method m : clazz.getMethods()) - if (m.getName().equals(name) && (args.length == 0 || ClassListEqual(args, m.getParameterTypes()))) { - m.setAccessible(true); - return m; - } - return null; - } - - public static boolean ClassListEqual(Class[] l1, Class[] l2) { - boolean equal = true; - if (l1.length != l2.length) - return false; - for (int i = 0; i < l1.length; i++) - if (l1[i] != l2[i]) { - equal = false; - break; - } - return equal; - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/97/6096c38cfd2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/97/6096c38cfd2e001511a3ba75618c68e5 deleted file mode 100644 index e0f927c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/97/6096c38cfd2e001511a3ba75618c68e5 +++ /dev/null @@ -1,47 +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; - -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 - p.sendMessage("§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to this thread."); - //System.out.println("Added player "+p.getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i 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/d0e97d74fc3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/97/d0e97d74fc3d00151c31fb33fff4337f new file mode 100644 index 0000000..1eb050a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/97/d0e97d74fc3d00151c31fb33fff4337f @@ -0,0 +1,15 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer { + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/98/b0f95768c12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/98/b0f95768c12e001511a3ba75618c68e5 deleted file mode 100644 index 3c8ae92..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/98/b0f95768c12e001511a3ba75618c68e5 +++ /dev/null @@ -1,293 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForClass(flairclass); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/98/e00fcf2df82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/98/e00fcf2df82e001511a3ba75618c68e5 deleted file mode 100644 index 4ee334b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/98/e00fcf2df82e001511a3ba75618c68e5 +++ /dev/null @@ -1,111 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //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"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(player); - break; - default: - return false; - } - return true; - } - - - return false; - } - private static void DoReload(Player player) - { - if(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) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - 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/99/506d71b4013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/99/506d71b4013e00151c31fb33fff4337f new file mode 100644 index 0000000..5edf504 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/99/506d71b4013e00151c31fb33fff4337f @@ -0,0 +1,418 @@ +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/603c843af82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/99/603c843af82e001511a3ba75618c68e5 deleted file mode 100644 index 1efbd17..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/99/603c843af82e001511a3ba75618c68e5 +++ /dev/null @@ -1,112 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //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"); - } - 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.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) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - 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/99/a045560ec82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/99/a045560ec82e001511a3ba75618c68e5 deleted file mode 100644 index 51d6e14..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/99/a045560ec82e001511a3ba75618c68e5 +++ /dev/null @@ -1,322 +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.Towny; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - GetPlugin().getTownyInstance() - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/99/e0cf6ed0f02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/99/e0cf6ed0f02e001511a3ba75618c68e5 deleted file mode 100644 index b80d7ec..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/99/e0cf6ed0f02e001511a3ba75618c68e5 +++ /dev/null @@ -1,356 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9a/e0576b12f82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/9a/e0576b12f82e001511a3ba75618c68e5 deleted file mode 100644 index dbe8d35..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/9a/e0576b12f82e001511a3ba75618c68e5 +++ /dev/null @@ -1,111 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //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"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(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) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } - private static void DoReload(Player player) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9b/f056a849012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/9b/f056a849012f001511a3ba75618c68e5 deleted file mode 100644 index 196f023..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/9b/f056a849012f001511a3ba75618c68e5 +++ /dev/null @@ -1,79 +0,0 @@ -package de.inventivegames.TellRawAutoMessage; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -import org.bukkit.Bukkit; - -public class Reflection { - - public static String getVersion() { - String name = Bukkit.getServer().getClass().getPackage().getName(); - String version = name.substring(name.lastIndexOf('.') + 1) + "."; - return version; - } - - public static Class getNMSClass(String className) { - String fullName = "net.minecraft.server." + getVersion() + className; - Class clazz = null; - try { - clazz = Class.forName(fullName); - } catch (Exception e) { - e.printStackTrace(); - } - return clazz; - } - - public static Class getOBCClass(String className) { - String fullName = "org.bukkit.craftbukkit." + getVersion() + className; - Class clazz = null; - try { - clazz = Class.forName(fullName); - } catch (Exception e) { - e.printStackTrace(); - } - return clazz; - } - - public static Object getHandle(Object obj) { - try { - return getMethod(obj.getClass(), "getHandle").invoke(obj); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - public static Field getField(Class clazz, String name) { - try { - Field field = clazz.getDeclaredField(name); - field.setAccessible(true); - return field; - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - public static Method getMethod(Class clazz, String name, Class... args) { - for (Method m : clazz.getMethods()) - if (m.getName().equals(name) && (args.length == 0 || ClassListEqual(args, m.getParameterTypes()))) { - m.setAccessible(true); - return m; - } - return null; - } - - public static boolean ClassListEqual(Class[] l1, Class[] l2) { - boolean equal = true; - if (l1.length != l2.length) - return false; - for (int i = 0; i < l1.length; i++) - if (l1[i] != l2[i]) { - equal = false; - break; - } - return equal; - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9c/a0b5740cad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/9c/a0b5740cad2b00151fa6e49f3e10bf0b deleted file mode 100644 index 0f3be9c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/9c/a0b5740cad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,67 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedWriter; -import java.io.FileWriter; -import java.io.IOException; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/fa/60103664f82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/9c/d0841f77fe3d00151c31fb33fff4337f similarity index 86% rename from .metadata/.plugins/org.eclipse.core.resources/.history/fa/60103664f82e001511a3ba75618c68e5 rename to .metadata/.plugins/org.eclipse.core.resources/.history/9c/d0841f77fe3d00151c31fb33fff4337f index d23e173..bf1e453 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/fa/60103664f82e001511a3ba75618c68e5 +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/9c/d0841f77fe3d00151c31fb33fff4337f @@ -28,12 +28,16 @@ public class Commands implements CommandExecutor { { if(PluginMain.IgnoredPlayers.contains(player.getName())) PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) { - String flair=PluginMain.PlayerFlairs.get(player.getName()); + //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()); + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. player.sendMessage("§6Your flair has been set:§r "+flair); } else @@ -99,7 +103,7 @@ public class Commands implements CommandExecutor { } String msg="§6Reloaded config file.§r"; if(player!=null) - player.sendMessage(msg); + player.sendMessage(msg); else System.out.println(msg); } @@ -107,7 +111,8 @@ public class Commands implements CommandExecutor { catch(Exception e) { System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); } } else diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9d/1061e789922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/9d/1061e789922b00151fa6e49f3e10bf0b deleted file mode 100644 index 6be33d1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/9d/1061e789922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,16 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.util.function.Predicate; - -public class MyPredicate implements Predicate -{ - public MyPredicate(T first) - { - - } - @Override - public boolean test(T arg0) { - return false; - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9d/60c3c8dcf82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/9d/60c3c8dcf82e001511a3ba75618c68e5 deleted file mode 100644 index 5e3e6af..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/9d/60c3c8dcf82e001511a3ba75618c68e5 +++ /dev/null @@ -1,385 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9d/e0ffd477033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/9d/e0ffd477033e00151c31fb33fff4337f new file mode 100644 index 0000000..41b903e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/9d/e0ffd477033e00151c31fb33fff4337f @@ -0,0 +1,78 @@ +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. + if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + //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/9e/90fa2465922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/9e/90fa2465922b00151fa6e49f3e10bf0b deleted file mode 100644 index e5ed87f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/9e/90fa2465922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,37 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.util.function.Predicate; - -public class MyPredicate implements Predicate { - - @Override - public Predicate and(Predicate arg0) { - // TODO Auto-generated method stub - return null; - } - - @Override - public static Predicate isEqual(Object arg0) { - // TODO Auto-generated method stub - return null; - } - - @Override - public Predicate negate() { - // TODO Auto-generated method stub - return null; - } - - @Override - public Predicate or(Predicate arg0) { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean test(T arg0) { - // TODO Auto-generated method stub - return false; - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9f/1004ed17a72b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/9f/1004ed17a72b00151fa6e49f3e10bf0b deleted file mode 100644 index 96a6182..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/9f/1004ed17a72b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,47 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9f/9012fdfea32b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/9f/9012fdfea32b00151fa6e49f3e10bf0b deleted file mode 100644 index f6c23d1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/9f/9012fdfea32b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,36 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - break; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/9f/90f1d8f29a2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/9f/90f1d8f29a2b00151fa6e49f3e10bf0b deleted file mode 100644 index 2693ac3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/9f/90f1d8f29a2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,38 +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; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - System.out.println("Added player "+event.getPlayer().getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i 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/a/80754cfbf72e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a/80754cfbf72e001511a3ba75618c68e5 deleted file mode 100644 index d4a0f2e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a/80754cfbf72e001511a3ba75618c68e5 +++ /dev/null @@ -1,107 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //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"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(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) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a/c0191a3f023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/a/c0191a3f023e00151c31fb33fff4337f new file mode 100644 index 0000000..772f7ef --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a/c0191a3f023e00151c31fb33fff4337f @@ -0,0 +1,125 @@ +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(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); + } + 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 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"); + } + 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(MaybeOfflinePlayer p : MaybeOfflinePlayer.AllPlayers.values()) + { + if(p.Flair!=null) + { + String flair=p.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/a/e0a46b3df82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a/e0a46b3df82e001511a3ba75618c68e5 deleted file mode 100644 index 1efbd17..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a/e0a46b3df82e001511a3ba75618c68e5 +++ /dev/null @@ -1,112 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //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"); - } - 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.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) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - 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/a0/30a4e47faf2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/a0/30a4e47faf2b00151fa6e49f3e10bf0b deleted file mode 100644 index d527262..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a0/30a4e47faf2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,279 +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; - -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", "")); - } - 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", "")); - } - br.close(); - } - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a0/602b122cfd2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a0/602b122cfd2e001511a3ba75618c68e5 deleted file mode 100644 index c5f649b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a0/602b122cfd2e001511a3ba75618c68e5 +++ /dev/null @@ -1,397 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a0/e0c38940ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a0/e0c38940ef2e001511a3ba75618c68e5 deleted file mode 100644 index 5abf264..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a0/e0c38940ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,341 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>();for(int i=str.length()-1; i>=0; i--) { - if(Character.isUpperCase(str.charAt(i))) { - return i; - } - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a0/e0ec5f84012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a0/e0ec5f84012f001511a3ba75618c68e5 deleted file mode 100644 index 978ff27..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a0/e0ec5f84012f001511a3ba75618c68e5 +++ /dev/null @@ -1,67 +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 - { - 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("ChatSerializer"); - private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); - public static void sendRawMessage(Player player, String message) { - try { - Object handle = Reflection.getHandle(player); - Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); - Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); - Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); - Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); - } catch (Exception e) { - e.printStackTrace(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a1/302a6e59d22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a1/302a6e59d22e001511a3ba75618c68e5 deleted file mode 100644 index 4d192e3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a1/302a6e59d22e001511a3ba75618c68e5 +++ /dev/null @@ -1,99 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //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"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(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(); - - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a2/205f1d48a92b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/a2/205f1d48a92b00151fa6e49f3e10bf0b deleted file mode 100644 index 78fc1a1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a2/205f1d48a92b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,57 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - break; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a2/d087eaeb063e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/a2/d087eaeb063e00151c31fb33fff4337f new file mode 100644 index 0000000..2b88815 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a2/d087eaeb063e00151c31fb33fff4337f @@ -0,0 +1,83 @@ +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. + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + if(!MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + MaybeOfflinePlayer.AddPlayerIfNeeded(p.getName()); //2015.08.08. + if() + //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. + String flair=MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName()).Flair; //2015.08.08. + if(flair==null) + flair=""; //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/a3/109449b7ac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/a3/109449b7ac2b00151fa6e49f3e10bf0b deleted file mode 100644 index 2b55ba6..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a3/109449b7ac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,259 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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 { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a3/70684cbef22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a3/70684cbef22e001511a3ba75618c68e5 deleted file mode 100644 index a1d7eef..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a3/70684cbef22e001511a3ba75618c68e5 +++ /dev/null @@ -1,382 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a3/a0b004efd22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a3/a0b004efd22e001511a3ba75618c68e5 deleted file mode 100644 index ca7e83d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a3/a0b004efd22e001511a3ba75618c68e5 +++ /dev/null @@ -1,335 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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(flair), dname.indexOf(flair))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a4/605a1b57ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a4/605a1b57ef2e001511a3ba75618c68e5 deleted file mode 100644 index 806a5d7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a4/605a1b57ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,343 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a4/80b15bca902b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/a4/80b15bca902b00151fa6e49f3e10bf0b deleted file mode 100644 index 930c6ba..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a4/80b15bca902b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,21 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerJoinEvent; - -public class PlayerListener implements Listener -{ - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - event.getPlayer(); - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a4/903b023fa42b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/a4/903b023fa42b00151fa6e49f3e10bf0b deleted file mode 100644 index f6c23d1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a4/903b023fa42b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,36 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - break; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a4/d0f0e8f0033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/a4/d0f0e8f0033e00151c31fb33fff4337f new file mode 100644 index 0000000..fc57414 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a4/d0f0e8f0033e00151c31fb33fff4337f @@ -0,0 +1,426 @@ +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/a032f69ec82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a5/a032f69ec82e001511a3ba75618c68e5 deleted file mode 100644 index 75715db..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a5/a032f69ec82e001511a3ba75618c68e5 +++ /dev/null @@ -1,322 +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.Towny; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - getPlugin()).getTownyInstance() - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a5/d04ca173f93d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/a5/d04ca173f93d00151c31fb33fff4337f new file mode 100644 index 0000000..2cb43de --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a5/d04ca173f93d00151c31fb33fff4337f @@ -0,0 +1,76 @@ +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/a6/30615366ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a6/30615366ef2e001511a3ba75618c68e5 deleted file mode 100644 index e98f293..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a6/30615366ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,343 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a7/7048aedcf62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a7/7048aedcf62e001511a3ba75618c68e5 deleted file mode 100644 index 1a7b96c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a7/7048aedcf62e001511a3ba75618c68e5 +++ /dev/null @@ -1,383 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a7/a0feefeac52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a7/a0feefeac52e001511a3ba75618c68e5 deleted file mode 100644 index ef924ce..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a7/a0feefeac52e001511a3ba75618c68e5 +++ /dev/null @@ -1,312 +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; - -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", "")); - } - 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", "")); - } - br.close(); - } - file=new File("autoflairconfig.txt"); - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - String[] s=line.split(" "); - PlayerTowns.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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - try { - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a8/20776c1dc92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a8/20776c1dc92e001511a3ba75618c68e5 deleted file mode 100644 index 500a6bc..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a8/20776c1dc92e001511a3ba75618c68e5 +++ /dev/null @@ -1,333 +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.List; -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.Towny; -import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { - //List towns = TownyUniverse.getDataSource().getTowns(); - try { - WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - } catch (NotRegisteredException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a8/50ba8ab4043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/a8/50ba8ab4043e00151c31fb33fff4337f new file mode 100644 index 0000000..d13af26 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/a8/50ba8ab4043e00151c31fb33fff4337f @@ -0,0 +1,81 @@ +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. + if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + //PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + 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. + 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/a9/600d733bf12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a9/600d733bf12e001511a3ba75618c68e5 deleted file mode 100644 index c54e853..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a9/600d733bf12e001511a3ba75618c68e5 +++ /dev/null @@ -1,365 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a9/6080831f022f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a9/6080831f022f001511a3ba75618c68e5 deleted file mode 100644 index 09aad10..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a9/6080831f022f001511a3ba75618c68e5 +++ /dev/null @@ -1,68 +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("ChatSerializer"); - private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); - public static void sendRawMessage(Player player, String message) { - try { - System.out.prinln() - Object handle = Reflection.getHandle(player); - Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); - Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); - Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); - Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); - } catch (Exception e) { - e.printStackTrace(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/a9/f0f38415f82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/a9/f0f38415f82e001511a3ba75618c68e5 deleted file mode 100644 index b3f26a1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/a9/f0f38415f82e001511a3ba75618c68e5 +++ /dev/null @@ -1,112 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //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"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(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) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } - private static void DoReload(Player player) - { - if(player==null) - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/aa/a089d581ad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/aa/a089d581ad2b00151fa6e49f3e10bf0b deleted file mode 100644 index fdff40e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/aa/a089d581ad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,270 +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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - 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(String player : IgnoredPlayers) - { - File file=new File("flairsignored.txt"File file=new File( - 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. - { - 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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/aa/b0d2228ec52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/aa/b0d2228ec52e001511a3ba75618c68e5 deleted file mode 100644 index a274210..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/aa/b0d2228ec52e001511a3ba75618c68e5 +++ /dev/null @@ -1,310 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - while((String line=br.readLine())!=null) - { - - } - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/aa/e0af633fee2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/aa/e0af633fee2e001511a3ba75618c68e5 deleted file mode 100644 index 8458bae..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/aa/e0af633fee2e001511a3ba75618c68e5 +++ /dev/null @@ -1,338 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList(); - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ab/2091a3e5d22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ab/2091a3e5d22e001511a3ba75618c68e5 deleted file mode 100644 index cf4429d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ab/2091a3e5d22e001511a3ba75618c68e5 +++ /dev/null @@ -1,335 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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(2, dname.indexOf(flair))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ab/20d4c998cf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ab/20d4c998cf2e001511a3ba75618c68e5 deleted file mode 100644 index ef48299..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ab/20d4c998cf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,97 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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. - if(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(); - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§6Reloaded config file.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ab/c074771bfa3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ab/c074771bfa3d00151c31fb33fff4337f new file mode 100644 index 0000000..5b17225 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ab/c074771bfa3d00151c31fb33fff4337f @@ -0,0 +1,11 @@ +package tk.sznp.thebuttonautoflair; + +public class MaybeOfflinePlayer { + String PlayerName; + String UserName; + String Flair; + boolean AcceptedFlair; + boolean IgnoredFlair; + String TownColors; + String DisplayName; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ab/e0241976f62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ab/e0241976f62e001511a3ba75618c68e5 deleted file mode 100644 index 4caaf54..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ab/e0241976f62e001511a3ba75618c68e5 +++ /dev/null @@ -1,383 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ac/209cc836c52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ac/209cc836c52e001511a3ba75618c68e5 deleted file mode 100644 index 8e2d176..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ac/209cc836c52e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.ini"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String line=br.readLine(); - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ac/5065ec8ffe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ac/5065ec8ffe3d00151c31fb33fff4337f new file mode 100644 index 0000000..51a39bf --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ac/5065ec8ffe3d00151c31fb33fff4337f @@ -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; + if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + 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.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); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(PluginMain.AcceptedPlayers.contains(player.getName())) + PluginMain.AcceptedPlayers.remove(player.getName()); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + 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"); + } + 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) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + 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/ac/e05e031af22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ac/e05e031af22e001511a3ba75618c68e5 deleted file mode 100644 index b587176..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ac/e05e031af22e001511a3ba75618c68e5 +++ /dev/null @@ -1,376 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ad/102621c3912b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/ad/102621c3912b00151fa6e49f3e10bf0b deleted file mode 100644 index d9fcdba..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ad/102621c3912b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,28 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - PluginMain.Players.remove(event.getPlayer()); - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ad/d0a7a16df93d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ad/d0a7a16df93d00151c31fb33fff4337f new file mode 100644 index 0000000..8bbd84b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ad/d0a7a16df93d00151c31fb33fff4337f @@ -0,0 +1,75 @@ +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/ad/e0eec742012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ad/e0eec742012f001511a3ba75618c68e5 deleted file mode 100644 index 99186fb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ad/e0eec742012f001511a3ba75618c68e5 +++ /dev/null @@ -1,4 +0,0 @@ - -public class Reflection { - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ae/60376ea0ee2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ae/60376ea0ee2e001511a3ba75618c68e5 deleted file mode 100644 index e8a4d34..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ae/60376ea0ee2e001511a3ba75618c68e5 +++ /dev/null @@ -1,341 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - int x=0; - while((x=displayname.indexOf("§", x))) - Positions.add(x) - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/af/00b3c459f02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/af/00b3c459f02e001511a3ba75618c68e5 deleted file mode 100644 index bcd05bd..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/af/00b3c459f02e001511a3ba75618c68e5 +++ /dev/null @@ -1,352 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/af/505239fb033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/af/505239fb033e00151c31fb33fff4337f new file mode 100644 index 0000000..277ee06 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/af/505239fb033e00151c31fb33fff4337f @@ -0,0 +1,426 @@ +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/af/708b111d012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/af/708b111d012f001511a3ba75618c68e5 deleted file mode 100644 index cdae381..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/af/708b111d012f001511a3ba75618c68e5 +++ /dev/null @@ -1,65 +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; - -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 - { - 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\"}]}}}]"; - p.sendTitle(json, ""; - } - //System.out.println("Added player "+p.getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String[] line=br.readLine().split(" "); - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/af/e01790d7f82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/af/e01790d7f82e001511a3ba75618c68e5 deleted file mode 100644 index 0f71b25..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/af/e01790d7f82e001511a3ba75618c68e5 +++ /dev/null @@ -1,385 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b/40053f0ee52d0015105bf01c854e42e3 b/.metadata/.plugins/org.eclipse.core.resources/.history/b/40053f0ee52d0015105bf01c854e42e3 deleted file mode 100644 index a456c10..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b/40053f0ee52d0015105bf01c854e42e3 +++ /dev/null @@ -1,287 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b/50330699ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b/50330699ef2e001511a3ba75618c68e5 deleted file mode 100644 index e75cd9b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b/50330699ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,343 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b1/204e43add12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b1/204e43add12e001511a3ba75618c68e5 deleted file mode 100644 index e74356c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b1/204e43add12e001511a3ba75618c68e5 +++ /dev/null @@ -1,98 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - PluginMain.AppendPlayerDisplayFlairFinal(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. - if(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(); - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b1/90d6a166922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/b1/90d6a166922b00151fa6e49f3e10bf0b deleted file mode 100644 index c5e32c0..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b1/90d6a166922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,12 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.util.function.Predicate; - -public class MyPredicate implements Predicate { - @Override - public boolean test(T arg0) { - // TODO Auto-generated method stub - return false; - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b1/b0d96b12ae2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/b1/b0d96b12ae2b00151fa6e49f3e10bf0b deleted file mode 100644 index 6248dc7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b1/b0d96b12ae2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,278 +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; - -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", "")); - } - br.close(); - } - file=new File("flairsignored.txt"); - if(file.exists()) - { - BufferedReader Bluebr=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - } - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b1/e03de6b6013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/b1/e03de6b6013e00151c31fb33fff4337f new file mode 100644 index 0000000..5edf504 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b1/e03de6b6013e00151c31fb33fff4337f @@ -0,0 +1,418 @@ +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/e02b9ea1ee2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b2/e02b9ea1ee2e001511a3ba75618c68e5 deleted file mode 100644 index c8fb15d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b2/e02b9ea1ee2e001511a3ba75618c68e5 +++ /dev/null @@ -1,341 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - int x=0; - while((x=displayname.indexOf("§", x))!=-1) - Positions.add(x); - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b3/20455670d22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b3/20455670d22e001511a3ba75618c68e5 deleted file mode 100644 index 6a2c3cc..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b3/20455670d22e001511a3ba75618c68e5 +++ /dev/null @@ -1,100 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //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"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(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.AcceptedPlayers) - ; - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b3/b0196cc5c12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b3/b0196cc5c12e001511a3ba75618c68e5 deleted file mode 100644 index 99bad29..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b3/b0196cc5c12e001511a3ba75618c68e5 +++ /dev/null @@ -1,294 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForClass(flairclass); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b3/e0282178012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b3/e0282178012f001511a3ba75618c68e5 deleted file mode 100644 index 3b1ae41..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b3/e0282178012f001511a3ba75618c68e5 +++ /dev/null @@ -1,67 +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 - { - 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\"}]}}}]"; - - } - //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("ChatSerializer"); - private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); - public static void sendRawMessage(Player player, String message) { - try { - Object handle = Reflection.getHandle(player); - Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); - Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); - Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); - Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); - } catch (Exception e) { - e.printStackTrace(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b4/709af161ff2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b4/709af161ff2e001511a3ba75618c68e5 deleted file mode 100644 index be69dbf..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b4/709af161ff2e001511a3ba75618c68e5 +++ /dev/null @@ -1,47 +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; - -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 - p.sendRawMessage("[\"\",{\"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\"}]}}}]"); - //System.out.println("Added player "+p.getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b4/a0d4cfa39b2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/b4/a0d4cfa39b2b00151fa6e49f3e10bf0b deleted file mode 100644 index 3fba4db..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b4/a0d4cfa39b2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,42 +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; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - event.getPlayer().setDisplayName(event.getPlayer().getDisplayName()+PluginMain.GetFlair(event.getPlayer())); - System.out.println("Added player "+event.getPlayer().getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i 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/703791ec052f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b5/703791ec052f001511a3ba75618c68e5 deleted file mode 100644 index f0ab017..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b5/703791ec052f001511a3ba75618c68e5 +++ /dev/null @@ -1,398 +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); - this.getCommand("tellraw").getExecutor(); - //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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b5/c0ca4f18013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/b5/c0ca4f18013e00151c31fb33fff4337f new file mode 100644 index 0000000..664f96d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b5/c0ca4f18013e00151c31fb33fff4337f @@ -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; + if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName()); + //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); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + 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"); + } + 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) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + 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/b5/d0028812fa3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/b5/d0028812fa3d00151c31fb33fff4337f new file mode 100644 index 0000000..d15ab52 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b5/d0028812fa3d00151c31fb33fff4337f @@ -0,0 +1,10 @@ +package tk.sznp.thebuttonautoflair; + +public class MaybeOfflinePlayer { + String PlayerName; + String UserName; + String Flair; + boolean AcceptedFlair; + boolean IgnoredFlair; + String TownColor; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b5/d00a745e053e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/b5/d00a745e053e00151c31fb33fff4337f new file mode 100644 index 0000000..eb56553 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b5/d00a745e053e00151c31fb33fff4337f @@ -0,0 +1,83 @@ +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. + if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + //PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + 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. + String flair=MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName()).Flair; //2015.08.08. + if(flair==null) + flair=""; + 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/b6/5024b6e30d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/b6/5024b6e30d3e00151089cca86c5b1a99 new file mode 100644 index 0000000..1ead049 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b6/5024b6e30d3e00151089cca86c5b1a99 @@ -0,0 +1,83 @@ +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. + 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. + } + + 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/b6/604a1fa6f22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b6/604a1fa6f22e001511a3ba75618c68e5 deleted file mode 100644 index e65dd1c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b6/604a1fa6f22e001511a3ba75618c68e5 +++ /dev/null @@ -1,378 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b6/609d3f28ee2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b6/609d3f28ee2e001511a3ba75618c68e5 deleted file mode 100644 index 4f4cbb1..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b6/609d3f28ee2e001511a3ba75618c68e5 +++ /dev/null @@ -1,338 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList s - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b6/90a348520c3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/b6/90a348520c3e00151089cca86c5b1a99 new file mode 100644 index 0000000..87c9d49 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b6/90a348520c3e00151089cca86c5b1a99 @@ -0,0 +1,432 @@ +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/b6/a0d78e97a42b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/b6/a0d78e97a42b00151fa6e49f3e10bf0b deleted file mode 100644 index f04e670..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b6/a0d78e97a42b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,43 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - break; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b6/e0d9140ff82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b6/e0d9140ff82e001511a3ba75618c68e5 deleted file mode 100644 index 4b62f9c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b6/e0d9140ff82e001511a3ba75618c68e5 +++ /dev/null @@ -1,111 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //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"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(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) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } - private static void DoReload(Player player=null) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b7/500aa169fd3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/b7/500aa169fd3d00151c31fb33fff4337f new file mode 100644 index 0000000..d2b76a1 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b7/500aa169fd3d00151c31fb33fff4337f @@ -0,0 +1,25 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + 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); + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b7/a002ab6dcf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b7/a002ab6dcf2e001511a3ba75618c68e5 deleted file mode 100644 index 6d662be..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b7/a002ab6dcf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,93 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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. - if(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(); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b8/108b64cac52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b8/108b64cac52e001511a3ba75618c68e5 deleted file mode 100644 index 6456812..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b8/108b64cac52e001511a3ba75618c68e5 +++ /dev/null @@ -1,304 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b8/2084fc30ad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/b8/2084fc30ad2b00151fa6e49f3e10bf0b deleted file mode 100644 index fc67df5..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b8/2084fc30ad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,267 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - for(String player : IgnoredPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsignored.txt", true)); - bw.write(player+"\n"); - bw.close();green - } 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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b8/a05981c0ac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/b8/a05981c0ac2b00151fa6e49f3e10bf0b deleted file mode 100644 index 1c164bc..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b8/a05981c0ac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,260 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b8/b00f8654d22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b8/b00f8654d22e001511a3ba75618c68e5 deleted file mode 100644 index a6ce4bd..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b8/b00f8654d22e001511a3ba75618c68e5 +++ /dev/null @@ -1,98 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //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"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(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(); - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b9/20a7d70dc52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/20a7d70dc52e001511a3ba75618c68e5 deleted file mode 100644 index 8e2d176..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b9/20a7d70dc52e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.ini"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String line=br.readLine(); - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b9/409c8390fe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/409c8390fe3d00151c31fb33fff4337f new file mode 100644 index 0000000..51a39bf --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/409c8390fe3d00151c31fb33fff4337f @@ -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; + if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + 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.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); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(PluginMain.AcceptedPlayers.contains(player.getName())) + PluginMain.AcceptedPlayers.remove(player.getName()); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + 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"); + } + 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) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + 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/b9/40c2f665ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/40c2f665ef2e001511a3ba75618c68e5 deleted file mode 100644 index e98f293..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/b9/40c2f665ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,343 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/b9/5032653a043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/5032653a043e00151c31fb33fff4337f new file mode 100644 index 0000000..3787be5 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/5032653a043e00151c31fb33fff4337f @@ -0,0 +1,427 @@ +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/50eb23fc013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/50eb23fc013e00151c31fb33fff4337f new file mode 100644 index 0000000..89e8084 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/50eb23fc013e00151c31fb33fff4337f @@ -0,0 +1,125 @@ +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(MaybeOfflinePlayer.AllPlayers.get(player.)) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + 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); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + 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"); + } + 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) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + 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/b9/d06dd7f9023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/d06dd7f9023e00151c31fb33fff4337f new file mode 100644 index 0000000..7fba36b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/d06dd7f9023e00151c31fb33fff4337f @@ -0,0 +1,76 @@ +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 new file mode 100644 index 0000000..2ef29ec --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/b9/f0e30e98f63d00151c31fb33fff4337f @@ -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(); + 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/20380095912b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/ba/20380095912b00151fa6e49f3e10bf0b deleted file mode 100644 index a7cb33e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ba/20380095912b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,21 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerJoinEvent; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ba/50775507fd3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ba/50775507fd3d00151c31fb33fff4337f new file mode 100644 index 0000000..a5f989f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ba/50775507fd3d00151c31fb33fff4337f @@ -0,0 +1,24 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer { + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static void AddPlayer(String playername) + { + if(!AllPlayers.containsKey(arg0)(playername)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ba/d013f5efc12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ba/d013f5efc12e001511a3ba75618c68e5 deleted file mode 100644 index 1a26ee8..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ba/d013f5efc12e001511a3ba75618c68e5 +++ /dev/null @@ -1,294 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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(); - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForClass(flairclass); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ba/d05064d1013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ba/d05064d1013e00151c31fb33fff4337f new file mode 100644 index 0000000..5edf504 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ba/d05064d1013e00151c31fb33fff4337f @@ -0,0 +1,418 @@ +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/bb/30c1a2d8c82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/bb/30c1a2d8c82e001511a3ba75618c68e5 deleted file mode 100644 index c47fb8f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/bb/30c1a2d8c82e001511a3ba75618c68e5 +++ /dev/null @@ -1,326 +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.List; -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.Towny; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - //List towns = TownyUniverse.getDataSource().getTowns(); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bb/600ef5ddf82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/bb/600ef5ddf82e001511a3ba75618c68e5 deleted file mode 100644 index 5e3e6af..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/bb/600ef5ddf82e001511a3ba75618c68e5 +++ /dev/null @@ -1,385 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bb/60b5d072043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/bb/60b5d072043e00151c31fb33fff4337f new file mode 100644 index 0000000..cd04256 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/bb/60b5d072043e00151c31fb33fff4337f @@ -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]) + { + 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); + } + 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 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"); + } + 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(p.Flair!=null) + { + String flair=p.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/bb/a010fc64a42b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/bb/a010fc64a42b00151fa6e49f3e10bf0b deleted file mode 100644 index 5298216..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/bb/a010fc64a42b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,41 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - PluginMain.IgnoredPlayers.add(player.getName()); - break; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bb/a0fbec03ac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/bb/a0fbec03ac2b00151fa6e49f3e10bf0b deleted file mode 100644 index 8ae0412..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/bb/a0fbec03ac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,245 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - BufferedReader br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - 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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bb/b00f19f8d22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/bb/b00f19f8d22e001511a3ba75618c68e5 deleted file mode 100644 index ed06c98..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/bb/b00f19f8d22e001511a3ba75618c68e5 +++ /dev/null @@ -1,101 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //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"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(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) - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - PluginMain.AppendPlayerDisplayFlairFinal(p, PluginMain.PlayerFlairs.get(p.getName())); - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bb/e0bd71c4f22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/bb/e0bd71c4f22e001511a3ba75618c68e5 deleted file mode 100644 index f4e563a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/bb/e0bd71c4f22e001511a3ba75618c68e5 +++ /dev/null @@ -1,382 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bc/204e03f6a82b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/bc/204e03f6a82b00151fa6e49f3e10bf0b deleted file mode 100644 index 3765d03..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/bc/204e03f6a82b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,50 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - player.setDisplayName(dname.substring(0, dname)); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bc/30d0c335ad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/bc/30d0c335ad2b00151fa6e49f3e10bf0b deleted file mode 100644 index 294da4a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/bc/30d0c335ad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,267 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - for(String player : IgnoredPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsignored.txt", true)); - bw.write(player+"\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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bd/d05bd96d083e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/bd/d05bd96d083e00151c31fb33fff4337f new file mode 100644 index 0000000..abdc7d1 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/bd/d05bd96d083e00151c31fb33fff4337f @@ -0,0 +1,26 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.HashMap; + +public class MaybeOfflinePlayer +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String DisplayName; + public boolean HasFlair; + 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/be/102c495fa42b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/be/102c495fa42b00151fa6e49f3e10bf0b deleted file mode 100644 index 64290b9..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/be/102c495fa42b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,39 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - PluginMain.IgnoredPlayers.add(player.getName()); - break; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/be/206ef6f9c52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/be/206ef6f9c52e001511a3ba75618c68e5 deleted file mode 100644 index e5cbf3b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/be/206ef6f9c52e001511a3ba75618c68e5 +++ /dev/null @@ -1,312 +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; - -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", "")); - } - 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", "")); - } - 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(" "); - PlayerTowns.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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - -} - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/be/d0face78043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/be/d0face78043e00151c31fb33fff4337f new file mode 100644 index 0000000..87c0c13 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/be/d0face78043e00151c31fb33fff4337f @@ -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]) + { + 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); + } + 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 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"); + } + 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(p.Flair!=null) + { + String flair=p.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/bf/30eef93ec52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/bf/30eef93ec52e001511a3ba75618c68e5 deleted file mode 100644 index 8e09b68..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/bf/30eef93ec52e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String[] line=br.readLine(); - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bf/40b7a880bf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/bf/40b7a880bf2e001511a3ba75618c68e5 deleted file mode 100644 index 3e34365..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/bf/40b7a880bf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,64 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/bf/a0c81b95c12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/bf/a0c81b95c12e001511a3ba75618c68e5 deleted file mode 100644 index 3c8ae92..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/bf/a0c81b95c12e001511a3ba75618c68e5 +++ /dev/null @@ -1,293 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForClass(flairclass); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c/106816bd922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/c/106816bd922b00151fa6e49f3e10bf0b deleted file mode 100644 index 1ab472b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c/106816bd922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,30 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - PluginMain.Players.removeIf( - return var==event.getPlayer().getName();); - } - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c/2058cec6a82b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/c/2058cec6a82b00151fa6e49f3e10bf0b deleted file mode 100644 index c670f7b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c/2058cec6a82b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,49 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c/206bd40cc92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c/206bd40cc92e001511a3ba75618c68e5 deleted file mode 100644 index 3a96c12..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c/206bd40cc92e001511a3ba75618c68e5 +++ /dev/null @@ -1,327 +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.List; -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.Towny; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - //List towns = TownyUniverse.getDataSource().getTowns(); - WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c/40594044033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/c/40594044033e00151c31fb33fff4337f new file mode 100644 index 0000000..987dab3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c/40594044033e00151c31fb33fff4337f @@ -0,0 +1,78 @@ +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)); + if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + + 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/c/a03dc224c62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c/a03dc224c62e001511a3ba75618c68e5 deleted file mode 100644 index 12b08af..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c/a03dc224c62e001511a3ba75618c68e5 +++ /dev/null @@ -1,313 +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; - -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", "")); - } - 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", "")); - } - 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(" "); - PlayerTowns.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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - if() - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c/a0bbdf39cf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c/a0bbdf39cf2e001511a3ba75618c68e5 deleted file mode 100644 index 870f3b0..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c/a0bbdf39cf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,70 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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": - if(player.isOp()) - { - - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c0/2087239bc52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c0/2087239bc52e001511a3ba75618c68e5 deleted file mode 100644 index b1c8a2e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c0/2087239bc52e001511a3ba75618c68e5 +++ /dev/null @@ -1,311 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String line; - while((line=br.readLine())!=null) - { - - } - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c0/609e9b12f22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c0/609e9b12f22e001511a3ba75618c68e5 deleted file mode 100644 index bcc3811..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c0/609e9b12f22e001511a3ba75618c68e5 +++ /dev/null @@ -1,376 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c0/e0ca4cccf82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c0/e0ca4cccf82e001511a3ba75618c68e5 deleted file mode 100644 index 3bddf63..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c0/e0ca4cccf82e001511a3ba75618c68e5 +++ /dev/null @@ -1,385 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c1/402ed649c02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c1/402ed649c02e001511a3ba75618c68e5 deleted file mode 100644 index 27b8fb2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c1/402ed649c02e001511a3ba75618c68e5 +++ /dev/null @@ -1,292 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c2/e08d9071fc3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/c2/e08d9071fc3d00151c31fb33fff4337f new file mode 100644 index 0000000..9e3f840 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c2/e08d9071fc3d00151c31fb33fff4337f @@ -0,0 +1,14 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; + +public class MaybeOfflinePlayer { + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static ArrayList AllPlayers=new ArrayList<>(); //2015.08.08. +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c3/20dba6edad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/c3/20dba6edad2b00151fa6e49f3e10bf0b deleted file mode 100644 index 32ca590..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c3/20dba6edad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,276 +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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - File file=new File("flairsaccepted.txt"); - if(file.exists()) - { - 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(String player : IgnoredPlayers) - { - File file=new File("flairsignored.txt"); - if(file.exists()) - { - 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. - { - 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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c3/50421721013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/c3/50421721013e00151c31fb33fff4337f new file mode 100644 index 0000000..da1f3aa --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c3/50421721013e00151c31fb33fff4337f @@ -0,0 +1,123 @@ +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; + if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + case "accept": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + /*if(PluginMain.IgnoredPlayers.contains(player.getName())) + PluginMain.IgnoredPlayers.remove(player.getName());*/ + if() + //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); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + 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"); + } + 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) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + 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/c3/709abd11f22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c3/709abd11f22e001511a3ba75618c68e5 deleted file mode 100644 index d0b0ed3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c3/709abd11f22e001511a3ba75618c68e5 +++ /dev/null @@ -1,375 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c3/90b90e40c52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c3/90b90e40c52e001511a3ba75618c68e5 deleted file mode 100644 index d656c74..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c3/90b90e40c52e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - BufferedReader br=new BufferedReader(new FileReader(file)); - String[] line=br.readLine().split(" "); - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c3/b0db23b2a92b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/c3/b0db23b2a92b00151fa6e49f3e10bf0b deleted file mode 100644 index 7d3ed12..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c3/b0db23b2a92b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,63 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("$cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c4/30128891cf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c4/30128891cf2e001511a3ba75618c68e5 deleted file mode 100644 index 98dee15..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c4/30128891cf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,95 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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. - if(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(); - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c4/60544486ed2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c4/60544486ed2e001511a3ba75618c68e5 deleted file mode 100644 index 9308b28..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c4/60544486ed2e001511a3ba75618c68e5 +++ /dev/null @@ -1,335 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c4/e0191ea8ed2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c4/e0191ea8ed2e001511a3ba75618c68e5 deleted file mode 100644 index 16f7068..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c4/e0191ea8ed2e001511a3ba75618c68e5 +++ /dev/null @@ -1,336 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c5/105bfc5c922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/c5/105bfc5c922b00151fa6e49f3e10bf0b deleted file mode 100644 index b5c1818..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c5/105bfc5c922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,7 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.util.function.Predicate; - -public class MyPredicate implements Predicate { - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c5/205ef9e6c72e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c5/205ef9e6c72e001511a3ba75618c68e5 deleted file mode 100644 index 068a352..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c5/205ef9e6c72e001511a3ba75618c68e5 +++ /dev/null @@ -1,322 +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.Towny; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - GetPlugin().getTownyInstance() - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c5/e0bc896e043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/c5/e0bc896e043e00151c31fb33fff4337f new file mode 100644 index 0000000..5cd2e80 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c5/e0bc896e043e00151c31fb33fff4337f @@ -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]) + { + 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); + } + 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 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"); + } + 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(p.Flair!=null) + { + String flair=p.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/c6/508d4163ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c6/508d4163ef2e001511a3ba75618c68e5 deleted file mode 100644 index 454245f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c6/508d4163ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,343 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c6/70f7bb04f92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c6/70f7bb04f92e001511a3ba75618c68e5 deleted file mode 100644 index 2f2755c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c6/70f7bb04f92e001511a3ba75618c68e5 +++ /dev/null @@ -1,385 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - ArrayList Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length)) //TODO - { - //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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c6/c0dc5f8ffe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/c6/c0dc5f8ffe3d00151c31fb33fff4337f new file mode 100644 index 0000000..02d5705 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c6/c0dc5f8ffe3d00151c31fb33fff4337f @@ -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; + if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + 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.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); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(PluginMain.AcceptedPlayers.contains(player.getName())) + PluginMain.AcceptedPlayers.remove(player.getName()); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=p.Flair; + //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"); + } + 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) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + 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/c6/d022346e043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/c6/d022346e043e00151c31fb33fff4337f new file mode 100644 index 0000000..8ca009c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c6/d022346e043e00151c31fb33fff4337f @@ -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]) + { + 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); + } + 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 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"); + } + 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 player : PluginMain.GetPlayers()) + { + + if(p.Flair!=null) + { + String flair=p.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/c6/e0f20f06f22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c6/e0f20f06f22e001511a3ba75618c68e5 deleted file mode 100644 index fd7d7dc..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c6/e0f20f06f22e001511a3ba75618c68e5 +++ /dev/null @@ -1,372 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c7/3015ce54d22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/3015ce54d22e001511a3ba75618c68e5 deleted file mode 100644 index a6ce4bd..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c7/3015ce54d22e001511a3ba75618c68e5 +++ /dev/null @@ -1,98 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //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"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(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(); - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c7/30e525880d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/30e525880d3e00151089cca86c5b1a99 new file mode 100644 index 0000000..2c323a3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/30e525880d3e00151089cca86c5b1a99 @@ -0,0 +1,435 @@ +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)"); + //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())) + System.out.println("PlayerName: "+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/c7/404ceb6dff3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/404ceb6dff3d00151c31fb33fff4337f new file mode 100644 index 0000000..8a9dc0b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/404ceb6dff3d00151c31fb33fff4337f @@ -0,0 +1,75 @@ +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/6023b583002f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/6023b583002f001511a3ba75618c68e5 deleted file mode 100644 index 0b43c2e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c7/6023b583002f001511a3ba75618c68e5 +++ /dev/null @@ -1,51 +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; - -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 - { - 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\"}]}}}]"; - Packet packet = new PacketPlayOutChat(ChatSerializer.a(json), true); - ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet); - } - //System.out.println("Added player "+p.getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i 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/c7/d05586b7fe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/d05586b7fe3d00151c31fb33fff4337f new file mode 100644 index 0000000..51a39bf --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/d05586b7fe3d00151c31fb33fff4337f @@ -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; + if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + 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.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); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(PluginMain.AcceptedPlayers.contains(player.getName())) + PluginMain.AcceptedPlayers.remove(player.getName()); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + 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"); + } + 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) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + 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/c7/e0524424f92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/e0524424f92e001511a3ba75618c68e5 deleted file mode 100644 index 645df56..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c7/e0524424f92e001511a3ba75618c68e5 +++ /dev/null @@ -1,386 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - ArrayList Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length)) //TODO - { - //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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c7/f00aad3f023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/f00aad3f023e00151c31fb33fff4337f new file mode 100644 index 0000000..02b2d98 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/f00aad3f023e00151c31fb33fff4337f @@ -0,0 +1,125 @@ +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(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); + } + 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 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"); + } + 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(MaybeOfflinePlayer p : MaybeOfflinePlayer.AllPlayers.values()) + { + if(p.Flair!=null) + { + String flair=p.Flair; + PluginMain.RemovePlayerDisplayFlairFinal(, 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/c7/f0d24c00f82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c7/f0d24c00f82e001511a3ba75618c68e5 deleted file mode 100644 index f2d8a31..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c7/f0d24c00f82e001511a3ba75618c68e5 +++ /dev/null @@ -1,108 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //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"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(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) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } - private static void D -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c8/2097812fd22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c8/2097812fd22e001511a3ba75618c68e5 deleted file mode 100644 index b26a2c5..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c8/2097812fd22e001511a3ba75618c68e5 +++ /dev/null @@ -1,335 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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(0, dname.indexOf(flair))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c9/70756544052f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/c9/70756544052f001511a3ba75618c68e5 deleted file mode 100644 index c5f649b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c9/70756544052f001511a3ba75618c68e5 +++ /dev/null @@ -1,397 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c9/a00609beac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/c9/a00609beac2b00151fa6e49f3e10bf0b deleted file mode 100644 index 6f23405..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/c9/a00609beac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,260 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - for(string player : AcceptedPlayers) - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/c9/d03887b7013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/c9/d03887b7013e00151c31fb33fff4337f new file mode 100644 index 0000000..d412cf3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/c9/d03887b7013e00151c31fb33fff4337f @@ -0,0 +1,418 @@ +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/ca/10df867da42b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/ca/10df867da42b00151fa6e49f3e10bf0b deleted file mode 100644 index 4cec69d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ca/10df867da42b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,42 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - PluginMain.IgnoredPlayers.add(player.getName()); - break; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ca/c067eb62d32e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ca/c067eb62d32e001511a3ba75618c68e5 deleted file mode 100644 index 50e6399..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ca/c067eb62d32e001511a3ba75618c68e5 +++ /dev/null @@ -1,335 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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)+2, dname.indexOf(flair))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/cb/a082a1d5a82b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/cb/a082a1d5a82b00151fa6e49f3e10bf0b deleted file mode 100644 index 488de41..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/cb/a082a1d5a82b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,49 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName().substring(0, 5)); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/cb/e00c8ff2f32e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/cb/e00c8ff2f32e001511a3ba75618c68e5 deleted file mode 100644 index d86ae2f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/cb/e00c8ff2f32e001511a3ba75618c68e5 +++ /dev/null @@ -1,382 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/cc/10137161ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/cc/10137161ef2e001511a3ba75618c68e5 deleted file mode 100644 index e75cd9b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/cc/10137161ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,343 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/cc/10d57c5c0d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/cc/10d57c5c0d3e00151089cca86c5b1a99 new file mode 100644 index 0000000..efac5c3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/cc/10d57c5c0d3e00151089cca86c5b1a99 @@ -0,0 +1,434 @@ +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)"); + //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(); //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/cc/306aac51cf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/cc/306aac51cf2e001511a3ba75618c68e5 deleted file mode 100644 index 81ec138..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/cc/306aac51cf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,92 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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": - if(player.isOp()) - { - try - { - File 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(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - } - } - catch(Exception e) - { - - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/6f/e053c88a032f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/cc/505a3848f63d00151c31fb33fff4337f similarity index 95% rename from .metadata/.plugins/org.eclipse.core.resources/.history/6f/e053c88a032f001511a3ba75618c68e5 rename to .metadata/.plugins/org.eclipse.core.resources/.history/cc/505a3848f63d00151c31fb33fff4337f index 0cb17d7..a181e3f 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/6f/e053c88a032f001511a3ba75618c68e5 +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/cc/505a3848f63d00151c31fb33fff4337f @@ -17,7 +17,7 @@ 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. + if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); else { //2015.07.20. @@ -47,12 +47,13 @@ public class PlayerListener implements Listener @EventHandler public void onPlayerChat(AsyncPlayerChatEvent event) { - + event.setFormat(event.getFormat()); } 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); diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/cc/60cf3d08f22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/cc/60cf3d08f22e001511a3ba75618c68e5 deleted file mode 100644 index 54fc22f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/cc/60cf3d08f22e001511a3ba75618c68e5 +++ /dev/null @@ -1,373 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - System.out.println("B"); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ce/10db96ee9a2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/ce/10db96ee9a2b00151fa6e49f3e10bf0b deleted file mode 100644 index 2805734..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ce/10db96ee9a2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,38 +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; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - System.out.println("Added player "+event.getPlayer().getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - - { - if(player.getName()==event.getPlayer().getName()) - { - PluginMain.Players.remove(player); - System.out.println("Removed player "+event.getPlayer().getName()); - } - } - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ce/500d093f033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ce/500d093f033e00151c31fb33fff4337f new file mode 100644 index 0000000..fa02e2a --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ce/500d093f033e00151c31fb33fff4337f @@ -0,0 +1,77 @@ +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. + if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + 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/ce/60e64a99f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ce/60e64a99f63d00151c31fb33fff4337f new file mode 100644 index 0000000..2ef29ec --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ce/60e64a99f63d00151c31fb33fff4337f @@ -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(); + 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/ab/60ddb85af82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ce/d00a337efe3d00151c31fb33fff4337f similarity index 81% rename from .metadata/.plugins/org.eclipse.core.resources/.history/ab/60ddb85af82e001511a3ba75618c68e5 rename to .metadata/.plugins/org.eclipse.core.resources/.history/ce/d00a337efe3d00151c31fb33fff4337f index 507c71c..5660588 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ab/60ddb85af82e001511a3ba75618c68e5 +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ce/d00a337efe3d00151c31fb33fff4337f @@ -28,12 +28,16 @@ public class Commands implements CommandExecutor { { if(PluginMain.IgnoredPlayers.contains(player.getName())) PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) { - String flair=PluginMain.PlayerFlairs.get(player.getName()); + //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()); + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. player.sendMessage("§6Your flair has been set:§r "+flair); } else @@ -44,7 +48,8 @@ public class Commands implements CommandExecutor { { if(PluginMain.AcceptedPlayers.contains(player.getName())) PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(p.IgnoredFlair) { PluginMain.IgnoredPlayers.add(player.getName()); //String dname=player.getDisplayName(); @@ -97,13 +102,18 @@ public class Commands implements CommandExecutor { PluginMain.AppendPlayerDisplayFlairFinal(p, flair); } } - player.sendMessage("§6Reloaded config file.§r"); + 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); - player.sendMessage("§cAn error occured. See console for details.§r"); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); } } else diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ce/d07741ef023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ce/d07741ef023e00151c31fb33fff4337f new file mode 100644 index 0000000..a6a1d5d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ce/d07741ef023e00151c31fb33fff4337f @@ -0,0 +1,419 @@ +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 new file mode 100644 index 0000000..1d416db --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/cf/40c8a91f043e00151c31fb33fff4337f @@ -0,0 +1,427 @@ +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/509e01bffe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/cf/509e01bffe3d00151c31fb33fff4337f new file mode 100644 index 0000000..6224020 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/cf/509e01bffe3d00151c31fb33fff4337f @@ -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; + if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + 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.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); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(PluginMain.AcceptedPlayers.contains(player.getName())) + PluginMain.AcceptedPlayers.remove(player.getName()); + 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"); + } + 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) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + 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/cf/50fc0176fd3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/cf/50fc0176fd3d00151c31fb33fff4337f new file mode 100644 index 0000000..6913c61 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/cf/50fc0176fd3d00151c31fb33fff4337f @@ -0,0 +1,27 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + 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/d/10091b68922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/d/10091b68922b00151fa6e49f3e10bf0b deleted file mode 100644 index 3104167..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d/10091b68922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,13 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.util.function.Predicate; - -public class MyPredicate implements Predicate -{ - @Override - public boolean test(T arg0) { - // TODO Auto-generated method stub - return false; - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d/a0a4134fd42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/d/a0a4134fd42e001511a3ba75618c68e5 deleted file mode 100644 index 89db76b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d/a0a4134fd42e001511a3ba75618c68e5 +++ /dev/null @@ -1,335 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d/f0722227012f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/d/f0722227012f001511a3ba75618c68e5 deleted file mode 100644 index a8af32e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d/f0722227012f001511a3ba75618c68e5 +++ /dev/null @@ -1,63 +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; - -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 - { - 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\"}]}}}]"; - p.sendTitle(json, ""; - } - //System.out.println("Added player "+p.getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d0/40969eebfc3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/d0/40969eebfc3d00151c31fb33fff4337f new file mode 100644 index 0000000..fbd73ba --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d0/40969eebfc3d00151c31fb33fff4337f @@ -0,0 +1,19 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer { + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static void AddPlayer(String playername) + { + AllPlayers.put(playername, new MaybeOfflinePlayer()); + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d0/60e816e10d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/d0/60e816e10d3e00151089cca86c5b1a99 new file mode 100644 index 0000000..018017c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d0/60e816e10d3e00151089cca86c5b1a99 @@ -0,0 +1,82 @@ +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. + 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. + String flair=MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName()).Flair; //2015.08.08. + if(flair==null) + flair=""; //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/d0/90ea12feac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/d0/90ea12feac2b00151fa6e49f3e10bf0b deleted file mode 100644 index ffd6703..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d0/90ea12feac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,265 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d0/a0b7202ba92b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/d0/a0b7202ba92b00151fa6e49f3e10bf0b deleted file mode 100644 index a810f00..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d0/a0b7202ba92b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,55 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - player.sendMessage("§6You have ignored this request. You can still use /u accept though.§r"); - break; - } - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d0/e00161a0f72e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/d0/e00161a0f72e001511a3ba75618c68e5 deleted file mode 100644 index fb7f1e5..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d0/e00161a0f72e001511a3ba75618c68e5 +++ /dev/null @@ -1,385 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d0/e03bfec4f12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/d0/e03bfec4f12e001511a3ba75618c68e5 deleted file mode 100644 index db10046..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d0/e03bfec4f12e001511a3ba75618c68e5 +++ /dev/null @@ -1,371 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d1/1064daeba32b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/d1/1064daeba32b00151fa6e49f3e10bf0b deleted file mode 100644 index 99dd0e4..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d1/1064daeba32b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,35 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - } - switch(args[0]) - { - case "accept": - PluginMain.AcceptedPlayers.add(player.getName()); - player.setDisplayName(player.getDisplayName()+PluginMain.PlayerFlairs.get(player.getName())); - break; - case "ignore": - break; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d1/50a093b2d12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/d1/50a093b2d12e001511a3ba75618c68e5 deleted file mode 100644 index 9005f94..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d1/50a093b2d12e001511a3ba75618c68e5 +++ /dev/null @@ -1,328 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List towns = TownyUniverse.getDataSource().getTowns(); - try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - return town.getName(); - } catch (Exception e) { - return ""; - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d1/706be4b5f12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/d1/706be4b5f12e001511a3ba75618c68e5 deleted file mode 100644 index 932715f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d1/706be4b5f12e001511a3ba75618c68e5 +++ /dev/null @@ -1,373 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - if(finalflair.length()>0) //<-- 2015.07.20. - { - - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d2/a0f5e567cf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/d2/a0f5e567cf2e001511a3ba75618c68e5 deleted file mode 100644 index b395558..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d2/a0f5e567cf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,93 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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": - if(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(); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d2/d0f664fd013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/d2/d0f664fd013e00151c31fb33fff4337f new file mode 100644 index 0000000..b72a527 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d2/d0f664fd013e00151c31fb33fff4337f @@ -0,0 +1,125 @@ +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=="") + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + 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); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + 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"); + } + 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) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + 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/d2/e0d75c1cf52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/d2/e0d75c1cf52e001511a3ba75618c68e5 deleted file mode 100644 index 632b739..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d2/e0d75c1cf52e001511a3ba75618c68e5 +++ /dev/null @@ -1,382 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d3/606f612ef92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/d3/606f612ef92e001511a3ba75618c68e5 deleted file mode 100644 index 85a20dc..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d3/606f612ef92e001511a3ba75618c68e5 +++ /dev/null @@ -1,389 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - ArrayList Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length)) //TODO - { - //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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d4/60100fb6043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/d4/60100fb6043e00151c31fb33fff4337f new file mode 100644 index 0000000..86f89f3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d4/60100fb6043e00151c31fb33fff4337f @@ -0,0 +1,81 @@ +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. + if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + //PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + 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. + String flair=MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName()).Flair; + 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/d4/906a60a69b2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/d4/906a60a69b2b00151fa6e49f3e10bf0b deleted file mode 100644 index 46bdd2a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d4/906a60a69b2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,43 +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; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - Player p=event.getPlayer(); - PluginMain.Players.add(event.getPlayer()); - event.getPlayer().setDisplayName(event.getPlayer().getDisplayName()+PluginMain.GetFlair(event.getPlayer())); - System.out.println("Added player "+event.getPlayer().getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i 1) //2015.07.15. - flair = flairdata[1]; - else - flair=""; - if (flair != "-1") - flair = flair + "s"; - else - flair = "non-presser"; - String flairclass; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d4/a0f792099b2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/d4/a0f792099b2b00151fa6e49f3e10bf0b deleted file mode 100644 index 4d1464d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d4/a0f792099b2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,39 +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; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - System.out.println("Added player "+event.getPlayer().getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i 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/607f4314033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/d5/607f4314033e00151c31fb33fff4337f new file mode 100644 index 0000000..6ca2c66 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d5/607f4314033e00151c31fb33fff4337f @@ -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.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/b0f64d23d22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/d5/b0f64d23d22e001511a3ba75618c68e5 deleted file mode 100644 index b26a2c5..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d5/b0f64d23d22e001511a3ba75618c68e5 +++ /dev/null @@ -1,335 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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(0, dname.indexOf(flair))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d5/d023b881073e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/d5/d023b881073e00151c31fb33fff4337f new file mode 100644 index 0000000..3d1d393 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d5/d023b881073e00151c31fb33fff4337f @@ -0,0 +1,429 @@ +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/201352cfac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/d6/201352cfac2b00151fa6e49f3e10bf0b deleted file mode 100644 index edc4fe2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d6/201352cfac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,265 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player.getName()+"\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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d6/d059d3b7fd3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/d6/d059d3b7fd3d00151c31fb33fff4337f new file mode 100644 index 0000000..3c5dbca --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d6/d059d3b7fd3d00151c31fb33fff4337f @@ -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; + 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/d6/e08d6864ff2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/d6/e08d6864ff2e001511a3ba75618c68e5 deleted file mode 100644 index 17fc5c8..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d6/e08d6864ff2e001511a3ba75618c68e5 +++ /dev/null @@ -1,49 +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; - -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 - { - 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\"}]}}}]"; - } - //System.out.println("Added player "+p.getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - for(int pos : Positions) - { - - } - } - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d7/c0293873043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/d7/c0293873043e00151c31fb33fff4337f new file mode 100644 index 0000000..cd04256 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d7/c0293873043e00151c31fb33fff4337f @@ -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]) + { + 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); + } + 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 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"); + } + 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(p.Flair!=null) + { + String flair=p.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/d7/d06d9fe5f93d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/d7/d06d9fe5f93d00151c31fb33fff4337f new file mode 100644 index 0000000..476dd34 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d7/d06d9fe5f93d00151c31fb33fff4337f @@ -0,0 +1,5 @@ +package tk.sznp.thebuttonautoflair; + +public class MaybeOfflinePlayer { + String PlayerName; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d8/f05418d3042f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/d8/f05418d3042f001511a3ba75618c68e5 deleted file mode 100644 index c5f649b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d8/f05418d3042f001511a3ba75618c68e5 +++ /dev/null @@ -1,397 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/d8/f0762d6f043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/d8/f0762d6f043e00151c31fb33fff4337f new file mode 100644 index 0000000..87c0c13 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/d8/f0762d6f043e00151c31fb33fff4337f @@ -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]) + { + 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); + } + 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 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"); + } + 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(p.Flair!=null) + { + String flair=p.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/a0effc8dcf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/d9/a0effc8dcf2e001511a3ba75618c68e5 deleted file mode 100644 index ae7069d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/d9/a0effc8dcf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,94 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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. - if(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(); - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/da/3015c517d22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/da/3015c517d22e001511a3ba75618c68e5 deleted file mode 100644 index ace2a3c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/da/3015c517d22e001511a3ba75618c68e5 +++ /dev/null @@ -1,334 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/da/60d0a320f52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/da/60d0a320f52e001511a3ba75618c68e5 deleted file mode 100644 index ea1b159..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/da/60d0a320f52e001511a3ba75618c68e5 +++ /dev/null @@ -1,382 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.substring(1).split("§"); - String displayname=player.getDisplayName(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/da/90595120922b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/da/90595120922b00151fa6e49f3e10bf0b deleted file mode 100644 index 01dd5bb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/da/90595120922b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,28 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - PluginMain.Players.removeIf(event.getPlayer().getName()); - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/da/a0ee8a65cf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/da/a0ee8a65cf2e001511a3ba75618c68e5 deleted file mode 100644 index 771250c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/da/a0ee8a65cf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,92 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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": - if(player.isOp()) - { - try - { - File 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(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/da/b01aba10d22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/da/b01aba10d22e001511a3ba75618c68e5 deleted file mode 100644 index 9de04f2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/da/b01aba10d22e001511a3ba75618c68e5 +++ /dev/null @@ -1,98 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //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"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(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(); - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/da/e028ee36ee2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/da/e028ee36ee2e001511a3ba75618c68e5 deleted file mode 100644 index d1f1142..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/da/e028ee36ee2e001511a3ba75618c68e5 +++ /dev/null @@ -1,338 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/da/f088765c0c3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/da/f088765c0c3e00151089cca86c5b1a99 new file mode 100644 index 0000000..f058cfe --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/da/f088765c0c3e00151089cca86c5b1a99 @@ -0,0 +1,433 @@ +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. + 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/db/600bbc16013e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/db/600bbc16013e00151c31fb33fff4337f new file mode 100644 index 0000000..b00988e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/db/600bbc16013e00151c31fb33fff4337f @@ -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; + if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + 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.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); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(p.AcceptedFlair) + p.AcceptedFlair=false; //2015.08.08. + 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"); + } + 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) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + 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/db/60525316f62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/db/60525316f62e001511a3ba75618c68e5 deleted file mode 100644 index f642bdd..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/db/60525316f62e001511a3ba75618c68e5 +++ /dev/null @@ -1,383 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/db/d0069951053e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/db/d0069951053e00151c31fb33fff4337f new file mode 100644 index 0000000..abdc7d1 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/db/d0069951053e00151c31fb33fff4337f @@ -0,0 +1,26 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.HashMap; + +public class MaybeOfflinePlayer +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String DisplayName; + public boolean HasFlair; + 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/db/e0afd61c022f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/db/e0afd61c022f001511a3ba75618c68e5 deleted file mode 100644 index 57d6080..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/db/e0afd61c022f001511a3ba75618c68e5 +++ /dev/null @@ -1,68 +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("ChatSerializer"); - private static Class nmsPacketPlayOutChat = Reflection.getNMSClass("PacketPlayOutChat"); - public static void sendRawMessage(Player player, String message) { - try { - System.out.println - Object handle = Reflection.getHandle(player); - Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle); - Object serialized = Reflection.getMethod(nmsChatSerializer, "a", String.class).invoke(null, message); - Object packet = nmsPacketPlayOutChat.getConstructor(Reflection.getNMSClass("IChatBaseComponent")).newInstance(serialized); - Reflection.getMethod(connection.getClass(), "sendPacket").invoke(connection, packet); - } catch (Exception e) { - e.printStackTrace(); - } - } - -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/db/e0beb2d9fa2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/db/e0beb2d9fa2e001511a3ba75618c68e5 deleted file mode 100644 index 631491a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/db/e0beb2d9fa2e001511a3ba75618c68e5 +++ /dev/null @@ -1,397 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/dc/20e486bcc52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/dc/20e486bcc52e001511a3ba75618c68e5 deleted file mode 100644 index 7d3ed8d..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/dc/20e486bcc52e001511a3ba75618c68e5 +++ /dev/null @@ -1,305 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.txt"); - try { - br.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/dc/50e028f2023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/dc/50e028f2023e00151c31fb33fff4337f new file mode 100644 index 0000000..6db15de --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/dc/50e028f2023e00151c31fb33fff4337f @@ -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.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/dc/d0bfbbf2bf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/dc/d0bfbbf2bf2e001511a3ba75618c68e5 deleted file mode 100644 index 0762826..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/dc/d0bfbbf2bf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,291 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - 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. - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/dd/200daaf7c52e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/dd/200daaf7c52e001511a3ba75618c68e5 deleted file mode 100644 index e4467b2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/dd/200daaf7c52e001511a3ba75618c68e5 +++ /dev/null @@ -1,315 +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; - -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", "")); - } - 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", "")); - } - 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(" "); - PlayerTowns.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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - try { - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/dd/20e88117c62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/dd/20e88117c62e001511a3ba75618c68e5 deleted file mode 100644 index 1c1913e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/dd/20e88117c62e001511a3ba75618c68e5 +++ /dev/null @@ -1,312 +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; - -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", "")); - } - 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", "")); - } - 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(" "); - PlayerTowns.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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - if() - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/dd/50875957023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/dd/50875957023e00151c31fb33fff4337f new file mode 100644 index 0000000..a6a1d5d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/dd/50875957023e00151c31fb33fff4337f @@ -0,0 +1,419 @@ +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/dd/a0d6be9fc42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/dd/a0d6be9fc42e001511a3ba75618c68e5 deleted file mode 100644 index 26cb915..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/dd/a0d6be9fc42e001511a3ba75618c68e5 +++ /dev/null @@ -1,294 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForClass(flairclass); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/dd/e083e020f82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/dd/e083e020f82e001511a3ba75618c68e5 deleted file mode 100644 index f1bc4e3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/dd/e083e020f82e001511a3ba75618c68e5 +++ /dev/null @@ -1,111 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //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"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - DoReload(); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } - private static void DoReload(Player player) - { - if(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) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - 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/de/10304fc2912b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/de/10304fc2912b00151fa6e49f3e10bf0b deleted file mode 100644 index 43e93df..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/de/10304fc2912b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,28 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/de/500da46afb3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/de/500da46afb3d00151c31fb33fff4337f new file mode 100644 index 0000000..5f100a3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/de/500da46afb3d00151c31fb33fff4337f @@ -0,0 +1,11 @@ +package tk.sznp.thebuttonautoflair; + +public class MaybeOfflinePlayer { + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/de/d037d008fa3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/de/d037d008fa3d00151c31fb33fff4337f new file mode 100644 index 0000000..a948ff8 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/de/d037d008fa3d00151c31fb33fff4337f @@ -0,0 +1,9 @@ +package tk.sznp.thebuttonautoflair; + +public class MaybeOfflinePlayer { + String PlayerName; + String UserName; + String Flair; + boolean AcceptedFlair; + boolean IgnoredFlair; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/de/f0a001d10d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/de/f0a001d10d3e00151089cca86c5b1a99 new file mode 100644 index 0000000..018017c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/de/f0a001d10d3e00151089cca86c5b1a99 @@ -0,0 +1,82 @@ +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. + 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. + String flair=MaybeOfflinePlayer.AllPlayers.get(event.getPlayer().getName()).Flair; //2015.08.08. + if(flair==null) + flair=""; //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/df/300c6d49c02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/df/300c6d49c02e001511a3ba75618c68e5 deleted file mode 100644 index 345b5ff..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/df/300c6d49c02e001511a3ba75618c68e5 +++ /dev/null @@ -1,292 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - player.setDisplayName(player.getDisplayName()+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/df/40c1de71cf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/df/40c1de71cf2e001511a3ba75618c68e5 deleted file mode 100644 index 67e9a37..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/df/40c1de71cf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,94 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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. - if(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(); - - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/df/a0feec31ad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/df/a0feec31ad2b00151fa6e49f3e10bf0b deleted file mode 100644 index 0bde836..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/df/a0feec31ad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,267 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - for(String player : IgnoredPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsignored.txt", true)); - bw.write(player+"\n"); - bw.close();blue - } 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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/df/c06a7eb00d3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/df/c06a7eb00d3e00151089cca86c5b1a99 new file mode 100644 index 0000000..efac5c3 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/df/c06a7eb00d3e00151089cca86c5b1a99 @@ -0,0 +1,434 @@ +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)"); + //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(); //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/df/c0aa55450c3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/df/c0aa55450c3e00151089cca86c5b1a99 new file mode 100644 index 0000000..7b905e7 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/df/c0aa55450c3e00151089cca86c5b1a99 @@ -0,0 +1,432 @@ +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/df/d01c41c0f63d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/df/d01c41c0f63d00151c31fb33fff4337f new file mode 100644 index 0000000..3c6c00f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/df/d01c41c0f63d00151c31fb33fff4337f @@ -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(); + 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/20950642c92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/e/20950642c92e001511a3ba75618c68e5 deleted file mode 100644 index 42da296..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e/20950642c92e001511a3ba75618c68e5 +++ /dev/null @@ -1,333 +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.List; -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.Towny; -import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { - //List towns = TownyUniverse.getDataSource().getTowns(); - try { - Town town = WorldCoord.parseWorldCoord(player).getTownBlock().getTown(); - return town.getName(); - } catch (NotRegisteredException e) { - return ""; - } - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e/e0fe31e9033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/e/e0fe31e9033e00151c31fb33fff4337f new file mode 100644 index 0000000..3fc50f1 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e/e0fe31e9033e00151c31fb33fff4337f @@ -0,0 +1,425 @@ +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/61/60e73961f82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/e1/3009907cfe3d00151c31fb33fff4337f similarity index 83% rename from .metadata/.plugins/org.eclipse.core.resources/.history/61/60e73961f82e001511a3ba75618c68e5 rename to .metadata/.plugins/org.eclipse.core.resources/.history/e1/3009907cfe3d00151c31fb33fff4337f index 9aa3be7..22c5797 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/61/60e73961f82e001511a3ba75618c68e5 +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e1/3009907cfe3d00151c31fb33fff4337f @@ -28,12 +28,16 @@ public class Commands implements CommandExecutor { { if(PluginMain.IgnoredPlayers.contains(player.getName())) PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + //if(!PluginMain.AcceptedPlayers.contains(player.getName())) + if(!p.AcceptedFlair) { - String flair=PluginMain.PlayerFlairs.get(player.getName()); + //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()); + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. player.sendMessage("§6Your flair has been set:§r "+flair); } else @@ -44,6 +48,7 @@ public class Commands implements CommandExecutor { { if(PluginMain.AcceptedPlayers.contains(player.getName())) PluginMain.AcceptedPlayers.remove(player.getName()); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); if(!PluginMain.IgnoredPlayers.contains(player.getName())) { PluginMain.IgnoredPlayers.add(player.getName()); @@ -97,8 +102,9 @@ public class Commands implements CommandExecutor { PluginMain.AppendPlayerDisplayFlairFinal(p, flair); } } + String msg="§6Reloaded config file.§r"; if(player!=null) - player.sendMessage("§6Reloaded config file.§r"); + player.sendMessage(msg); else System.out.println(msg); } @@ -106,7 +112,8 @@ public class Commands implements CommandExecutor { catch(Exception e) { System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); + if(player!=null) + player.sendMessage("§cAn error occured. See console for details.§r"); } } else diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e1/a0985d119b2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/e1/a0985d119b2b00151fa6e49f3e10bf0b deleted file mode 100644 index 2799a0f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e1/a0985d119b2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,41 +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; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - System.out.println("Added player "+event.getPlayer().getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i 1) //2015.07.15. - flair = flairdata[1]; - else - flair=""; - if (flair != "-1") - flair = flair + "s"; - else - flair = "non-presser"; - String flairclass; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e1/d020d619fa3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/e1/d020d619fa3d00151c31fb33fff4337f new file mode 100644 index 0000000..8f85bbd --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e1/d020d619fa3d00151c31fb33fff4337f @@ -0,0 +1,10 @@ +package tk.sznp.thebuttonautoflair; + +public class MaybeOfflinePlayer { + String PlayerName; + String UserName; + String Flair; + boolean AcceptedFlair; + boolean IgnoredFlair; + String TownColors; +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e1/e0d02fe9ed2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/e1/e0d02fe9ed2e001511a3ba75618c68e5 deleted file mode 100644 index e0c4ba7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e1/e0d02fe9ed2e001511a3ba75618c68e5 +++ /dev/null @@ -1,336 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e2/30cf0cc0c82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/e2/30cf0cc0c82e001511a3ba75618c68e5 deleted file mode 100644 index 56b2e71..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e2/30cf0cc0c82e001511a3ba75618c68e5 +++ /dev/null @@ -1,325 +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.List; -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.Towny; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - List towns = TownyUniverse.getDataSource().getTowns(); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e2/60b2fa130a3e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/e2/60b2fa130a3e00151c31fb33fff4337f new file mode 100644 index 0000000..962d1ac --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e2/60b2fa130a3e00151c31fb33fff4337f @@ -0,0 +1,431 @@ +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/e2/e09936ccef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/e2/e09936ccef2e001511a3ba75618c68e5 deleted file mode 100644 index cbee395..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e2/e09936ccef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,347 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - - } - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e3/90184b440c3e00151089cca86c5b1a99 b/.metadata/.plugins/org.eclipse.core.resources/.history/e3/90184b440c3e00151089cca86c5b1a99 new file mode 100644 index 0000000..9ada4e2 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e3/90184b440c3e00151089cca86c5b1a99 @@ -0,0 +1,431 @@ +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/e3/a0978eb0c82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/e3/a0978eb0c82e001511a3ba75618c68e5 deleted file mode 100644 index 7dc19bb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e3/a0978eb0c82e001511a3ba75618c68e5 +++ /dev/null @@ -1,324 +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.Towny; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - TownyUniverse.getDataSource().getTowns(); - getPlugin()).getTownyInstance() - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/64/705f43f0042f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/e3/d08eed38f63d00151c31fb33fff4337f similarity index 96% rename from .metadata/.plugins/org.eclipse.core.resources/.history/64/705f43f0042f001511a3ba75618c68e5 rename to .metadata/.plugins/org.eclipse.core.resources/.history/e3/d08eed38f63d00151c31fb33fff4337f index 073e89c..33f1fce 100644 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/64/705f43f0042f001511a3ba75618c68e5 +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e3/d08eed38f63d00151c31fb33fff4337f @@ -17,7 +17,7 @@ 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. + if(PluginMain.PlayerUserNames.containsKey(p.getName())) //<-- 2015.07.20. PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); else { //2015.07.20. @@ -47,7 +47,7 @@ public class PlayerListener implements Listener @EventHandler public void onPlayerChat(AsyncPlayerChatEvent event) { - + event.getFormat(); } private static Class nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e4/20573e85ad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/e4/20573e85ad2b00151fa6e49f3e10bf0b deleted file mode 100644 index 4c116de..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e4/20573e85ad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,270 +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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e4/50af645b023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/e4/50af645b023e00151c31fb33fff4337f new file mode 100644 index 0000000..f2a51ac --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e4/50af645b023e00151c31fb33fff4337f @@ -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.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/e5/607d36ccf02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/e5/607d36ccf02e001511a3ba75618c68e5 deleted file mode 100644 index 48601d9..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e5/607d36ccf02e001511a3ba75618c68e5 +++ /dev/null @@ -1,355 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e5/60d93450f93d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/e5/60d93450f93d00151c31fb33fff4337f new file mode 100644 index 0000000..6051f6c --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e5/60d93450f93d00151c31fb33fff4337f @@ -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(); + 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/e5/e039cfb8f22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/e5/e039cfb8f22e001511a3ba75618c68e5 deleted file mode 100644 index 92ad0d2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e5/e039cfb8f22e001511a3ba75618c68e5 +++ /dev/null @@ -1,381 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e6/7092210c0a3e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/e6/7092210c0a3e00151c31fb33fff4337f new file mode 100644 index 0000000..efbefe2 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e6/7092210c0a3e00151c31fb33fff4337f @@ -0,0 +1,431 @@ +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/e6/a040ea06ad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/e6/a040ea06ad2b00151fa6e49f3e10bf0b deleted file mode 100644 index a9b3bbb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e6/a040ea06ad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,268 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - FileWriter fw; - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - } - for(String player : AcceptedPlayers) - { - try { - BufferedWriter bw=new BufferedWriter(new FileWriter("flairsaccepted.txt", true)); - bw.write(player+"\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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e6/c0b7626f043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/e6/c0b7626f043e00151c31fb33fff4337f new file mode 100644 index 0000000..87c0c13 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e6/c0b7626f043e00151c31fb33fff4337f @@ -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]) + { + 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); + } + 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 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"); + } + 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(p.Flair!=null) + { + String flair=p.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/e6/d0c6108f083e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/e6/d0c6108f083e00151c31fb33fff4337f new file mode 100644 index 0000000..f174b9f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e6/d0c6108f083e00151c31fb33fff4337f @@ -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.HasFlair) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + 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); + } + 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 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"); + } + 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/e6/e09fc270f02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/e6/e09fc270f02e001511a3ba75618c68e5 deleted file mode 100644 index 74f40d7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e6/e09fc270f02e001511a3ba75618c68e5 +++ /dev/null @@ -1,353 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e7/d06d6706fd3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/e7/d06d6706fd3d00151c31fb33fff4337f new file mode 100644 index 0000000..ec14e74 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e7/d06d6706fd3d00151c31fb33fff4337f @@ -0,0 +1,24 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer { + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static void AddPlayer(String playername) + { + if(!AllPlayers.contains(playername)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e8/10533cf0ad2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/e8/10533cf0ad2b00151fa6e49f3e10bf0b deleted file mode 100644 index bfd2e56..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e8/10533cf0ad2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,276 +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; - -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", "")); - } - br.close(); - } - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.close(); - fw = new FileWriter("flairsignored.txt"); - fw.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() - { - for(String player : AcceptedPlayers) - { - 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(String player : IgnoredPlayers) - { - File file=new File("flairsignored.txt"); - if(file.exists()) - { - 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. - { - 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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e8/207d10c3f52a00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/e8/207d10c3f52a00151fa6e49f3e10bf0b deleted file mode 100644 index d243776..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e8/207d10c3f52a00151fa6e49f3e10bf0b +++ /dev/null @@ -1,6 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 -org.eclipse.jdt.core.compiler.compliance=1.4 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning -org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning -org.eclipse.jdt.core.compiler.source=1.3 diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/e8/e08ce196093e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/e8/e08ce196093e00151c31fb33fff4337f new file mode 100644 index 0000000..6eec9c9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/e8/e08ce196093e00151c31fb33fff4337f @@ -0,0 +1,430 @@ +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 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/e9/a0aad154902b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/e9/a0aad154902b00151fa6e49f3e10bf0b deleted file mode 100644 index c9898ce..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/e9/a0aad154902b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,21 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerJoinEvent; - -public class PlayerListener implements Listener -{ - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ea/40a8228bfe3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ea/40a8228bfe3d00151c31fb33fff4337f new file mode 100644 index 0000000..fe7d591 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ea/40a8228bfe3d00151c31fb33fff4337f @@ -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; + if(!PluginMain.PlayerFlairs.containsKey(player.getName())) + { + player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); + return true; + } + switch(args[0]) + { + 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.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); + } + else + player.sendMessage("§cYou already have this user's flair.§r"); + break; + } + case "ignore": + { + if(PluginMain.AcceptedPlayers.contains(player.getName())) + PluginMain.AcceptedPlayers.remove(player.getName()); + MaybeOfflinePlayer p=MaybeOfflinePlayer.AllPlayers.get(player.getName()); + if(!p.IgnoredFlair) + { + p.IgnoredFlair=true; + //String dname=player.getDisplayName(); + String flair=PluginMain.PlayerFlairs.get(player.getName()); + //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"); + } + 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) + { + if(PluginMain.PlayerFlairs.containsKey(p.getName())) + { + String flair=PluginMain.PlayerFlairs.get(p.getName()); + 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/ea/5018d788033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ea/5018d788033e00151c31fb33fff4337f new file mode 100644 index 0000000..3892cd9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ea/5018d788033e00151c31fb33fff4337f @@ -0,0 +1,81 @@ +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. + if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + //PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); + { + MaybeOfflinePlayer mp = MaybeOfflinePlayer.AllPlayers.get(p.getName()); + PluginMain.AppendPlayerDisplayFlair(player, p, 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. + 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/ea/a085533dcf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ea/a085533dcf2e001511a3ba75618c68e5 deleted file mode 100644 index 7134c94..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ea/a085533dcf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,85 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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": - if(player.isOp()) - { - 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(); - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ea/d0facaee052f001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ea/d0facaee052f001511a3ba75618c68e5 deleted file mode 100644 index 009fd12..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ea/d0facaee052f001511a3ba75618c68e5 +++ /dev/null @@ -1,398 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/eb/a0999107ac2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/eb/a0999107ac2b00151fa6e49f3e10bf0b deleted file mode 100644 index 6b5772f..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/eb/a0999107ac2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,245 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -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; - -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 { - BufferedReader br=new BufferedReader(new FileReader("flairsaccepted.txt")); - String line; - while ((line = br.readLine()) != null) - { - AcceptedPlayers.add(line.replace("\n", "")); - } - br.close(); - br=new BufferedReader(new FileReader("flairsignored.txt")); - while ((line = br.readLine()) != null) - { - IgnoredPlayers.add(line.replace("\n", "")); - } - br.close(); - FileWriter fw; - fw = new FileWriter("flairsaccepted.txt"); - fw.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() - { - 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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ec/30fe1899d22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ec/30fe1899d22e001511a3ba75618c68e5 deleted file mode 100644 index cac4a74..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ec/30fe1899d22e001511a3ba75618c68e5 +++ /dev/null @@ -1,100 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //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"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - if(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) - ; - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - player.sendMessage("§cAn error occured. See console for details.§r"); - } - } - else - player.sendMessage("§cYou need to be OP to use this command.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ec/90418517a72b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/ec/90418517a72b00151fa6e49f3e10bf0b deleted file mode 100644 index 96a6182..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ec/90418517a72b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,47 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ec/c098ba41033e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ec/c098ba41033e00151c31fb33fff4337f new file mode 100644 index 0000000..bcc675e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ec/c098ba41033e00151c31fb33fff4337f @@ -0,0 +1,77 @@ +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)); + if(MaybeOfflinePlayer.AllPlayers.containsKey(p.getName())) //<-- 2015.08.08. + 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/ec/c0d3c395fc3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ec/c0d3c395fc3d00151c31fb33fff4337f new file mode 100644 index 0000000..455b8df --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ec/c0d3c395fc3d00151c31fb33fff4337f @@ -0,0 +1,19 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer { + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static void AddPlayer(String username) + { + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ec/d0cc5971043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/ec/d0cc5971043e00151c31fb33fff4337f new file mode 100644 index 0000000..87c0c13 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/ec/d0cc5971043e00151c31fb33fff4337f @@ -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]) + { + 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); + } + 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 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"); + } + 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(p.Flair!=null) + { + String flair=p.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/ed/e0feb053f22e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ed/e0feb053f22e001511a3ba75618c68e5 deleted file mode 100644 index ad75455..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ed/e0feb053f22e001511a3ba75618c68e5 +++ /dev/null @@ -1,378 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ed/f09acb29f62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ed/f09acb29f62e001511a3ba75618c68e5 deleted file mode 100644 index 82303dc..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ed/f09acb29f62e001511a3ba75618c68e5 +++ /dev/null @@ -1,383 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f/30dc59d9c82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/f/30dc59d9c82e001511a3ba75618c68e5 deleted file mode 100644 index 5f1d24a..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f/30dc59d9c82e001511a3ba75618c68e5 +++ /dev/null @@ -1,326 +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.List; -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.Towny; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - //List towns = TownyUniverse.getDataSource().getTowns(); - TownyUniverse.getDataSource().get - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f/4081c9edc12e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/f/4081c9edc12e001511a3ba75618c68e5 deleted file mode 100644 index 99bad29..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f/4081c9edc12e001511a3ba75618c68e5 +++ /dev/null @@ -1,294 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForClass(flairclass); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f/902d449b9b2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/f/902d449b9b2b00151fa6e49f3e10bf0b deleted file mode 100644 index 395fad3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f/902d449b9b2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,42 +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; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - event.getPlayer().setDisplayName(event.getPlayer().getDisplayName()+""); - System.out.println("Added player "+event.getPlayer().getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(String playername) - { - new Class<1, 2>(); - getPlugin()).getTownyInstance() - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f0/d01b9bcffc3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/f0/d01b9bcffc3d00151c31fb33fff4337f new file mode 100644 index 0000000..6737bc4 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f0/d01b9bcffc3d00151c31fb33fff4337f @@ -0,0 +1,19 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer { + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static void AddPlayer(String playername) + { + + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f0/e006e534f82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/f0/e006e534f82e001511a3ba75618c68e5 deleted file mode 100644 index 9463dc6..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f0/e006e534f82e001511a3ba75618c68e5 +++ /dev/null @@ -1,112 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //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"); - } - 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) - { - if(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) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - 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/f1/5056a305043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/f1/5056a305043e00151c31fb33fff4337f new file mode 100644 index 0000000..277ee06 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f1/5056a305043e00151c31fb33fff4337f @@ -0,0 +1,426 @@ +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 new file mode 100644 index 0000000..7fba36b --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f1/d02f5a6dff3d00151c31fb33fff4337f @@ -0,0 +1,76 @@ +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/f2/e0fcf2d8f02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/f2/e0fcf2d8f02e001511a3ba75618c68e5 deleted file mode 100644 index b6b91b4..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f2/e0fcf2d8f02e001511a3ba75618c68e5 +++ /dev/null @@ -1,356 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f3/102d06a3fe2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/f3/102d06a3fe2e001511a3ba75618c68e5 deleted file mode 100644 index 48efb04..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f3/102d06a3fe2e001511a3ba75618c68e5 +++ /dev/null @@ -1,47 +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; - -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 - p.sendRawMessage("§6Hi! If you'd like your flair displayed ingame, write your Minecraft name to [this thread].§r"); - //System.out.println("Added player "+p.getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f4/100cd858cf2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/f4/100cd858cf2e001511a3ba75618c68e5 deleted file mode 100644 index bd4bfa3..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f4/100cd858cf2e001511a3ba75618c68e5 +++ /dev/null @@ -1,92 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(dname.substring(0, dname.indexOf(flair))); - 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": - if(player.isOp()) - { - try - { - File 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(" "); - PluginMain.TownColors.put(s[0], s[1]); - } - br.close(); - } - } - catch(Exception e) - { - - } - } - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f4/908b5426932b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/f4/908b5426932b00151fa6e49f3e10bf0b deleted file mode 100644 index 15c1ace..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f4/908b5426932b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,37 +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; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - System.out.println("Added player "+event.getPlayer().getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - for(Player player : PluginMain.Players) - { - if(player.getName()==event.getPlayer().getName()) - { - PluginMain.Players.remove(player); - System.out.println("Added player "+event.getPlayer().getName()); - } - } - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f4/d034285bfd3d00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/f4/d034285bfd3d00151c31fb33fff4337f new file mode 100644 index 0000000..8538c44 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/f4/d034285bfd3d00151c31fb33fff4337f @@ -0,0 +1,25 @@ +package tk.sznp.thebuttonautoflair; + +import java.util.ArrayList; +import java.util.HashMap; + +public class MaybeOfflinePlayer +{ //2015.08.08. + public String PlayerName; + public String UserName; + public String Flair; + public boolean AcceptedFlair; + public boolean IgnoredFlair; + public String TownColors; + public String DisplayName; + public static HashMap AllPlayers=new HashMap<>(); //2015.08.08. + public static void AddPlayer(String playername) + { + if(!AllPlayers.containsKey(playername)) + { + MaybeOfflinePlayer player=new MaybeOfflinePlayer(); + player.PlayerName=playername; + AllPlayers.put(playername, player); + } + } +} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f5/606e09ccfa2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/f5/606e09ccfa2e001511a3ba75618c68e5 deleted file mode 100644 index 17c8cb7..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f5/606e09ccfa2e001511a3ba75618c68e5 +++ /dev/null @@ -1,393 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - Thread.currentThread().sleep(5000); //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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f6/20de0123932b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/f6/20de0123932b00151fa6e49f3e10bf0b deleted file mode 100644 index cfb22cd..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f6/20de0123932b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,36 +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; - -public class PlayerListener implements Listener -{ //2015.07.16. - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - PluginMain.Players.add(event.getPlayer()); - System.out.println("Added player "+event.getPlayer()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - for(Player player : PluginMain.Players) - { - if(player.getName()==event.getPlayer().getName()) - { - PluginMain.Players.remove(player); - } - } - } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) - { - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f6/a065bef2c42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/f6/a065bef2c42e001511a3ba75618c68e5 deleted file mode 100644 index a0e0892..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f6/a065bef2c42e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.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); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f7/20ed419eaf2b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/f7/20ed419eaf2b00151fa6e49f3e10bf0b deleted file mode 100644 index 995da41..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f7/20ed419eaf2b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,286 +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; - -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", "")); - } - 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", "")); - } - 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) - { - - } - for(String player : AcceptedPlayers) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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; - if(flairdata.length>1) - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - player.setDisplayName(player.getDisplayName()+flair); - else - player.sendMessage("§9Are you Reddit user "+username+"?§r §6Type /u accept or /u ignore§r"); - - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f7/30fdd3fbc42e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/f7/30fdd3fbc42e001511a3ba75618c68e5 deleted file mode 100644 index 8335a11..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f7/30fdd3fbc42e001511a3ba75618c68e5 +++ /dev/null @@ -1,307 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - File file=new File("autoflairconfig.ini"); - try { - BufferedReader bw=new BufferedReader(new FileWriter(file, true)); - bw.write(player+"\n"); - bw.close(); - } catch (IOException e) { - System.out.println("Error!\n"+e); - } - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f7/60d64f66fd2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/f7/60d64f66fd2e001511a3ba75618c68e5 deleted file mode 100644 index d67f6da..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f7/60d64f66fd2e001511a3ba75618c68e5 +++ /dev/null @@ -1,44 +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; - -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)); - PluginMain.AppendPlayerDisplayFlair(p, PluginMain.PlayerUserNames.get(p.getName()), PluginMain.GetFlair(p)); - //System.out.println("Added player "+p.getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i 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/f8/20e60535a72b00151fa6e49f3e10bf0b b/.metadata/.plugins/org.eclipse.core.resources/.history/f8/20e60535a72b00151fa6e49f3e10bf0b deleted file mode 100644 index 80d6ebb..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f8/20e60535a72b00151fa6e49f3e10bf0b +++ /dev/null @@ -1,48 +0,0 @@ -package tk.sznp.thebuttonautoflair; - -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.add(player.getName()); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - player.setDisplayName(player.getDisplayName()+flair); - player.sendMessage("§6Your flair has been set:§r "+flair); - break; - case "ignore": - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.add(player.getName()); - player.sendMessage("§6You have ignored this request. You can still use /u accept.§r"); - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f8/e0c1b81ef82e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/f8/e0c1b81ef82e001511a3ba75618c68e5 deleted file mode 100644 index d17c526..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f8/e0c1b81ef82e001511a3ba75618c68e5 +++ /dev/null @@ -1,110 +0,0 @@ -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; - if(!PluginMain.PlayerFlairs.containsKey(player.getName())) - { - player.sendMessage("Error: You need to write your username to the reddit thread at /r/TheButtonMinecraft"); - return true; - } - switch(args[0]) - { - case "accept": - { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(player.getName())) - { - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //player.setDisplayName(player.getDisplayName()+flair); - PluginMain.AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. - PluginMain.AcceptedPlayers.add(player.getName()); - player.sendMessage("§6Your flair has been set:§r "+flair); - } - else - player.sendMessage("§cYou already have this user's flair.§r"); - break; - } - case "ignore": - { - if(PluginMain.AcceptedPlayers.contains(player.getName())) - PluginMain.AcceptedPlayers.remove(player.getName()); - if(!PluginMain.IgnoredPlayers.contains(player.getName())) - { - PluginMain.IgnoredPlayers.add(player.getName()); - //String dname=player.getDisplayName(); - String flair=PluginMain.PlayerFlairs.get(player.getName()); - //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"); - } - else - player.sendMessage("§cYou already ignored this request.§r"); - break; - } - case "reload": //2015.07.20. - break; - default: - return false; - } - return true; - } - - // If the player (or console) uses our command correct, we can return true - return false; - } - private static void DoReload(Player player) - { - if(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) - { - if(PluginMain.PlayerFlairs.containsKey(p.getName())) - { - String flair=PluginMain.PlayerFlairs.get(p.getName()); - PluginMain.RemovePlayerDisplayFlairFinal(p, flair); - PluginMain.AppendPlayerDisplayFlairFinal(p, flair); - } - } - player.sendMessage("§6Reloaded config file.§r"); - } - } - catch(Exception e) - { - System.out.println("Error!\n"+e); - 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/f9/6022dfe8f92e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/f9/6022dfe8f92e001511a3ba75618c68e5 deleted file mode 100644 index f25382b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f9/6022dfe8f92e001511a3ba75618c68e5 +++ /dev/null @@ -1,391 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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(); - ArrayList Positions=new ArrayList<>(); - //System.out.println("B"); - for(int i=0; i=colors.length)) //TODO - { - //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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/f9/60a3e283fd2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/f9/60a3e283fd2e001511a3ba75618c68e5 deleted file mode 100644 index 91276c6..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/f9/60a3e283fd2e001511a3ba75618c68e5 +++ /dev/null @@ -1,45 +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; - -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)); - //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/fb/6086a867ee2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/fb/6086a867ee2e001511a3ba75618c68e5 deleted file mode 100644 index 8458bae..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/fb/6086a867ee2e001511a3ba75618c68e5 +++ /dev/null @@ -1,338 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList(); - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/fb/806b4e4ac02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/fb/806b4e4ac02e001511a3ba75618c68e5 deleted file mode 100644 index 27b8fb2..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/fb/806b4e4ac02e001511a3ba75618c68e5 +++ /dev/null @@ -1,292 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/fb/b0ab4825c62e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/fb/b0ab4825c62e001511a3ba75618c68e5 deleted file mode 100644 index e3ae66e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/fb/b0ab4825c62e001511a3ba75618c68e5 +++ /dev/null @@ -1,313 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { - if() - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/fc/3086b133c72e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/fc/3086b133c72e001511a3ba75618c68e5 deleted file mode 100644 index ab2c50c..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/fc/3086b133c72e001511a3ba75618c68e5 +++ /dev/null @@ -1,314 +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; - -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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(PlayerTowns.get(player.getName())); - player.setDisplayName(color+player.getDisplayName()+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/fc/50e6e65e043e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/fc/50e6e65e043e00151c31fb33fff4337f new file mode 100644 index 0000000..fb4f19d --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/fc/50e6e65e043e00151c31fb33fff4337f @@ -0,0 +1,125 @@ +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(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); + } + 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 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"); + } + 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()) + { + if(p.Flair!=null) + { + String flair=p.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/fd/80dba9e9f02e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/fd/80dba9e9f02e001511a3ba75618c68e5 deleted file mode 100644 index 01cd525..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/fd/80dba9e9f02e001511a3ba75618c68e5 +++ /dev/null @@ -1,360 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/fe/50283165ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/fe/50283165ef2e001511a3ba75618c68e5 deleted file mode 100644 index e75cd9b..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/fe/50283165ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,343 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/fe/50e0facf023e00151c31fb33fff4337f b/.metadata/.plugins/org.eclipse.core.resources/.history/fe/50e0facf023e00151c31fb33fff4337f new file mode 100644 index 0000000..ff19301 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.history/fe/50e0facf023e00151c31fb33fff4337f @@ -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.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/fe/e0151cd4ef2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/fe/e0151cd4ef2e001511a3ba75618c68e5 deleted file mode 100644 index 071c147..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/fe/e0151cd4ef2e001511a3ba75618c68e5 +++ /dev/null @@ -1,347 +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", "")); - } - 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", "")); - } - 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) - { - 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(String player : IgnoredPlayers) - { - 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. - { - 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); - } - - 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; - default: - finalflair=""; - break; - } - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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. - String color = GetColorForTown(GetPlayerTown(player)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - ArrayList Positions=new ArrayList<>(); - for(int i=0; i=colors.length) - { - player.setDisplayName() - } - player.setDisplayName(color+displayname+"§r"+flair); - } - - public static String GetColorForTown(String townname) - { //2015.07.20. - if(TownColors.containsKey(townname)) - return TownColors.get(townname); - return ""; - } - - public static String GetPlayerTown(Player player) - { //2015.07.20. - //List 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))); - } -} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.history/ff/60ae02e4fe2e001511a3ba75618c68e5 b/.metadata/.plugins/org.eclipse.core.resources/.history/ff/60ae02e4fe2e001511a3ba75618c68e5 deleted file mode 100644 index e0c395e..0000000 --- a/.metadata/.plugins/org.eclipse.core.resources/.history/ff/60ae02e4fe2e001511a3ba75618c68e5 +++ /dev/null @@ -1,47 +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; - -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 - p.sendRawMessage("[\"\",{\"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\"}]}}}]"); - //System.out.println("Added player "+p.getName()); - } - - @EventHandler - public void onPlayerLeave(PlayerQuitEvent event) - { - //for(Player player : PluginMain.Players) - for(int i=0; i 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); - } - - 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; - 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())) - return; - if(AcceptedPlayers.contains(player.getName())) - //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)); //TODO: Multiple colors put on first capital letters - String[] colors = color.split("§"); - String displayname=player.getDisplayName(); - 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))); - } -} 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 00c7e0d4fb965939bd21e10b45f41956d891c13b..1253ec8ad8c6db053a75de6169f668d2efcd4ee5 100644 GIT binary patch delta 5 Mcmcb>YB0e700s#G#sB~S literal 720 gcmZ?R*xjhShe1S2b=vdAllRFvjPggrV+f}Q0OS=fb^rhX 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 00c7e0d4fb965939bd21e10b45f41956d891c13b..1253ec8ad8c6db053a75de6169f668d2efcd4ee5 100644 GIT binary patch delta 5 Mcmcb>YB0e700s#G#sB~S literal 720 gcmZ?R*xjhShe1S2b=vdAllRFvjPggrV+f}Q0OS=fb^rhX diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.indexes/af/history.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.indexes/af/history.index deleted file mode 100644 index b414196be899b9f327c5e0cd0033540d8a7da2ff..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 118 zcmZQ#U|?WmP}SEfPAw_P%u6rU&o4^XOHIznEGSOZ%StKHOU^G!)hj4UO)F+#J`mu! zoll!VRDRi$`E~;PxtIL4p5({Kz_4KLy(lImah9@|6G7q%wE~B~Y9Z8zg}nfa0|3|} BCw2e; 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 7cac1ac6156659e8bc9aec19068bfc489d8d7a50..f6e515887cd4807c24eb85a70b5ee1bc4b115405 100644 GIT binary patch literal 4779 zcmajhc~BH*8V2xzC336?CTb9HAs!VB(c#b)k4O`0gl%Uh_ zo77u0hM61GscMA}*SsLlVWDEYr~gpk$fLll07d_pa2tg}Ut5=rK6cw($;IevTJ$X= zeUkG|*8|W6uP(}uDqa2x^f&rmq5R%8Z=-Xr5;Hmf+$I%$VmY~Lt2qUIb2!U8RV1JnyiLwc4U0oJTMyElvwWh_ zpO%yJ+v?v(UwYwlnm=u&J-UAjxu}gFg>F8^+^)kGy|R#85xRN!Iowafcyg||d;r}& zri|wFIM9Kvxb=6sw<~A&qyMR$T=Xa^Lcj08yg$>3-u%B(smHR%l!V^uTujgFHPk%> zbJooJgxvY?2K1bhg_4VhE>9YSd`1I4HEqE2Z)0g=i(E2+)dd@Lj}7G3CG!WK!8{>r$So;T`_W_m!g{m^Z=4vsz07C4Y|Sl7)N0kb zxMcdS39z0s@5covMEBF6=Uw-q_bw;5DEI9_pI&lD%Byz!grbiWwNuYv`(|7;E_!ld zTzWEkrjGgaAelFABv+jj4Vd@e!1}-aROUYMtS8r9<_#Kher8`1_ISs#o{Nz(&s33f z+a}1IU&;C#ViU2acLljMb%xAcB3OTPpAPf&;pCR4oifi}#`2SA$$WADCFwr-zP=dj zscB$-APjM0c56PLqr0C(OotT?O-#p8n`PzN{x_vKPAb zHI^^k>Va-K{vDlr!eunNDVxM3Su#087V`GG0V(IcOKEA^|qE?d#( zv@}Z2Ww}j5e|m(RfA{q_(5tgqe(@o9bbS)J&=&57J|~`B^~a_O=pTC3O6Q8dUTuB> zi?wkyIbUvb2K~e@HI!euqXGT(o@&YYxFHj|{dID#Y`e@IerEZ~*)pHr&0O=Jeb{5_ zA{VZIDD&1v)?YJu7v?|P$~^C44!TVox#$%5G5Xp_az95?271kGme2J{L+@^{qUSa1 z7977RB|bs7Or4-(D^9T8t9F8)kTv}gUA5!(5cHk=L&;V3gRh}G&ST!T z%N5;y61l$UjnU|kTsaNBHI$rdt@T0=GGCzn4=P_lw_n3NV(t)rtEt?`MeAKFde^Ju zuJ5_Z{POKKy3ZH>{g^jZl8X<=_n=1_=o?X$wP+l=Uktgpd&XGw6Q%U+$RF{2h^y>Q z5p#>r19UNqeQTzL{EFUPf0pjSGT4D$c(_?|)q^jx&{t^5t&@V&(9M_VUx0AK5`+H3 zDRTbHxM=jyGUoY_tI*rlvDI2tcnw!v))I2zz}z3v)icROKCTnJC$~wOUku7`K>t3Q z-11J}DRff?xymM3=5MBxo9cQ`Vm>H^oUfW9^IAP~ZPM46*T<8K%N@T$e@jiS@*G!> oUbm3t^E!{BuhO5UzstRdJ?NYRxyfM2L_cj$u5gc*xt96=0rB?p8UO$Q literal 13391 zcmajld0345|3C1gB9f_O3+HaLd{7e=l@byiOCd|@Fq2A~OexDb94+=G)1j!SNz1V$ z!{Nt~w22d?Bv}%J%G#nxQTblye!Z{j_w29p@8f!2&-d$ozo&cdW=2^_Nl8`7)O170 z8q?4K(+$4{NlZh1y*kV{pc z$DyaLX8HWSQuHtv=D%M#h@LctT)u4UZgeSgCELkoYs8`6bT*n??3SuO z;0%thXo&syY@|c063`Euk_%i8A3=XVnB}jRO3~%-KJq;R@teKqA4|w(mv-(%_c%!| z{j9bfJ!3laJzv(N8*8wBbvCP|0{2c2belx-@ZS{6 z(9P$NbBi>8MjyglY4U%aflHuxi+9L;zYU?@LEa&B435nq24i}eD(PyaUJDZ+@U1(O z0t_4;A*|NBp^BNus1Sc4uP zKrZ=K?TMbSmgNsm@9EwwpYTbHdGP@cT6cM7OE;|RG=W@{rCf_%e0L?yKiVn_-8+(8 zFi|ZPT`PGB^)GIV?Sg*&VCJt|qtS~!$whI62hbD7GEaRKghQ0^s781=bra6ME6P~7c7X=L$?{mdLmb1Sh^3G*$l-`bRK9*cy zefTB%tfAyeJB(hSXXZ50{7)9$M;~NGF7O?kgYFr~-X1Pio6&aw0gdWo2nFx?ixrg@bEo=?y!XABV+fVZ$0#q=FbSbCx!VFL&?K0xZgpaAM%{f z%g)?)MZY+@VR?C>zTwRGi;V&WG=zCYqKsSqHo)%z>J|&7=G;N19 zx_A}KtJRsKzh6Y&+`D}e`b$%mA6PaKz3*pJx-S27M(CE+i$S-jv zmk%7)j$Yzn!}rU?%PY|B-dU5MzLJN2Vi7s#aNsn0>^SB_wxpt;sk5T_yNAZ3hdrIj zJ2!io1U>E?xx8|VAG)oKV+2q281*g!fv&d!1OEb{N?<1ENUy-4ETaTvx%Hm^X&|lS$ zT&TS#20f|On9s|aIuD}H&LGdL8yAT_Z!1Xi zXV;-G&>)uwU+_oo>M)`?ztpWoPkYb2ai2H(gcNdV%!-xhyOPPdzXUzp=>)l8Uyd8* zU5_%?c)S9AnJ>A}KXVcKPIuN{d(jy^z15J;W$g3m=)>#CWjmMHq6e2S&wgQrzBQ2C zex}WM^c%xjen!zKba%hJGynd*bFZWW^WgO`#F_c;hx((x%e&6!?XR2)&xQQ$>TL2! zXMaJD@sHtMapl&#%W!7ly|Ai!lX>_j63Aqn5W0lz1K50YK}&K zmwuRfHnn~`3q2t-$z^BmeL!!{+`;GN)rJ>OLw@W2DC+U)*ooc{N-i_s6N#=KOwLVg zh(O=*HInb)tmm#r*Kdm;Up;az`pBu|vMbzpbe+I(J}(&4*&kioj$CHZrh=~eY&-QY z?A>+>uIu?Qa+%JW$LMeRFpo@mh<-KWcj{Sj?-sh27rF3D>UH!Tzl2i0Ue)4HSl4+D zxoqeOGjxrs8~D7;@s=L?gCuf+O2ZKJ&=brTUg_Zzj+0Ag?Cjx6iOlyq_wZ@)%p^nbjgF8D_Rj0!H-gAz5pe?SS*l6Sr7C)%hjxYV`yg1j;711R z+rgP@Xn%qpA4>xtY0dmm^ilK!k39Lj^yrQ~=sOOP3tsHnhVCsP=ge|Y^3)AIz=T}#D9i=DK*g5NH>dS8MBlgDhI$NMyzPK}2wp#xcge=?_2_;tEGeJ& zbrQN;KJ)cr6ZFcn%tsFykFLF)T(Q`}2tB33g6~)S_E{a>UrsLhnyrGqDvdmR>nmk+ zr;Fw^r{0^Q7m;mGGqDnids8%1+&+YyewK{$f)<*6LHco4bbk;e#hvlDvMGiYKz zbnD;A%k|c&qN^I}^7-aR#sfaXoS#DnQIE!EyNa&Ant9>P|A#)Pr9aK{^G_M*!z!3( zPftPL?b46(Gkkr}?>|(hIlJXc(4V{aC12HhIQstapwoherB4e(VRBjH_^po$jiHH3eo?*tIFpk z0kxOWw_ac#r?`MFT}$4a9G`)%U$0E-PQKxQJ~ofJXOkVe)oF6kfDJb2*(S_GbH}1f zmi6NM%V*^GLAQ=k;yt|j^t)!*hjE9KM(_CWgZ~#y zQ5IB=ZdFb$+GbgT9%IMycRDYlho0=_d&++@PC_?}CRZ5gB%(WMvwYULJ?N5qUDT6b zz775JW^zSxfdu{92=Z{9zdX^+2a}5eFN)Ecpq zrRW_CS^o5bS?H&SG9RR3gYKyIonKc}W2lARG5H&LhvugyIA6EK4)TFTPta#870Hx$8Ee+V z|NMjb!5M3?=TbDe{pfU0^uk@_0-aznx0L@ z9eVm6a#89jYxHs3nD2cx6`hM{p?O}r-fV=|Ps)i;3t0&>yZK7o?3k ziXO3;^~8^fLzn#BO#R17en&6XCl~EHwHE!;uqMi%Uo#zj&#OlAv5l7KR*~eQ6Vu0{ zkKE3Dc;OiIhA|C%kLbd()&|%ICl%%CG49-FrD|jwI4hmfWOkW<(+f?bqIRB3c1iw zpo1g!FgeiLROH1D6Z3_(1{jM@UsXP*0Esk8M zTQmfHg0VT@BUD{`^*+qQ{h*JIU1WzZqHAmG(>z%&W%nSzp@pM)nnLfOpS#)3fAlAl ztT|i^`PG-nIUS7{^seA8%7)XS-qX-W`;!Z&Y?y*xug7`< zBgdo1=6n-_lb0&G&x>!guF;h5 z|G@ri>P0Sm=Jo{rNoNP27v`UQjK1SCIp{7p)Xs(+<$*Ay7x@h<2va& z`lz;ceqGtoXgPXmB=bpaN$BM+U+B7?8XBN4bz;7xmp=Na@#Iox&k^VYRLEs&>j$I% zP<-b52td!#A(x3FmZA%*o9KEq74y*_+$QII-#DRj zmgK@+7bc^ppMFR4>}g$j3-%#Ak@?c%73hOq-ctU@)Y0gTPUP~lbB)oZj^r}i0weUA z?{D}X+2qy3(9@g9xwjER&?i>0eBWdp^a2x>4{GZug89$uljlVbYDfPvisc8K`HEgu zSI^HQENE#&kG@MT>u!3F{`-D%`K56$(bG4RbDN!>qmOi8`F6`H^rdZe{JMhuUU$$l zGRTG7?QWolCX#ctyRM_x9%lYgoQ=MFI_sGjnT2j`%Y3bI50A~OrSsiwn23450CIVS zK{R@qBe|^Cfj#J=z*lr#>iYKR4FTk`w4puxZ|2g!HG6oR7v+VG9d_7r!jAPMn^>XO znUHhG|FJ~hX7rMuNA6&tiT=ib-2Q*H1JL7`bALYS;ejJ4FUzjg!2B=$n9m*654}N^ z`GYWZ^reLgejefJ`9E&L>oz@yocl-8jh>Uq@?8(Uqvy$3es`~L=t+mk<%9dQqiY0{ z%e-&2plf=v{D4i(=mD0j-|+4`^qTS){QQcy%}>xnO31mWq#oY&Gr3IlRT1XR$FRJ@ zFArT<^qlX{bKG224;A6_HpKD;`Q`JjvBvI7ZO=$ea|SKUZP zZy3rv)Z{3-Wl;^iu53N`q2IVxPUpL@<3ItNZ^Gpg-ph5qH06UI{gd22qPPLw;o4n3 z&$S#cMt_h-?lNl0E%dS^a`~{pB6JhaJA9AqAH7)g;LXJ}&-TDz^y+Ek@{Z-c=+W^7 zd|s|P&>O!3UfPmRbB64hhd#fNTw3w|XLQf^HmHOZ?8ICvu>i2uE4!{#Lk5?Uwe$y z=RGf`T~Z64zl-BtF6(qdpLcxKG5)Lkh8aoc;j6K8;e%8r&cK zp&mK+y{s>K*k>8dSy!rzu5pfB7Weim{Z12Me^qjrS&6aLMpBTmbvFld!v~cD% zAAUpk)*$CToBN|*zLdz%DJ(CvKtGU3F6;hihVB(h&h6+FqUY>oc{2-B^uHt6Pdn`2 ztD)O@F?S18M$ef;E`6`vjX&YotQ$}Jsk68Y{g?java=wiZ)N$YcT)6u?T7j6mBq*OL0_d{{{3Tb^wMDF2AZw-)0Z#($+?=S*XX~g Qu)K}?EA*z3fAH)6AB>?_Qvd(} diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.indexes/e4/81/43/bf/history.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.indexes/e4/81/43/bf/history.index deleted file mode 100644 index 8a5584d7255bb8fc8eca90ed8be1cfc09ef77716..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 162 zcmZQ#U|?Wmu+%RuO4d(F)z8c;OU*0EEK5yK%uOxU4@u3*2}&$?EG^0RO)V}?Oi$Gh zN=?g2O)kmI&(q6FEK6iy`4G0klTn{RRB-XG(!`#Orx&+mukm998tXX+tN4R=$DNSX Tt1W=2H<-S_9$9?he26#z>SH=6 diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.indexes/e4/history.index b/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.indexes/e4/history.index deleted file mode 100644 index 24c595ff109e882e9b6c371b33118b777be7704f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 101 zcmZQ#U|?Wm5YaC#O4bibP0LA5F3HT#)5}UMOJrbX@SNkxsLvoOxOi7-Vo%1?i(9hS d_%SjtJa~8930Yii0Yuzj`T~1o@rCmt;s8w=A}Rm? diff --git a/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.markers b/.metadata/.plugins/org.eclipse.core.resources/.projects/TheButtonAutoFlair/.markers index 5f455b122a76be9803c6ad70efe1d6812545ff2e..1f85f2358df0e380f16e220855cfe0a4a1a47076 100644 GIT binary patch delta 349 zcmey)wugIyG85ayiK_oN{P}{`H8D8pPnKsAo9xI~!6bBP@@~dGEW$+$a+5zYiBF!y zB*{2$@){<6CR2;acbR4}Gq}MN%b6rrrWW~R7MG;vr55RBC6*;JFfcFzF%WP+12GsG zI2kyTGZKq}OA?Dpm>3wCzX6R;Vho)u$7E`Np*=bv2U(1P9i-JYF9oQP#T??G`qaF{ zq@2_gpy^yWnR%&xrMXF|ML-1%k__y*sl~;K>8Z>No<2Y+g`}d?#O#9n%)AmSRD%_w zL0YX8j7(z{bQSXRAhKRSl^O`9YguYui6(<&eo?w!YI06yL2;^HO6uhQOkRwdlf9T_ PMNpi|!06BSN{6v&IU}*iH7|vUfx%FE@XPi{2Mo-8lx#U#uFF>MXlwD};@ zm`p7vKjc`z#KR9aj%f+9aZFby?@`&nC9_>dAvjsk$%e^t)?|Mt879kllM`)4Cb#6O@XrI915$SxsE&!jZSqBC z)5)c!BAg%#fPnkiWI;_wCgyKI$0sp{PByeOoy=S%C>tG+lUSKr~+H&l+Z`$5Ql{R21w{{K?{9;=47DBLpt@6`wnw6Fbd^OA-nsL_^#tzSLP`JD(S~jh#4c(m0rauM zoNXI=cg{9;X|ig<7ZLb{pI9b}S`BkpB8sMFEh3#v+L9*cbS0(g!_rBU>@aj&R&`?b z$!40Es1D7~5X+K>NgeujPfpd6I4j#JY-Nd}4ynY#WRxg5TQzh{^byrG^bFB$yhk39 z5BIKbmo`fnp2#FvhF{&ldk*zlSk*0C)-;lYzp$Mm_>^I$t*opN_$1rxSj#q5#n#5K zVr1Z!>YxUPsc>sMrNUi{_mVJbu*e88ReLN7AS0+jGZZ+((Cg5G;xofH`(8K~+xhAj zKfJ-@cJRhC<1e4Oy4_2TJsxswvrMJUPPbX7^=unF^&k_o3}POlVs1O2<%U(g55y;( z1o-SxsMHZ!6-AO;>`6EuL=Fe;1$pmRtkd*9Bzy#u><)}g+;OLd20 z?y}Po#VnO#9(Q3rTKtUW)93HilkoJ5Q)m_cI1YC9wREod1p*0(&ad z?D^jkdsurcOZLebu!S{~%S0+Z996k*9JzG1iYiA%M}I<Tn2o+7XEEH9f zQBcOioEhI${2D8=t{XNUB-kXDp^d;;U>jJ*BeJPdMsU$VWHnj-9_bhsG5e*T-XAkI!=BdgJ9A(=slf zi0+BG9?@O<@gqRTQ4~zX7P`-2#6}~w{0RSSuq3p01wX>CZ4pNJH600>4S;+Mq+$+3 z_Cp_TcK^rGPZt&D6dsYJoIRtz1oA~qf}jSO}!NPTSQFSwEz za7S9*PCyIuu;1SP!L)d4rrF=(o3)%VS@NCo!`H8HDlwgmN$19yn=#4T--Uqf@0wtL z*9H4q-tO3+YDl~H_l_zgOH+u<-s%zh0ViDLK^?M8klvy>Nr+076dr_>V;T<`Cg#qi zsZW}#EL;o22c2drA%|%ir*y|MY5vnT$1tQsZNieLgGO@9ZJnFEt@EAh?^V${^J(M& zl1q#KSJT#cer{W56;-azVS)fuZi!OMD%Vt3zRI29IBQx1!j>67ApA1e0U-|Q$zquz zt_TCdy!Hf5_OlV-1VVq~q`Cg^7}Uu|F)>Y`e5ifdMw;kWE2bv^;X`%IX4NgrhH`|P z%eT9^d>Qk!Zan!~e%QN8i8fMZZZ>{Oz%nXeS=y1<*4#q}DX1tp!;F)n1z;a=z&7x} zT4|wCfI!;mnS(nzA6$&%#meC93gRlCdB@5ONrx{U~D@#BxucL zFqclNwv=UMVOHst_CSE=ln0xKiJkwe8077sm6NXidzvxEjCMeYEzUZRL4g)$SaB0i zoZnJ7D_*Fk(=sKiz&kf!ZYR`Q{ML-*?-cptk@qb zVyTA(mKqQQSJ$417wGmnhr5+$r3t#ltK+L%ags1fVzUAm3;W`5*tUq{PZi;KM8IJR zIA#Ld0=_D;EksE4r@p03GlR(*Q`H+I&+t-?JS#}KDIc)G>=RAet6DZwohB4{f>WKf z)MV65)_`G*8QR3r#b_*N5%(C4mbl00Q8q^Z_r)LOk;bXkAom#UgD0x-c%o+oJa@Jy zV1$*jvX&v{FgOxcfkJEu7RRK1`mYzpZ5&4bD@=|1Q+~MDRf4^ zNpPne_z&tT#Lt%Fl(}B@p6QCg>w;5DWrd$q?y5*CeS%cR1*v?#45=J3OfBi98TVBp z5_Ywz<+0L79szh=O{rQA*KThpKV177M_bbg*EWPRo@8KP$MS-h@wDWnT2{HHgXOE- z(`Bk$=hm5la^}{R{cX|+K$gsh=p(Rl(g`- z0wpb?<+h1R8zZI@VxdjqQ`(aj+KQJDlk@11o0V8n`$E?bpQ|D(g>I)aS+Xf~JFB&# zGITRTl`GEAtv?zSmw3`;oX$#3*-E2^sf$Z%|AiKU$7l8?Rhw2tfzG(eAW#scOV}`q zT;cr5j{f~S_a|^)PP0{*3*oqr7S85uT9zDAP0NNEfmyhqhM_KLL#+ZeWKGp5u1*%2 zJkm+)N*8)p{jQ3{9pK!EFj%YoU=7w=m$gXLr^wl|Rj{Lb1<$AW^8%#X+7ky1OQo}gJyC7+ zLp5>sRKQ9m02hFDFoo}#en(zZT*c|Vnr9D*A0i^LMsZbsLECps@xn` zIfr@X!8DV~Gk+~drmTW|wK`RhO|%MfvGJ|nR56SXYl&eku~y-$P(d7U>6a0HvYI}=$u8KoY7~6$*QM0jKQ)^B4pm@Ff9u(&|4{chVpJs69_L^k5 zQ04rVif^c4mGf+Sva5onAS-F&bXIk}mS*RxvffCEe!1Vs@rp297BIXf zU|3qfKox9%&ZaiurDc)>hdU}DWYZcDgJYw{yrn)GEE_dk?f~|fCa-Il$ro+dc=Mls% z3kdG(v#T@LonMLLlsKI=^Ip(;`QBIWy%^NXcqx$B`*g$XF!^8oGGRYS?uv-@)d|-a&x` zPgjKCpnzadKmbFfp0Pxyk-Z8?v-0~mca$9ELF$fMHpzC*$QRvsMd+Rr&|MPHeUhOo z8RflnZ7l#SInV>+^an0KC%_$|_uKsl{572oNesVWYui5 wOr^_COV(*UE7>VBn6qs|m*H!+$Njjo^Gctr>MToewD_54sHQMiC@h)zKiK2HqW}N^ 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 00c7e0d4fb965939bd21e10b45f41956d891c13b..1253ec8ad8c6db053a75de6169f668d2efcd4ee5 100644 GIT binary patch delta 5 Mcmcb>YB0e700s#G#sB~S literal 720 gcmZ?R*xjhShe1S2b=vdAllRFvjPggrV+f}Q0OS=fb^rhX diff --git a/.metadata/.plugins/org.eclipse.core.resources/.root/.markers.snap b/.metadata/.plugins/org.eclipse.core.resources/.root/.markers.snap index 00c7e0d4fb965939bd21e10b45f41956d891c13b..1253ec8ad8c6db053a75de6169f668d2efcd4ee5 100644 GIT binary patch delta 5 Mcmcb>YB0e700s#G#sB~S literal 720 gcmZ?R*xjhShe1S2b=vdAllRFvjPggrV+f}Q0OS=fb^rhX diff --git a/.metadata/.plugins/org.eclipse.core.resources/.root/2.tree b/.metadata/.plugins/org.eclipse.core.resources/.root/2.tree deleted file mode 100644 index 5edf4fd21ec3d745f1b84baa905b023a31907931..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3730 zcma)9OK%%h6h3|sB~Fv(i5kSBg+{cMVhIT$fe=!fqyp49X=2jyW-`8s$FV(TW}Mc2 z2o^|eS_!;}LykoYPc%zDWjG*H(eTaRL%C(l%rg`>6mJ2L$zok z4w^S@M^XQpT`ehR%5BxnN8u&}SF#+hHRXB+a+ro$R;5R=26P#Ie4SZc)`5XRNAn`F3^`h{9)ome-jE<7HtQTPj7p`G#Xxlc?k!EwxJX~5!>5_qt<+SF#q=Te;*2I2tF(0 zam;1as`Cs^hiN9{-k^APhtrfnnhvhLb9X`Rn-N?oMcImLM*;%4D1cG~s79!7X7+5* zL=HRcr*H4vyDq3TcwG0bOmt|*wl^#lL-$pn-4_xeux3@!%-5C|3e%2bv|>142no?O2kJ7) zoViP;YIv4ikKuhKJjB<$I@-p(`ItW6|5*quU18g7qH!iHtn%(TUT9XU2UG1`6DH7_ z`2iZ+hphn&X{|rQ-eIq+7uxG@xJAuva zUamK~fO7&k5dogWq2QI(s(&aLI26|WLm?VJq@9e=PGxCu#;( z;9r&T9ip+ts?kyo@B6rIxmC#hDB!E`Vcy$#suruwb*nyaSoP!2?$5V9Ir+NK+VD9U ze~I>XXfdQ^0iHs4e+b4YXiu);=gPNgRdjD8(CDozU;icWr{KdJQ_yJFF}ch7D8Py0 z+kkj>gB^_yaP6I+zLoo-1oO{x5sf|oJSPNpOT*O58qLQvvX2E-Mjp$h2pALX7l}^9 zhs|JG5jq%A=tK^1+OPtBzCb6U!!=^c3f3m7&xs@ewVg*FStbH`PNV>)?ScqWN1YRC zfNFaK4dYDM%87Vjw7n?@N1)Bg9N@IQB^(jh#5}-hds~E3>uVwlNNw+kP=-R2NCHsX zyHcL0Ya$0YZSN5cXmL$s0Hy8ysJ0Frc!+UZn}HWK*4D(h0BBo9^$}@Je!hMZs(wkMzdMK}<&^pnB(*sm;g8UDh%y#F2h zrviT!_}w*=;+EpuKa1dFjv7E?)E&{~sNK5t;Y(5ot9y@(KaWxOF4BtvWOe^O7^ijv fx&B{er4BR);lqWvbuCnPZVoP25)fU@imYT9$19LO&)=SkhloRxgc2Kv2jdDmOyCFlSKJm#%Z_6brsDRP#^h-h6KT0Z&CS)`}L&vRV(@u`DMtXq2m~u^5eHqm{_AHl9sEjNQ$lVt$IyH<8h~1{UhB@*44r&>5Ruo03X$$x+rUZL=D(sDEmSb z((0peQeKK{i5^R8MoZ?~9q!_7*R_GJ`2Wl#??)pjU29Q@1vsmeqY1)U6LFEcHNf!9%D_B~yd z?d)AU`wMeThlAg3#7$??FI_#GxJcege^XKK-*;8>0D(I`wZ zU46n3#Z&Vh!EI?eYPBV@OU9&VhtT|ad>8~i`)2k{?48_a-_pwQ=^w8nA*6?Nub%&k zD0eVxM>lTODqo^EhB2-osB>q%ewv}017T!-vP?E?0Q!n$@NSy_7!G@Utl3Tpzh>cM zMh07l5vh_zIj2%vfLJxJQk!evV22&-@he1WPpi=gnzguR9WR}t^N!|M@o|rO6h3mu zj>(`iC#UA;>tRz)*Mm;RzFpe&8v_Vz;wFB6Lx?dAP|(Oc(-#_jES^Ju8$Z8_S8}?( zvJf^WgRptS?LCA2sq$}@Qm`_6^DOqJi)BFnVkkgQ@c_;L5J9S~e3d(mI&6*TG?VaXosIK*tfd%qWgE+1?9xAbFLY(zsmwHG5u|Hs-YMOy z=NEI+R1fx|gT3U5K_^Yog$I);4pWw@V03)Oz30IcHRs`7Hd#vBUOWH457_2(*S2`r z$x=PShaKU}u-HObioK8NrS2X~G2@8$2`U$Hvc5oKS0TBZpK>usZ9`PsN}dqRa`jH+6No)3b?WSt z&p0tkAPgynQ%tTOCtL}{AeAa?hRLOzXeDr)Q>ns)+FS@i+i;&#!{hvt%Q*KwaYTp# zn_hAWsBC-E%`O}-oR=6s+lElHg|bVoU5Z7fAqEaQ$t9P8&Nf7A&Mo@ny>eMlBBVB= zJM}s0$T=;PRP%9>!i@osn8L zv%B~W_i<+xH*5A!NED-+GK=9tqkUI%0}U*&lOYVFg5Xr?r%6sgVg~}> zdz!iLBZ~E^7E~W7>hQmZE~C0E6x?bI8m{@)PK*1rIaQ5u&Qoqs^MFE0D?Y+8+jZAxgOam}dEOSdE-^#q&!_GMPli-PY}!;L9b5~P5?vBF7+Kl0*0*<+-NtK1S#g948gi(@MdI{ z1S#%K=3w7)xO}Ecf)wz724LI*xg~*1et&{Vx}}&MLe9?sf)w-| zdxFqi`i*WUSrJ< a=f017Q$??JhlVg|- UQN3kiXk}zfih5u$;8iaG0DG8PM*si- literal 36407 zcmeHQO>fgc5anE{H%=T-q>8KY?)oEMsZu4{3lawe2X4qs+~VLSk?pipoH)Y`i9f(E z;0!{X_$&N?9=R}1+$3(}P5ObNPom9@trw$y>**+IiJ)Z%S~%KOttWdgUbdty+|7+n5{2n*l;q*-L3(IK zog^M+k=2d%M~7BtkVe~iI-+@M#tpmCWYj^JWc9;RnsWJMc@!R5o#Skk8GGG)vdD6M z-Qp4U-VNh4%;Q17@-V$Dw|d!dGOciwZ#!P#DbH@#K3B2egE)yYYZRL;a6*$Ghe_NW z|L?Zh4#ldM+hJn-Wq*8hnw<8nJj~uMU*yzUv&S(S?0lJpv1DM|focc!V5!*GY=FXA zz3hB?^Vnk1NjU0v-o*XG6<%|7?)mrZZ*Dxc@-&LJW$ha;kQ@$UD<2G!to*lMul}Bm zee3zzr}y7ae((HmUo#uzs?KJf?Rwr;&S^x?4c*PW?CbfPdCsZBnTK8QIP>6&%auco zRy%i!JLGdKEc-T{uKc^Jdfl_ZWQUV>OW0c3+IE_?!>#ZdDj|42^xgF>u6(u{dU3(y zj8tTi!_`b%v6guSReYPr-s*-`v-CyV)NF6NiR%b0Jng#c;X11!VFl7qfxZ}%a1JmW25D4Z2<})t97v%}5h0-?AkJ!&M_KUW*1!Dj1rG6Xm{&8E3xu~$-^);!b z0`pneZ3gsnK!01SHEGO%;(2L4#Jv*2YUac@pfMGp$ai&y-n<`r~v`8USz#< zS+7f-MaX)Q^>WO5N$~MCi9c&`=mN|K%%`m6-%eL4rM#5*wt;?VKGVZxe5zeaOJ6IX zAIyg*^HG%eg82abOwsQH{m}d8kJa;GJ|58??Ren*;Qb7Fzo#8&K8tS_L9Ms(wO$hY zB^~cV>__Zp8T+ZfUj{%w(9aP4e$n3##dFb}YG6K%XFfhPcxoH5ABrbO#gouqP=7EV zFdvr8hb{sV=x|2t=NbFy;ziVY!TaYfk>*qFqC&60xn9(IdDeOf{hpTK{a`*knU9Mb zO;GEtd~t#k^Py^&!pTO&evYx9t}~$z>Y&pB=;w+4@%J{M_e1YzsQ0&vY8UQugW}0j z@oZ};sL2_zAF-ch?8oVrnwx*n<<|HvH#*owU#~!y8?s)WS+DEj9#7PIdDeRA(-m~3 z56<->_H&H=gnqik7J5I>&lCN^p++}oKG1v^YCd$Rmu@ly`Vsqi#(w3{MYf3ji2W>M QKlS(HWFu<5jj8qi1BULhF#rGn diff --git a/.metadata/.plugins/org.eclipse.core.resources/.snap b/.metadata/.plugins/org.eclipse.core.resources/.snap index 34c6aaec55bb2da9074e5fe3e65366f1ddca5c2a..8425340e87fe71934d9bc163ebee1a0c5d3ce809 100644 GIT binary patch literal 1898 zcmeH{ziSjh6vyAr9t!TA7cU1U7B>C>gMiH@$ zR%+}7u?gB}t3j-66+|sX5c~sDUgMh|{@`+MBHEc(y!S1>Z+70yXQ%mW<;J0Ps2@18 z`t{MBmj_EOA)teNG4*@)`lw1!Px-vhf;j35=1WEw{h%jcl(WTDvIb`&&3M2X3oM86 zVOBp#IRh_D<2K_BktacsZ`}IY5tn&GNQ&PGXwYHpqOQu1ZK(Af0LO8lcCo`wXHurg zR3_6iF^#xOz->i|>j04pm`mbH(#2Yn9oEuTiq=qDT^O68d5g`4VH_oFE~Yu-eh^b3 zaB-NzQ*&mkj_8^5B1>40S^W^8HWz2}Q8GiL>o1IW!j@SQfZ$Zse9BetwuX;^zKQ3>Mwg6=pkn8l&!&PPJBWC(fQJG>GVq=jihOCWc*BF}>l z)~d+cYxPPoc^P}d_x)pU*w{5M8x)G~y7gJYtLu*vjUAOx4zof1_tu9=J bqVBO)Pm9gmk8B`Rz#&m?6=R^XSn0sdqPZpF*!eyJ+Qxh z?mg$b`*m-U30v=7-sjI&*VFnw_}Rt>Ug(wM^>{2f#1QqaUvp|8{qJbgdKqOQft_TdN3@o*JIH?Y;2!#Vy-n>xN+(39pWNA%> zNv{X%%?*a5ONT_Fe#}wfuUHV6YeKbeJPfigEK3MsbuL{HxVSbN4b>FYMnjiW`GaAv z*J?YoqRJnMEb>PeK*tg|c`@~mtG_>uPdgv)r?A|^vb=MGHC~V9#hH=%#jO70YNaAN zvnt+17h&ZrjD%{MC~juOE;hxkovk(#CtanEgtUv4*)=&utUZ|Qu{_kW+D#0FDuV$B zz<5>~WCLIyJ1M|b!AR5r#2YOJ+CZ4G?PaB<#SZFZn=}W|ixe$^f6FKJ(okifCJ=T& zk#P*spI)SB(S#kZD4903C>-`Lb-<7=hB${_q$p?YLYT=nRs`4LM>>EGGpN7@!m&zF zNi-a+nePDF#h|loAQGm@Y--N>NwRV z2AydGVcHJG;n1Q0u3v|fdW<2xY>=}otM&BBMU$pXK7K9ST>KUOnTF`9-lg2lvf9ja z+|i9nOPoOvmT_F2pzVIvkFw(FHV}@?6Rose!)vTtSq-!6A-dyYk1VTM)I{+%R_w0T za4bG}qUeIa9O;St@I>>-6FI_sHrS~-R)>k9>S}+@+(`3vtYp6v%g z17W)Eoi9r-(E>w|ztii4)9+kdRXaaeGsPdQDHzdwKF{kCWrDHQMxCb+9 zcD!;it5U$xu+e7L?0BV!LByI|mNC}}v&Q4jnw`O4D1(wUekJFAgQ#TV@lTkx5yOr47OYnc$0>zzb>1}yGWtR%Q9k|+3D0A!60G}hj}q9Q|#IO^zW2;$(~V4E*O>$d+vadmdl=GE@aR4@6{qp7s3goKr}Lu zV9)k%8AK%D6iy7!6bbfhdqJ6(BtR6TQ7|GE5?ro8`ZZ@Aq?3#UZUuT`^J{$CRG@QO zV8Jsu7wCztl+9rXTb3t=H80Q;Tf?k~t6dK<+@(NIG%RB6%kZw#XZQ}c0zJ`C!+=X| z0PLfwKuUu=-@1I_5JL=!u3BMoqGzFrlG9Pc%$p%tRXovnDCf z6Ajv>QbMSg4fDDc=!ph>&BAdv0x)UP0zJ{tfe(>7BYG-WF%{^E2A$tduz|>39Iv&T zl{bm{8+oRSY#qJ;cc7 z1$tuZ@W7NboCdg3Vx(4;n&UZiNzsV6JY6HhH?+ipIwW`nMzSPuBf+7%S9#-!1Ue(aMQ!o~hw64Sh)6(T8bcs|&5S2F zRL5kLBv_)%_rD+=66}SMED795aJZDOH0cR+JzHTW!QoP!01^p`)Gi6^R%S?WxOk5; zDM@gvlKXE-g9NPx!$_6{ZX`ImWh?I?d4m2dqXaQ|f}>lWVnrfB3Cnk9iUdbDa|t9# zuv(cPurVDHP|VAcz>NgQUiR}I5(&6_El|FiNO0_BxC$CFCz!$Vy_q7xv6r4yCM5|T zQ1XCnsgQuXBy7fNMMd37M*_#^RbqLsx98K&$9o%=dt!5(o>z(Gy_Ks}s3g=wOl{T< zvnfv1Y9PQg=XO{uFLArl67%t{3yz>`I}CtZ7%mn8f?Oh!uZ%i{q>oIu5rkRI5y@Bfj6_+2G6Fpp z<~2qnUs(gAme^2~V$&@o=O-v*zA{~BQ9-1q!nE!Y$yc_8=ZV@Nn9~%I7Agq6ib|J= z4`K{&Fe5y>}0dvVOJhp1{Ek&Y`?X*HOwP8N}TGo~wb z!51_AC2C9&$ybKdM5-+&U6yg`$s&@kjPe@{v4~!zXbGIYIU@PWE@xG8P#T80O%cgg zb{T`vg=+*YN+%*sfT5EvB4y$s$5`JR_w!;CBRaE;&|%)#-d(?BRoYlD%OH|zV|#b~ ziWO;NH3%d+;Vzr|LykBR4jl3!N4lCZ+V(d+f;{lVzi*b$qQp7a^(lsqsu9j2kO&N9vE6Cbg0e|k(Uu=E)NS$-%P)5e_+zfVIl zEsteNoZX)biH$p5KL$Wd(;y_ynPA$uXZNY2kW9N*$?et}nKrJ+aK@a9)N;L&2M*6N z?dL`(!-qX$lIhBB9TCY zkQ-#i6MVh=EM;DLg6EYy_?=Wd0cFRw(Ta>@N#I6;BkMW86Lj(9tA$HOf+Op3)zgr5 z&RCWo&lCxctSeI{B?A=*9A*W>0Wz(@U&Ko?sHo z^_e2Uu}7oIq$I&dN*?z2bVz_&IZFb!FA#`(_ERx|Aw9tWmY+0|03c4^r6-uipcgVk zg1Bd2Z)H-F;NMCf{(TxGXia_ntS4~s1o1ZSzR7z?o}iFrgiu3H0MHw(NS=TiL>S`L zOp&0?+iYHv;5%i0#2e|5pc9N_N#I6;cH54rMV6jm9Lqb+Bxtwo2Ua8!=tcu}E+dIy zyxnvEROTfK`1nSqlM}S=27_4=xRIb+A9!&Zk_1I8BTq1Sf^L0wvLcaSKFjZ9iUi&I zv{ELC1o)ybIY!=;jwgVjED2n5f?k{G2@niPf=gJ2XE%|c*QTYcNF?B=1jGlKB0;am zUR35K338P@@}YD{a2kwcJ%O7iDERV5waAhLbf*zRz_Xi3Q1B%lc#(=k0=~m7_GXF% z1qX|jc}W6pNRCSB>pFhYCurRh2D2n^Bf+3Ce^U!CNpLmGZ<|RlXbfBh4Ot!Vjc$RP zOPR?D293#A<|PTbD0$T4bUeX87-_jAFx+#B53m1NEwH@1soTe!liYKP4_@2AFe)fY zSVk^qavp=%KFx~cJajbKp8{{(pS{6}3|7YF-Ocq%ZjWY%`+fBI;58n`P~t&}BgUxO zbeJ{_7P3rpcw!?yBC%SouXi?jNXvCSBH3qF;AX{VN)J|dQaA4$T5 zS*!fYtVK+is^r}3(%DrqnB7&^?{be{w?wx;X;(X`C8v)uW^Pxnt9?gw<(!U|tn|qNMS+P-rgoosKxX(Gp{cRfJ^ue))+^ z{0@Nm*A|jxFVz**Y>>D~H#RWn=%mMKTq*iNAu%;x`H5bsUnxzgeV5}(HA3`C5utd9 zyIohR8H}rCLW+A(2HRGOQWq=;|9}LJZm+U0sHKs^GI)I=KTDA$7*@~OqU=exIa|qX zJn39uPsoEjseX$orBBl(qh|OTyW8x`+li7XbHOlNs>>xxaTf5dmZr0-blW4F;<%?c z%bw6(5OO#})sl-xGP$eEp6IR2%4?NNt2S%X+11xt^sXlTWruiO$Jco$X;+7{ydhZ; zTz7=yh-{(MGVF-C2(CNAkwo^<)+vyuZ3+xZS_Id1v@ +content_assist_lru_history= content_assist_number_of_computers=21 content_assist_proposals_background=255,255,255 content_assist_proposals_foreground=0,0,0 diff --git a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jst.jsp.core.prefs b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jst.jsp.core.prefs index 592b8fe..66f87be 100644 --- a/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jst.jsp.core.prefs +++ b/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jst.jsp.core.prefs @@ -1,2 +1,2 @@ eclipse.preferences.version=1 -org.eclipse.jst.jsp.core.taglib.TaglibIndex=DIRTY +org.eclipse.jst.jsp.core.taglib.TaglibIndex=CLEAN diff --git a/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi b/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi index a3181bb..9b6a653 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 @@ -182,7 +182,7 @@ - + newtablook @@ -202,7 +202,7 @@ - + @@ -235,25 +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 + + + Editor org.eclipse.jdt.ui.CompilationUnitEditor removeOnHide @@ -312,7 +318,7 @@ categoryTag:General - + View categoryTag:General @@ -338,6 +344,7 @@ categoryTag:General + View categoryTag:General @@ -380,9 +387,15 @@ View categoryTag:Java - + + View categoryTag:Java + + ViewMenu + menuContribution:menu + + View @@ -407,18 +420,18 @@ Draggable - - - - - - - - - - - - + + + + + + + + + + + + toolbarSeparator @@ -426,38 +439,38 @@ Draggable - - - + + + Draggable - - + + Draggable - - + + Draggable - - + + Draggable - - - - + + + + Draggable - - - - + + + + Draggable @@ -467,20 +480,20 @@ Draggable - - - - + + + + Draggable - - - - - - - + + + + + + + Draggable @@ -498,15 +511,15 @@ Draggable - - - - - - - - - + + + + + + + + + toolbarSeparator @@ -518,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 f7782c801a78cde965948aacac7c998bacd8d0c9..3d68147e07078d1d55244c4ae488ae59c8e127b1 100644 GIT binary patch literal 16667 zcmb7L>v9~`c3yLzo{KJ)xS3G+z#(ub@L)sbT*5ggvMhs$EE!3LQ$>-g)=W!kd!~En z?y)R>k;)U~QBswM$OGgBlHU@RErDzScD}XN?#o2}xcy@f&KUw6XL z-f>#%&UV*nN3QQ(yk+09izRCK!A|Q|=zFcjt1D9_D*66x*O@C(am5XzCjNf9xp`x@ zM3qhdw&OVghOEyv)>apSz~0BWwRE@b^cf^x^4C}Je|c@|7IxvMjVN%votN;%31%x) z5+Haeei^t7y?P_?`%Vz;nk(qMmXG?(d}0Ft=DfwyUx}iihR!oGTU9-4O)wS zuV;Im@bwa%yKe7qIcwY7UDtDNbnSg7c)damePT2m?>E?Lu;Y5yZPz2Bf1~=26Y1ev zmoShoTU2tqPV4fMCr^%PDssZ;3%l!f+-Sdb31g>J!ir?>>kIuprt210-LQ{cukpFA zxt`q>CyGOH(KmEwkMmPP-71~aDe5&X?-Lp z);63-u#ooyD)SOETc7zLCsf16t0H4cnyE-|F!W^9ex#MlOx&wZ+wFm)@eVa630B*(_J|Cz<7x3>tG=j!!K3l19WH;O zlvPx-hmY4(gdfRHb>2zzrS$h|N7J-F8%Ij;Ye_`krodO0|LKgl)TzlVRh>RP8$6PPD7&K>-Z`c7AIcxyMA!Z2PyVEfqg&~;iv0R;+rph-19~59jfEe@Th8?P+9#O>;DM zjWLcTf_Z5qm5D-B0|mtJ8o?^>1$N&Y!V2A<+qE-xAQa=f=^L%V`n;8#oT+z8mgjHu z?Y1IvpQN~KTXYW-;3PjSTZF*t|6lr_w{#U9Szu%t56$)8$hbeV$22ju`uQfCkWxuL^289z&CEngf*Ar1_s@$ri zFmnpIszo*5TkT;)RNs+hCv4~&qfOucWveCAq}0IkM%?ZZ^WFjESjNM7He>1 zfgM4rm>Fl(WO-Qh;TRz^Jaj}=htX2@L1UxX+OusfmaTdtGsYyV=0w$@FzH;`E;mgU zs3ML%7JQbrwJVERX-k}cJg3S+4actJo=rTz;jE%t+O^{&&UD0zkDB+6v+LY#@3Ni) zuM?`+9Eb^$FmzxKe7L-wQn^0}ca2m}$K+mdY}Qb$Jp`5oYAkWksM-|BXm#z569jI@ z!S_`Kvg}5U`n8CC}Nr<>TW+DlXhu+rZNiSu9$DAzr~yaE+(aJk?}3 zP)7j5B`kZ8XpqRUdpxB9@^^S!cvHn)LvJD70o4||T^;8A741r(`3MFI1UV_VUWDg5 z5C`)cO(t$xg9HrMbQq+Vr;6*jk!yFc-F?b!F~ow^oS|GBk5-O3!^=_8wVHzLg zm~ui00#Fa{CzSIU3=qrp@las+xo`L>hhQ$pB6UDHCPyjXV61W~0_QUFWF+3evFr#w z9jOr0`61=@c$|^AiwB@BN;3`CwmH7ToJZ8?INSE1tD&<2^9JJ4UAT*nRlwgH&!1Rq zzo$BY+{o&8am(-Q%drb*k4OtTP8Tr%T%q(8h6Wi=OJa1 zy&;A)Cn|Epgl90KP=wmgQ`5wh8&D<@p?j3yR(&lGf^HZo`RdDSNdk)Xr84*qp+TOw z>+6hiqVomjcfF(88gD3=q}D~L!KlM_a+V`{t1dB%rA5kggR*yQ5FAz2`czsF7)AM+K9_YJ`zPt+4xRLjH;f)>)|8 z>NlEHQ+-c+%X(51lDRvc)p*st{)t-H~ zgIdQf-j1oTaQy}zj;MIYciEmW&4dCKHoyoU87f)u)>_~ zA5vL;K4yxnR!o9`_X-;*wucjn9r&#Fw5-VjZv>-N67>UI*lPG?qwFf)b*}0d|A-ks zQ}LRsG6*rKiAVnUuYVC{0r=-P*ETWhNGXyys76Mr=4saJg>aA2h7-UryWfiP98w`P zAweSzW54telY+g#oe zM<{dWxt?(Yp)O!$p`22_#|O*L&Qa;}n@bz17h3V#ww&ygid!hg$ToGRO&YFn?8%mF zCJsTeCalgF88o*BoCN7f_u|loquC~v7p0PiZ@*9>^80u|I=-a^6C4d-jE|i?hXgie zS_ktEsT2oQf_1?kuu91@Op561DK&4duOP(sw4R7%NLJKfd_Hg^i7EwFxwp^063@VR z7ysm`&`N{NKep+)L^f`83S)TAG(($^$7O@;4SJ zsnl%R0YYi}$X1 z*1nBLcx1j6!YR(h0b|BIRf^+H^YofJlxZ8@&LWxZUr*ipngQ{Sz zlR^|{HhLm~lK+%&NxtSDMsX0b$B zQATHFct}$YXfWbmSyh;wXP~Hf1vx7MeU>H-?bDzo6SvjUi$|z z+#^sX5jhc`Iuu zfoHgCRvkPc-PFW_bu`K1GpU%Y9JbgpG@P9b%S)#CB6Fe3_pKBCf!f9Gc|Ni5BJ6r!i-&dN^UV+e8gpl5l z9?;xaGGl7DQ)-@7u+3O@cTP}Y1{=fs@@OVQNQ0K-00yoqft(Xi>QvPljBIoOG!q+T z&UtRsoybg-kW!5@Yb9S1!!6K@9BwJy;ypplA82~WG|BNQT-HUNJOuPIX5&C<=#*e0 z)G#o)X8i*-(!#FJLP4dO$!6t*Khw05)>I61CT^h0jEcT-m}x?f_^xxD0DO1wh%93& zm6R5jq~qF4%sb{3JH2EopZ16hCv>)u8Q0(%eh9F!$_$(%Zpe9CSiIzpL4097@szSO zU&b-iti`Fb;iK>?b1?RXru-t*IidOSil3}S$&Xp4oMk!VEEHk%i<9zPfpv;LizGl1 z7!RmwZf6*PR>Bf;Wmt)HahOMZ6EhUxBC0U*Ms%Le8?teuN~_g^?Y^jeD~mZ$>j}Lc ze>dmZAD{GqUW+Gbc04}iF4S< zMxCZSU}%#zd`Pdxt68zfPxLeWF%kLJhzdLhVV0FcdLxF?^x)d)?%;+K%qTFimGNe>pI-}oboFpVIPTH~EGZaw~J-{|E(S>JC{Gdh3-QQ(EKLc

ta)F z;lv|)Nih_IKXRsD=vC3bWH>|R^9=ozX4sV_-<2It=;f^G82S1WU7DaZ&*lI3G{?Kc z*p9$^NG~Mra^%wkdOOkU=WcM1X4rR(fVd9||2H+w+ipY#{_)#EKi7QgNF~QMjkCkcU;t&*71RPA8 zdN_Q0l6lvNY$kAa;M-B`=Nr6GdO6U_;)Y-D0=p1NxdxYo5)$tjbhhHgJuZlu{mVT& zxNX9)EM;_qI!Ze$+7+h(*vx zyK9Hn(H64Qm4-23END&940g}tVTK#%Pjt{qBa=9K$E1JGbU5MFoG@u2WN;uW&*a*& zfitPCH0fTgYXUii9u81JYL**Glg@PCbU<@yNg4EDnA|EEqkWhY+P+4cH}6T8v#OY! z6ZdM9+m3MmV_2i?{uRw^DBPkCD=R3%0ZTgX5}U%{OtYM6J;p3aX=?$l^|+jx5WgX6 z8h+`bB~;j1M0we{3w<+O1cSKqFHWWmC$wdXU-Cs_%YyPd+8|NPmcBKHgnSv}V60F9 z9jnq1n`Bqa&kA~z?Nwu+co$h6E6h_mty!j^;9(RDxVSH?apfU(JzWaT0cqpXwoE{x zi)C>Wt4LmDZnWc^(ZQ)^-EhT;U~krftL}~)_m^tt9nV3vjazKFmzQ5bAqH+rQ!)nJ zxyZACwU~ic1!-BD)O|YI1}$f3rhV@gGI!I5lys<?rR ze7nXq3Rv(7U9aP^MKOArT*9)4pZ6jZ!4cV{;Qe`u3_u0N^6ncd0$n{y+ zxCXs~R!U?biZfcMAYk$`+VqN}prw+F{`k>D$kH#|;PS+dCEL=c$1--<( z>b=4E=By`~T%RTOoVHnNZ=QM!&{W*Ra04WJ1A!>K#7{-6={d4sy;spRBV)-mPT39D z`hwy;YP#V~bn6;N#BAnkV8BvsXE%PBd1rp0kb-+4wIOjs$yf*HbbAm4FwLe!rd|W~ zhC3C99cojI#|YZ+MV~r%O&Do51wng)ND*p^L%QJ&wB@^PBLr69^t-r)ND<}?{qO~7#+}y;LocMz$;9o7 z^Q=(DeQ7UG?16@UcEKm&vL_lA;%gxhDqM7JAu5!8%@z2}#I|<^fMEG4zaWuz7H*9Z zojag;SeSL_wG&2(V^>zpiY}y=U&f|pe*b`S=g5x&Mt+wAl0Af*5A}B;I2gnqxLJ^3 zj))9L%nu#-+@R;=j`H#5`dHwUtBDx#Ybj?nK!MCJHyAcH9{CXp2NZE~?x9IT?Jj)y zUgpPB=2#ON)1T4a&x>$^Io<%*#kfIsg3bLt$AJ6^a?HQ>FyRoWgzQA9joSuMgp*F-6ydkb^z4l>HwKv1r*uxrS#tEaK7##!ri+@HC6(;w6XTHH zjcpNrx%T||aM)a78r}K{z02p0>u-tfT`^J8-|bT%`{?U)Mpl;%z8 za+G$D=~dp*toUFEj1cQoYlfyYGXDLHUSj}yICdxFQ+}YAGiAlm6Z}H6TxuH~zW)p< z)zhXD>PwgOu#{R-tbDU|{(ryw4&r%A?`F%8!!i<6R#FC~*iZDk3|%HqmyQvgeoF7~ z^htse1JBGpqxX4sT8EtoA1Wu+B~zMxF^N@1N%ep(J_}sZlHZd43q9~7RPx_!(f@q+ z-Lvi00lkw{O=aI_TDN;oCj*}_*3i3phBLilnnW}skGA|4ObBrH42DdA4TDMT2g^WXjtvUDr?`0jtwbY{8E`P0V#0lb0#2mk;8 literal 16240 zcmb7LTX!7Cajv~zu!{>pOST+GvSrJ*j?C39v7MthhXg?i4hT>LX!#r;KMZyUz>tfb z^~@|UdXj%fenMXJBl47o{DLI!06`KmNSG4+eN{cPvkQ<^_(06|RCia`y{cb?Z98GNO?7glQ#Z- zy199Mp(3@-@U}njBMdcuyRp7@F^atV7;h}!>-s}3i66yltN6dVzI6+`@M$B7g2B$~ zc;iP4HL2(#cqo4!1zf#;Jqm|@l-$R2>G#)G=f@iXxwn(so%oBvu#@ciTcaci2ObWy z-S>j1vlQ;_d4pd3W<_SN_r3dmM1+aq53%fMCm3Awf`N$qS>|HJVl(`m*B|+v4=`A4 z%*o8azn3iaeQ(ft|M~OhN75LC8$+)P2>g5~3s?PQDeQ;Ql`z^2?+$c$U+TkAvOY{Y z9|GuDnn`G9?7WX<%hkqAD>ufi>V;ydT&-inG34Fj5$Gj1)5fOZOnIgb4?igV@{Z`?}G-w3UA007SRF52b}^m%>nKs$|Bz`OBbP zKlFO(dcb*KD!|#H_~s3NFTCR$6S2h*+`K{_UkL_YU+E00M+!8Fu}YH?zF3);W_&vs zUiace*FBU9sX#70mf0lap-nDzjhZrL76jScjeM_n%};j2UV1VER}oj}QlZ|EW{~)i zmxPf*ofspQp>T-NKeaphRvyr}GdIW>vK6hX-1Iw`mrD*cXRJ_hzM zAgS>n1_wgPxEzis1}TS|qd_WV0QpAVco7PnkMMq9=A-cLrZU7)7^BZ+elXhG@}X%t zIXRX_I80Wvl(bqrR8;PO)Zp>G`|uFt% zrMeeJW(SUBCKz;KGs#m!!%2Q>dQw!IS5tK%*uIM9nyzWnn&Du1khA*Ke`hR-vy2sT zY1gy84phs|vM+squ#@bX#RjV!nT(CCPrZ2Ms%fsFLXWt1Z6ogyXA?iB<^;Xe>OwaG zmQ(4JaMY?rj|PV5Q$7iq-7UeKqCJ3+2v>-;`#*b=o+*D{$FDM@RY zQJEv4C?ND?$3Q?|_ z;l;0d0r5|JZhle9G-4QO6pEF4qlGc4u7+K&?<+zjM5B0HmW6YRQcOaw)S8!bIPoV& ztoQ8CZxpp!?C(&*b#5hLfQlKVGBz)bqQ1f`C_m_0KQRMtQ!8CYb_!9xbaCw}=aB&A zr5mePF#Jq%6V1YL;)yg6FNAlg5Jav9A$A&tp9ue2i_*N_&xN1Gg>wij{kvvgIR}E@ z{4Jty15*?lB#YNYe1V@w(Bu0w76Di*bgC6ISH)KLnP2V~KaI#HZ zrE%cWXnR}HeJ=GhFj73ryZEP1B?tf~$)Z#fFM`_Wa1F@`vk~G^Yn_wA7M{wbMtfcg zT|DMwqd;8B*tIPM!q+#aidbP@>WH0U zf72uVo=AZ*^H>Ud051wQ9pLwo6jTuDTOd_&Vq#PH6M#wu1fB(wlzc9bD-}pA7*pV3 z_oZOK)s6c|PPlA|*ca|{22XVl4>+)82%r=4kK0P811XP^pwHL(a+d1zooily8=C0% zpr={lr5iQ8JtR^w3>3WUDBDBpwm-p%PLyn#tH)#gyDARD9<@H0GZru@tU zRkR?IZ8>*3XEg+ctor;PUUz89Jai9ta0{S7HdLHx%d8Ka$MGLldL$)8QEs~`Q#2K@2U3fyxWgTU zs8F#m0WK>e2j122PAz-Y!Ws<0ZMESs_hK4B1nJ|*?GJy%2uwtO?4rwCD41XrdSPK8 zQ4zSo>#$s~>iVj(u3)Wl^tb@%~dN*a8)?#a^F+y zIh*PLRRAuB(%8L?1s+S~%Ei?U3LgXv)h*WToHpV0GpRWPO@Ib`Np+}IGybF|m0(Wz z%tBQe^#qz~29K?_l!ssq)*H-CWXkL zQm4tz=uqBV1ch8 zZru*lMj^~ayrSqd{Is6TEgLPFS%wK@;SEZwL$fmW)A`7}7C zihU->nUBW65z=VHO2g1tP&3P;q@rrH?6;<-Y9T-fHPv=tEC4To;`P{fG5uLE(Q#&R zEp;^|*bp3}1?IZ&6gw&7=Y~AAu#{E${TdP-e`_JZ28iCji!#}9KryH z#3zpKn5ABi*$SS`ku=9}?!6MrreLI%6YE83)7xYw6|dWTT~XS=$xD-**&JsN&CkQA z-&+d9h=DHBQ_#%D4Y#+AcnF1^fCK!2l)z+Sg?OXv;$xQdBmYhijvR>) zCtlAFR4s(Ud|1FPOA2^=Dqu=3QHJS2Eb_${SR8}^zPb%!7E?kCGHWiBmkI>G&*TP1 zwu=MU&Lyaz9;yVA*mfREjCcg2hMHFD`z*(Uo1hxP_iv>jWHqi zm~kxSwVSJon);=lRroXW($IKnH5hP9p zgaR3UKhm(w6?i!p#;%5f2>YY}SkE0h_!U={+lXq=9e*1R) z@fn7wOv|rWH8R72pE$8a3mMl+NI(^CR@s*+p#m3U&2K??k$0rHx{1+;GA^y;lxQrQ z`Rr#RLDl+iB{5X8AK+(W+niI8}q0D!1q?mxpE1 zq7JHb#5A&g5E^E`J z(!lGXpcbUSD)x9f%2JevFNumWcQWA$b!n$Ecs@)kN)N&I_ws3kmRB1V%rNv(oA113 zc74}yb+oMh*-VvO3#j|Dm`fQgT-3@os;QiX73<0;U z1yqVBR+*7=(@CbH@e~Knih2&?x`puieqUPSdAjtU!Myt#Q0!=S9TQ&ZP{B;WL?=uuTSuTjVN_ zV!s#*rQXIJ`!s=A;eIL&mw_0|k<`pjrh>Yl+Tje6$R4H)HfY@hMMtxHy4G}31PhM~ z8g2@smtDPBT9idUhD8-vSa_FKT-+g)Td7Eqj5w%^aFsR)rN|cJ9_h?l1&Xb&os}u- z3|v8tQ#{?}k<@e74Hi9RG|90GdFmt|*lUot@fBEOCsQKdlkYp)bjZ+7r-Q2c1?%xx zDu5`@sq%A&FD3zmi2~1*cwoBj4q`R6wWR9@&;o)~8-R zmIXD?Q^U{X^_==ly*!kUa!{O6xZ>A%PuJjK|~Ol|vAUbo|` zg`ax)wR~UICmYUD`3j!MG+`Q3C!ZQQU%H7JbEv2xsz5g-2T-)FS_kwoHJU`W>8nj(FRR_LA)|RT^{Q@ zBo>Ca>%$coDy*BR&0v^EL7BI0mmm&dcRscxrnSJdL29z4F>R;e1l$r%cdvmk$fA>Q zHN1<0G46E~`9o<0vDpD`Z_yvNN_#*s3pE?Bhu$Q-M)bx~ADc#QYO5@xM^u-ln=&dm zy%P0A=13>@RiL)%Tk9ao7cr`LdS1v07Mvg;H!2qDvasvL*Kn7=+}8#j99mC?!X~!Q zWjT%^={~q+qu?)20 zfzrgpk=@$r_@h{sb9j$*42?a0PwyvmC8VAh2N#{j;4T4OU|Fg{=5b-2km^JYjc4AP zOC?^^NQy~N=s1Z+yw_IX1GEeJNm`oHA>2|2@v5J|POL|lgPp({w~%Q~_E)6`LS52` zg4 zc6wC11$6?!i%?^esY$LimTMMEGS$oZjgrebG{>9C?oP~OM-20QnCx6@Wa=MWbF=g8 zw(qI7+1xy80Q$I~-g=|q+GMBu5cNiUecOp!-EJ9_$0(X8ACNgy+SoF%iWW~q@3uEC zq9Jek1D&b>8TasEXGmj8MvA{uS55Ef{=YehF+69!Z@+}1sJzZ?t-a;+?o^vxQcX=d zXRW-}KV|*_L{*0{)y$usN6(4R7aDVD-h#1S(>6X#$_n_^AYLEp86QYHh;O3l+PNO` z87@87(yON)|0exWm%x3i2~FC-(N-HUg}Z*FFzGMnx}zw9g?7ay^Bv|ECJYG5k%?=k zr%`so)x4VWop^v7N%*OM&k2u14P@U_5|q&rgrfxUbu@ejT_+5U$RGCU)~(>=njCTN zEDUP#=4RZct0cjNsb1xKg~Zz~155xR;v#nB%PGT~K7qPKxxi7j&#=E!M=Iw^lD` znQv$j8oFfkn(5=VY?7r}vpH63N>Ph@bBG?`(C>g=E_P%iVeSi+C(`B(>k2zlsHm8W z+cS2Aq~@7JG*d6=kj)>Soc|{Oi36uXch2t0PrJOif%S9Ywu1dG=c#?p+hvAPnKaR1 z&&64AMC0KKoR!CBZWBk>=M4bYzK9mRe8V+}jLTd2Ep}3={_V?o2>K1^I9h`F&o=8A%mtdKm(pS{kQ?o5K`bh)lHA{JxN>50i$F)^P?C2 zbZ0sL#YoCvV_qgG{8=t&GwJxF7A}p=r`p{aU!*zp0R1;+g;8zRjK#$4V~5ol&CD

Oe1y{#*XBQnQkDE$v)bUl)d1=I`hQC!38Pw1OEZG+_ z>3P)CC}(hcsPEHniX4Ovx>(uvZp`93bo}X56B040P&5IId@rGM$vztZMf4!rq?Dat z4x+=pxi}8eFIv#ie(Gx>2JL5mqr(teWrZ}s*KkZC^qR`~Kja|GdqaF7L__i@{gS{O zW$ptd+BDM_({<)br@y%vC!O^Dr2@*$oR}JKjMZHfZ!g@6w34`^yqZSdni5dmaCJ(0 z0}LN}IAWjvyeyyJnS&VPLB29H!A%5%fxNrn8KIjPRbM?wmIv0U?6lT>tiT0;Gz44Z z$MSYQd`FpJoSvh#w1cJwD;*rmuXBJOP5>G;-m|XqPTJ=8p0%*0(?8A?QQqeCZ&OJD zhGNwoNAb5=J;_kSdH*86dLdrp7p{l>4}a|33f~)OzNF=@WBGBe@bkeLr|QIZfI~T_ zl_NzxtzcmPXL4bxV5Sf+E|Xx+fxMgA4}4JdYIyik7IUVzelG9wglQdY5_@-#!UPKj zN)LM^KPJ4Zj7@^O!Mg_eSl%b3yJ?xA%DB^{)6JSwY}Sc<{9=6aId-lUD8=k2FP`Z* z@Az^ojGv-t{&q+H_scI|QacCT_T^_;$y4`zsX{+^2_1-Hs-pJ{iDQ%Dv((E8 zoTr~TI!SyXN6uLKM9y>c48eK=OIkQzz^wqTE2V(%*cnbB#6YV$<427BgS5TDAWXFJ z59S(?G1`nGeYnAo0MI~XpnvxtGK-utc0~_`{ri8%*Q{(H)n7k)N9qYe7lVK2-=tw% R>C2z*$Xsr^!Tjof{sz}RWA6X} diff --git a/.metadata/.plugins/org.eclipse.jdt.core/externalLibsTimeStamps b/.metadata/.plugins/org.eclipse.jdt.core/externalLibsTimeStamps index 71eabc0da3772f46a9870b3ea8c215deb24ee99f..68afc218bc387affeee105a7d57ba92b6a9ff808 100644 GIT binary patch delta 65 zcmdnVvy+E~fq_9{qLa@=Ry#)XNsL+(Uy4oaGuZh56VqfzChf_|EJBk%G8b)Lz#`2E U6i}b6!Y0bZU;$J(`5CJi0G#m?3R`GFbfC1fLWrfh*jD1!@kRbg#bfZsL{%FyvSggxkk>TH$ZB3JR!=W$Vr$@nhbI+-&zw4lptu?+9;_AGNl=#lZhty({&#M0 TzW-0BXsdiBwWV+1RhYpyq14(( delta 27 icmeyzvXqI9fq{XU!E - - - @@ -33,10 +30,28 @@ - + + + + + + + + + + + + + + + + + + + diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/dialog_settings.xml b/.metadata/.plugins/org.eclipse.jdt.ui/dialog_settings.xml index d8b97ca..616f553 100644 --- a/.metadata/.plugins/org.eclipse.jdt.ui/dialog_settings.xml +++ b/.metadata/.plugins/org.eclipse.jdt.ui/dialog_settings.xml @@ -3,7 +3,7 @@ - +

@@ -40,6 +40,12 @@
+
+ + + + +
diff --git a/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/1.png b/.metadata/.plugins/org.eclipse.jdt.ui/jdt-images/1.png index a6abcd86620000924d5b0b0715ce61ac59867f9b..56554ec38d3e023519caa92e643d159bddfcabc5 100644 GIT binary patch delta 256 zcmV+b0ssE$1DgVnBYyzmNkl)*aR>e1fKOS zfO`SN#%e&}w%-3?%M1RmK0gx)&j5>oVP`fVOQcgW^&!4H5&%5i}rWUF(1Q8S(!+b~gU+*wOgE6No`<`{@b)L2?8Q00HMY zIsd(8r~aS5x8r}))_O1-Bu12G7|7q)1&>A$nhBYy$0Nkl`Qh@A$0`GB7wRU3mW{bSUp=#H}A)H zF&A|ra!Vl8{D88-$SmYG4%|#FO#XJ*w#P8O=SpOm>RN$ZFscUiNyy(ta_yX8 zvk^7R&8QJbl&PlqKglVOJ>8-iB~yBoPS>$q@9p{7_W!^qbmhJ2DF?CU00000NkvXX Hu0mjfvsK?( 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 4768f9574b046bb13ba7d5e57a31af547462687a..a95f60827ddd5cf84fb7081d4fce1a53aae0d8d0 100644 GIT binary patch delta 211 zcmV;^04)Es1MUHkBYyz3NklF`_gVZtMLYw!Gl~>hm*^@C>jRNRFTZ%ncs@oAx&SZ`s#^!24Uk zVjww!2FUh={ZCp2v~6P<6qkZ&kQhjgpaCiCTL0V6i2vWQvrO@S$BxGToj?p?+fPsU z50WD)9GvIm{P&uj`hWV~j{i+t>%nZ07*U#GAb(>QJQ_i4k~9x3006VLgT53A+;ac` N002ovPDHLkV1h^oXW*ZgU5A$la1&J8)R;x#ymp*_pLi3~1Kh zV1J_yVUGrLd=WxZMOve7^qP=KH0h8ioI^Z%!-zHN*zY?W7=J&8?dUbghxee$ZAPq7 z$NrBY&z%qOjwrCXRE2!<0gULh-l@JNR;dsDJps5!Q8Tz}Yh3w5BL^sJRx?us>;)$Tp75 zEASAJvlGLhM1RQwFhHne%#-=SP;bFVa(LH z6Y)!)%^_!k#6>oaEkB!b+ZY9;Rou2PZmoX)zg?2)GLMk*EruD2MROgWWXiEFVPrV8 WA@t|7>KkhrfWXt$&t;ucLK6UC;4muy delta 166 zcmV;X09pT&0m1>0B!7uXL_t(|oMT`h68r~(4||UPKhC5J#vnEb5UU?-07xSYz}RFP z00Sf$K(QB)0YNWJJhAS-%fb>c2C+#B1CR!j85#dOcQk@Ahz$bIdKbXG0Ak}b0HmRC zV=3G=5E~>$w0{NKe8D!u0Ei6|Biex4z4QOW41s9|i4ko8%pVZB&LHwMj{?#F0HP<| U``u5UKmY&$07*qoM6N<$f(S1@<^TWy 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 56554ec38d3e023519caa92e643d159bddfcabc5..a930fe16c945152aed77887896b5b53fc6e5b66d 100644 GIT binary patch delta 484 zcmV~0|GN#66%`Bl-YkUcrsVQt6ikCz~v4G*9WMQl;hMbbVKEC!Qzo4 zLD&s%VJ2t>ckZY8UGx^FZ6n1sd9=w57>fcjn*y%GB?`WNi9qRUPI%`^H(ERz>a}(i z2tKI+k(D#Vz<&~qD>#T8BTHX~OkF8;vd&}6kv}Sia9qN#D^e8{nk4+hO|-#%^Z`W^ zG6+pl>YigCyr&%G&Q6Fd@>B)nOu}&~6iy9d?{D#;g+pjx9l+FHT-ED)3=Mo;W>cbL zjZJP4evZ&9s+v>rH^JhHpTSpqj6J~|n1$S~rnt0^YF&t%MwX5NGgSknyA8UHQ5d() zG?KiAC+CkyKyW`kCQ{7SGrY`3R6EqD=1C-yob3Nf{xl-5YF>ll2{}q8>u9WZ{_$V< apY{Q_NRAJ%G-2Za0000)*aR>e1fKOS zfO`SN#%e&}w%-3?%M1RmK0gx)&j5>oVP`fVOQcgW^&!4H5&%5i}rWUF(1Q8S(!+b~gU+*wOgE6No`<`{@b)L2?8Q00HMY zIsd(8r~aS5x8r}))_O1-Bu12G7|7q)1&>A$nRX5DnrJ?Od1v$bc*ZU@myx kF@Zb-&@o8{i~`~T0RL0Yma{*{u>b%707*qoM6N<$f^ow!F#rGn delta 249 zcmVqA(Igv!Y&%)5 zpvVAZ=ff~TZW`FZ1Z`}N`{&?T9|8pI9l5YF^|KOjbtR*w&`IA52XU+Xp|Lb1gf8XfW2XiJ!1kOrS ms81HRk#fwLWWuk@z_58+^F9&IJH~0|GN#66%`Bl-YkUcrsVQ{V^aVZo| z4Px(a@u7u7XkQ(`)LvZG>w63hd|hT!qGOFsZV-Ns&?~B%Q}H*!;)-!5o-{ z+^(j$w2x|tn?{z70W(ztrMnHfjZql4%`}p{h9~EbNI-BuJ|VmQOh{+ z_!HX(B>~!Hxmw+*{9EJh&cU{D407xS`z-j;pzy9zQuK^6$0L*~Hmmk6n z!sZ1Kjn@DW$e*^8d>5bxV(In?|B(&Asu`aF@vBNO0u?7H+}8U)YN z{fzkk9XlKUckF2V-wDJZw*B;k{~$Sn27rL`oSgq&vs3?1-`nxOX=^>04H6?tGYsT! q?E25z==oo7YQldInIn diff --git a/.metadata/.plugins/org.eclipse.jst.jsp.core/taglibindex/1508644233.dat b/.metadata/.plugins/org.eclipse.jst.jsp.core/taglibindex/1508644233.dat new file mode 100644 index 0000000000000000000000000000000000000000..dfc9f45563b26259d19c3f60e0dcd50d7ce7c465 GIT binary patch literal 134 zcmZvTO$tB&6b5JQ6fQvI1VmAi{4A_QBpVA+l(XZ@+TzuGy_x%=qGQ4&Wu|A
+
+ + +
diff --git a/.metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml b/.metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml index 690670e..c458f04 100644 --- a/.metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml +++ b/.metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml @@ -1,8 +1,16 @@
+
+ + +
+
+ + +
diff --git a/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml b/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml index 416375a..8fa58f5 100644 --- a/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml +++ b/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml @@ -3,4 +3,7 @@ + + + \ No newline at end of file diff --git a/TheButtonAutoFlair.jar b/TheButtonAutoFlair.jar index 1a559fa31467d95463e0010a33ddc4ad4c097b6b..9d4dd6457ed37dc8ed42c53f90d763d450ee1728 100644 GIT binary patch delta 12862 zcmZ8|Wmp~Awk;0918m$axVyW%ySux?CTP%&I|O%kcY+0XcXxO4x^MS;=iFEIXVh3@ z&H7g9teRtutU}iBLn155LPBAH!NI|S`cSvj1J+M$*e~mIRr&$>I;)}in;5Qv7)J7y3p<^Zy|3NI)H@FDLovogEek1YHcaFk-wa`A-7eP8yG$Uy?rSYVj(QWGu>%Qdi z%$xN#%#P_(z;?55X!zF)X(#$?;`Z5cFGK5K^ zv{WPaTd0E$S{FA>SWNWDNw^r#hHZ3He0=N3L9}t+Q)C|70EfNofJ~)It(jIU|BV1j zaZrazL+(>stTj^0e2SPZG<1u#(pN+iq!X$yGVqlPwNS#)iL9{WoxZbHve#?C>}s2hMiuaEYgFO z(JA8F{^-08UPbm^nAJM)Cf{Hj?RdFzcgPG#f`g=6tNxuvGnu=$Flr%%!5U7!RdUD! z8fj^V!yy_a@6eQ-xZXNR?88oG;mEt zbDwNwHIMd3`m9x+xNU0dBP?P1R;td7J4t@?wRjin3TDE68x8TmmyQ4h1+0?7yDnUw zT18>;@DM82CUQ#Z#iAVnYD_=kZ}`%#a2v~uGwg@%=;2_0gE&eRNg-b>w3fdCg>5a}89{R*^E$EC07j0zcXSzc_FUNWDXxM^ zmiby^!tQ=RzX7))_eBDxf~^-jrIkP`(Qj`ejLJx$yZeOh;hk4i*wW4e+raLZ0I3n3NfG4bK_0@~nOT5;9a(KTMSPSsmXQpcfe za{f-;0pESM=_Y@D>Nf$TtJL0d7gc;(tIjrZl0&8fiEQGh_Sq?(`E1VB5F$->IO$=m6SJc%KDkFyLb7eZaGhVSmv#cxLa&GfbF8$`~@ke@e_b_XkF+(6;$=1hFxNfdc?q#)g>CtTiM2#W0rN!mE;a-LtUCks zg^>h@rj}22O)8@j!;+2C@JyqSPO%Wnsec$c+l~cKUOfgsBbBs-I{|t$Z#v5Sp4gsp zl9J~-Oy7k$ZpZ6CF>`lGhT|p|e$Ojwr{5+7IMk@S$%jXrxIK1a)$mKVdGlir5*N4Z z>m8|dfwE;q+|p)+AJ#iW3e@_12={;o?=?a=BDWF)&VZ}bTY7RvriM-0mttdTONSjf z^q;qm-d-!@DS{CTJGfWgZ`_LS$e&@)P&#GJ2#mKD!bR?Llx_k=@saXasOicT_mu34 z;&;%fLokXj3hUx!9Z@QHFG*nx%wg~XS5>scm^DD$7F5{@O%oiAulF`SRmStSb-`#Is5jU4 zcORHHqcdMSfA2Lwe{jiEo{ijq87Oq{{&>NDBni~?ickK)lBaP4$lrE*;n!q+t1qTr ztuC@`I0{gYpQC<)-@qfR2$ll=Hof#_a1NXbU=giOXc&oDN{q`1qlI&3dWWMKAmewR zBA!#^?$G-T$%a^mP>|nc$GQ#+gCIogNfvy+_Yi>h(geTCHg-ZHfPBi$@GM@#euH5{ zS3p=e7}#M8mjR0BkNMM{Y3uKgL5v#c+t1+>0F}$5B-=QJ0Br^33>&I3H7Q-m!jT$k z7tB5`lK01~7C+E!Rwq!$tb9c`!^2{o&>^PlcPp|>J&ODBK7R#5*Souupu$bc1JmyO zMc-bhF#q>p!o+MnHHj%lNq)+yZP2_0?C`H0#b?&^b)k(OCp86G|7TiBaGlD5Ew1w1 zDzML3ppwF^UTFQFZDxQbB-@Q5n*M0&fM;u2Y3Z((lUZ%N zZ+A;AS70eObWz}8;@(ydTfY3Vmr)v2MOQaKrB{Mf-tSElAYGG^IcEaJPPdmjxO!|e zZ2s-5)&rLs+lxlz5PF>Gr4QPyvduwk!;(s(GtW)$4EpNI@s9B8QKrJu9t+|RZ_f0(1Ps-l*^wsoqJSYF z*sn37RQlIzT@KcEBB-G7LxJbZ`R>q(ka8q+8w1 zv~_sNfPxROofd+pupxUQ$XIXBH&ba^bdc<`C?OHkZNyo`O7K+fCT+;DpB&U*H^r{^ zS9BRZbBr(zivX?^bd@GQA>wux76XAsq%qMnjG3jmGFU4J)~-2*Djr{y(Nxr;C{v8S zs%xSyyqm)(pxUb|qU@d6{}uzUGF5eXi|aOgSC1|xf@xlMQe#T*jG`Ed*3O_8|Dzg4 zha^QP%F*1md}wUNTWD`k1unicLevYVe#8{XECL^*_CSAbr&y$K~JsE~> zts!&G_9->yrkY}Ybhu!zLMd@krrepZq;)4mm$(YM!aRB!nIb!b_`X-+9emPD8aWf+ z45D4^x_Q;}iR0gw=`DF*rw#xD3@iugzb{j-+P{)_p&nkKualZ4&Yx^EPS3>kYb|0k zgrtLoPGVVW*)^!zFCikCnqP{MjLs$w$=jS7Jbj-Wq-u4}5Oj&u=NEIUnpUgf1$rq- z#N$muBh}Yl--mJBC5C5k{y0fko-18@PC8I|2TsUceoVexK4o9|^=v(5Hykl`d%^e0 zKX-lS`wsX7c59sqk>cFFnQ5**ZG{bRv)3rES&>-;kVT7AVwy$-&d`2f zR{YckW*RDU^Ussg4Y5Efe{Y+6Pt%G83`P<{Ih0yuMEdF<+*3C-sZ%-#wFx;@tcLeH zt=5yM!JpgR^DR}xc(k8biHu#AUP(OpHZvB8I;=(&tIo%i}9~)*uP=$Tf0lr z3*z3H@V=P^E9kN&Vmwt68eVj*4%$?HrBe6`oVG}p(e7IR6BLOPcSVUF?iMA3sY(A^`t0kiqsl`=BAgwuTKFOVurHK}brLOlqvxu&2N%pW&d^yq{=F$wH7c640(7vPq zWYhKNAM{wKs4WyoH&duTUok03z-a8L^5}PgGD#dWMYFcd4KNS?PWe4l6@X;DW=s+~ zO|XW?HGq$-JF&QPGQLYYr}vXnFGHAA`{!=e6Zo76ZU#_Li3e#)gy%=(?fo~Fep z+hxXh*FgL|?#d#W#0_38XLJxSMJHJYwEW?W7^h`NmSJ&FX6MBoEoJV}62Z@-&uiAh zOI(vsje3c-oU&oKXpFgeS!oIiiKFh3xZ`zj9DtwN(|jDH`s>}+T6;^mW+MHzO9PXLR`d)-|_J0D#*;Y^QQooVFf|`2tkD`Fo7F< z{7n7AD$HZVJ&_0I`&l(1(Mt|Fc+J9GiKiGqNU>Q*X4Rjz8)Pp_gjSAJDEBPI%Er5p zF+Vik-TBkJn5=PQS!2zZ9+~-c+;(t7478!Uhf?1RJ6%kOlJ3>xqDl;Vk@S;>T#%6C zMwqW(p>u9ys$s}k{acQ|__s+9;10@O0gOQZG$pm1pIo+kUn?2?RPQjf%r^)dsi%9X z-LBwm*;7K(yH1wnbHA^IL*LX#{UY^wHHq3#+(dbQ3@1Obt}m^vR#HEZ;G2{el)L+H z4q{zHiIUXWKR(~4|8=&77ACu`Ot8b#7tAtJS|+CNHfOx^@;~Y$O5BEMfRhz?ff?_S z5tc62E~+Ykg9gg(uo~7APnkcrH<}#Ir6=cT@ZkpboPF3ohdB|=ye=mSIdA0sqGWFy zZ|M9vsk8U3eI0TFVt09Ay7|8kl2=7s?fQ~yi6FnKqAah&B!4)gZ)qa3EPv=cTf>n- zL@jgGyN|z4&N8fu!l`>>0ZkD1U=-v8lEPHF&pB^M6<98+W!{3uubaPO|Gbu}_{sf2 z5@5ECar0Byez%baFQzcV1&t(YN9gC^c%<4NKkcUNpK>RitYBPicVSKnM)Vz;{-iX? z4W)RX66u2stBxcaAoWuG3?WT>k>iR2&Dvc6O)byT9c49`KFjKAF%W8j+I?@_oxt39 z+Y)_kR+$aCoI^$^B4{k9w{jGkByLIEZ9K!Gn)wv6JiC^Bq_{I+;oGZf7yj7zNp>eH zedMZl?$Ciom%-?ue1n94wE6k(mv@v~o2t#urCaS0g+ALSbxbkXC38PN^F{bn1kiSUhrDid9k06{lRF4; z4t-4r;kNi9AHu&*Y(v2|`Alc`eMROt?sI}stT5+5DqvEH69fjy+sr#*pWW{^<3VyFv5|{=#IAyrskH zAty^cD6~y^yP!?HW0=W+c zHPu5tC`mbCLh81u5$jDV8m$fy`Bgd#UO5m-FX5C*g9JEwB@%6_pwS=frX70?orHVZ zHrpG7pk+^Nkzq0Vs$?MTO*Q3(zT1OJ899GJI^4bCR;A@qcS`rW+_^S4>;{yGeT;|_ zyCbCfK()ykEl4yB`|F0}dm`7eHyX%81GIx~`t0Tk6SWi~$QwDe0P`HtPmTsxi8q}1 z((3s@)eW3qak-rRNyX<6VMs9S3enVuI768Sf}_fZ#pr>Yd-2CK*H*xe7aCN`ny!&B z_mSJaE>hjWvVlbO(MV=ldS7Xr19ghRMGHM zM2z1fRRTT6rSG<;8}g_4sTkUR*g!(UASZA;=AWabQWNJfOwD8^YxqV83I%IU(gGNi zX}J*Cu(^8pKxFS4oC8}QD1WC}2p=mutY5&u;!*!Q%S!$G7iq(YF~k&C1LmkcIIba? zc{30k46NX^&=9GVZmmj$*5{~)_Q@a6p=VNze%U5DYI#@xw-kFp`y9zqa1VM zN${yFo!m_6{OakZ;qKDsvhC<|iu;f69F}0fEz{SD>B&WD(~P)fJ%Sz}F@BYTn-;x( zgc$kxm5kV`$fr@Ik9cVXKeoXkN|?I~b4<+OYK3k)ha)oOU(foASH3@(z=!nbx^Na8 zq#dt*B8R3lO7@(%V;xFOzONB1-gwEaaf0gx{DNp-v;$7uY9j2AmLx^uwX&>#@E6j4 zMO0_Jlbp%!;aMhp{MK#))N;1?v)SgqU!^b@wDY+7o&Jt^AZ-m7J}fxGTaMfO;4D|k zpWNt#Ey>!dW{~333%0PmEU=RjFk@8Q*=D07z?__xr06iigx#Fc&ZAqoj0=>7(*bZu z=zQe4e`+b6me0s@@4L@Qv&odipNPL+t`*L(g-LJiqPT01uMu|x?L@sX??%Q<X<;=wT5eDj|1mtt2dF0J#jvLM{z4}kt%A&{WR-`n8%9c~`qSa~w#nEb`4z4QM zOB1ZeGLXkP4GFSqkS#Tfkf$t(a%zg!mM|ikpft52a%(Cr#M?5%R{JmAfZn=qH#?Fft+r>|4+(s+KWnDGSE&-oU0EsvoB9c+^X{nRWve z5^dm0biqihTSGrCNNx3i+Q?~dNaYJBY{j>VA+R(?gNmJ%16DKJIQ=%+WGJWzXzqqgUu7R!d?TjU5Nt=?UL$tG3er?(5x)XfAm zKvd8Hdm~TW1O^}VM;ts=lY$)JRYlA^`%K4KjC%=zc}z`!G#9-22{Dslgdr0wX8Plf zyH{kOU6Xr2YG|pUZ|5VO#=?n7vGFj+)D?VKZM$%)Nviy(LdCD6;*0z8#X$s#i>r6DYN%IIx{iwx?SwWe10gv*3QK7e>C+NOVx;6}Cf? znvMU(EBBf}UcA1jM2;+X5fsKz97jRMjHg2SHcq)gQ9l9Gp&!9<>;OhmplM6Kj%n8- zj9s(=k>pEKgGB}L4Lb2HFG&&XRy{G{p1qO?2nq}Oaxe`kU*~L;8BSOj?(PGZd6C*L z{|dtokt9i>JaIy6=RNMNVVmz^B>U1!8T{Bgj`hnVep#y}cbge}c5it5+xYwE^Ncl- zhnq;D1z+dGmsLhe-d;6jk07;Dzib7?M+7xno_((kx43TV{+yuU`vq@xO|1hT06NMn zutkn1Kb8oeE@k>8T_C;H_@&<-qQD5MY-s@#!-l2xk1~rjeecrsuk$*wv)>PbdcXW*g)mDw1PjEoYasd?% z46@=kJa!BycBuOi3%+~G4~3E~6Va7d`B(lf=oWzgJIz`0ed7Ffqv+(?y=3-h+@^Go zLE@(v5HnME4Q-fG0Ct4ugI!kVn0>GVqO?c&l^MB9xb`0FHQcRdiII8P^*ehVaI;75 z)$o;}(lS#)q)9CBDYQMHm+dA*uR=rP6(lVgigV}yc$swxKkphATNJLI<9)xOv{SXD zN3x{IL&<7tuEKe~=e=G<+Yu(4K81Y5y(bCI$gxO0>p{ z7Gc#{-0pL>Sf$FuhAJlq&RZG_1fNKeuT3=$T}3nRA-LZ5VP{3uOUHr(| z1W3YgO>D=EaDT&#&IDh=?)>s;z&??Sh2+rZPZ5nXlLi>p3eJn&1Z?7m$wsuT$~jo# zr`N5@aQ)KB7}EL!)R%qX8Fom7cSB~5xg?m0+pGl~XYN4{qG2|G>0Ex&A3aP}#6B63 z_G^_uP1;R{rspOw$wSIShS)B0tUuujY7=;uDKpDe#>_c1OzbsBSd0*X&is@G4^3-I z=47#xzXmI(7Pk;Kqrpw(HA_{_!B^@pq~R3a9h{6OM+>I{GZ_HR2V}v6Xuv`*6ONpzFX&v`VX>F*j$mJ?~RQX}+%lJDW`^p5DBK!*Us>@549B1U4 z*;ECM6tRan)Ji*_Vy=G`f)<(SIY+>=wU(OyxFKhtNf%NIlav>iS01Yj9aiPyFaYwj z=`HG%#I#gLWw7DSgiYQFm;Ve?O4l2<-r!(&dbU#oitHIA5+&B!1xCA#oaOc@8W~jx zX4MXSN0dqL{E0Gh@&3*LqzaHrQ%uZ7f(hQk+xfviv+YO1v%Gs# z_1l7bU?fd;S@EzujpTY_Brn6+V~M>O!Tn6JoVQebUAppraJW<{egwuc+#fJ zf}?EDhUG%(83HoBfFK+QRP9N}-YpaV^c(dK0MF)4zw={1L2~OJWu3hWHa{f$1d(XF z6q#&?k)z--T{atG8;=^84Blw=77nHJF(06-jb>CKJR4H}Vf=#^8z>Lt+49I3WFbm> zC;0=*5WqK1mw-g<8bEoMRKxmAHb@*;!eH^zEAL-{G4l{%?KI1;bn8Yu2zy<1606gF z3S{{CF?$d-SZE@sYy=gnW~w^3ud*E>I%E!(+M^$>qXr^D9UCG$TEh{gkGNC9kupogKud&tWSnS0#i8|HuB~diWGg zL;`p0Y$HRHcCjfxAQi=X{kEllSguM85_t9iwP$NQq17emFxvTgi{wzH#w)!faqqj8 zx?Y+Cl(Z!SV9`3_PirHDHqI1tNSH{+3ZllnYN_&SL&VV%cJ?NO-Eali_k;aP6|kfe z7@Z$e`wc;&GB`d>LyQWO@{%ZDHRerI|IYjpIbn7;xuwGgj)%rkey1t6E1Vp}3KVYY z0UQ()Cebl&JBu7~c(+Fwg)uy-sgE^`(s0ZIQn2z9K7j<_3|VV_;?3fR7Ilk!-u$x) ztWDk~j3~1r{X~evsX7~0N5Ha{?keM%k*bL$%wrw?b$KeId7{%slZ)dYCBh739Tj9_ zVGCzubxOGcXc5qI_Ib^4BayGBKy6)RRp*0+=EXu<1&f8Y<7wprb7HEx)m61*WsS`8pNO)i3+nH%`noY43lWp?sO18H zZ{3I{OEeX%^+P-k=Ps80kW8F+T#D?jv>>AG{i~qMg;t{$ov3-;mAFk$U^_Lb+@?Yw zhslG8K^0dFMIgaFU-}m5!0m$qL1iP3Gy}ZRM7&Ih zwPJ2!a)8|4Y`=@%G|m$O5LrNC4}n&N4d+j0KpZMR@{C?7d(AF!c8(|@6hXD|8I@jq zt{#JZ#r=&_+!me^xyUSXQf7wxjFzw@MHIt|!EQ~FASRib$MG9GLB7)+No4u2<$y>= zSrv8los@oi>h|1Up-m_=kB9xTk8|cl)foCY`4zb`WoKaed#jS1KskjO`U&}|r+3uQ zwdC{cu6j#Lv#Z}D3@6Fim@bw&BWpM$h9`h}2Kqu5!41=KY;AQf!$?BZi%400?m1a~ z2JFK#?nVLn6Z!Zgv2w+;KUDYOon6hZ;l~jc_{!xss00{o;VH)NJ6%lgEI9*B_iV^A z$mbTgpsg=plI$_XKx?+pVpYhATywU>#W^~j@I$2#8!CyC8F4m{12{x?^ed#Aq+yAV zPZs8MV&e~ke2RM(`l6-M_)W1F#d)!-X?UNX8Y(DNha`-DA^Lb@flVB=Td zp1b7)g{Z-<>am!?G_NE8u zZUYQsva`RUJ$vatXX%0}^xjUgKkhxhSBwlU0||41qE0(0jl6zTIX7ROR?ZkfJfFLC zF--y%s|$BSinBYD0zBvM!1=uXWMnxHF5Ce`y$uONAjIX?p$cJo-ycle&@EIE^KZx` zi09%=0y3t@en!;DD9a+_)_7F~4mQOI#0R9O`4?_v`iS1C(+urNk0!qp8zG0iD7q9h zXKIdZj4p6r!CDeXUm;Rw-T5-AkJ1~1k7i;ze>kXMgJhfzhme15sEu%+L!kNvu}_Ly zbMujcfbK5{4DZr>#IO}_%iDfNepnvFX>P^`_pL3gdje9Rfz=b|pt-2gE@?}KlXxR~ zRX4dHkdL~2iEZ{PpNsjaP!q<_%kP_Au3;aXiQAl)au8Br=fTr%stGma*Y)3qf^ku9 zl%VJy+g0@T4|b>tcMh1T38TP%q1)(5OE9UW0d2~8`oAsgryLeb%F8)x%Nsa$shs+h zT^^KUXjW|D98I#wJU|%M#qX{(+(z9sb&Tp~8QQIj2G3kh&I%N&r7mXR@>82e#_Yah zOrf_?S69r??spIm$$G#yIx_AS!D6>Q&9|alk73kQq2~I$&2`BfF1>aNcE8+?DhO=WV+mhCL$wjzS%mbVN~RHn zuZW}H_>Zw1+$1cdy71zM5$11^&atM1v`A*gp@d{Dpak<530H@ktu zKTr-?zU+#|?wZaFECMW$)ICjCELfwl1p2_ybC1Ps1mwLuo9$*}F5eW$e!p{HQISN^mA@ zpU6hq&i75(tXZ^1{lJ7T+43bA6Rl0H#+=@+K5>37$vtdmd~6p#&PKAW=Uzl^$OWX! z=YQVJ14UF4MbF~-8$4ftB_b)3|^LMC2c47MO{A>7apKjHe(UUxxm$@mfVda`tb6mu-``<_l_ z`4|OrcKtiN0ur!fFLKKP1Yo$-g|&JI=_p;3 zW5w!(w2z|AmU5GC!hOnoj%JgZidK|ZHx{Z%FF)hct*pZFnEY(ZdH0p&S;y4nn{ab? z#YH!f`PrJ?(+9ckmP^M~$;zvR*Nf$C)q4oDXy?1@i;NM>X1tU~ylst;IGV8ar9c22 z(UQPtD7tpndl-QZ3Gj&Xc_{0CLPX!?xkWCLY+?UfStr|;h4i~djIs^>eoJ~>=i`Og zEwkO!t7-zwDAkZ-Ks_hq@Hn_oKIlX}B+OI009YHvpEVx5bD9|Uhjw}5!Ag5D*b7}p zw>6MathOVqt1~$2nTBDf!y9`GK_hAZ>pL-MU(yS)WO?|_8;CDBwD+Q&)63}0{wKM_ znsRDh;<{{=t9pSlUjPtIIk41ZZOu7d%z}6W)NxBh%eDX&s zG+g)u_^k~13Y7Li!I?e zmRo4QaO9sax6w}XS}%M!p=$~I<$RR5eM$xfxv_bJIaSTlMwW!hpz~b#2$oGH*KOk}scZTrWFvm2?n1qirkBC#B zr3y2e_ZP+j83P4YFN&((iyF@8YB!A3*$$2XrBjXPc=~-6h0&4t=?~FQkSGab(4`28 zV-;8K0si!Dio66w`HjuXwz_=tDtonPMu~S1M=2$zC8pHsv5Ka%fefCX5bgRGnN-~@ zPa(XVS)fE!4=E^09U`-?;|R%%r`1g6PMu&=zGeUStg8i%^lI#mgbbdi7_GcDdLIT7 z`!7IiW|(y9+4`n}XTrM7DqRapLJA6*I^az6m``6M2mxviiGkW;ZfveoVWx{O^D@~d zYq66S(IaJb!&N%LAVqY@W?&!`6!E5tiUAiUsY=fc`k?tJn{sRa9oB%5L z3HVI<`lBUyMGx^BxucoJxYlWfhJD@oYMFUl)EgCwY5F(H<@?p>|X z1;Y?Zuu3zIdc&mrT`9(9^E>scn22_(~t7sw}AEn~s5>QR$s<_d47rG9CpYoeld zAUu=0aVjDk8aTtJF4oxVY+UhK6j5|ebG1@JQ70X_(N$R9xwx(Hu3cuDCL=mPId@Gv zRL+1{Oc*9o`hYbHkQ)$+0nJjC*x$TqF&cip?uf-dOwMhO441a<=5lBjWUCpa0u`5z z;n=UJ*B9~H=4DB?U<~|tlWz(94d5khER7@!@25!CbM6j6jFY6yeiVa%zKt`L)!n4# z#yXaws`WXle)CsUnh`w>cxR_U!|!>Q5@-CmW*u*0nWV4~#J^W@?ddI0#C;jXr^pPz z`=cM0iUyF_dBEF`v0ED;J*yP8nH+o;etBJoEKY|l=Xj#WX8tJ*f9qc&Jf zzf9*7EZ}`hx7O&cMmr~LbQ)eaa_!a5SgO@dxBh_tU59e~>I;Q{3kK%G+Ay-W2@du5 zRD{Ix1D}69{#1vC|A44N!GFNyq3AyVaK!fyP(Kp+2V@@o+q8Qm_76jI{4e8t%>NHl ze=PnFcsu?#pumaLKTPDwzv7wy3$RZm{%JBf{dZsar~gJiJq&`HU|MoZicTJA^fAx&&|GQ_RZ4YuH z>Nz6u-}SfuuFTQ@FEQZvUt-2Y+kb`sIl^FIwEs(ZHSw45TVnS)6NKt<;`KQjx#9^J hn3J8mrL_Ztx4oT`EHupD9q|8JUtqz&$WH&>`agi!mBIi3 delta 11627 zcmY*Q7Jqs(u_mj;%wYD9b@YVS&NH!GSsDJxDg7pg=%*W;{qXl0m@2LU~#IgBajR|AQ3K zSfT!ML0D&Se~}aM7o2~iWJNUm4pBQ&{XOM|Epkt z$4{=hL~0cJe)sp8Mh?UK|IGenDsPC;s9g+Y1YIn*AV|oYx`>g!jN)!Tvq+L+FQ~9SnxFG@2~j9X~ki`k0Xk5)|fSz~v4` z`a;74BXXKWN@ikg;Z@d^ZU>0Teo+i}vwPS&Rwg@TLFn|!(OVIFldC%|bpN-)wtnKiVu*?C69F_vWy-L&6gO=lJPtU=kjbA66zCq>!*EzI8*n0PxG zy;y3Cp^adiK!e5jnpjPdIy+m00n!{{|qN4pUm9u@wI|4!?3cMZ`P`gmA zch0m&z8*?uRG`Q$4H|w#&nbu-Ii{>dL4J1*I7NvOI!7o|!YO17fUc1#p8Fmje4=uT zWot#H#6={=6F9jJ!XU}@G&MI~-iOQ6a8~QjqQc<>5+z5RtF|1nAzX2osQe&Vxk2(i zg>Ru*{B*a!o% zuv6g*nmF<@wktwS8ua={A9*PI`cWbGyKX#KM zor?PApP8<3zB#5^Qq@}ae4((xPd@bHsm+NV$keXwvzHTJYgZYQM#)S>k%q^-*g>^p zrNP_dh_Czmu0Z15Pnv4QK}n#YqES^<)so`EebyRpq!YW^EmPuYQ>E8j*I#!nS*U!( z5ueDu>PinGB`641gL}xpd%Kxw&6`2~?g7cuZby)}M5D{1C-e!yRIj=yJdZwW+ZQzz zI88~Rq@&>;oo61W26b$nPvkQxtgS&Pis6NvCit^?@3kn=wFIB!;n**U;!eJcvYkK> z>$G-q_hfc4uNCD0!WU-YK*Zbzu_R0{kEXwVyW54aV^fBqxv!H|ZGAgWns_@NweqEJ zp@(A}eiY9ajpD4JY%tX`O-5)GB&+{Y+~AV*Ml}92cW)b z-)O1cf%wu4R3BV%;!}27!s3g|nDGq#=)R^@bSjzm^U_%1anc*+!QSkJki+{0{PO#W zwf4ri`~^j7Ngs!*>Du~5xE4B&CN#Y{@^Z zE3s>H&6M$sCOuPcu!_LK_#=i{1bu{M6`sB>4P9?ICQS22?ujk)yMd2jS;n1RUhvb) z*@q6L_^}0B*H{+16;BAEHYf@mn*eqRcE&R z<$bD?mxeqPE{as-tCmiXz6VKEM(4bg0>jPRJ=r3Iez9W*f7=VA9x+A;kLV82DIeJMM5TP}}E^{!F4@thb$GE(%#0|xgGA03a-#9GzYTgqP-Er^T zg0dbOwmx-b)Lyu&w9gJcPcL`a=flZ;k7!%29JY;{RVVeSF9aZGb5u$lWtD(EirTgS#2Q z_Hox5)}T9katSKY@Rt>gv+zG0fva~*WXLtw|gWD2~ zb%9j?9E)sfIH9MfIa^)(9$n8kbvi!xsAx}Zs9Qbz`Tx8fz{HAT7mw7r($DT!8t{wz7L17%WNRs}_>IPAM z%aVw-NQNRc!r^+A#q!kS^9j)4D!;(c_xy-#Q6^0^)G@#3$H7 zQEOLhrhm26-j9W}PpxQcvUOlDF1=kp($(LPr?Po6_@&+>H3$e?Grbr~vF-SrKLX9O zT*_obY7@w|hh|?C@MS7yR8SAfpJv3?2juB*6-W}NGR``$b0yDH7q^z;k#AO-q8uSu z!Jj&CcxP1Mn;)*gYQ=1@0hPXq7f{ZI#l32gDHAoSFn{vvn)mii{TR88a19q_#9ICC zxRIt$Y~8w$n38fEVJm^MUdll6sj(ghBDOBW3q3o6p=gO2RY+IRCAf{)l`L`xNTpZb zb8m~En6}KHR{Ak6e-Cq!+(S#EKIN4Zi;FhnTtDl$m^9PRW zcI|rNpa-$JBH=Z+*gx=O#p$YsAh*d4N(P={BAu73I|LW6X*BYju3ikAOp=@js0kAS zHfwwpD;~e}oT&x20VPJeS10Vz9RnpW$=&=k(POz!SHmtLTy1@PGWV*-r%M+n!=&nA zILs-bi@Y9_M)%-tL<1YZpHHp6`_QuPIU@@|S;XdRrE@1&H<8gov>J|8+i2R|YLSww zC8E%&qDyuB#ASB}!PTtRJQV6RKb@>bzhnCvY(mJ<>sa$jx5lBmMI(E2vt9)@Ea0T}YT zu9DfdVNqVK-A^rSaJ7bnbn({Nyj1zA!HQTtDSzpf4p=fKAy6GGsGFqGLh#Sj+ARj! zM8lOhp(mOl1{!*awc#>bz&=uF3MUJzIG#$1H{wc{2KIRg1Vi zLjImp;Lj|RD*jFN<3|3TRJr6sPmJfTxR@kfCK`KLiJs#9PTu|!K}Ea4PT`ceJoCIb zhw(>_BitK5!qq&rxA2}yoeFN>_WVt<{wGuhIh7kH7bVt0c?mHK=-bYHieCj~I^o+s$rtUmTLDSP@asSOd>(IqnD zmC{uyHo&;llte|8Au3c5C|Nys1v>3O&GI4UIwA3Ly0WloA~{cQs|uUIU$}#bCF)HW zNM%-<`UQdBM^NZKl4<9htfP^TrWTtDQ${6xsZ=hZNZp40=sN-83+c|GX1CY@+IQ=Yz8Zq2EaP~D{v|#6e%pwGmqD{gGs`b^0D0wh&j+jF0 zAo!2js$qRmcZU-kHci2lgIZy(mT%Tmy%Ff8H~rP%X}voh<)&L$4^M|X1bY;HJOWMR z>OnYfDgsPI!-w?G*v_SB^)w&Rz#F(c;k*6{cf^}*@u>6j>dn>dt{{C?vlCf0FjsVc zwPM>vuF@{IpcKBKLaE+fmf__-OAMpSN_ z>gH@`@sQ1YXtRk(WoYzc5h>vi`6d;KWUeRF;~pDlglX3T9e=YKU2<`<%_CU}?MPav z0fut()8G+_+GL#Tw3=l@+?!b&=XPtC>zMU{RsU%47Q< zQQNuEdv*LbDPjZqOst*7GFp_$_`8L z%Me@~oXzI^QzP%P0bdMF*ll|$(h(!FpEI12`a7RQAllQrX3P!)w3RMWsWn>fH3(|pjb}dB|RG+5quj?+PB2>0~1JEVdh0*QM!`Ov#2KQK)DnUHX z_>KqVruUlI^{L$(GAR}qpinx8Vfu?9ou*ro-fSU(iU}Xj)=fDpAW0v3OWsJZCk_ni zk8VMOJwbL#14$a@qUfjR`ENYiUk-p&CqRmwKa@+3!SqrY*h2j9XyCVfFhcqLEH`qJ ztx>05$wLqGK6t%PCk@#*mb%T9FXr*IurGs0Ov0ZrW8t=93;H=`xv+u zLjN56^UpE`3n%o508a!D24?$zmaD>?e~xr0ri>v31scPq^uY<34cAP8;9y|I5dV7z z`?u_KS`erW@2mFnQTW(A>6!gL>8n_PXj(m-Hk@%{1bjI;R79AxHgpYdreIRy_!KV( zc##_&y?W(O8~r|=^kqd|YwYT8tf@NZ4m`RwEzR!D(aSbf8YNb5x$oQZ)MiC5e?EVU z{^~q$f6lwlb?tdSIz=TF6c@j5qR!F~J3feBruPtf~Rxt;ywyrD==!ZW5~jAV%z70OoQ z(uEtrhd%>G>-ypX!w&zK{ul}%%jt*^bPR%IL2#WVEEYY})wl_bw$ z!iqwpRf{55g@R>KKZuVLw{-0c(OuWl&VoR{r{N2tmDwSt{6vW$E%`QnfQv;F5vCci z(2Rn}24UR&?v%1}r6SH+JdDfR#JOq`6xsx5gW@r|_yQMVt1+PBygGU3_LC5RuvpEN ztFdO%tfLK?R;6*Cx^|x0{Fu@lR%{=bsv)SXVbJ@jZM;Yp$oCxjJ$$YfUpk7G9ODQqx_9P~4DOf+7O zWhN4ovhI}y$Q;k(>=2jf5e6$}N~UTe34yXZXscDN>Iut*lfM9j(eRtUi01#o0NUA2 z(GMuGCGRc89-5pUT98)B!lnS*kzdIU3FII}CkseIFiOTVX5niZ_cqY;S{6bvwzEKh zL>b&gDmcKh`&aVPy?x1C;b`Qt5T>i`t~D_$ee>7#nsUW-QM)5C_s(qhxlo6W6!)l$ z*?y(T#TmzVW$6wCX&1r=FKUcSeG2b4h{dF-dv5o)qN&_Is$nZ}RXx2V`3lPsBlVs^FxsZMbt>#jABF6G(rTktL(RvT=sBLl0E zCGLE_sNu-&0_|h?w`@q_788#-&4Zg()Ahbx35l~4kG&Ifmy^1z2d)mn$)PX(U-d*? z%Nu41){hFI{8Y;vS+RjgvWL`u(O3P66c{eJW_&IGt7d;m+| zCRS`%aq^bKIz#EU+`B?Yeh=c!%NKOHFQRVTeyDsA6paSrlnVR>7ig#(x%|W-l5unt z3fcRm24|S5!1#(EA9(j#&;uuhqRgG8s>(a1;U~uEPmm|%_hi7Tj&Jnm6(=`npK~B7 zY*`a$L(ba8eSE%(*O=1FJ)6LKr`Bn3nd8vl!ah(lIZ3Sj_?6*_M_?5#0V@>vS2VpQ zN<{8CQ}d&Zm{@629HP`q@slW2gYji(egutCzu!y&>4UO&gN0Oq87Xewx8-Q{!UPd= zaGs)0w-8&5c`v{unck9gW9`$s3OvCM!Q=%lfy=(f>(hAtPjV`Na-9sYNaPz0xvkH~ z32TnzmEn(&sz9Mng_t)FX^{y!o+u&1!WGavX)r{Zkmg!v^l!S&Gvw0KQ7DJdGhn3Y z$2%=hI{bF`a~Iot1LP4hao~{5Bt1D@l=m#}Z8*@heF}_j7Q^KK^Lv3Z20%sG)WH&!I+t+mPNrKO#~lZd_a&E%w==g_nUZ zjFe?rv);$=lUK zR&rY2Vl;*iw{lQBaPn)FDR~o;ld}6hs2S_8VxK+0^c3bsJ9miYTV}+zw=6dDEs8N9+b!{G zBXVfLGzTtfEF5YIWp2#v<$$>`D&T(D~-Tp1r`NWTyP zjfHzwj8A&DA4C?I@1k7OizrZ`2~Qs^;;%$O06nlQVm5@`08XwD4f0l8uSny(uWege z^Hv^|4y+DnTzlR(T}(YzxGLelR*D5#azBBU(1DF#auZcMoW0_i*gd)SKCyzGBX{_N zR|bDo9pgQi28-SZkxxa4*Wis1_;TB=6R%?g$whX|uz6ty*AiCMv=vt`HqxH|SypM7 zncs*(=l_O^2`kB2hGN%jNv#3i0M*VIkXB{6;T7zfwJ($r!MaRk%$n_LOl?J?7Q6v8 zjw|BGY9?NZO^e@-^R@WSCf|f?>)7&hzh%vM4mbKV$yAD{n>g1$=({x=UbB$fLjpEz z9ijt@RA=>5bCu3QFrbHQ_|6=uV{?;2v@)E9{nZ491aYvyBz6}~tgNQmnNE$51Lh4) zvG0EC&b+Ln5b`UhR+}Hc!(_7_{>C&=^X3?^ojLL28)c?1Rqz__K18D|oHt_+dz7E} zzR+4O{rMqLwD0yo)hhuJL|_>ol(4Pgb!fagl5%!noOdRmW_%^m5w}W!ju9)0C-h_2 z9lON|drZI6!uk<{2N>zN@G4mfZ{lk>bbQ^UCKhyMKhlKL1?kZM>C2(&=d}!cjH4@T z^Wxd6zR#04$neVOy0Sw1j!gTFd>ZwiECT7%q_tsC8@VloCAdVJ2M)J6XK=rx&yeHQ zp&iAGj2-2UP+%)aX4AbRy_&xNmXI2#3egDeGEYZ3f;8eb02g}cME0%6{?0>Ok)-+@ zaRjMH$&CoO!J7~V+#N@&+8ut96|;AET+D~h-B0*5g@(Q4ifdWg^)P8u28@O z+xtJ-od@dzWF{AkeU_!{s1Vbj z#euA^@gFoh7~#J?2`)Hy5&G&fK5#{26UFk&&mF1%hX#E zk&NchnkV{5CpGBUb*O=FL7{&lbMqn4Qoto`y}xK^D|lpnYJ(VwQltEaN8uXov#I~c zS+&uGG1Y>}`VmhoJ7#`x|3Rtn$@G0m?yh!bKLE=6Yx1hjvqy^cI{~b<9`Qef>mQ}X zK)+WGD1u1f9cLnSiAg`^4*X+xjD9N`Hjy*i6}A`6*H~xCt+)VToc&&r_U;GO<(V`m z2T33snw8C)=5ZU%3`~b5TP>^{^e0IlO0<&F-voK3?rDFh&9j44r%JIibP9(cH5r`( zsgNna!0Zpu5Ym2d;xMo^f2R)#D5Rw}vm$HZn=73nwY4!g?ueAw~rcy0o2Y;hmlYlfMEr!ps&K_+=YGrH#=%;rdI`4=Qi7SSKBL19>)qKucN z%?FFrK*G*kw%qOe+e*_(``fYZu~tXrt;^e|)v6EHgm_8#_A@iAllLZpoERv4YzAai zxy}dYjeJabiR^ir3GBK1Fm5GGm%nnT%5g98RN!`9Br^e3ST?e4ZSI>eFA#%voSj)O zV4;pvNVA(Bu;8kG;+(8Uw*B-kiY#?c(y)}0w>Hgsg-;u)M11Ab*9~EqZkS0_t}sX) z?Liutr>|n@`boe|bl4&w>cLf8>Tg@|)}+dLqivn`723u@GB1uB;j+<$6Q3j((xhtt zkKV)}hoL`ET+CK@f}s8OiAbHNf=r)fsFSu>7~(on>Sr|UG>dpmh-6_27SnOD!f%|% z`4ePVtBX&7UI%AkJar-GtAAD!vw~cDY1wG%wQ3Q=Em2wAjVt3lBIB)~0?1H>uluX( zsis7WjiU#ZM@UY`uX=^Rg=t=wd2PyHM&cpXN(HZKRUx?< z7^Ol`$a{Hxa?guFd&$WF8}p8P4% z&Y$S6&1pACx4ja5^F}G5`V^(4`U+N%A-vvM_#yy%B0RQ{4uUNx6+YVn`xIGSkV1{z zysqnek$MuXn%0{zJ!R7pt!@aOxXFR|mWKt zO*~sZjvdeQfNPQRfm6TWE_XuQQlDR;N}n12V$2uToS!NFVSpa66JH!<%L^u4Cm@Pz z{;0nq#umk-?5| zYvhY=Oi#a@?ZW4Uwk@P+j92uObz_d`ks@>3)Gr<@Lce%#vPUuRMB#6a5WCk#OU4~gT3aLgRm-Hq(uONniBtlsD|xRgmykHH;7gE1&n2);+w;Ps0!!!veE7g5)WP>MOF_K{A>Wf zUuj@oGv@$16`~8nfNpHkwP1X8j~=^N z&NDVdw{^vD?2(JT+hJvsUn%HePv4ECt}J9_iz(Cf8m4Yk(gQxvN$V z7ng@aZUw1Es|i7_bM)%Cc;*n(Rb9NAM{R$RnQ?f7nEPP)O@#K-W70PXMOhZ0gR=TGGDQ~ zD+%Rp4FKs_DvYx5TwfK=EB5O+7l3RSKF6f!ife@ccE}qW?kA`K4kTc)MC9Pgn&oH< z7H|&o&O_1xl6>{#k3W#XOP8`_yT?fZAWfVm)Bx?6ra`Ii8+zu35Pl+&<_Am}r z^ch9WvPnEnU2;F)(6j1XpV6IbYsYJgDE55xKkFxyGlv)Y?s#Jk$a;+uMsyou1-n|w zJKzJoA?eYt+CcF>|Fl1_(%)t^L$*?}|g6uWp}L_?~s6okWg^*9cvvo|E4B!@A2I zIM!I~6J$Wj49+%&F_2l`UNT9ZMw2 z&6Ai9JxeI%>yPl>3O2CnmvK;^8a95FY4USQmp6}Sdr%RZ*;F5XG`|n1PXe}{gYEoU z*ZoAMmOUc3p0!$pd$*p&TYAjhf2pp$Rm#5LdntWJuwkf!YnTNJ9jw#1KOL|bdJcQj7+a0P<@nhx!XA2p#d@K2?=@e$NE&8rM_un86P z3wW@Rpac6S<_su#uub7qkD~9OFZoq)Fu?5kLUm|y4U%28u2joq<|>oZ=vYc+*8k^* zoiI%|78~D&Y9~%b15gDeDw)q@e+*P(n$Fjz{5%KHK#)f5~w607%q9Emo-E)hjg$?!RW*0A{e0!{ zXeo$B;h{qo9Y^Hkrzek=x`VYrUFl@#^uwZ@t@dfdItI`_Lwo|D8LI*P?69ZmhNV(ZKTAIs)XZ6jjys0Q z#cZ}Np|dH$)6AQ0>mn)Rx^@Z9ExEerr4;3nb&kO>@S`n%N>k0wFOatOXDTl~qy4#Y z`%7Of!2H40R_JuglikDgEAU4np-08>$yP?NyJ@MrsoWH)*2&E8DteA^4L-8Dku@?W zI){~)MLHcduq;^DnjvBeC4 z)UQz zscwvcLkO9t5@y5&nl1E|vce$+zxT~2a31`VFcMHq(*HQ^p!-C!JemFrGUugX`xTAb zUnEtNp1v_#a@AbGeM_^;mdv8!+GHny+L4Ck*~}N0uugqX90+>K|8_C_#j%XS6w49b zp_tyMxe~-pQ!(w>-}$=-2c3B_x^GCeHOvGr?nQ<6tT94Jz>3l^4c%3e4-L%qr{Z!* zB6*#elX*g2s!?r9U2YZvKL8x-9K$;kf#1Erx~94o#x^(6!+{Iq7KvAN9lR+fR}Xse zN{sSDa0<}8&L&gB#6Awu-)qft>`5#btCHZ%Be)XSsFsk!$KhhBLvHU1p~`E I{FnCs0a;~D3IG5A diff --git a/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/Commands.class b/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/Commands.class index d5d26fa50f7f9437c6f6ce9b0796c7fd1f9c1cd0..d2e0bc8863e47b4b7283568a50336e525838ccbf 100644 GIT binary patch delta 2318 zcmY+FYjjjs6~}*PUiW5lL(_qTTzMrSkQd36w4{Armc?(SKB7G*jC%I5+BfJl4%gBR!~GOzQ4GZx|WY6YxzN!u4NYz_q_=v{c`R; zkNw~K?EnAld!_hTN$}#e*UtjC^1D;Pqe|5r%U@RC7CExtYVYlhMf=!*1fiUYeZn59;6r}37 zRiPh{$Xnt)mcm<6xm{<2A`t2Bwg!?x!rX4~UN*{-_0UixCP^1mEC|!S|De^KY^?0m zX_Pb3zW#W^(z!$IgcXZNdYnApXK*J?3S+yw-7}xATHERDZZX*E?B+GOF|E1nAT8Xj zahGC^)YE=m8Q$%@-}d@;do^0^1HR>Ir~Rm}EVP4N1{yU%cCg#vUhcDJe2s-WxZmIb zR>=L5@wsB?bl8T!R&SxpV2^+``%Bec+w!-m581E!YXkcYy6Lh1>VGW97fJLv1a;X1 zfhG0}fwciOpa{20F2+J`?X!W^sX>DzLkeGXuw70`6+1N!%Y9w`qVaG`G$utkB6yLZ zWW3j5t2^G`8||x2j!2P*+2srm8+_D(30Nc1!Q^0$R3K&WaXulcxi5aWe@i?TPe@WX zEl`bUqH$|3kMO9*r=*5A6yvJp)950P?wA!xXgsDUyq;0>P;al5uzGe|kseF-p0HEe zQvGp0>(ugd_6e;}ALU7B@&)^hRAs;FFW zNx67TR2Gf*H|Fv(U)M-0mfX1NjeUbx_=Zp(wO`Ro0~35p@idRmN)tFY~ySQ_2=*VEwI%M!VGxpw`;^y!2J&m)%;`J)- zk~fwVaaj>Lb&eWA9dMRn{W{;5$+koyo+t@A(tOjA<`3<2Id$rS{jZ!2>c@6vaJ~A8 z-4*Qecn;Z9!DsRZ@R0-Rj_NlEjj1YoU#__>!^(3MGz84RYm{AJk?9XrWU2Dtn=pOe zx{d}dL+wfFKk#S!+1wQ=Ep%Ik`f-ZWOq*J$!JYJ^IVqD(?qn>@2?uWT7&&IZJIQ8e z);vy~8>B%u{iZ(6HZ$Oxq}lY(u%jc?HbuLsXSgTB2i*8+x+Iqe=k0bELI6`PVzY}s z&T1FK#V@;#+bM1zoOd(D-ZyXOnf_@aY5d-axx0lny^N-0%{w8t^J2(&oH7~nMVL2} zM~EdXrclNT8E=smyD^1HBg=S_5}uZJ`J6bsL^%^w3h~usr4e4HhF^)8e=jb7;5Poo z2L3@k|B+UAl?LTylL|@`Tg+xv$en7H^rup`s&cleD(Ok<*sf}6Rkzco8rdm{APvQ( zj?^MAvVc|PZl@Q|)ekxRee&Pfq)in&rIb9OTpR;&K zAj=6|rBHLmGL3?(tkVb^hLKmVd-BS4kM=g|zbTYK&}n26TT=3L3AQfY*Q(BARArGL z#TZv+814v-OmVceI>SfC_|s`VmgSR*8Ady1c)X)}iqA~(`L;C6YeL5|*bP28;z-W) z`RcMf?d1Ux=a)NnUYPx(7$>HAA5v!XKVe|>%^tiA&MpQc4K}o5bQ^Mb*aF-SK-b@Kqml%{VN#2sK{ud7OcX9nE zNBK7o^FL|wj$Q`Hbx3i^N5W5v*H0zIdY(3nE#;SD`2?a=#Qtl6b~JPkxp~*9))>|p75ThP(X7M?h^pRM j6L)!V4YMrAzi?fS!>sHoS%qeei=`f!@f!j5@Z0|bihUP9 delta 2348 zcmZ{lYjj*y6~}*PGBfvPa+9`0lk{RANgpAPHtB=5G_jO4ZJ{)2LqbW@fHGumk}1=f zbY@Z-Y&+lsi?v|63M8PQ2vOUr4R(?tfZ(I$p`xIuUtIQsA6zVTEnT`0k+|=jDUGh> zT6dkh&)Mhf|9J|`>RsR+FG!E-MHYxwQiz}-qMJ30F!%iE(v{gGH(C=xT6hp8~y zqoH9du`L>kB$A3*t@}a;Lk&ZzNVLIzTQ$@dv4~2I3Ptf{O%NdIxk?v+J^zLro-|>}@x=v4|ZKSihB0R7s8&*+=z4y_7bCo$Rvz zTF|l5F?^Fjhhw-P6b@_LtSJBAY;7KjM8j4>=N3EcT^j6UkAX%_fKK)r^l+;^>TN3P zmEA|$>rR6wJ8hq8wWkSriMq-v@;wgi#=iQ1YT?#y7Fy>G| z%U!6XQ_yc3e2Y`Ir?AR@hVN*6+paGxFZeEJ?HdX!O3(1D!S|drXu|%T)}fS6#y(P5 zv2c>-G_wDFTZWSs}@}q7K_H6q)HP z3q6cdV)}whvs8KTo;JM&tGgTh8EQ{SUqNk>q2Sb2=j1F)vPJ)XQ~oPox$)i+`ENA+ z!Ic?Sk5VzFf-+g_PEL*~pG?-flfRAe?l>DvUzRHs88(hE=h8gwENt!?XX|D4DA$iO zH$TsEgNK)>Yt&4isZG*4b8CB->6@anJGgs-E>p|Uo#8e&iZPB!M7QVV!!r-%;PZIt zJp2srM!DvacaC%I;@tmp<_^KI@))Mb{du|A^i2{O!&h)Rm(Jk&XV8?a6`XdGi6P?y zECE{;m#0@zF74Zti?M)5Sjf}TPR>!utFq(gEai7B;~!M(v&bu zros&N6GORDoIyOUbby4o>}ZpughRzD$q)zeiGwS+OSGE6&(2945<^u4-=|C?IRAZ? zYt$KrvEW~H>K+-l=pOAolzavOrx_s}Cqi>8BhhwKzTKE-oPR%vFE=AotF~YK$D|r_BO|R*nSrW{byzY?IT|$<2AxVd1xs!G5W&>UFeC?5y-O>a0%9GF|)wzvh zB0bLSJVi+QQ;+nZFq2q3PahW;5c~TC;ZD+TN!kA>h5r+A{>}m3MV?V9wZoA|d=a+KA zE1Jdp%HnM?=^)3UJaHrrVfeDH_( zD^MdOk{F-;QN}y7Rf*+=Zqk{#d(XM&+`0Sn*SGHgmhdcv7(-1STK)H4&yxG16-w!Q zJd}RN2zGj6E9tUEP@n97$y$*J8rq$>smXl17S-BBYM5fj|4-m@h_n% z1IO#u8Pc!&B8c86))hO$*s5)do)qoDne8!{8(q&2{)UWI*Nv$A4EcyRl#Xk?;QjqA z-Xr2n)9HF#h5=RH9nM%D7Sp(r<@$>1i z*p%Epq@fzziqZ7Lz!vL{x}vG!Z(&hgJm$z-oW7?dtz?jP45`7I9;_J{IzFn`j2Z*V zx<;`W#tEIq1hN##QKU*S^&34${_PnGUoicNjxo&8zbXO(&+3ROMME|KTC}RSiOLyn z{0~WJh#4i|CT>w;2Dfo%0RBKKRNdNVOjk}Z_Yt$_U{wEpqgwfj1r@HIqV%SE5@kI6 z0d_)wxYjkJjZTog96fnbHA&P3%+pS3Ek@*cr1NrQ_c2Lec%m8DJZ+a~8^hDzbUGOg literal 0 HcmV?d00001 diff --git a/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PlayerListener.class b/TheButtonAutoFlair/bin/tk/sznp/thebuttonautoflair/PlayerListener.class index c79a59c4c37a70f23c52f7a24a457c0a03bb5744..8c0b249562474a9dd5d4dee30aac5f5cf684e844 100644 GIT binary patch delta 2025 zcmZuyX;@TM7=F)ecjj_Q9R)$fB}!4i2?b415m6R(29yl3QZLK}MrV_mF|~#EJifICJh2NjTMg#`V zTduBBU9qUo@2XKF?QS((CZik`5@yg%pG^fb>1c+qk1Q*3@U z*yd`8cKCvANzb(k<``!7g%Pd8qXsk?^Wc%-7PxSI|D5z#n=j~AeL)3vsMk+eRIy;! zWa~0vyF|f4T&j23Hc6&HSim)p`3?D>`~)n^BcY%^U#ioK?Bn&Yy@Fb5$d}M6P@o@^ zvh-v2L7hg>?FxKYE|6Z)(xQcWaftw7c`bg`b zOk?R51-Ifh0h<~QYeCjeA?s(vq7 zU=GEij60ROFXXCcRYmDYQv;0dQOaHB#5M)nQJFfe z8a3$kYj!+I*aR77Jf+}iJfrK5+~LnLhE#Bsp}97)*e}rU+=*BE)kwr}eL%rMysU@hX4@-xO~R}CNjb;-I^NLF$kk(x z5L;}=Tf8>4mF;SDrW(;ILxFH8s0E`k_Tg;>@8FoOrPVs#!v_-H7s%1qrRDIw_z)lI zr_xHNoghbv9VdAz5guZ_+Ok4pHJ;+~BpIjixrEPn$ zECQgJBEi+O zyn?(c=K{@W;ofNO+Bh4-{yct1c>68vo0v0I@Fq1#rR^?Ys-D8bkU41E1eLML30%9U6E_sbakKMwHr%_DT^#G;Sbt8OA@mGP#y~#lS-?29__WK#@K)$&fsDz2A3Oqn1%;%KIr3?~crcOAFr<3MPOEl7z;cR;k zHaffF*gP(QC)~zl2PXw_>~ubx!1EmJ@))aeuJ&NCGhsP^eNAR(tRaDy1SjSubACe{ zhe|Dm+2N$w&|afA6Bxj~qe-()bGC((cT25?;c*&Lj-Aer%_JmOVTvo;YLKzOHab6{ z$qv}vjN#L6h7EM_TA%JMq|)T+RI;3AAsw?>PF2*a8u_f6IjF?~wjG#@wfwPcfE!&a z;lWn^PPSowQp_42Ec55)V)n-9OTzgR;N$fbzNVPD1b@SknN$t z72n7e6%?gDS`{BOXb32XC_X^NAK(|q?|#s6m~j|&-J2qHbTT*R?0xoGd#`o&Ils@k zG($fB=gHFms`109{Hw+3LI70~=IDoPm8rR?7LeK^YQGjw2oyE@1*~dU7Xiw12oW{f9ayuaN9#=1R%|p<)+$(pI)VIL zvULe9-l|UT)tEJZT-Fw~uhxwQERnESV3J-aO|mOkijY3bI-|yoyD)^CKaQm`7$dZjH8kkBenU~V#NYfr|*(QcWAwJEq6YXzJuwd9J3 z8jcIhF4qgBDJ2!-xa8s~MF6)bScmocd7CP3J?67-7LJVyZo}>RKF7f+ww^>RD&YC= zR(-3q#&1a3ZB(_@(5h*ChB38d^uQ}&n?RZVlVhrWL~<>b(SlwDQG=sH+rC4MBn%+Z z-fp_$T5oKpX1EdxlGq_&ON0kB9!hydlR$-DWtm1Gxllla`O)X-GtXTASqfQ6m=Tlp zd}q;g7w*IT5>o#bt3Q#{Sil2#P#=(|*X$-nm5fKQN5Z35x*{A4v{BO}mC{rOKZeKI zT78BqLPd)7A=kw6^)ftoQo&Pb7I1ZI$woEW715k{hLCe*Sn;faebDva=?p1alY5>`ogS>NL>_P#=dY9|hJP$j&^wz_)Sp@^EGWFEYs z;7ttc7u{PNZ{ZyYZ|e(`66+DXt9K|X%iibSc}^VV`89>Ms>!8lLJP%u`(jZonv^kw zw1Q*!P(PwLXKIf^)}?=2?Wj22RY^k5AZ?N>dOU?{3JOL3v9Wvwa!N>qsN$ zJArz^oXadYfN8#Qo+b;%6W3mOA% zq}xHOjN=4;$LTZ3)LZLDP(?Du8QgUS4Xu8Y3@L`qNd}Pvn80;^DuYAj^KT z%5lku^)l?@GV&@(=nt+74B#I9$9!L^+C;pTKG1tb9YMrRHdp*x(@jNF7TMh3adegYh^Q!F>hBjC|E$vynE@)UcSiS8T zj0A0Iqy|0jnQ_;TMSYM(As0t;ag%MFe-yMEcpo#)Z)7=TB_OfD?`II3e zaJI09&qi4`a0rLlqq#l_nx__|$hGW~MeLF~q)K`IUcS$(uo!Ex1aY>^0J~#9mT~iP z-jNl&VU4Crjb@__o5~U!!}yZ@!nYfH@fE(NhNay54QE#3wc|WzHX?d)fipX?Z1@)6 WF>b8GE+PN0gtIncd`~($S|55z#d5Je@SAajA_p$%~`$npCIN)}2blqQUM|tRoT(Cu){Px;KQQ zi-X~)PA;Y~vBZX&w(gA^!>O9M>Z-XgxG7k34*u9fnT)1rG8K%rTTBz0KN0DACRZ{Q zi!=F}6}d<-x}j!HEEchXQFMA%#x_SAW06=Q$uz_s(wz!NY8D6M=ytCNZ-@p{-3hEX zy?^h_JbEiqiEwm7{qZfcK*N~X9tlUosaZ?~eXfRXJOf}6-Ol2my$s-(wqgG3ISDTes8ElJytCHqedoZ#(m%TP zM(H#%yGZ`NO&U$7FzK6uk#1{A2gsMNt;l0OD;`;Sj7d5fU^>+qhKP(r(-O>sVRa1>llW>%3#r`BsnoLu$r?{*ViDKdMyd60Q zRI%EFElo4&befLC-C(6wScy$mLPl3K=K;`euJ_Uzbf!)-AjIQ3O{ycDZZU{tksJ+f z5L&18r{#dT-=KP(&SI)KA%ufHR-!o!fkv%_hh~z`OJ~y@of?=<$>U}q@+LLXT&BSZ zYl9F-%-du|Q#idD<@uYmq_rlyM16i&Kce*&s|}jZ#N8sjg(fx8InW$zyfN0*6^w?M zY6lW_KEZZ-q@(oCJV>D#;yQs8oPkLXEfPpCp=CNPWeVi&e?ZD6EvFSs-lUb9x5a7) zxNt5L`t3eD&sicn44aj8R++S#)&TF=<*Fpkm1!7`H4o~x%6q7l*6FmizZ$4Mlg^{h z0FenR9tn!cDl2bn9FW8kT5r+?6vT31*jaA!Cl#r)fqK!_c9ROJNGGgjW|d@qIAR&J z0j5IfS2Eb%ZpBkpXi{oR%0nRvi@BL1rHv*~=-kpnCy? zod0i+MLWV9Y!Jq2rvT-C(CY(=z)8X6K`@15YNaoml%}s>{bW26hHrsFAA7*{73+>~ z^U@>qm`;ykvub?S!JG6|dK@T^i=%>V>?5|M?Lw4B_C-{lR>+nB(d8Gr)WsB3b zcs+E0zAnU`hQ{PeVR?5{`Fdp&570MEdPW^TVz5L?r^9)kxM|6}En-%}F}Pk=2aXQz z#}+7bUL7Tq)&_i?lxyv8OW;dgq5u-o^c{qwcIb;jTLA=ECEox?j2`s%1si$%fG}g- zVR=+@8$%b4K7T=5B$zX3MJm|75h0lqXt`t2x#6UQK05vQ7^}A?5r&ub(5qreUZuN4 z2YzbO8}u{y$%aV8)?s1YW+Ff0gW)KqUzqeJ{SvlEg=83bQr6k1p$JeTz$1i23HC;U}oPURgg%O-?)LyhFd&>37+ksCBZvCjEi_C^EOUKs@~& zp95r_{xpDF=o7^I0;oTO`Y{T7Vp%NY56Xm};>A zA4ur>A=CJLn0~BkLA3AEe@r?ekzwIxIV5ShOZMJt!t21->7Bu33%02uPE?Z{9o!W;hg1O+t86lc+(2Z3ozkp;_&TU`MJ(;vR_xYo>*!P7lRuat3*Q zQbq6UodN56V%>@LUD(i&|t7101gFHK@XqIqjbhi$k%THd!W!AjZi!vP&qya7+-I20Q%M5i9jM@ zMTPjOCZEP*;q4sW6z5Fk|2s)FvR*d%8-piE=+TWsO$gBnlPg7{>XM@3NrNY1M{TiC zkHM2rYFf}z2c6)_CQsq1Kyo-5vbM-|ZosQglZ-vx?gWl8W$ViSBsH;8v)&s2((L zV=&Q$h`2r2qcksFBpQ(>>C)5{o@+Z9IPUSMxMYNe0^ zigd&hT~=t-^5)ziov+GXu4D|lJba}XsVn&!ldt9LUG$QMRof&<7 zFelf8g;hB4>V^#fqQSTdKGPN`T zJ`$;(fdl0{k!J1PYFXqqlW*rcunAbRrYJ&V^de;=p`oML@PT<9Fkd(ET_%4)bh`wT zusP%`QuCtiu@JIi2IHDgxN7D6>KPushrgur7nw#0YJ%}#d#9xwQY@OR5wc5GA@`QV zEsAkhsCUqP%z6VbeteUMchX%t-=FpA{b|4eb|)gRYCstZxlq*+D&SOr>q*WFA17<^ z(qZ)H#hZPSLZ^Y-s@gn48Gg*2{FqCf{{+i4jQ}% z1KWeqlx+@VP{!najCj8YryGnQM(k(i9R;dbYcOJbBO0?O8vJ!w5oJNgTI4P#o;vCUQuneX#2h@ zSt$Kbm4Ya}s!C^~^qMM7N9lE>H4mrHD7S6jB%90|I5^NNhX^L50*Zg>5PAOGxo3{*B4Ml?Yq%bxWdsH*M(rf8(G9 zk52L#*bS$8kg1Z3xR>AN-KVf2nN*36IaX*l=b0V2cl8nZDYpJAKt2m{eqz!ISQ*e;7xO<%{wMzn zihxZY6UJqsmZx=2leno5P5w9k2P*z?l9?|Xfag2`PkEGcw#nd+V1o{)&umCo0mP<( z)|>pP?ZwuN_Y7nwhmV>MEr?q2yLQ znpaYnt=bS%E7pcWf7_ALYJgB(h^87nnold$wPD%G>Lww{tzbKJ%+$)X;b1eITm_sZ z8iPsPa$V((6>B}3UpraXMj&O<-&G?8jZ2b-a2K&y{^5$_L}xu1(ng!wDPl_sf}xPq z$C%owVt`!9@WqxijK%S5rLkmKe5IH*`}F%u5k{56;^hTA_8dlFP!Nw{hA#J1RVuQB zRcxdiFD?*4|JM=V!nw^?4zx)AlTKDzvv5;>L_5pWW{JGKa0@BCSS1%(J!t2DK+RG> zfpFx}=4f+utq~6!a`}n}BVATv13Hpf%OWFtYGNw4RI?_Qh=dwru|&w!=4nW;4~Yj8 zNvp4!sd*q3nWxNCeMR%9TLi~GM_XuWP1-s3O+~;vClYJl$TS6>{gY73O#!iHtwq-s zBgyrtCYst34dJ+0QX$4P@lz~~RhRScbZrIhR-bfLAVH*#EZHaCA)q#Dxz!ch*Zrw*EPg3b_ zR5coozeN~C$c3DwS_n0~J313*V~q3;s@zBZ%7XngVlM^yrVduzj3gJH4NMxTNSO8n zI#uz9hn+030vCA3{er_!(Abj73{AxUQx6af&Ow?9wq{ixpxFgfSu!s}3l7pEG%e0h zi(R+>W@u&c_@R`}(772pe@*3+)OL_UttB1%sI$2$Ll+JxFoYnAk_j#c8Up zF4gMd18icYi)U<_xmW^sc3KS zqkTq>HX0q;Wqq`>MDETKc_&BYOMOIEXNgqpqx)?BMpl(q=)cyMe5L(40h?Yjsxm<3AEPLFe&I zyoD{N3wRx#xkA*&oz$*C^B4^kU^t*z1DfBY=fJ)2@-2EEC`?c#y+Gf_KJLd;v|YNC z0`wxa*VhEZKT$Ox%&vX>sXsxlXXxh#=vO%AG{q(!AOx|`&<)L1 zd+6pJRFtN5IqiU2ybHB>wYA!{kKWryf2ni%U7`sX`}h6yFTkl}Q&t`REt>IBnnw2N zi{MRK9l&9&qf9$`KX)P??#|;uwCMkfhe{}~ZJ5M3j>NAT@CJ&Pt1kfe?;ry>GKc?7 zGzudkFqK_6geb5V!}vIzLKgu`Noc?(Jo|3Jt8WkT%ol^orPPhboLlHJ(7T*=&=s^B zW1gaIIL2#`+rO56LD#{0UQZw5Rx%8ae15u-N7GF_owo5Tx`pTCg-vX0T#Pd>a4_zn z5-wmD;1Ce3aUn`epbH#*`4UF%A1`8%#SUEfHo!qz&v*WOKcAVh! zGV-j~nag^y-vS}6gIVaPPt|m~!Ku$87kceFP%Xu0d%<_#oZ~m#!n2%4&@CYBDlHoBhU_7qQm1Y=2h3l5;XZYm0LVsa) z)c6dS*A?~EtE8^`bstw}xJLb*c0sM-*NX$CMuyL*b(gxed&yJkE;a6>!D#mk&_2Yk zOKV-7o|ZACMyWf)vxIJj8|w5*`OeMo!tDh0x^oyW+RxBEZ=Gj9FU#<%N>M2vpDWr@ z$z$a19`+b}`ya@N7DzcuuWF4SUE}&-KC~RvlPUU!-C8EB# zD~aMm1Mw(>pW$5wHj41Q9M({R!uKH(9pAYJ`ASj2ZK85lw^aN1vp&8d!#6^WZmo0S z@13G{FOb{E+tY+1sxE)we!d&(2fe+|U$hH!Y`~0%*a(7i(~qI|ui=n>f=J_a0OzNO zGv2^2n0|&>;^*q{7TW7OhX+ph0SFQII~>)6{16UrFrvdRa~iZq<40y+;fG=U#=_D) zf^mhQh1U?2ij+q_g|uFTHAPuzUa9jXm%jP@q6=zXag}86=#6A4z z^JIt{*(E`4-*!A;g6LmZ>;uJez@C+3xr`rIEEm#H{u+dC2L}f65gH0(iZzj~x7T#J zz`O@h_mt|^I%w*yM}gc2K;3=&t?4)LUH0~&-Dlvt{!jWt6Y%ZAw;bO~@U6i2dVDMK zy$jzed>_JhBEC;foMk+N@3a0QA3vGly*qeLniojzfT|Uz`An%Dlp3u~bCuMdR<+JF zkCNIqRBcn5he+*NRl7RPEVXZ{+O28&o7BFgYWJn-ZK=JWYMHb|En@jzgylo*d6kb} zc1%}cn!aK8eRrU~2kgG@4b*p?-S>lm`Zn5qKN_fSiQV_(f%>NT_$PJXsp|!q$@?fa?1jGrI?BPbV%;!OPR2q!eq+-4V#_lrq@ircYhlw)e)Q2M@?&ma* z;79Nv`Z%A$84e(=d>TKE7tH5)9KXyp$ZJkPHfuVPOJ{1QalJMk^~s26#O$hgU7M0s z18s_<1^_p|2Zeyrpd=;{N`}(=D7nPq@SjmCWN)rCAy;b5mDcAU^3TaaD^g!aCPM&D*+98&p?VP>UdKwBJ=)l+gz7*Gje{q$?~f+OM6I(MGMg zx`<1a1Dm$9_f2RzV#$mas6MolZY!wO3u=utZN+dSqn-AQ=Fe#35kVSij4O064VNz0 z1$~{KGaImRt2#>c5dOQL24NZff?5QO4mWBENJw#G zfU?7lrxXEre{Rfv+?ZKzY>Eh+wfOz{ zIvU5H0Su5};Pupq@=|W6mAF)&&l`{o=)_M`FQiR~^RD79x)ZV97bPx36!s?i{)iat zJ-!4#6}pr@;;o2mE(3I~fU&y@Mr<35)-_zkpXJqfMvb8F3cP~ehNw_X)vHu0c*#Ny zB>@;RwtS;DNkMHGU!m0?wkrUiTeQh&bAj8KHbt8Xzh6$}+BEP{1a8mPPDgJM1?dKD zI@;u-be-xoa4GE6YE{&D8x?40pya{N9~+#~x2a50@|vm zxN%u(Q&c=W#-ZZnDu;@fS36WptqwbrOqyH(H3O1MaYn7%XT#jaWIWwt{BYQ-mwG+NBkw2!F$nqA40O7dDdo_0|5lg z+DdH|W)H4fy=VCtfHUohQcb@ivyiFl|#o!Ar$MU%nKSbujk zzA_Yz>*QvdmPmF7yZSe8j;4cssw;RwXiF$~CO+(;Ozu=V(Z^KTu6kmjcz19~A`!Df z@g^p-GZq@Kl1qhnifN2Js6QQz1y_dpFu=1q+8qz2`;!*a!s6b=1r%4OlhJs0(~&Kw zg2otok+mr+*%9isu#RrGpj1^rvpJaz4YWs7Y0Q~7TKnSmg8f?YbTmBxiO2?;)H==K zu+^8gB6;dHqf;4?gu}PYE^q6OCz1t|y=xL%<1L9;LL_4>4#%SLX!=wpS9Q%gh_xjV zv2;3?=@>;$$!vKj)dRVCX*~H&nn>fAN*AkX9%7ngl1_${rkLa-L#F`rGBP{Ae=kiX zzl@u1l1XJ!I>Dqdc4?ML$JnJBlPbs%twrNjM}KdZm0T0*ia}Eq?TK(Gwl0*6N?kR2 z$whuI&7rwE1#?UnqQRtjG#{$j5{mU(XKi8{UwyVCzrtZn!p(^$l~5^!knV{>IJ4T1 z3bGKgk%+g(g(nZ4Oiem9GL0?J#y~1<^_sMpPJx&c{pmbDqKRN95SE6%tWa;0L8mdz zS<_<$mM8-WG{Zvbm5Bsw+y}Y_0v(BDSG3bgM+4Q3oi$!+rWT!+%Yu0(O`DG?8r#6^Ix0POPCAU~f8C_F|O}n|tM=NNhPVEqP0dVb3lRD@u z>>fmNMja1z3$5wJv>dxG8U)FGgsJ93r7mV6#$?57%fSq}441lC4`{Y|!(f>cUN0(i+Sy(Nx$~M6{`9ok3?aalc6KT$4UV=P`M)@s>ny zZzvvNY8Xw}g#^R)NXP#<^B{%uA+8URf-^AXrHumqFu`K6T%ch8qf$0$6LmBBQdYWk zn-vDQpqE)iyU)#YmdFjmW@VkINf*#&;2pbMn}S}M#zCzGP`4eXmwG9o6Yy4O2CC1b zKDrQyOj>=hP#6TpSGTl`N+L`tlhV|W<-oAB+}xuTsj~qHb1TjR#UV^%X*6aTGyqqk ztSS|9T>d3$pn;F>Pe? zA|kc*yRr3vZ2F5PeTnYHGO4~;6kZb0JOWxZ=N#GQqYQmjr>`)Tsqwjk-lVV5eb{oJ zxLjEI2r*~NN46A7&l#lC*O`tTnQI@eOZuZRXx*R(0OricPrNe|IC z0iIA_pCz84ew4)vmnx#!BqXvX?Nxe6C+tq0_CX>a;uUhPG#Z~V&r5?eBqIM7Q*HH8 zo?|s|qx*|Yc1@3w-U;kZ&!vFZ8<+t6*M5f!b`@ppRjqm7`z-J(%Le zV_2$y5t)Sr#}$yv?+9JMOyNqlEHI~RbvhK@jCjb2N<4}98PSxS{yM#MmzfAhKgfb;tMWn*stsK9;ehnox`&*q+w8b8KhHsh z!N&lxkx)A1$=KN@*Yg}K6tm*p=^hnosE)ZpWF9bI-PTs4S{9gm zA}<63ss65%Vn7H(+J_%cI752*BpJO(LM+T5eMqCpO>)e*L9ACmbBf8Q@@WWUap`MY zwp4D=A8-&C5X{}YaS`KYlb47^nqBsFe4SjpN{|SUKOB*d@=}wR@p3ulW0r+Gyu12L zaX63inI^AbTr0}L{Yj`XZQIo0&dqVeGNHrdv*g6_;C5prll^^ZgK>ihis`}fHiweE z2+hKw0cCml#6!Ixa86%O-)a50yr)hvcs2a}@do1(!Hov5hrQR&Gw6o~Bf$5?6Y=`K zq?N*0gU^Ld`{SGAFewq&c_wdUgzLs?EA0qt#V8Ofkd>qQqiLyG=g4i=Se+3?Oc~K~ zTW-Tvq`<|w#o)xr71@XlXuvAbbpZ^zU}eWFp#u2SUU7p(6Z73Jgn1ARZig-v&S=&) zra%Fq(b$3e^r#?Fqz!GWGJvJN!?92*rOO#xa6_=y)9FVTmERRcVKIB_aVw1kPHa;m z*=t4Cu4>N@()prXlrLk@<>di!QUiR6$(J(lSe`&A){=EAu`?`v+H~9v!?Fvl7=5S?B zx5mSX2vS-G-w2JYU9+@)k(WQmx9EH`(_~S8s4o=mvDAT-h^K-oVp@yD8SY|x`BtVT z2i=FQHwxoNHhFm`-KsNg4|aN}miO1$=QFQ=;b&###LRdLJ)f{PwWj2VpU zgb`2J?m&io-Q;fwolYw^K+29z{APP0!kxUN*_PV zFPQvO!I}=NNj6k`A=bs!^D|HtG*f*x^i4nS-W z_44~B4{J!Um4=c0Xoi^G2zOe%nx?sR&6V>cDsY!HNGJ?bF|`t{6g);#Yk|CEODF|U zxT{-`;m{1tt81R3OtBnZNKxW8qxn>@RH!wl6YguTi3CWBWzLDevB##Y78j6)gz1nPTj;_@soh^5szEG^!N_L|omGdAn zav+#csi)xjL^2j>NhFdHQwwTy0hYc{GG&c4GqsO~`c~zJnrhnryG5FWz4@lLKs(XC zAP63p#1dgZa2^iSqoJ0c0%8r?B3(NPx7z<|qN$y%HQF9ih%wFnFP6rti}?jz!;3=o z(XI+*i`0=3I_e!lr;}G%y@@T>k>1;JMOp@a$*4IJv_i~nh`f?5 z682dsng)w@;Xa__e>}P1(<6^aX!W41AqDD@r=+4fo{aMKa`fZjC|@6oI-ZY;>Uc!T z*S%DZS|yD`OBGhQ5NpWaDMK`V!(N*35FM8X=;H7(LQN^iQI=wbaOZU;4OheR(jjXEO zN2^^_Td^Ta=M2$CG=;L%W!LS`EcJ|?c?@N;6w6X_{Sa;0P_b<2{tXr1 z*h>#$N4vB1FvK)OgBu|KN7{$z(G8&c?UfjRU^isj##KClo`4oax!Wm#&*Oog*--2p z{1>D)WWH8Iy=T*jv>6(S(;~VA-&a#3?Z89d=jar=olZl>tC=347TS;Rr>K>_Ps;$0 z<@7S0Nv}~my@BVlxA9yy-#?)-=foHI`tl;@`Gf)M>C46 z({t4c?~=Jhrzgf^13$|{`8wEtMNKh+YARU))gd-b;VpOMh#0``rSIx3FgitW1~(7#}C8%yL6D&krBo!t>i`x zC`28Il;RV^*#F3wilZ3>*0dZnU1lk^*8!{bO9&SmH0qjhd3>Kx64heY(_jzh22FWOWxk2b=`Q%2uR=yW!`ShJs znxR|9amygLX2{p*9pttwudEeosN_x{e~+`DKdKyn>wp9MT` zq#1M*0D3bu(Jg@1tvFn71I%{<=DX-hxa;fb^Z4%$0RK+BQrtz4(A@z4J)nLs=zkfm zE@=96i93=s|9vJxHWJjMQhASI{7L;2|8pc6U;usY&m1e((L$a3 z4~Yf#PIHerBnH|$46PhVvqH=jZb1wi7Kj%N{CaE)*eJ#KR(Lmw-`;>oBz8PwhzG<3 zFBX&gct?FDUslQ6vwUTJmUlF|@%b4syQj!g3CkrEQFZ%E2KgqKAMExvf9ZpuV*_R; z#70oL2mYxXXX^y0ehN<388{giKtzji8a6|a;_;T->pRK=Cwx0bNc`HwpXWQEymD&b zFYuk9J%wiSU3@qE+zblvJs4L4T6j7@sZ^bwQ%M^}SW%jj=77#u>AVv{B5IaTmaII; z%jTOwT*B9~J#<{%KK`PH$KHC`g&mBRVi?h%6_?}ffq5>=_{)k*maMf+&b1GGVc*)A z`VEaR!pwaD1}Wi#|++kHI>_k}?2%}V~Z<9|vrwAb$Y&S-tN+kM|1t?v_d z-xH(th3&qlM(bN<_kC})zPd{Oej|87kR$GP)G^{!0oE+n?IQPX(X+qA4sQ3*mX3Vo_~x_%yS}{)A!Kvh))`g4AuAzJ0{|14|_;gC(G*_z6m)i0r zD_`o(m#)p1Za~PR=<(lh9UJCf!T7~9UP_2PI!SlTRss(BhhErine%s?`qPga28%fZ z&y7?AjbZ#s&vO_J)uY_(2@>9nI*~m5YyOSn6}lk{@d}fHmRhCWef(QZ#lUq>kx{WD zL+-i}U+0yK(fv~-3 zmjAd@L3Tz#-B&w%kpG;afD>Z8n#b$wHdOcV8ybxuPTi-0r!hQ_#`1h*Oi!d)IAhP? zlN7T7dr^m3EU)w~Zm(6bZC^=B$TfESB=C#0s^jangI|f_cGV8@KL`2WD`(>jm|w~7 zAhhWK!v~ofaVb#u|Hcwm1LCA9es>kz;(LP{UN6f1B~_(^nl3lqD@(abogsC15C0nW zif}Hgnf3ecrkh+1x~l<3cL|0YS#8W?8a^u!#2IRgJ8~x-D_!pMM>@S3^2&)+*Wk4s z!#faCeU*Nt&hy2n-H83X2-WbLZ>|PUhWe^J4G1Y!N0lDIzk8?*%joAfAZBy8QAuz9d5i;zQegOi?}g! z+}IQm!R8jad-z%fgdF4Ix^VN_r%kj$;8yqUtC1xlmUHqHNw>E;gFfFU&__<9xy~^j%-+3dwg_G|+ z1Y5*ia7q#U$YB#tM3^-L0ahIX$aNAxq3<&MIA|xQ6yRQvgO_*Z0EZ_m38RqkzA0Vy+K&t1GlwG8dS?Oi?k|MVBZl9`;g~qT=Og z4iz7)+@|8=bq*C%lha)CN{UYn0iLq<^QdeXo7Q!H7UnMhxL*~fVzFZprv%`vj_AV( z3Hc7;7XXJ4dA>_6xZ%H#ACfcblbyC@?_fQTya(9!h#%zIiLgmX;=ue6%Iu`EcG>n_ z4_53L@mVS_h8WP~ZRE%Mu0$QeKkmU=E#yLqe-|NL;gRPEXOSen#WRkp9n|Ww+Pti` z5NQRi>A`j(F4M;#63^WlDxf&x%isVnhws@=$FP0HwSCSw2Lgy(wNo{T$Z)RUb|6<= zIS~+ibs};lk9K;_>Ci + + TheButtonAutoFlair + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/Commands.java b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/Commands.java index ad08b24..1cd84d0 100644 --- a/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/Commands.java +++ b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/Commands.java @@ -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,14 +28,19 @@ public class Commands implements CommandExecutor { { case "accept": { - if(PluginMain.IgnoredPlayers.contains(player.getName())) - PluginMain.IgnoredPlayers.remove(player.getName()); - if(!PluginMain.AcceptedPlayers.contains(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) { - String flair=PluginMain.PlayerFlairs.get(player.getName()); + //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()); + //PluginMain.AcceptedPlayers.add(player.getName()); + p.AcceptedFlair=true; //2015.08.08. player.sendMessage("§6Your flair has been set:§r "+flair); } else @@ -42,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"); @@ -88,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/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/MaybeOfflinePlayer.java b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/MaybeOfflinePlayer.java new file mode 100644 index 0000000..79bdfc7 --- /dev/null +++ b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/MaybeOfflinePlayer.java @@ -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/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PlayerListener.java b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PlayerListener.java index 93cc476..0e6c94e 100644 --- a/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PlayerListener.java +++ b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PlayerListener.java @@ -15,10 +15,14 @@ public class PlayerListener implements Listener public void onPlayerJoin(PlayerJoinEvent event) { Player p=event.getPlayer(); - PluginMain.Players.add(p); + //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\"}]}}}]"; @@ -31,7 +35,7 @@ public class PlayerListener implements Listener 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. } private static Class nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); diff --git a/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PluginMain.java b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PluginMain.java index c5f649b..ba283d2 100644 --- a/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PluginMain.java +++ b/TheButtonAutoFlair/src/tk/sznp/thebuttonautoflair/PluginMain.java @@ -11,6 +11,7 @@ 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; @@ -21,12 +22,14 @@ 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() @@ -45,6 +48,7 @@ public class PluginMain extends JavaPlugin //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()) @@ -53,7 +57,10 @@ public class PluginMain extends JavaPlugin String line; while ((line = br.readLine()) != null) { - AcceptedPlayers.add(line.replace("\n", "")); + //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(); } @@ -64,7 +71,9 @@ public class PluginMain extends JavaPlugin String line; while ((line = br.readLine()) != null) { - IgnoredPlayers.add(line.replace("\n", "")); + //IgnoredPlayers.add(line.replace("\n", "")); + String name=line.replace("\n", ""); + MaybeOfflinePlayer.AddPlayerIfNeeded(name).IgnoredFlair=true; //2015.08.08. } br.close(); } @@ -105,23 +114,28 @@ public class PluginMain extends JavaPlugin { System.out.println("Error!\n"+e); } - for(String player : AcceptedPlayers) + //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.write(player.PlayerName+"\n"); bw.close(); } catch (IOException e) { System.out.println("Error!\n"+e); } } - for(String player : IgnoredPlayers) + 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.write(player.PlayerName+"\n"); bw.close(); } catch (IOException e) { System.out.println("Error!\n"+e); @@ -207,13 +221,13 @@ public class PluginMain extends JavaPlugin } //It has to store offline player flairs too, therefore it can't use Player object - public static Map PlayerFlairs=new HashMap(); + /*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 PlayerTowns=new HashMap(); //2015.07.20.*/ public static Map TownColors=new HashMap(); //2015.07.20. public Boolean HasIGFlair(String playername) { @@ -228,7 +242,10 @@ public class PluginMain extends JavaPlugin } if(player==null) return false;*/ - return PlayerFlairs.containsKey(playername); + //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) @@ -260,14 +277,20 @@ public class PluginMain extends JavaPlugin 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); + //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) @@ -278,7 +301,8 @@ public class PluginMain extends JavaPlugin }*/ //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 : 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)); @@ -295,15 +319,18 @@ public class PluginMain extends JavaPlugin public static String GetFlair(Player player) { //2015.07.16. - String flair=PlayerFlairs.get(player.getName()); + //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(IgnoredPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).IgnoredFlair) return; - if(AcceptedPlayers.contains(player.getName())) + //if(AcceptedPlayers.contains(player.getName())) + if(MaybeOfflinePlayer.AllPlayers.get(player.getName()).AcceptedFlair) //player.setDisplayName(player.getDisplayName()+flair); AppendPlayerDisplayFlairFinal(player, flair); //2015.07.20. else @@ -315,7 +342,8 @@ public class PluginMain extends JavaPlugin //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.getDisplayName(); + String displayname=player.getName(); //2015.08.08. ArrayList Positions=new ArrayList<>(); //System.out.println("B"); 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 ""; @@ -390,8 +420,15 @@ 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))); + //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(); } }